toolkit/mozapps/extensions/test/xpinstall/browser_offline.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 let proxyPrefValue;
     3 // ----------------------------------------------------------------------------
     4 // Tests that going offline cancels an in progress download.
     5 function test() {
     6   Harness.downloadProgressCallback = download_progress;
     7   Harness.installsCompletedCallback = finish_test;
     8   Harness.setup();
    10   var pm = Services.perms;
    11   pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    13   var triggers = encodeURIComponent(JSON.stringify({
    14     "Unsigned XPI": TESTROOT + "unsigned.xpi"
    15   }));
    16   gBrowser.selectedTab = gBrowser.addTab();
    17   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    18 }
    20 function download_progress(addon, value, maxValue) {
    21   try {
    22     // Tests always connect to localhost, and per bug 87717, localhost is now
    23     // reachable in offline mode.  To avoid this, disable any proxy.
    24     proxyPrefValue = Services.prefs.getIntPref("network.proxy.type");
    25     Services.prefs.setIntPref("network.proxy.type", 0);
    26     Services.io.manageOfflineStatus = false;
    27     Services.io.offline = true;
    28   } catch (ex) {
    29   }
    30 }
    32 function finish_test(count) {
    33   function wait_for_online() {
    34     info("Checking if the browser is still offline...");
    36     let tab = gBrowser.selectedTab;
    37     tab.linkedBrowser.addEventListener("DOMContentLoaded", function errorLoad() {
    38       tab.linkedBrowser.removeEventListener("DOMContentLoaded", errorLoad, true);
    39       let url = tab.linkedBrowser.contentDocument.documentURI;
    40       info("loaded: " + url);
    41       if (/^about:neterror\?e=netOffline/.test(url)) {
    42         wait_for_online();
    43       } else {
    44         gBrowser.removeCurrentTab();
    45         Harness.finish();
    46       }
    47     }, true);
    48     tab.linkedBrowser.loadURI("http://example.com/");
    49   }
    51   is(count, 0, "No add-ons should have been installed");
    52   try {
    53     Services.prefs.setIntPref("network.proxy.type", proxyPrefValue);
    54     Services.io.offline = false;
    55   } catch (ex) {
    56   }
    58   Services.perms.remove("example.com", "install");
    60   wait_for_online();
    61 }

mercurial