michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: let Cr = Components.results; michael@0: michael@0: function test_visibility_open() michael@0: { michael@0: var dmui = Cc["@mozilla.org/download-manager-ui;1"]. michael@0: getService(Ci.nsIDownloadManagerUI); michael@0: is(dmui.visible, true, michael@0: "nsIDownloadManagerUI indicates that the UI is visible"); michael@0: } michael@0: michael@0: function test_getAttention_opened() michael@0: { michael@0: var dmui = Cc["@mozilla.org/download-manager-ui;1"]. michael@0: getService(Ci.nsIDownloadManagerUI); michael@0: michael@0: // switch focus to this window michael@0: window.focus(); michael@0: michael@0: dmui.getAttention(); michael@0: is(dmui.visible, true, michael@0: "nsIDownloadManagerUI indicates that the UI is visible"); michael@0: } michael@0: michael@0: function test_visibility_closed(aWin) michael@0: { michael@0: var dmui = Cc["@mozilla.org/download-manager-ui;1"]. michael@0: getService(Ci.nsIDownloadManagerUI); michael@0: aWin.close(); michael@0: is(dmui.visible, false, michael@0: "nsIDownloadManagerUI indicates that the UI is not visible"); michael@0: } michael@0: michael@0: function test_getAttention_closed() michael@0: { michael@0: var dmui = Cc["@mozilla.org/download-manager-ui;1"]. michael@0: getService(Ci.nsIDownloadManagerUI); michael@0: michael@0: var exceptionCaught = false; michael@0: try { michael@0: dmui.getAttention(); michael@0: } catch (e) { michael@0: is(e.result, Cr.NS_ERROR_UNEXPECTED, michael@0: "Proper exception was caught"); michael@0: exceptionCaught = true; michael@0: } finally { michael@0: is(exceptionCaught, true, michael@0: "Exception was caught, as expected"); michael@0: } michael@0: } michael@0: michael@0: var testFuncs = [ michael@0: test_visibility_open michael@0: , test_getAttention_opened michael@0: , test_visibility_closed /* all tests after this *must* expect there to be michael@0: no open window, otherwise they will fail! */ michael@0: , test_getAttention_closed michael@0: ]; michael@0: michael@0: function test() michael@0: { michael@0: try { michael@0: if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) { michael@0: return; michael@0: } michael@0: } catch (ex) { } michael@0: michael@0: var dm = Cc["@mozilla.org/download-manager;1"]. michael@0: getService(Ci.nsIDownloadManager); michael@0: var db = dm.DBConnection; michael@0: michael@0: // First, we populate the database with some fake data michael@0: db.executeSimpleSQL("DELETE FROM moz_downloads"); michael@0: michael@0: // See if the DM is already open, and if it is, close it! michael@0: var win = Services.wm.getMostRecentWindow("Download:Manager"); michael@0: if (win) michael@0: win.close(); michael@0: michael@0: // Ensure that the download manager callbacks and nsIDownloadManagerUI always michael@0: // use the window UI instead of the panel in the browser's window. michael@0: Services.prefs.setBoolPref("browser.download.useToolkitUI", true); michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.clearUserPref("browser.download.useToolkitUI"); michael@0: }); michael@0: michael@0: // OK, now that all the data is in, let's pull up the UI michael@0: Cc["@mozilla.org/download-manager-ui;1"]. michael@0: getService(Ci.nsIDownloadManagerUI).show(); michael@0: michael@0: // The window doesn't open once we call show, so we need to wait a little bit michael@0: function finishUp() { michael@0: var win = Services.wm.getMostRecentWindow("Download:Manager"); michael@0: michael@0: // Now we can run our tests michael@0: for each (var t in testFuncs) michael@0: t(win); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: waitForExplicitFinish(); michael@0: window.setTimeout(finishUp, 1000); michael@0: }