toolkit/mozapps/downloads/tests/chrome/test_esc_key_closes_clears.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  * This test ensures that the escape key closes the download manager.  This test
     7  * was added in bug 416303.
     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 const DLMGR_UI_DONE = "download-manager-ui-done";
    26 let os = Cc["@mozilla.org/observer-service;1"].
    27          getService(Ci.nsIObserverService);
    29 function test()
    30 {
    31   var dmui = getDMUI();
    32   if (!dmui) {
    33     todo(false, "skip test for toolkit download manager UI");
    34     return;
    35   }
    37   // Close the UI if necessary
    38   let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
    39            getService(Ci.nsIWindowMediator);
    40   let win = wm.getMostRecentWindow("Download:Manager");
    41   if (win) win.close();
    43   // Register with the observer service
    44   os.addObserver(testObs, DLMGR_UI_DONE, false);
    46   // Show the Download Manager UI
    47   dmui.show();
    49   SimpleTest.waitForExplicitFinish();
    50 }
    52 let testObs = {
    53   observe: function(aSubject, aTopic, aData)
    54   {
    55     if (aTopic != DLMGR_UI_DONE)
    56       return;
    58     SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
    59   }
    60 };
    62 function continueTest(win)
    63 {
    64   // Put in a value to clear out
    65   let search = win.document.getElementById("searchbox");
    66   search.focus();
    67   search.value = "download manager escape test";
    69   // Send the escape key to the download manager UI window
    70   let sendEscape = function() synthesizeKey("VK_ESCAPE", {}, win);
    72   // Escape from search box
    73   sendEscape();
    74   is(win.closed, false,
    75     "Escape doesn't close the window when in the search box");
    76   is(search.value, "", "Escape correctly emptied the search box");
    78   // Escape from list (escape from search box moves focus to list)
    79   sendEscape();
    80   is(win.closed, true,
    81     "Previous escape moved focus to list and now escape closed the window");
    83   os.removeObserver(testObs, DLMGR_UI_DONE);
    84   SimpleTest.finish();
    85 };
    87   ]]>
    88   </script>
    90   <body xmlns="http://www.w3.org/1999/xhtml">
    91     <p id="display"></p>
    92     <div id="content" style="display:none;"></div>
    93     <pre id="test"></pre>
    94   </body>
    95 </window>

mercurial