1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/commandline/test/browser_cmd_screenshot.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,183 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test that screenshot command works properly 1.8 +const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" + 1.9 + "test/browser_cmd_screenshot.html"; 1.10 + 1.11 +let FileUtils = (Cu.import("resource://gre/modules/FileUtils.jsm", {})).FileUtils; 1.12 + 1.13 +function test() { 1.14 + return Task.spawn(spawnTest).then(finish, helpers.handleError); 1.15 +} 1.16 + 1.17 +function spawnTest() { 1.18 + waitForExplicitFinish(); 1.19 + 1.20 + info("RUN TEST: non-private window"); 1.21 + let normWin = yield addWindow({ private: false }); 1.22 + yield addTabWithToolbarRunTests(normWin); 1.23 + normWin.close(); 1.24 + 1.25 + info("RUN TEST: private window"); 1.26 + let pbWin = yield addWindow({ private: true }); 1.27 + yield addTabWithToolbarRunTests(pbWin); 1.28 + pbWin.close(); 1.29 +} 1.30 + 1.31 +function addTabWithToolbarRunTests(win) { 1.32 + let options = yield helpers.openTab(TEST_URI, { chromeWindow: win }); 1.33 + yield helpers.openToolbar(options); 1.34 + 1.35 + // Test input status 1.36 + yield helpers.audit(options, [ 1.37 + { 1.38 + setup: 'screenshot', 1.39 + check: { 1.40 + input: 'screenshot', 1.41 + markup: 'VVVVVVVVVV', 1.42 + status: 'VALID', 1.43 + args: { 1.44 + } 1.45 + }, 1.46 + }, 1.47 + { 1.48 + setup: 'screenshot abc.png', 1.49 + check: { 1.50 + input: 'screenshot abc.png', 1.51 + markup: 'VVVVVVVVVVVVVVVVVV', 1.52 + status: 'VALID', 1.53 + args: { 1.54 + filename: { value: "abc.png"}, 1.55 + } 1.56 + }, 1.57 + }, 1.58 + { 1.59 + setup: 'screenshot --fullpage', 1.60 + check: { 1.61 + input: 'screenshot --fullpage', 1.62 + markup: 'VVVVVVVVVVVVVVVVVVVVV', 1.63 + status: 'VALID', 1.64 + args: { 1.65 + fullpage: { value: true}, 1.66 + } 1.67 + }, 1.68 + }, 1.69 + { 1.70 + setup: 'screenshot abc --delay 5', 1.71 + check: { 1.72 + input: 'screenshot abc --delay 5', 1.73 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', 1.74 + status: 'VALID', 1.75 + args: { 1.76 + filename: { value: "abc"}, 1.77 + delay: { value: 5 }, 1.78 + } 1.79 + }, 1.80 + }, 1.81 + { 1.82 + setup: 'screenshot --selector img#testImage', 1.83 + check: { 1.84 + input: 'screenshot --selector img#testImage', 1.85 + markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', 1.86 + status: 'VALID', 1.87 + args: { 1.88 + selector: { 1.89 + value: options.window.document.getElementById("testImage") 1.90 + }, 1.91 + } 1.92 + }, 1.93 + }, 1.94 + ]); 1.95 + 1.96 + // Test capture to file 1.97 + let file = FileUtils.getFile("TmpD", [ "TestScreenshotFile.png" ]); 1.98 + 1.99 + yield helpers.audit(options, [ 1.100 + { 1.101 + setup: 'screenshot ' + file.path, 1.102 + check: { 1.103 + args: { 1.104 + filename: { value: "" + file.path }, 1.105 + fullpage: { value: false }, 1.106 + clipboard: { value: false }, 1.107 + chrome: { value: false }, 1.108 + }, 1.109 + }, 1.110 + exec: { 1.111 + output: new RegExp("^Saved to "), 1.112 + }, 1.113 + post: function() { 1.114 + // Bug 849168: screenshot command tests fail in try but not locally 1.115 + // ok(file.exists(), "Screenshot file exists"); 1.116 + 1.117 + if (file.exists()) { 1.118 + file.remove(false); 1.119 + } 1.120 + } 1.121 + }, 1.122 + ]); 1.123 + 1.124 + // Test capture to clipboard 1.125 + let clipid = Ci.nsIClipboard; 1.126 + let clip = Cc["@mozilla.org/widget/clipboard;1"].getService(clipid); 1.127 + let trans = Cc["@mozilla.org/widget/transferable;1"] 1.128 + .createInstance(Ci.nsITransferable); 1.129 + trans.init(null); 1.130 + trans.addDataFlavor("image/png"); 1.131 + 1.132 + yield helpers.audit(options, [ 1.133 + { 1.134 + setup: 'screenshot --fullpage --clipboard', 1.135 + check: { 1.136 + args: { 1.137 + fullpage: { value: true }, 1.138 + clipboard: { value: true }, 1.139 + chrome: { value: false }, 1.140 + }, 1.141 + }, 1.142 + exec: { 1.143 + output: new RegExp("^Copied to clipboard.$"), 1.144 + }, 1.145 + post: function() { 1.146 + try { 1.147 + clip.getData(trans, clipid.kGlobalClipboard); 1.148 + let str = new Object(); 1.149 + let strLength = new Object(); 1.150 + trans.getTransferData("image/png", str, strLength); 1.151 + 1.152 + ok(str.value, "screenshot exists"); 1.153 + ok(strLength.value > 0, "screenshot has length"); 1.154 + } 1.155 + finally { 1.156 + Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true); 1.157 + 1.158 + // Recent PB changes to the test I'm modifying removed the 'pb' 1.159 + // variable, but left this line in tact. This seems so obviously 1.160 + // wrong that I'm leaving this in in case the analysis is wrong 1.161 + // pb.privateBrowsingEnabled = true; 1.162 + } 1.163 + } 1.164 + }, 1.165 + ]); 1.166 + 1.167 + yield helpers.closeToolbar(options); 1.168 + yield helpers.closeTab(options); 1.169 +} 1.170 + 1.171 +function addWindow(windowOptions) { 1.172 + let deferred = promise.defer(); 1.173 + 1.174 + let win = OpenBrowserWindow(windowOptions); 1.175 + 1.176 + // This feels hacky, we should refactor it 1.177 + whenDelayedStartupFinished(win, function() { 1.178 + // Would like to get rid of this executeSoon, but without it the url 1.179 + // (TEST_URI) provided in addTabWithToolbarRunTests hasn't loaded 1.180 + executeSoon(function() { 1.181 + deferred.resolve(win); 1.182 + }); 1.183 + }); 1.184 + 1.185 + return deferred.promise; 1.186 +}