Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android' OR os == 'android' OR http3 OR http2
- Manifest: toolkit/components/passwordmgr/test/mochitest/mochitest.toml
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test autofill on an HTTPS page using upgraded HTTP logins</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script>
const MISSING_ACTION_PATH = TESTS_DIR + "mochitest/form_basic.html";
const CROSS_ORIGIN_SECURE_PATH = TESTS_DIR + "mochitest/form_cross_origin_secure_action.html";
const chromeScript = runChecksAfterCommonInit(false);
let nsLoginInfo = SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
SpecialPowers.Ci.nsILoginInfo,
"init");
</script>
<p id="display"></p>
<!-- we presumably can't hide the content for this test. -->
<div id="content">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
let win = window.open("about:blank");
SimpleTest.registerCleanupFunction(() => win.close());
async function prepareLoginsAndProcessForm(url, logins = []) {
await LoginManager.removeAllUserFacingLogins();
let dates = Date.now();
for (let login of logins) {
SpecialPowers.do_QueryInterface(login, SpecialPowers.Ci.nsILoginMetaInfo);
// Force all dates to be the same so they don't affect things like deduping.
login.timeCreated = login.timePasswordChanged = login.timeLastUsed = dates;
await LoginManager.addLoginAsync(login);
}
let processedPromise = promiseFormsProcessed();
win.location = url;
await processedPromise;
}
add_setup(async () => {
await SpecialPowers.pushPrefEnv({"set": [
["signon.schemeUpgrades", true],
["signon.includeOtherSubdomainsInLookup", true],
]});
});
add_task(async function test_simpleNoDupesNoAction() {
"name2", "pass2", "uname", "pword"),
]);
await checkLoginFormInFrame(win,
"form-basic-username", "name2",
"form-basic-password", "pass2");
});
add_task(async function test_simpleNoDupesUpgradeOriginAndAction() {
"name2", "pass2", "uname", "pword"),
]);
await checkLoginFormInFrame(win, "form-basic-username", "name2",
"form-basic-password", "pass2");
});
add_task(async function test_simpleNoDupesUpgradeOriginOnly() {
"name2", "pass2", "uname", "pword"),
]);
await checkLoginFormInFrame(win, "form-basic-username", "name2",
"form-basic-password", "pass2");
});
add_task(async function test_simpleNoDupesUpgradeActionOnly() {
"name2", "pass2", "uname", "pword"),
]);
await checkLoginFormInFrame(win, "form-basic-username", "name2",
"form-basic-password", "pass2");
});
add_task(async function test_dedupe() {
"name1", "passHTTPStoHTTPS", "uname", "pword"),
"name1", "passHTTPtoHTTP", "uname", "pword"),
"name1", "passHTTPtoHTTPS", "uname", "pword"),
"name1", "passHTTPStoHTTP", "uname", "pword"),
]);
await checkLoginFormInFrame(win, "form-basic-username", "name1",
"form-basic-password", "passHTTPStoHTTPS");
});
add_task(async function test_dedupe_subdomain() {
// subdomain match (should be autofilled)
"name1", "pass1");
const loginToFillGUID = "subdomain-match"
// Assign a GUID to this login so we can ensure this is the login that gets
// filled later.
loginToFill.QueryInterface(SpecialPowers.Ci.nsILoginMetaInfo).guid = loginToFillGUID;
// All logins have the same username and password:
// https: (scheme match)
"name1", "pass1"),
loginToFill,
// formActionOrigin match
"name1", "pass1"),
]);
await checkLoginFormInFrame(win, "form-basic-username", "name1",
"form-basic-password", "pass1");
let filledGUID = await SpecialPowers.spawn(win, [], function getFilledGUID() {
let LMC = this.content.windowGlobalChild.getActor("LoginManager");
let doc = this.content.document;
let form = doc.getElementById("form-basic");
let { login: filledLogin } = LMC.stateForDocument(doc).fillsByRootElement.get(form);
return filledLogin && filledLogin.guid;
});
is(filledGUID, loginToFillGUID, "Check the correct login was filled");
});
</script>
</pre>
</body>
</html>