mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1269039 - Make test_master_password.html work with e10s. r=dolske
MozReview-Commit-ID: 2LZ4EjI8MHW --HG-- extra : rebase_source : 4c3d4dc1f6aaaee7702a43dfde0544ed785e1541
This commit is contained in:
parent
0abd943a74
commit
123e86924e
@ -75,9 +75,9 @@ var add_task = (function () {
|
||||
}
|
||||
} catch (ex) {
|
||||
try {
|
||||
ok(false, "" + ex, "Should not throw any errors", ex.stack);
|
||||
SimpleTest.record(false, "" + ex, "Should not throw any errors", ex.stack);
|
||||
} catch (ex2) {
|
||||
ok(false, "(The exception cannot be converted to string.)",
|
||||
SimpleTest.record(false, "(The exception cannot be converted to string.)",
|
||||
"Should not throw any errors", ex.stack);
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,8 @@ skip-if = toolkit == 'android' && debug # bug 1397615
|
||||
[test_input_events.html]
|
||||
[test_input_events_for_identical_values.html]
|
||||
[test_master_password.html]
|
||||
skip-if = toolkit == 'android' || e10s # Tests desktop prompts
|
||||
scheme = https
|
||||
skip-if = toolkit == 'android' # Tests desktop prompts
|
||||
support-files =
|
||||
chrome_timeout.js
|
||||
subtst_master_pass.html
|
||||
|
@ -17,28 +17,33 @@ Login Manager test: master password.
|
||||
// Force parent to not look for tab-modal prompts, as they're not used for auth prompts.
|
||||
isTabModal = false;
|
||||
|
||||
commonInit();
|
||||
var chromeScript = runChecksAfterCommonInit();
|
||||
SimpleTest.requestFlakyTimeout("untriaged");
|
||||
|
||||
var pwmgr = SpecialPowers.Services.logins;
|
||||
var pwcrypt = SpecialPowers.Cc["@mozilla.org/login-manager/crypto/SDR;1"]
|
||||
.getService(Ci.nsILoginManagerCrypto);
|
||||
|
||||
var nsLoginInfo = new SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo);
|
||||
|
||||
var exampleCom = "http://example.com/tests/toolkit/components/passwordmgr/test/mochitest/";
|
||||
var exampleOrg = "http://example.org/tests/toolkit/components/passwordmgr/test/mochitest/";
|
||||
var exampleCom = "https://example.com/tests/toolkit/components/passwordmgr/test/mochitest/";
|
||||
var exampleOrg = "https://example.org/tests/toolkit/components/passwordmgr/test/mochitest/";
|
||||
|
||||
var login1 = new nsLoginInfo();
|
||||
var login2 = new nsLoginInfo();
|
||||
runInParent(() => {
|
||||
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
|
||||
var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
||||
|
||||
login1.init("http://example.com", "http://example.com", null,
|
||||
"user1", "pass1", "uname", "pword");
|
||||
login2.init("http://example.org", "http://example.org", null,
|
||||
"user2", "pass2", "uname", "pword");
|
||||
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo);
|
||||
|
||||
pwmgr.addLogin(login1);
|
||||
pwmgr.addLogin(login2);
|
||||
var login1 = new nsLoginInfo();
|
||||
var login2 = new nsLoginInfo();
|
||||
|
||||
login1.init("https://example.com", "https://example.com", null,
|
||||
"user1", "pass1", "uname", "pword");
|
||||
login2.init("https://example.org", "https://example.org", null,
|
||||
"user2", "pass2", "uname", "pword");
|
||||
|
||||
pwmgr.addLogin(login1);
|
||||
pwmgr.addLogin(login2);
|
||||
});
|
||||
</script>
|
||||
|
||||
<p id="display"></p>
|
||||
@ -54,9 +59,9 @@ var iframe1 = document.getElementById("iframe1");
|
||||
var iframe2 = document.getElementById("iframe2");
|
||||
|
||||
add_task(async function test_1() {
|
||||
ok(pwcrypt.isLoggedIn, "should be initially logged in (no MP)");
|
||||
ok(isLoggedIn(), "should be initially logged in (no MP)");
|
||||
enableMasterPassword();
|
||||
ok(!pwcrypt.isLoggedIn, "should be logged out after setting MP");
|
||||
ok(!isLoggedIn(), "should be logged out after setting MP");
|
||||
|
||||
// Trigger a MP prompt via the API
|
||||
var state = {
|
||||
@ -80,14 +85,14 @@ add_task(async function test_1() {
|
||||
};
|
||||
var promptDone = handlePrompt(state, action);
|
||||
|
||||
var logins = pwmgr.getAllLogins();
|
||||
var logins = LoginManager.getAllLogins()
|
||||
|
||||
await promptDone;
|
||||
is(logins.length, 3, "expected number of logins");
|
||||
|
||||
ok(pwcrypt.isLoggedIn, "should be logged in after MP prompt");
|
||||
ok(isLoggedIn(), "should be logged in after MP prompt");
|
||||
logoutMasterPassword();
|
||||
ok(!pwcrypt.isLoggedIn, "should be logged out");
|
||||
ok(!isLoggedIn(), "should be logged out");
|
||||
});
|
||||
|
||||
add_task(async function test_2() {
|
||||
@ -115,12 +120,12 @@ add_task(async function test_2() {
|
||||
var failedAsExpected = false;
|
||||
var logins = null;
|
||||
try {
|
||||
logins = pwmgr.getAllLogins();
|
||||
logins = LoginManager.getAllLogins();
|
||||
} catch (e) { failedAsExpected = true; }
|
||||
await promptDone;
|
||||
ok(failedAsExpected, "getAllLogins should have thrown");
|
||||
is(logins, null, "shouldn't have gotten logins");
|
||||
ok(!pwcrypt.isLoggedIn, "should still be logged out");
|
||||
ok(!isLoggedIn(), "should still be logged out");
|
||||
});
|
||||
|
||||
add_task(async function test_3() {
|
||||
@ -145,9 +150,7 @@ add_task(async function test_3() {
|
||||
};
|
||||
var promptDone = handlePrompt(state, action);
|
||||
|
||||
var fillPromise = new Promise(resolve => {
|
||||
addEventListener("message", resolve);
|
||||
});
|
||||
var fillPromise = promiseFormsProcessed();
|
||||
|
||||
info("Load a single iframe to trigger a MP");
|
||||
iframe1.src = exampleCom + "subtst_master_pass.html";
|
||||
@ -163,9 +166,9 @@ add_task(async function test_3() {
|
||||
is(u.value, "user1", "checking expected user to have been filled in");
|
||||
is(p.value, "pass1", "checking expected pass to have been filled in");
|
||||
|
||||
ok(pwcrypt.isLoggedIn, "should be logged in");
|
||||
ok(isLoggedIn(), "should be logged in");
|
||||
logoutMasterPassword();
|
||||
ok(!pwcrypt.isLoggedIn, "should be logged out");
|
||||
ok(!isLoggedIn(), "should be logged out");
|
||||
});
|
||||
|
||||
add_task(async function test_4() {
|
||||
@ -200,7 +203,7 @@ add_task(async function test_4() {
|
||||
is(u.value, "", "checking expected empty user");
|
||||
is(p.value, "", "checking expected empty pass");
|
||||
|
||||
ok(!pwcrypt.isLoggedIn, "should be logged out");
|
||||
ok(!isLoggedIn(), "should be logged out");
|
||||
|
||||
// XXX check that there's 1 MP window open
|
||||
|
||||
@ -225,7 +228,7 @@ add_task(async function test_4() {
|
||||
let chromeURL = SimpleTest.getTestFileURL("chrome_timeout.js");
|
||||
let script = SpecialPowers.loadChromeScript(chromeURL);
|
||||
script.addMessageListener("ready", _ => {
|
||||
script.sendAsyncMessage("setTimeout", { delay: 500 });
|
||||
script.sendAsyncMessage("setTimeout", { delay: 500 });
|
||||
});
|
||||
script.addMessageListener("timeout", resolve);
|
||||
});
|
||||
@ -239,14 +242,12 @@ add_task(async function test_4() {
|
||||
is(u.value, "", "checking expected empty user");
|
||||
is(p.value, "", "checking expected empty pass");
|
||||
|
||||
// XXX check that there's 1 MP window open
|
||||
ok(!pwcrypt.isLoggedIn, "should be logged out");
|
||||
// XXX check that there's 1 MP window open
|
||||
ok(!isLoggedIn(), "should be logged out");
|
||||
|
||||
// Ok, now enter the MP. The MP prompt is already up.
|
||||
|
||||
var fillPromise = new Promise(resolve => {
|
||||
addEventListener("message", resolve);
|
||||
});
|
||||
var fillPromise = promiseFormsProcessed(2);
|
||||
|
||||
// fill existing MP dialog with MP.
|
||||
action = {
|
||||
@ -260,7 +261,7 @@ add_task(async function test_4() {
|
||||
// filling of iframe2's data. We notify observers synchronously, so
|
||||
// iframe2's observer will process iframe2 before iframe1 even finishes
|
||||
// processing the form.
|
||||
ok(pwcrypt.isLoggedIn, "should be logged in");
|
||||
ok(isLoggedIn(), "should be logged in");
|
||||
|
||||
// check contents of iframe1 fields
|
||||
u = SpecialPowers.wrap(iframe1).contentDocument.getElementById("userfield");
|
||||
@ -278,10 +279,7 @@ add_task(async function test_4() {
|
||||
// XXX do a test5ABC with clicking cancel?
|
||||
|
||||
SimpleTest.registerCleanupFunction(function finishTest() {
|
||||
disableMasterPassword();
|
||||
|
||||
pwmgr.removeLogin(login1);
|
||||
pwmgr.removeLogin(login2);
|
||||
disableMasterPassword();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
@ -200,28 +200,19 @@ function disableMasterPassword() {
|
||||
}
|
||||
|
||||
function setMasterPassword(enable) {
|
||||
var oldPW, newPW;
|
||||
if (enable) {
|
||||
oldPW = "";
|
||||
newPW = masterPassword;
|
||||
} else {
|
||||
oldPW = masterPassword;
|
||||
newPW = "";
|
||||
}
|
||||
// Set master password. Note that this logs in the user if no password was
|
||||
// set before. But after logging out the next invocation of pwmgr can
|
||||
// trigger a MP prompt.
|
||||
chromeScript.sendSyncMessage("setMasterPassword", { enable });
|
||||
}
|
||||
|
||||
var pk11db = Cc["@mozilla.org/security/pk11tokendb;1"].getService(Ci.nsIPK11TokenDB);
|
||||
var token = pk11db.getInternalKeyToken();
|
||||
info("MP change from " + oldPW + " to " + newPW);
|
||||
token.changePassword(oldPW, newPW);
|
||||
token.logoutSimple();
|
||||
function isLoggedIn() {
|
||||
return chromeScript.sendSyncMessage("isLoggedIn")[0][0];
|
||||
}
|
||||
|
||||
function logoutMasterPassword() {
|
||||
var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
|
||||
sdr.logoutAndTeardown();
|
||||
runInParent(function parent_logoutMasterPassword() {
|
||||
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
|
||||
var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
|
||||
sdr.logoutAndTeardown();
|
||||
});
|
||||
}
|
||||
|
||||
function dumpLogins(pwmgr) {
|
||||
@ -420,10 +411,37 @@ if (this.addMessageListener) {
|
||||
let rv = Services.logins[msg.methodName](...recreatedArgs);
|
||||
if (rv instanceof Ci.nsILoginInfo) {
|
||||
rv = LoginHelper.loginToVanillaObject(rv);
|
||||
} else if (Array.isArray(rv) && rv.length > 0 && rv[0] instanceof Ci.nsILoginInfo) {
|
||||
rv = rv.map(login => LoginHelper.loginToVanillaObject(login));
|
||||
}
|
||||
return rv;
|
||||
});
|
||||
|
||||
addMessageListener("isLoggedIn", () => {
|
||||
// This can't use the LoginManager proxy below since it's not a method.
|
||||
return Services.logins.isLoggedIn;
|
||||
});
|
||||
|
||||
addMessageListener("setMasterPassword", ({ enable }) => {
|
||||
let oldPW, newPW;
|
||||
if (enable) {
|
||||
oldPW = "";
|
||||
newPW = masterPassword;
|
||||
} else {
|
||||
oldPW = masterPassword;
|
||||
newPW = "";
|
||||
}
|
||||
// Set master password. Note that this logs in the user if no password was
|
||||
// set before. But after logging out the next invocation of pwmgr can
|
||||
// trigger a MP prompt.
|
||||
|
||||
var pk11db = Cc["@mozilla.org/security/pk11tokendb;1"].getService(Ci.nsIPK11TokenDB);
|
||||
var token = pk11db.getInternalKeyToken();
|
||||
dump("MP change from " + oldPW + " to " + newPW + "\n");
|
||||
token.changePassword(oldPW, newPW);
|
||||
token.logoutSimple();
|
||||
});
|
||||
|
||||
Services.mm.addMessageListener("RemoteLogins:onFormSubmit", function onFormSubmit(message) {
|
||||
sendAsyncMessage("formSubmissionProcessed", message.data, message.objects);
|
||||
});
|
||||
|
@ -1,7 +1,4 @@
|
||||
const Ci = SpecialPowers.Ci;
|
||||
const Cc = SpecialPowers.Cc;
|
||||
ok(Ci != null, "Access Ci");
|
||||
ok(Cc != null, "Access Cc");
|
||||
const { Cc, Ci } = SpecialPowers;
|
||||
|
||||
function hasTabModalPrompts() {
|
||||
var prefName = "prompts.tab_modal.enabled";
|
||||
|
Loading…
Reference in New Issue
Block a user