Bug 1025703 - Ignore autocomplete=off for filling login forms.r=dolske

This commit is contained in:
Allison Naaktgeboren 2015-02-17 13:52:44 -08:00
parent 8ec0d4cb74
commit 48a51ce3e6
7 changed files with 13 additions and 383 deletions

View File

@ -250,7 +250,7 @@ var LoginManagerContent = {
let doc = form.ownerDocument;
let autofillForm = gAutofillForms && !PrivateBrowsingUtils.isContentWindowPrivate(doc.defaultView);
this._fillForm(form, autofillForm, false, false, false, loginsFound);
this._fillForm(form, autofillForm, false, false, loginsFound);
},
/*
@ -293,7 +293,7 @@ var LoginManagerContent = {
if (usernameField == acInputField && passwordField) {
this._asyncFindLogins(acForm, { showMasterPassword: false })
.then(({ form, loginsFound }) => {
this._fillForm(form, true, true, true, true, loginsFound);
this._fillForm(form, true, true, true, loginsFound);
})
.then(null, Cu.reportError);
} else {
@ -564,14 +564,13 @@ var LoginManagerContent = {
* [success, foundLogins].
*
* - autofillForm denotes if we should fill the form in automatically
* - ignoreAutocomplete denotes if we should ignore autocomplete=off
* attributes
* - userTriggered is an indication of whether this filling was triggered by
* the user
* - foundLogins is an array of nsILoginInfo for optimization
*/
_fillForm : function (form, autofillForm, ignoreAutocomplete,
clobberPassword, userTriggered, foundLogins) {
_fillForm : function (form, autofillForm, clobberPassword,
userTriggered, foundLogins) {
let ignoreAutocomplete = true;
// Heuristically determine what the user/pass fields are
// We do this before checking to see if logins are stored,
// so that the user isn't prompted for a master password

View File

@ -587,8 +587,7 @@ LoginManager.prototype = {
log("fillForm processing form[ id:", form.id, "]");
return LoginManagerContent._asyncFindLogins(form, { showMasterPassword: true })
.then(function({ form, loginsFound }) {
return LoginManagerContent._fillForm(form, true, true,
false, false, loginsFound)[0];
return LoginManagerContent._fillForm(form, true, false, false, loginsFound)[0];
});
},

View File

@ -40,7 +40,6 @@ skip-if = toolkit == 'android'
[test_case_differences.html]
skip-if = toolkit == 'android'
[test_basic_form_html5.html]
[test_basic_form_observer_autocomplete.html]
[test_basic_form_observer_autofillForms.html]
[test_basic_form_observer_foundLogins.html]
[test_basic_form_pwevent.html]
@ -49,7 +48,6 @@ skip-if = toolkit == 'android'
# This test doesn't pass because we can't ensure a cross-platform event that
# occurs between DOMContentLoaded and Pageload
skip-if = true
[test_bug_227640.html]
[test_bug_242956.html]
[test_bug_360493_1.html]
[test_bug_360493_2.html]

View File

@ -558,13 +558,13 @@ function* runTest() {
yield runNextTest();
/* Tests for single-user forms with autocomplete=off */
/* Tests for single-user forms for ignoring autocomplete=off */
/* test 100 */
// Turn our attention to form2
uname = $_(2, "uname");
pword = $_(2, "pword");
checkACForm("", "");
checkACForm("singleuser5", "singlepass5");
// Trigger autocomplete popup
restoreForm();
@ -585,8 +585,8 @@ function* runTest() {
// Turn our attention to form3
uname = $_(3, "uname");
pword = $_(3, "pword");
checkACForm("", "");
checkACForm("singleuser5", "singlepass5");
// Trigger autocomplete popup
restoreForm();
doKey("down");
@ -605,7 +605,7 @@ function* runTest() {
// Turn our attention to form4
uname = $_(4, "uname");
pword = $_(4, "pword");
checkACForm("", "");
checkACForm("singleuser5", "singlepass5");
// Trigger autocomplete popup
restoreForm();
@ -625,7 +625,7 @@ function* runTest() {
// Turn our attention to form5
uname = $_(5, "uname");
pword = $_(5, "pword");
checkACForm("", "");
checkACForm("singleuser5", "singlepass5");
// Trigger autocomplete popup
restoreForm();

View File

@ -1,103 +0,0 @@
<!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: simple form with autocomplete off and notifying observers & normal form
<script>
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
commonInit();
SimpleTest.waitForExplicitFinish();
</script>
<p id="display"></p>
<div id="content" style="display: block">
<form id="form1" action="formtest.js" autocomplete="off">
<p>This is form 1.</p>
<input type="text" name="uname">
<input type="password" name="pword">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<form id="form2" action="formtest.js">
<p>This is form 2.</p>
<input type="text" name="uname">
<input type="password" name="pword">
<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: simple form with autocomplete off and notifying observers & normal form **/
var TestObserver = {
receivedNotification1 : false,
receivedNotification2 : false,
data1 : "",
data2 : "",
observe : function (subject, topic, data) {
var pwmgr = Cc["@mozilla.org/login-manager;1"].
getService(Ci.nsILoginManager);
if (topic == "passwordmgr-found-form") {
if (subject.id == "form1") {
this.receivedNotification1 = true;
this.data1 = data;
} else if (subject.id == "form2") {
this.receivedNotification2 = true;
this.data2 = data;
}
// Now fill the form
pwmgr.fillForm(subject)
.then(startTest);
}
}
};
// Add the observer
SpecialPowers.addObserver(TestObserver, "passwordmgr-found-form", false);
function startTest(){
// Test that observer is notified & got correct data
is(TestObserver.receivedNotification1, true, "Checking observer was notified");
is(TestObserver.data1, "autocompleteOff", "Checking observer got correct data");
// Check that form1 was filled
is($_(1, "uname").value, "testuser", "Checking for filled username 1");
is($_(1, "pword").value, "testpass", "Checking for filled password 1");
// Test that observer wasn't notified & didn't get data
is(TestObserver.receivedNotification2, false, "Checking observer was not notified");
is(TestObserver.data2, "", "Checking observer didn't get data");
// Check that form2 was filled
is($_(2, "uname").value, "testuser", "Checking for filled username 2");
is($_(2, "pword").value, "testpass", "Checking for filled password 2");
// Remove the observer
try {
SpecialPowers.removeObserver(TestObserver, "passwordmgr-found-form");
} catch (e) {
ok(false, SpecialPowers.wrap(e));
}
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>

View File

@ -44,7 +44,7 @@ var TestObserver = {
};
// Initialize the object that stores the results of notifications.
for (var formID of ["form1", "form2", "form3", "form4", "form5"])
for (var formID of ["form1", "form2", "form3", "form5"])
TestObserver.results[formID] = { receivedNotification: false, data: null };
// Add the observer
@ -82,15 +82,6 @@ SpecialPowers.addObserver(TestObserver, "passwordmgr-found-logins", false);
<button type="reset"> Reset </button>
</form>
<form id="form4" action="formtest.js" autocomplete="off">
<p>This is form 4.</p>
<input type="text" name="uname">
<input type="password" name="pword">
<button type="submit">Submit</button>
<button type="reset"> Reset </button>
</form>
<form id="form5" action="http://www.example.com">
<p>This is form 5.</p>
<input type="text" name="uname">
@ -139,17 +130,6 @@ function startTest(){
is(TestObserver.results["form3"].data.get("foundLogins").length, 1, "Checking foundLogins contains one login");
is(TestObserver.results["form3"].data.get("selectedLogin"), null, "Checking selectedLogin is null");
// Test notification of a form that wasn't filled because autocomplete is off.
is(TestObserver.results["form4"].receivedNotification, true, "Checking observer was notified");
is(TestObserver.results["form4"].data.get("didntFillReason"), "autocompleteOff", "Checking didntFillReason is autocompleteOff");
is(SpecialPowers.unwrap(TestObserver.results["form4"].data.get("usernameField")), $_(4, "uname"), "Checking username field is correct");
is(SpecialPowers.unwrap(TestObserver.results["form4"].data.get("passwordField")), $_(4, "pword"), "Checking password field is correct");
is(TestObserver.results["form4"].data.get("foundLogins").constructor.name, "Array", "Checking foundLogins is array");
is(TestObserver.results["form4"].data.get("foundLogins").length, 1, "Checking foundLogins contains one login");
ok(TestObserver.results["form4"].data.get("selectedLogin").QueryInterface(Ci.nsILoginInfo), "Checking selectedLogin is nsILoginInfo");
ok(TestObserver.results["form4"].data.get("selectedLogin").equals(TestObserver.results["form4"].data.get("foundLogins")[0]),
"Checking selectedLogin is found login");
// Test notification of a form that wasn't filled because multiple logins
// are available for the form.
is(TestObserver.results["form5"].receivedNotification, true, "Checking observer was notified");

View File

@ -1,243 +0,0 @@
<!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>