Bug 1046644 - Honor OpenH264 autoupdate pref for the initial GMP install check. r=gfritzsche a=sylvestre
authorBrian R. Bondy <netzen@gmail.com>
Fri, 01 Aug 2014 16:46:45 -0400
changeset 217416 cf771b63d6d78d648de5e220bc3751f48ef54c5b
parent 217415 7123465251a7053de4c349a6e6edba20d0258e8a
child 217417 126d41d598be3b3f5b0c0080d8ebb885f89e5d69
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, sylvestre
bugs1046644
milestone33.0a2
Bug 1046644 - Honor OpenH264 autoupdate pref for the initial GMP install check. r=gfritzsche a=sylvestre
toolkit/modules/GMPInstallManager.jsm
toolkit/modules/tests/xpcshell/test_GMPInstallManager.js
--- a/toolkit/modules/GMPInstallManager.jsm
+++ b/toolkit/modules/GMPInstallManager.jsm
@@ -22,17 +22,17 @@ Cu.import("resource://gre/modules/FileUt
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/ctypes.jsm");
 
 this.EXPORTED_SYMBOLS = ["GMPInstallManager", "GMPExtractor", "GMPDownloader",
-                         "GMPAddon", "GMPPrefs"];
+                         "GMPAddon", "GMPPrefs", "OPEN_H264_ID"];
 
 var gLocale = null;
 const PARENT_LOGGER_ID = "GMPInstallManager";
 
 // Setup the parent logger with dump logging. It'll only be used if logging is
 // enabled though.
 let parentLogger = Log.repository.getLogger(PARENT_LOGGER_ID);
 parentLogger.level = Log.Level.Debug;
@@ -104,16 +104,17 @@ let GMPPrefs = {
 
   /**
    * List of keys which can be used in get and set
    */
   KEY_LOG_ENABLED: "media.gmp-manager.log",
   KEY_ADDON_LAST_UPDATE: "media.{0}.lastUpdate",
   KEY_ADDON_PATH: "media.{0}.path",
   KEY_ADDON_VERSION: "media.{0}.version",
+  KEY_ADDON_AUTOUPDATE: "media.{0}.autoupdate",
   KEY_URL: "media.gmp-manager.url",
   KEY_URL_OVERRIDE: "media.gmp-manager.url.override",
   KEY_CERT_CHECKATTRS: "media.gmp-manager.cert.checkAttributes",
   KEY_CERT_REQUIREBUILTIN: "media.gmp-manager.cert.requireBuiltIn",
   KEY_UPDATE_LAST_CHECK: "media.gmp-manager.lastCheck",
   KEY_UPDATE_SECONDS_BETWEEN_CHECKS: "media.gmp-manager.secondsBetweenChecks",
   KEY_APP_DISTRIBUTION: "distribution.id",
   KEY_APP_DISTRIBUTION_VERSION: "distribution.version",
@@ -409,59 +410,78 @@ GMPInstallManager.prototype = {
     }
     return now - lastCheck;
   },
   _updateLastCheck: function() {
     let now = Math.round(Date.now() / 1000);
     GMPPrefs.set(GMPPrefs.KEY_UPDATE_LAST_CHECK, now);
   },
   /**
-   * Wrapper for checkForAddons and installaddon.
+   * Wrapper for checkForAddons and installAddon.
    * Will only install if not already installed and will log the results.
+   * This will only install/update the OpenH264 plugin
    */
   simpleCheckAndInstall: function() {
     let log = getScopedLogger("GMPInstallManager.simpleCheckAndInstall");
+
+    let autoUpdate = GMPPrefs.get(GMPPrefs.KEY_ADDON_AUTOUPDATE,
+                                  OPEN_H264_ID, true);
+    if (!autoUpdate) {
+        log.info("Auto-update is off for openh264, aborting check.");
+        return Promise.resolve({status: "check-disabled"});
+    }
+
     let secondsBetweenChecks =
       GMPPrefs.get(GMPPrefs.KEY_UPDATE_SECONDS_BETWEEN_CHECKS, undefined,
                    DEFAULT_SECONDS_BETWEEN_CHECKS)
     let secondsSinceLast = this._getTimeSinceLastCheck();
     log.info("Last check was: " + secondsSinceLast +
              " seconds ago, minimum seconds: " + secondsBetweenChecks);
     if (secondsBetweenChecks > secondsSinceLast) {
       log.info("Will not check for updates.");
-      return Promise.resolve();
+      return Promise.resolve({status: "too-frequent-no-check"});
     }
 
+    let deferred = Promise.defer();
     let promise = this.checkForAddons();
     promise.then(gmpAddons => {
       this._updateLastCheck();
       log.info("Found " + gmpAddons.length + " addons advertised.");
       let addonsToInstall = gmpAddons.filter(gmpAddon => {
         log.info("Found addon: " + gmpAddon.toString());
         return gmpAddon.isValid && gmpAddon.isOpenH264 &&
                !gmpAddon.isInstalled
       });
       if (!addonsToInstall.length) {
         log.info("No new addons to install, returning");
-        return;
+        return deferred.resolve({status: "nothing-new-to-install"});
       }
+      // Only 1 addon will be returned because of the gmpAddon.isOpenH264
+      // check above.
       addonsToInstall.forEach(gmpAddon => {
         promise = this.installAddon(gmpAddon);
         promise.then(extractedPaths => {
           // installed!
           log.info("Addon installed successfully: " + gmpAddon.toString());
+          return deferred.resolve({status: "addon-install"});
         }, () => {
           if (!GMPPrefs.get(GMPPrefs.KEY_LOG_ENABLED)) {
-            Cu.reportError(gmpAddon.toString() + " could not be installed. Enable " +
+            Cu.reportError(gmpAddon.toString() +
+                           " could not be installed. Enable " +
                            GMPPrefs.KEY_LOG_ENABLED + " for details!");
           }
           log.error("Could not install addon: " + gmpAddon.toString());
+          deferred.reject();
         });
       });
+    }, () => {
+        log.error("Could not check for addons");
+        deferred.reject();
     });
+    return deferred.promise;
   },
 
   /**
    * Makes sure everything is cleaned up
    */
   uninit: function() {
     let log = getScopedLogger("GMPDownloader.uninit");
     if (this._request) {
--- a/toolkit/modules/tests/xpcshell/test_GMPInstallManager.js
+++ b/toolkit/modules/tests/xpcshell/test_GMPInstallManager.js
@@ -29,28 +29,31 @@ add_test(function test_prefs() {
   GMPPrefs.set(GMPPrefs.KEY_URL, "http://not-really-used");
   GMPPrefs.set(GMPPrefs.KEY_URL_OVERRIDE, "http://not-really-used-2");
   GMPPrefs.set(GMPPrefs.KEY_ADDON_LAST_UPDATE, "1", addon1);
   GMPPrefs.set(GMPPrefs.KEY_ADDON_PATH, "2", addon1);
   GMPPrefs.set(GMPPrefs.KEY_ADDON_VERSION, "3", addon1);
   GMPPrefs.set(GMPPrefs.KEY_ADDON_LAST_UPDATE, "4", addon2);
   GMPPrefs.set(GMPPrefs.KEY_ADDON_PATH, "5", addon2);
   GMPPrefs.set(GMPPrefs.KEY_ADDON_VERSION, "6", addon2);
+  GMPPrefs.set(GMPPrefs.KEY_ADDON_AUTOUPDATE, false, addon2);
   GMPPrefs.set(GMPPrefs.KEY_CERT_CHECKATTRS, true);
 
   do_check_true(GMPPrefs.get(GMPPrefs.KEY_LOG_ENABLED));
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_URL), "http://not-really-used");
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_URL_OVERRIDE), "http://not-really-used-2");
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_ADDON_LAST_UPDATE, addon1), "1");
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_ADDON_PATH, addon1), "2");
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_ADDON_VERSION, addon1), "3");
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_ADDON_LAST_UPDATE, addon2), "4");
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_ADDON_PATH, addon2), "5");
   do_check_eq(GMPPrefs.get(GMPPrefs.KEY_ADDON_VERSION, addon2), "6");
