toolkit/mozapps/downloads/tests/chrome/test_delete_key_removes.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial