summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/tests/browser/browser_no_browsers_state.js
blob: cd4677f31dc8907a6af3aa1c025a885e9d9863e2 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that the wizard switches to the NO_BROWSERS_FOUND page
 * when no migrators are detected.
 */
add_task(async function test_browser_no_programs() {
  let sandbox = sinon.createSandbox();
  registerCleanupFunction(() => {
    sandbox.restore();
  });

  sandbox.stub(MigrationUtils, "availableMigratorKeys").get(() => {
    return [];
  });

  // Let's enable the Passwords CSV import by default so that it appears
  // as a file migrator.
  await SpecialPowers.pushPrefEnv({
    set: [["signon.management.page.fileImport.enabled", true]],
  });

  await withMigrationWizardDialog(async prefsWin => {
    let dialog = prefsWin.document.querySelector("#migrationWizardDialog");
    let wizard = dialog.querySelector("migration-wizard");
    let shadow = wizard.openOrClosedShadowRoot;
    let deck = shadow.querySelector("#wizard-deck");

    await BrowserTestUtils.waitForMutationCondition(
      deck,
      { attributeFilter: ["selected-view"] },
      () => {
        return (
          deck.getAttribute("selected-view") ==
          "page-" + MigrationWizardConstants.PAGES.NO_BROWSERS_FOUND
        );
      }
    );

    Assert.ok(
      true,
      "Went to no browser page after attempting to search for migrators."
    );
    let chooseImportFromFile = shadow.querySelector("#choose-import-from-file");
    Assert.ok(
      !chooseImportFromFile.hidden,
      "Selecting a file migrator should still be possible."
    );
  });

  // Now disable all file migrators to make sure that the "Import from file"
  // button is hidden.
  await SpecialPowers.pushPrefEnv({
    set: [
      ["signon.management.page.fileImport.enabled", false],
      ["browser.migrate.bookmarks-file.enabled", false],
    ],
  });

  await withMigrationWizardDialog(async prefsWin => {
    let dialog = prefsWin.document.querySelector("#migrationWizardDialog");
    let wizard = dialog.querySelector("migration-wizard");
    let shadow = wizard.openOrClosedShadowRoot;
    let deck = shadow.querySelector("#wizard-deck");

    await BrowserTestUtils.waitForMutationCondition(
      deck,
      { attributeFilter: ["selected-view"] },
      () => {
        return (
          deck.getAttribute("selected-view") ==
          "page-" + MigrationWizardConstants.PAGES.NO_BROWSERS_FOUND
        );
      }
    );

    Assert.ok(
      true,
      "Went to no browser page after attempting to search for migrators."
    );
    let chooseImportFromFile = shadow.querySelector("#choose-import-from-file");
    Assert.ok(
      chooseImportFromFile.hidden,
      "Selecting a file migrator should not be possible."
    );
  });

  sandbox.restore();
});