docshell/test/chrome/test_bug453650.xul

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:03f911ca8dbc
1 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="/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 type="application/javascript"
11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
12
13 <!-- test code goes here -->
14 <script type="application/javascript">
15 <![CDATA[
16
17 /** Test for Bug 453650 **/
18 SimpleTest.waitForExplicitFinish();
19
20 var Ci = Components.interfaces;
21 var Cr = Components.results;
22
23 var iter = runTests();
24 nextTest();
25
26 function runTests() {
27 var iframe = document.createElement("iframe");
28 iframe.style.width = "300px";
29 iframe.style.height = "300px";
30 iframe.setAttribute("src", "data:text/html,<h1 id='h'>hello</h1>");
31
32 document.documentElement.appendChild(iframe);
33 yield whenLoaded(iframe);
34 info("iframe loaded");
35
36 var h1 = iframe.contentDocument.getElementById("h");
37 h1.style.width = "400px";
38 yield waitForInterruptibleReflow(iframe.docShell);
39
40 h1.style.width = "300px";
41 waitForReflow(iframe.docShell);
42 yield is(300, h1.offsetWidth, "h1 has correct width");
43 }
44
45 function waitForInterruptibleReflow(docShell) {
46 waitForReflow(docShell, true);
47 }
48
49 function waitForReflow(docShell, interruptible = false) {
50 function done() {
51 docShell.removeWeakReflowObserver(observer);
52 SimpleTest.executeSoon(nextTest);
53 }
54
55 var observer = {
56 reflow: function (start, end) {
57 if (interruptible) {
58 ok(false, "expected interruptible reflow");
59 } else {
60 ok(true, "observed uninterruptible reflow");
61 }
62
63 info("times: " + start + ", " + end);
64 ok(start < end, "reflow start time lower than end time");
65 done();
66 },
67
68 reflowInterruptible: function (start, end) {
69 if (!interruptible) {
70 ok(false, "expected uninterruptible reflow");
71 } else {
72 ok(true, "observed interruptible reflow");
73 }
74
75 info("times: " + start + ", " + end);
76 ok(start < end, "reflow start time lower than end time");
77 done();
78 },
79
80 QueryInterface: function (iid) {
81 if (Ci.nsIReflowObserver.equals(iid) ||
82 Ci.nsISupportsWeakReference.equals(iid) ||
83 Ci.nsISupports.equals(iid))
84 return this;
85 throw Cr.NS_ERROR_NO_INTERFACE;
86 },
87 };
88
89 docShell.addWeakReflowObserver(observer);
90 }
91
92 function whenLoaded(iframe) {
93 iframe.addEventListener("load", function onLoad() {
94 iframe.removeEventListener("load", onLoad);
95 SimpleTest.executeSoon(nextTest);
96 });
97 }
98
99 function nextTest() {
100 try {
101 iter.next();
102 } catch (e if e instanceof StopIteration) {
103 SimpleTest.finish();
104 }
105 }
106
107 ]]>
108 </script>
109
110 <!-- test results are displayed in the html:body -->
111 <body xmlns="http://www.w3.org/1999/xhtml">
112 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=453650"
113 target="_blank">Mozilla Bug 453650</a>
114 </body>
115 </window>

mercurial