bug113934_window.xhtml (5847B)
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"> 5 6 <hbox> 7 <vbox id="box1"> 8 </vbox> 9 <vbox id="box2"> 10 </vbox> 11 <spacer flex="1"/> 12 </hbox> 13 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]; 22 } 23 24 function $(id) { 25 return document.getElementById(id); 26 } 27 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); 38 } 39 addBrowser("box1", "f1", 300, 200); 40 addBrowser("box1", "f2", 300, 200); 41 addBrowser("box2", "f3", 30, 200); 42 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>"; 47 48 49 $("f1").setAttribute("src", doc1); 50 $("f2").setAttribute("src", doc2); 51 $("f3").setAttribute("src", doc2); 52 53 async function doTheTest() { 54 var s2 = await snapshotWindow($("f2").contentWindow); 55 // var s3 = await snapshotWindow($("f3").contentWindow); 56 57 // This test is broken - see bug 1090274 58 //ok(!compareSnapshots(s2, s3, true)[0], 59 // "Should look different due to different sizing"); 60 61 function getDOM(id) { 62 return $(id).contentDocument.documentElement.innerHTML; 63 } 64 65 var dom1 = getDOM("f1"); 66 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!"); 71 72 $("f1").swapDocShells($("f2")); 73 // now we have doms 2*, 1, 2 in the frames 74 75 is(getDOM("f1"), dom2star, "Shouldn't have changed the DOM on swap"); 76 is(getDOM("f2"), dom1, "Shouldn't have fired event handlers"); 77 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 _addedDispatched: false, 89 async handleEvent(aEvent) { 90 if (!this._afterFirst) { 91 is(aEvent.type, "DOMLinkAdded"); 92 93 var strs = { "f1": "", "f3" : "" }; 94 function attachListener(node, type) { 95 var listener = function() { 96 if (strs[node.id]) strs[node.id] += " "; 97 strs[node.id] += node.id + ".page" + type; 98 } 99 node.addEventListener("page" + type, listener); 100 101 listener.detach = function() { 102 node.removeEventListener("page" + type, listener); 103 } 104 return listener; 105 } 106 107 var l1 = attachListener($("f1"), "show"); 108 var l2 = attachListener($("f1"), "hide"); 109 var l3 = attachListener($("f3"), "show"); 110 var l4 = attachListener($("f3"), "hide"); 111 112 $("f1").swapDocShells($("f3")); 113 // now we have DOMs 2, 1, 2* in the frames 114 115 l1.detach(); 116 l2.detach(); 117 l3.detach(); 118 l4.detach(); 119 120 // swapDocShells reflows asynchronously, ensure layout is 121 // clean so that the viewport of f1 is the right size. 122 $("f1").getBoundingClientRect(); 123 var s1_new = await snapshotWindow($("f1").contentWindow); 124 var [same, first, second] = compareSnapshots(s1_new, s2, true); 125 ok(same, "Should reflow on swap. Expected " + second + " but got " + first); 126 127 is(strs.f1, "f1.pagehide f1.pageshow"); 128 is(strs.f3, "f3.pagehide f3.pageshow"); 129 this._afterFirst = true; 130 return; 131 } 132 if (aEvent.type == "DOMLinkAdded") { 133 is(this._addedDispatched, false); 134 this._addedDispatched = true; 135 } 136 137 if (this._addedDispatched) { 138 $("f1").removeEventListener("DOMLinkAdded", this); 139 $("f3").removeEventListener("DOMLinkAdded", this); 140 window.close(); 141 SimpleTest.finish(); 142 } 143 } 144 }; 145 146 $("f1").addEventListener("DOMLinkAdded", DOMLinkListener); 147 $("f3").addEventListener("DOMLinkAdded", DOMLinkListener); 148 149 var linkElement = $("f1").contentDocument.createElement("link"); 150 linkElement.setAttribute("rel", "alternate"); 151 linkElement.setAttribute("href", "about:blank"); 152 $("f1").contentDocument.documentElement.firstChild.appendChild(linkElement); 153 } 154 155 ]]></script> 156 </window>