toolkit/mozapps/extensions/test/xpcshell/test_bug393285.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 {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
     8 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
    10 Cu.import("resource://testing-common/httpd.js");
    11 var testserver = new HttpServer();
    12 testserver.start(-1);
    13 gPort = testserver.identity.primaryPort;
    15 // register static files with server and interpolate port numbers in them
    16 mapFile("/data/test_bug393285.xml", testserver);
    18 const profileDir = gProfD.clone();
    19 profileDir.append("extensions");
    21 let addonIDs = ["test_bug393285_1@tests.mozilla.org",
    22                 "test_bug393285_2@tests.mozilla.org",
    23                 "test_bug393285_3a@tests.mozilla.org",
    24                 "test_bug393285_3b@tests.mozilla.org",
    25                 "test_bug393285_4@tests.mozilla.org",
    26                 "test_bug393285_5@tests.mozilla.org",
    27                 "test_bug393285_6@tests.mozilla.org",
    28                 "test_bug393285_7@tests.mozilla.org",
    29                 "test_bug393285_8@tests.mozilla.org",
    30                 "test_bug393285_9@tests.mozilla.org",
    31                 "test_bug393285_10@tests.mozilla.org",
    32                 "test_bug393285_11@tests.mozilla.org",
    33                 "test_bug393285_12@tests.mozilla.org",
    34                 "test_bug393285_13@tests.mozilla.org",
    35                 "test_bug393285_14@tests.mozilla.org"];
    37 // A window watcher to deal with the blocklist UI dialog.
    38 var WindowWatcher = {
    39   openWindow: function(parent, url, name, features, arguments) {
    40     // Should be called to list the newly blocklisted items
    41     do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG);
    43     // Simulate auto-disabling any softblocks
    44     var list = arguments.wrappedJSObject.list;
    45     list.forEach(function(aItem) {
    46       if (!aItem.blocked)
    47         aItem.disable = true;
    48     });
    50     //run the code after the blocklist is closed
    51     Services.obs.notifyObservers(null, "addon-blocklist-closed", null);
    53   },
    55   QueryInterface: function(iid) {
    56     if (iid.equals(Ci.nsIWindowWatcher)
    57      || iid.equals(Ci.nsISupports))
    58       return this;
    60     throw Cr.NS_ERROR_NO_INTERFACE;
    61   }
    62 };
    64 var WindowWatcherFactory = {
    65   createInstance: function createInstance(outer, iid) {
    66     if (outer != null)
    67       throw Cr.NS_ERROR_NO_AGGREGATION;
    68     return WindowWatcher.QueryInterface(iid);
    69   }
    70 };
    72 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
    73 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
    74                           "Fake Window Watcher",
    75                           "@mozilla.org/embedcomp/window-watcher;1",
    76                           WindowWatcherFactory);
    79 function load_blocklist(aFile, aCallback) {
    80   Services.obs.addObserver(function() {
    81     Services.obs.removeObserver(arguments.callee, "blocklist-updated");
    83     do_execute_soon(aCallback);
    84   }, "blocklist-updated", false);
    86   Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
    87                              gPort + "/data/" + aFile);
    88   var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
    89                   getService(Ci.nsITimerCallback);
    90   blocklist.notify(null);
    91 }
    94 function end_test() {
    95   testserver.stop(do_test_finished);
    96 }
    98 function run_test() {
    99   do_test_pending();
   101   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
   103   writeInstallRDFForExtension({
   104     id: "test_bug393285_1@tests.mozilla.org",
   105     name: "extension 1",
   106     version: "1.0",
   107     targetApplications: [{
   108       id: "xpcshell@tests.mozilla.org",
   109       minVersion: "1",
   110       maxVersion: "3"
   111     }]
   112   }, profileDir);
   115   writeInstallRDFForExtension({
   116     id: "test_bug393285_2@tests.mozilla.org",
   117     name: "extension 2",
   118     version: "1.0",
   119     targetApplications: [{
   120       id: "xpcshell@tests.mozilla.org",
   121       minVersion: "1",
   122       maxVersion: "3"
   123     }]
   124   }, profileDir);
   126   writeInstallRDFForExtension({
   127     id: "test_bug393285_3a@tests.mozilla.org",
   128     name: "extension 3a",
   129     version: "1.0",
   130     targetApplications: [{
   131       id: "xpcshell@tests.mozilla.org",
   132       minVersion: "1",
   133       maxVersion: "3"
   134     }]
   135   }, profileDir);
   137   writeInstallRDFForExtension({
   138     id: "test_bug393285_3b@tests.mozilla.org",
   139     name: "extension 3b",
   140     version: "2.0",
   141     targetApplications: [{
   142       id: "xpcshell@tests.mozilla.org",
   143       minVersion: "1",
   144       maxVersion: "3"
   145     }]
   146   }, profileDir);
   148   writeInstallRDFForExtension({
   149     id: "test_bug393285_4@tests.mozilla.org",
   150     name: "extension 4",
   151     version: "1.0",
   152     targetApplications: [{
   153       id: "xpcshell@tests.mozilla.org",
   154       minVersion: "1",
   155       maxVersion: "3"
   156     }]
   157   }, profileDir);
   159   writeInstallRDFForExtension({
   160     id: "test_bug393285_5@tests.mozilla.org",
   161     name: "extension 5",
   162     version: "1.0",
   163     targetApplications: [{
   164       id: "xpcshell@tests.mozilla.org",
   165       minVersion: "1",
   166       maxVersion: "3"
   167     }]
   168   }, profileDir);
   170   writeInstallRDFForExtension({
   171     id: "test_bug393285_6@tests.mozilla.org",
   172     name: "extension 6",
   173     version: "1.0",
   174     targetApplications: [{
   175       id: "xpcshell@tests.mozilla.org",
   176       minVersion: "1",
   177       maxVersion: "3"
   178     }]
   179   }, profileDir);
   181   writeInstallRDFForExtension({
   182     id: "test_bug393285_7@tests.mozilla.org",
   183     name: "extension 7",
   184     version: "1.0",
   185     targetApplications: [{
   186       id: "xpcshell@tests.mozilla.org",
   187       minVersion: "1",
   188       maxVersion: "3"
   189     }]
   190   }, profileDir);
   192   writeInstallRDFForExtension({
   193     id: "test_bug393285_8@tests.mozilla.org",
   194     name: "extension 8",
   195     version: "1.0",
   196     targetApplications: [{
   197       id: "xpcshell@tests.mozilla.org",
   198       minVersion: "1",
   199       maxVersion: "3"
   200     }]
   201   }, profileDir);
   203   writeInstallRDFForExtension({
   204     id: "test_bug393285_9@tests.mozilla.org",
   205     name: "extension 9",
   206     version: "1.0",
   207     targetApplications: [{
   208       id: "xpcshell@tests.mozilla.org",
   209       minVersion: "1",
   210       maxVersion: "3"
   211     }]
   212   }, profileDir);
   214   writeInstallRDFForExtension({
   215     id: "test_bug393285_10@tests.mozilla.org",
   216     name: "extension 10",
   217     version: "1.0",
   218     targetApplications: [{
   219       id: "xpcshell@tests.mozilla.org",
   220       minVersion: "1",
   221       maxVersion: "3"
   222     }]
   223   }, profileDir);
   225   writeInstallRDFForExtension({
   226     id: "test_bug393285_11@tests.mozilla.org",
   227     name: "extension 11",
   228     version: "1.0",
   229     targetApplications: [{
   230       id: "xpcshell@tests.mozilla.org",
   231       minVersion: "1",
   232       maxVersion: "3"
   233     }]
   234   }, profileDir);
   236   writeInstallRDFForExtension({
   237     id: "test_bug393285_12@tests.mozilla.org",
   238     name: "extension 12",
   239     version: "1.0",
   240     targetApplications: [{
   241       id: "xpcshell@tests.mozilla.org",
   242       minVersion: "1",
   243       maxVersion: "3"
   244     }]
   245   }, profileDir);
   247   writeInstallRDFForExtension({
   248     id: "test_bug393285_13@tests.mozilla.org",
   249     name: "extension 13",
   250     version: "1.0",
   251     targetApplications: [{
   252       id: "xpcshell@tests.mozilla.org",
   253       minVersion: "1",
   254       maxVersion: "3"
   255     }]
   256   }, profileDir);
   258   writeInstallRDFForExtension({
   259     id: "test_bug393285_14@tests.mozilla.org",
   260     name: "extension 14",
   261     version: "1.0",
   262     targetApplications: [{
   263       id: "xpcshell@tests.mozilla.org",
   264       minVersion: "1",
   265       maxVersion: "3"
   266     }]
   267   }, profileDir);
   269   startupManager();
   271   AddonManager.getAddonsByIDs(addonIDs, function(addons) {
   272     for (addon of addons) {
   273       do_check_eq(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   274     }
   275     run_test_1();
   276   });
   277 }
   279 function run_test_1() {
   280   load_blocklist("test_bug393285.xml", function() {
   281     restartManager();
   283     var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]
   284                     .getService(Ci.nsIBlocklistService);
   286     AddonManager.getAddonsByIDs(addonIDs,
   287                                function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
   288                                          a11, a12, a13, a14, a15]) {
   289       // No info in blocklist, shouldn't be blocked
   290       do_check_false(blocklist.isAddonBlocklisted(a1, "1", "1.9"));
   292       // Should always be blocked
   293       do_check_true(blocklist.isAddonBlocklisted(a2, "1", "1.9"));
   295       // Only version 1 should be blocked
   296       do_check_true(blocklist.isAddonBlocklisted(a3, "1", "1.9"));
   297       do_check_false(blocklist.isAddonBlocklisted(a4, "1", "1.9"));
   299       // Should be blocked for app version 1
   300       do_check_true(blocklist.isAddonBlocklisted(a5, "1", "1.9"));
   301       do_check_false(blocklist.isAddonBlocklisted(a5, "2", "1.9"));
   303       // Not blocklisted because we are a different OS
   304       do_check_false(blocklist.isAddonBlocklisted(a6, "2", "1.9"));
   306       // Blocklisted based on OS
   307       do_check_true(blocklist.isAddonBlocklisted(a7, "2", "1.9"));
   308       do_check_true(blocklist.isAddonBlocklisted(a8, "2", "1.9"));
   310       // Not blocklisted because we are a different ABI
   311       do_check_false(blocklist.isAddonBlocklisted(a9, "2", "1.9"));
   313       // Blocklisted based on ABI
   314       do_check_true(blocklist.isAddonBlocklisted(a10, "2", "1.9"));
   315       do_check_true(blocklist.isAddonBlocklisted(a11, "2", "1.9"));
   317       // Doesnt match both os and abi so not blocked
   318       do_check_false(blocklist.isAddonBlocklisted(a12, "2", "1.9"));
   319       do_check_false(blocklist.isAddonBlocklisted(a13, "2", "1.9"));
   320       do_check_false(blocklist.isAddonBlocklisted(a14, "2", "1.9"));
   322       // Matches both os and abi so blocked
   323       do_check_true(blocklist.isAddonBlocklisted(a15, "2", "1.9"));
   324       end_test();
   325     });
   326   });
   327 }

mercurial