browser/base/content/test/general/browser_printpreview.js

branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
equal deleted inserted replaced
-1:000000000000 0:917002bbef2f
1 function test() {
2 waitForExplicitFinish();
3
4 ok(!gInPrintPreviewMode,
5 "Should NOT be in print preview mode at starting this tests");
6 // Skip access key test on platforms which don't support access key.
7 if (!/Win|Linux/.test(navigator.platform)) {
8 openPrintPreview(testClosePrintPreviewWithEscKey);
9 } else {
10 openPrintPreview(testClosePrintPreviewWithAccessKey);
11 }
12 }
13
14 function testClosePrintPreviewWithAccessKey() {
15 EventUtils.synthesizeKey("c", { altKey: true });
16 checkPrintPreviewClosed(function (aSucceeded) {
17 ok(aSucceeded,
18 "print preview mode should be finished by access key");
19 openPrintPreview(testClosePrintPreviewWithEscKey);
20 });
21 }
22
23 function testClosePrintPreviewWithEscKey() {
24 EventUtils.synthesizeKey("VK_ESCAPE", {});
25 checkPrintPreviewClosed(function (aSucceeded) {
26 ok(aSucceeded,
27 "print preview mode should be finished by Esc key press");
28 openPrintPreview(testClosePrintPreviewWithClosingWindowShortcutKey);
29 });
30 }
31
32 function testClosePrintPreviewWithClosingWindowShortcutKey() {
33 EventUtils.synthesizeKey("w", { accelKey: true });
34 checkPrintPreviewClosed(function (aSucceeded) {
35 ok(aSucceeded,
36 "print preview mode should be finished by closing window shortcut key");
37 finish();
38 });
39 }
40
41 function openPrintPreview(aCallback) {
42 document.getElementById("cmd_printPreview").doCommand();
43 executeSoon(function () {
44 if (gInPrintPreviewMode) {
45 executeSoon(aCallback);
46 return;
47 }
48 executeSoon(arguments.callee);
49 });
50 }
51
52 function checkPrintPreviewClosed(aCallback) {
53 let count = 0;
54 executeSoon(function () {
55 if (!gInPrintPreviewMode) {
56 executeSoon(function () { aCallback(count < 1000); });
57 return;
58 }
59 if (++count == 1000) {
60 // The test might fail.
61 PrintUtils.exitPrintPreview();
62 }
63 executeSoon(arguments.callee);
64 });
65 }

mercurial