mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 13:18:45 +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
66 lines
2.8 KiB
JavaScript
66 lines
2.8 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");
|
|
|
|
let cis;
|
|
|
|
// Basic tests
|
|
add_task(function() {
|
|
ok(!!ContextualIdentityService, "ContextualIdentityService exists");
|
|
|
|
cis = ContextualIdentityService.createNewInstanceForTesting(TEST_STORE_FILE_PATH);
|
|
ok(!!cis, "We have our instance of ContextualIdentityService");
|
|
|
|
equal(cis.getPublicIdentities().length, 4, "By default, 4 containers.");
|
|
equal(cis.getPublicIdentityFromId(0), null, "No identity with id 0");
|
|
|
|
ok(!!cis.getPublicIdentityFromId(1), "Identity 1 exists");
|
|
ok(!!cis.getPublicIdentityFromId(2), "Identity 2 exists");
|
|
ok(!!cis.getPublicIdentityFromId(3), "Identity 3 exists");
|
|
ok(!!cis.getPublicIdentityFromId(4), "Identity 4 exists");
|
|
});
|
|
|
|
// Create a new identity
|
|
add_task(function() {
|
|
equal(cis.getPublicIdentities().length, 4, "By default, 4 containers.");
|
|
|
|
let identity = cis.create("New Container", "Icon", "Color");
|
|
ok(!!identity, "New container created");
|
|
equal(identity.name, "New Container", "Name matches");
|
|
equal(identity.icon, "Icon", "Icon matches");
|
|
equal(identity.color, "Color", "Color matches");
|
|
|
|
equal(cis.getPublicIdentities().length, 5, "Expected 5 containers.");
|
|
|
|
ok(!!cis.getPublicIdentityFromId(identity.userContextId), "Identity exists");
|
|
equal(cis.getPublicIdentityFromId(identity.userContextId).name, "New Container", "Identity name is OK");
|
|
equal(cis.getPublicIdentityFromId(identity.userContextId).icon, "Icon", "Identity icon is OK");
|
|
equal(cis.getPublicIdentityFromId(identity.userContextId).color, "Color", "Identity color is OK");
|
|
equal(cis.getUserContextLabel(identity.userContextId), "New Container", "Identity label is OK");
|
|
|
|
// Remove an identity
|
|
equal(cis.remove(-1), false, "cis.remove() returns false if identity doesn't exist.");
|
|
equal(cis.remove(1), true, "cis.remove() returns true if identity exists.");
|
|
|
|
equal(cis.getPublicIdentities().length, 4, "Expected 4 containers.");
|
|
});
|
|
|
|
// Update an identity
|
|
add_task(function() {
|
|
ok(!!cis.getPublicIdentityFromId(2), "Identity 2 exists");
|
|
|
|
equal(cis.update(-1, "Container", "Icon", "Color"), false, "Update returns false if the identity doesn't exist");
|
|
|
|
equal(cis.update(2, "Container", "Icon", "Color"), true, "Update returns true if everything is OK");
|
|
|
|
ok(!!cis.getPublicIdentityFromId(2), "Identity exists");
|
|
equal(cis.getPublicIdentityFromId(2).name, "Container", "Identity name is OK");
|
|
equal(cis.getPublicIdentityFromId(2).icon, "Icon", "Identity icon is OK");
|
|
equal(cis.getPublicIdentityFromId(2).color, "Color", "Identity color is OK");
|
|
equal(cis.getUserContextLabel(2), "Container", "Identity label is OK");
|
|
});
|