Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / docshell / test / chrome / bug113934_window.xhtml
blob794b8b28363f4e4ada94da1f1f1241a68638c979
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <window title="Mozilla Bug 113934" onload="doTheTest()"
4 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
6 <hbox>
7 <vbox id="box1">
8 </vbox>
9 <vbox id="box2">
10 </vbox>
11 <spacer flex="1"/>
12 </hbox>
14 <!-- test code goes here -->
15 <script type="application/javascript"><![CDATA[
16 /* globals SimpleTest, is, isnot, ok, snapshotWindow, compareSnapshots,
17 onerror */
18 var imports = [ "SimpleTest", "is", "isnot", "ok", "snapshotWindow",
19 "compareSnapshots", "onerror" ];
20 for (var name of imports) {
21 window[name] = window.arguments[0][name];
24 function $(id) {
25 return document.getElementById(id);
28 function addBrowser(parent, id, width, height) {
29 var b =
30 document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "browser");
31 var type = window.location.search.slice(1);
32 is(type == "chrome" || type == "content", true, "Unexpected type");
33 b.setAttribute("type", type);
34 b.setAttribute("id", id);
35 b.style.width = width + "px";
36 b.style.height = height + "px";
37 $(parent).appendChild(b);
39 addBrowser("box1", "f1", 300, 200);
40 addBrowser("box1", "f2", 300, 200);
41 addBrowser("box2", "f3", 30, 200);
43 /** Test for Bug 113934 */
44 var doc1 =
45 "data:text/html,<html><body onbeforeunload='document.documentElement.textContent = \"\"' onunload='document.documentElement.textContent = \"\"' onpagehide='document.documentElement.textContent = \"\"'>This is a test</body></html>";
46 var doc2 = "data:text/html,<html><head></head><body>This is a second test</body></html>";
49 $("f1").setAttribute("src", doc1);
50 $("f2").setAttribute("src", doc2);
51 $("f3").setAttribute("src", doc2);
53 async function doTheTest() {
54 var s2 = await snapshotWindow($("f2").contentWindow);
55 // var s3 = await snapshotWindow($("f3").contentWindow);
57 // This test is broken - see bug 1090274
58 //ok(!compareSnapshots(s2, s3, true)[0],
59 // "Should look different due to different sizing");
61 function getDOM(id) {
62 return $(id).contentDocument.documentElement.innerHTML;
65 var dom1 = getDOM("f1");
67 var dom2 = getDOM("f2");
68 $("f2").contentDocument.body.textContent = "Modified the text";
69 var dom2star = getDOM("f2");
70 isnot(dom2, dom2star, "We changed the DOM!");
72 $("f1").swapDocShells($("f2"));
73 // now we have doms 2*, 1, 2 in the frames
75 is(getDOM("f1"), dom2star, "Shouldn't have changed the DOM on swap");
76 is(getDOM("f2"), dom1, "Shouldn't have fired event handlers");
78 // Test for bug 480149
79 // The DOMLink* events are dispatched asynchronously, thus I cannot
80 // just include the <link> element in the initial DOM and swap the
81 // docshells. Instead, the link element is added now. Then, when the
82 // first DOMLinkAdded event (which is a result of the actual addition)
83 // is dispatched, the docshells are swapped and the pageshow and pagehide
84 // events are tested. Only then, we wait for the DOMLink* events,
85 // which are a result of swapping the docshells.
86 var DOMLinkListener = {
87 _afterFirst: false,
88 _removedDispatched: false,
89 _addedDispatched: false,
90 async handleEvent(aEvent) {
91 if (!this._afterFirst) {
92 is(aEvent.type, "DOMLinkAdded");
94 var strs = { "f1": "", "f3" : "" };
95 function attachListener(node, type) {
96 var listener = function(e) {
97 if (strs[node.id]) strs[node.id] += " ";
98 strs[node.id] += node.id + ".page" + type;
100 node.addEventListener("page" + type, listener);
102 listener.detach = function() {
103 node.removeEventListener("page" + type, listener);
105 return listener;
108 var l1 = attachListener($("f1"), "show");
109 var l2 = attachListener($("f1"), "hide");
110 var l3 = attachListener($("f3"), "show");
111 var l4 = attachListener($("f3"), "hide");
113 $("f1").swapDocShells($("f3"));
114 // now we have DOMs 2, 1, 2* in the frames
116 l1.detach();
117 l2.detach();
118 l3.detach();
119 l4.detach();
121 // swapDocShells reflows asynchronously, ensure layout is
122 // clean so that the viewport of f1 is the right size.
123 $("f1").getBoundingClientRect();
124 var s1_new = await snapshotWindow($("f1").contentWindow);
125 var [same, first, second] = compareSnapshots(s1_new, s2, true);
126 ok(same, "Should reflow on swap. Expected " + second + " but got " + first);
128 is(strs.f1, "f1.pagehide f1.pageshow");
129 is(strs.f3, "f3.pagehide f3.pageshow");
130 this._afterFirst = true;
131 return;
133 if (aEvent.type == "DOMLinkAdded") {
134 is(this._addedDispatched, false);
135 this._addedDispatched = true;
137 else {
138 is(this._removedDispatched, false);
139 this._removedDispatched = true;
142 if (this._addedDispatched && this._removedDispatched) {
143 $("f1").removeEventListener("DOMLinkAdded", this);
144 $("f1").removeEventListener("DOMLinkRemoved", this);
145 $("f3").removeEventListener("DOMLinkAdded", this);
146 $("f3").removeEventListener("DOMLinkRemoved", this);
147 window.close();
148 SimpleTest.finish();
153 $("f1").addEventListener("DOMLinkAdded", DOMLinkListener);
154 $("f1").addEventListener("DOMLinkRemoved", DOMLinkListener);
155 $("f3").addEventListener("DOMLinkAdded", DOMLinkListener);
156 $("f3").addEventListener("DOMLinkRemoved", DOMLinkListener);
158 var linkElement = $("f1").contentDocument.createElement("link");
159 linkElement.setAttribute("rel", "alternate");
160 linkElement.setAttribute("href", "about:blank");
161 $("f1").contentDocument.documentElement.firstChild.appendChild(linkElement);
164 ]]></script>
165 </window>