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