toolkit/mozapps/extensions/test/xpcshell/test_hotfix.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 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // This verifies that hotfix installation works
     7 // The test extension uses an insecure update url.
     8 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
     9 // Ignore any certificate requirements the app has set
    10 Services.prefs.setBoolPref("extensions.hotfix.cert.checkAttributes", false);
    12 Components.utils.import("resource://testing-common/httpd.js");
    13 var testserver = new HttpServer();
    14 testserver.start(-1);
    15 gPort = testserver.identity.primaryPort;
    16 testserver.registerDirectory("/addons/", do_get_file("addons"));
    17 mapFile("/data/test_hotfix_1.rdf", testserver);
    18 mapFile("/data/test_hotfix_2.rdf", testserver);
    19 mapFile("/data/test_hotfix_3.rdf", testserver);
    21 const profileDir = gProfD.clone();
    22 profileDir.append("extensions");
    24 function run_test() {
    25   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    27   startupManager();
    29   do_test_pending();
    30   run_test_1();
    31 }
    33 function end_test() {
    34   testserver.stop(do_test_finished);
    35 }
    37 // Test that background updates find and install any available hotfix
    38 function run_test_1() {
    39   Services.prefs.setCharPref("extensions.hotfix.id", "hotfix@tests.mozilla.org");
    40   Services.prefs.setCharPref("extensions.update.background.url", "http://localhost:" +
    41                              gPort + "/data/test_hotfix_1.rdf");
    43   prepare_test({
    44     "hotfix@tests.mozilla.org": [
    45       "onInstalling"
    46     ]
    47   }, [
    48     "onNewInstall",
    49     "onDownloadStarted",
    50     "onDownloadEnded",
    51     "onInstallStarted",
    52     "onInstallEnded",
    53   ], callback_soon(check_test_1));
    55   // Fake a timer event
    56   gInternalManager.notify(null);
    57 }
    59 function check_test_1() {
    60   restartManager();
    62   AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
    63     do_check_neq(aAddon, null);
    64     do_check_eq(aAddon.version, "1.0");
    66     aAddon.uninstall();
    67     do_execute_soon(run_test_2);
    68   });
    69 }
    71 // Don't install an already used hotfix
    72 function run_test_2() {
    73   restartManager();
    75   AddonManager.addInstallListener({
    76     onNewInstall: function() {
    77       do_throw("Should not have seen a new install created");
    78     }
    79   });
    81   function observer() {
    82     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
    83     do_execute_soon(run_test_3);
    84   }
    86   Services.obs.addObserver(observer, "addons-background-update-complete", false);
    88   // Fake a timer event
    89   gInternalManager.notify(null);
    90 }
    92 // Install a newer hotfix
    93 function run_test_3() {
    94   restartManager();
    95   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
    96                              gPort + "/data/test_hotfix_2.rdf");
    98   prepare_test({
    99     "hotfix@tests.mozilla.org": [
   100       "onInstalling"
   101     ]
   102   }, [
   103     "onNewInstall",
   104     "onDownloadStarted",
   105     "onDownloadEnded",
   106     "onInstallStarted",
   107     "onInstallEnded",
   108   ], callback_soon(check_test_3));
   110   // Fake a timer event
   111   gInternalManager.notify(null);
   112 }
   114 function check_test_3() {
   115   restartManager();
   117   AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
   118     do_check_neq(aAddon, null);
   119     do_check_eq(aAddon.version, "2.0");
   121     aAddon.uninstall();
   122     do_execute_soon(run_test_4);
   123   });
   124 }
   126 // Don't install an incompatible hotfix
   127 function run_test_4() {
   128   restartManager();
   130   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
   131                              gPort + "/data/test_hotfix_3.rdf");
   133   AddonManager.addInstallListener({
   134     onNewInstall: function() {
   135       do_throw("Should not have seen a new install created");
   136     }
   137   });
   139   function observer() {
   140     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
   141     do_execute_soon(run_test_5);
   142   }
   144   Services.obs.addObserver(observer, "addons-background-update-complete", false);
   146   // Fake a timer event
   147   gInternalManager.notify(null);
   148 }
   150 // Don't install an older hotfix
   151 function run_test_5() {
   152   restartManager();
   154   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
   155                              gPort + "/data/test_hotfix_1.rdf");
   157   AddonManager.addInstallListener({
   158     onNewInstall: function() {
   159       do_throw("Should not have seen a new install created");
   160     }
   161   });
   163   function observer() {
   164     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
   165     do_execute_soon(run_test_6);
   166   }
   168   Services.obs.addObserver(observer, "addons-background-update-complete", false);
   170   // Fake a timer event
   171   gInternalManager.notify(null);
   172 }
   174 // Don't re-download an already pending install
   175 function run_test_6() {
   176   restartManager();
   178   Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
   179   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
   180                              gPort + "/data/test_hotfix_1.rdf");
   182   prepare_test({
   183     "hotfix@tests.mozilla.org": [
   184       "onInstalling"
   185     ]
   186   }, [
   187     "onNewInstall",
   188     "onDownloadStarted",
   189     "onDownloadEnded",
   190     "onInstallStarted",
   191     "onInstallEnded",
   192   ], callback_soon(check_test_6));
   194   // Fake a timer event
   195   gInternalManager.notify(null);
   196 }
   198 function check_test_6() {
   199   AddonManager.addInstallListener({
   200     onNewInstall: function() {
   201       do_throw("Should not have seen a new install created");
   202     }
   203   });
   205   function observer() {
   206     Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
   207     restartManager();
   209     AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
   210       aAddon.uninstall();
   211       do_execute_soon(run_test_7);
   212     });
   213   }
   215   Services.obs.addObserver(observer, "addons-background-update-complete", false);
   217   // Fake a timer event
   218   gInternalManager.notify(null);
   219 }
   221 // Start downloading again if something cancels the install
   222 function run_test_7() {
   223   restartManager();
   225   Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
   227   prepare_test({
   228     "hotfix@tests.mozilla.org": [
   229       "onInstalling"
   230     ]
   231   }, [
   232     "onNewInstall",
   233     "onDownloadStarted",
   234     "onDownloadEnded",
   235     "onInstallStarted",
   236     "onInstallEnded",
   237   ], check_test_7);
   239   // Fake a timer event
   240   gInternalManager.notify(null);
   241 }
   243 function check_test_7(aInstall) {
   244   prepare_test({
   245     "hotfix@tests.mozilla.org": [
   246       "onOperationCancelled"
   247     ]
   248   }, [
   249     "onInstallCancelled",
   250   ]);
   252   aInstall.cancel();
   254   prepare_test({
   255     "hotfix@tests.mozilla.org": [
   256       "onInstalling"
   257     ]
   258   }, [
   259     "onNewInstall",
   260     "onDownloadStarted",
   261     "onDownloadEnded",
   262     "onInstallStarted",
   263     "onInstallEnded",
   264   ], callback_soon(finish_test_7));
   266   // Fake a timer event
   267   gInternalManager.notify(null);
   268 }
   270 function finish_test_7() {
   271   restartManager();
   273   AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) {
   274     do_check_neq(aAddon, null);
   275     do_check_eq(aAddon.version, "1.0");
   277     aAddon.uninstall();
   278     do_execute_soon(run_test_8);
   279   });
   280 }
   282 // Cancel a pending install when a newer version is already available
   283 function run_test_8() {
   284   restartManager();
   286   Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0");
   287   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
   288                              gPort + "/data/test_hotfix_1.rdf");
   290   prepare_test({
   291     "hotfix@tests.mozilla.org": [
   292       "onInstalling"
   293     ]
   294   }, [
   295     "onNewInstall",
   296     "onDownloadStarted",
   297     "onDownloadEnded",
   298     "onInstallStarted",
   299     "onInstallEnded",
   300   ], check_test_8);
   302   // Fake a timer event
   303   gInternalManager.notify(null);
   304 }
   306 function check_test_8() {
   307   Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" +
   308                              gPort + "/data/test_hotfix_2.rdf");
   310   prepare_test({
   311     "hotfix@tests.mozilla.org": [
   312       "onOperationCancelled",
   313       "onInstalling"
   314     ]
   315   }, [
   316     "onNewInstall",
   317     "onDownloadStarted",
   318     "onDownloadEnded",
   319     "onInstallStarted",
   320     "onInstallCancelled",
   321     "onInstallEnded",
   322   ], finish_test_8);
   324   // Fake a timer event
   325   gInternalManager.notify(null);
   326 }
   328 function finish_test_8() {
   329   AddonManager.getAllInstalls(callback_soon(function(aInstalls) {
   330     do_check_eq(aInstalls.length, 1);
   331     do_check_eq(aInstalls[0].version, "2.0");
   333     restartManager();
   335     AddonManager.getAddonByID("hotfix@tests.mozilla.org", callback_soon(function(aAddon) {
   336       do_check_neq(aAddon, null);
   337       do_check_eq(aAddon.version, "2.0");
   339       aAddon.uninstall();
   340       restartManager();
   342       end_test();
   343     }));
   344   }));
   345 }

mercurial