toolkit/mozapps/downloads/tests/chrome/test_close_download_manager.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_close_download_manager.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     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 basically checks if the download manager
    1.10 + * closes when you press the esc key and accel + w.
    1.11 +-->
    1.12 +
    1.13 +<window title="Download Manager Test"
    1.14 +        onload="runTest();"
    1.15 +        xmlns:html="http://www.w3.org/1999/xhtml"
    1.16 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.17 +
    1.18 +  <script type="application/javascript"
    1.19 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.20 +  <script type="application/javascript"
    1.21 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.22 +  <script type="application/javascript"
    1.23 +          src="utils.js"/>
    1.24 +
    1.25 +  <script type="application/javascript">
    1.26 +
    1.27 +  <![CDATA[
    1.28 +
    1.29 +const dmui = getDMUI();
    1.30 +
    1.31 +function testCloseDMWithEscKey(aWin)
    1.32 +{
    1.33 +  function dmWindowClosedListener() {
    1.34 +    aWin.removeEventListener("unload", dmWindowClosedListener, false);
    1.35 +    ok(!dmui.visible, "DMUI closes with ESC key");
    1.36 +    dmui.show();
    1.37 +  }
    1.38 +  aWin.addEventListener("unload", dmWindowClosedListener, false);
    1.39 +
    1.40 +  synthesizeKey("VK_ESCAPE", { }, aWin);
    1.41 +}
    1.42 +
    1.43 +function testCloseDMWithAccelKey(aWin)
    1.44 +{
    1.45 +  function dmWindowClosedListener() {
    1.46 +    aWin.removeEventListener("unload", dmWindowClosedListener, false);
    1.47 +    ok(!dmui.visible, "DMUI closes with accel + w");
    1.48 +    setCleanState();
    1.49 +    SimpleTest.finish();
    1.50 +  }
    1.51 +  aWin.addEventListener("unload", dmWindowClosedListener, false);
    1.52 +
    1.53 +  synthesizeKey("w", { accelKey: true }, aWin);
    1.54 +}
    1.55 +
    1.56 +function runTest()
    1.57 +{
    1.58 +  if (!dmui) {
    1.59 +    todo(false, "skip test for toolkit download manager UI");
    1.60 +    return;
    1.61 +  }
    1.62 +
    1.63 +  const DLMGR_UI_DONE = "download-manager-ui-done";
    1.64 +
    1.65 +  // Close the DM UI if it is already open
    1.66 +  let dm_win = getDMWindow();
    1.67 +  if (dm_win) dm_win.close();
    1.68 +
    1.69 +  let testPhase = 0;
    1.70 +  // Specify an observer that will be notified when the dm has been rendered on screen
    1.71 +  let obs = Cc["@mozilla.org/observer-service;1"].
    1.72 +            getService(Ci.nsIObserverService);
    1.73 +  let testObs = {
    1.74 +    observe: function(aSubject, aTopic, aData) {
    1.75 +      SimpleTest.waitForFocus(function () { closeDM(aSubject) }, aSubject);
    1.76 +    }
    1.77 +  };
    1.78 +
    1.79 +  function closeDM(win) {
    1.80 +    switch(testPhase++) {
    1.81 +      case 0:
    1.82 +        testCloseDMWithEscKey(win);
    1.83 +        break;
    1.84 +      case 1:
    1.85 +        obs.removeObserver(testObs, DLMGR_UI_DONE);
    1.86 +        testCloseDMWithAccelKey(win);
    1.87 +    }
    1.88 +  }
    1.89 +  obs.addObserver(testObs, DLMGR_UI_DONE, false);
    1.90 +
    1.91 +  dmui.show();
    1.92 +
    1.93 +  SimpleTest.waitForExplicitFinish();
    1.94 +}
    1.95 +
    1.96 +  ]]>
    1.97 +  </script>
    1.98 +
    1.99 +  <body xmlns="http://www.w3.org/1999/xhtml">
   1.100 +    <p id="display"></p>
   1.101 +    <div id="content" style="display: none"></div>
   1.102 +    <pre id="test"></pre>
   1.103 +  </body>
   1.104 +</window>

mercurial