|
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 test ensures that the delete key removes a download. This was added by |
|
7 * bug 411172. SimpleTest.waitForFocus(function () { closeDM(aSubject) }, aSubject); |
|
8 } |
|
9 }; |
|
10 |
|
11 function closeDM(win) { |
|
12 |
|
13 */ |
|
14 --> |
|
15 |
|
16 <window title="Download Manager Test" |
|
17 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
18 onload="test();"> |
|
19 |
|
20 <script type="application/javascript" |
|
21 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
22 <script type="application/javascript" |
|
23 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
24 <script type="application/javascript" |
|
25 src="utils.js"/> |
|
26 |
|
27 <script type="application/javascript"> |
|
28 <![CDATA[ |
|
29 |
|
30 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); |
|
31 var dmFile = Cc["@mozilla.org/file/directory_service;1"]. |
|
32 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); |
|
33 dmFile.append("dm-ui-test.file"); |
|
34 dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
|
35 var gTestPath = ios.newFileURI(dmFile).spec; |
|
36 |
|
37 // Downloads are sorted by endTime, so make sure the end times are distinct |
|
38 const DownloadData = [ |
|
39 { name: "381603.patch", |
|
40 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
|
41 target: gTestPath, |
|
42 startTime: 1180493839859230, |
|
43 endTime: 1180493839859239, |
|
44 state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED, |
|
45 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
|
46 { name: "381603.patch", |
|
47 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
|
48 target: gTestPath, |
|
49 startTime: 1180493839859230, |
|
50 endTime: 1180493839859236, |
|
51 state: Ci.nsIDownloadManager.DOWNLOAD_FAILED, |
|
52 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
|
53 { name: "381603.patch", |
|
54 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
|
55 target: gTestPath, |
|
56 startTime: 1180493839859230, |
|
57 endTime: 1180493839859234, |
|
58 state: Ci.nsIDownloadManager.DOWNLOAD_CANCELED, |
|
59 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
|
60 { name: "381603.patch", |
|
61 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
|
62 target: gTestPath, |
|
63 startTime: 1180493839859230, |
|
64 endTime: 1180493839859232, |
|
65 state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL, |
|
66 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
|
67 { name: "381603.patch", |
|
68 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
|
69 target: gTestPath, |
|
70 startTime: 1180493839859230, |
|
71 endTime: 1180493839859230, |
|
72 state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY, |
|
73 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
|
74 { name: "381603.patch", |
|
75 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
|
76 target: gTestPath, |
|
77 startTime: 1180493839859229, |
|
78 endTime: 1180493839859229, |
|
79 state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY, |
|
80 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 } |
|
81 ]; |
|
82 |
|
83 |
|
84 function test() |
|
85 { |
|
86 var dmui = getDMUI(); |
|
87 if (!dmui) { |
|
88 todo(false, "skip test for toolkit download manager UI"); |
|
89 return; |
|
90 } |
|
91 |
|
92 var dm = Cc["@mozilla.org/download-manager;1"]. |
|
93 getService(Ci.nsIDownloadManager); |
|
94 var db = dm.DBConnection; |
|
95 |
|
96 // First, we populate the database with some fake data |
|
97 db.executeSimpleSQL("DELETE FROM moz_downloads"); |
|
98 var stmt = db.createStatement( |
|
99 "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " + |
|
100 "state, currBytes, maxBytes, preferredAction, autoResume) " + |
|
101 "VALUES (:name, :source, :target, :startTime, :endTime, :state, " + |
|
102 ":currBytes, :maxBytes, :preferredAction, :autoResume)"); |
|
103 for each (var dl in DownloadData) { |
|
104 for (var prop in dl) |
|
105 stmt.params[prop] = dl[prop]; |
|
106 |
|
107 stmt.execute(); |
|
108 } |
|
109 stmt.finalize(); |
|
110 |
|
111 // See if the DM is already open, and if it is, close it! |
|
112 var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. |
|
113 getService(Ci.nsIWindowMediator); |
|
114 var win = wm.getMostRecentWindow("Download:Manager"); |
|
115 if (win) |
|
116 win.close(); |
|
117 |
|
118 let os = Cc["@mozilla.org/observer-service;1"]. |
|
119 getService(Ci.nsIObserverService); |
|
120 const DLMGR_UI_DONE = "download-manager-ui-done"; |
|
121 |
|
122 let testObs = { |
|
123 observe: function(aSubject, aTopic, aData) |
|
124 { |
|
125 if (aTopic != DLMGR_UI_DONE) |
|
126 return; |
|
127 |
|
128 SimpleTest.waitForFocus(function () { deleteDownload(aSubject) }, aSubject); |
|
129 } |
|
130 }; |
|
131 |
|
132 function deleteDownload(win) { |
|
133 let doc = win.document; |
|
134 |
|
135 let stmt = db.createStatement("SELECT COUNT(*) FROM moz_downloads"); |
|
136 try { |
|
137 stmt.executeStep(); |
|
138 let richlistbox = doc.getElementById("downloadView"); |
|
139 richlistbox.selectedIndex = 0; |
|
140 is(stmt.getInt32(0), richlistbox.children.length, |
|
141 "The database and the number of downloads display matches"); |
|
142 stmt.reset(); |
|
143 |
|
144 let len = DownloadData.length; |
|
145 for (let i = 0; i < len; i++) { |
|
146 synthesizeKey("VK_DELETE", {}, win); |
|
147 |
|
148 stmt.executeStep(); |
|
149 is(stmt.getInt32(0), len - (i + 1), |
|
150 "The download was properly removed"); |
|
151 stmt.reset(); |
|
152 } |
|
153 } |
|
154 finally { |
|
155 stmt.reset(); |
|
156 stmt.finalize(); |
|
157 } |
|
158 |
|
159 win.close(); |
|
160 dmFile.remove(false); |
|
161 os.removeObserver(testObs, DLMGR_UI_DONE); |
|
162 SimpleTest.finish(); |
|
163 } |
|
164 |
|
165 // Register with the observer service |
|
166 os.addObserver(testObs, DLMGR_UI_DONE, false); |
|
167 |
|
168 // Show the Download Manager UI |
|
169 dmui.show(); |
|
170 |
|
171 SimpleTest.waitForExplicitFinish(); |
|
172 } |
|
173 |
|
174 ]]> |
|
175 </script> |
|
176 |
|
177 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
178 <p id="display"></p> |
|
179 <div id="content" style="display:none;"></div> |
|
180 <pre id="test"></pre> |
|
181 </body> |
|
182 </window> |