Bug 1220198 - Never appDisable experiments if they don't have the right app compatibility information available. r=rhelmer, a=lizzard
authorDave Townsend <dtownsend@oxymoronical.com>
Mon, 02 Nov 2015 11:15:12 -0800
changeset 296642 b87f9e2d6355
parent 296641 6a65996ee241
child 296643 eb3dd7f7d487
push id5270
push usercbook@mozilla.com
push date2015-11-06 14:47 +0000
treeherdermozilla-beta@b87f9e2d6355 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhelmer, lizzard
bugs1220198
milestone43.0
Bug 1220198 - Never appDisable experiments if they don't have the right app compatibility information available. r=rhelmer, a=lizzard
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_experiment.js
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -623,16 +623,26 @@ function isUsableAddon(aAddon) {
       if (aAddon.signedState != AddonManager.SIGNEDSTATE_SYSTEM)
         return false;
     }
   }
 
   if (aAddon.blocklistState == Blocklist.STATE_BLOCKED)
     return false;
 
+  // Experiments are installed through an external mechanism that
+  // limits target audience to compatible clients. We trust it knows what
+  // it's doing and skip compatibility checks.
+  //
+  // This decision does forfeit defense in depth. If the experiments system
+  // is ever wrong about targeting an add-on to a specific application
+  // or platform, the client will likely see errors.
+  if (aAddon.type == "experiment")
+    return true;
+
   if (AddonManager.checkUpdateSecurity && !aAddon.providesUpdatesSecurely)
     return false;
 
   if (!aAddon.isPlatformCompatible)
     return false;
 
   if (AddonManager.checkCompatibility) {
     if (!aAddon.isCompatible)
--- a/toolkit/mozapps/extensions/test/xpcshell/test_experiment.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_experiment.js
@@ -1,28 +1,33 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 var scope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm");
 const XPIProvider = scope.XPIProvider;
 
+var gIsNightly = false;
+
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   startupManager();
 
+  gIsNightly = isNightlyChannel();
+
   run_next_test();
 }
 
 add_test(function test_experiment() {
   AddonManager.getInstallForFile(do_get_addon("test_experiment1"), (install) => {
     completeAllInstalls([install], () => {
       AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
         Assert.ok(addon, "Addon is found.");
 
         Assert.ok(addon.userDisabled, "Experiments are userDisabled by default.");
+        Assert.ok(!addon.appDisabled, "Experiments are not appDisabled by compatibility.");
         Assert.equal(addon.isActive, false, "Add-on is not active.");
         Assert.equal(addon.updateURL, null, "No updateURL for experiments.");
         Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE,
                      "Background updates are disabled.");
         Assert.equal(addon.permissions, AddonManager.PERM_CAN_UNINSTALL,
                      "Permissions are minimal.");
         Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_ENABLE),
                   "Should not be pending enable");
@@ -86,19 +91,39 @@ add_test(function test_userDisabledNotPe
           let persisted = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
           Assert.ok(!("experiment1@tests.mozilla.org" in persisted),
                     "Experiment add-on not persisted to bootstrappedAddons.");
 
           AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
             Assert.ok(addon, "Add-on retrieved.");
             Assert.ok(addon.userDisabled, "Add-on is disabled after restart.");
             Assert.equal(addon.isActive, false, "Add-on is not active after restart.");
+            addon.uninstall();
 
             run_next_test();
           });
         });
       },
     };
 
     AddonManager.addAddonListener(listener);
     addon.userDisabled = false;
   });
 });
+
+add_test(function test_checkCompatibility() {
+  if (gIsNightly)
+    Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", false);
+  else
+    Services.prefs.setBoolPref("extensions.checkCompatibility.1", false);
+
+  restartManager();
+
+  installAllFiles([do_get_addon("test_experiment1")], () => {
+    AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
+      Assert.ok(addon, "Add-on is found.");
+      Assert.ok(addon.userDisabled, "Add-on is user disabled.");
+      Assert.ok(!addon.appDisabled, "Add-on is not app disabled.");
+
+      run_next_test();
+    });
+  });
+});