toolkit/mozapps/downloads/tests/chrome/test_esc_key_closes_clears.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_esc_key_closes_clears.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     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 + * This test ensures that the escape key closes the download manager.  This test
    1.10 + * was added in bug 416303.
    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 +const DLMGR_UI_DONE = "download-manager-ui-done";
    1.28 +
    1.29 +let os = Cc["@mozilla.org/observer-service;1"].
    1.30 +         getService(Ci.nsIObserverService);
    1.31 +
    1.32 +function test()
    1.33 +{
    1.34 +  var dmui = getDMUI();
    1.35 +  if (!dmui) {
    1.36 +    todo(false, "skip test for toolkit download manager UI");
    1.37 +    return;
    1.38 +  }
    1.39 +
    1.40 +  // Close the UI if necessary
    1.41 +  let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
    1.42 +           getService(Ci.nsIWindowMediator);
    1.43 +  let win = wm.getMostRecentWindow("Download:Manager");
    1.44 +  if (win) win.close();
    1.45 +
    1.46 +  // Register with the observer service
    1.47 +  os.addObserver(testObs, DLMGR_UI_DONE, false);
    1.48 +
    1.49 +  // Show the Download Manager UI
    1.50 +  dmui.show();
    1.51 +
    1.52 +  SimpleTest.waitForExplicitFinish();
    1.53 +}
    1.54 +
    1.55 +let testObs = {
    1.56 +  observe: function(aSubject, aTopic, aData)
    1.57 +  {
    1.58 +    if (aTopic != DLMGR_UI_DONE)
    1.59 +      return;
    1.60 +
    1.61 +    SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
    1.62 +  }
    1.63 +};
    1.64 +
    1.65 +function continueTest(win)
    1.66 +{
    1.67 +  // Put in a value to clear out
    1.68 +  let search = win.document.getElementById("searchbox");
    1.69 +  search.focus();
    1.70 +  search.value = "download manager escape test";
    1.71 +
    1.72 +  // Send the escape key to the download manager UI window
    1.73 +  let sendEscape = function() synthesizeKey("VK_ESCAPE", {}, win);
    1.74 +
    1.75 +  // Escape from search box
    1.76 +  sendEscape();
    1.77 +  is(win.closed, false,
    1.78 +    "Escape doesn't close the window when in the search box");
    1.79 +  is(search.value, "", "Escape correctly emptied the search box");
    1.80 +
    1.81 +  // Escape from list (escape from search box moves focus to list)
    1.82 +  sendEscape();
    1.83 +  is(win.closed, true,
    1.84 +    "Previous escape moved focus to list and now escape closed the window");
    1.85 +
    1.86 +  os.removeObserver(testObs, DLMGR_UI_DONE);
    1.87 +  SimpleTest.finish();
    1.88 +};
    1.89 +
    1.90 +  ]]>
    1.91 +  </script>
    1.92 +
    1.93 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.94 +    <p id="display"></p>
    1.95 +    <div id="content" style="display:none;"></div>
    1.96 +    <pre id="test"></pre>
    1.97 +  </body>
    1.98 +</window>

mercurial