toolkit/components/downloads/test/browser/browser_nsIDownloadManagerUI.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/. */
     4 let Cr = Components.results;
     6 function test_visibility_open()
     7 {
     8   var dmui = Cc["@mozilla.org/download-manager-ui;1"].
     9              getService(Ci.nsIDownloadManagerUI);
    10   is(dmui.visible, true,
    11      "nsIDownloadManagerUI indicates that the UI is visible");
    12 }
    14 function test_getAttention_opened()
    15 {
    16   var dmui = Cc["@mozilla.org/download-manager-ui;1"].
    17              getService(Ci.nsIDownloadManagerUI);
    19   // switch focus to this window
    20   window.focus();
    22   dmui.getAttention();
    23   is(dmui.visible, true,
    24      "nsIDownloadManagerUI indicates that the UI is visible");
    25 }
    27 function test_visibility_closed(aWin)
    28 {
    29   var dmui = Cc["@mozilla.org/download-manager-ui;1"].
    30              getService(Ci.nsIDownloadManagerUI);
    31   aWin.close();
    32   is(dmui.visible, false,
    33      "nsIDownloadManagerUI indicates that the UI is not visible");
    34 }
    36 function test_getAttention_closed()
    37 {
    38   var dmui = Cc["@mozilla.org/download-manager-ui;1"].
    39              getService(Ci.nsIDownloadManagerUI);
    41   var exceptionCaught = false;
    42   try {
    43     dmui.getAttention();
    44   } catch (e) {
    45     is(e.result, Cr.NS_ERROR_UNEXPECTED,
    46        "Proper exception was caught");
    47     exceptionCaught = true;
    48   } finally {
    49     is(exceptionCaught, true,
    50        "Exception was caught, as expected");
    51   }
    52 }
    54 var testFuncs = [
    55     test_visibility_open
    56   , test_getAttention_opened
    57   , test_visibility_closed /* all tests after this *must* expect there to be
    58                               no open window, otherwise they will fail! */
    59   , test_getAttention_closed
    60 ];
    62 function test()
    63 {
    64   try {
    65     if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
    66       return;
    67     }
    68   } catch (ex) { }
    70   var dm = Cc["@mozilla.org/download-manager;1"].
    71            getService(Ci.nsIDownloadManager);
    72   var db = dm.DBConnection;
    74   // First, we populate the database with some fake data
    75   db.executeSimpleSQL("DELETE FROM moz_downloads");
    77   // See if the DM is already open, and if it is, close it!
    78   var win = Services.wm.getMostRecentWindow("Download:Manager");
    79   if (win)
    80     win.close();
    82   // Ensure that the download manager callbacks and nsIDownloadManagerUI always
    83   // use the window UI instead of the panel in the browser's window.
    84   Services.prefs.setBoolPref("browser.download.useToolkitUI", true);
    85   registerCleanupFunction(function() {
    86     Services.prefs.clearUserPref("browser.download.useToolkitUI");
    87   });
    89   // OK, now that all the data is in, let's pull up the UI
    90   Cc["@mozilla.org/download-manager-ui;1"].
    91   getService(Ci.nsIDownloadManagerUI).show();
    93   // The window doesn't open once we call show, so we need to wait a little bit
    94   function finishUp() {
    95     var win = Services.wm.getMostRecentWindow("Download:Manager");
    97     // Now we can run our tests
    98     for each (var t in testFuncs)
    99       t(win);
   101     finish();
   102   }
   104   waitForExplicitFinish();
   105   window.setTimeout(finishUp, 1000);
   106 }

mercurial