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

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

mercurial