1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/downloads/tests/chrome/test_cleanup_search.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 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 414850 to make sure only downloads that are shown when 1.10 + * searching are cleared and afterwards, the default list is shown. 1.11 + * 1.12 + * Test bug 430486 to make sure the Clear list button is disabled only when 1.13 + * there are no download items visible. 1.14 +--> 1.15 + 1.16 +<window title="Download Manager Test" 1.17 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.18 + onload="test();"> 1.19 + 1.20 + <script type="application/javascript" 1.21 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.22 + <script type="application/javascript" 1.23 + src="utils.js"/> 1.24 + 1.25 + <script type="application/javascript"> 1.26 + <![CDATA[ 1.27 + 1.28 +function test() 1.29 +{ 1.30 + var dmui = getDMUI(); 1.31 + if (!dmui) { 1.32 + todo(false, "skip test for toolkit download manager UI"); 1.33 + return; 1.34 + } 1.35 + 1.36 + let dm = Cc["@mozilla.org/download-manager;1"]. 1.37 + getService(Ci.nsIDownloadManager); 1.38 + let db = dm.DBConnection; 1.39 + 1.40 + // Empty any old downloads 1.41 + db.executeSimpleSQL("DELETE FROM moz_downloads"); 1.42 + 1.43 + // Make a file name for the downloads 1.44 + let file = Cc["@mozilla.org/file/directory_service;1"]. 1.45 + getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); 1.46 + file.append("cleanUp"); 1.47 + let filePath = Cc["@mozilla.org/network/io-service;1"]. 1.48 + getService(Ci.nsIIOService).newFileURI(file).spec; 1.49 + 1.50 + let stmt = db.createStatement( 1.51 + "INSERT INTO moz_downloads (name, target, source, state) " + 1.52 + "VALUES (?1, ?2, ?3, ?4)"); 1.53 + 1.54 + try { 1.55 + for each (let site in ["delete.me", "i.live"]) { 1.56 + stmt.bindStringParameter(0, "Super Pimped Download"); 1.57 + stmt.bindStringParameter(1, filePath); 1.58 + stmt.bindStringParameter(2, "http://" + site + "/file"); 1.59 + stmt.bindInt32Parameter(3, dm.DOWNLOAD_FINISHED); 1.60 + 1.61 + // Add it! 1.62 + stmt.execute(); 1.63 + } 1.64 + } 1.65 + finally { 1.66 + stmt.reset(); 1.67 + stmt.finalize(); 1.68 + } 1.69 + 1.70 + // Close the UI if necessary 1.71 + let wm = Cc["@mozilla.org/appshell/window-mediator;1"]. 1.72 + getService(Ci.nsIWindowMediator); 1.73 + let win = wm.getMostRecentWindow("Download:Manager"); 1.74 + if (win) win.close(); 1.75 + 1.76 + let obs = Cc["@mozilla.org/observer-service;1"]. 1.77 + getService(Ci.nsIObserverService); 1.78 + const DLMGR_UI_DONE = "download-manager-ui-done"; 1.79 + 1.80 + let testPhase = 0; 1.81 + let testObs = { 1.82 + observe: function(aSubject, aTopic, aData) { 1.83 + if (aTopic != DLMGR_UI_DONE) 1.84 + return; 1.85 + 1.86 + let win = aSubject.QueryInterface(Ci.nsIDOMWindow); 1.87 + win.focus(); 1.88 + let $ = function(aId) win.document.getElementById(aId); 1.89 + let downloadView = $("downloadView"); 1.90 + let searchbox = $("searchbox"); 1.91 + let clearList = $("clearListButton"); 1.92 + 1.93 + // The list must have built, so figure out what test to do 1.94 + switch (testPhase++) { 1.95 + case 0: 1.96 + // Make sure the button is initially enabled 1.97 + is(clearList.disabled, false, "Clear list is enabled for default 2 item view"); 1.98 + 1.99 + // Search for multiple words in any order in all places 1.100 + searchbox.value = "delete me"; 1.101 + searchbox.doCommand(); 1.102 + 1.103 + break; 1.104 + case 1: 1.105 + // Search came back with 1 item 1.106 + is(downloadView.itemCount, 1, "Search found the item to delete"); 1.107 + is(clearList.disabled, false, "Clear list is enabled for search matching 1 item"); 1.108 + 1.109 + // Clear the list that has the single matched item 1.110 + clearList.doCommand(); 1.111 + 1.112 + break; 1.113 + case 2: 1.114 + // Done rebuilding with one item left 1.115 + is(downloadView.itemCount, 1, "Clear list rebuilt the list with one"); 1.116 + is(clearList.disabled, false, "Clear list still enabled for 1 item in default view"); 1.117 + 1.118 + // Clear the whole list 1.119 + clearList.doCommand(); 1.120 + 1.121 + break; 1.122 + case 3: 1.123 + // There's nothing left 1.124 + is(downloadView.itemCount, 0, "Clear list killed everything"); 1.125 + is(clearList.disabled, true, "Clear list is disabled for no items"); 1.126 + 1.127 + // We're done! 1.128 + win.close(); 1.129 + obs.removeObserver(testObs, DLMGR_UI_DONE); 1.130 + SimpleTest.finish(); 1.131 + 1.132 + break; 1.133 + } 1.134 + } 1.135 + }; 1.136 + obs.addObserver(testObs, DLMGR_UI_DONE, false); 1.137 + 1.138 + // Show the Download Manager UI 1.139 + dmui.show(); 1.140 + 1.141 + SimpleTest.waitForExplicitFinish(); 1.142 +} 1.143 + 1.144 + ]]> 1.145 + </script> 1.146 + 1.147 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.148 + <p id="display"></p> 1.149 + <div id="content" style="display:none;"></div> 1.150 + <pre id="test"></pre> 1.151 + </body> 1.152 +</window>