Bug 630575: Properly distinguish soft and hard blocked items in the update pings. r=Unfocused, a=gavin
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 10 Feb 2011 10:34:55 -0800
changeset 62300 53d06f07a4d2bacb18a217d243973d97eafdd7ca
parent 62299 75663a5ad23e7a34e514b4f12d7f2c6d21cd0717
child 62301 d1c5def46796203e45f690aa1047283c09bb4aa9
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersUnfocused, gavin
bugs630575
milestone2.0b12pre
Bug 630575: Properly distinguish soft and hard blocked items in the update pings. r=Unfocused, a=gavin
toolkit/mozapps/extensions/XPIProvider.jsm
toolkit/mozapps/extensions/test/addons/test_bug335238_3/install.rdf
toolkit/mozapps/extensions/test/addons/test_bug335238_4/install.rdf
toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -953,18 +953,20 @@ function verifyZipSigning(aZip, aPrincip
  * @return the appropriately escaped uri.
  */
 function escapeAddonURI(aAddon, aUri, aUpdateType, aAppVersion)
 {
   var addonStatus = aAddon.userDisabled ? "userDisabled" : "userEnabled";
 
   if (!aAddon.isCompatible)
     addonStatus += ",incompatible";
-  if (aAddon.blocklistState > 0)
+  if (aAddon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
     addonStatus += ",blocklisted";
+  if (aAddon.blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED)
+    addonStatus += ",softblocked";
 
   try {
     var xpcomABI = Services.appinfo.XPCOMABI;
   } catch (ex) {
     xpcomABI = UNKNOWN_XPCOM_ABI;
   }
 
   let uri = aUri.replace(/%ITEM_ID%/g, aAddon.id);
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bug335238_3/install.rdf
@@ -0,0 +1,30 @@
+<?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:requires>
+      <Description>
+        <em:id>unknown@tests.mozilla.org</em:id>
+        <em:minVersion>2</em:minVersion>
+        <em:maxVersion>72</em:maxVersion>
+      </Description>
+    </em:requires>
+    
+    <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,30 @@
+<?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:requires>
+      <Description>
+        <em:id>unknown@tests.mozilla.org</em:id>
+        <em:minVersion>2</em:minVersion>
+        <em:maxVersion>72</em:maxVersion>
+      </Description>
+    </em:requires>
+    
+    <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/xpcshell/test_bug335238.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js
@@ -64,26 +64,93 @@ var EXPECTED = [
     maxAppVersion: "7",
     status: "userDisabled",
     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"}
 ];
 
+// This is a replacement for the blocklist service
+var BlocklistService = {
+  getAddonBlocklistState: function(aId, aVersion, aAppVersion, aToolkitVersion) {
+    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 = {
   pendingCount: 0,
 
   onUpdateAvailable: function(aAddon) {
     do_throw("Should not have seen an update for " + aAddon.id);
   },
@@ -112,16 +179,18 @@ var requestHandler = {
 
 function run_test() {
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
   server = new nsHttpServer();
   server.registerPathHandler("/0", requestHandler);
   server.registerPathHandler("/1", requestHandler);
+  server.registerPathHandler("/2", requestHandler);
+  server.registerPathHandler("/3", requestHandler);
   server.start(4444);
 
   Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
   Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "en-US");
 
   startupManager();
   installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() {