+  do_check_eq(GMPPrefs.get(GMPPrefs.KEY_ADDON_AUTOUPDATE, addon2), false);
   do_check_true(GMPPrefs.get(GMPPrefs.KEY_CERT_CHECKATTRS));
+  GMPPrefs.set(GMPPrefs.KEY_ADDON_AUTOUPDATE, true, addon2);
   run_next_test();
 });
 
 /**
  * Tests that an uninit without a check works fine
  */
 add_test(function test_checkForAddons_noResponse() {
   let installManager = new GMPInstallManager();
@@ -473,16 +476,58 @@ function test_checkForAddons_installAddo
   });
 }
 
 add_task(test_checkForAddons_installAddon.bind(null, "1", true, false));
 add_task(test_checkForAddons_installAddon.bind(null, "2", false, false));
 add_task(test_checkForAddons_installAddon.bind(null, "3", true, true));
 
 /**
+ * Tests simpleCheckAndInstall autoupdate disabled
+ */
+add_task(function test_simpleCheckAndInstall() {
+    GMPPrefs.set(GMPPrefs.KEY_ADDON_AUTOUPDATE, false, OPEN_H264_ID);
+    let installManager = new GMPInstallManager();
+    let promise = installManager.simpleCheckAndInstall();
+    promise.then((result) => {
+        do_check_eq(result.status, "check-disabled");
+    }, () => {
+        do_throw("simple check should not reject");
+    });
+});
+
+/**
+ * Tests simpleCheckAndInstall nothing to install
+ */
+add_task(function test_simpleCheckAndInstall() {
+    GMPPrefs.set(GMPPrefs.KEY_ADDON_AUTOUPDATE, true, OPEN_H264_ID);
+    let installManager = new GMPInstallManager();
+    let promise = installManager.simpleCheckAndInstall();
+    promise.then((result) => {
+        do_check_eq(result.status, "nothing-new-to-install");
+    }, () => {
+        do_throw("simple check should not reject");
+    });
+});
+
+/**
+ * Tests simpleCheckAndInstall too frequent
+ */
+add_task(function test_simpleCheckAndInstall() {
+    GMPPrefs.set(GMPPrefs.KEY_ADDON_AUTOUPDATE, true, OPEN_H264_ID);
+    let installManager = new GMPInstallManager();
+    let promise = installManager.simpleCheckAndInstall();
+    promise.then((result) => {
+        do_check_eq(result.status, "too-frequent-no-check");
+    }, () => {
+        do_throw("simple check should not reject");
+    });
+});
+
+/**
  * Tests that installing addons when there is no server works as expected
  */
 add_test(function test_installAddon_noServer() {
   let dir = FileUtils.getDir("TmpD", [], true);
   let zipFileName = "test_GMP.zip";
   let zipURL = URL_HOST + ":0/" + zipFileName;
 
   let data = "e~=0.5772156649";