gecko/toolkit/components/passwordmgr/test/test_bug_227640.html

244 lines
8.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Login Manager</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: 227640
<script>
commonInit();
SimpleTest.waitForExplicitFinish();
var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"]
.getService(SpecialPowers.Ci.nsILoginManager);
</script>
<p id="display"></p>
<div id="content" style="display: none">
<!-- no autocomplete for password field -->
<form id="form1" onsubmit="return checkSubmit(1)" method="get">
<input type="text" name="uname" value="">
<input type="password" name="pword" value="" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for username field -->
<form id="form2" onsubmit="return checkSubmit(2);" method="get">
<input type="text" name="uname" value="" autocomplete=off>
<input type="password" name="pword" value="">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for username or password fields -->
<form id="form3" onsubmit="return checkSubmit(3);" method="get">
<input type="text" name="uname" value="" autocomplete=off>
<input type="password" name="pword" value="" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form -->
<form id="form4" onsubmit="return checkSubmit(4);" method="get" autocomplete=off>
<input type="text" name="uname" value="">
<input type="password" name="pword" value="">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form and password field -->
<form id="form5" onsubmit="return checkSubmit(5);" method="get">
<input type="text" name="uname" value="">
<input type="password" name="pword" value="" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form and username field -->
<form id="form6" onsubmit="return checkSubmit(6);" method="get">
<input type="text" name="uname" value="" autocomplete=off>
<input type="password" name="pword" value="">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form, userfield, and password field -->
<form id="form7" onsubmit="return checkSubmit(7);" method="get" autocomplete=off>
<input type="text" name="uname" value="" autocomplete=off>
<input type="password" name="pword" value="" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- ===== repeat, but with logins not previously stored ===== -->
<!-- no autocomplete for password field -->
<form id="form8" onsubmit="return checkSubmit(8);" method="get">
<input type="text" name="xxxuname" value="newuser">
<input type="password" name="xxxpword" value="newpass" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for username field -->
<form id="form9" onsubmit="return checkSubmit(9);" method="get">
<input type="text" name="xxxuname" value="newuser" autocomplete=off>
<input type="password" name="xxxpword" value="newpass">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for username or password fields -->
<form id="form10" onsubmit="return checkSubmit(10);" method="get">
<input type="text" name="xxxuname" value="newuser" autocomplete=off>
<input type="password" name="xxxpword" value="newpass" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form -->
<form id="form11" onsubmit="return checkSubmit(11);" method="get" autocomplete=off>
<input type="text" name="xxxuname" value="newuser">
<input type="password" name="xxxpword" value="newpass">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form and password field -->
<form id="form12" onsubmit="return checkSubmit(12);" method="get">
<input type="text" name="xxxuname" value="newuser">
<input type="password" name="xxxpword" value="newpass" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form and username field -->
<form id="form13" onsubmit="return checkSubmit(13);" method="get">
<input type="text" name="xxxuname" value="newuser" autocomplete=off>
<input type="password" name="xxxpword" value="newpass">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<!-- no autocomplete for entire form, userfield, and password field -->
<form id="form14" onsubmit="return checkSubmit(14);" method="get" autocomplete=off>
<input type="text" name="xxxuname" value="newuser" autocomplete=off>
<input type="password" name="xxxpword" value="newpass" autocomplete=off>
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: 227640 (password is saved even when the
password field has autocomplete="off") **/
// This test ensures that pwmgr does not save a username or password when
// autocomplete=off is present.
var numStartingLogins = 0;
var numSubmittedForms = 0;
function startTest() {
// Get current number of logins, so we can know if some accidently get
// added during the test.
numStartingLogins = countLogins();
ok(numStartingLogins > 0, "counting logins at start");
// Check first set of forms, which should not be filled by pwmgr.
for (var i = 1; i <= 7; i++) {
is($_(i, "uname").value, "", "Checking for unfilled username " + i);
is($_(i, "pword").value, "", "Checking for unfilled password " + i);
// Set the field values to that of an existing login
$_(i, "uname").value = "testuser";
$_(i, "pword").value = "testpass";
}
// Check second set of forms, which should have preset values (and are unknown to pwmgr).
for (var i = 8; i <= 14; i++) {
is($_(i, "xxxuname").value, "newuser", "Checking unmodified username " + i);
is($_(i, "xxxpword").value, "newpass", "Checking unmodified password " + i);
}
var button = getFormSubmitButton(1);
// submit the first form.
button.click();
}
// Called by each form's onsubmit handler.
function checkSubmit(formNum) {
numSubmittedForms++;
// End the test at the last form.
if (formNum == 14) {
is(numSubmittedForms, 14, "Ensuring all forms were submitted.");;
var numEndingLogins = countLogins();
ok(numEndingLogins > 0, "counting logins at end");
is(numStartingLogins, numEndingLogins, "counting logins at end");
SimpleTest.finish();
return false; // return false to cancel current form submission
}
var button = getFormSubmitButton(formNum + 1);
// submit the next form.
button.click();
return false; // return false to cancel current form submission
}
function getFormSubmitButton(formNum) {
var form = $("form" + formNum); // by id, not name
ok(form != null, "getting form " + formNum);
// we can't just call form.submit(), because that doesn't seem to
// invoke the form onsubmit handler.
var button = form.firstChild;
while (button && button.type != "submit") { button = button.nextSibling; }
ok(button != null, "getting form submit button");
return button;
}
// Counts the number of logins currently stored by password manager.
function countLogins() {
var logins = pwmgr.getAllLogins();
return logins.length;
}
window.addEventListener("runTests", startTest);
</script>
</pre>
</body>
</html>