1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/downloads/tests/chrome/test_multiword_search.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 1.4 +<?xml version="1.0"?> 1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.6 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.8 +<!-- 1.9 + * Test for bug 419403 that lets the download manager support multiple word 1.10 + * search against the download name, source/referrer, date/time, file size, 1.11 + * etc. 1.12 +--> 1.13 + 1.14 +<window title="Download Manager Test" 1.15 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.16 + onload="test();"> 1.17 + 1.18 + <script type="application/javascript" 1.19 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.20 + <script type="application/javascript" 1.21 + src="utils.js"/> 1.22 + 1.23 + <script type="application/javascript"> 1.24 + <![CDATA[ 1.25 + 1.26 +function test() 1.27 +{ 1.28 + var dmui = getDMUI(); 1.29 + if (!dmui) { 1.30 + todo(false, "skip test for toolkit download manager UI"); 1.31 + return; 1.32 + } 1.33 + 1.34 + let dm = Cc["@mozilla.org/download-manager;1"]. 1.35 + getService(Ci.nsIDownloadManager); 1.36 + let db = dm.DBConnection; 1.37 + 1.38 + // Empty any old downloads 1.39 + db.executeSimpleSQL("DELETE FROM moz_downloads"); 1.40 + 1.41 + // Make a file name for the downloads 1.42 + let file = Cc["@mozilla.org/file/directory_service;1"]. 1.43 + getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); 1.44 + file.append("multiWord"); 1.45 + let filePath = Cc["@mozilla.org/network/io-service;1"]. 1.46 + getService(Ci.nsIIOService).newFileURI(file).spec; 1.47 + 1.48 + let stmt = db.createStatement( 1.49 + "INSERT INTO moz_downloads (name, target, source, state, endTime, maxBytes) " + 1.50 + "VALUES (?1, ?2, ?3, ?4, ?5, ?6)"); 1.51 + 1.52 + try { 1.53 + for each (let site in ["ed.agadak.net", "mozilla.org"]) { 1.54 + stmt.bindStringParameter(0, "Super Pimped Download"); 1.55 + stmt.bindStringParameter(1, filePath); 1.56 + stmt.bindStringParameter(2, "http://" + site + "/file"); 1.57 + stmt.bindInt32Parameter(3, dm.DOWNLOAD_FINISHED); 1.58 + stmt.bindInt64Parameter(4, new Date(1985, 7, 2) * 1000); 1.59 + stmt.bindInt64Parameter(5, 111222333444); 1.60 + 1.61 + // Add it! 1.62 + stmt.execute(); 1.63 + } 1.64 + } finally { 1.65 + stmt.reset(); 1.66 + stmt.finalize(); 1.67 + } 1.68 + 1.69 + // Close the UI if necessary 1.70 + let wm = Cc["@mozilla.org/appshell/window-mediator;1"]. 1.71 + getService(Ci.nsIWindowMediator); 1.72 + let win = wm.getMostRecentWindow("Download:Manager"); 1.73 + if (win) win.close(); 1.74 + 1.75 + let obs = Cc["@mozilla.org/observer-service;1"]. 1.76 + getService(Ci.nsIObserverService); 1.77 + const DLMGR_UI_DONE = "download-manager-ui-done"; 1.78 + 1.79 + let testPhase = -1; 1.80 + let testObs = { 1.81 + observe: function(aSubject, aTopic, aData) { 1.82 + if (aTopic != DLMGR_UI_DONE) 1.83 + return; 1.84 + 1.85 + let win = aSubject.QueryInterface(Ci.nsIDOMWindow); 1.86 + win.focus(); 1.87 + let $ = function(aId) win.document.getElementById(aId); 1.88 + let downloadView = $("downloadView"); 1.89 + let searchbox = $("searchbox"); 1.90 + 1.91 + let search = function(aTerms) { 1.92 + searchbox.value = aTerms; 1.93 + searchbox.doCommand(); 1.94 + }; 1.95 + 1.96 + let testResults = function(aExpected) { 1.97 + is(downloadView.itemCount, aExpected, 1.98 + "Phase " + testPhase + ": search matched " + aExpected + " download(s)"); 1.99 + }; 1.100 + 1.101 + // The list must have built, so figure out what test to do 1.102 + switch (++testPhase) { 1.103 + case 0: 1.104 + // Search for multiple words in any order in all places 1.105 + search("download super pimped 104 GB august 2"); 1.106 + 1.107 + break; 1.108 + case 1: 1.109 + // Done populating the two items 1.110 + testResults(2); 1.111 + 1.112 + // Do partial word matches including the site 1.113 + search("Agadak.net aug 2 downl 104"); 1.114 + 1.115 + break; 1.116 + case 2: 1.117 + // Done populating the one result 1.118 + testResults(1); 1.119 + 1.120 + // The search term shouldn't be treated like a regular expression, 1.121 + // e.g. "D.wnload" shouldn't match "Download". 1.122 + search("D.wnload"); 1.123 + 1.124 + break; 1.125 + case 3: 1.126 + testResults(0); 1.127 + 1.128 + // We're done! 1.129 + win.close(); 1.130 + obs.removeObserver(testObs, DLMGR_UI_DONE); 1.131 + SimpleTest.finish(); 1.132 + 1.133 + break; 1.134 + } 1.135 + } 1.136 + }; 1.137 + obs.addObserver(testObs, DLMGR_UI_DONE, false); 1.138 + 1.139 + // Show the Download Manager UI 1.140 + dmui.show(); 1.141 + 1.142 + SimpleTest.waitForExplicitFinish(); 1.143 +} 1.144 + 1.145 + ]]> 1.146 + </script> 1.147 + 1.148 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.149 + <p id="display"></p> 1.150 + <div id="content" style="display:none;"></div> 1.151 + <pre id="test"></pre> 1.152 + </body> 1.153 +</window>