bug449778_window.xhtml (3482B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 <window title="Mozilla Bug 449778" onload="doTheTest()" 4 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 5 6 <hbox id="parent"> 7 </hbox> 8 9 <!-- test code goes here --> 10 <script type="application/javascript"><![CDATA[ 11 /* globals SimpleTest, is */ 12 var imports = [ "SimpleTest", "is" ]; 13 for (var name of imports) { 14 window[name] = window.arguments[0][name]; 15 } 16 17 function $(id) { 18 return document.getElementById(id); 19 } 20 21 function addBrowser(parent, id, width, height) { 22 var b = 23 document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "browser"); 24 b.setAttribute("type", "content"); 25 b.setAttribute("id", id); 26 b.setAttribute("width", width); 27 b.setAttribute("height", height); 28 $(parent).appendChild(b); 29 } 30 addBrowser("parent", "f1", 300, 200); 31 addBrowser("parent", "f2", 300, 200); 32 33 /** Test for Bug 449778 */ 34 var doc1 = "data:text/html,<html><body>This is a test</body></html>"; 35 var doc2 = "data:text/html,<html><body>This is a second test</body></html>"; 36 var doc3 = "data:text/html,<html><body>This is a <script>var evt = document.createEvent('Events'); evt.initEvent('testEvt', true, true); document.dispatchEvent(evt);</script>third test</body></html>"; 37 38 39 $("f1").setAttribute("src", doc1); 40 $("f2").setAttribute("src", doc2); 41 42 function doTheTest() { 43 var strs = { "f1": "", "f2" : "" }; 44 function attachListener(node, type) { 45 var listener = function() { 46 if (strs[node.id]) strs[node.id] += " "; 47 strs[node.id] += node.id + ".page" + type; 48 } 49 node.addEventListener("page" + type, listener); 50 51 listener.detach = function() { 52 node.removeEventListener("page" + type, listener); 53 } 54 return listener; 55 } 56 57 var l1 = attachListener($("f1"), "show"); 58 var l2 = attachListener($("f1"), "hide"); 59 var l3 = attachListener($("f2"), "show"); 60 var l4 = attachListener($("f2"), "hide"); 61 62 $("f1").swapDocShells($("f2")); 63 64 is(strs.f1, "f1.pagehide f1.pageshow", 65 "Expected hide then show on first loaded page"); 66 is(strs.f2, "f2.pagehide f2.pageshow", 67 "Expected hide then show on second loaded page"); 68 69 function listener2() { 70 $("f2").removeEventListener("testEvt", listener2); 71 72 strs = { "f1": "", "f2" : "" }; 73 74 $("f1").swapDocShells($("f2")); 75 is(strs.f1, "f1.pagehide", 76 "Expected hide on already-loaded page, then nothing"); 77 is(strs.f2, "f2.pageshow f2.pagehide f2.pageshow", 78 "Expected show on still-loading page, then hide on it, then show " + 79 "on already-loaded page"); 80 81 strs = { "f1": "", "f2" : "" }; 82 83 $("f1").addEventListener("pageshow", listener3); 84 } 85 86 function listener3() { 87 $("f1").removeEventListener("pageshow", listener3); 88 89 is(strs.f1, "f1.pageshow", 90 "Expected show as our page finishes loading"); 91 is(strs.f2, "", "Expected no more events here."); 92 93 l1.detach(); 94 l2.detach(); 95 l3.detach(); 96 l4.detach(); 97 98 window.close(); 99 SimpleTest.finish(); 100 } 101 102 $("f2").addEventListener("testEvt", listener2, false, true); 103 $("f2").setAttribute("src", doc3); 104 } 105 106 ]]></script> 107 </window>