test_bug453650.xhtml (3639B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 4 <!-- 5 https://bugzilla.mozilla.org/show_bug.cgi?id=453650 6 --> 7 <window title="Mozilla Bug 453650" 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 9 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 11 12 <!-- test code goes here --> 13 <script type="application/javascript"> 14 <![CDATA[ 15 16 /** Test for Bug 453650 */ 17 SimpleTest.waitForExplicitFinish(); 18 19 var iter = runTests(); 20 nextTest(); 21 22 function* runTests() { 23 var iframe = document.createXULElement("iframe"); 24 iframe.style.width = "300px"; 25 iframe.style.height = "300px"; 26 iframe.setAttribute("src", "data:text/html,<h1 id='h'>hello</h1>"); 27 28 document.documentElement.appendChild(iframe); 29 yield whenLoaded(iframe); 30 info("iframe loaded"); 31 32 var h1 = iframe.contentDocument.getElementById("h"); 33 let myCallback = function() { h1.style.width = "400px"; }; 34 info("Calling waitForInterruptibleReflow"); 35 yield waitForInterruptibleReflow(iframe.docShell, myCallback); 36 info("got past top-level waitForInterruptibleReflow"); 37 38 myCallback = function() { h1.style.width = "300px"; }; 39 info("Calling waitForReflow"); 40 waitForReflow(iframe.docShell, myCallback); 41 info("got past top-level waitForReflow"); 42 yield is(300, h1.offsetWidth, "h1 has correct width"); 43 44 SimpleTest.finish(); 45 } 46 47 function waitForInterruptibleReflow(docShell, 48 callbackThatShouldTriggerReflow) { 49 waitForReflow(docShell, callbackThatShouldTriggerReflow, true); 50 } 51 52 function waitForReflow(docShell, callbackThatShouldTriggerReflow, 53 interruptible = false) { 54 info("Entering waitForReflow"); 55 function done() { 56 info("Entering done (inside of waitForReflow)"); 57 58 docShell.removeWeakReflowObserver(observer); 59 SimpleTest.executeSoon(nextTest); 60 } 61 62 var observer = { 63 reflow (start, end) { 64 info("Entering observer.reflow"); 65 if (interruptible) { 66 ok(false, "expected interruptible reflow"); 67 } else { 68 ok(true, "observed uninterruptible reflow"); 69 } 70 71 info("times: " + start + ", " + end); 72 ok(start <= end, "reflow start time lower than end time"); 73 done(); 74 }, 75 76 reflowInterruptible (start, end) { 77 info("Entering observer.reflowInterruptible"); 78 if (!interruptible) { 79 ok(false, "expected uninterruptible reflow"); 80 } else { 81 ok(true, "observed interruptible reflow"); 82 } 83 84 info("times: " + start + ", " + end); 85 ok(start <= end, "reflow start time lower than end time"); 86 done(); 87 }, 88 89 QueryInterface: ChromeUtils.generateQI([ 90 "nsIReflowObserver", 91 "nsISupportsWeakReference", 92 ]), 93 }; 94 95 info("waitForReflow is adding a reflow observer"); 96 docShell.addWeakReflowObserver(observer); 97 callbackThatShouldTriggerReflow(); 98 } 99 100 function whenLoaded(iframe) { 101 info("entering whenLoaded"); 102 iframe.addEventListener("load", function() { 103 SimpleTest.executeSoon(nextTest); 104 }, { once: true }); 105 } 106 107 function nextTest() { 108 info("entering nextTest"); 109 iter.next(); 110 } 111 112 ]]> 113 </script> 114 115 <!-- test results are displayed in the html:body --> 116 <body xmlns="http://www.w3.org/1999/xhtml"> 117 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=453650" 118 target="_blank">Mozilla Bug 453650</a> 119 </body> 120 </window>