Bug 1323845: Part 5b - Add tests for bundled experiments APIs. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Tue, 09 Jan 2018 17:01:29 -0800
changeset 450988 bbf3129f4a56db20b1806247bc8d4bab0e8a430f
parent 450987 179d025d51cdf2c5d0e7eea3357d8f5fd1dc9b6c
child 450989 17ee1f919ec1d4a98c9a6ecaab695cf2501992c7
push id8543
push userryanvm@gmail.com
push dateTue, 16 Jan 2018 14:33:22 +0000
treeherdermozilla-beta@a6525ed16a32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1323845
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1323845: Part 5b - Add tests for bundled experiments APIs. r=aswan MozReview-Commit-ID: C0gAmW2QfNr
toolkit/components/extensions/ExtensionTestCommon.jsm
toolkit/components/extensions/test/xpcshell/test_ext_experiments.js
--- a/toolkit/components/extensions/ExtensionTestCommon.jsm
+++ b/toolkit/components/extensions/ExtensionTestCommon.jsm
@@ -378,11 +378,14 @@ this.ExtensionTestCommon = class Extensi
     if (!id) {
       id = uuidGen.generateUUID().number;
     }
 
     return new Extension({
       id,
       resourceURI: jarURI,
       cleanupFile: file,
+      signedState: data.isPrivileged ? AddonManager.SIGNEDSTATE_PRIVILEGED
+                                     : AddonManager.SIGNEDSTATE_SIGNED,
+      temporarilyInstalled: !!data.temporarilyInstalled,
     });
   }
 };
--- a/toolkit/components/extensions/test/xpcshell/test_ext_experiments.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_experiments.js
@@ -182,8 +182,122 @@ add_task(async function test_experiments
   boringAddon.userDisabled = true;
   await new Promise(executeSoon);
 
   equal(addon.appDisabled, true, "Add-on should be app-disabled after its dependency is removed.");
 
   addon.uninstall();
   boringAddon.uninstall();
 });
+
+add_task(async function test_bundled_experiments() {
+  let extension = ExtensionTestUtils.loadExtension({
+    isPrivileged: true,
+
+    manifest: {
+      experiment_apis: {
+        foo: {
+          schema: "schema.json",
+          parent: {
+            scopes: ["addon_parent"],
+            script: "parent.js",
+            paths: [["experiments", "foo", "parent"]],
+          },
+          child: {
+            scopes: ["addon_child"],
+            script: "child.js",
+            paths: [["experiments", "foo", "child"]],
+          },
+        },
+      },
+    },
+
+    async background() {
+      browser.test.assertEq("object", typeof browser.experiments,
+                            "typeof browser.experiments");
+
+      browser.test.assertEq("object", typeof browser.experiments.foo,
+                            "typeof browser.experiments.foo");
+
+      browser.test.assertEq("function", typeof browser.experiments.foo.child,
+                            "typeof browser.experiments.foo.child");
+
+      browser.test.assertEq("function", typeof browser.experiments.foo.parent,
+                            "typeof browser.experiments.foo.parent");
+
+      browser.test.assertEq("child", browser.experiments.foo.child(),
+                            "foo.child()");
+
+      browser.test.assertEq("parent", await browser.experiments.foo.parent(),
+                            "await foo.parent()");
+
+      browser.test.notifyPass("background.experiments.foo");
+    },
+
+    files: {
+      "schema.json": JSON.stringify([
+        {
+          "namespace": "experiments.foo",
+          "types": [
+            {
+              "id": "Meh",
+              "type": "object",
+              "properties": {},
+            },
+          ],
+          "functions": [
+            {
+              "name": "parent",
+              "type": "function",
+              "async": true,
+              "parameters": [],
+            },
+            {
+              "name": "child",
+              "type": "function",
+              "parameters": [],
+              "returns": {"type": "string"},
+            },
+          ],
+        },
+      ]),
+
+      /* globals ExtensionAPI */
+      "parent.js": () => {
+        this.foo = class extends ExtensionAPI {
+          getAPI(context) {
+            return {
+              experiments: {
+                foo: {
+                  parent() {
+                    return Promise.resolve("parent");
+                  },
+                },
+              },
+            };
+          }
+        };
+      },
+
+      "child.js": () => {
+        this.foo = class extends ExtensionAPI {
+          getAPI(context) {
+            return {
+              experiments: {
+                foo: {
+                  child() {
+                    return "child";
+                  },
+                },
+              },
+            };
+          }
+        };
+      },
+    },
+  });
+
+  await extension.startup();
+
+  await extension.awaitFinish("background.experiments.foo");
+
+  await extension.unload();
+});