toolkit/components/downloads/test/browser/browser_bug414214.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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 function test()
     6 {
     7   try {
     8     if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
     9       return;
    10     }
    11   } catch (ex) { }
    13   const PREF_BDM_CLOSEWHENDONE = "browser.download.manager.closeWhenDone";
    14   var dm = Cc["@mozilla.org/download-manager;1"].
    15            getService(Ci.nsIDownloadManager);
    16   var db = dm.DBConnection;
    18   // First, we clean up the DM
    19   db.executeSimpleSQL("DELETE FROM moz_downloads");
    21   // See if the DM is already open, and if it is, close it!
    22   var win = Services.wm.getMostRecentWindow("Download:Manager");
    23   if (win)
    24     win.close();
    26   // We need to set browser.download.manager.closeWhenDone to true to test this
    27   Services.prefs.setBoolPref(PREF_BDM_CLOSEWHENDONE, true);
    29   // register a callback to add a load listener to know when the download
    30   // manager opens
    31   Services.ww.registerNotification(function (aSubject, aTopic, aData) {
    32     Services.ww.unregisterNotification(arguments.callee);
    34     var win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
    35     win.addEventListener("DOMContentLoaded", finishUp, false);
    36   });
    38   // The window doesn't open once we call show, so we need to wait a little bit
    39   function finishUp() {
    40     var dmui = Cc["@mozilla.org/download-manager-ui;1"].
    41                getService(Ci.nsIDownloadManagerUI);
    42     ok(dmui.visible, "Download Manager window is open, as expected.");
    44     // Reset the pref to its default value
    45     try {
    46       Services.prefs.clearUserPref(PREF_BDM_CLOSEWHENDONE);
    47     }
    48     catch (err) { }
    50     finish();
    51   }
    53   // OK, let's pull up the UI
    54   // Linux uses y, everything else is j
    55   var key = navigator.platform.match("Linux") ? "y" : "j";
    56   EventUtils.synthesizeKey(key, {metaKey: true}, window.opener);
    58   waitForExplicitFinish();
    59 }

mercurial