|
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 * Test bug 429614 to make sure ctrl/cmd-a work to select all downloads and |
|
7 * hitting delete removes them all. |
|
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="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
18 <script type="application/javascript" |
|
19 src="utils.js"/> |
|
20 |
|
21 <script type="application/javascript"> |
|
22 <![CDATA[ |
|
23 |
|
24 function test() |
|
25 { |
|
26 var dmui = getDMUI(); |
|
27 if (!dmui) { |
|
28 todo(false, "skip test for toolkit download manager UI"); |
|
29 return; |
|
30 } |
|
31 |
|
32 let dm = Cc["@mozilla.org/download-manager;1"]. |
|
33 getService(Ci.nsIDownloadManager); |
|
34 let db = dm.DBConnection; |
|
35 |
|
36 // Empty any old downloads |
|
37 db.executeSimpleSQL("DELETE FROM moz_downloads"); |
|
38 |
|
39 // Make a file name for the downloads |
|
40 let file = Cc["@mozilla.org/file/directory_service;1"]. |
|
41 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); |
|
42 file.append("selectAll"); |
|
43 let filePath = Cc["@mozilla.org/network/io-service;1"]. |
|
44 getService(Ci.nsIIOService).newFileURI(file).spec; |
|
45 |
|
46 let stmt = db.createStatement( |
|
47 "INSERT INTO moz_downloads (target, source, state) " + |
|
48 "VALUES (?1, ?2, ?3)"); |
|
49 |
|
50 let sites = ["mozilla.org", "mozilla.com", "select.all"]; |
|
51 try { |
|
52 for each (let site in sites) { |
|
53 stmt.bindStringParameter(0, filePath); |
|
54 stmt.bindStringParameter(1, "http://" + site + "/file"); |
|
55 stmt.bindInt32Parameter(2, dm.DOWNLOAD_FINISHED); |
|
56 |
|
57 // Add it! |
|
58 stmt.execute(); |
|
59 } |
|
60 } |
|
61 finally { |
|
62 stmt.reset(); |
|
63 stmt.finalize(); |
|
64 } |
|
65 |
|
66 // Close the UI if necessary |
|
67 let wm = Cc["@mozilla.org/appshell/window-mediator;1"]. |
|
68 getService(Ci.nsIWindowMediator); |
|
69 let win = wm.getMostRecentWindow("Download:Manager"); |
|
70 if (win) win.close(); |
|
71 |
|
72 let obs = Cc["@mozilla.org/observer-service;1"]. |
|
73 getService(Ci.nsIObserverService); |
|
74 const DLMGR_UI_DONE = "download-manager-ui-done"; |
|
75 |
|
76 let testObs = { |
|
77 observe: function(aSubject, aTopic, aData) { |
|
78 if (aTopic != DLMGR_UI_DONE) |
|
79 return; |
|
80 |
|
81 SimpleTest.waitForFocus(function () { checkSelectAndRemove(aSubject) }, aSubject); |
|
82 } |
|
83 }; |
|
84 |
|
85 var checkSelectAndRemove = function(win) |
|
86 { |
|
87 let $ = function(aId) win.document.getElementById(aId); |
|
88 let downloadView = $("downloadView"); |
|
89 is(downloadView.itemCount, sites.length, "All downloads displayed"); |
|
90 |
|
91 // Select all downloads |
|
92 let isMac = navigator.platform.search("Mac") == 0; |
|
93 synthesizeKey("a", { metaKey: isMac, ctrlKey: !isMac }, win); |
|
94 is(downloadView.selectedCount, sites.length, "All downloads selected"); |
|
95 |
|
96 // Delete all downloads |
|
97 synthesizeKey("VK_DELETE", {}, win); |
|
98 is(downloadView.itemCount, 0, "All downloads removed"); |
|
99 |
|
100 // We're done! |
|
101 win.close(); |
|
102 obs.removeObserver(testObs, DLMGR_UI_DONE); |
|
103 SimpleTest.finish(); |
|
104 } |
|
105 |
|
106 obs.addObserver(testObs, DLMGR_UI_DONE, false); |
|
107 |
|
108 // Show the Download Manager UI |
|
109 dmui.show(); |
|
110 |
|
111 SimpleTest.waitForExplicitFinish(); |
|
112 } |
|
113 |
|
114 ]]> |
|
115 </script> |
|
116 |
|
117 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
118 <p id="display"></p> |
|
119 <div id="content" style="display:none;"></div> |
|
120 <pre id="test"></pre> |
|
121 </body> |
|
122 </window> |