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

mercurial