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 Feb. 4, 2016, 11:29 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: function(aTab)
44 start(); 49 {
45 }, false, true); 50 tab = aTab;
51 start();
52 }
53 });
46 54
47 stop(); 55 stop();
48 }, 56 },
49 teardown: function() 57 afterEach: function()
50 { 58 {
51 restoreFilterComponents.call(this); 59 restoreFilterComponents.call(this);
52 restorePrefs.call(this); 60 restorePrefs.call(this);
53 61
54 stop(); 62 stop();
55 server.stop(function() 63 server.stop(function()
56 { 64 {
57 wnd.gBrowser.removeTab(tab); 65 tab.close(function()
58 66 {
59 server = null; 67 server = null;
60 frame = null; 68 start();
61 69 });
62 start();
63 }); 70 });
64 } 71 }
65 }); 72 });
66 73
67 let tests = [ 74 let tests = [
68 ["||127.0.0.1:1234/target$popup", false], 75 ["||127.0.0.1:1234/target$popup", false],
69 ["||127.0.0.1:1234/target$~subdocument", true], 76 ["||127.0.0.1:1234/target$~subdocument", true],
70 ["||127.0.0.1:1234/target$popup,domain=127.0.0.1", false], 77 ["||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], 78 ["||127.0.0.1:1234/target$popup,domain=128.0.0.1", true],
72 ["||127.0.0.1:1234/redirect$popup", false], 79 ["||127.0.0.1:1234/redirect$popup", false],
73 ["||127.0.0.1:1234/redirect$~subdocument", true], 80 ["||127.0.0.1:1234/redirect$~subdocument", true],
74 ["||127.0.0.1:1234/redirect$popup,domain=127.0.0.1", false], 81 ["||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], 82 ["||127.0.0.1:1234/redirect$popup,domain=128.0.0.1", true],
76 ]; 83 ];
77 84
78 function runTest(filter, result) 85 function runTest(filter, result)
79 { 86 {
80 FilterStorage.addFilter(filter); 87 FilterStorage.addFilter(filter);
81 88
82 let successful = false; 89 let successful = false;
83 90
84 function onTabOpen(event) 91 function onTabOpen(tab)
85 { 92 {
93 tabs.off("ready", onTabOpen);
94
95 // link in '/test' was clicked
96 tab.on("close", onTabClose);
86 window.clearTimeout(timeout); 97 window.clearTimeout(timeout);
87 wnd.gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false) ;
88 98
89 let tab = event.target; 99 var worker = tab.attach({
90 let browser = wnd.gBrowser.getBrowserForTab(tab); 100 contentScriptWhen: "ready",
91 Utils.runAsync(function() 101 contentScript: "self.port.emit('done', document.body.textContent);"
102 });
103
104 worker.port.once("done", function(bodyText)
92 { 105 {
93 browser.contentWindow.addEventListener("load", function(event) 106 if (bodyText.indexOf("OK") >= 0)
94 { 107 successful = true;
95 if (browser.contentDocument.body.textContent.indexOf("OK") >= 0)
96 successful = true;
97 108
98 browser.contentWindow.close(); 109 // pop-up was not blocked so close it
99 }, false); 110 tab.close();
100 }); 111 });
101 } 112 }
113 tabs.on("ready", onTabOpen);
102 114
103 function onTabClose(event) 115 function onTabClose(tab)
104 { 116 {
105 wnd.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, fals e); 117 tabs.off("ready", onTabOpen);
118 if (tab)
119 tab.off("close", onTabClose);
120
106 ok(result == successful, "Opening tab with filter " + filter.text); 121 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 122
111 FilterStorage.removeFilter(filter); 123 FilterStorage.removeFilter(filter);
124
112 start(); 125 start();
113 } 126 }
114 127
115 wnd.gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); 128 // In case the tab isn't opened
116 wnd.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); 129 let timeout = window.setTimeout(onTabClose, 1000, null);
117 let timeout = window.setTimeout(onTabClose, 1000); // In case the tab isn 't opened
118 130
119 wnd.gBrowser.getBrowserForTab(tab).contentDocument.getElementById("link").cl ick(); 131 // click the link in the '/test' tab opened before the test
132 var worker = tab.attach({
133 contentScriptWhen: "ready",
134 contentScript: "(" + function()
135 {
136 document.getElementById('link').click();
137 } + ")()"
138 });
120 } 139 }
121 140
122 for (let [filter, result] of tests) 141 for (let [filter, result] of tests)
123 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result)); 142 asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result));
124 })(); 143 })();
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