toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4  */
     6 const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
     7 const PREF_SELECTED_LOCALE = "general.useragent.locale";
     9 // Disables security checking our updates which haven't been signed
    10 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
    12 const Ci = Components.interfaces;
    13 const Cu = Components.utils;
    15 Cu.import("resource://testing-common/httpd.js");
    17 // This is the data we expect to see sent as part of the update url.
    18 var EXPECTED = [
    19   {
    20     id: "bug335238_1@tests.mozilla.org",
    21     version: "1.3.4",
    22     maxAppVersion: "5",
    23     status: "userEnabled",
    24     appId: "xpcshell@tests.mozilla.org",
    25     appVersion: "1",
    26     appOs: "XPCShell",
    27     appAbi: "noarch-spidermonkey",
    28     locale: "en-US",
    29     reqVersion: "2"
    30   },
    31   {
    32     id: "bug335238_2@tests.mozilla.org",
    33     version: "28at",
    34     maxAppVersion: "7",
    35     status: "userDisabled",
    36     appId: "xpcshell@tests.mozilla.org",
    37     appVersion: "1",
    38     appOs: "XPCShell",
    39     appAbi: "noarch-spidermonkey",
    40     locale: "en-US",
    41     reqVersion: "2"
    42   },
    43   {
    44     id: "bug335238_3@tests.mozilla.org",
    45     version: "58",
    46     maxAppVersion: "*",
    47     status: "userDisabled,softblocked",
    48     appId: "xpcshell@tests.mozilla.org",
    49     appVersion: "1",
    50     appOs: "XPCShell",
    51     appAbi: "noarch-spidermonkey",
    52     locale: "en-US",
    53     reqVersion: "2"
    54   },
    55   {
    56     id: "bug335238_4@tests.mozilla.org",
    57     version: "4",
    58     maxAppVersion: "2+",
    59     status: "userEnabled,blocklisted",
    60     appId: "xpcshell@tests.mozilla.org",
    61     appVersion: "1",
    62     appOs: "XPCShell",
    63     appAbi: "noarch-spidermonkey",
    64     locale: "en-US",
    65     reqVersion: "2"
    66   }
    67 ];
    69 var ADDONS = [
    70   {id: "bug335238_1@tests.mozilla.org",
    71    addon: "test_bug335238_1"},
    72   {id: "bug335238_2@tests.mozilla.org",
    73    addon: "test_bug335238_2"},
    74   {id: "bug335238_3@tests.mozilla.org",
    75    addon: "test_bug335238_3"},
    76   {id: "bug335238_4@tests.mozilla.org",
    77    addon: "test_bug335238_4"}
    78 ];
    80 // This is a replacement for the blocklist service
    81 var BlocklistService = {
    82   getAddonBlocklistState: function(aAddon, aAppVersion, aToolkitVersion) {
    83     if (aAddon.id == "bug335238_3@tests.mozilla.org")
    84       return Ci.nsIBlocklistService.STATE_SOFTBLOCKED;
    85     if (aAddon.id == "bug335238_4@tests.mozilla.org")
    86       return Ci.nsIBlocklistService.STATE_BLOCKED;
    87     return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
    88   },
    90   getPluginBlocklistState: function(aPlugin, aVersion, aAppVersion, aToolkitVersion) {
    91     return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
    92   },
    94   isAddonBlocklisted: function(aAddon, aAppVersion, aToolkitVersion) {
    95     return this.getAddonBlocklistState(aAddon, aAppVersion, aToolkitVersion) ==
    96            Ci.nsIBlocklistService.STATE_BLOCKED;
    97   },
    99   QueryInterface: function(iid) {
   100     if (iid.equals(Ci.nsIBlocklistService)
   101      || iid.equals(Ci.nsISupports))
   102       return this;
   104     throw Components.results.NS_ERROR_NO_INTERFACE;
   105   }
   106 };
   108 var BlocklistServiceFactory = {
   109   createInstance: function (outer, iid) {
   110     if (outer != null)
   111       throw Components.results.NS_ERROR_NO_AGGREGATION;
   112     return BlocklistService.QueryInterface(iid);
   113   }
   114 };
   115 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
   116 registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "BlocklistService",
   117                           "@mozilla.org/extensions/blocklist;1", BlocklistServiceFactory);
   119 var server;
   121 var updateListener = {
   122   pendingCount: 0,
   124   onUpdateAvailable: function(aAddon) {
   125     do_throw("Should not have seen an update for " + aAddon.id);
   126   },
   128   onUpdateFinished: function() {
   129     if (--this.pendingCount == 0)
   130       server.stop(do_test_finished);
   131   }
   132 }
   134 var requestHandler = {
   135   handle: function(metadata, response)
   136   {
   137     var expected = EXPECTED[metadata.path.substring(1)];
   138     var params = metadata.queryString.split("&");
   139     do_check_eq(params.length, 10);
   140     for (var k in params) {
   141       var pair = params[k].split("=");
   142       var name = decodeURIComponent(pair[0]);
   143       var value = decodeURIComponent(pair[1]);
   144       do_check_eq(expected[name], value);
   145     }
   146     response.setStatusLine(metadata.httpVersion, 404, "Not Found");
   147   }
   148 }
   150 function run_test() {
   151   do_test_pending();
   152   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
   154   server = new HttpServer();
   155   server.registerPathHandler("/0", requestHandler);
   156   server.registerPathHandler("/1", requestHandler);
   157   server.registerPathHandler("/2", requestHandler);
   158   server.registerPathHandler("/3", requestHandler);
   159   server.start(4444);
   161   Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
   162   Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "en-US");
   164   startupManager();
   165   installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() {
   167     restartManager();
   168     AddonManager.getAddonByID(ADDONS[1].id, callback_soon(function(addon) {
   169       do_check_true(!(!addon));
   170       addon.userDisabled = true;
   171       restartManager();
   173       AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(installedItems) {
   174         installedItems.forEach(function(item) {
   175           updateListener.pendingCount++;
   176           item.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED);
   177         });
   178       });
   179     }));
   180   });
   181 }

mercurial