Bug 630575: Properly distinguish soft and hard blocked items in the update pings. r=robstrong, a=dveditz
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 16 Mar 2011 11:58:41 -0700
changeset 27375 72a72241e47c1388c566a12e114f794f422055b5
parent 27374 9c8182d5a5ec2e6163cde544c653f0cdd3b5a9d2
child 27376 cc1618c6d434dd84fb2638d3f08bac3f3874724b
push id2698
push userdtownsend@mozilla.com
push dateWed, 23 Mar 2011 18:27:09 +0000
reviewersrobstrong, dveditz
bugs630575
milestone1.9.1.19pre
Bug 630575: Properly distinguish soft and hard blocked items in the update pings. r=robstrong, a=dveditz
toolkit/mozapps/extensions/src/nsExtensionManager.js.in
toolkit/mozapps/extensions/test/addons/test_bug335238_3/install.rdf
toolkit/mozapps/extensions/test/addons/test_bug335238_4/install.rdf
toolkit/mozapps/extensions/test/unit/test_bug335238.js
--- a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
+++ b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
@@ -6415,21 +6415,29 @@ function escapeAddonURI(aItem, aAppVersi
   else if (aDS.getItemProperty(aItem.id, "type") == Ci.nsIUpdateItem.TYPE_THEME) {
     var currentSkin = gPref.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN);
     if (aDS.getItemProperty(aItem.id, "internalName") != currentSkin)
       itemStatus = "userDisabled";
   }
 
   if (aDS.getItemProperty(aItem.id, "compatible") == "false")
     itemStatus += ",incompatible";
-  if (aDS.getItemProperty(aItem.id, "blocklisted") == "true")
-    itemStatus += ",blocklisted";
   if (aDS.getItemProperty(aItem.id, "satisfiesDependencies") == "false")
     itemStatus += ",needsDependencies";
 
+  var version = aDS.getItemProperty(aItem.id, "version");
+  if (!gBlocklist)
+    gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].
+                 getService(Ci.nsIBlocklistService);
+  var blockState = gBlocklist.getAddonBlocklistState(aItem.id, version);
+  if (blockState == Ci.nsIBlocklistService.STATE_BLOCKED)
+    itemStatus += ",blocklisted";
+  else if (blockState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
+    itemStatus += ",softblocked";
+
   aURI = aURI.replace(/%ITEM_ID%/g, aItem.id);
   aURI = aURI.replace(/%ITEM_VERSION%/g, aItem.version);
   aURI = aURI.replace(/%ITEM_MAXAPPVERSION%/g, aItem.maxAppVersion);
   aURI = aURI.replace(/%ITEM_STATUS%/g, itemStatus);
   aURI = aURI.replace(/%APP_ID%/g, gApp.ID);
   aURI = aURI.replace(/%APP_VERSION%/g, aAppVersion ? aAppVersion : gApp.version);
   aURI = aURI.replace(/%REQ_VERSION%/g, REQ_VERSION);
   aURI = aURI.replace(/%APP_OS%/g, gOSTarget);
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bug335238_3/install.rdf
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>bug335238_3@tests.mozilla.org</em:id>
+    <em:version>58</em:version>
+    
+    <em:targetApplication>
+      <Description>
+        <em:id>xpcshell@tests.mozilla.org</em:id>
+        <em:minVersion>1</em:minVersion>
+        <em:maxVersion>*</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+    
+    <em:name>Bug 335238</em:name>
+    <em:updateURL>http://localhost:4444/2?id=%ITEM_ID%&amp;version=%ITEM_VERSION%&amp;maxAppVersion=%ITEM_MAXAPPVERSION%&amp;status=%ITEM_STATUS%&amp;appId=%APP_ID%&amp;appVersion=%APP_VERSION%&amp;appOs=%APP_OS%&amp;appAbi=%APP_ABI%&amp;locale=%APP_LOCALE%&amp;reqVersion=%REQ_VERSION%</em:updateURL>
+    
+  </Description>      
+</RDF>
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bug335238_4/install.rdf
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>bug335238_4@tests.mozilla.org</em:id>
+    <em:version>4</em:version>
+    
+    <em:targetApplication>
+      <Description>
+        <em:id>xpcshell@tests.mozilla.org</em:id>
+        <em:minVersion>1</em:minVersion>
+        <em:maxVersion>2+</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+    
+    <em:name>Bug 335238</em:name>
+    <em:updateURL>http://localhost:4444/3?id=%ITEM_ID%&amp;version=%ITEM_VERSION%&amp;maxAppVersion=%ITEM_MAXAPPVERSION%&amp;status=%ITEM_STATUS%&amp;appId=%APP_ID%&amp;appVersion=%APP_VERSION%&amp;appOs=%APP_OS%&amp;appAbi=%APP_ABI%&amp;locale=%APP_LOCALE%&amp;reqVersion=%REQ_VERSION%</em:updateURL>
+    
+  </Description>      
+</RDF>
--- a/toolkit/mozapps/extensions/test/unit/test_bug335238.js
+++ b/toolkit/mozapps/extensions/test/unit/test_bug335238.js
@@ -64,26 +64,98 @@ var EXPECTED = [
     maxAppVersion: "7",
     status: "userDisabled,needsDependencies",
     appId: "xpcshell@tests.mozilla.org",
     appVersion: "1",
     appOs: "XPCShell",
     appAbi: "noarch-spidermonkey",
     locale: "en-US",
     reqVersion: "2"
+  },
+  {
+    id: "bug335238_3@tests.mozilla.org",
+    version: "58",
+    maxAppVersion: "*",
+    status: "userDisabled,softblocked",
+    appId: "xpcshell@tests.mozilla.org",
+    appVersion: "1",
+    appOs: "XPCShell",
+    appAbi: "noarch-spidermonkey",
+    locale: "en-US",
+    reqVersion: "2"
+  },
+  {
+    id: "bug335238_4@tests.mozilla.org",
+    version: "4",
+    maxAppVersion: "2+",
+    status: "userEnabled,blocklisted",
+    appId: "xpcshell@tests.mozilla.org",
+    appVersion: "1",
+    appOs: "XPCShell",
+    appAbi: "noarch-spidermonkey",
+    locale: "en-US",
+    reqVersion: "2"
   }
 ];
 
 var ADDONS = [
   {id: "bug335238_1@tests.mozilla.org",
    addon: "test_bug335238_1"},
   {id: "bug335238_2@tests.mozilla.org",
-   addon: "test_bug335238_2"}
+   addon: "test_bug335238_2"},
+  {id: "bug335238_3@tests.mozilla.org",
+   addon: "test_bug335238_3"},
+  {id: "bug335238_4@tests.mozilla.org",
+   addon: "test_bug335238_4"}
 ];
 
