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.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 5 <!--
michael@0 6 * This test basically checks if the download manager
michael@0 7 * closes when you press the esc key and accel + w.
michael@0 8 -->
michael@0 9
michael@0 10 <window title="Download Manager Test"
michael@0 11 onload="runTest();"
michael@0 12 xmlns:html="http://www.w3.org/1999/xhtml"
michael@0 13 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 14
michael@0 15 <script type="application/javascript"
michael@0 16 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 17 <script type="application/javascript"
michael@0 18 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 19 <script type="application/javascript"
michael@0 20 src="utils.js"/>
michael@0 21
michael@0 22 <script type="application/javascript">
michael@0 23
michael@0 24 <![CDATA[
michael@0 25
michael@0 26 const dmui = getDMUI();
michael@0 27
michael@0 28 function testCloseDMWithEscKey(aWin)
michael@0 29 {
michael@0 30 function dmWindowClosedListener() {
michael@0 31 aWin.removeEventListener("unload", dmWindowClosedListener, false);
michael@0 32 ok(!dmui.visible, "DMUI closes with ESC key");
michael@0 33 dmui.show();
michael@0 34 }
michael@0 35 aWin.addEventListener("unload", dmWindowClosedListener, false);
michael@0 36
michael@0 37 synthesizeKey("VK_ESCAPE", { }, aWin);
michael@0 38 }
michael@0 39
michael@0 40 function testCloseDMWithAccelKey(aWin)
michael@0 41 {
michael@0 42 function dmWindowClosedListener() {
michael@0 43 aWin.removeEventListener("unload", dmWindowClosedListener, false);
michael@0 44 ok(!dmui.visible, "DMUI closes with accel + w");
michael@0 45 setCleanState();
michael@0 46 SimpleTest.finish();
michael@0 47 }
michael@0 48 aWin.addEventListener("unload", dmWindowClosedListener, false);
michael@0 49
michael@0 50 synthesizeKey("w", { accelKey: true }, aWin);
michael@0 51 }
michael@0 52
michael@0 53 function runTest()
michael@0 54 {
michael@0 55 if (!dmui) {
michael@0 56 todo(false, "skip test for toolkit download manager UI");
michael@0 57 return;
michael@0 58 }
michael@0 59
michael@0 60 const DLMGR_UI_DONE = "download-manager-ui-done";
michael@0 61
michael@0 62 // Close the DM UI if it is already open
michael@0 63 let dm_win = getDMWindow();
michael@0 64 if (dm_win) dm_win.close();
michael@0 65
michael@0 66 let testPhase = 0;
michael@0 67 // Specify an observer that will be notified when the dm has been rendered on screen
michael@0 68 let obs = Cc["@mozilla.org/observer-service;1"].
michael@0 69 getService(Ci.nsIObserverService);
michael@0 70 let testObs = {
michael@0 71 observe: function(aSubject, aTopic, aData) {
michael@0 72 SimpleTest.waitForFocus(function () { closeDM(aSubject) }, aSubject);
michael@0 73 }
michael@0 74 };
michael@0 75
michael@0 76 function closeDM(win) {
michael@0 77 switch(testPhase++) {
michael@0 78 case 0:
michael@0 79 testCloseDMWithEscKey(win);
michael@0 80 break;
michael@0 81 case 1:
michael@0 82 obs.removeObserver(testObs, DLMGR_UI_DONE);
michael@0 83 testCloseDMWithAccelKey(win);
michael@0 84 }
michael@0 85 }
michael@0 86 obs.addObserver(testObs, DLMGR_UI_DONE, false);
michael@0 87
michael@0 88 dmui.show();
michael@0 89
michael@0 90 SimpleTest.waitForExplicitFinish();
michael@0 91 }
michael@0 92
michael@0 93 ]]>
michael@0 94 </script>
michael@0 95
michael@0 96 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 97 <p id="display"></p>
michael@0 98 <div id="content" style="display: none"></div>
michael@0 99 <pre id="test"></pre>
michael@0 100 </body>
michael@0 101 </window>

mercurial