Commit 2d87cac7 authored by Dimi's avatar Dimi
Browse files

Bug 1763080 - Do not use arbitary timeout in browser_remoteiframe.js r=sgalich,tgiles

This patch does the following:
1. Use `focusUpdateSubmitForm` utility function
2. Use `waitForAutofill` utility function instead of using arbitary
   timeout to wait for autofill result
3. Use `openPopupForSubframe` utility function instead of only using
   `synthesizeKey`. This ensures the next key event is triggered after
   the popup is opened.
4. Add "autofill-clear-button" to `runAndWaitForAutocompletePopupOpen`
   so "Clear Autofill Form" popup is recognized by the utility function.

Differential Revision: https://phabricator.services.mozilla.com/D144878
parent 24cf77db
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ add_task(async function test_first_time_save() {
  await BrowserTestUtils.withNewTab({ gBrowser, url: FORM_URL }, async function(
    browser
  ) {
    let promiseShown = promiseNotificationShown();
    let onPopupShown = waitForPopupShown();
    let tabPromise = BrowserTestUtils.waitForNewTab(
      gBrowser,
      "about:preferences#privacy"
@@ -31,7 +31,7 @@ add_task(async function test_first_time_save() {
      },
    });

    await promiseShown;
    await onPopupShown;
    let cb = getDoorhangerCheckbox();
    ok(cb.hidden, "Sync checkbox should be hidden");
    // Open the panel via main button
@@ -100,7 +100,7 @@ add_task(async function test_first_time_save_with_sync_account() {
  await BrowserTestUtils.withNewTab({ gBrowser, url: FORM_URL }, async function(
    browser
  ) {
    let promiseShown = promiseNotificationShown();
    let onPopupShown = waitForPopupShown();
    let tabPromise = BrowserTestUtils.waitForNewTab(
      gBrowser,
      "about:preferences#privacy-address-autofill"
@@ -114,7 +114,7 @@ add_task(async function test_first_time_save_with_sync_account() {
      },
    });

    await promiseShown;
    await onPopupShown;
    let cb = getDoorhangerCheckbox();
    ok(!cb.hidden, "Sync checkbox should be visible");

+30 −31
Original line number Diff line number Diff line
/* eslint-disable mozilla/no-arbitrary-setTimeout */
"use strict";

const IFRAME_URL_PATH = BASE_URL + "autocomplete_iframe.html";
@@ -44,34 +43,32 @@ add_task(async function test_iframe_autocomplete() {
  await expectWarningText(browser, "Also autofills organization, email");
  EventUtils.synthesizeKey("VK_RETURN", {});

  let promiseShown = promiseNotificationShown();

  await new Promise(resolve => setTimeout(resolve, 1000));

  let loadPromise = BrowserTestUtils.browserLoaded(browser, true);
  let onLoaded = BrowserTestUtils.browserLoaded(browser, true);
  await SpecialPowers.spawn(iframeBC, [], async function() {
    Assert.equal(
      content.document.getElementById("street-address").value,
      "32 Vassar Street MIT Room 32-G524"
    await ContentTaskUtils.waitForCondition(() => {
      return (
        content.document.getElementById("street-address").value ==
          "32 Vassar Street MIT Room 32-G524" &&
        content.document.getElementById("country").value == "US" &&
        content.document.getElementById("organization").value ==
          "World Wide Web Consortium"
      );
    Assert.equal(content.document.getElementById("country").value, "US");

    let org = content.document.getElementById("organization");
    Assert.equal(org.value, "World Wide Web Consortium");

    // Now, modify the organization.
    org.setUserInput("Example Inc.");

    await new Promise(resolve => content.setTimeout(resolve, 1000));
    content.document.querySelector("input[type=submit]").click();
    });
  });

  await loadPromise;
  await promiseShown;
  let onPopupShown = waitForPopupShown();
  await focusUpdateSubmitForm(iframeBC, {
    focusSelector: "#organization",
    newValues: {
      "#organization": "Example Inc.",
    },
  });
  await onPopupShown;
  await onLoaded;

  let onChanged = TestUtils.topicObserved("formautofill-storage-changed");
  let onUpdated = waitForStorageChangedEvents("update");
  await clickDoorhangerButton(MAIN_BUTTON);
  await onChanged;
  await onUpdated;

  // Check that the organization was updated properly.
  let addresses = await getAddresses();
@@ -87,19 +84,21 @@ add_task(async function test_iframe_autocomplete() {
  await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, iframeBC);
  EventUtils.synthesizeKey("VK_RETURN", {});

  await new Promise(resolve => setTimeout(resolve, 1000));
  await waitForAutofill(iframeBC, "#organization", "Example Inc.");

  // Open the dropdown and select the Clear Form item.
  await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, iframeBC);
  await openPopupForSubframe(browser, iframeBC, "#street-address");
  await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, iframeBC);
  EventUtils.synthesizeKey("VK_RETURN", {});

  await new Promise(resolve => setTimeout(resolve, 1000));

  await SpecialPowers.spawn(iframeBC, [], async function() {
    Assert.equal(content.document.getElementById("street-address").value, "");
    Assert.equal(content.document.getElementById("country").value, "");
    Assert.equal(content.document.getElementById("organization").value, "");
    await ContentTaskUtils.waitForCondition(() => {
      return (
        content.document.getElementById("street-address").value == "" &&
        content.document.getElementById("country").value == "" &&
        content.document.getElementById("organization").value == ""
      );
    });
  });

  await BrowserTestUtils.removeTab(tab);
+10 −10
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ add_task(async function test_update_address() {
  await BrowserTestUtils.withNewTab({ gBrowser, url: FORM_URL }, async function(
    browser
  ) {
    let promiseShown = promiseNotificationShown();
    let onPopupShown = waitForPopupShown();
    await openPopupOn(browser, "form #organization");
    await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
    await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
@@ -25,7 +25,7 @@ add_task(async function test_update_address() {
      form.querySelector("input[type=submit]").click();
    });

    await promiseShown;
    await onPopupShown;
    await clickDoorhangerButton(MAIN_BUTTON);
  });

@@ -41,7 +41,7 @@ add_task(async function test_create_new_address() {
  await BrowserTestUtils.withNewTab({ gBrowser, url: FORM_URL }, async function(
    browser
  ) {
    let promiseShown = promiseNotificationShown();
    let onPopupShown = waitForPopupShown();
    await openPopupOn(browser, "form #tel");
    await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
    await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
@@ -57,7 +57,7 @@ add_task(async function test_create_new_address() {
      form.querySelector("input[type=submit]").click();
    });

    await promiseShown;
    await onPopupShown;
    await clickDoorhangerButton(SECONDARY_BUTTON);
  });

@@ -73,7 +73,7 @@ add_task(async function test_create_new_address_merge() {
  await BrowserTestUtils.withNewTab({ gBrowser, url: FORM_URL }, async function(
    browser
  ) {
    let promiseShown = promiseNotificationShown();
    let onPopupShown = waitForPopupShown();
    await openPopupOn(browser, "form #tel");
    await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
    await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
@@ -89,7 +89,7 @@ add_task(async function test_create_new_address_merge() {
      form.querySelector("input[type=submit]").click();
    });

    await promiseShown;
    await onPopupShown;
    await clickDoorhangerButton(SECONDARY_BUTTON);
  });

@@ -104,7 +104,7 @@ add_task(async function test_submit_untouched_fields() {
  await BrowserTestUtils.withNewTab({ gBrowser, url: FORM_URL }, async function(
    browser
  ) {
    let promiseShown = promiseNotificationShown();
    let onPopupShown = waitForPopupShown();
    await openPopupOn(browser, "form #organization");
    info("before down");
    await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
@@ -129,7 +129,7 @@ add_task(async function test_submit_untouched_fields() {
      info("after submit");
    });

    await promiseShown;
    await onPopupShown;
    await clickDoorhangerButton(MAIN_BUTTON);
  });

@@ -145,7 +145,7 @@ add_task(async function test_submit_reduced_fields() {

  let url = BASE_URL + "autocomplete_simple_basic.html";
  await BrowserTestUtils.withNewTab({ gBrowser, url }, async function(browser) {
    let promiseShown = promiseNotificationShown();
    let onPopupShown = waitForPopupShown();
    await openPopupOn(browser, "form#simple input[name=tel]");
    await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
    await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
@@ -161,7 +161,7 @@ add_task(async function test_submit_reduced_fields() {
      form.querySelector("input[type=submit]").click();
    });

    await promiseShown;
    await onPopupShown;
    await clickDoorhangerButton(MAIN_BUTTON);
  });

+38 −38
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ add_task(async function test_submit_creditCard_cancel_saving() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -24,7 +24,7 @@ add_task(async function test_submit_creditCard_cancel_saving() {
        !SpecialPowers.Services.prefs.prefHasUserValue(SYNC_USERNAME_PREF),
        "Sync account should not exist by default"
      );
      await promiseShown;
      await onPopupShown;
      let cb = getDoorhangerCheckbox();
      ok(cb.hidden, "Sync checkbox should be hidden");
      await clickDoorhangerButton(SECONDARY_BUTTON);
@@ -51,7 +51,7 @@ add_task(async function test_submit_creditCard_saved() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();

      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
@@ -64,7 +64,7 @@ add_task(async function test_submit_creditCard_saved() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -214,7 +214,7 @@ add_task(async function test_iframe_unload_save_card() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_IFRAME_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      let iframeBC = browser.browsingContext.children[0];
      await focusUpdateSubmitForm(
        iframeBC,
@@ -237,7 +237,7 @@ add_task(async function test_iframe_unload_save_card() {
        frame.remove();
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -268,7 +268,7 @@ add_task(async function test_submit_changed_subset_creditCard_form() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -279,7 +279,7 @@ add_task(async function test_submit_changed_subset_creditCard_form() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -387,7 +387,7 @@ add_task(async function test_submit_creditCard_never_save() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -396,7 +396,7 @@ add_task(async function test_submit_creditCard_never_save() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MENU_BUTTON, 0);
    }
  );
@@ -429,7 +429,7 @@ add_task(async function test_submit_creditCard_with_sync_account() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -438,7 +438,7 @@ add_task(async function test_submit_creditCard_with_sync_account() {
        },
      });

      await promiseShown;
      await onPopupShown;
      let cb = getDoorhangerCheckbox();
      ok(!cb.hidden, "Sync checkbox should be visible");
      is(
@@ -516,7 +516,7 @@ add_task(async function test_submit_creditCard_with_synced_already() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -525,7 +525,7 @@ add_task(async function test_submit_creditCard_with_synced_already() {
        },
      });

      await promiseShown;
      await onPopupShown;
      let cb = getDoorhangerCheckbox();
      ok(cb.hidden, "Sync checkbox should be hidden");
      await clickDoorhangerButton(SECONDARY_BUTTON);
@@ -545,7 +545,7 @@ add_task(async function test_submit_manual_mergeable_creditCard_form() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -556,7 +556,7 @@ add_task(async function test_submit_manual_mergeable_creditCard_form() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -597,7 +597,7 @@ add_task(async function test_update_autofill_form_name() {
      let osKeyStoreLoginShown = OSKeyStoreTestUtils.waitForOSKeyStoreLogin(
        true
      );
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();

      await openPopupOn(browser, "form #cc-name");
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
@@ -612,7 +612,7 @@ add_task(async function test_update_autofill_form_name() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -657,7 +657,7 @@ add_task(async function test_update_autofill_form_exp_date() {
      let osKeyStoreLoginShown = OSKeyStoreTestUtils.waitForOSKeyStoreLogin(
        true
      );
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await openPopupOn(browser, "form #cc-name");
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
      await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
@@ -671,7 +671,7 @@ add_task(async function test_update_autofill_form_exp_date() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -716,7 +716,7 @@ add_task(async function test_create_new_autofill_form() {
      let osKeyStoreLoginShown = OSKeyStoreTestUtils.waitForOSKeyStoreLogin(
        true
      );
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await openPopupOn(browser, "form #cc-name");
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
      await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
@@ -729,7 +729,7 @@ add_task(async function test_create_new_autofill_form() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(SECONDARY_BUTTON);
      await osKeyStoreLoginShown;
    }
@@ -814,7 +814,7 @@ add_task(async function test_submit_creditCard_with_invalid_network() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -826,7 +826,7 @@ add_task(async function test_submit_creditCard_with_invalid_network() {
        },
      });

      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -850,7 +850,7 @@ add_task(async function test_submit_form_with_combined_expiry_field() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_COMBINED_EXPIRY_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -859,7 +859,7 @@ add_task(async function test_submit_form_with_combined_expiry_field() {
          "#cc-exp": "05/28",
        },
      });
      await promiseShown;
      await onPopupShown;
      await clickDoorhangerButton(MAIN_BUTTON);
    }
  );
@@ -889,7 +889,7 @@ add_task(async function test_submit_third_party_creditCard_logo() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -898,7 +898,7 @@ add_task(async function test_submit_third_party_creditCard_logo() {
        },
      });

      await promiseShown;
      await onPopupShown;
      let doorhanger = getNotification();
      let creditCardLogo = doorhanger.querySelector(".desc-message-box image");
      let creditCardLogoWithoutExtension = creditCardLogo.src.split(".", 1)[0];
@@ -930,7 +930,7 @@ add_task(async function test_update_third_party_creditCard_logo() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -941,7 +941,7 @@ add_task(async function test_update_third_party_creditCard_logo() {
        },
      });

      await promiseShown;
      await onPopupShown;

      let doorhanger = getNotification();
      let creditCardLogo = doorhanger.querySelector(".desc-message-box image");
@@ -966,7 +966,7 @@ add_task(async function test_submit_generic_creditCard_logo() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -975,7 +975,7 @@ add_task(async function test_submit_generic_creditCard_logo() {
        },
      });

      await promiseShown;
      await onPopupShown;
      let doorhanger = getNotification();
      let creditCardLogo = doorhanger.querySelector(".desc-message-box image");
      let creditCardLogoWithoutExtension = creditCardLogo.src.split(".", 1)[0];
@@ -1006,7 +1006,7 @@ add_task(async function test_update_generic_creditCard_logo() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -1017,7 +1017,7 @@ add_task(async function test_update_generic_creditCard_logo() {
        },
      });

      await promiseShown;
      await onPopupShown;

      let doorhanger = getNotification();
      let creditCardLogo = doorhanger.querySelector(".desc-message-box image");
@@ -1043,7 +1043,7 @@ add_task(async function test_save_panel_spaces_in_cc_number_logo() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -1051,7 +1051,7 @@ add_task(async function test_save_panel_spaces_in_cc_number_logo() {
        },
      });

      await promiseShown;
      await onPopupShown;
      let doorhanger = getNotification();
      let creditCardLogo = doorhanger.querySelector(".desc-message-box image");
      let creditCardLogoWithoutExtension = creditCardLogo.src.split(".", 1)[0];
@@ -1082,7 +1082,7 @@ add_task(async function test_update_panel_with_spaces_in_cc_number_logo() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let onPopupShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -1093,7 +1093,7 @@ add_task(async function test_update_panel_with_spaces_in_cc_number_logo() {
        },
      });

      await promiseShown;
      await onPopupShown;

      let doorhanger = getNotification();
      let creditCardLogo = doorhanger.querySelector(".desc-message-box image");
+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ add_task(async function test_new_submitted_card_is_normalized() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let promiseShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
@@ -81,7 +81,7 @@ add_task(async function test_updated_card_is_normalized() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function(browser) {
      let promiseShown = promiseNotificationShown();
      let promiseShown = waitForPopupShown();
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#cc-name",
        newValues: {
Loading