toolkit/mozapps/downloads/tests/chrome/test_cleanup_search.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 414850 to make sure only downloads that are shown when
michael@0 7 * searching are cleared and afterwards, the default list is shown.
michael@0 8 *
michael@0 9 * Test bug 430486 to make sure the Clear list button is disabled only when
michael@0 10 * there are no download items visible.
michael@0 11 -->
michael@0 12
michael@0 13 <window title="Download Manager Test"
michael@0 14 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 15 onload="test();">
michael@0 16
michael@0 17 <script type="application/javascript"
michael@0 18 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 19 <script type="application/javascript"
michael@0 20 src="utils.js"/>
michael@0 21
michael@0 22 <script type="application/javascript">
michael@0 23 <![CDATA[
michael@0 24
michael@0 25 function test()
michael@0 26 {
michael@0 27 var dmui = getDMUI();
michael@0 28 if (!dmui) {
michael@0 29 todo(false, "skip test for toolkit download manager UI");
michael@0 30 return;
michael@0 31 }
michael@0 32
michael@0 33 let dm = Cc["@mozilla.org/download-manager;1"].
michael@0 34 getService(Ci.nsIDownloadManager);
michael@0 35 let db = dm.DBConnection;
michael@0 36
michael@0 37 // Empty any old downloads
michael@0 38 db.executeSimpleSQL("DELETE FROM moz_downloads");
michael@0 39
michael@0 40 // Make a file name for the downloads
michael@0 41 let file = Cc["@mozilla.org/file/directory_service;1"].
michael@0 42 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
michael@0 43 file.append("cleanUp");
michael@0 44 let filePath = Cc["@mozilla.org/network/io-service;1"].
michael@0 45 getService(Ci.nsIIOService).newFileURI(file).spec;
michael@0 46
michael@0 47 let stmt = db.createStatement(
michael@0 48 "INSERT INTO moz_downloads (name, target, source, state) " +
michael@0 49 "VALUES (?1, ?2, ?3, ?4)");
michael@0 50
michael@0 51 try {
michael@0 52 for each (let site in ["delete.me", "i.live"]) {
michael@0 53 stmt.bindStringParameter(0, "Super Pimped Download");
michael@0 54 stmt.bindStringParameter(1, filePath);
michael@0 55 stmt.bindStringParameter(2, "http://" + site + "/file");
michael@0 56 stmt.bindInt32Parameter(3, dm.DOWNLOAD_FINISHED);
michael@0 57
michael@0 58 // Add it!
michael@0 59 stmt.execute();
michael@0 60 }
michael@0 61 }
michael@0 62 finally {
michael@0 63 stmt.reset();
michael@0 64 stmt.finalize();
michael@0 65 }
michael@0 66
michael@0 67 // Close the UI if necessary
michael@0 68 let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
michael@0 69 getService(Ci.nsIWindowMediator);
michael@0 70 let win = wm.getMostRecentWindow("Download:Manager");
michael@0 71 if (win) win.close();
michael@0 72
michael@0 73 let obs = Cc["@mozilla.org/observer-service;1"].
michael@0 74 getService(Ci.nsIObserverService);
michael@0 75 const DLMGR_UI_DONE = "download-manager-ui-done";
michael@0 76
michael@0 77 let testPhase = 0;
michael@0 78 let testObs = {
michael@0 79 observe: function(aSubject, aTopic, aData) {
michael@0 80 if (aTopic != DLMGR_UI_DONE)
michael@0 81 return;
michael@0 82
michael@0 83 let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
michael@0 84 win.focus();
michael@0 85 let $ = function(aId) win.document.getElementById(aId);
michael@0 86 let downloadView = $("downloadView");
michael@0 87 let searchbox = $("searchbox");
michael@0 88 let clearList = $("clearListButton");
michael@0 89
michael@0 90 // The list must have built, so figure out what test to do
michael@0 91 switch (testPhase++) {
michael@0 92 case 0:
michael@0 93 // Make sure the button is initially enabled
michael@0 94 is(clearList.disabled, false, "Clear list is enabled for default 2 item view");
michael@0 95
michael@0 96 // Search for multiple words in any order in all places
michael@0 97 searchbox.value = "delete me";
michael@0 98 searchbox.doCommand();
michael@0 99
michael@0 100 break;
michael@0 101 case 1:
michael@0 102 // Search came back with 1 item
michael@0 103 is(downloadView.itemCount, 1, "Search found the item to delete");
michael@0 104 is(clearList.disabled, false, "Clear list is enabled for search matching 1 item");
michael@0 105
michael@0 106 // Clear the list that has the single matched item
michael@0 107 clearList.doCommand();
michael@0 108
michael@0 109 break;
michael@0 110 case 2:
michael@0 111 // Done rebuilding with one item left
michael@0 112 is(downloadView.itemCount, 1, "Clear list rebuilt the list with one");
michael@0 113 is(clearList.disabled, false, "Clear list still enabled for 1 item in default view");
michael@0 114
michael@0 115 // Clear the whole list
michael@0 116 clearList.doCommand();
michael@0 117
michael@0 118 break;
michael@0 119 case 3:
michael@0 120 // There's nothing left
michael@0 121 is(downloadView.itemCount, 0, "Clear list killed everything");
michael@0 122 is(clearList.disabled, true, "Clear list is disabled for no items");
michael@0 123
michael@0 124 // We're done!
michael@0 125 win.close();
michael@0 126 obs.removeObserver(testObs, DLMGR_UI_DONE);
michael@0 127 SimpleTest.finish();
michael@0 128
michael@0 129 break;
michael@0 130 }
michael@0 131 }
michael@0 132 };
michael@0 133 obs.addObserver(testObs, DLMGR_UI_DONE, false);
michael@0 134
michael@0 135 // Show the Download Manager UI
michael@0 136 dmui.show();
michael@0 137
michael@0 138 SimpleTest.waitForExplicitFinish();
michael@0 139 }
michael@0 140
michael@0 141 ]]>
michael@0 142 </script>
michael@0 143
michael@0 144 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 145 <p id="display"></p>
michael@0 146 <div id="content" style="display:none;"></div>
michael@0 147 <pre id="test"></pre>
michael@0 148 </body>
michael@0 149 </window>

mercurial