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 | * Make sure the download manager can display downloads in the right order and |
michael@0 | 7 | * contains the expected data. The list has one of each download state ordered |
michael@0 | 8 | * by the start/end times. |
michael@0 | 9 | --> |
michael@0 | 10 | |
michael@0 | 11 | <window title="Download Manager Test" |
michael@0 | 12 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 13 | onload="test();"> |
michael@0 | 14 | |
michael@0 | 15 | <script type="application/javascript" |
michael@0 | 16 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
michael@0 | 17 | <script type="application/javascript" |
michael@0 | 18 | src="utils.js"/> |
michael@0 | 19 | |
michael@0 | 20 | <script type="application/javascript"> |
michael@0 | 21 | <![CDATA[ |
michael@0 | 22 | |
michael@0 | 23 | var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); |
michael@0 | 24 | var dmFile = Cc["@mozilla.org/file/directory_service;1"]. |
michael@0 | 25 | getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); |
michael@0 | 26 | dmFile.append("dm-ui-test.file"); |
michael@0 | 27 | dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 28 | var gTestPath = ios.newFileURI(dmFile).spec; |
michael@0 | 29 | |
michael@0 | 30 | // Downloads are sorted by endTime, so make sure the end times are distinct |
michael@0 | 31 | const DownloadData = [ |
michael@0 | 32 | /* Active states first */ |
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_NOTSTARTED, |
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: 1180493839859238, |
michael@0 | 45 | state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING, |
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: 1180493839859237, |
michael@0 | 52 | state: Ci.nsIDownloadManager.DOWNLOAD_PAUSED, |
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: 1180493839859236, |
michael@0 | 59 | state: Ci.nsIDownloadManager.DOWNLOAD_SCANNING, |
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: 1180493839859235, |
michael@0 | 66 | state: Ci.nsIDownloadManager.DOWNLOAD_QUEUED, |
michael@0 | 67 | currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
michael@0 | 68 | /* Finished states */ |
michael@0 | 69 | { name: "381603.patch", |
michael@0 | 70 | source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
michael@0 | 71 | target: gTestPath, |
michael@0 | 72 | startTime: 1180493839859230, |
michael@0 | 73 | endTime: 1180493839859234, |
michael@0 | 74 | state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED, |
michael@0 | 75 | currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
michael@0 | 76 | { name: "381603.patch", |
michael@0 | 77 | source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
michael@0 | 78 | target: gTestPath, |
michael@0 | 79 | startTime: 1180493839859230, |
michael@0 | 80 | endTime: 1180493839859233, |
michael@0 | 81 | state: Ci.nsIDownloadManager.DOWNLOAD_FAILED, |
michael@0 | 82 | currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
michael@0 | 83 | { name: "381603.patch", |
michael@0 | 84 | source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
michael@0 | 85 | target: gTestPath, |
michael@0 | 86 | startTime: 1180493839859230, |
michael@0 | 87 | endTime: 1180493839859232, |
michael@0 | 88 | state: Ci.nsIDownloadManager.DOWNLOAD_CANCELED, |
michael@0 | 89 | currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
michael@0 | 90 | { name: "381603.patch", |
michael@0 | 91 | source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
michael@0 | 92 | target: gTestPath, |
michael@0 | 93 | startTime: 1180493839859230, |
michael@0 | 94 | endTime: 1180493839859231, |
michael@0 | 95 | state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL, |
michael@0 | 96 | currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
michael@0 | 97 | { name: "381603.patch", |
michael@0 | 98 | source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
michael@0 | 99 | target: gTestPath, |
michael@0 | 100 | startTime: 1180493839859230, |
michael@0 | 101 | endTime: 1180493839859230, |
michael@0 | 102 | state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY, |
michael@0 | 103 | currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, |
michael@0 | 104 | { name: "381603.patch", |
michael@0 | 105 | source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
michael@0 | 106 | target: gTestPath, |
michael@0 | 107 | startTime: 1180493839859229, |
michael@0 | 108 | endTime: 1180493839859229, |
michael@0 | 109 | state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY, |
michael@0 | 110 | currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 } |
michael@0 | 111 | ]; |
michael@0 | 112 | |
michael@0 | 113 | function test_numberOfRichlistitems(aWin) |
michael@0 | 114 | { |
michael@0 | 115 | var doc = aWin.document; |
michael@0 | 116 | var richlistbox = doc.getElementById("downloadView"); |
michael@0 | 117 | is(richlistbox.children.length, DownloadData.length, |
michael@0 | 118 | "There is the correct number of richlistitems"); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | function test_properDownloadData(aWin) |
michael@0 | 122 | { |
michael@0 | 123 | // This also tests the ordering of the display |
michael@0 | 124 | var doc = aWin.document; |
michael@0 | 125 | var richlistbox = doc.getElementById("downloadView"); |
michael@0 | 126 | for (var i = 0; i < richlistbox.children.length; i++) { |
michael@0 | 127 | var elm = richlistbox.children[i]; |
michael@0 | 128 | is(elm.getAttribute("target"), DownloadData[i].name, |
michael@0 | 129 | "Download names match up"); |
michael@0 | 130 | is(elm.getAttribute("state"), DownloadData[i].state, |
michael@0 | 131 | "Download states match up"); |
michael@0 | 132 | is(elm.getAttribute("file"), DownloadData[i].target, |
michael@0 | 133 | "Download targets match up"); |
michael@0 | 134 | is(elm.getAttribute("uri"), DownloadData[i].source, |
michael@0 | 135 | "Download sources match up"); |
michael@0 | 136 | } |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | var testFuncs = [ |
michael@0 | 140 | test_numberOfRichlistitems |
michael@0 | 141 | , test_properDownloadData |
michael@0 | 142 | ]; |
michael@0 | 143 | |
michael@0 | 144 | function test() |
michael@0 | 145 | { |
michael@0 | 146 | var dmui = getDMUI(); |
michael@0 | 147 | if (!dmui) { |
michael@0 | 148 | todo(false, "skip test for toolkit download manager UI"); |
michael@0 | 149 | return; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | var dm = Cc["@mozilla.org/download-manager;1"]. |
michael@0 | 153 | getService(Ci.nsIDownloadManager); |
michael@0 | 154 | var db = dm.DBConnection; |
michael@0 | 155 | |
michael@0 | 156 | // First, we populate the database with some fake data |
michael@0 | 157 | db.executeSimpleSQL("DELETE FROM moz_downloads"); |
michael@0 | 158 | var stmt = db.createStatement( |
michael@0 | 159 | "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " + |
michael@0 | 160 | "state, currBytes, maxBytes, preferredAction, autoResume) " + |
michael@0 | 161 | "VALUES (:name, :source, :target, :startTime, :endTime, :state, " + |
michael@0 | 162 | ":currBytes, :maxBytes, :preferredAction, :autoResume)"); |
michael@0 | 163 | for each (var dl in DownloadData) { |
michael@0 | 164 | for (var prop in dl) |
michael@0 | 165 | stmt.params[prop] = dl[prop]; |
michael@0 | 166 | |
michael@0 | 167 | stmt.execute(); |
michael@0 | 168 | } |
michael@0 | 169 | stmt.finalize(); |
michael@0 | 170 | |
michael@0 | 171 | // See if the DM is already open, and if it is, close it! |
michael@0 | 172 | var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. |
michael@0 | 173 | getService(Ci.nsIWindowMediator); |
michael@0 | 174 | var win = wm.getMostRecentWindow("Download:Manager"); |
michael@0 | 175 | if (win) |
michael@0 | 176 | win.close(); |
michael@0 | 177 | |
michael@0 | 178 | let os = Cc["@mozilla.org/observer-service;1"]. |
michael@0 | 179 | getService(Ci.nsIObserverService); |
michael@0 | 180 | const DLMGR_UI_DONE = "download-manager-ui-done"; |
michael@0 | 181 | |
michael@0 | 182 | let testObs = { |
michael@0 | 183 | observe: function(aSubject, aTopic, aData) |
michael@0 | 184 | { |
michael@0 | 185 | if (aTopic != DLMGR_UI_DONE) |
michael@0 | 186 | return; |
michael@0 | 187 | |
michael@0 | 188 | let win = aSubject.QueryInterface(Ci.nsIDOMWindow); |
michael@0 | 189 | win.focus(); |
michael@0 | 190 | |
michael@0 | 191 | // Now we can run our tests |
michael@0 | 192 | for each (let t in testFuncs) |
michael@0 | 193 | t(win); |
michael@0 | 194 | |
michael@0 | 195 | win.close(); |
michael@0 | 196 | dmFile.remove(false); |
michael@0 | 197 | os.removeObserver(testObs, DLMGR_UI_DONE); |
michael@0 | 198 | SimpleTest.finish(); |
michael@0 | 199 | } |
michael@0 | 200 | }; |
michael@0 | 201 | |
michael@0 | 202 | // Register with the observer service |
michael@0 | 203 | os.addObserver(testObs, DLMGR_UI_DONE, false); |
michael@0 | 204 | |
michael@0 | 205 | // Show the Download Manager UI |
michael@0 | 206 | dmui.show(); |
michael@0 | 207 | |
michael@0 | 208 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | ]]> |
michael@0 | 212 | </script> |
michael@0 | 213 | |
michael@0 | 214 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 215 | <p id="display"></p> |
michael@0 | 216 | <div id="content" style="display:none;"></div> |
michael@0 | 217 | <pre id="test"></pre> |
michael@0 | 218 | </body> |
michael@0 | 219 | </window> |