Bug 1827431 - Make sure to select the appropriate profile when choosing what resource data is available for migration. r=niklas

We weren't passing the appropriate profile object to getMigrateData, and thanks to mocking,
we didn't catch this in automated testing.

This patch fixes the issue, and updates our mocking helpers to ensure that the expected
profile object gets passed to the `getResources` calls during mochitest-browser tests.

Differential Revision: https://phabricator.services.mozilla.com/D175144
This commit is contained in:
Mike Conley
2023-04-12 16:01:41 +00:00
parent 614b5aa6ac
commit 40cfbea3c0
6 changed files with 47 additions and 13 deletions

View File

@@ -22,9 +22,21 @@ export class InternalTestingProfileMigrator extends MigratorBase {
return "Internal Testing Migrator";
}
getSourceProfiles() {
return Promise.resolve([InternalTestingProfileMigrator.testProfile]);
}
// We will create a single MigratorResource for each resource type that
// just immediately reports a successful migration.
getResources() {
getResources(aProfile) {
if (
!aProfile ||
aProfile.id != InternalTestingProfileMigrator.testProfile.id
) {
throw new Error(
"InternalTestingProfileMigrator.getResources expects test profile."
);
}
return Object.values(lazy.MigrationUtils.resourceTypes).map(type => {
return {
type,
@@ -44,4 +56,8 @@ export class InternalTestingProfileMigrator extends MigratorBase {
flushResourceCache() {
this._resourcesByProfile = null;
}
static get testProfile() {
return { id: "test-profile", name: "Some test profile" };
}
}

View File

@@ -159,7 +159,7 @@ export class MigrationWizardParent extends JSWindowActorParent {
*/
async #doMigration(migratorKey, resourceTypeNames, profileObj) {
let migrator = await MigrationUtils.getMigrator(migratorKey);
let availableResourceTypes = await migrator.getMigrateData();
let availableResourceTypes = await migrator.getMigrateData(profileObj);
let resourceTypesToMigrate = 0;
let progress = {};

View File

@@ -119,7 +119,7 @@ add_task(async function test_successful_migrations() {
let migration = waitForTestMigration(
[MigrationUtils.resourceTypes.BOOKMARKS],
[MigrationUtils.resourceTypes.BOOKMARKS],
null
InternalTestingProfileMigrator.testProfile
);
await withMigrationWizardDialog(async prefsWin => {
@@ -167,7 +167,7 @@ add_task(async function test_successful_migrations() {
MigrationUtils.resourceTypes.PASSWORDS,
],
[MigrationUtils.resourceTypes.PASSWORDS],
null
InternalTestingProfileMigrator.testProfile
);
await withMigrationWizardDialog(async prefsWin => {
@@ -215,7 +215,11 @@ add_task(async function test_successful_migrations() {
return MigrationUtils.resourceTypes[resourceTypeStr];
});
migration = waitForTestMigration(allResourceTypes, allResourceTypes, null);
migration = waitForTestMigration(
allResourceTypes,
allResourceTypes,
InternalTestingProfileMigrator.testProfile
);
await withMigrationWizardDialog(async prefsWin => {
let dialogBody = prefsWin.document.body;
@@ -246,7 +250,7 @@ add_task(async function test_invalid_resource_type() {
let migration = waitForTestMigration(
[MigrationUtils.resourceTypes.BOOKMARKS],
[MigrationUtils.resourceTypes.BOOKMARKS],
null
InternalTestingProfileMigrator.testProfile
);
await withMigrationWizardDialog(async prefsWin => {

View File

@@ -28,7 +28,7 @@ add_task(async function test_ie_edge_bookmarks_success_strings() {
let migration = waitForTestMigration(
[MigrationUtils.resourceTypes.BOOKMARKS],
[MigrationUtils.resourceTypes.BOOKMARKS],
null
InternalTestingProfileMigrator.testProfile
);
await withMigrationWizardDialog(async prefsWin => {

View File

@@ -122,7 +122,12 @@ async function waitForTestMigration(
// a single fake MigratorResource per availableResourceType.
sandbox
.stub(InternalTestingProfileMigrator.prototype, "getResources")
.callsFake(() => {
.callsFake(aProfile => {
Assert.deepEqual(
aProfile,
expectedProfile,
"Should have gotten the expected profile."
);
return Promise.resolve(
availableResourceTypes.map(resourceType => {
return {

View File

@@ -5,6 +5,9 @@
const { FirefoxProfileMigrator } = ChromeUtils.importESModule(
"resource:///modules/FirefoxProfileMigrator.sys.mjs"
);
const { InternalTestingProfileMigrator } = ChromeUtils.importESModule(
"resource:///modules/InternalTestingProfileMigrator.sys.mjs"
);
// These preferences are set to true anytime MigratorBase.migrate
// successfully completes a migration of their type.
@@ -280,7 +283,9 @@ add_task(async function test_times_migration() {
* TelemetryEnvironment.sys.mjs.
*/
add_task(async function test_interaction_telemetry() {
let testingMigrator = await MigrationUtils.getMigrator("internal-testing");
let testingMigrator = await MigrationUtils.getMigrator(
InternalTestingProfileMigrator.key
);
Services.prefs.clearUserPref(BOOKMARKS_PREF);
Services.prefs.clearUserPref(HISTORY_PREF);
@@ -294,7 +299,7 @@ add_task(async function test_interaction_telemetry() {
await testingMigrator.migrate(
MigrationUtils.resourceTypes.BOOKMARKS,
false,
{}
InternalTestingProfileMigrator.testProfile
);
Assert.ok(
Services.prefs.getBoolPref(BOOKMARKS_PREF),
@@ -306,7 +311,7 @@ add_task(async function test_interaction_telemetry() {
await testingMigrator.migrate(
MigrationUtils.resourceTypes.HISTORY,
false,
{}
InternalTestingProfileMigrator.testProfile
);
Assert.ok(
Services.prefs.getBoolPref(BOOKMARKS_PREF),
@@ -321,7 +326,7 @@ add_task(async function test_interaction_telemetry() {
await testingMigrator.migrate(
MigrationUtils.resourceTypes.PASSWORDS,
false,
{}
InternalTestingProfileMigrator.testProfile
);
Assert.ok(
Services.prefs.getBoolPref(BOOKMARKS_PREF),
@@ -342,7 +347,11 @@ add_task(async function test_interaction_telemetry() {
Services.prefs.clearUserPref(HISTORY_PREF);
Services.prefs.clearUserPref(PASSWORDS_PREF);
await testingMigrator.migrate(MigrationUtils.resourceTypes.ALL, false, {});
await testingMigrator.migrate(
MigrationUtils.resourceTypes.ALL,
false,
InternalTestingProfileMigrator.testProfile
);
Assert.ok(
Services.prefs.getBoolPref(BOOKMARKS_PREF),
"Bookmarks pref should have been set."