Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / xpinstall / tests / browser_offline.js
blobb51a19865f142ba1e91f9edcd239469590b5226a
1 // Load in the test harness
2 var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
3                              .getService(Components.interfaces.mozIJSSubScriptLoader);
5 var rootDir = getRootDirectory(window.location.href);
6 scriptLoader.loadSubScript(rootDir + "harness.js", this);
8 // ----------------------------------------------------------------------------
9 // Tests that going offline cancels an in progress download.
10 function test() {
11   Harness.downloadProgressCallback = download_progress;
12   Harness.installEndedCallback = check_xpi_install;
13   Harness.installsCompletedCallback = finish_test;
14   Harness.setup();
16   var pm = Services.perms;
17   pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
19   var triggers = encodeURIComponent(JSON.stringify({
20     "Unsigned XPI": TESTROOT + "unsigned.xpi"
21   }));
22   gBrowser.selectedTab = gBrowser.addTab();
23   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
26 function download_progress(addon, value, maxValue) {
27   try {
28     Services.io.manageOfflineStatus = false;
29     Services.prefs.setBoolPref("browser.offline", true);
30     Services.io.offline = true;
31   } catch (ex) {
32   }
35 function check_xpi_install(addon, status) {
36   is(status, -210, "Install should be cancelled");
39 function finish_test() {
40   try {
41     Services.prefs.setBoolPref("browser.offline", false);
42     Services.io.offline = false;
43   } catch (ex) {
44   }
46   Services.perms.remove("example.com", "install");
48   gBrowser.removeCurrentTab();
49   Harness.finish();