--- a/toolkit/components/passwordmgr/test/mochitest/test_prompt.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_prompt.html
@@ -28,16 +28,31 @@ var tmplogin, login1, login2A, login2B,
var mozproxy, proxiedHost = "http://mochi.test:8888";
var proxyChannel;
var systemPrincipal = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal();
var iframe = document.getElementById("iframe");
// Force parent to not look for tab-modal prompts, as they're not used for auth prompts.
isTabModal = false;
+const Cc_promptFac= Cc["@mozilla.org/passwordmanager/authpromptfactory;1"];
+ok(Cc_promptFac != null, "Access Cc[@mozilla.org/passwordmanager/authpromptfactory;1]");
+
+const Ci_promptFac = Ci.nsIPromptFactory;
+ok(Ci_promptFac != null, "Access Ci.nsIPromptFactory");
+
+const promptFac = Cc_promptFac.getService(Ci_promptFac);
+ok(promptFac != null, "promptFac getService()");
+
+var prompter1 = promptFac.getPrompt(window, Ci.nsIAuthPrompt);
+var prompter2 = promptFac.getPrompt(window, Ci.nsIAuthPrompt2);
+
+const defaultTitle = "the title";
+const defaultMsg = "the message";
+
function initLogins(pi) {
observerService = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
observerService.addObserver(storageObserver, "passwordmgr-storage-changed", false);
pwmgr = Cc["@mozilla.org/login-manager;1"].
getService(Ci.nsILoginManager);
ioService = Cc["@mozilla.org/network/io-service;1"].
@@ -255,17 +270,17 @@ var storageObserver = SpecialPowers.wrap
} catch (e) {
ok(false, "OBSERVER FAILED: " + e);
}
}
});
startup();
-add_task(function* runTests() {
+add_task(function* setup() {
info("Waiting for startup to complete...");
yield startupComplete;
var authinfo = {
username : "",
password : "",
domain : "",
@@ -282,42 +297,30 @@ add_task(function* runTests() {
flags : Ci.nsIAuthInformation.AUTH_PROXY,
authenticationScheme : "basic",
realm : ""
};
var prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
- const Cc_promptFac= Cc["@mozilla.org/passwordmanager/authpromptfactory;1"];
- ok(Cc_promptFac != null, "Access Cc[@mozilla.org/passwordmanager/authpromptfactory;1]");
- const Ci_promptFac = Ci.nsIPromptFactory;
- ok(Ci_promptFac != null, "Access Ci.nsIPromptFactory");
-
- const promptFac = Cc_promptFac.getService(Ci_promptFac);
- ok(promptFac != null, "promptFac getService()");
-
- var prompter1 = promptFac.getPrompt(window, Ci.nsIAuthPrompt);
- var prompter2 = promptFac.getPrompt(window, Ci.nsIAuthPrompt2);
+ // popupNotifications (not *popup*) is a constant, per-tab container. So, we
+ // only need to fetch it once.
+ var popupNotifications = getPopupNotifications(window.top);
+ ok(popupNotifications, "Got popupNotifications");
+});
var uname = { value : null };
var pword = { value : null };
var result = { value : null };
var isOk;
- const defaultTitle = "the title";
- const defaultMsg = "the message";
- // popupNotifications (not *popup*) is a constant, per-tab container. So, we
- // only need to fetch it once.
- var popupNotifications = getPopupNotifications(window.top);
- ok(popupNotifications, "Got popupNotifications");
-
- info("===== test 1 =====");
+add_task(function* test_1() {
state = {
msg : "the message",
title : "the title",
textValue : "abc",
passValue : "",
iconClass : "question-icon",
titleHidden : true,
textHidden : false,
@@ -334,18 +337,19 @@ add_task(function* runTests() {
};
promptDone = handlePrompt(state, action);
isOk = prompter1.prompt(defaultTitle, defaultMsg, "http://example.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(result.value, "xyz", "Checking prompt() returned value");
+});
- info("===== test 2 =====");
+add_task(function* test_2() {
state = {
msg : "the message",
title : "the title",
textValue : "abc",
passValue : "",
iconClass : "question-icon",
titleHidden : true,
textHidden : false,
@@ -359,18 +363,19 @@ add_task(function* runTests() {
action = {
buttonClick : "cancel",
};
promptDone = handlePrompt(state, action);
isOk = prompter1.prompt(defaultTitle, defaultMsg, "http://example.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result);
yield promptDone;
ok(!isOk, "Checking dialog return value (cancel)");
+});
- info("===== test 10 =====");
+add_task(function* test_10() {
// Default password provided, existing logins are ignored.
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "inputpw",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -388,18 +393,19 @@ add_task(function* runTests() {
};
pword.value = "inputpw";
promptDone = handlePrompt(state, action);
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://example.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "secret", "Checking returned password");
+});
- info("===== test 11 =====");
+add_task(function* test_11() {
// Default password provided, existing logins are ignored.
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "inputpw",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -415,18 +421,19 @@ add_task(function* runTests() {
buttonClick : "cancel",
};
pword.value = "inputpw";
promptDone = handlePrompt(state, action);
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://example.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
yield promptDone;
ok(!isOk, "Checking dialog return value (cancel)");
+});
- info("===== test 12 =====");
+add_task(function* test_12() {
// No default password provided, realm does not match existing login.
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -444,26 +451,28 @@ add_task(function* runTests() {
};
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://nonexample.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "secret", "Checking returned password");
+});
- info("===== test 13 =====");
+add_task(function* test_13() {
// No default password provided, matching login is returned w/o prompting.
pword.value = null;
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://example.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "examplepass", "Checking returned password");
+});
- info("===== test 14 =====");
+add_task(function* test_14() {
// No default password provided, none of the logins from this host are
// password-only so the user is prompted.
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "",
iconClass : "authentication-icon question-icon",
@@ -482,60 +491,66 @@ add_task(function* runTests() {
};
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "secret", "Checking returned password");
+});
- info("===== test 15 =====");
+add_task(function* test_15() {
// No default password provided, matching login is returned w/o prompting.
pword.value = null;
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://user1name@example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "user1pass", "Checking returned password");
+});
- info("===== test 16 =====");
+add_task(function* test_16() {
// No default password provided, matching login is returned w/o prompting.
pword.value = null;
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://user2name@example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "user2pass", "Checking returned password");
+});
- info("===== test 17 =====");
+add_task(function* test_17() {
// No default password provided, matching login is returned w/o prompting.
pword.value = null;
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://user3%2Ename%40host@example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "user3pass", "Checking returned password");
+});
- info("===== test 18 =====");
+add_task(function* test_18() {
// No default password provided, matching login is returned w/o prompting.
pword.value = null;
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://100@beef@example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "user3pass", "Checking returned password");
+});
- info("===== test 19 =====");
+add_task(function* test_19() {
// No default password provided, matching login is returned w/o prompting.
pword.value = null;
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "http://100%25beef@example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "user3pass", "Checking returned password");
// XXX test saving a password with Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY
+});
- info("===== test 30 =====");
+add_task(function* test_30() {
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -553,18 +568,19 @@ add_task(function* runTests() {
};
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "example2.com:80 (somerealm)",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "fill2pass", "Checking returned password");
+});
- info("===== test 31 =====");
+add_task(function* test_31() {
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -582,18 +598,19 @@ add_task(function* runTests() {
};
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptPassword(defaultTitle, defaultMsg, "example2.com:80 (somerealm)",
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(pword.value, "fill2pass", "Checking returned password");
+});
- info("===== test 100 =====");
+add_task(function* test_100() {
state = {
msg : "the message",
title : "the title",
textValue : "inuser",
passValue : "inpass",
iconClass : "authentication-icon question-icon",
titleHidden : true,
textHidden : false,
@@ -613,18 +630,19 @@ add_task(function* runTests() {
pword.value = "inpass";
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://nonexample.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(uname.value, "outuser", "Checking returned username");
is(pword.value, "outpass", "Checking returned password");
+});
- info("===== test 101 =====");
+add_task(function* test_101() {
state = {
msg : "the message",
title : "the title",
textValue : "inuser",
passValue : "inpass",
iconClass : "authentication-icon question-icon",
titleHidden : true,
textHidden : false,
@@ -640,18 +658,19 @@ add_task(function* runTests() {
};
uname.value = "inuser";
pword.value = "inpass";
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://nonexample.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
yield promptDone;
ok(!isOk, "Checking dialog return value (cancel)");
+});
- info("===== test 102 =====");
+add_task(function* test_102() {
// test filling in existing password-only login
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "examplepass",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -670,18 +689,19 @@ add_task(function* runTests() {
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://example.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(uname.value, "", "Checking returned username");
is(pword.value, "examplepass", "Checking returned password");
+});
- info("===== test 103 =====");
+add_task(function* test_103() {
// test filling in existing login (undetermined from multiple selection)
// user2name/user2pass would also be valid to fill here.
state = {
msg : "the message",
title : "the title",
textValue : "user1name",
passValue : "user1pass",
iconClass : "authentication-icon question-icon",
@@ -701,18 +721,19 @@ add_task(function* runTests() {
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
ok(uname.value == "user1name" || uname.value == "user2name", "Checking returned username");
ok(pword.value == "user1pass" || uname.value == "user2pass", "Checking returned password");
+});
- info("===== test 104 =====");
+add_task(function* test_104() {
// test filling in existing login (user1 from multiple selection)
state = {
msg : "the message",
title : "the title",
textValue : "user1name",
passValue : "user1pass",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -731,18 +752,19 @@ add_task(function* runTests() {
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(uname.value, "user1name", "Checking returned username");
is(pword.value, "user1pass", "Checking returned password");
+});
- info("===== test 105 =====");
+add_task(function* test_105() {
// test filling in existing login (user2 from multiple selection)
state = {
msg : "the message",
title : "the title",
textValue : "user2name",
passValue : "user2pass",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -761,18 +783,19 @@ add_task(function* runTests() {
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(uname.value, "user2name", "Checking returned username");
is(pword.value, "user2pass", "Checking returned password");
+});
- info("===== test 106 =====");
+add_task(function* test_106() {
// test changing password
state = {
msg : "the message",
title : "the title",
textValue : "user2name",
passValue : "user2pass",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -792,18 +815,19 @@ add_task(function* runTests() {
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(uname.value, "user2name", "Checking returned username");
is(pword.value, "NEWuser2pass", "Checking returned password");
+});
- info("===== test 107 =====");
+add_task(function* test_107() {
// test changing password (back to original value)
state = {
msg : "the message",
title : "the title",
textValue : "user2name",
passValue : "NEWuser2pass",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -823,18 +847,19 @@ add_task(function* runTests() {
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "http://example2.com",
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(uname.value, "user2name", "Checking returned username");
is(pword.value, "user2pass", "Checking returned password");
+});
- info("===== test 120 =====");
+add_task(function* test_120() {
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -855,18 +880,19 @@ add_task(function* runTests() {
pword.value = null;
promptDone = handlePrompt(state, action);
isOk = prompter1.promptUsernameAndPassword(defaultTitle, defaultMsg, "example2.com:80 (somerealm)",
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
yield promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(uname.value, "fill2user", "Checking returned username");
is(pword.value, "fill2pass", "Checking returned password");
+});
- info("===== test 121 =====");
+add_task(function* test_121() {
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
state = {
msg : "the message",
title : "the title",
textValue : "",
passValue : "",
iconClass : "authentication-icon question-icon",
titleHidden : true,
@@ -908,17 +934,19 @@ add_task(function* runTests() {
null, // aLoadingNode
SpecialPowers.Services.
scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
Ci.nsIContentPolicy.TYPE_OTHER);
var level = Ci.nsIAuthPrompt2.LEVEL_NONE;
+});
+add_task(function* test_rest() {
info("===== test 500 =====");
state = {
msg : "http://example.com is requesting your username and password.\n\nThe site says: “some realm”",
title : "Authentication Required",
textValue : "inuser",
passValue : "inpass",
iconClass : "authentication-icon question-icon",
titleHidden : true,