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.

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

mercurial