1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_printpreview.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +function test() { 1.5 + waitForExplicitFinish(); 1.6 + 1.7 + ok(!gInPrintPreviewMode, 1.8 + "Should NOT be in print preview mode at starting this tests"); 1.9 + // Skip access key test on platforms which don't support access key. 1.10 + if (!/Win|Linux/.test(navigator.platform)) { 1.11 + openPrintPreview(testClosePrintPreviewWithEscKey); 1.12 + } else { 1.13 + openPrintPreview(testClosePrintPreviewWithAccessKey); 1.14 + } 1.15 +} 1.16 + 1.17 +function testClosePrintPreviewWithAccessKey() { 1.18 + EventUtils.synthesizeKey("c", { altKey: true }); 1.19 + checkPrintPreviewClosed(function (aSucceeded) { 1.20 + ok(aSucceeded, 1.21 + "print preview mode should be finished by access key"); 1.22 + openPrintPreview(testClosePrintPreviewWithEscKey); 1.23 + }); 1.24 +} 1.25 + 1.26 +function testClosePrintPreviewWithEscKey() { 1.27 + EventUtils.synthesizeKey("VK_ESCAPE", {}); 1.28 + checkPrintPreviewClosed(function (aSucceeded) { 1.29 + ok(aSucceeded, 1.30 + "print preview mode should be finished by Esc key press"); 1.31 + openPrintPreview(testClosePrintPreviewWithClosingWindowShortcutKey); 1.32 + }); 1.33 +} 1.34 + 1.35 +function testClosePrintPreviewWithClosingWindowShortcutKey() { 1.36 + EventUtils.synthesizeKey("w", { accelKey: true }); 1.37 + checkPrintPreviewClosed(function (aSucceeded) { 1.38 + ok(aSucceeded, 1.39 + "print preview mode should be finished by closing window shortcut key"); 1.40 + finish(); 1.41 + }); 1.42 +} 1.43 + 1.44 +function openPrintPreview(aCallback) { 1.45 + document.getElementById("cmd_printPreview").doCommand(); 1.46 + executeSoon(function () { 1.47 + if (gInPrintPreviewMode) { 1.48 + executeSoon(aCallback); 1.49 + return; 1.50 + } 1.51 + executeSoon(arguments.callee); 1.52 + }); 1.53 +} 1.54 + 1.55 +function checkPrintPreviewClosed(aCallback) { 1.56 + let count = 0; 1.57 + executeSoon(function () { 1.58 + if (!gInPrintPreviewMode) { 1.59 + executeSoon(function () { aCallback(count < 1000); }); 1.60 + return; 1.61 + } 1.62 + if (++count == 1000) { 1.63 + // The test might fail. 1.64 + PrintUtils.exitPrintPreview(); 1.65 + } 1.66 + executeSoon(arguments.callee); 1.67 + }); 1.68 +}