Bug 1775902 - Fix intermittent failures for browser_autocomplete_import.js r=sgalich

This patch changes the following:
1. Use synthesizeKey instead of SynthesizeMouse
2. Use `waitForCondition` when testing the value of the test element
3. Call `promiseFocus` to ensure the window is focused before
   synthesizing key events

Differential Revision: https://phabricator.services.mozilla.com/D165126
This commit is contained in:
Dimi 2023-01-03 07:53:07 +00:00
parent 9f5a56591e
commit c88334fe16
2 changed files with 20 additions and 18 deletions

View file

@ -28,9 +28,6 @@ skip-if = !debug && os == "linux" && bits == 64 && os_version == "18.04" # Bug 1
[browser_autocomplete_generated_password_private_window.js]
[browser_autocomplete_import.js]
https_first_disabled = true
skip-if =
os == "mac" # Bug 1775902
os == "win" && !debug # Bug 1775902
[browser_autocomplete_insecure_warning.js]
[browser_autocomplete_primary_password.js]
[browser_autofill_hidden_document.js]

View file

@ -110,8 +110,10 @@ add_task(async function import_suggestion_wizard() {
"Wait for migration wizard to open"
);
// The modal window blocks execution, so avoid calling directly.
executeSoon(() => EventUtils.synthesizeMouseAtCenter(importableItem, {}));
executeSoon(() => {
EventUtils.synthesizeKey("KEY_ArrowDown");
EventUtils.synthesizeKey("KEY_Enter");
});
wizard = await wizardPromise;
Assert.ok(wizard, "Wizard opened");
@ -157,7 +159,9 @@ add_task(async function import_suggestion_learn_more() {
Services.urlFormatter.formatURLPref("app.support.baseURL") +
"password-import"
);
EventUtils.synthesizeMouseAtCenter(learnMoreItem, {});
await EventUtils.synthesizeKey("KEY_ArrowDown");
await EventUtils.synthesizeKey("KEY_ArrowDown");
await EventUtils.synthesizeKey("KEY_Enter");
supportTab = await supportTabPromise;
Assert.ok(supportTab, "Support tab opened");
@ -199,23 +203,24 @@ add_task(async function import_suggestion_migrate() {
() => gTestMigrator.migrate.callCount,
"Wait for direct migration attempt"
);
EventUtils.synthesizeMouseAtCenter(importableItem, {});
EventUtils.synthesizeKey("KEY_ArrowDown");
EventUtils.synthesizeKey("KEY_Enter");
const callCount = await migratePromise;
Assert.equal(callCount, 1, "Direct migrate used once");
const importedItem = await BrowserTestUtils.waitForCondition(
() => popup.querySelector(`[originaltype="loginWithOrigin"]`),
"Wait for imported login to show"
);
EventUtils.synthesizeMouseAtCenter(importedItem, {});
await SimpleTest.promiseFocus(browser);
EventUtils.synthesizeKey("KEY_ArrowDown");
EventUtils.synthesizeKey("KEY_Enter");
const username = await SpecialPowers.spawn(
browser,
[],
() => content.document.getElementById("form-basic-username").value
);
Assert.equal(username, "import", "username from import filled in");
await SpecialPowers.spawn(browser, [], async () => {
await ContentTaskUtils.waitForCondition(() => {
return (
"import" ==
content.document.getElementById("form-basic-username").value
);
}, "username from import filled in");
});
LoginTestUtils.clearData();
}