summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/tests/browser/browser_aboutwelcome_behavior.js
blob: 72c90851e2272454ffae32526f79bb866bce00ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that if browser.migrate.content-modal.about-welcome-behavior
 * is "autoclose", that closing the migration dialog when opened with the
 * NEWTAB entrypoint (which currently only occurs from about:welcome),
 * will result in the about:preferences tab closing too.
 */
add_task(async function test_autoclose_from_welcome() {
  await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");

  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.migrate.content-modal.about-welcome-behavior", "autoclose"],
    ],
  });

  let migrationDialogPromise = waitForMigrationWizardDialogTab();
  MigrationUtils.showMigrationWizard(window, {
    entrypoint: MigrationUtils.MIGRATION_ENTRYPOINTS.NEWTAB,
  });

  let prefsBrowser = await migrationDialogPromise;
  let prefsTab = gBrowser.getTabForBrowser(prefsBrowser);

  let tabClosed = BrowserTestUtils.waitForTabClosing(prefsTab);

  let dialog = prefsBrowser.contentDocument.querySelector(
    "#migrationWizardDialog"
  );

  let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "close");
  await BrowserTestUtils.synthesizeKey("VK_ESCAPE", {}, prefsBrowser);
  await dialogClosed;
  await tabClosed;
  Assert.ok(true, "Preferences tab closed with autoclose behavior.");
});

/**
 * Tests that if browser.migrate.content-modal.about-welcome-behavior
 * is "default", that closing the migration dialog when opened with the
 * NEWTAB entrypoint (which currently only occurs from about:welcome),
 * will result in the about:preferences tab still staying open.
 */
add_task(async function test_no_autoclose_from_welcome() {
  // Create a new blank tab which about:preferences will open into.
  await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");

  await SpecialPowers.pushPrefEnv({
    set: [["browser.migrate.content-modal.about-welcome-behavior", "default"]],
  });

  let migrationDialogPromise = waitForMigrationWizardDialogTab();
  MigrationUtils.showMigrationWizard(window, {
    entrypoint: MigrationUtils.MIGRATION_ENTRYPOINTS.NEWTAB,
  });

  let prefsBrowser = await migrationDialogPromise;
  let prefsTab = gBrowser.getTabForBrowser(prefsBrowser);

  let dialog = prefsBrowser.contentDocument.querySelector(
    "#migrationWizardDialog"
  );

  let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "close");
  await BrowserTestUtils.synthesizeKey("VK_ESCAPE", {}, prefsBrowser);
  await dialogClosed;
  Assert.ok(!prefsTab.closing, "about:preferences tab is not closing.");

  BrowserTestUtils.removeTab(prefsTab);
});

/**
 * Tests that if browser.migrate.content-modal.about-welcome-behavior
 * is "standalone", that opening the migration wizard from the NEWTAB
 * entrypoint opens the migration wizard in a standalone top-level
 * window.
 */
add_task(async function test_no_autoclose_from_welcome() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.migrate.content-modal.about-welcome-behavior", "standalone"],
    ],
  });

  let windowOpened = BrowserTestUtils.domWindowOpened();
  MigrationUtils.showMigrationWizard(window, {
    entrypoint: MigrationUtils.MIGRATION_ENTRYPOINTS.NEWTAB,
  });
  let dialogWin = await windowOpened;
  Assert.ok(dialogWin, "Top-level dialog window opened for the migrator.");
  await BrowserTestUtils.waitForEvent(dialogWin, "MigrationWizard:Ready");

  let dialogClosed = BrowserTestUtils.domWindowClosed(dialogWin);
  dialogWin.close();
  await dialogClosed;
});