mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 21:28:04 +02:00
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
92 lines
3.2 KiB
JavaScript
92 lines
3.2 KiB
JavaScript
"use strict";
|
|
|
|
const profileDir = do_get_profile();
|
|
|
|
const {ContextualIdentityService} = ChromeUtils.import("resource://gre/modules/ContextualIdentityService.jsm");
|
|
const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
|
|
|
const TEST_STORE_FILE_PATH = OS.Path.join(profileDir.path, "test-containers.json");
|
|
|
|
// Test the containers JSON file migrations.
|
|
add_task(async function migratedFile() {
|
|
// Let's create a file that has to be migrated.
|
|
const oldFileData = {
|
|
version: 2,
|
|
lastUserContextId: 6,
|
|
identities: [
|
|
{ userContextId: 1,
|
|
public: true,
|
|
icon: "fingerprint",
|
|
color: "blue",
|
|
l10nID: "userContextPersonal.label",
|
|
accessKey: "userContextPersonal.accesskey",
|
|
telemetryId: 1,
|
|
},
|
|
{ userContextId: 2,
|
|
public: true,
|
|
icon: "briefcase",
|
|
color: "orange",
|
|
l10nID: "userContextWork.label",
|
|
accessKey: "userContextWork.accesskey",
|
|
telemetryId: 2,
|
|
},
|
|
{ userContextId: 3,
|
|
public: true,
|
|
icon: "dollar",
|
|
color: "green",
|
|
l10nID: "userContextBanking.label",
|
|
accessKey: "userContextBanking.accesskey",
|
|
telemetryId: 3,
|
|
},
|
|
{ userContextId: 4,
|
|
public: true,
|
|
icon: "cart",
|
|
color: "pink",
|
|
l10nID: "userContextShopping.label",
|
|
accessKey: "userContextShopping.accesskey",
|
|
telemetryId: 4,
|
|
},
|
|
{ userContextId: 5,
|
|
public: false,
|
|
icon: "",
|
|
color: "",
|
|
name: "userContextIdInternal.thumbnail",
|
|
accessKey: "",
|
|
},
|
|
{ userContextId: 6,
|
|
public: true,
|
|
icon: "cart",
|
|
color: "ping",
|
|
name: "Custom user-created identity",
|
|
},
|
|
],
|
|
};
|
|
|
|
await OS.File.writeAtomic(TEST_STORE_FILE_PATH, JSON.stringify(oldFileData),
|
|
{ tmpPath: TEST_STORE_FILE_PATH + ".tmp" });
|
|
|
|
let cis = ContextualIdentityService.createNewInstanceForTesting(TEST_STORE_FILE_PATH);
|
|
ok(!!cis, "We have our instance of ContextualIdentityService");
|
|
|
|
// Check that the custom user-created identity exists.
|
|
|
|
const expectedPublicLength = oldFileData.identities.filter(
|
|
identity => identity.public).length;
|
|
const publicIdentities = cis.getPublicIdentities();
|
|
const oldLastIdentity = oldFileData.identities[oldFileData.identities.length - 1];
|
|
const customUserCreatedIdentity = publicIdentities.filter(
|
|
identity => identity.name === oldLastIdentity.name).pop();
|
|
|
|
equal(publicIdentities.length, expectedPublicLength,
|
|
"We should have the expected number of public identities");
|
|
ok(!!customUserCreatedIdentity, "Got the custom user-created identity");
|
|
|
|
// Check that the reserved userContextIdInternal.webextStorageLocal identity exists.
|
|
|
|
const webextStorageLocalPrivateId = ContextualIdentityService._defaultIdentities.filter(
|
|
identity => identity.name === "userContextIdInternal.webextStorageLocal").pop().userContextId;
|
|
|
|
const privWebExtStorageLocal = cis.getPrivateIdentity("userContextIdInternal.webextStorageLocal");
|
|
equal(privWebExtStorageLocal && privWebExtStorageLocal.userContextId, webextStorageLocalPrivateId,
|
|
"We should have the default userContextIdInternal.webextStorageLocal private identity");
|
|
});
|