3 function makeSandbox() {
5 Services.scriptSecurityManager.getSystemPrincipal(),
8 wantGlobalProperties: ["ChromeUtils"],
9 sandboxName: `Sandbox type used for ext-*.js ExtensionAPI subscripts`,
14 // This test will fail (and should be removed) once the JSM shim is dropped.
15 add_task(function test_import_from_sandbox_using_shim() {
16 let sandbox = makeSandbox();
17 Object.assign(sandbox, {
18 injected1: ChromeUtils.import("resource://test/esmified-1.jsm"),
21 Assert.equal(Cu.isModuleLoaded("resource://test/esmified-2.jsm"), false);
23 Services.scriptloader.loadSubScript(
27 const shimmed1 = ChromeUtils.import("resource://test/esmified-1.jsm");
28 const shimmed2 = ChromeUtils.import("resource://test/esmified-2.jsm");
31 shimmed1: shimmed1.obj.value,
32 injected1: injected1.obj.value,
33 sameInstance1: injected1 === shimmed1,
34 shimmed2: shimmed2.obj.value,
39 let tr = sandbox.testResults;
41 Assert.equal(tr.injected1, 10, "Injected esmified-1.mjs has correct value.");
42 Assert.equal(tr.shimmed1, 10, "Shim-imported esmified-1.jsm correct value.");
43 Assert.ok(tr.sameInstance1, "Injected and imported are the same instance.");
44 Assert.equal(tr.shimmed2, 10, "Shim-imported esmified-2.jsm correct value.");
46 Assert.equal(Cu.isModuleLoaded("resource://test/esmified-2.jsm"), true);
49 // This tests the ESMification transition for extension API scripts.
50 add_task(function test_import_from_sandbox_transition() {
51 let sandbox = makeSandbox();
53 Object.assign(sandbox, {
54 injected3: ChromeUtils.importESModule("resource://test/esmified-3.sys.mjs"),
57 Services.scriptloader.loadSubScript("resource://test/api_script.js", sandbox);
58 let tr = sandbox.testResults;
60 Assert.equal(tr.injected3, 16, "Injected esmified-3.mjs has correct value.");
61 Assert.equal(tr.module3, 16, "Iimported esmified-3.mjs has correct value.");
62 Assert.ok(tr.sameInstance3, "Injected and imported are the same instance.");
63 Assert.equal(tr.module4, 14, "Iimported esmified-4.mjs has correct value.");
66 // Same as above, just using a PrecompiledScript.
67 add_task(async function test_import_from_sandbox_transition() {
68 let sandbox = makeSandbox();
70 Object.assign(sandbox, {
71 injected3: ChromeUtils.importESModule("resource://test/esmified-3.sys.mjs"),
74 let script = await ChromeUtils.compileScript("resource://test/api_script.js");
75 script.executeInGlobal(sandbox);
76 let tr = sandbox.testResults;
78 Assert.equal(tr.injected3, 22, "Injected esmified-3.mjs has correct value.");
79 Assert.equal(tr.module3, 22, "Iimported esmified-3.mjs has correct value.");
80 Assert.ok(tr.sameInstance3, "Injected and imported are the same instance.");
81 Assert.equal(tr.module4, 18, "Iimported esmified-4.mjs has correct value.");