docshell/test/chrome/bug113934_window.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial