toolkit/mozapps/extensions/test/xpcshell/test_bug324121.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 // Disables security checking our updates which haven't been signed
     7 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
     9 // Get the HTTP server.
    10 Components.utils.import("resource://testing-common/httpd.js");
    11 var testserver;
    13 var next_test = null;
    14 var gItemsNotChecked =[];
    16 var ADDONS = [ {id: "bug324121_1@tests.mozilla.org",
    17                 addon: "test_bug324121_1",
    18                 shouldCheck: false },
    19                {id: "bug324121_2@tests.mozilla.org",
    20                 addon: "test_bug324121_2",
    21                 shouldCheck: true },
    22                {id: "bug324121_3@tests.mozilla.org",
    23                 addon: "test_bug324121_3",
    24                 shouldCheck: true },
    25                {id: "bug324121_4@tests.mozilla.org",
    26                 addon: "test_bug324121_4",
    27                 shouldCheck: true },
    28                {id: "bug324121_5@tests.mozilla.org",
    29                 addon: "test_bug324121_5",
    30                 shouldCheck: false },
    31                {id: "bug324121_6@tests.mozilla.org",
    32                 addon: "test_bug324121_6",
    33                 shouldCheck: true },
    34                {id: "bug324121_7@tests.mozilla.org",
    35                 addon: "test_bug324121_7",
    36                 shouldCheck: true },
    37                {id: "bug324121_8@tests.mozilla.org",
    38                 addon: "test_bug324121_8",
    39                 shouldCheck: true },
    40                {id: "bug324121_9@tests.mozilla.org",
    41                 addon: "test_bug324121_9",
    42                 shouldCheck: false } ];
    44 // nsIAddonUpdateCheckListener
    45 var updateListener = {
    46   pendingCount: 0,
    48   onUpdateAvailable: function onAddonUpdateEnded(aAddon) {
    49     switch (aAddon.id) {
    50       // add-on disabled - should not happen
    51       case "bug324121_1@tests.mozilla.org":
    52       // app id already compatible - should not happen
    53       case "bug324121_5@tests.mozilla.org":
    54       // toolkit id already compatible - should not happen
    55       case "bug324121_9@tests.mozilla.org":
    56         do_throw("Should not have seen an update check for " + aAddon.id);
    57         break;
    59       // app id incompatible update available
    60       case "bug324121_3@tests.mozilla.org":
    61       // update rdf not found
    62       case "bug324121_4@tests.mozilla.org":
    63       // toolkit id incompatible update available
    64       case "bug324121_7@tests.mozilla.org":
    65       // update rdf not found
    66       case "bug324121_8@tests.mozilla.org":
    67         do_throw("Should be no update available for " + aAddon.id);
    68         break;
    70       // Updates available
    71       case "bug324121_2@tests.mozilla.org":
    72       case "bug324121_6@tests.mozilla.org":
    73         break;
    75       default:
    76         do_throw("Update check for unknown " + aAddon.id);
    77     }
    79     // pos should always be >= 0 so just let this throw if this fails
    80     var pos = gItemsNotChecked.indexOf(aAddon.id);
    81     gItemsNotChecked.splice(pos, 1);
    82   },
    84   onNoUpdateAvailable: function onNoUpdateAvailable(aAddon) {
    85     switch (aAddon.id) {
    86       // add-on disabled - should not happen
    87       case "bug324121_1@tests.mozilla.org":
    88       // app id already compatible - should not happen
    89       case "bug324121_5@tests.mozilla.org":
    90       // toolkit id already compatible - should not happen
    91       case "bug324121_9@tests.mozilla.org":
    92         do_throw("Should not have seen an update check for " + aAddon.id);
    93         break;
    95       // app id incompatible update available
    96       case "bug324121_3@tests.mozilla.org":
    97       // update rdf not found
    98       case "bug324121_4@tests.mozilla.org":
    99       // toolkit id incompatible update available
   100       case "bug324121_7@tests.mozilla.org":
   101       // update rdf not found
   102       case "bug324121_8@tests.mozilla.org":
   103         break;
   105       // Updates available
   106       case "bug324121_2@tests.mozilla.org":
   107       case "bug324121_6@tests.mozilla.org":
   108         do_throw("Should be an update available for " + aAddon.id);
   109         break;
   111       default:
   112         do_throw("Update check for unknown " + aAddon.id);
   113     }
   115     // pos should always be >= 0 so just let this throw if this fails
   116     var pos = gItemsNotChecked.indexOf(aAddon.id);
   117     gItemsNotChecked.splice(pos, 1);
   118   },
   120   onUpdateFinished: function onUpdateFinished(aAddon) {
   121     if (--this.pendingCount == 0)
   122       test_complete();
   123   }
   124 };
   126 function run_test() {
   127   do_test_pending();
   128   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
   130   const dataDir = do_get_file("data");
   132   // Create and configure the HTTP server.
   133   testserver = new HttpServer();
   134   testserver.registerDirectory("/data/", dataDir);
   135   testserver.start(4444);
   137   startupManager();
   139   installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() {
   140     restartManager();
   141     AddonManager.getAddonByID(ADDONS[0].id, callback_soon(function(addon) {
   142       do_check_true(!(!addon));
   143       addon.userDisabled = true;
   144       restartManager();
   146       AddonManager.getAddonsByTypes(["extension"], function(installedItems) {
   147         var items = [];
   149         for (let addon of ADDONS) {
   150           for (let installedItem of installedItems) {
   151             if (addon.id != installedItem.id)
   152               continue;
   153             if (installedItem.userDisabled)
   154               continue;
   156             if (addon.shouldCheck == installedItem.isCompatibleWith("3", "3")) {
   157               do_throw(installedItem.id + " had the wrong compatibility: " +
   158                 installedItem.isCompatibleWith("3", "3"));
   159             }
   161             if (addon.shouldCheck) {
   162               gItemsNotChecked.push(addon.id);
   163               updateListener.pendingCount++;
   164               installedItem.findUpdates(updateListener,
   165                                             AddonManager.UPDATE_WHEN_USER_REQUESTED,
   166                                             "3", "3");
   167             }
   168           }
   169         }
   170       });
   171     }));
   172   });
   173 }
   175 function test_complete() {
   176   do_check_eq(gItemsNotChecked.length, 0);
   177   testserver.stop(do_test_finished);
   178 }

mercurial