toolkit/mozapps/downloads/tests/chrome/test_select_all.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 429614 to make sure ctrl/cmd-a work to select all downloads and
     7  * hitting delete removes them all.
     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="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    18   <script type="application/javascript"
    19           src="utils.js"/>
    21   <script type="application/javascript">
    22   <![CDATA[
    24 function test()
    25 {
    26   var dmui = getDMUI();
    27   if (!dmui) {
    28     todo(false, "skip test for toolkit download manager UI");
    29     return;
    30   }
    32   let dm = Cc["@mozilla.org/download-manager;1"].
    33            getService(Ci.nsIDownloadManager);
    34   let db = dm.DBConnection;
    36   // Empty any old downloads
    37   db.executeSimpleSQL("DELETE FROM moz_downloads");
    39   // Make a file name for the downloads
    40   let file = Cc["@mozilla.org/file/directory_service;1"].
    41              getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
    42   file.append("selectAll");
    43   let filePath = Cc["@mozilla.org/network/io-service;1"].
    44                  getService(Ci.nsIIOService).newFileURI(file).spec;
    46   let stmt = db.createStatement(
    47     "INSERT INTO moz_downloads (target, source, state) " +
    48     "VALUES (?1, ?2, ?3)");
    50   let sites = ["mozilla.org", "mozilla.com", "select.all"];
    51   try {
    52     for each (let site in sites) {
    53       stmt.bindStringParameter(0, filePath);
    54       stmt.bindStringParameter(1, "http://" + site + "/file");
    55       stmt.bindInt32Parameter(2, dm.DOWNLOAD_FINISHED);
    57       // Add it!
    58       stmt.execute();
    59     }
    60   }
    61   finally {
    62     stmt.reset();
    63     stmt.finalize();
    64   }
    66   // Close the UI if necessary
    67   let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
    68            getService(Ci.nsIWindowMediator);
    69   let win = wm.getMostRecentWindow("Download:Manager");
    70   if (win) win.close();
    72   let obs = Cc["@mozilla.org/observer-service;1"].
    73             getService(Ci.nsIObserverService);
    74   const DLMGR_UI_DONE = "download-manager-ui-done";
    76   let testObs = {
    77     observe: function(aSubject, aTopic, aData) {
    78       if (aTopic != DLMGR_UI_DONE)
    79         return;
    81       SimpleTest.waitForFocus(function () { checkSelectAndRemove(aSubject) }, aSubject);
    82     }
    83   };
    85   var checkSelectAndRemove = function(win)
    86   {
    87     let $ = function(aId) win.document.getElementById(aId);
    88     let downloadView = $("downloadView");
    89     is(downloadView.itemCount, sites.length, "All downloads displayed");
    91     // Select all downloads
    92     let isMac = navigator.platform.search("Mac") == 0;
    93     synthesizeKey("a", { metaKey: isMac, ctrlKey: !isMac }, win);
    94     is(downloadView.selectedCount, sites.length, "All downloads selected");
    96     // Delete all downloads
    97     synthesizeKey("VK_DELETE", {}, win);
    98     is(downloadView.itemCount, 0, "All downloads removed");
   100     // We're done!
   101     win.close();
   102     obs.removeObserver(testObs, DLMGR_UI_DONE);
   103     SimpleTest.finish();
   104   }
   106   obs.addObserver(testObs, DLMGR_UI_DONE, false);
   108   // Show the Download Manager UI
   109   dmui.show();
   111   SimpleTest.waitForExplicitFinish();
   112 }
   114   ]]>
   115   </script>
   117   <body xmlns="http://www.w3.org/1999/xhtml">
   118     <p id="display"></p>
   119     <div id="content" style="display:none;"></div>
   120     <pre id="test"></pre>
   121   </body>
   122 </window>

mercurial