InternalTestingProfileMigrator.sys.mjs (2223B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import { MigratorBase } from "resource:///modules/MigratorBase.sys.mjs"; 6 import { MigrationWizardConstants } from "chrome://browser/content/migration/migration-wizard-constants.mjs"; 7 8 const lazy = {}; 9 10 ChromeUtils.defineESModuleGetters(lazy, { 11 MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs", 12 }); 13 14 /** 15 * A stub of a migrator used for automated testing only. 16 */ 17 export class InternalTestingProfileMigrator extends MigratorBase { 18 static get key() { 19 return "internal-testing"; 20 } 21 22 static get displayNameL10nID() { 23 return "Internal Testing Migrator"; 24 } 25 26 static get sourceID() { 27 return 1; 28 } 29 30 getSourceProfiles() { 31 return Promise.resolve([InternalTestingProfileMigrator.testProfile]); 32 } 33 34 // We will create a single MigratorResource for each resource type that 35 // just immediately reports a successful migration. 36 getResources(aProfile) { 37 if ( 38 !aProfile || 39 aProfile.id != InternalTestingProfileMigrator.testProfile.id 40 ) { 41 throw new Error( 42 "InternalTestingProfileMigrator.getResources expects test profile." 43 ); 44 } 45 return Object.values(lazy.MigrationUtils.resourceTypes).map(type => { 46 return { 47 type, 48 migrate: callback => { 49 if (type == lazy.MigrationUtils.resourceTypes.EXTENSIONS) { 50 callback(true, { 51 progressValue: MigrationWizardConstants.PROGRESS_VALUE.SUCCESS, 52 totalExtensions: [], 53 importedExtensions: [], 54 }); 55 } else { 56 callback(true /* success */); 57 } 58 }, 59 }; 60 }); 61 } 62 63 /** 64 * Clears the MigratorResources that are normally cached by the 65 * MigratorBase parent class after a call to getResources. This 66 * allows our automated tests to try different resource availability 67 * scenarios between tests. 68 */ 69 flushResourceCache() { 70 this._resourcesByProfile = null; 71 } 72 73 static get testProfile() { 74 return { id: "test-profile", name: "Some test profile" }; 75 } 76 }