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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/downloads/tests/chrome/test_select_all.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,122 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/.  -->
     1.8 +<!--
     1.9 + * Test bug 429614 to make sure ctrl/cmd-a work to select all downloads and
    1.10 + * hitting delete removes them all.
    1.11 +-->
    1.12 +
    1.13 +<window title="Download Manager Test"
    1.14 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.15 +        onload="test();">
    1.16 +
    1.17 +  <script type="application/javascript"
    1.18 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.19 +  <script type="application/javascript"
    1.20 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.21 +  <script type="application/javascript"
    1.22 +          src="utils.js"/>
    1.23 +
    1.24 +  <script type="application/javascript">
    1.25 +  <![CDATA[
    1.26 +
    1.27 +function test()
    1.28 +{
    1.29 +  var dmui = getDMUI();
    1.30 +  if (!dmui) {
    1.31 +    todo(false, "skip test for toolkit download manager UI");
    1.32 +    return;
    1.33 +  }
    1.34 +
    1.35 +  let dm = Cc["@mozilla.org/download-manager;1"].
    1.36 +           getService(Ci.nsIDownloadManager);
    1.37 +  let db = dm.DBConnection;
    1.38 +
    1.39 +  // Empty any old downloads
    1.40 +  db.executeSimpleSQL("DELETE FROM moz_downloads");
    1.41 +
    1.42 +  // Make a file name for the downloads
    1.43 +  let file = Cc["@mozilla.org/file/directory_service;1"].
    1.44 +             getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
    1.45 +  file.append("selectAll");
    1.46 +  let filePath = Cc["@mozilla.org/network/io-service;1"].
    1.47 +                 getService(Ci.nsIIOService).newFileURI(file).spec;
    1.48 +
    1.49 +  let stmt = db.createStatement(
    1.50 +    "INSERT INTO moz_downloads (target, source, state) " +
    1.51 +    "VALUES (?1, ?2, ?3)");
    1.52 +
    1.53 +  let sites = ["mozilla.org", "mozilla.com", "select.all"];
    1.54 +  try {
    1.55 +    for each (let site in sites) {
    1.56 +      stmt.bindStringParameter(0, filePath);
    1.57 +      stmt.bindStringParameter(1, "http://" + site + "/file");
    1.58 +      stmt.bindInt32Parameter(2, dm.DOWNLOAD_FINISHED);
    1.59 +
    1.60 +      // Add it!
    1.61 +      stmt.execute();
    1.62 +    }
    1.63 +  }
    1.64 +  finally {
    1.65 +    stmt.reset();
    1.66 +    stmt.finalize();
    1.67 +  }
    1.68 +
    1.69 +  // Close the UI if necessary
    1.70 +  let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
    1.71 +           getService(Ci.nsIWindowMediator);
    1.72 +  let win = wm.getMostRecentWindow("Download:Manager");
    1.73 +  if (win) win.close();
    1.74 +
    1.75 +  let obs = Cc["@mozilla.org/observer-service;1"].
    1.76 +            getService(Ci.nsIObserverService);
    1.77 +  const DLMGR_UI_DONE = "download-manager-ui-done";
    1.78 +
    1.79 +  let testObs = {
    1.80 +    observe: function(aSubject, aTopic, aData) {
    1.81 +      if (aTopic != DLMGR_UI_DONE)
    1.82 +        return;
    1.83 +
    1.84 +      SimpleTest.waitForFocus(function () { checkSelectAndRemove(aSubject) }, aSubject);
    1.85 +    }
    1.86 +  };
    1.87 +
    1.88 +  var checkSelectAndRemove = function(win)
    1.89 +  {
    1.90 +    let $ = function(aId) win.document.getElementById(aId);
    1.91 +    let downloadView = $("downloadView");
    1.92 +    is(downloadView.itemCount, sites.length, "All downloads displayed");
    1.93 +
    1.94 +    // Select all downloads
    1.95 +    let isMac = navigator.platform.search("Mac") == 0;
    1.96 +    synthesizeKey("a", { metaKey: isMac, ctrlKey: !isMac }, win);
    1.97 +    is(downloadView.selectedCount, sites.length, "All downloads selected");
    1.98 +
    1.99 +    // Delete all downloads
   1.100 +    synthesizeKey("VK_DELETE", {}, win);
   1.101 +    is(downloadView.itemCount, 0, "All downloads removed");
   1.102 +
   1.103 +    // We're done!
   1.104 +    win.close();
   1.105 +    obs.removeObserver(testObs, DLMGR_UI_DONE);
   1.106 +    SimpleTest.finish();
   1.107 +  }
   1.108 +
   1.109 +  obs.addObserver(testObs, DLMGR_UI_DONE, false);
   1.110 +
   1.111 +  // Show the Download Manager UI
   1.112 +  dmui.show();
   1.113 +
   1.114 +  SimpleTest.waitForExplicitFinish();
   1.115 +}
   1.116 +
   1.117 +  ]]>
   1.118 +  </script>
   1.119 +
   1.120 +  <body xmlns="http://www.w3.org/1999/xhtml">
   1.121 +    <p id="display"></p>
   1.122 +    <div id="content" style="display:none;"></div>
   1.123 +    <pre id="test"></pre>
   1.124 +  </body>
   1.125 +</window>

mercurial