summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/browser/browser_aboutwelcome_import.js
blob: 76716ec47f75d90239fe4e478d2eaa3d8dd8f226 (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
101
102
103
104
105
106
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";
const IMPORT_SCREEN = {
  id: "AW_IMPORT",
  content: {
    primary_button: {
      label: "import",
      action: {
        navigate: true,
        type: "SHOW_MIGRATION_WIZARD",
      },
    },
  },
};

const FORCE_LEGACY =
  Services.prefs.getCharPref(
    "browser.migrate.content-modal.about-welcome-behavior",
    "default"
  ) === "legacy";

add_task(async function test_wait_import_modal() {
  await setAboutWelcomeMultiStage(
    JSON.stringify([IMPORT_SCREEN, { id: "AW_NEXT", content: {} }])
  );
  const { cleanup, browser } = await openMRAboutWelcome();

  // execution
  await test_screen_content(
    browser,
    "renders IMPORT screen",
    //Expected selectors
    ["main.AW_IMPORT", "button[value='primary_button']"],

    //Unexpected selectors:
    ["main.AW_NEXT"]
  );

  const wizardPromise = BrowserTestUtils.waitForMigrationWizard(
    window,
    FORCE_LEGACY
  );
  const prefsTab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:preferences"
  );
  await onButtonClick(browser, "button.primary");
  const wizard = await wizardPromise;

  await test_screen_content(
    browser,
    "still shows IMPORT screen",
    //Expected selectors
    ["main.AW_IMPORT", "button[value='primary_button']"],

    //Unexpected selectors:
    ["main.AW_NEXT"]
  );

  await BrowserTestUtils.closeMigrationWizard(wizard, FORCE_LEGACY);

  await test_screen_content(
    browser,
    "moved to NEXT screen",
    //Expected selectors
    ["main.AW_NEXT"],

    //Unexpected selectors:
    []
  );

  // cleanup
  await SpecialPowers.popPrefEnv(); // for setAboutWelcomeMultiStage
  BrowserTestUtils.removeTab(prefsTab);
  await cleanup();
});

add_task(async function test_wait_import_spotlight() {
  const spotlightPromise = TestUtils.topicObserved("subdialog-loaded");
  ChromeUtils.import(
    "resource://activity-stream/lib/Spotlight.jsm"
  ).Spotlight.showSpotlightDialog(gBrowser.selectedBrowser, {
    content: { modal: "tab", screens: [IMPORT_SCREEN] },
  });
  const [win] = await spotlightPromise;

  const wizardPromise = BrowserTestUtils.waitForMigrationWizard(
    window,
    FORCE_LEGACY
  );
  const prefsTab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "about:preferences"
  );
  win.document
    .querySelector(".onboardingContainer button[value='primary_button']")
    .click();
  const wizard = await wizardPromise;

  await BrowserTestUtils.closeMigrationWizard(wizard, FORCE_LEGACY);

  // cleanup
  BrowserTestUtils.removeTab(prefsTab);
});