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

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:25404866d408
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;
5
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 }
13
14 function test_getAttention_opened()
15 {
16 var dmui = Cc["@mozilla.org/download-manager-ui;1"].
17 getService(Ci.nsIDownloadManagerUI);
18
19 // switch focus to this window
20 window.focus();
21
22 dmui.getAttention();
23 is(dmui.visible, true,
24 "nsIDownloadManagerUI indicates that the UI is visible");
25 }
26
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 }
35
36 function test_getAttention_closed()
37 {
38 var dmui = Cc["@mozilla.org/download-manager-ui;1"].
39 getService(Ci.nsIDownloadManagerUI);
40
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 }
53
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 ];
61
62 function test()
63 {
64 try {
65 if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
66 return;
67 }
68 } catch (ex) { }
69
70 var dm = Cc["@mozilla.org/download-manager;1"].
71 getService(Ci.nsIDownloadManager);
72 var db = dm.DBConnection;
73
74 // First, we populate the database with some fake data
75 db.executeSimpleSQL("DELETE FROM moz_downloads");
76
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();
81
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 });
88
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();
92
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");
96
97 // Now we can run our tests
98 for each (var t in testFuncs)
99 t(win);
100
101 finish();
102 }
103
104 waitForExplicitFinish();
105 window.setTimeout(finishUp, 1000);
106 }

mercurial