diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-02-16 16:16:33 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-02-16 16:16:33 +0100 |
commit | d448b16f969be780444190d178dad4c8b2347612 (patch) | |
tree | 70518229a92bf0e7b5cdc2497bd59356de1d47a3 /tests/pagemod-test-helpers.js | |
parent | 10dcf8de5c6965832452c538451d6170b3bafb66 (diff) | |
download | bugzilla-triage-d448b16f969be780444190d178dad4c8b2347612.tar.gz |
Fix the password recognition.
* doh! !== instead of ===
* also skip attachment.cgi page
Diffstat (limited to 'tests/pagemod-test-helpers.js')
-rw-r--r-- | tests/pagemod-test-helpers.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/pagemod-test-helpers.js b/tests/pagemod-test-helpers.js new file mode 100644 index 0000000..b019810 --- /dev/null +++ b/tests/pagemod-test-helpers.js @@ -0,0 +1,55 @@ +"use strict"; + +const {Cc,Ci} = require("chrome"); + +/** + * A helper function that creates a PageMod, then opens the specified URL + * and checks the effect of the page mod on 'onload' event via testCallback. + */ +exports.testPageMod = function testPageMod(test, testURL, pageModOptions, + testCallback, timeout) { + var xulApp = require("xul-app"); + if (!xulApp.versionInRange(xulApp.platformVersion, "1.9.3a3", "*") && + !xulApp.versionInRange(xulApp.platformVersion, "1.9.2.7", "1.9.2.*")) { + test.pass("Note: not testing PageMod, as it doesn't work on this platform version"); + return null; + } + + var wm = Cc['@mozilla.org/appshell/window-mediator;1'] + .getService(Ci.nsIWindowMediator); + var browserWindow = wm.getMostRecentWindow("navigator:browser"); + if (!browserWindow) { + test.pass("page-mod tests: could not find the browser window, so " + + "will not run. Use -a firefox to run the pagemod tests.") + return null; + } + + if (timeout !== undefined) { + test.waitUntilDone(timeout); + } else { + test.waitUntilDone(); + } + + let loader = test.makeSandboxedLoader(); + let pageMod = loader.require("page-mod"); + + var pageMods = [new pageMod.PageMod(opts) for each(opts in pageModOptions)]; + + var tabBrowser = browserWindow.gBrowser; + var newTab = tabBrowser.addTab(testURL); + tabBrowser.selectedTab = newTab; + var b = tabBrowser.getBrowserForTab(newTab); + + function onPageLoad() { + b.removeEventListener("load", onPageLoad, true); + testCallback(b.contentWindow.wrappedJSObject, function done() { + pageMods.forEach(function(mod) mod.destroy()); + // XXX leaks reported if we don't close the tab? + tabBrowser.removeTab(newTab); + test.done(); + }); + } + b.addEventListener("load", onPageLoad, true); + + return pageMods; +} |