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.

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

mercurial