Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/tests/popupBlocker.js

Issue 29331996: Issue 3244 - Pop-up blocker unit tests broken in E10S mode (Closed)
Patch Set: Issue 3244 - Pop-up blocker unit tests broken in E10S mode Created Jan. 14, 2016, 10:58 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/content/common.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 let tabs = SDK.require("sdk/tabs");
3 let server = null; 4 let server = null;
4 let wnd = null;
5 let tab = null; 5 let tab = null;
6 6
7 module("Pop-up blocker", { 7 module("Pop-up blocker", {
8 setup: function() 8 beforeEach: function()
9 { 9 {
10 prepareFilterComponents.call(this, true); 10 prepareFilterComponents.call(this, true);
11 preparePrefs.call(this); 11 preparePrefs.call(this);
12 12
13 server = new nsHttpServer(); 13 server = new nsHttpServer();
14 server.start(1234); 14 server.start(1234);
15 15
16 // '/test' serves an html page with a single link
16 server.registerPathHandler("/test", function(metadata, response) 17 server.registerPathHandler("/test", function(metadata, response)
17 { 18 {
18 response.setStatusLine("1.1", "200", "OK"); 19 response.setStatusLine("1.1", "200", "OK");
19 response.setHeader("Content-Type", "text/html; charset=utf-8"); 20 response.setHeader("Content-Type", "text/html; charset=utf-8");
20 21
21 let body = 22 let body =
22 '<body onload="document.dispatchEvent(new CustomEvent(\'abp:frameready \', {bubbles: true}));">' + 23 '<body>' +
23 '<a id="link" href="/redirect" target="_blank">link</a>' + 24 '<a id="link" href="/redirect" target="_blank">link</a>' +
24 '</body>'; 25 '</body>';
25 response.bodyOutputStream.write(body, body.length); 26 response.bodyOutputStream.write(body, body.length);
26 }); 27 });
28
29 // redirects '/redirect' to '/target'
27 server.registerPathHandler("/redirect", function(metadata, response) 30 server.registerPathHandler("/redirect", function(metadata, response)
28 { 31 {
29 response.setStatusLine("1.1", "302", "Moved Temporarily"); 32 response.setStatusLine("1.1", "302", "Moved Temporarily");
30 response.setHeader("Location", "http://127.0.0.1:1234/target"); 33 response.setHeader("Location", "http://127.0.0.1:1234/target");
31 }); 34 });
35
36 // '/target' serves an html page with 'OK' message
32 server.registerPathHandler("/target", function(metadata, response) 37 server.registerPathHandler("/target", function(metadata, response)
33 { 38 {
34 response.setHeader("Content-Type", "text/html; charset=utf-8"); 39 response.setHeader("Content-Type", "text/html; charset=utf-8");
35 40
36 let body = '<html><body>OK</body></html>'; 41 let body = '<html><body>OK</body></html>';
37 response.bodyOutputStream.write(body, body.length); 42 response.bodyOutputStream.write(body, body.length);
38 }); 43 });
39 44
40 wnd = UI.currentWindow; 45 tabs.open({
41 tab = wnd.gBrowser.loadOneTab("http://127.0.0.1:1234/test", {inBackground: false}); 46 url: "http://127.0.0.1:1234/test",
42 wnd.gBrowser.getBrowserForTab(tab).addEventListener("abp:frameready", func tion(event) 47 inBackground: false,
43 { 48 onReady: start
44 start(); 49 });
45 }, false, true);
46 50
47 stop(); 51 stop();
48 }, 52 },
49 teardown: function() 53 afterEach: function()
50 { 54 {
51 restoreFilterComponents.call(this); 55 restoreFilterComponents.call(this);
52 restorePrefs.call(this); 56 restorePrefs.call(this);
53 57
54 stop(); 58 stop();
55 server.stop(function() 59 server.stop(function()
56 { 60 {
57 wnd.gBrowser.removeTab(tab); 61 tab.close(function()
58 62 {
59 server = null; 63 server = null;
60 frame = null; 64 start();
61 65 });
62 start();
63 }); 66 });
64 } 67 }
65 }); 68 });
66 69
67 let tests = [ 70 let tests = [
68 ["||127.0.0.1:1234/target$popup", false], 71 ["||127.0.0.1:1234/target$popup", false],
69 ["||127.0.0.1:1234/target$~subdocument", true], 72 ["||127.0.0.1:1234/target$~subdocument", true],
70 ["||127.0.0.1:1234/target$popup,domain=127.0.0.1", false], 73 ["||127.0.0.1:1234/target$popup,domain=127.0.0.1", false],
71 ["||127.0.0.1:1234/target$popup,domain=128.0.0.1", true], 74 ["||127.0.0.1:1234/target$popup,domain=128.0.0.1", true],
72 ["||127.0.0.1:1234/redirect$popup", false], 75 ["||127.0.0.1:1234/redirect$popup", false],
73 ["||127.0.0.1:1234/redirect$~subdocument", true], 76 ["||127.0.0.1:1234/redirect$~subdocument", true],
74 ["||127.0.0.1:1234/redirect$popup,domain=127.0.0.1", false], 77 ["||127.0.0.1:1234/redirect$popup,domain=127.0.0.1", false],
75 ["||127.0.0.1:1234/redirect$popup,domain=128.0.0.1", true], 78 ["||127.0.0.1:1234/redirect$popup,domain=128.0.0.1", true],
76 ]; 79 ];
77 80
78 function runTest(filter, result) 81 function runTest(filter, result)
79 { 82 {
80 FilterStorage.addFilter(filter); 83 FilterStorage.addFilter(filter);
81 84
82 let successful = false; 85 let successful = false;
83 86
84 function onTabOpen(event) 87 function onTabOpen(tab)
85 { 88 {
89 tabs.off("ready", onTabOpen);
90
91 // link in '/test' was clicked
92 tab.on("close", onTabClose);
86 window.clearTimeout(timeout); 93 window.clearTimeout(timeout);
87 wnd.gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false) ;
88 94
89 let tab = event.target; 95 var worker = tab.attach({
90 let browser = wnd.gBrowser.getBrowserForTab(tab); 96 contentScriptWhen: "ready",
91 Utils.runAsync(function() 97 contentScript: "self.port.emit('done', document.body.textContent);"
98 });
99
100 worker.port.once("done", function(bodyText)
92 { 101 {
93 browser.contentWindow.addEventListener("load", function(event) 102 if (bodyText.indexOf("OK") >= 0)
94 { 103 successful = true;
95 if (browser.contentDocument.body.textContent.indexOf("OK") >= 0)
96 successful = true;
97 104
98 browser.contentWindow.close(); 105 // pop-up was not blocked so close it
99 }, false); 106 tab.close();
100 }); 107 });
101 } 108 }
109 tabs.on("ready", onTabOpen);
102 110
103 function onTabClose(event) 111 function onTabClose(tab)
104 { 112 {
105 wnd.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, fals e); 113 tabs.off("ready", onTabOpen);
114 if (tab)
115 tab.off("close", onTabClose);
116
106 ok(result == successful, "Opening tab with filter " + filter.text); 117 ok(result == successful, "Opening tab with filter " + filter.text);
107 var keys = [];
108 for (let key in defaultMatcher.blacklist.keywordByFilter)
109 keys.push(key);
110 118
111 FilterStorage.removeFilter(filter); 119 FilterStorage.removeFilter(filter);
120
112 start(); 121 start();
113 } 122 }
114 123
115 wnd.gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); 124 // In case the tab isn't opened
116 wnd.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); 125 let timeout = window.setTimeout(onTabClose, 1000, null);
117 let timeout = window.setTimeout(onTabClose, 1000); // In case the tab isn 't opened
118 126
119 wnd.gBrowser.getBrowserForTab(tab).contentDocument.getElementById("link").cl ick(); 127 // click the link in the '/test' tab opened before the test
128 var worker = tab.attach({
129 contentScriptWhen: "ready",
130 contentScript: "(" + function()
131 {
132 document.getElementById('link').click();
133 } + ")()"
134 });
120 } 135 }
121 136
122 for (let [filter, result] of tests) 137 for (let [filter, result] of tests)
123 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result)); 138 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result));
124 })(); 139 })();
OLDNEW
« no previous file with comments | « chrome/content/common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld