bug450930.xhtml (5670B)
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 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,<div id='d'><span style='margin-left:3px;'>Hello</span> 17 </div><div style='margin-top:500px' id='d2'> 18 <span style='margin-left:3px;'>Goodbye</span></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,<div id='d'><span style='margin-left:3px;'>Hello</span> 23 </div><div style='margin-top:500px' id='d2'> 24 <span style='margin-left:3px;'>Goodbye</span></div>"></iframe> 25 </svg:foreignObject> 26 </svg:svg> 27 </div> 28 <div id="content" style="display: none"> 29 </div> 30 31 32 <pre id="test"> 33 <script class="testbody" type="text/javascript"><![CDATA[ 34 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 } 42 43 function le(v1, v2, s) { 44 window.opener.ok(v1 <= v2, s + " (" + v1 + "," + v2 + ")"); 45 } 46 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 } 53 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 } 60 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 } 68 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 } 73 74 function rectToString(r) { 75 return "(" + r.left + "," + r.top + "," + r.right + "," + r.bottom + ")"; 76 } 77 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 } 91 92 function checkGotSubdoc(list, container) { 93 var r = container.getBoundingClientRect(); 94 return doesRectContainListElement(r, list); 95 } 96 97 function runTest1() { 98 // test basic functionality 99 var iterations = 0; 100 var foundExactRect = false; 101 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); 110 ++iterations; 111 if (iterations < 4) { 112 setTimeout(triggerPaint, 100); 113 } else { 114 window.opener.ok(foundExactRect, "Found exact rect"); 115 runNext(); 116 } 117 } 118 119 function triggerPaint() { 120 window.addEventListener("MozAfterPaint", listener); 121 flash(document, 'd'); 122 window.opener.ok(true, "trigger test1 paint"); 123 } 124 triggerPaint(); 125 } 126 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); 133 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 } 142 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); 147 runNext(); 148 } 149 150 function triggerPaint() { 151 window.addEventListener("MozAfterPaint", listener); 152 document.body.offsetTop; 153 flash(iframe.contentDocument, 'd'); 154 } 155 triggerPaint(); 156 } 157 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 } 175 176 177 ]]></script> 178 </pre> 179 180 </body> 181 </html>