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 | * Test for bug 419403 that lets the download manager support multiple word |
michael@0 | 7 | * search against the download name, source/referrer, date/time, file size, |
michael@0 | 8 | * etc. |
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 | function test() |
michael@0 | 24 | { |
michael@0 | 25 | var dmui = getDMUI(); |
michael@0 | 26 | if (!dmui) { |
michael@0 | 27 | todo(false, "skip test for toolkit download manager UI"); |
michael@0 | 28 | return; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | let dm = Cc["@mozilla.org/download-manager;1"]. |
michael@0 | 32 | getService(Ci.nsIDownloadManager); |
michael@0 | 33 | let db = dm.DBConnection; |
michael@0 | 34 | |
michael@0 | 35 | // Empty any old downloads |
michael@0 | 36 | db.executeSimpleSQL("DELETE FROM moz_downloads"); |
michael@0 | 37 | |
michael@0 | 38 | // Make a file name for the downloads |
michael@0 | 39 | let file = Cc["@mozilla.org/file/directory_service;1"]. |
michael@0 | 40 | getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); |
michael@0 | 41 | file.append("multiWord"); |
michael@0 | 42 | let filePath = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 43 | getService(Ci.nsIIOService).newFileURI(file).spec; |
michael@0 | 44 | |
michael@0 | 45 | let stmt = db.createStatement( |
michael@0 | 46 | "INSERT INTO moz_downloads (name, target, source, state, endTime, maxBytes) " + |
michael@0 | 47 | "VALUES (?1, ?2, ?3, ?4, ?5, ?6)"); |
michael@0 | 48 | |
michael@0 | 49 | try { |
michael@0 | 50 | for each (let site in ["ed.agadak.net", "mozilla.org"]) { |
michael@0 | 51 | stmt.bindStringParameter(0, "Super Pimped Download"); |
michael@0 | 52 | stmt.bindStringParameter(1, filePath); |
michael@0 | 53 | stmt.bindStringParameter(2, "http://" + site + "/file"); |
michael@0 | 54 | stmt.bindInt32Parameter(3, dm.DOWNLOAD_FINISHED); |
michael@0 | 55 | stmt.bindInt64Parameter(4, new Date(1985, 7, 2) * 1000); |
michael@0 | 56 | stmt.bindInt64Parameter(5, 111222333444); |
michael@0 | 57 | |
michael@0 | 58 | // Add it! |
michael@0 | 59 | stmt.execute(); |
michael@0 | 60 | } |
michael@0 | 61 | } finally { |
michael@0 | 62 | stmt.reset(); |
michael@0 | 63 | stmt.finalize(); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | // Close the UI if necessary |
michael@0 | 67 | let wm = Cc["@mozilla.org/appshell/window-mediator;1"]. |
michael@0 | 68 | getService(Ci.nsIWindowMediator); |
michael@0 | 69 | let win = wm.getMostRecentWindow("Download:Manager"); |
michael@0 | 70 | if (win) win.close(); |
michael@0 | 71 | |
michael@0 | 72 | let obs = Cc["@mozilla.org/observer-service;1"]. |
michael@0 | 73 | getService(Ci.nsIObserverService); |
michael@0 | 74 | const DLMGR_UI_DONE = "download-manager-ui-done"; |
michael@0 | 75 | |
michael@0 | 76 | let testPhase = -1; |
michael@0 | 77 | let testObs = { |
michael@0 | 78 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 79 | if (aTopic != DLMGR_UI_DONE) |
michael@0 | 80 | return; |
michael@0 | 81 | |
michael@0 | 82 | let win = aSubject.QueryInterface(Ci.nsIDOMWindow); |
michael@0 | 83 | win.focus(); |
michael@0 | 84 | let $ = function(aId) win.document.getElementById(aId); |
michael@0 | 85 | let downloadView = $("downloadView"); |
michael@0 | 86 | let searchbox = $("searchbox"); |
michael@0 | 87 | |
michael@0 | 88 | let search = function(aTerms) { |
michael@0 | 89 | searchbox.value = aTerms; |
michael@0 | 90 | searchbox.doCommand(); |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | let testResults = function(aExpected) { |
michael@0 | 94 | is(downloadView.itemCount, aExpected, |
michael@0 | 95 | "Phase " + testPhase + ": search matched " + aExpected + " download(s)"); |
michael@0 | 96 | }; |
michael@0 | 97 | |
michael@0 | 98 | // The list must have built, so figure out what test to do |
michael@0 | 99 | switch (++testPhase) { |
michael@0 | 100 | case 0: |
michael@0 | 101 | // Search for multiple words in any order in all places |
michael@0 | 102 | search("download super pimped 104 GB august 2"); |
michael@0 | 103 | |
michael@0 | 104 | break; |
michael@0 | 105 | case 1: |
michael@0 | 106 | // Done populating the two items |
michael@0 | 107 | testResults(2); |
michael@0 | 108 | |
michael@0 | 109 | // Do partial word matches including the site |
michael@0 | 110 | search("Agadak.net aug 2 downl 104"); |
michael@0 | 111 | |
michael@0 | 112 | break; |
michael@0 | 113 | case 2: |
michael@0 | 114 | // Done populating the one result |
michael@0 | 115 | testResults(1); |
michael@0 | 116 | |
michael@0 | 117 | // The search term shouldn't be treated like a regular expression, |
michael@0 | 118 | // e.g. "D.wnload" shouldn't match "Download". |
michael@0 | 119 | search("D.wnload"); |
michael@0 | 120 | |
michael@0 | 121 | break; |
michael@0 | 122 | case 3: |
michael@0 | 123 | testResults(0); |
michael@0 | 124 | |
michael@0 | 125 | // We're done! |
michael@0 | 126 | win.close(); |
michael@0 | 127 | obs.removeObserver(testObs, DLMGR_UI_DONE); |
michael@0 | 128 | SimpleTest.finish(); |
michael@0 | 129 | |
michael@0 | 130 | break; |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | }; |
michael@0 | 134 | obs.addObserver(testObs, DLMGR_UI_DONE, false); |
michael@0 | 135 | |
michael@0 | 136 | // Show the Download Manager UI |
michael@0 | 137 | dmui.show(); |
michael@0 | 138 | |
michael@0 | 139 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | ]]> |
michael@0 | 143 | </script> |
michael@0 | 144 | |
michael@0 | 145 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 146 | <p id="display"></p> |
michael@0 | 147 | <div id="content" style="display:none;"></div> |
michael@0 | 148 | <pre id="test"></pre> |
michael@0 | 149 | </body> |
michael@0 | 150 | </window> |