Index: chrome/content/tests/popupBlocker.js |
=================================================================== |
--- a/chrome/content/tests/popupBlocker.js |
+++ b/chrome/content/tests/popupBlocker.js |
@@ -1,64 +1,65 @@ |
(function() |
{ |
let server = null; |
- let frame = null; |
+ let wnd = null; |
+ let tab = null; |
module("Pop-up blocker", { |
setup: function() |
{ |
prepareFilterComponents.call(this, true); |
preparePrefs.call(this); |
server = new nsHttpServer(); |
server.start(1234); |
server.registerPathHandler("/test", function(metadata, response) |
{ |
response.setStatusLine("1.1", "200", "OK"); |
response.setHeader("Content-Type", "text/html; charset=utf-8"); |
- let body = '<html><body><a id="link" href="/redirect" target="_blank">link</a></body></html>'; |
+ let body = |
+ '<body onload="document.dispatchEvent(new CustomEvent(\'frameready\', {bubbles: true}));">' + |
+ '<a id="link" href="/redirect" target="_blank">link</a>' + |
+ '</body>'; |
response.bodyOutputStream.write(body, body.length); |
}); |
server.registerPathHandler("/redirect", function(metadata, response) |
{ |
response.setStatusLine("1.1", "302", "Moved Temporarily"); |
response.setHeader("Location", "http://127.0.0.1:1234/target"); |
}); |
server.registerPathHandler("/target", function(metadata, response) |
{ |
- response.setStatusLine("1.1", "302", "Moved Temporarily"); |
response.setHeader("Content-Type", "text/html; charset=utf-8"); |
let body = '<html><body>OK</body></html>'; |
response.bodyOutputStream.write(body, body.length); |
}); |
- frame = document.createElement("iframe"); |
- frame.setAttribute("src", "http://127.0.0.1:1234/test"); |
- frame.style.visibility = "collapse"; |
- document.body.appendChild(frame); |
+ wnd = UI.currentWindow; |
+ tab = wnd.gBrowser.loadOneTab("http://127.0.0.1:1234/test", {inBackground: false}); |
+ wnd.gBrowser.getBrowserForTab(tab).addEventListener("frameready", function(event) |
+ { |
+ start(); |
+ }, false, true); |
stop(); |
- frame.addEventListener("load", function(event) |
- { |
- start(); |
- }, false); |
}, |
teardown: function() |
{ |
restoreFilterComponents.call(this); |
restorePrefs.call(this); |
stop(); |
server.stop(function() |
{ |
- frame.parentElement.removeChild(frame); |
+ wnd.gBrowser.removeTab(tab); |
server = null; |
frame = null; |
start(); |
}); |
} |
}); |
@@ -74,17 +75,16 @@ |
["||127.0.0.1:1234/redirect$popup,domain=128.0.0.1", true], |
]; |
function runTest(filter, result) |
{ |
FilterStorage.addFilter(filter); |
let successful = false; |
- let wnd = Utils.getChromeWindow(window); |
function onTabOpen(event) |
{ |
window.clearTimeout(timeout); |
wnd.gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false); |
let tab = event.target; |
let browser = wnd.gBrowser.getBrowserForTab(tab); |
@@ -111,14 +111,14 @@ |
FilterStorage.removeFilter(filter); |
start(); |
} |
wnd.gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); |
wnd.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); |
let timeout = window.setTimeout(onTabClose, 1000); // In case the tab isn't opened |
- frame.contentDocument.getElementById("link").click(); |
+ wnd.gBrowser.getBrowserForTab(tab).contentDocument.getElementById("link").click(); |
} |
for (let [filter, result] of tests) |
asyncTest(filter, runTest.bind(null, Filter.fromText(filter), result)); |
})(); |