LEFT | RIGHT |
1 (function() | 1 (function() |
2 { | 2 { |
3 let server = null; | 3 let server = null; |
4 let frame = null; | 4 let wnd = null; |
| 5 let tab = null; |
5 | 6 |
6 module("Pop-up blocker", { | 7 module("Pop-up blocker", { |
7 setup: function() | 8 setup: function() |
8 { | 9 { |
9 prepareFilterComponents.call(this, true); | 10 prepareFilterComponents.call(this, true); |
10 preparePrefs.call(this); | 11 preparePrefs.call(this); |
11 | 12 |
12 server = new nsHttpServer(); | 13 server = new nsHttpServer(); |
13 server.start(1234); | 14 server.start(1234); |
14 | 15 |
15 server.registerPathHandler("/test", function(metadata, response) | 16 server.registerPathHandler("/test", function(metadata, response) |
16 { | 17 { |
17 response.setStatusLine("1.1", "200", "OK"); | 18 response.setStatusLine("1.1", "200", "OK"); |
18 response.setHeader("Content-Type", "text/html; charset=utf-8"); | 19 response.setHeader("Content-Type", "text/html; charset=utf-8"); |
19 | 20 |
20 let body = | 21 let body = |
21 '<body onload="document.dispatchEvent(new CustomEvent(\'frameready\',
{bubbles: true}));">' + | 22 '<body onload="document.dispatchEvent(new CustomEvent(\'abp:frameready
\', {bubbles: true}));">' + |
22 '<a id="link" href="/redirect" target="_blank">link</a>' + | 23 '<a id="link" href="/redirect" target="_blank">link</a>' + |
23 '</body>'; | 24 '</body>'; |
24 response.bodyOutputStream.write(body, body.length); | 25 response.bodyOutputStream.write(body, body.length); |
25 }); | 26 }); |
26 server.registerPathHandler("/redirect", function(metadata, response) | 27 server.registerPathHandler("/redirect", function(metadata, response) |
27 { | 28 { |
28 response.setStatusLine("1.1", "302", "Moved Temporarily"); | 29 response.setStatusLine("1.1", "302", "Moved Temporarily"); |
29 response.setHeader("Location", "http://127.0.0.1:1234/target"); | 30 response.setHeader("Location", "http://127.0.0.1:1234/target"); |
30 }); | 31 }); |
31 server.registerPathHandler("/target", function(metadata, response) | 32 server.registerPathHandler("/target", function(metadata, response) |
32 { | 33 { |
33 response.setHeader("Content-Type", "text/html; charset=utf-8"); | 34 response.setHeader("Content-Type", "text/html; charset=utf-8"); |
34 | 35 |
35 let body = '<html><body>OK</body></html>'; | 36 let body = '<html><body>OK</body></html>'; |
36 response.bodyOutputStream.write(body, body.length); | 37 response.bodyOutputStream.write(body, body.length); |
37 }); | 38 }); |
38 | 39 |
39 frame = document.createElementNS("http://www.mozilla.org/keymaster/gatekee
per/there.is.only.xul", "iframe"); | 40 wnd = UI.currentWindow; |
40 frame.setAttribute("type", "content"); | 41 tab = wnd.gBrowser.loadOneTab("http://127.0.0.1:1234/test", {inBackground:
false}); |
41 frame.setAttribute("src", "http://127.0.0.1:1234/test"); | 42 wnd.gBrowser.getBrowserForTab(tab).addEventListener("abp:frameready", func
tion(event) |
42 frame.style.visibility = "collapse"; | |
43 document.body.appendChild(frame); | |
44 | |
45 stop(); | |
46 frame.addEventListener("frameready", function(event) | |
47 { | 43 { |
48 start(); | 44 start(); |
49 }, false, true); | 45 }, false, true); |
| 46 |
| 47 stop(); |
50 }, | 48 }, |
51 teardown: function() | 49 teardown: function() |
52 { | 50 { |
53 restoreFilterComponents.call(this); | 51 restoreFilterComponents.call(this); |
54 restorePrefs.call(this); | 52 restorePrefs.call(this); |
55 | 53 |
56 stop(); | 54 stop(); |
57 server.stop(function() | 55 server.stop(function() |
58 { | 56 { |
59 frame.parentElement.removeChild(frame); | 57 wnd.gBrowser.removeTab(tab); |
60 | 58 |
61 server = null; | 59 server = null; |
62 frame = null; | 60 frame = null; |
63 | 61 |
64 start(); | 62 start(); |
65 }); | 63 }); |
66 } | 64 } |
67 }); | 65 }); |
68 | 66 |
69 let tests = [ | 67 let tests = [ |
70 ["||127.0.0.1:1234/target$popup", false], | 68 ["||127.0.0.1:1234/target$popup", false], |
71 ["||127.0.0.1:1234/target$~subdocument", true], | 69 ["||127.0.0.1:1234/target$~subdocument", true], |
72 ["||127.0.0.1:1234/target$popup,domain=127.0.0.1", false], | 70 ["||127.0.0.1:1234/target$popup,domain=127.0.0.1", false], |
73 ["||127.0.0.1:1234/target$popup,domain=128.0.0.1", true], | 71 ["||127.0.0.1:1234/target$popup,domain=128.0.0.1", true], |
74 ["||127.0.0.1:1234/redirect$popup", false], | 72 ["||127.0.0.1:1234/redirect$popup", false], |
75 ["||127.0.0.1:1234/redirect$~subdocument", true], | 73 ["||127.0.0.1:1234/redirect$~subdocument", true], |
76 ["||127.0.0.1:1234/redirect$popup,domain=127.0.0.1", false], | 74 ["||127.0.0.1:1234/redirect$popup,domain=127.0.0.1", false], |
77 ["||127.0.0.1:1234/redirect$popup,domain=128.0.0.1", true], | 75 ["||127.0.0.1:1234/redirect$popup,domain=128.0.0.1", true], |
78 ]; | 76 ]; |
79 | 77 |
80 function runTest(filter, result) | 78 function runTest(filter, result) |
81 { | 79 { |
82 FilterStorage.addFilter(filter); | 80 FilterStorage.addFilter(filter); |
83 | 81 |
84 let successful = false; | 82 let successful = false; |
85 let wnd = Utils.getChromeWindow(window); | |
86 | 83 |
87 function onTabOpen(event) | 84 function onTabOpen(event) |
88 { | 85 { |
89 window.clearTimeout(timeout); | 86 window.clearTimeout(timeout); |
90 wnd.gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false)
; | 87 wnd.gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false)
; |
91 | 88 |
92 let tab = event.target; | 89 let tab = event.target; |
93 let browser = wnd.gBrowser.getBrowserForTab(tab); | 90 let browser = wnd.gBrowser.getBrowserForTab(tab); |
94 Utils.runAsync(function() | 91 Utils.runAsync(function() |
95 { | 92 { |
(...skipping 16 matching lines...) Expand all Loading... |
112 keys.push(key); | 109 keys.push(key); |
113 | 110 |
114 FilterStorage.removeFilter(filter); | 111 FilterStorage.removeFilter(filter); |
115 start(); | 112 start(); |
116 } | 113 } |
117 | 114 |
118 wnd.gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); | 115 wnd.gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); |
119 wnd.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); | 116 wnd.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); |
120 let timeout = window.setTimeout(onTabClose, 1000); // In case the tab isn
't opened | 117 let timeout = window.setTimeout(onTabClose, 1000); // In case the tab isn
't opened |
121 | 118 |
122 frame.contentDocument.getElementById("link").click(); | 119 wnd.gBrowser.getBrowserForTab(tab).contentDocument.getElementById("link").cl
ick(); |
123 } | 120 } |
124 | 121 |
125 for (let [filter, result] of tests) | 122 for (let [filter, result] of tests) |
126 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result)); | 123 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result)); |
127 })(); | 124 })(); |
LEFT | RIGHT |