summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/tests/browser/browser_disabled_migrator.js
blob: a1c8540c35d3e467d86de620fa7a7f57b7075e9c (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { MigratorBase } = ChromeUtils.importESModule(
  "resource:///modules/MigratorBase.sys.mjs"
);

/**
 * Tests that the InternalTestingProfileMigrator is listed in
 * the new migration wizard selector when enabled.
 */
add_task(async function test_enabled_migrator() {
  await withMigrationWizardDialog(async prefsWin => {
    let dialog = prefsWin.document.querySelector("#migrationWizardDialog");
    let wizard = dialog.querySelector("migration-wizard");
    let shadow = wizard.openOrClosedShadowRoot;
    let selector = shadow.querySelector("#browser-profile-selector");
    selector.click();

    await new Promise(resolve => {
      wizard
        .querySelector("panel-list")
        .addEventListener("shown", resolve, { once: true });
    });

    let panelItem = wizard.querySelector(
      `panel-item[key="${InternalTestingProfileMigrator.key}"]`
    );

    Assert.ok(
      panelItem,
      "The InternalTestingProfileMigrator panel-item exists."
    );
    panelItem.click();

    Assert.ok(
      selector.innerText.includes("Internal Testing Migrator"),
      "Testing for enabled internal testing migrator"
    );
  });
});

/**
 * Tests that the InternalTestingProfileMigrator is not listed in
 * the new migration wizard selector when disabled.
 */
add_task(async function test_disabling_migrator() {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.migrate.internal-testing.enabled", false]],
  });

  let sandbox = sinon.createSandbox();
  registerCleanupFunction(() => {
    sandbox.restore();
  });

  let internalTestingMigrator = new InternalTestingProfileMigrator();

  // We create a fake migrator that we know will still be present after
  // disabling the InternalTestingProfileMigrator so that we don't switch
  // the wizard to the NO_BROWSERS_FOUND page, which we're not testing here.
  let fakeMigrator = new FakeMigrator();

  let getMigratorStub = sandbox.stub(MigrationUtils, "getMigrator");
  getMigratorStub
    .withArgs("internal-testing")
    .resolves(internalTestingMigrator);
  getMigratorStub.withArgs("fake-migrator").resolves(fakeMigrator);

  sandbox.stub(MigrationUtils, "availableMigratorKeys").get(() => {
    return ["internal-testing", "fake-migrator"];
  });

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

    await new Promise(resolve => {
      wizard
        .querySelector("panel-list")
        .addEventListener("shown", resolve, { once: true });
    });

    let panelItem = wizard.querySelector(
      `panel-item[key="${InternalTestingProfileMigrator.key}"]`
    );

    Assert.ok(
      !panelItem,
      "The panel-item for the InternalTestingProfileMigrator does not exist"
    );
  });

  sandbox.restore();
});

/**
 * A stub of a migrator used for automated testing only.
 */
class FakeMigrator extends MigratorBase {
  static get key() {
    return "fake-migrator";
  }

  static get displayNameL10nID() {
    return "migration-wizard-migrator-display-name-firefox";
  }

  // We will create a single MigratorResource for each resource type that
  // just immediately reports a successful migration.
  getResources() {
    return Object.values(MigrationUtils.resourceTypes).map(type => {
      return {
        type,
        migrate: callback => {
          callback(true /* success */);
        },
      };
    });
  }

  // We need to override enabled() to always return true for testing purposes.
  get enabled() {
    return true;
  }
}