2008-07-12 21:42:30 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test for Login Manager</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
2008-07-12 21:42:30 -07:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="pwmgr_common.js"></script>
|
2008-10-12 20:05:11 -07:00
|
|
|
<script type="text/javascript" src="notification_common.js"></script>
|
2008-07-12 21:42:30 -07:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Login Manager test: notifications
|
|
|
|
<p id="display"></p>
|
|
|
|
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
<iframe id="iframe"></iframe>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Login Manager: notifications. **/
|
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
// Set testpath to the directory where we live. Used to load tests from
|
|
|
|
// alternate Mochitest servers (different hostnames, same content).
|
|
|
|
var testpath = document.location.pathname + "/../";
|
|
|
|
|
2008-07-12 21:42:30 -07:00
|
|
|
var subtests = [
|
|
|
|
"subtst_notifications_1.html", // 1
|
|
|
|
"subtst_notifications_1.html", // 2
|
|
|
|
"subtst_notifications_1.html", // 3
|
|
|
|
"subtst_notifications_1.html", // 4
|
|
|
|
"subtst_notifications_1.html", // 5
|
|
|
|
"subtst_notifications_1.html", // 6
|
|
|
|
"subtst_notifications_1.html", // 7
|
|
|
|
"subtst_notifications_1.html", // 8
|
|
|
|
"subtst_notifications_2.html", // 9
|
|
|
|
"subtst_notifications_3.html", // 10
|
|
|
|
"subtst_notifications_4.html", // 11
|
2008-07-13 00:04:30 -07:00
|
|
|
"subtst_notifications_5.html", // 12
|
|
|
|
"subtst_notifications_1.html", // 13
|
|
|
|
"subtst_notifications_6.html", // 14
|
|
|
|
"subtst_notifications_1.html", // 15
|
2008-10-12 20:05:11 -07:00
|
|
|
"subtst_notifications_6.html", // 16
|
|
|
|
"subtst_notifications_8.html", // 17
|
|
|
|
"subtst_notifications_8.html", // 18
|
|
|
|
"subtst_notifications_9.html", // 19
|
2008-10-30 23:28:39 -07:00
|
|
|
"subtst_notifications_10.html", // 20
|
|
|
|
"http://test1.example.org:80" + testpath + "subtst_notifications_1.html", // 21
|
|
|
|
"http://test1.example.org:80" + testpath + "subtst_notifications_7.html", // 22
|
|
|
|
"http://test1.example.org:80" + testpath + "subtst_notifications_6.html", // 23
|
2008-07-12 21:42:30 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
var ignoreLoad = false;
|
|
|
|
function handleLoad(aEvent) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
// ignore every other load event ... We get one for loading the subtest (which
|
|
|
|
// we want to ignore), and another when the subtest's form submits itself
|
|
|
|
// (which we want to handle, to start the next test).
|
|
|
|
ignoreLoad = !ignoreLoad;
|
|
|
|
if (ignoreLoad) {
|
|
|
|
ok(true, "Ignoring load of subtest #" + testNum);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(true, "Processing submission of subtest #" + testNum);
|
|
|
|
|
|
|
|
checkTest();
|
|
|
|
|
|
|
|
testNum++;
|
|
|
|
|
|
|
|
|
|
|
|
// Remove any notification bar that might be lingering from a failed test.
|
|
|
|
notifyBox.removeAllNotifications(true);
|
|
|
|
|
|
|
|
if (testNum <= subtests.length) {
|
|
|
|
ok(true, "Starting test #" + testNum);
|
|
|
|
iframe.src = subtests[testNum-1];
|
|
|
|
} else {
|
|
|
|
ok(true, "notification tests finished.");
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remember, Never for This Site, Not Now
|
|
|
|
function checkTest() {
|
2008-10-30 23:28:39 -07:00
|
|
|
var bar, notificationText, expectedText;
|
2008-07-12 21:42:30 -07:00
|
|
|
|
|
|
|
// The document generated from formsubmit.sjs contains the user/pass it
|
|
|
|
// received inside <span id="blah">value</span>
|
|
|
|
var gotUser = iframe.contentDocument.getElementById("user").textContent;
|
|
|
|
var gotPass = iframe.contentDocument.getElementById("pass").textContent;
|
|
|
|
|
|
|
|
|
|
|
|
switch(testNum) {
|
|
|
|
|
|
|
|
/* Basic Yes/No/Never tests... */
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-07-12 21:42:30 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
// Same subtest, this time click Never
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
|
|
|
is(true, pwmgr.getLoginSavingEnabled("http://localhost:8888"),
|
|
|
|
"Checking for login saving enabled");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNeverButton);
|
2008-07-12 21:42:30 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
// Same subtest, make sure Never took effect
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
is(false, pwmgr.getLoginSavingEnabled("http://localhost:8888"),
|
|
|
|
"Checking for login saving disabled");
|
|
|
|
// reenable login saving.
|
|
|
|
pwmgr.setLoginSavingEnabled("http://localhost:8888", true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
// Same subtest, this time click Remember
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kRememberButton);
|
2008-07-12 21:42:30 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
// Same subtest, make sure we didn't prompt for an existing login.
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
// remove that login
|
2008-07-13 00:04:30 -07:00
|
|
|
pwmgr.removeLogin(login1);
|
2008-07-12 21:42:30 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* signons.rememberSignons pref tests... */
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
// Same subtest, make sure we're getting the bar again.
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-07-12 21:42:30 -07:00
|
|
|
// Change prefs to no longer remember signons
|
|
|
|
prefs.setBoolPref("rememberSignons", false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
// Same subtest, make sure we're not prompting.
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
// Change prefs to remember signons again
|
|
|
|
prefs.setBoolPref("rememberSignons", true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
// Same subtest, make sure we're getting the bar again.
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-07-12 21:42:30 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* autocomplete=off tests... */
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
// Check for no notification bar when autocomplete=off present
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
// Check for no notification bar when autocomplete=off present
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
// Check for no notification bar when autocomplete=off present
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* no password field test... */
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
// Check for no notification bar when no password field present
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "null", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
2008-07-13 00:04:30 -07:00
|
|
|
|
|
|
|
// Add login for the next test.
|
|
|
|
pwmgr.addLogin(login2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
// Check for no notification bar when existing pw-only login matches form.
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
pwmgr.removeLogin(login2);
|
|
|
|
|
|
|
|
// Add login for the next test
|
|
|
|
pwmgr.addLogin(login1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
|
|
|
// Check for no notification bar when pw-only form matches existing login.
|
|
|
|
is(gotUser, "null", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(!bar, "checking for no notification bar");
|
|
|
|
pwmgr.removeLogin(login1);
|
|
|
|
|
|
|
|
// Add login for the next test
|
|
|
|
pwmgr.addLogin(login2B);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
// Check for notification bar when existing pw-only login doesn't match form.
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-07-13 00:04:30 -07:00
|
|
|
pwmgr.removeLogin(login2B);
|
|
|
|
|
|
|
|
// Add login for the next test
|
|
|
|
pwmgr.addLogin(login1B);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
// Check for notification bar when pw-only form doesn't match existing login.
|
|
|
|
is(gotUser, "null", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-07-13 00:04:30 -07:00
|
|
|
pwmgr.removeLogin(login1B);
|
2008-10-12 20:05:11 -07:00
|
|
|
|
|
|
|
// Add login for the next tests
|
|
|
|
pwmgr.addLogin(login1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 17:
|
|
|
|
// Check for change-password bar, u+p login on u+p form. (not changed)
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "pass2", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-change");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kDontChangeButton);
|
2008-10-12 20:05:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
// Check for change-password bar, u+p login on u+p form.
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "pass2", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-change");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kChangeButton);
|
2008-10-12 20:05:11 -07:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
login1.password = "pass2";
|
|
|
|
pwmgr.removeLogin(login1);
|
|
|
|
login1.password = "notifyp1";
|
|
|
|
|
|
|
|
// Add login for the next test
|
|
|
|
pwmgr.addLogin(login2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// ...can't change a u+p login on a p-only form...
|
|
|
|
|
|
|
|
case 19:
|
|
|
|
// Check for change-password bar, p-only login on u+p form.
|
|
|
|
// (needed a different subtest for this because the login created in
|
|
|
|
// test_0init was interfering)
|
|
|
|
is(gotUser, "", "Checking submitted username");
|
|
|
|
is(gotPass, "pass2", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-change");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kChangeButton);
|
2008-10-12 20:05:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 20:
|
|
|
|
// Check for change-password bar, p-only login on p-only form.
|
|
|
|
is(gotUser, "null", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-change");
|
|
|
|
ok(bar, "got notification bar");
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kChangeButton);
|
2008-10-12 20:05:11 -07:00
|
|
|
|
|
|
|
pwmgr.removeLogin(login2);
|
2008-07-12 21:42:30 -07:00
|
|
|
break;
|
|
|
|
|
2008-10-30 23:28:39 -07:00
|
|
|
case 21:
|
|
|
|
// Check text on a user+pass notification bar
|
|
|
|
is(gotUser, "notifyu1", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
|
|
|
// Check the text, which comes from the localized saveLoginText string.
|
|
|
|
notificationText = bar.getAttribute("label");
|
|
|
|
expectedText = /^Do you want .+ to remember the password for \"notifyu1\" on example.org\?$/;
|
|
|
|
ok(expectedText.test(notificationText), "Checking text: " + notificationText);
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-10-30 23:28:39 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 22:
|
|
|
|
// Check text on a user+pass notification bar, username is really long
|
|
|
|
is(gotUser, "nowisthetimeforallgoodmentocometotheaidoftheircountry", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
|
|
|
// Check the text, which comes from the localized saveLoginText string.
|
|
|
|
notificationText = bar.getAttribute("label");
|
|
|
|
expectedText = /^Do you want .+ to remember the password for \"nowisthetimeforallgoodmentocom[^e]\" on example.org\?$/;
|
|
|
|
ok(expectedText.test(notificationText), "Checking text: " + notificationText);
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-10-30 23:28:39 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 23:
|
|
|
|
// Check text on a pass-only notification bar
|
|
|
|
is(gotUser, "null", "Checking submitted username");
|
|
|
|
is(gotPass, "notifyp1", "Checking submitted password");
|
|
|
|
bar = getNotificationBar(notifyBox, "password-save");
|
|
|
|
ok(bar, "got notification bar");
|
|
|
|
// Check the text, which comes from the localized saveLoginTextNoUser string.
|
|
|
|
notificationText = bar.getAttribute("label");
|
|
|
|
expectedText = /^Do you want .+ to remember this password on example.org\?$/;
|
|
|
|
ok(expectedText.test(notificationText), "Checking text: " + notificationText);
|
2009-05-06 12:55:25 -07:00
|
|
|
clickNotificationButton(bar, kNotNowButton);
|
2008-10-30 23:28:39 -07:00
|
|
|
break;
|
|
|
|
|
2008-07-12 21:42:30 -07:00
|
|
|
default:
|
|
|
|
ok(false, "Unexpected call to checkTest for test #" + testNum);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// * existing login test, form has different password --> change password, no save prompt
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
ok(Ci != null, "Access Ci");
|
|
|
|
ok(Cc != null, "Access Cc");
|
|
|
|
|
|
|
|
var pwmgr = Cc["@mozilla.org/login-manager;1"].
|
|
|
|
getService(Ci.nsILoginManager);
|
|
|
|
ok(pwmgr != null, "Access pwmgr");
|
|
|
|
|
|
|
|
var prefs = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefService);
|
|
|
|
ok(prefs != null, "Access prefs");
|
|
|
|
prefs = prefs.getBranch("signon.");
|
|
|
|
ok(prefs != null, "Access pref branch");
|
|
|
|
|
2008-07-13 00:04:30 -07:00
|
|
|
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
|
|
|
|
Ci.nsILoginInfo, "init");
|
|
|
|
var login1 = new nsLoginInfo("http://localhost:8888", "http://localhost:8888", null,
|
|
|
|
"notifyu1", "notifyp1", "user", "pass");
|
|
|
|
var login2 = new nsLoginInfo("http://localhost:8888", "http://localhost:8888", null,
|
|
|
|
"", "notifyp1", "", "pass");
|
|
|
|
var login1B = new nsLoginInfo("http://localhost:8888", "http://localhost:8888", null,
|
|
|
|
"notifyu1B", "notifyp1B", "user", "pass");
|
|
|
|
var login2B = new nsLoginInfo("http://localhost:8888", "http://localhost:8888", null,
|
|
|
|
"", "notifyp1B", "", "pass");
|
|
|
|
|
2008-07-12 21:42:30 -07:00
|
|
|
var iframe = document.getElementById("iframe");
|
|
|
|
iframe.onload = handleLoad;
|
|
|
|
|
|
|
|
// The notification box (not *bar*) is a constant, per-tab container. So, we
|
|
|
|
// only need to fetch it once.
|
|
|
|
var notifyBox = getNotificationBox(window.top);
|
|
|
|
ok(notifyBox, "Got notification box");
|
|
|
|
|
|
|
|
// Remove any notification bars that might be left over from other tests.
|
|
|
|
notifyBox.removeAllNotifications(true);
|
|
|
|
|
|
|
|
var testNum = 1;
|
|
|
|
ok(true, "Starting test #" + testNum);
|
|
|
|
iframe.src = subtests[testNum-1];
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|