toolkit/mozapps/downloads/tests/chrome/test_close_download_manager.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 basically checks if the download manager
     7  * closes when you press the esc key and accel + w.
     8 -->
    10 <window title="Download Manager Test"
    11         onload="runTest();"
    12         xmlns:html="http://www.w3.org/1999/xhtml"
    13         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    15   <script type="application/javascript"
    16           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    17   <script type="application/javascript"
    18           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    19   <script type="application/javascript"
    20           src="utils.js"/>
    22   <script type="application/javascript">
    24   <![CDATA[
    26 const dmui = getDMUI();
    28 function testCloseDMWithEscKey(aWin)
    29 {
    30   function dmWindowClosedListener() {
    31     aWin.removeEventListener("unload", dmWindowClosedListener, false);
    32     ok(!dmui.visible, "DMUI closes with ESC key");
    33     dmui.show();
    34   }
    35   aWin.addEventListener("unload", dmWindowClosedListener, false);
    37   synthesizeKey("VK_ESCAPE", { }, aWin);
    38 }
    40 function testCloseDMWithAccelKey(aWin)
    41 {
    42   function dmWindowClosedListener() {
    43     aWin.removeEventListener("unload", dmWindowClosedListener, false);
    44     ok(!dmui.visible, "DMUI closes with accel + w");
    45     setCleanState();
    46     SimpleTest.finish();
    47   }
    48   aWin.addEventListener("unload", dmWindowClosedListener, false);
    50   synthesizeKey("w", { accelKey: true }, aWin);
    51 }
    53 function runTest()
    54 {
    55   if (!dmui) {
    56     todo(false, "skip test for toolkit download manager UI");
    57     return;
    58   }
    60   const DLMGR_UI_DONE = "download-manager-ui-done";
    62   // Close the DM UI if it is already open
    63   let dm_win = getDMWindow();
    64   if (dm_win) dm_win.close();
    66   let testPhase = 0;
    67   // Specify an observer that will be notified when the dm has been rendered on screen
    68   let obs = Cc["@mozilla.org/observer-service;1"].
    69             getService(Ci.nsIObserverService);
    70   let testObs = {
    71     observe: function(aSubject, aTopic, aData) {
    72       SimpleTest.waitForFocus(function () { closeDM(aSubject) }, aSubject);
    73     }
    74   };
    76   function closeDM(win) {
    77     switch(testPhase++) {
    78       case 0:
    79         testCloseDMWithEscKey(win);
    80         break;
    81       case 1:
    82         obs.removeObserver(testObs, DLMGR_UI_DONE);
    83         testCloseDMWithAccelKey(win);
    84     }
    85   }
    86   obs.addObserver(testObs, DLMGR_UI_DONE, false);
    88   dmui.show();
    90   SimpleTest.waitForExplicitFinish();
    91 }
    93   ]]>
    94   </script>
    96   <body xmlns="http://www.w3.org/1999/xhtml">
    97     <p id="display"></p>
    98     <div id="content" style="display: none"></div>
    99     <pre id="test"></pre>
   100   </body>
   101 </window>

mercurial