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