Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android' OR os == 'android'
- Manifest: toolkit/components/passwordmgr/test/mochitest/mochitest.toml
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test includeOtherSubdomainsInLookup</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content"></div>
<pre id="test">
Test that logins with non-exact match origin appear in autocomplete dropdown.
The includeOtherSubdomainsInLookup feature offers autocomplete results for
subdomain related logins.
For this testcase, there exists two logins for this origin on different
subdomains (old.example.com and new.example.com) but with different
passwords, beneath one login for the parent domain (example.com). Both
logins should appear in the autocomplete popup.
<template id="form1-template">
<input type="text" name="uname">
<input type="password" name="pword">
</form>
</template>
<script class="testbody" type="text/javascript">
const formTemplate = document.getElementById("form1-template");
const domainname = location.hostname;
const loginInfos = [
[`https://${domainname}/`, `https://${domainname}/`, null, "example-user", "example-password", "uname", "pword"],
[`https://old.${domainname}/`, `https://old.${domainname}/`, null, "example-user", "example-password", "uname", "pword"],
[`https://new.${domainname}/`, `https://new.${domainname}/`, null, "example-user", "new-example-password", "uname", "pword"],
];
// calculates a date representation as used in the autocomplete menu to
// distinguish duplicate logins
function getDateString() {
const dateAndTimeFormatter = new Services.intl.DateTimeFormat(undefined, { dateStyle: "medium" });
return dateAndTimeFormatter.format(new Date());
}
add_setup(async () => {
listenForUnexpectedPopupShown();
});
add_named_task("not including https login when includeOtherSubdomainsInLookup is false", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
await setStoredLoginsDuringTask(
[`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
);
const form = setContentForTask(formTemplate);
form.uname.focus();
await noPopupByArrowDown();
ok(true, "no popup has been opened")
});
add_named_task("including https login when includeOtherSubdomainsInLookup is true", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
await setStoredLoginsDuringTask(
[`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
);
const form = setContentForTask(formTemplate);
form.uname.focus();
const autocompleteItems = await popupByArrowDown();
checkAutoCompleteResults(autocompleteItems, ["example-user-https"], window.location.host, "https login showed");
});
add_named_task("including http login when includeOtherSubdomainsInLookup is false", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
await setStoredLoginsDuringTask(
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
[`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
);
const form = setContentForTask(formTemplate);
form.uname.focus();
const autocompleteItems = await popupByArrowDown();
checkAutoCompleteResults(autocompleteItems, ["example-user-http"], window.location.host, "http login showed");
});
add_named_task("including http login when includeOtherSubdomainsInLookup is true", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
await setStoredLoginsDuringTask(
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
[`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
);
const form = setContentForTask(formTemplate);
form.uname.focus();
const autocompleteItems = await popupByArrowDown();
checkAutoCompleteResults(autocompleteItems, ["example-user-http"], window.location.host, "http login showed");
});
add_named_task("including https and http login when includeOtherSubdomainsInLookup is false", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
await setStoredLoginsDuringTask(
[`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
[`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
);
const form = setContentForTask(formTemplate);
form.uname.focus();
const autocompleteItems = await popupByArrowDown();
// checkAutoCompleteResults(autocompleteItems, ["example-user-https"], window.location.host, "https login showed");
checkAutoCompleteResults(autocompleteItems, ["example-user-http"], window.location.host, "https login showed");
});
add_named_task("including https and http login when includeOtherSubdomainsInLookup is true", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
await setStoredLoginsDuringTask(
[`https://${domainname}/`, `https://${domainname}/`, null, "example-user-https", "example-password", "uname", "pword"],
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
[`http://${domainname}/`, `https://${domainname}/`, null, "example-user-http", "example-password", "uname", "pword"],
);
const form = setContentForTask(formTemplate);
form.uname.focus();
const autocompleteItems = await popupByArrowDown();
// checkAutoCompleteResults(autocompleteItems, ["example-user-https"], window.location.host, "https login showed");
checkAutoCompleteResults(autocompleteItems, ["example-user-http", "example-user-https"], window.location.host, "http and https logins showed");
});
add_named_task("menu does not show login for different subdomain when includeOtherSubdomainsInLookup is false", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", false]);
await setStoredLoginsDuringTask(
...[
// These two logins should never be visible on https: versions of
// *.example.com since the login is for http: and an https: login exists
// for this username.
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
[`http://${domainname}/`, `https://${domainname}/`, null, "example-user", "example-password", "uname", "pword"],
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
[`http://old.${domainname}/`, `https://old.${domainname}/`, null, "example-user", "old-example-password", "uname", "pword"],
...loginInfos,
]
);
const form = setContentForTask(formTemplate);
form.uname.focus();
const autocompleteItems = await popupByArrowDown();
checkAutoCompleteResults(autocompleteItems, ["example-user"], window.location.host, "Only exact subdomain showed");
});
add_named_task("menu shows two logins with the same username for different subdomain", async () => {
await setStoredLoginsDuringTask(...loginInfos);
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
const form = setContentForTask(formTemplate);
// The logins are added "today" and since they are duplicates, the date that they were last
// changed will be appended.
const dateString = getDateString();
const username = `example-user (${dateString})`;
form.uname.focus();
const autocompleteItems = await popupByArrowDown();
checkAutoCompleteResults(autocompleteItems, [username, username], window.location.host, "Check all menuitems are displayed correctly.");
});
add_named_task("login with different subdomain is selectable", async () => {
await setPreferencesForTask(["signon.includeOtherSubdomainsInLookup", true]);
await setStoredLoginsDuringTask(...loginInfos);
const form = setContentForTask(formTemplate);
// consume initial autofill event
await formAutofillResult(form.id);
form.uname.focus();
// select first item
await popupByArrowDown();
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_Enter");
await formAutofillResult(form.id);
is(form.uname.value, "example-user", "correct username is set");
is(form.pword.value, "example-password", "password matches first login");
// select second item
await popupByArrowDown();
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_ArrowDown");
synthesizeKey("KEY_Enter");
await formAutofillResult(form.id);
is(form.uname.value, "example-user", "correct username is set");
is(form.pword.value, "new-example-password", "password matches second login");
});
</script>
</pre>
</body>
</html>