|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?> |
|
4 |
|
5 <window title="Popup Reflow Tests" |
|
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
7 |
|
8 <panel id="testPanel" |
|
9 type="arrow" |
|
10 noautohide="true"> |
|
11 </panel> |
|
12 |
|
13 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
14 |
|
15 <script> |
|
16 <![CDATA[ |
|
17 const {classes: Cc, interfaces: Ci, utils: Cu} = Components; |
|
18 |
|
19 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
20 Cu.import("resource://gre/modules/Promise.jsm"); |
|
21 |
|
22 let panel, anchor, arrow; |
|
23 |
|
24 // A reflow observer - it just remembers the stack trace of all sync reflows |
|
25 // done by the panel. |
|
26 let observer = { |
|
27 reflows: [], |
|
28 reflow: function (start, end) { |
|
29 this.reflows.push(new Error().stack); |
|
30 }, |
|
31 |
|
32 reflowInterruptible: function (start, end) { |
|
33 // We're not interested in interruptible reflows. Why, you ask? Because |
|
34 // we've simply cargo-culted this test from browser_tabopen_reflows.js! |
|
35 }, |
|
36 |
|
37 QueryInterface: XPCOMUtils.generateQI([Ci.nsIReflowObserver, |
|
38 Ci.nsISupportsWeakReference]) |
|
39 }; |
|
40 |
|
41 // A test utility that counts the reflows caused by a test function. If the |
|
42 // count of reflows isn't what is expected, it causes a test failure and logs |
|
43 // the stack trace of all seen reflows. |
|
44 function countReflows(testfn, expected) { |
|
45 let deferred = Promise.defer(); |
|
46 observer.reflows = []; |
|
47 let docShell = panel.ownerDocument.defaultView |
|
48 .QueryInterface(Components.interfaces.nsIInterfaceRequestor) |
|
49 .getInterface(Components.interfaces.nsIWebNavigation) |
|
50 .QueryInterface(Components.interfaces.nsIDocShell); |
|
51 docShell.addWeakReflowObserver(observer); |
|
52 testfn().then(() => { |
|
53 docShell.removeWeakReflowObserver(observer); |
|
54 SimpleTest.is(observer.reflows.length, expected, "correct number of reflows"); |
|
55 if (observer.reflows.length != expected) { |
|
56 SimpleTest.info("stack traces of reflows:\n" + observer.reflows.join("\n") + "\n"); |
|
57 } |
|
58 deferred.resolve(); |
|
59 }); |
|
60 return deferred.promise |
|
61 } |
|
62 |
|
63 function openPopup() { |
|
64 let deferred = Promise.defer(); |
|
65 panel.addEventListener("popupshown", function popupshown() { |
|
66 panel.removeEventListener("popupshown", popupshown); |
|
67 deferred.resolve(); |
|
68 }); |
|
69 panel.openPopup(anchor, "before_start"); |
|
70 return deferred.promise |
|
71 } |
|
72 |
|
73 // ******************** |
|
74 // The actual tests... |
|
75 // We only have one atm - simply open a popup. |
|
76 // |
|
77 function testSimplePanel() { |
|
78 return openPopup(); |
|
79 } |
|
80 |
|
81 // ******************** |
|
82 // The test harness... |
|
83 // |
|
84 SimpleTest.waitForExplicitFinish(); |
|
85 |
|
86 addEventListener("load", function() { |
|
87 anchor = document.getElementById("anchor"); |
|
88 panel = document.getElementById("testPanel"); |
|
89 arrow = document.getAnonymousElementByAttribute(panel, "anonid", "arrow"); |
|
90 |
|
91 // Cancel the arrow panel slide-in transition (bug 767133) - we are only |
|
92 // testing reflows in the core panel implementation and not reflows that may |
|
93 // or may not be caused by transitioning.... |
|
94 arrow.style.transition = "none"; |
|
95 |
|
96 // and off we go... |
|
97 countReflows(testSimplePanel, 1).then(SimpleTest.finish); |
|
98 }); |
|
99 ]]> |
|
100 </script> |
|
101 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
102 <p>The anchor --> <span id="anchor">v</span> <--</p> |
|
103 </body> |
|
104 </window> |