зеркало из https://github.com/mozilla/gecko-dev.git
Bug 444968 - password-only forms should prefer a password-only login when present. r=gavin
This commit is contained in:
Родитель
1ed150d07b
Коммит
6df99df2bf
|
@ -1109,34 +1109,31 @@ LoginManager.prototype = {
|
|||
if (usernameField && usernameField.value) {
|
||||
// If username was specified in the form, only fill in the
|
||||
// password if we find a matching login.
|
||||
|
||||
var username = usernameField.value.toLowerCase();
|
||||
|
||||
var matchingLogin;
|
||||
var found = logins.some(function(l) {
|
||||
matchingLogin = l;
|
||||
return (l.username.toLowerCase() == username);
|
||||
});
|
||||
if (found)
|
||||
selectedLogin = matchingLogin;
|
||||
let matchingLogins = logins.filter(function(l)
|
||||
l.username.toLowerCase() == username);
|
||||
if (matchingLogins.length)
|
||||
selectedLogin = matchingLogins[0];
|
||||
else
|
||||
this.log("Password not filled. None of the stored " +
|
||||
"logins match the username already present.");
|
||||
|
||||
} else if (usernameField && logins.length == 2) {
|
||||
// Special case, for sites which have a normal user+pass
|
||||
// login *and* a password-only login (eg, a PIN)...
|
||||
// When we have a username field and 1 of 2 available
|
||||
// logins is password-only, go ahead and prefill the
|
||||
// one with a username.
|
||||
if (!logins[0].username && logins[1].username)
|
||||
selectedLogin = logins[1];
|
||||
else if (!logins[1].username && logins[0].username)
|
||||
selectedLogin = logins[0];
|
||||
} else if (logins.length == 1) {
|
||||
selectedLogin = logins[0];
|
||||
} else {
|
||||
this.log("Multiple logins for form, so not filling any.");
|
||||
// We have multiple logins. Handle a special case here, for sites
|
||||
// which have a normal user+pass login *and* a password-only login
|
||||
// (eg, a PIN). Prefer the login that matches the type of the form
|
||||
// (user+pass or pass-only) when there's exactly one that matches.
|
||||
let matchingLogins;
|
||||
if (usernameField)
|
||||
matchingLogins = logins.filter(function(l) l.username);
|
||||
else
|
||||
matchingLogins = logins.filter(function(l) !l.username);
|
||||
if (matchingLogins.length == 1)
|
||||
selectedLogin = matchingLogins[0];
|
||||
else
|
||||
this.log("Multiple logins for form, so not filling any.");
|
||||
}
|
||||
|
||||
var didFillForm = false;
|
||||
|
|
|
@ -68,6 +68,7 @@ MOCHI_TESTS = \
|
|||
test_bug_360493_2.html \
|
||||
test_bug_391514.html \
|
||||
test_bug_427033.html \
|
||||
test_bug_444968.html \
|
||||
test_notifications.html \
|
||||
test_prompt.html \
|
||||
test_xhr.html \
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for Login Manager</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<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: 444968
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
<!-- first 3 forms have matching user+pass and pass-only logins -->
|
||||
|
||||
<!-- user+pass form. -->
|
||||
<form id="form1" action="http://bug444968-1">
|
||||
<input type="text" name="uname">
|
||||
<input type="password" name="pword">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<!-- password-only form. -->
|
||||
<form id="form2" action="http://bug444968-1">
|
||||
<input type="password" name="pword">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<!-- user+pass form, username prefilled -->
|
||||
<form id="form3" action="http://bug444968-1">
|
||||
<input type="text" name="uname" value="testuser1A">
|
||||
<input type="password" name="pword">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
|
||||
<!-- next 4 forms have matching user+pass (2x) and pass-only (1x) logins -->
|
||||
|
||||
<!-- user+pass form. -->
|
||||
<form id="form4" action="http://bug444968-2">
|
||||
<input type="text" name="uname">
|
||||
<input type="password" name="pword">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<!-- password-only form. -->
|
||||
<form id="form5" action="http://bug444968-2">
|
||||
<input type="password" name="pword">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<!-- user+pass form, username prefilled -->
|
||||
<form id="form6" action="http://bug444968-2">
|
||||
<input type="text" name="uname" value="testuser2A">
|
||||
<input type="password" name="pword">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
<!-- user+pass form, username prefilled -->
|
||||
<form id="form7" action="http://bug444968-2">
|
||||
<input type="text" name="uname" value="testuser2C">
|
||||
<input type="password" name="pword">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/* Test for Login Manager: 444968 (password-only forms should prefer a
|
||||
* password-only login when present )
|
||||
*/
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
pwmgr = Cc["@mozilla.org/login-manager;1"].
|
||||
getService(Ci.nsILoginManager);
|
||||
|
||||
login1A = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
||||
createInstance(Ci.nsILoginInfo);
|
||||
login1B = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
||||
createInstance(Ci.nsILoginInfo);
|
||||
login2A = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
||||
createInstance(Ci.nsILoginInfo);
|
||||
login2B = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
||||
createInstance(Ci.nsILoginInfo);
|
||||
login2C = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
||||
createInstance(Ci.nsILoginInfo);
|
||||
|
||||
login1A.init("http://localhost:8888", "http://bug444968-1", null,
|
||||
"testuser1A", "testpass1A", "", "");
|
||||
login1B.init("http://localhost:8888", "http://bug444968-1", null,
|
||||
"", "testpass1B", "", "");
|
||||
|
||||
login2A.init("http://localhost:8888", "http://bug444968-2", null,
|
||||
"testuser2A", "testpass2A", "", "");
|
||||
login2B.init("http://localhost:8888", "http://bug444968-2", null,
|
||||
"", "testpass2B", "", "");
|
||||
login2C.init("http://localhost:8888", "http://bug444968-2", null,
|
||||
"testuser2C", "testpass2C", "", "");
|
||||
|
||||
pwmgr.addLogin(login1A);
|
||||
pwmgr.addLogin(login1B);
|
||||
pwmgr.addLogin(login2A);
|
||||
pwmgr.addLogin(login2B);
|
||||
pwmgr.addLogin(login2C);
|
||||
|
||||
function startTest() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
checkForm(1, "testuser1A", "testpass1A");
|
||||
checkForm(2, "testpass1B");
|
||||
checkForm(3, "testuser1A", "testpass1A");
|
||||
|
||||
checkUnmodifiedForm(4); // 2 logins match
|
||||
checkForm(5, "testpass2B");
|
||||
checkForm(6, "testuser2A", "testpass2A");
|
||||
checkForm(7, "testuser2C", "testpass2C");
|
||||
|
||||
pwmgr.removeLogin(login1A);
|
||||
pwmgr.removeLogin(login1B);
|
||||
pwmgr.removeLogin(login2A);
|
||||
pwmgr.removeLogin(login2B);
|
||||
pwmgr.removeLogin(login2C);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
window.onload = startTest;
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче