Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

"use strict";
const TEST_ORIGIN = "https://example.com";
const BASIC_FORM_PAGE_PATH = DIRECTORY_PATH + "form_basic.html";
function loginList() {
return [
LoginTestUtils.testData.formLogin({
origin: "https://example.com",
formActionOrigin: "https://example.com",
username: "username",
password: "password",
}),
LoginTestUtils.testData.formLogin({
origin: "https://example.com",
formActionOrigin: "https://example.com",
username: "username2",
password: "password2",
}),
];
}
/**
* Initialize logins and set prefs needed for the test.
*/
add_task(async function test_initialize() {
Services.prefs.setBoolPref("signon.showAutoCompleteFooter", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("signon.showAutoCompleteFooter");
});
await Services.logins.addLogins(loginList());
});
add_task(async function test_autocomplete_footer_onclick() {
let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH;
await BrowserTestUtils.withNewTab(
{
gBrowser,
url,
},
async function footer_onclick(browser) {
let popup = document.getElementById("PopupAutoComplete");
Assert.ok(popup, "Got popup");
await openACPopup(popup, browser, "#form-basic-username");
let footer = popup.querySelector(`[originaltype="loginsFooter"]`);
Assert.ok(footer, "Got footer richlistitem");
// Wait for the layout to stabilize by waiting for possible reflow;
// otherwise, the synthesized mouse event might not be dispatched
// correctly.
await new Promise(requestAnimationFrame);
await TestUtils.waitForCondition(() => {
return !EventUtils.isHidden(footer);
}, "Waiting for footer to become visible");
let openingFunc = () => EventUtils.synthesizeMouseAtCenter(footer, {});
let passwordManager = await openPasswordManager(openingFunc, false);
info("Password Manager was opened");
Assert.ok(
!passwordManager.filterValue,
"Search string should not be set to filter logins"
);
// open_management
await LoginTestUtils.telemetry.waitForEventCount(1);
// Check event telemetry recorded when opening management UI
TelemetryTestUtils.assertEvents(
[["pwmgr", "open_management", "autocomplete"]],
{ category: "pwmgr", method: "open_management" },
{ clear: true, process: "content" }
);
await passwordManager.close();
await closePopup(popup);
}
);
});
add_task(async function test_autocomplete_footer_keydown() {
let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH;
await BrowserTestUtils.withNewTab(
{
gBrowser,
url,
},
async function footer_enter_keydown(browser) {
let popup = document.getElementById("PopupAutoComplete");
Assert.ok(popup, "Got popup");
await openACPopup(popup, browser, "#form-basic-username");
let footer = popup.querySelector(`[originaltype="loginsFooter"]`);
Assert.ok(footer, "Got footer richlistitem");
await TestUtils.waitForCondition(() => {
return !EventUtils.isHidden(footer);
}, "Waiting for footer to become visible");
await EventUtils.synthesizeKey("KEY_ArrowDown");
await EventUtils.synthesizeKey("KEY_ArrowDown");
await EventUtils.synthesizeKey("KEY_ArrowDown");
let openingFunc = () => EventUtils.synthesizeKey("KEY_Enter");
let passwordManager = await openPasswordManager(openingFunc, false);
info("Login dialog was opened");
Assert.ok(
!passwordManager.filterValue,
"Search string should not be set to filter logins"
);
// Check event telemetry recorded when opening management UI
TelemetryTestUtils.assertEvents(
[["pwmgr", "open_management", "autocomplete"]],
{ category: "pwmgr", method: "open_management" },
{ clear: true, process: "content" }
);
await passwordManager.close();
await closePopup(popup);
}
);
});
add_task(async function test_show_logins_recorded_once_per_open() {
Services.fog.testResetFOG();
let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH;
await BrowserTestUtils.withNewTab(
{ gBrowser, url },
async function (browser) {
let popup = document.getElementById("PopupAutoComplete");
await openACPopup(popup, browser, "#form-basic-username");
// Typing narrows the results while the popup stays open. The parent-side
// matchCount changing is the barrier that the redraw was processed.
let initialCount = popup.view.matchCount;
await BrowserTestUtils.synthesizeKey("u", {}, browser);
await BrowserTestUtils.synthesizeKey("x", {}, browser);
await TestUtils.waitForCondition(
() => popup.view.matchCount != initialCount,
"waiting for the popup to redraw with the narrowed results"
);
await closePopup(popup);
await SpecialPowers.spawn(browser, [], () => {
const field = content.document.querySelector("#form-basic-username");
field.value = "";
field.blur();
});
await openACPopup(popup, browser, "#form-basic-username");
await closePopup(popup);
}
);
await Services.fog.testFlushAllChildren();
const events = Glean.formAutocomplete.showLogins.testGetValue() ?? [];
Assert.equal(events.length, 1, "one event recorded when the popup opened");
Assert.greaterOrEqual(
Number(events[0].extra.value),
0,
"the event carries the time until the popup was shown"
);
});