Bug 1135451 - fillForm() cleanup part A: remove unused return type, kill E10S unfriendly fillForm from nsILoginManager, kill passwordmgr-found-form notification, largely a backout of bug 439365. r=MattN

This commit is contained in:
Justin Dolske 2015-02-27 15:47:37 -08:00
parent 7271c124f5
commit 76313bd0ad
5 changed files with 11 additions and 199 deletions

View File

@ -573,15 +573,15 @@ var LoginManagerContent = {
/*
* _fillform
*
* Fill the form with the provided login information.
* The logins are returned so they can be reused for
* optimization. Success of action is also returned in format
* [success, foundLogins].
* Attempt to find the username and password fields in a form, and fill them
* in using the provided logins.
*
* - autofillForm denotes if we should fill the form in automatically
* - clobberPassword controls if an existing password value can be
* overwritten
* - userTriggered is an indication of whether this filling was triggered by
* the user
* - foundLogins is an array of nsILoginInfo
* - foundLogins is an array of nsILoginInfo that could be used for the form
*/
_fillForm : function (form, autofillForm, clobberPassword,
userTriggered, foundLogins) {
@ -613,7 +613,7 @@ var LoginManagerContent = {
if (foundLogins.length == 0) {
// We don't log() here since this is a very common case.
recordAutofillResult(AUTOFILL_RESULT.NO_SAVED_LOGINS);
return [false, foundLogins];
return;
}
// Heuristically determine what the user/pass fields are
@ -627,14 +627,14 @@ var LoginManagerContent = {
if (passwordField == null) {
log("not filling form, no password field found");
recordAutofillResult(AUTOFILL_RESULT.NO_PASSWORD_FIELD);
return [false, foundLogins];
return;
}
// If the password field is disabled or read-only, there's nothing to do.
if (passwordField.disabled || passwordField.readOnly) {
log("not filling form, password field disabled or read-only");
recordAutofillResult(AUTOFILL_RESULT.PASSWORD_DISABLED_READONLY);
return [false, foundLogins];
return;
}
// Discard logins which have username/password values that don't
@ -662,7 +662,7 @@ var LoginManagerContent = {
if (logins.length == 0) {
log("form not filled, none of the logins fit in the field");
recordAutofillResult(AUTOFILL_RESULT.NO_LOGINS_FIT);
return [false, foundLogins];
return;
}
// The reason we didn't end up filling the form, if any. We include
@ -683,7 +683,7 @@ var LoginManagerContent = {
passwordField, foundLogins, null);
log("form not filled, the password field was already filled");
recordAutofillResult(AUTOFILL_RESULT.EXISTING_PASSWORD);
return [false, foundLogins];
return;
}
// If the form has an autocomplete=off attribute in play, don't
@ -770,16 +770,10 @@ var LoginManagerContent = {
}
didFillForm = true;
} else if (selectedLogin && !autofillForm) {
// For when autofillForm is false, but we still have the information
// to fill a form, we notify observers.
didntFillReason = "noAutofillForms";
Services.obs.notifyObservers(form, "passwordmgr-found-form", didntFillReason);
log("autofillForms=false but form can be filled; notified observers");
} else if (selectedLogin && isFormDisabled) {
// For when autocomplete is off, but we still have the information
// to fill a form, we notify observers.
didntFillReason = "autocompleteOff";
Services.obs.notifyObservers(form, "passwordmgr-found-form", didntFillReason);
log("autocomplete=off but form can be filled; notified observers");
}
@ -807,8 +801,6 @@ var LoginManagerContent = {
}
recordAutofillResult(autofillResult);
}
return [didFillForm, foundLogins];
},

View File

@ -13,7 +13,7 @@ interface nsIDOMHTMLInputElement;
interface nsIDOMHTMLFormElement;
interface nsIPropertyBag;
[scriptable, uuid(f0c5ca21-db71-4b32-993e-ab63054cc6f5)]
[scriptable, uuid(38c7f6af-7df9-49c7-b558-2776b24e6cc1)]
interface nsILoginManager : nsISupports {
/**
* This promise is resolved when initialization is complete, and is rejected
@ -215,16 +215,6 @@ interface nsILoginManager : nsISupports {
in nsIDOMHTMLInputElement aElement,
in nsIFormAutoCompleteObserver aListener);
/**
* Fill a form with login information if we have it. This method will fill
* aForm regardless of the signon.autofillForms preference.
*
* @param aForm
* The form to fill
* @return Promise that is resolved with whether or not the form was filled.
*/
jsval fillForm(in nsIDOMHTMLFormElement aForm);
/**
* Search for logins in the login manager. An array is always returned;
* if there are no logins the array is empty.

View File

@ -31,7 +31,6 @@ support-files =
[test_basic_form_0pw.html]
[test_basic_form_1pw.html]
[test_basic_form_1pw_2.html]
[test_basic_form_2.html]
[test_basic_form_2pw_1.html]
[test_basic_form_2pw_2.html]
[test_basic_form_3pw_1.html]
@ -40,7 +39,6 @@ skip-if = toolkit == 'android'
[test_case_differences.html]
skip-if = toolkit == 'android'
[test_basic_form_html5.html]
[test_basic_form_observer_autofillForms.html]
[test_basic_form_observer_foundLogins.html]
[test_basic_form_pwevent.html]
[test_basic_form_pwonly.html]

View File

@ -1,64 +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 fill with autofillForms disabled
<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: block">
<form id="form1" action="formtest.js">
<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>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: simple form fill with autofillForms disabled **/
function startTest(){
// Ensure the form is empty at start
is($_(1, "uname").value, "", "Checking for blank username");
is($_(1, "pword").value, "", "Checking for blank password");
// Call the public method, check return value
pwmgr.fillForm(document.getElementById("form1"))
.then(function(result) {
is(result, true, "Checking return value of fillForm");
// Check that the form was filled
is($_(1, "uname").value, "testuser", "Checking for filled username");
is($_(1, "pword").value, "testpass", "Checking for filled password");
SimpleTest.finish();
});
}
// Assume that the pref starts out true, so set to false
SpecialPowers.pushPrefEnv({"set":[["signon.autofillForms", false]]}, setup);
function setup() {
window.addEventListener("runTests", startTest);
}
</script>
</pre>
</body>
</html>

View File

@ -1,104 +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 autofillForms disabled and notifying observers
<script>
commonInit(true);
SimpleTest.waitForExplicitFinish();
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
var TestObserver;
// Assume that the pref starts out true, so set to false
SpecialPowers.pushPrefEnv({"set":[["signon.autofillForms", false]]}, function() {
TestObserver = {
receivedNotificationFoundForm : false,
receivedNotificationFoundLogins : false,
dataFoundForm : "",
dataFoundLogins : null,
observe : function (subject, topic, data) {
var pwmgr = Cc["@mozilla.org/login-manager;1"].
getService(Ci.nsILoginManager);
if (topic == "passwordmgr-found-form") {
info("got passwordmgr-found-form");
this.receivedNotificationFoundForm = true;
this.dataFoundForm = data;
// Now fill the form
pwmgr.fillForm(subject)
.then(window.startTest)
.then(null, function(e) { alert(e); });
} else if (topic == "passwordmgr-found-logins") {
info("got passwordmgr-found-logins");
// We only care about the first notification (the second comes from our
// own call to pwmgr.fillForm.
if (this.receivedNotificationFoundLogins)
return;
this.receivedNotificationFoundLogins = true;
this.dataFoundLogins = subject.QueryInterface(Ci.nsIPropertyBag2);
}
}
};
// Add the observer
SpecialPowers.addObserver(TestObserver, "passwordmgr-found-form", false);
SpecialPowers.addObserver(TestObserver, "passwordmgr-found-logins", false);
});
</script>
<p id="display"></p>
<div id="content" style="display: block">
<form id="form1" action="formtest.js">
<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>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: simple form with autofillForms disabled and notifying observers **/
function startTest() {
// Test that found-form observer is notified & got correct data
is(TestObserver.receivedNotificationFoundForm, true, "Checking found-form observer was notified");
is(TestObserver.dataFoundForm, "noAutofillForms", "Checking found-form observer got correct data");
// Check that form1 was filled
is($_(1, "uname").value, "testuser", "Checking for filled username");
is($_(1, "pword").value, "testpass", "Checking for filled password");
// Test that found-logins observer is notified & got correct data
is(TestObserver.receivedNotificationFoundLogins, true, "Checking found-logins observer was notified");
is(TestObserver.dataFoundLogins.get("didntFillReason"), "noAutofillForms", "Checking didntFillReason is noAutofillForms");
is(SpecialPowers.unwrap(TestObserver.dataFoundLogins.get("usernameField")), $_(1, "uname"), "Checking username field is correct");
is(SpecialPowers.unwrap(TestObserver.dataFoundLogins.get("passwordField")), $_(1, "pword"), "Checking password field is correct");
is(TestObserver.dataFoundLogins.get("foundLogins").constructor.name, "Array", "Checking foundLogins is array");
is(TestObserver.dataFoundLogins.get("foundLogins").length, 1, "Checking foundLogins contains one login");
ok(TestObserver.dataFoundLogins.get("selectedLogin").QueryInterface(Ci.nsILoginInfo), "Checking selectedLogin is nsILoginInfo");
ok(TestObserver.dataFoundLogins.get("selectedLogin").equals(TestObserver.dataFoundLogins.get("foundLogins")[0]),
"Checking selectedLogin is found login");
// Remove the observer
SpecialPowers.removeObserver(TestObserver, "passwordmgr-found-form");
SpecialPowers.removeObserver(TestObserver, "passwordmgr-found-logins");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>