michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that screenshot command works properly michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" + michael@0: "test/browser_cmd_screenshot.html"; michael@0: michael@0: let FileUtils = (Cu.import("resource://gre/modules/FileUtils.jsm", {})).FileUtils; michael@0: michael@0: function test() { michael@0: return Task.spawn(spawnTest).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: function spawnTest() { michael@0: waitForExplicitFinish(); michael@0: michael@0: info("RUN TEST: non-private window"); michael@0: let normWin = yield addWindow({ private: false }); michael@0: yield addTabWithToolbarRunTests(normWin); michael@0: normWin.close(); michael@0: michael@0: info("RUN TEST: private window"); michael@0: let pbWin = yield addWindow({ private: true }); michael@0: yield addTabWithToolbarRunTests(pbWin); michael@0: pbWin.close(); michael@0: } michael@0: michael@0: function addTabWithToolbarRunTests(win) { michael@0: let options = yield helpers.openTab(TEST_URI, { chromeWindow: win }); michael@0: yield helpers.openToolbar(options); michael@0: michael@0: // Test input status michael@0: yield helpers.audit(options, [ michael@0: { michael@0: setup: 'screenshot', michael@0: check: { michael@0: input: 'screenshot', michael@0: markup: 'VVVVVVVVVV', michael@0: status: 'VALID', michael@0: args: { michael@0: } michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'screenshot abc.png', michael@0: check: { michael@0: input: 'screenshot abc.png', michael@0: markup: 'VVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: args: { michael@0: filename: { value: "abc.png"}, michael@0: } michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'screenshot --fullpage', michael@0: check: { michael@0: input: 'screenshot --fullpage', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: args: { michael@0: fullpage: { value: true}, michael@0: } michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'screenshot abc --delay 5', michael@0: check: { michael@0: input: 'screenshot abc --delay 5', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: args: { michael@0: filename: { value: "abc"}, michael@0: delay: { value: 5 }, michael@0: } michael@0: }, michael@0: }, michael@0: { michael@0: setup: 'screenshot --selector img#testImage', michael@0: check: { michael@0: input: 'screenshot --selector img#testImage', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: args: { michael@0: selector: { michael@0: value: options.window.document.getElementById("testImage") michael@0: }, michael@0: } michael@0: }, michael@0: }, michael@0: ]); michael@0: michael@0: // Test capture to file michael@0: let file = FileUtils.getFile("TmpD", [ "TestScreenshotFile.png" ]); michael@0: michael@0: yield helpers.audit(options, [ michael@0: { michael@0: setup: 'screenshot ' + file.path, michael@0: check: { michael@0: args: { michael@0: filename: { value: "" + file.path }, michael@0: fullpage: { value: false }, michael@0: clipboard: { value: false }, michael@0: chrome: { value: false }, michael@0: }, michael@0: }, michael@0: exec: { michael@0: output: new RegExp("^Saved to "), michael@0: }, michael@0: post: function() { michael@0: // Bug 849168: screenshot command tests fail in try but not locally michael@0: // ok(file.exists(), "Screenshot file exists"); michael@0: michael@0: if (file.exists()) { michael@0: file.remove(false); michael@0: } michael@0: } michael@0: }, michael@0: ]); michael@0: michael@0: // Test capture to clipboard michael@0: let clipid = Ci.nsIClipboard; michael@0: let clip = Cc["@mozilla.org/widget/clipboard;1"].getService(clipid); michael@0: let trans = Cc["@mozilla.org/widget/transferable;1"] michael@0: .createInstance(Ci.nsITransferable); michael@0: trans.init(null); michael@0: trans.addDataFlavor("image/png"); michael@0: michael@0: yield helpers.audit(options, [ michael@0: { michael@0: setup: 'screenshot --fullpage --clipboard', michael@0: check: { michael@0: args: { michael@0: fullpage: { value: true }, michael@0: clipboard: { value: true }, michael@0: chrome: { value: false }, michael@0: }, michael@0: }, michael@0: exec: { michael@0: output: new RegExp("^Copied to clipboard.$"), michael@0: }, michael@0: post: function() { michael@0: try { michael@0: clip.getData(trans, clipid.kGlobalClipboard); michael@0: let str = new Object(); michael@0: let strLength = new Object(); michael@0: trans.getTransferData("image/png", str, strLength); michael@0: michael@0: ok(str.value, "screenshot exists"); michael@0: ok(strLength.value > 0, "screenshot has length"); michael@0: } michael@0: finally { michael@0: Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true); michael@0: michael@0: // Recent PB changes to the test I'm modifying removed the 'pb' michael@0: // variable, but left this line in tact. This seems so obviously michael@0: // wrong that I'm leaving this in in case the analysis is wrong michael@0: // pb.privateBrowsingEnabled = true; michael@0: } michael@0: } michael@0: }, michael@0: ]); michael@0: michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: } michael@0: michael@0: function addWindow(windowOptions) { michael@0: let deferred = promise.defer(); michael@0: michael@0: let win = OpenBrowserWindow(windowOptions); michael@0: michael@0: // This feels hacky, we should refactor it michael@0: whenDelayedStartupFinished(win, function() { michael@0: // Would like to get rid of this executeSoon, but without it the url michael@0: // (TEST_URI) provided in addTabWithToolbarRunTests hasn't loaded michael@0: executeSoon(function() { michael@0: deferred.resolve(win); michael@0: }); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: }