browser/components/downloads/test/browser/browser_first_download_panel.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* Any copyright is dedicated to the Public Domain.
     4    http://creativecommons.org/publicdomain/zero/1.0/ */
     6 /**
     7  * Make sure the downloads panel only opens automatically on the first
     8  * download it notices. All subsequent downloads, even across sessions, should
     9  * not open the panel automatically.
    10  */
    11 function test_task()
    12 {
    13   // Clear the download panel has shown preference first as this test is used to
    14   // verify this preference's behaviour.
    15   let oldPrefValue = true;
    16   try {
    17     oldPrefValue = Services.prefs.getBoolPref("browser.download.panel.shown");
    18   } catch(ex) { }
    19   Services.prefs.setBoolPref("browser.download.panel.shown", false);
    21   try {
    22     // Ensure that state is reset in case previous tests didn't finish.
    23     yield task_resetState();
    25     // With this set to false, we should automatically open the panel the first
    26     // time a download is started.
    27     DownloadsCommon.getData(window).panelHasShownBefore = false;
    29     let promise = promisePanelOpened();
    30     DownloadsCommon.getData(window)._notifyDownloadEvent("start");
    31     yield promise;
    33     // If we got here, that means the panel opened.
    34     DownloadsPanel.hidePanel();
    36     ok(DownloadsCommon.getData(window).panelHasShownBefore,
    37        "Should have recorded that the panel was opened on a download.")
    39     // Next, make sure that if we start another download, we don't open the
    40     // panel automatically.
    41     let originalOnPopupShown = DownloadsPanel.onPopupShown;
    42     DownloadsPanel.onPopupShown = function () {
    43       originalOnPopupShown.apply(this, arguments);
    44       ok(false, "Should not have opened the downloads panel.");
    45     };
    47     try {
    48       DownloadsCommon.getData(window)._notifyDownloadEvent("start");
    50       // Wait 2 seconds to ensure that the panel does not open.
    51       let deferTimeout = Promise.defer();
    52       setTimeout(deferTimeout.resolve, 2000);
    53       yield deferTimeout.promise;
    54     } finally {
    55       DownloadsPanel.onPopupShown = originalOnPopupShown;
    56     }
    57   } finally {
    58     // Clean up when the test finishes.
    59     yield task_resetState();
    60     // Set the preference instead of clearing it afterwards to ensure the
    61     // right value is used no matter what the default was. This ensures the
    62     // panel doesn't appear and affect other tests.
    63     Services.prefs.setBoolPref("browser.download.panel.shown", oldPrefValue);
    64   }
    65 }

mercurial