|
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 --> |
|
9 |
|
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"> |
|
14 |
|
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"/> |
|
21 |
|
22 <script type="application/javascript"> |
|
23 |
|
24 <![CDATA[ |
|
25 |
|
26 const dmui = getDMUI(); |
|
27 |
|
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); |
|
36 |
|
37 synthesizeKey("VK_ESCAPE", { }, aWin); |
|
38 } |
|
39 |
|
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); |
|
49 |
|
50 synthesizeKey("w", { accelKey: true }, aWin); |
|
51 } |
|
52 |
|
53 function runTest() |
|
54 { |
|
55 if (!dmui) { |
|
56 todo(false, "skip test for toolkit download manager UI"); |
|
57 return; |
|
58 } |
|
59 |
|
60 const DLMGR_UI_DONE = "download-manager-ui-done"; |
|
61 |
|
62 // Close the DM UI if it is already open |
|
63 let dm_win = getDMWindow(); |
|
64 if (dm_win) dm_win.close(); |
|
65 |
|
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 }; |
|
75 |
|
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); |
|
87 |
|
88 dmui.show(); |
|
89 |
|
90 SimpleTest.waitForExplicitFinish(); |
|
91 } |
|
92 |
|
93 ]]> |
|
94 </script> |
|
95 |
|
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> |