OLD | NEW |
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 = '<html><body><a id="link" href="/redirect" target="_blank">li
nk</a></body></html>'; | 21 let body = |
| 22 '<body onload="document.dispatchEvent(new CustomEvent(\'abp:frameready
\', {bubbles: true}));">' + |
| 23 '<a id="link" href="/redirect" target="_blank">link</a>' + |
| 24 '</body>'; |
21 response.bodyOutputStream.write(body, body.length); | 25 response.bodyOutputStream.write(body, body.length); |
22 }); | 26 }); |
23 server.registerPathHandler("/redirect", function(metadata, response) | 27 server.registerPathHandler("/redirect", function(metadata, response) |
24 { | 28 { |
25 response.setStatusLine("1.1", "302", "Moved Temporarily"); | 29 response.setStatusLine("1.1", "302", "Moved Temporarily"); |
26 response.setHeader("Location", "http://127.0.0.1:1234/target"); | 30 response.setHeader("Location", "http://127.0.0.1:1234/target"); |
27 }); | 31 }); |
28 server.registerPathHandler("/target", function(metadata, response) | 32 server.registerPathHandler("/target", function(metadata, response) |
29 { | 33 { |
30 response.setStatusLine("1.1", "302", "Moved Temporarily"); | |
31 response.setHeader("Content-Type", "text/html; charset=utf-8"); | 34 response.setHeader("Content-Type", "text/html; charset=utf-8"); |
32 | 35 |
33 let body = '<html><body>OK</body></html>'; | 36 let body = '<html><body>OK</body></html>'; |
34 response.bodyOutputStream.write(body, body.length); | 37 response.bodyOutputStream.write(body, body.length); |
35 }); | 38 }); |
36 | 39 |
37 frame = document.createElement("iframe"); | 40 wnd = UI.currentWindow; |
38 frame.setAttribute("src", "http://127.0.0.1:1234/test"); | 41 tab = wnd.gBrowser.loadOneTab("http://127.0.0.1:1234/test", {inBackground:
false}); |
39 frame.style.visibility = "collapse"; | 42 wnd.gBrowser.getBrowserForTab(tab).addEventListener("abp:frameready", func
tion(event) |
40 document.body.appendChild(frame); | 43 { |
| 44 start(); |
| 45 }, false, true); |
41 | 46 |
42 stop(); | 47 stop(); |
43 frame.addEventListener("load", function(event) | |
44 { | |
45 start(); | |
46 }, false); | |
47 }, | 48 }, |
48 teardown: function() | 49 teardown: function() |
49 { | 50 { |
50 restoreFilterComponents.call(this); | 51 restoreFilterComponents.call(this); |
51 restorePrefs.call(this); | 52 restorePrefs.call(this); |
52 | 53 |
53 stop(); | 54 stop(); |
54 server.stop(function() | 55 server.stop(function() |
55 { | 56 { |
56 frame.parentElement.removeChild(frame); | 57 wnd.gBrowser.removeTab(tab); |
57 | 58 |
58 server = null; | 59 server = null; |
59 frame = null; | 60 frame = null; |
60 | 61 |
61 start(); | 62 start(); |
62 }); | 63 }); |
63 } | 64 } |
64 }); | 65 }); |
65 | 66 |
66 let tests = [ | 67 let tests = [ |
67 ["||127.0.0.1:1234/target$popup", false], | 68 ["||127.0.0.1:1234/target$popup", false], |
68 ["||127.0.0.1:1234/target$~subdocument", true], | 69 ["||127.0.0.1:1234/target$~subdocument", true], |
69 ["||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], |
70 ["||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], |
71 ["||127.0.0.1:1234/redirect$popup", false], | 72 ["||127.0.0.1:1234/redirect$popup", false], |
72 ["||127.0.0.1:1234/redirect$~subdocument", true], | 73 ["||127.0.0.1:1234/redirect$~subdocument", true], |
73 ["||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], |
74 ["||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], |
75 ]; | 76 ]; |
76 | 77 |
77 function runTest(filter, result) | 78 function runTest(filter, result) |
78 { | 79 { |
79 FilterStorage.addFilter(filter); | 80 FilterStorage.addFilter(filter); |
80 | 81 |
81 let successful = false; | 82 let successful = false; |
82 let wnd = Utils.getChromeWindow(window); | |
83 | 83 |
84 function onTabOpen(event) | 84 function onTabOpen(event) |
85 { | 85 { |
86 window.clearTimeout(timeout); | 86 window.clearTimeout(timeout); |
87 wnd.gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false)
; | 87 wnd.gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false)
; |
88 | 88 |
89 let tab = event.target; | 89 let tab = event.target; |
90 let browser = wnd.gBrowser.getBrowserForTab(tab); | 90 let browser = wnd.gBrowser.getBrowserForTab(tab); |
91 Utils.runAsync(function() | 91 Utils.runAsync(function() |
92 { | 92 { |
(...skipping 16 matching lines...) Expand all Loading... |
109 keys.push(key); | 109 keys.push(key); |
110 | 110 |
111 FilterStorage.removeFilter(filter); | 111 FilterStorage.removeFilter(filter); |
112 start(); | 112 start(); |
113 } | 113 } |
114 | 114 |
115 wnd.gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); | 115 wnd.gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); |
116 wnd.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); | 116 wnd.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); |
117 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 |
118 | 118 |
119 frame.contentDocument.getElementById("link").click(); | 119 wnd.gBrowser.getBrowserForTab(tab).contentDocument.getElementById("link").cl
ick(); |
120 } | 120 } |
121 | 121 |
122 for (let [filter, result] of tests) | 122 for (let [filter, result] of tests) |
123 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result)); | 123 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result)); |
124 })(); | 124 })(); |
OLD | NEW |