|
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 bug 410289. Specifically, it tests that the pause button is |
|
7 * active for resumable downloads, and inactive for non-resumable ones. |
|
8 --> |
|
9 |
|
10 <window title="Download Manager Test" |
|
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 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); |
|
23 var dmFile = Cc["@mozilla.org/file/directory_service;1"]. |
|
24 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); |
|
25 dmFile.append("dm-ui-test.file"); |
|
26 dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
|
27 var gTestPath = ios.newFileURI(dmFile).spec; |
|
28 |
|
29 const DownloadData = [ |
|
30 { name: "Firefox 2.0.0.11.dmg", |
|
31 source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg", |
|
32 target: gTestPath, |
|
33 startTime: 1200185939538521, |
|
34 endTime: 1200185939538521, |
|
35 entityID: "%22216c12-1116bd8-440070d5d2700%22/17918936/Thu, 29 Nov 2007 01:15:40 GMT", |
|
36 state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING, |
|
37 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
|
38 { name: "Firefox 2.0.0.11.dmg", |
|
39 source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg", |
|
40 target: gTestPath, |
|
41 startTime: 1200185939538520, |
|
42 endTime: 1200185939538520, |
|
43 entityID: "", |
|
44 state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING, |
|
45 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 } |
|
46 ]; |
|
47 |
|
48 function test() |
|
49 { |
|
50 var dmui = getDMUI(); |
|
51 if (!dmui) { |
|
52 todo(false, "skip test for toolkit download manager UI"); |
|
53 return; |
|
54 } |
|
55 |
|
56 var dm = Cc["@mozilla.org/download-manager;1"]. |
|
57 getService(Ci.nsIDownloadManager); |
|
58 var db = dm.DBConnection; |
|
59 |
|
60 // First, we populate the database with some fake data |
|
61 db.executeSimpleSQL("DELETE FROM moz_downloads"); |
|
62 var stmt = db.createStatement( |
|
63 "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " + |
|
64 "state, currBytes, maxBytes, preferredAction, autoResume, entityID) " + |
|
65 "VALUES (:name, :source, :target, :startTime, :endTime, :state, " + |
|
66 ":currBytes, :maxBytes, :preferredAction, :autoResume, :entityID)"); |
|
67 for each (var dl in DownloadData) { |
|
68 for (var prop in dl) |
|
69 stmt.params[prop] = dl[prop]; |
|
70 |
|
71 stmt.execute(); |
|
72 } |
|
73 stmt.finalize(); |
|
74 |
|
75 // See if the DM is already open, and if it is, close it! |
|
76 var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. |
|
77 getService(Ci.nsIWindowMediator); |
|
78 var win = wm.getMostRecentWindow("Download:Manager"); |
|
79 if (win) |
|
80 win.close(); |
|
81 |
|
82 let os = Cc["@mozilla.org/observer-service;1"]. |
|
83 getService(Ci.nsIObserverService); |
|
84 const DLMGR_UI_DONE = "download-manager-ui-done"; |
|
85 |
|
86 let testObs = { |
|
87 observe: function(aSubject, aTopic, aData) |
|
88 { |
|
89 if (aTopic != DLMGR_UI_DONE) |
|
90 return; |
|
91 |
|
92 let win = aSubject.QueryInterface(Ci.nsIDOMWindow); |
|
93 win.focus(); |
|
94 let doc = win.document; |
|
95 |
|
96 let richlistbox = doc.getElementById("downloadView"); |
|
97 for (let i = 0; i < DownloadData.length; i++) { |
|
98 let dl = richlistbox.children[i]; |
|
99 let buttons = dl.buttons; |
|
100 for (let j = 0; j < buttons.length; j++) { |
|
101 let button = buttons[j]; |
|
102 if ("cmd_pause" == button.getAttribute("cmd")) { |
|
103 let id = dl.getAttribute("dlid"); |
|
104 |
|
105 // check if it should be disabled or not |
|
106 let resumable = dm.getDownload(id).resumable; |
|
107 is(DownloadData[i].entityID ? true : false, resumable, |
|
108 "Pause button is properly disabled"); |
|
109 |
|
110 // also check if tooltip text was updated |
|
111 if (!resumable) { |
|
112 let sb = doc.getElementById("downloadStrings"); |
|
113 is(button.getAttribute("tooltiptext"), sb.getString("cannotPause"), |
|
114 "Pause button has proper text"); |
|
115 } |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 win.close(); |
|
121 dmFile.remove(false); |
|
122 os.removeObserver(testObs, DLMGR_UI_DONE); |
|
123 SimpleTest.finish(); |
|
124 } |
|
125 } |
|
126 |
|
127 // Register with the observer service |
|
128 os.addObserver(testObs, DLMGR_UI_DONE, false); |
|
129 |
|
130 // Show the Download Manager UI |
|
131 dmui.show(); |
|
132 |
|
133 SimpleTest.waitForExplicitFinish(); |
|
134 } |
|
135 |
|
136 ]]> |
|
137 </script> |
|
138 |
|
139 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
140 <p id="display"></p> |
|
141 <div id="content" style="display:none;"></div> |
|
142 <pre id="test"></pre> |
|
143 </body> |
|
144 </window> |