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

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

mercurial