Commit 4f80c0eb authored by Mike Conley's avatar Mike Conley
Browse files

Bug 1826155 - Fix more tests that break when the new migration wizard is...

Bug 1826155 - Fix more tests that break when the new migration wizard is enabled. r=sgalich,aminomancer

Differential Revision: https://phabricator.services.mozilla.com/D174494
parent 3c43de2d
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_setup(async () => {
  // Load the initial tab at example.com. This makes it so that if
  // we're using the new migration wizard, we'll load the about:preferences
  // page in a new tab rather than overtaking the initial one. This
  // makes it easier to be consistent with closing and opening
  // behaviours between the two kinds of migration wizards.
  let browser = gBrowser.selectedBrowser;
  BrowserTestUtils.loadURIString(browser, "https://example.com");
  await BrowserTestUtils.browserLoaded(browser);
});

add_task(async function file_menu_import_wizard() {
  // We can't call this code directly or our JS execution will get blocked on Windows/Linux where
  // the dialog is modal.
@@ -5,15 +21,7 @@ add_task(async function file_menu_import_wizard() {
    document.getElementById("menu_importFromAnotherBrowser").doCommand()
  );

  await TestUtils.waitForCondition(() => {
    let win = Services.wm.getMostRecentWindow("Browser:MigrationWizard");
    return win && win.document && win.document.readyState == "complete";
  }, "Migrator window loaded");

  let migratorWindow = Services.wm.getMostRecentWindow(
    "Browser:MigrationWizard"
  );
  ok(migratorWindow, "Migrator window opened");

  await BrowserTestUtils.closeWindow(migratorWindow);
  let wizard = await BrowserTestUtils.waitForMigrationWizard(window);
  ok(wizard, "Migrator window opened");
  await BrowserTestUtils.closeMigrationWizard(wizard);
});
+11 −9
Original line number Diff line number Diff line
@@ -13,6 +13,14 @@ add_setup(async function() {

add_task(async function test_no_logins_class() {
  let { platform } = AppConstants;
  let wizardPromise;

  // The import link is hidden on Linux, so we don't wait for the migration
  // wizard to open on that platform.
  if (AppConstants.platform != "linux") {
    wizardPromise = BrowserTestUtils.waitForMigrationWizard(window);
  }

  await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [platform],
@@ -100,15 +108,9 @@ add_task(async function test_no_logins_class() {
    // End the test now for Linux since the link is hidden.
    return;
  }
  await TestUtils.waitForCondition(() => {
    let win = Services.wm.getMostRecentWindow("Browser:MigrationWizard");
    return win && win.document && win.document.readyState == "complete";
  }, "Migrator window loaded");
  let migratorWindow = Services.wm.getMostRecentWindow(
    "Browser:MigrationWizard"
  );
  Assert.ok(migratorWindow, "Migrator window opened");
  await BrowserTestUtils.closeWindow(migratorWindow);
  let wizard = await wizardPromise;
  Assert.ok(wizard, "Migrator window opened");
  await BrowserTestUtils.closeMigrationWizard(wizard);
});

add_task(
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ add_setup(async function() {
});

add_task(async function test_open_import() {
  let promiseImportWindow = BrowserTestUtils.domWindowOpenedAndLoaded();
  let promiseImportWindow = BrowserTestUtils.waitForMigrationWizard(window);

  let browser = gBrowser.selectedBrowser;
  await BrowserTestUtils.synthesizeMouseAtCenter("menu-button", {}, browser);
@@ -56,5 +56,5 @@ add_task(async function test_open_import() {
    { process: "content" }
  );

  importWindow.close();
  await BrowserTestUtils.closeMigrationWizard(importWindow);
});
+56 −0
Original line number Diff line number Diff line
@@ -2719,6 +2719,55 @@ export var BrowserTestUtils = {
      return val;
    });
  },

  /**
   * A helper function for this test that returns a Promise that resolves
   * once either the legacy or new migration wizard appears.
   *
   * @param {DOMWindow} window
   *   The top-level window that the about:preferences tab is likely to open
   *   in if the new migration wizard is enabled.
   * @returns {Promise<Element>}
   *   Resolves to the dialog window in the legacy case, and the
   *   about:preferences tab otherwise.
   */
  async waitForMigrationWizard(window) {
    if (!this._usingNewMigrationWizard) {
      return this.waitForCondition(() => {
        let win = Services.wm.getMostRecentWindow("Browser:MigrationWizard");
        if (win?.document?.readyState == "complete") {
          return win;
        }
        return false;
      }, "Wait for migration wizard to open");
    }

    let wizardReady = this.waitForEvent(window, "MigrationWizard:Ready");
    let wizardTab = await this.waitForNewTab(window.gBrowser, url => {
      return url.startsWith("about:preferences");
    });
    await wizardReady;

    return wizardTab;
  },

  /**
   * Closes the migration wizard.
   *
   * @param {Element} wizardWindowOrTab
   *   The XUL dialog window for the migration wizard in the legacy case, and
   *   the about:preferences tab otherwise. In general, it's probably best to
   *   just pass whatever BrowserTestUtils.waitForMigrationWizard resolved to
   *   into this in order to handle both the old and new migration wizard.
   * @returns {Promise<undefined>}
   */
  closeMigrationWizard(wizardWindowOrTab) {
    if (!this._usingNewMigrationWizard) {
      return BrowserTestUtils.closeWindow(wizardWindowOrTab);
    }

    return BrowserTestUtils.removeTab(wizardWindowOrTab);
  },
};

XPCOMUtils.defineLazyPreferenceGetter(
@@ -2728,4 +2777,11 @@ XPCOMUtils.defineLazyPreferenceGetter(
  false
);

XPCOMUtils.defineLazyPreferenceGetter(
  BrowserTestUtils,
  "_usingNewMigrationWizard",
  "browser.migrate.content-modal.enabled",
  false
);

Services.obs.addObserver(BrowserTestUtils, "test-complete");
+5 −64
Original line number Diff line number Diff line
@@ -3,68 +3,9 @@

"use strict";

/**
 * We currently support both the legacy and the new migration wizard. The
 * legacy migration wizard opens in a top-level XUL dialog. The new migration
 * wizard opens as an HTML dialog within about:preferences.
 *
 * This variable is true if the new migration wizard that loads in
 * about:preferences is being used.
 *
 * The legacy wizard codepaths can be removed once bug 1824851 lands.
 */
const USING_LEGACY_WIZARD = !Services.prefs.getBoolPref(
  "browser.migrate.content-modal.enabled",
  false
);

/**
 * A helper function for this test that returns a Promise that resolves
 * once either the legacy or new migration wizard appears.
 *
 * @returns {Promise<Element>}
 *   Resolves to the dialog window in the legacy case, and the
 *   about:preferences tab otherwise.
 */
async function waitForWizard() {
  if (USING_LEGACY_WIZARD) {
    return BrowserTestUtils.waitForCondition(
      () => Services.wm.getMostRecentWindow("Browser:MigrationWizard"),
      "Wait for migration wizard to open"
    );
  }

  let wizardReady = BrowserTestUtils.waitForEvent(
    window,
    "MigrationWizard:Ready"
  );
  let wizardTab = await BrowserTestUtils.waitForNewTab(gBrowser, url => {
    return url.startsWith("about:preferences");
  });
  await wizardReady;

  return wizardTab;
}

/**
 * Closes the migration wizard.
 *
 * @param {Element} wizardWindowOrTab
 *   The XUL dialog window for the migration wizard in the legacy case, and
 *   the about:preferences tab otherwise.
 * @returns {Promise<undefined>}
 */
function closeWizard(wizardWindowOrTab) {
  if (USING_LEGACY_WIZARD) {
    return BrowserTestUtils.closeWindow(wizardWindowOrTab);
  }

  return BrowserTestUtils.removeTab(wizardWindowOrTab);
}

add_setup(async () => {
  // Load the initial tab at example.com. This makes it so that if
  // USING_LEGACY_WIZARD is false, we'll load the about:preferences
  // we're using the new migration wizard, we'll load the about:preferences
  // page in a new tab rather than overtaking the initial one. This
  // makes it easier to be consistent with closing and opening
  // behaviours between the two kinds of migration wizards.
@@ -74,17 +15,17 @@ add_setup(async () => {
});

add_task(async function test_SHOW_MIGRATION_WIZARD() {
  let wizardOpened = waitForWizard();
  let wizardOpened = BrowserTestUtils.waitForMigrationWizard(window);

  SMATestUtils.executeAndValidateAction({ type: "SHOW_MIGRATION_WIZARD" });

  let wizard = await wizardOpened;
  ok(wizard, "Migration wizard opened");
  closeWizard(wizard);
  await BrowserTestUtils.closeMigrationWizard(wizard);
});

add_task(async function test_SHOW_MIGRATION_WIZARD_WITH_SOURCE() {
  let wizardOpened = waitForWizard();
  let wizardOpened = BrowserTestUtils.waitForMigrationWizard(window);

  SMATestUtils.executeAndValidateAction({
    type: "SHOW_MIGRATION_WIZARD",
@@ -93,5 +34,5 @@ add_task(async function test_SHOW_MIGRATION_WIZARD_WITH_SOURCE() {

  let wizard = await wizardOpened;
  ok(wizard, "Migrator window opened when source param specified");
  closeWizard(wizard);
  await BrowserTestUtils.closeMigrationWizard(wizard);
});
Loading