Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function test() |
michael@0 | 6 | { |
michael@0 | 7 | try { |
michael@0 | 8 | if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) { |
michael@0 | 9 | return; |
michael@0 | 10 | } |
michael@0 | 11 | } catch (ex) { } |
michael@0 | 12 | |
michael@0 | 13 | const PREF_BDM_CLOSEWHENDONE = "browser.download.manager.closeWhenDone"; |
michael@0 | 14 | var dm = Cc["@mozilla.org/download-manager;1"]. |
michael@0 | 15 | getService(Ci.nsIDownloadManager); |
michael@0 | 16 | var db = dm.DBConnection; |
michael@0 | 17 | |
michael@0 | 18 | // First, we clean up the DM |
michael@0 | 19 | db.executeSimpleSQL("DELETE FROM moz_downloads"); |
michael@0 | 20 | |
michael@0 | 21 | // See if the DM is already open, and if it is, close it! |
michael@0 | 22 | var win = Services.wm.getMostRecentWindow("Download:Manager"); |
michael@0 | 23 | if (win) |
michael@0 | 24 | win.close(); |
michael@0 | 25 | |
michael@0 | 26 | // We need to set browser.download.manager.closeWhenDone to true to test this |
michael@0 | 27 | Services.prefs.setBoolPref(PREF_BDM_CLOSEWHENDONE, true); |
michael@0 | 28 | |
michael@0 | 29 | // register a callback to add a load listener to know when the download |
michael@0 | 30 | // manager opens |
michael@0 | 31 | Services.ww.registerNotification(function (aSubject, aTopic, aData) { |
michael@0 | 32 | Services.ww.unregisterNotification(arguments.callee); |
michael@0 | 33 | |
michael@0 | 34 | var win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); |
michael@0 | 35 | win.addEventListener("DOMContentLoaded", finishUp, false); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | // The window doesn't open once we call show, so we need to wait a little bit |
michael@0 | 39 | function finishUp() { |
michael@0 | 40 | var dmui = Cc["@mozilla.org/download-manager-ui;1"]. |
michael@0 | 41 | getService(Ci.nsIDownloadManagerUI); |
michael@0 | 42 | ok(dmui.visible, "Download Manager window is open, as expected."); |
michael@0 | 43 | |
michael@0 | 44 | // Reset the pref to its default value |
michael@0 | 45 | try { |
michael@0 | 46 | Services.prefs.clearUserPref(PREF_BDM_CLOSEWHENDONE); |
michael@0 | 47 | } |
michael@0 | 48 | catch (err) { } |
michael@0 | 49 | |
michael@0 | 50 | finish(); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | // OK, let's pull up the UI |
michael@0 | 54 | // Linux uses y, everything else is j |
michael@0 | 55 | var key = navigator.platform.match("Linux") ? "y" : "j"; |
michael@0 | 56 | EventUtils.synthesizeKey(key, {metaKey: true}, window.opener); |
michael@0 | 57 | |
michael@0 | 58 | waitForExplicitFinish(); |
michael@0 | 59 | } |