Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 * the download state changes.
8 -->
10 <window title="Win7 Taskbar Progress"
11 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
12 onload="test();">
14 <script type="application/javascript"
15 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
16 <script type="application/javascript"
17 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
18 <script type="application/javascript"
19 src="utils.js"/>
21 <script type="application/javascript">
22 <![CDATA[
24 const kTaskbarID = "@mozilla.org/windows-taskbar;1";
25 const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul";
26 const DLMGR_UI_DONE = "download-manager-ui-done";
28 const Cu = Components.utils;
29 const nsITP = Ci.nsITaskbarProgress;
31 let DownloadTaskbarProgress, dm;
32 let downloadA, downloadB, gGen;
34 let testState = {
35 activeDownloadCount: 0,
36 pausedDownloadCount: 0,
37 finishedDownloadCount: 0,
39 regularStateTested: false,
40 pausedStateTested: false,
41 noDownloadsStateTested: false
42 }
44 function continueTest() {
45 SimpleTest.executeSoon(function(){
46 gGen.next();
47 });
48 }
50 let wasPaused = {};
52 let downloadListener = {
54 onStateChange: function(a, b, c, d, e) {
55 checkCorrectState();
56 },
58 onDownloadStateChange: function(aState, aDownload)
59 {
61 if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_PAUSED) {
62 wasPaused[aDownload.id] = true;
63 testState.pausedDownloadCount++;
64 testState.activeDownloadCount--;
66 continueTest();
67 }
69 if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
70 testState.activeDownloadCount--;
71 testState.finishedDownloadCount++;
72 aDownload.targetFile.remove(false);
74 SimpleTest.executeSoon(checkCorrectState);
75 if(testState.finishedDownloadCount == 2) {
76 SimpleTest.executeSoon(finishTest);
77 }
79 }
81 if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING) {
82 if (!wasPaused[aDownload.id])
83 dm.pauseDownload(aDownload.id);
84 continueTest();
85 }
87 },
89 onProgressChange: function(a, b, c, d, e, f, g) { },
90 onSecurityChange: function(a, b, c, d) { }
91 };
93 function testSteps() {
95 // Step 1 - Add downloads and pause
97 testState.activeDownloadCount++;
98 downloadA = addDownload();
99 yield; // added
100 yield; // paused
102 testState.activeDownloadCount++;
103 downloadB = addDownload();
104 yield; // added
105 yield; // paused
107 // Step 2 - Resume downloads
109 testState.activeDownloadCount++;
110 testState.pausedDownloadCount--;
111 dm.resumeDownload(downloadA.id);
112 yield;
114 testState.activeDownloadCount++;
115 testState.pausedDownloadCount--;
116 dm.resumeDownload(downloadB.id);
117 yield;
119 yield;
120 }
122 function finishTest() {
123 ok(testState.regularStateTested, "Tests went through regular download state");
124 ok(testState.pausedStateTested, "Tests went through paused download state");
125 ok(testState.noDownloadsStateTested, "Tests went through finished downloads state");
126 dm.removeListener(downloadListener);
127 gGen.close();
128 SimpleTest.finish();
129 }
131 function checkCorrectState() {
133 if(testState.activeDownloadCount < 0 || testState.pausedDownloadCount < 0) {
134 ok(false, "There shouldn't be negative download counts");
135 SimpleTest.finish();
136 }
138 let taskbarState = DownloadTaskbarProgress.taskbarState;
140 if (testState.activeDownloadCount) {
141 //There's at least one active download
142 ok(taskbarState == nsITP.STATE_NORMAL || taskbarState == nsITP.STATE_INDETERMINATE, "Correct downloading state");
143 testState.regularStateTested = true;
144 } else if (testState.pausedDownloadCount) {
145 //There are no active downloads but there are paused ones
146 ok(taskbarState == nsITP.STATE_PAUSED, "Correct paused state");
147 testState.pausedStateTested = true;
148 } else {
149 //No more downloads
150 ok(taskbarState == nsITP.STATE_NO_PROGRESS, "Correct finished downloads state");
151 testState.noDownloadsStateTested = true;
152 }
154 }
156 function test() {
157 testSetup();
158 }
160 function testSetup()
161 {
162 //Test setup
163 let dmui = getDMUI();
164 if (!dmui) {
165 todo(false, "skip test for toolkit download manager UI");
166 return;
167 }
169 let isWin = /Win/.test(navigator.platform);
170 if (isWin) {
171 let isWin7OrHigher = false;
172 try {
173 let version = Cc["@mozilla.org/system-info;1"]
174 .getService(Ci.nsIPropertyBag2)
175 .getProperty("version");
176 isWin7OrHigher = (parseFloat(version) >= 6.1);
177 } catch (ex) { }
179 if (!isWin7OrHigher) {
180 ok(true, "This test only runs on Windows 7 or higher");
181 return;
182 }
183 }
185 let tempScope = {};
186 Cu.import("resource://gre/modules/DownloadTaskbarProgress.jsm", tempScope);
187 Cu.import("resource://gre/modules/Services.jsm");
189 DownloadTaskbarProgress = tempScope.DownloadTaskbarProgress;
190 isnot(DownloadTaskbarProgress, null, "Download taskbar progress service exists");
191 DownloadTaskbarProgress.init();
193 if (isWin) {
194 let TaskbarService = Cc[kTaskbarID].getService(Ci.nsIWinTaskbar);
195 is(TaskbarService.available, true, "Taskbar Service is available");
196 }
198 dm = Cc["@mozilla.org/download-manager;1"].
199 getService(Ci.nsIDownloadManager);
201 // First, we clear out the database
202 dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
204 // See if the DM is already open, and if it is, close it!
205 let win = Services.wm.getMostRecentWindow("Download:Manager");
206 if (win) {
207 win.close();
208 }
209 let os = Services.obs;
210 const DLMGR_UI_DONE = "download-manager-ui-done";
212 gGen = testSteps();
213 dm.addListener(downloadListener);
215 let testObs = {
216 observe: function(aSubject, aTopic, aData)
217 {
218 if (aTopic != DLMGR_UI_DONE) {
219 return;
220 }
221 os.removeObserver(testObs, DLMGR_UI_DONE);
222 continueTest();
223 }
224 };
226 // Register with the observer service
227 os.addObserver(testObs, DLMGR_UI_DONE, false);
229 // Show the Download Manager UI
230 dmui.show();
232 SimpleTest.waitForExplicitFinish();
233 }
235 ]]>
236 </script>
238 <body xmlns="http://www.w3.org/1999/xhtml">
239 <p id="display"></p>
240 <div id="content" style="display:none;"></div>
241 <pre id="test"></pre>
242 </body>
243 </window>