toolkit/components/downloads/test/unit/test_bug_395092.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 /* 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/. */
     5 // This file tests Bug 395092 - specifically that dl-start event isn't
     6 // dispatched for resumed downloads.
     8 const nsIDownloadManager = Ci.nsIDownloadManager;
     9 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
    11 var observer = {
    12   mCount: 0,
    13   id: 0,
    14   observe: function observe(aSubject, aTopic, aData)
    15   {
    16     print("observering " + aTopic);
    17     if ("dl-start" == aTopic) {
    18       var dl = aSubject.QueryInterface(Ci.nsIDownload);
    19       this.id = dl.id;
    20       dm.pauseDownload(this.id);
    21       this.mCount++;
    22       do_check_eq(1, this.mCount);
    23     } else if ("timer-callback" == aTopic) {
    24       dm.resumeDownload(this.id);
    25     }
    26   }
    27 };
    29 var httpserv = null;
    30 var timer = null;
    31 function run_test()
    32 {
    33   if (oldDownloadManagerDisabled()) {
    34     return;
    35   }
    37   httpserv = new HttpServer();
    38   httpserv.registerDirectory("/", do_get_cwd());
    39   httpserv.start(-1);
    41   // our download listener
    42   var listener = {
    43     onDownloadStateChange: function(aOldState, aDownload)
    44     {
    45       if (Ci.nsIDownloadManager.DOWNLOAD_PAUSED == aDownload.state) {
    46         // This is so hacky, but it let's the nsWebBrowserPersist catch up with
    47         // the script...
    48         timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
    49         timer.init(observer, 0, Ci.nsITimer.TYPE_ONE_SHOT);
    50       }
    52       if (Ci.nsIDownloadManager.DOWNLOAD_FINISHED == aDownload.state)
    53         do_test_finished();
    54     },
    55     onStateChange: function(a, b, c, d, e) { },
    56     onProgressChange: function(a, b, c, d, e, f, g) { },
    57     onSecurityChange: function(a, b, c, d) { }
    58   };
    59   dm.addListener(listener);
    60   dm.addListener(getDownloadListener());
    62   var os = Cc["@mozilla.org/observer-service;1"].
    63            getService(Ci.nsIObserverService);
    64   os.addObserver(observer, "dl-start", false);
    66   addDownload(httpserv);
    67   do_test_pending();
    68 }

mercurial