layout/base/tests/bug450930.xhtml

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     2 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg">
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=450930
     5 -->
     6 <head>
     7   <title>Test for Bug 450930 (MozAfterPaint)</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body onload="runNext()">
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450930">Mozilla Bug 450930</a>
    13 <div id="display">
    14   <div id="d" style="width:400px; height:200px;"></div>
    15   <iframe id="iframe" style="width:400px; height:200px;"
    16    src="data:text/html,&lt;div id='d'&gt;&lt;span style='margin-left:3px;'&gt;Hello&lt;/span&gt;
    17         &lt;/div&gt;&lt;div style='margin-top:500px' id='d2'&gt;
    18         &lt;span style='margin-left:3px;'&gt;Goodbye&lt;/span&gt;&lt;/div>"></iframe>
    19   <svg:svg style="width:410px; height:210px;" id="svg">
    20     <svg:foreignObject width="100%" height="100%">
    21       <iframe id="iframe2" style="width:400px; height:200px;"
    22        src="data:text/html,&lt;div id='d'&gt;&lt;span style='margin-left:3px;'&gt;Hello&lt;/span&gt;
    23             &lt;/div&gt;&lt;div style='margin-top:500px' id='d2'&gt;
    24             &lt;span style='margin-left:3px;'&gt;Goodbye&lt;/span&gt;&lt;/div>"></iframe>
    25     </svg:foreignObject>
    26   </svg:svg>
    27 </div>
    28 <div id="content" style="display: none">
    29 </div>
    32 <pre id="test">
    33 <script class="testbody" type="text/javascript"><![CDATA[
    35 function flash(doc, name) {
    36   var d = doc.getElementById(name);
    37   d.style.backgroundColor = d.style.backgroundColor == "blue" ? "yellow" : "blue";
    38   // Now flush out style changes in that document, since our event listeners
    39   // seem to assume that things will work that way.
    40   d.getBoundingClientRect();
    41 }
    43 function le(v1, v2, s) {
    44   window.opener.ok(v1 <= v2, s + " (" + v1 + "," + v2 + ")");
    45 }
    47 function checkContains(r1, r2, s) {
    48   le(Math.round(r1.left), Math.round(r2.left), "Left edges out" + s);
    49   le(Math.round(r2.right), Math.round(r1.right), "Right edges out" + s);
    50   le(Math.round(r1.top), Math.round(r2.top), "Top edges out" + s);
    51   le(Math.round(r2.bottom), Math.round(r1.bottom), "Bottom edges out" + s);
    52 }
    54 function isRect(r1, r2) {
    55   return (Math.abs(r1.left - r2.left) <= 1 ||
    56           Math.abs(r1.right - r2.right) <= 1 ||
    57           Math.abs(r1.top - r2.top) <= 1 ||
    58           Math.abs(r1.bottom - r2.bottom) <= 1);
    59 }
    61 function isRectInList(r, list) {
    62   for (var i = 0; i < list.length; ++i) {
    63     if (isRect(r, list[i]))
    64       return true;
    65   }
    66   return false;
    67 }
    69 function doesRectContain(r1, r2) {
    70   return Math.floor(r1.left) <= r2.left && r2.right <= Math.ceil(r1.right) &&
    71          Math.floor(r1.top) <= r2.top && r2.bottom <= Math.ceil(r1.bottom);
    72 }
    74 function rectToString(r) {
    75   return "(" + r.left + "," + r.top + "," + r.right + "," + r.bottom + ")";
    76 }
    78 function doesRectContainListElement(r, list) {
    79   dump("Incoming rect: " + rectToString(r) + "\n");
    80   for (var i = 0; i < list.length; ++i) {
    81     dump("List rect " + i + ": " + rectToString(list[i]));
    82     if (doesRectContain(r, list[i])) {
    83       dump(" FOUND\n");
    84       return true;
    85     }
    86     dump("\n");
    87   }
    88   dump("NOT FOUND\n");
    89   return false;
    90 }
    92 function checkGotSubdoc(list, container) {
    93   var r = container.getBoundingClientRect();
    94   return doesRectContainListElement(r, list);
    95 }
    97 function runTest1() {
    98   // test basic functionality
    99   var iterations = 0;
   100   var foundExactRect = false;
   102   function listener(event) {
   103     var r = SpecialPowers.wrap(event).boundingClientRect;
   104     var bounds = document.getElementById('d').getBoundingClientRect();
   105     checkContains(r, bounds, "");
   106     if (isRectInList(bounds, SpecialPowers.wrap(event).clientRects)) {
   107       foundExactRect = true;
   108     }
   109     window.removeEventListener("MozAfterPaint", listener, false);
   110     ++iterations;
   111     if (iterations < 4) {
   112       setTimeout(triggerPaint, 100);
   113     } else {
   114       window.opener.ok(foundExactRect, "Found exact rect");
   115       runNext();
   116     }
   117   }
   119   function triggerPaint() {
   120     window.addEventListener("MozAfterPaint", listener, false);
   121     flash(document, 'd');
   122     window.opener.ok(true, "trigger test1 paint");
   123   }
   124   triggerPaint();
   125 }
   127 function runTest2(frameID, containerID) {
   128   // test reporting of painting in subdocuments
   129   var fired = 0;
   130   var gotSubdocPrivileged = false;
   131   var iframe = document.getElementById(frameID);
   132   var container = document.getElementById(containerID);
   134   function listener(event) {
   135     if (checkGotSubdoc(SpecialPowers.wrap(event).clientRects, container))
   136       gotSubdocPrivileged = true;
   137     if (SpecialPowers.wrap(event).clientRects.length > 0) {
   138       if (++fired == 1)
   139         setTimeout(check, 100);
   140     }
   141   }
   143   function check() {
   144     window.opener.is(fired, 1, "Wrong event count (" + frameID + ")");
   145     window.opener.ok(gotSubdocPrivileged, "Didn't get subdoc invalidation while we were privileged (" + frameID + ")");
   146     window.removeEventListener("MozAfterPaint", listener, false);
   147     runNext();
   148   }
   150   function triggerPaint() {
   151     window.addEventListener("MozAfterPaint", listener, false);
   152     document.body.offsetTop;
   153     flash(iframe.contentDocument, 'd');
   154   }
   155   triggerPaint();
   156 }
   158 var test = 0;
   159 var tests = [runTest1,
   160              function() { runTest2("iframe", "iframe") },
   161              function() { runTest2("iframe2", "svg") }];
   162 function runNext() {
   163   if (SpecialPowers.DOMWindowUtils.isMozAfterPaintPending) {
   164     // Wait until there are no pending paints before trying to run tests
   165     setTimeout(runNext, 100);
   166     return;
   167   }
   168   if (test < tests.length) {
   169     ++test;
   170     tests[test - 1]();
   171   } else {
   172     window.opener.finishTests();
   173   }
   174 }
   177 ]]></script>
   178 </pre>
   180 </body>
   181 </html>

mercurial