From e01f4c4edd1872534e4423b10848967def021d1f Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Wed, 9 Mar 2016 15:36:17 -0800 Subject: [PATCH] Bug 1251151 - Make test_autofill_password-only.html work for e10s. r=dolske MozReview-Commit-ID: Atwqt9mp6Da --HG-- rename : toolkit/components/passwordmgr/test/test_autofill_password-only.html => toolkit/components/passwordmgr/test/mochitest/test_autofill_password-only.html extra : amend_source : aaf81c75cc91b4855f5a5ea10e2a276e56cfd06e --- .../components/passwordmgr/test/mochitest.ini | 1 - .../passwordmgr/test/mochitest/mochitest.ini | 1 + .../test_autofill_password-only.html | 80 ++++++++++--------- .../passwordmgr/test/pwmgr_common.js | 37 ++++++++- 4 files changed, 81 insertions(+), 38 deletions(-) rename toolkit/components/passwordmgr/test/{ => mochitest}/test_autofill_password-only.html (58%) diff --git a/toolkit/components/passwordmgr/test/mochitest.ini b/toolkit/components/passwordmgr/test/mochitest.ini index 761c6acbbd24..5a5f7f463525 100644 --- a/toolkit/components/passwordmgr/test/mochitest.ini +++ b/toolkit/components/passwordmgr/test/mochitest.ini @@ -34,7 +34,6 @@ support-files = # This test doesn't pass because we can't ensure a cross-platform event that # occurs between DOMContentLoaded and Pageload skip-if = true -[test_autofill_password-only.html] [test_basic_form.html] [test_basic_form_0pw.html] [test_basic_form_1pw.html] diff --git a/toolkit/components/passwordmgr/test/mochitest/mochitest.ini b/toolkit/components/passwordmgr/test/mochitest/mochitest.ini index 34e2849e55f2..a74293951622 100644 --- a/toolkit/components/passwordmgr/test/mochitest/mochitest.ini +++ b/toolkit/components/passwordmgr/test/mochitest/mochitest.ini @@ -3,4 +3,5 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g' support-files = ../pwmgr_common.js +[test_autofill_password-only.html] [test_recipe_login_fields.html] diff --git a/toolkit/components/passwordmgr/test/test_autofill_password-only.html b/toolkit/components/passwordmgr/test/mochitest/test_autofill_password-only.html similarity index 58% rename from toolkit/components/passwordmgr/test/test_autofill_password-only.html rename to toolkit/components/passwordmgr/test/mochitest/test_autofill_password-only.html index f933618011cf..ac5b83cc028e 100644 --- a/toolkit/components/passwordmgr/test/test_autofill_password-only.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_autofill_password-only.html @@ -10,42 +10,56 @@ Login Manager test: Bug 444968

@@ -119,12 +133,6 @@ function startTest() { checkForm(6, "testuser2A", "testpass2A"); checkForm(7, "testuser2C", "testpass2C"); - pwmgr.removeLogin(login1A); - pwmgr.removeLogin(login1B); - pwmgr.removeLogin(login2A); - pwmgr.removeLogin(login2B); - pwmgr.removeLogin(login2C); - SimpleTest.finish(); } diff --git a/toolkit/components/passwordmgr/test/pwmgr_common.js b/toolkit/components/passwordmgr/test/pwmgr_common.js index 263e1db8cbb9..b64a328c5ba9 100644 --- a/toolkit/components/passwordmgr/test/pwmgr_common.js +++ b/toolkit/components/passwordmgr/test/pwmgr_common.js @@ -160,6 +160,10 @@ function commonInit(selfFilling) { if (selfFilling) return; + registerRunTests(); +} + +function registerRunTests() { // We provide a general mechanism for our tests to know when they can // safely run: we add a final form that we know will be filled in, wait // for the login manager to tell us that it's filled in and then continue @@ -253,6 +257,9 @@ function dumpLogin(label, login) { function getRecipeParent() { var { LoginManagerParent } = SpecialPowers.Cu.import("resource://gre/modules/LoginManagerParent.jsm", {}); + if (!LoginManagerParent.recipeParentPromise) { + return null; + } return LoginManagerParent.recipeParentPromise.then((recipeParent) => { return SpecialPowers.wrap(recipeParent); }); @@ -275,6 +282,29 @@ function promiseFormsProcessed(expectedCount = 1) { }); } +function loadParentTestFile(aRelativeFilePath) { + let fileURL = SimpleTest.getTestFileURL(aRelativeFilePath); + let testScript = SpecialPowers.loadChromeScript(fileURL); + SimpleTest.registerCleanupFunction(function destroyChromeScript() { + testScript.destroy(); + }); + return testScript; +} + +/** + * Run a function synchronously in the parent process and destroy it in the test cleanup function. + * @param {Function} aFunction - function that will be stringified and run. + * @return {Object} - the return value of loadChromeScript providing message-related methods. + * @see loadChromeScript in specialpowersAPI.js + */ +function runFunctionInParent(aFunction) { + let chromeScript = SpecialPowers.loadChromeScript(aFunction); + SimpleTest.registerCleanupFunction(() => { + chromeScript.destroy(); + }); + return chromeScript; +} + // Code to run when loaded as a chrome script in tests via loadChromeScript if (this.addMessageListener) { const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; @@ -304,6 +334,11 @@ if (this.addMessageListener) { } else { // Code to only run in the mochitest pages (not in the chrome script). SimpleTest.registerCleanupFunction(() => { - getRecipeParent().then(recipeParent => recipeParent.reset()); + let recipeParent = getRecipeParent(); + if (!recipeParent) { + // No need to reset the recipes if the module wasn't even loaded. + return; + } + recipeParent.then(recipeParent => recipeParent.reset()); }); }