Bug 752461 - Hide click-to-play overlays when choosing "never activate plugins.....
[gecko.git] / docshell / test / chrome / bug449778_window.xul
blobdd311997ecd299a1a4fc5696d17486314a2fa646
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">
6 <hbox id="parent">
7 </hbox>
9 <!-- test code goes here -->
10 <script type="application/javascript"><![CDATA[
11 var imports = [ "SimpleTest", "is", "isnot", "ok", "onerror" ];
12 for each (var name in imports) {
13 window[name] = window.opener.wrappedJSObject[name];
16 function $(id) {
17 return document.getElementById(id);
20 function addBrowser(parent, id, width, height) {
21 var b =
22 document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "browser");
23 b.setAttribute("type", "content");
24 b.setAttribute("id", id);
25 b.setAttribute("width", width);
26 b.setAttribute("height", height);
27 $(parent).appendChild(b);
29 addBrowser("parent", "f1", 300, 200);
30 addBrowser("parent", "f2", 300, 200);
32 /** Test for Bug 449778 **/
33 var doc1 = "data:text/html,<html><body>This is a test</body></html>";
34 var doc2 = "data:text/html,<html><body>This is a second test</body></html>";
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>";
38 $("f1").setAttribute("src", doc1);
39 $("f2").setAttribute("src", doc2);
41 function doTheTest() {
42 var strs = { "f1": "", "f2" : "" };
43 function attachListener(node, type) {
44 var listener = function(e) {
45 if (strs[node.id]) strs[node.id] += " ";
46 strs[node.id] += node.id + ".page" + type;
48 node.addEventListener("page" + type, listener, false);
50 listener.detach = function() {
51 node.removeEventListener("page" + type, listener, false);
53 return listener;
56 var l1 = attachListener($("f1"), "show");
57 var l2 = attachListener($("f1"), "hide");
58 var l3 = attachListener($("f2"), "show");
59 var l4 = attachListener($("f2"), "hide");
61 $("f1").swapDocShells($("f2"));
63 is(strs["f1"], "f1.pagehide f1.pageshow",
64 "Expected hide then show on first loaded page");
65 is(strs["f2"], "f2.pagehide f2.pageshow",
66 "Expected hide then show on second loaded page");
68 function listener2() {
69 $("f2").removeEventListener("testEvt", listener2, false);
71 strs = { "f1": "", "f2" : "" };
73 $("f1").swapDocShells($("f2"));
74 is(strs["f1"], "f1.pagehide",
75 "Expected hide on already-loaded page, then nothing");
76 is(strs["f2"], "f2.pageshow f2.pagehide f2.pageshow",
77 "Expected show on still-loading page, then hide on it, then show " +
78 "on already-loaded page");
80 strs = { "f1": "", "f2" : "" };
82 $("f1").addEventListener("pageshow", listener3, false);
85 function listener3() {
86 $("f1").removeEventListener("pageshow", listener3, false);
88 is(strs["f1"], "f1.pageshow",
89 "Expected show as our page finishes loading");
90 is(strs["f2"], "", "Expected no more events here.");
92 l1.detach();
93 l2.detach();
94 l3.detach();
95 l4.detach();
97 window.close();
98 SimpleTest.finish();
101 $("f2").addEventListener("testEvt", listener2, false, true);
102 $("f2").setAttribute("src", doc3);
105 ]]></script>
106 </window>