+var gEnabledBlocklist = false;
+
+// This is a replacement for the blocklist service
+var BlocklistService = {
+  getAddonBlocklistState: function(aId, aVersion, aAppVersion, aToolkitVersion) {
+    if (gEnabledBlocklist) {
+      if (aId == "bug335238_3@tests.mozilla.org")
+        return Ci.nsIBlocklistService.STATE_SOFTBLOCKED;
+      if (aId == "bug335238_4@tests.mozilla.org")
+        return Ci.nsIBlocklistService.STATE_BLOCKED;
+    }
+
+    return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
+  },
+
+  getPluginBlocklistState: function(aPlugin, aVersion, aAppVersion, aToolkitVersion) {
+    return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
+  },
+
+  isAddonBlocklisted: function(aId, aVersion, aAppVersion, aToolkitVersion) {
+    return this.getAddonBlocklistState(aId, aVersion, aAppVersion, aToolkitVersion) ==
+           Ci.nsIBlocklistService.STATE_BLOCKED;
+  },
+
+  QueryInterface: function(iid) {
+    if (iid.equals(Components.interfaces.nsIBlocklistService)
+     || iid.equals(Components.interfaces.nsISupports))
+      return this;
+
+    throw Components.results.NS_ERROR_NO_INTERFACE;
+  }
+};
+
+var BlocklistServiceFactory = {
+  createInstance: function (outer, iid) {
+    if (outer != null)
+      throw Components.results.NS_ERROR_NO_AGGREGATION;
+    return BlocklistService.QueryInterface(iid);
+  }
+};
+var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "BlocklistService",
+                          "@mozilla.org/extensions/blocklist;1", BlocklistServiceFactory);
+
 var server;
 
 var updateListener = {
   onUpdateStarted: function()
   {
   },
   
   onUpdateEnded: function()
@@ -126,26 +198,32 @@ function run_test() {
 
   startupEM();
   for (var k in ADDONS)
     gEM.installItemFromFile(do_get_addon(ADDONS[k].addon),
                             NS_INSTALL_LOCATION_APPPROFILE);
 
   restartEM();
   gEM.disableItem(ADDONS[1].id);
+  gEM.disableItem(ADDONS[2].id);
   restartEM();
 
+  // Enable the fake blocklist now the items are all installed
+  gEnabledBlocklist = true;
+
   var updates = [];
   for (var k in ADDONS) {
     do_check_neq(gEM.getInstallLocation(ADDONS[k].id), null);
     var addon = gEM.getItemForID(ADDONS[k].id);
     updates.push(addon);
   }
 
   server = new nsHttpServer();
   server.registerPathHandler("/0", requestHandler);
   server.registerPathHandler("/1", requestHandler);
+  server.registerPathHandler("/2", requestHandler);
+  server.registerPathHandler("/3", requestHandler);
   server.start(4444);
   
   gEM.update(updates, updates.length, false, updateListener);
 
   do_test_pending();
 }