|
1 <?xml version="1.0"?> |
|
2 <!-- This Source Code Form is subject to the terms of the Mozilla Public |
|
3 - License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
|
5 <!-- |
|
6 * This tests that the Windows 7 Taskbar Progress is correctly updated when |
|
7 * windows are opened and closed. |
|
8 --> |
|
9 |
|
10 <window title="Win7 Taskbar Progress" |
|
11 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
12 onload="test();"> |
|
13 |
|
14 <script type="application/javascript" |
|
15 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
16 <script type="application/javascript" |
|
17 src="utils.js"/> |
|
18 |
|
19 <script type="application/javascript"> |
|
20 <![CDATA[ |
|
21 |
|
22 const kTaskbarID = "@mozilla.org/windows-taskbar;1"; |
|
23 const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul"; |
|
24 const DLMGR_UI_DONE = "download-manager-ui-done"; |
|
25 |
|
26 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
27 |
|
28 let DownloadTaskbarProgress, TaskbarService, observerService, wwatch, chromeWindow; |
|
29 let gGen = null; |
|
30 |
|
31 function test() { |
|
32 var dmui = getDMUI(); |
|
33 if (!dmui) { |
|
34 todo(false, "skip test for toolkit download manager UI"); |
|
35 return; |
|
36 } |
|
37 |
|
38 let isWin7OrHigher = false; |
|
39 try { |
|
40 let version = Cc["@mozilla.org/system-info;1"] |
|
41 .getService(Ci.nsIPropertyBag2) |
|
42 .getProperty("version"); |
|
43 isWin7OrHigher = (parseFloat(version) >= 6.1); |
|
44 } catch (ex) { } |
|
45 |
|
46 if (!isWin7OrHigher) { |
|
47 ok(true, "This test only runs on Windows 7 or higher"); |
|
48 return; |
|
49 } |
|
50 |
|
51 SimpleTest.waitForExplicitFinish(); |
|
52 gGen = doTest(); |
|
53 gGen.next(); |
|
54 } |
|
55 |
|
56 function continueTest() { |
|
57 gGen.next(); |
|
58 } |
|
59 |
|
60 function doTest() { |
|
61 // Ensure that the download manager callbacks always use the window UI instead |
|
62 // of the panel in the browser's window. |
|
63 Services.prefs.setBoolPref("browser.download.useToolkitUI", true); |
|
64 |
|
65 let tempScope = {}; |
|
66 Components.utils.import("resource://gre/modules/DownloadTaskbarProgress.jsm", tempScope); |
|
67 |
|
68 DownloadTaskbarProgress = tempScope.DownloadTaskbarProgress; |
|
69 TaskbarService = Cc[kTaskbarID].getService(Ci.nsIWinTaskbar); |
|
70 |
|
71 observerService = Cc["@mozilla.org/observer-service;1"]. |
|
72 getService(Ci.nsIObserverService); |
|
73 |
|
74 wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"]. |
|
75 getService(Ci.nsIWindowWatcher); |
|
76 |
|
77 isnot(DownloadTaskbarProgress, null, "Download taskbar progress service exists"); |
|
78 is(TaskbarService.available, true, "Taskbar Service is available"); |
|
79 |
|
80 let DMWindow = getDMWindow(); |
|
81 if (DMWindow) |
|
82 DMWindow.close(); |
|
83 |
|
84 //Manually call onBrowserWindowLoad because this is delayed in 10sec |
|
85 chromeWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
|
86 getInterface(Components.interfaces.nsIWebNavigation). |
|
87 QueryInterface(Components.interfaces.nsIDocShellTreeItem). |
|
88 rootTreeItem. |
|
89 QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
|
90 getInterface(Components.interfaces.nsIDOMWindow); |
|
91 |
|
92 DownloadTaskbarProgress.onBrowserWindowLoad(chromeWindow); |
|
93 |
|
94 is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, false, |
|
95 "DownloadTaskbarProgress window is not the Download window"); |
|
96 |
|
97 checkActiveTaskbar(false, window); |
|
98 openDownloadManager(continueTest); |
|
99 yield; |
|
100 |
|
101 let DMWindow = getDMWindow(); |
|
102 |
|
103 ok(DMWindow, "Download Manager window was opened"); |
|
104 checkActiveTaskbar(true, DMWindow); |
|
105 |
|
106 DMWindow.close(); |
|
107 setTimeout(continueTest, 100); |
|
108 yield; |
|
109 |
|
110 checkActiveTaskbar(false, window); |
|
111 |
|
112 let browserWindow = openBrowserWindow(continueTest); |
|
113 yield; |
|
114 |
|
115 ok(browserWindow, "Browser window was opened"); |
|
116 DownloadTaskbarProgress.onBrowserWindowLoad(browserWindow); |
|
117 |
|
118 // The owner window should not have changed, since our |
|
119 // original window still exists |
|
120 checkActiveTaskbar(false, window); |
|
121 |
|
122 Services.prefs.clearUserPref("browser.download.useToolkitUI"); |
|
123 |
|
124 browserWindow.close(); |
|
125 SimpleTest.finish(); |
|
126 yield; |
|
127 } |
|
128 |
|
129 function checkActiveTaskbar(isDownloadManager, ownerWindow) { |
|
130 |
|
131 isnot(DownloadTaskbarProgress.activeTaskbarProgress, null, "DownloadTaskbarProgress has an active taskbar"); |
|
132 |
|
133 is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, isDownloadManager, |
|
134 "The active taskbar progress " + (isDownloadManager ? "is" : "is not") + " the Download Manager"); |
|
135 |
|
136 if (ownerWindow) { |
|
137 let ownerWindowDocShell = ownerWindow.QueryInterface(Ci.nsIInterfaceRequestor). |
|
138 getInterface(Ci.nsIWebNavigation). |
|
139 QueryInterface(Ci.nsIDocShellTreeItem).treeOwner. |
|
140 QueryInterface(Ci.nsIInterfaceRequestor). |
|
141 getInterface(Ci.nsIXULWindow).docShell; |
|
142 |
|
143 let windowTaskbarProgress = TaskbarService.getTaskbarProgress(ownerWindowDocShell); |
|
144 |
|
145 is(DownloadTaskbarProgress.activeTaskbarProgress, windowTaskbarProgress, |
|
146 "DownloadTaskbarProgress has the expected taskbar as active"); |
|
147 } |
|
148 |
|
149 } |
|
150 |
|
151 function openBrowserWindow(callback) { |
|
152 |
|
153 let browserWindow = openDialog(chromeWindow.location, "_blank", |
|
154 "chrome,all,dialog=no", "about:blank"); |
|
155 |
|
156 let helperFunc = function() { |
|
157 callback(); |
|
158 browserWindow.removeEventListener("load", helperFunc, false); |
|
159 } |
|
160 |
|
161 browserWindow.addEventListener("load", helperFunc, false); |
|
162 |
|
163 return browserWindow; |
|
164 } |
|
165 |
|
166 function openDownloadManager(callback) { |
|
167 |
|
168 let testObs = { |
|
169 observe: function(aSubject, aTopic, aData) { |
|
170 if (aTopic != DLMGR_UI_DONE) { |
|
171 return; |
|
172 } |
|
173 |
|
174 callback(); |
|
175 observerService.removeObserver(testObs, DLMGR_UI_DONE); |
|
176 } |
|
177 }; |
|
178 |
|
179 observerService.addObserver(testObs, DLMGR_UI_DONE, false); |
|
180 |
|
181 Cc["@mozilla.org/download-manager-ui;1"]. |
|
182 getService(Ci.nsIDownloadManagerUI).show(); |
|
183 |
|
184 } |
|
185 ]]> |
|
186 </script> |
|
187 |
|
188 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
189 <p id="display"></p> |
|
190 <div id="content" style="display:none;"></div> |
|
191 <pre id="test"></pre> |
|
192 </body> |
|
193 </window> |