2013-03-13 08:51:30 +04:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
// Test that screenshot command works properly
|
2015-09-21 20:07:31 +03:00
|
|
|
const TEST_URI = "http://example.com/browser/devtools/client/commandline/" +
|
2013-03-13 08:51:30 +04:00
|
|
|
"test/browser_cmd_screenshot.html";
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var FileUtils = (Cu.import("resource://gre/modules/FileUtils.jsm", {})).FileUtils;
|
2013-03-13 08:51:30 +04:00
|
|
|
|
2013-09-03 15:20:27 +04:00
|
|
|
function test() {
|
|
|
|
return Task.spawn(spawnTest).then(finish, helpers.handleError);
|
|
|
|
}
|
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
function* spawnTest() {
|
2013-09-03 15:20:27 +04:00
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
info("RUN TEST: non-private window");
|
|
|
|
let normWin = yield addWindow({ private: false });
|
|
|
|
yield addTabWithToolbarRunTests(normWin);
|
|
|
|
normWin.close();
|
|
|
|
|
|
|
|
info("RUN TEST: private window");
|
|
|
|
let pbWin = yield addWindow({ private: true });
|
|
|
|
yield addTabWithToolbarRunTests(pbWin);
|
|
|
|
pbWin.close();
|
|
|
|
}
|
|
|
|
|
2015-05-25 15:42:51 +03:00
|
|
|
function* addTabWithToolbarRunTests(win) {
|
2013-09-03 15:20:27 +04:00
|
|
|
let options = yield helpers.openTab(TEST_URI, { chromeWindow: win });
|
|
|
|
yield helpers.openToolbar(options);
|
|
|
|
|
|
|
|
// Test input status
|
|
|
|
yield helpers.audit(options, [
|
|
|
|
{
|
|
|
|
setup: 'screenshot',
|
|
|
|
check: {
|
|
|
|
input: 'screenshot',
|
|
|
|
markup: 'VVVVVVVVVV',
|
|
|
|
status: 'VALID',
|
|
|
|
args: {
|
|
|
|
}
|
2013-03-13 08:51:30 +04:00
|
|
|
},
|
2013-09-03 15:20:27 +04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setup: 'screenshot abc.png',
|
|
|
|
check: {
|
|
|
|
input: 'screenshot abc.png',
|
|
|
|
markup: 'VVVVVVVVVVVVVVVVVV',
|
|
|
|
status: 'VALID',
|
|
|
|
args: {
|
|
|
|
filename: { value: "abc.png"},
|
|
|
|
}
|
2013-03-13 08:51:30 +04:00
|
|
|
},
|
2013-09-03 15:20:27 +04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setup: 'screenshot --fullpage',
|
|
|
|
check: {
|
|
|
|
input: 'screenshot --fullpage',
|
|
|
|
markup: 'VVVVVVVVVVVVVVVVVVVVV',
|
|
|
|
status: 'VALID',
|
|
|
|
args: {
|
|
|
|
fullpage: { value: true},
|
|
|
|
}
|
2013-03-13 08:51:30 +04:00
|
|
|
},
|
2013-09-03 15:20:27 +04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setup: 'screenshot abc --delay 5',
|
|
|
|
check: {
|
|
|
|
input: 'screenshot abc --delay 5',
|
|
|
|
markup: 'VVVVVVVVVVVVVVVVVVVVVVVV',
|
|
|
|
status: 'VALID',
|
|
|
|
args: {
|
|
|
|
filename: { value: "abc"},
|
|
|
|
delay: { value: 5 },
|
|
|
|
}
|
2013-03-13 08:51:30 +04:00
|
|
|
},
|
2013-09-03 15:20:27 +04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
setup: 'screenshot --selector img#testImage',
|
|
|
|
check: {
|
|
|
|
input: 'screenshot --selector img#testImage',
|
|
|
|
markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV',
|
|
|
|
status: 'VALID',
|
2013-03-13 08:51:30 +04:00
|
|
|
},
|
2013-09-03 15:20:27 +04:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Test capture to file
|
|
|
|
let file = FileUtils.getFile("TmpD", [ "TestScreenshotFile.png" ]);
|
|
|
|
|
|
|
|
yield helpers.audit(options, [
|
|
|
|
{
|
|
|
|
setup: 'screenshot ' + file.path,
|
|
|
|
check: {
|
|
|
|
args: {
|
|
|
|
filename: { value: "" + file.path },
|
|
|
|
fullpage: { value: false },
|
|
|
|
clipboard: { value: false },
|
|
|
|
chrome: { value: false },
|
2013-03-13 08:51:30 +04:00
|
|
|
},
|
|
|
|
},
|
2013-09-03 15:20:27 +04:00
|
|
|
exec: {
|
|
|
|
output: new RegExp("^Saved to "),
|
|
|
|
},
|
|
|
|
post: function() {
|
|
|
|
// Bug 849168: screenshot command tests fail in try but not locally
|
|
|
|
// ok(file.exists(), "Screenshot file exists");
|
2013-03-13 08:51:30 +04:00
|
|
|
|
2013-09-03 15:20:27 +04:00
|
|
|
if (file.exists()) {
|
|
|
|
file.remove(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Test capture to clipboard
|
|
|
|
let clipid = Ci.nsIClipboard;
|
|
|
|
let clip = Cc["@mozilla.org/widget/clipboard;1"].getService(clipid);
|
|
|
|
let trans = Cc["@mozilla.org/widget/transferable;1"]
|
|
|
|
.createInstance(Ci.nsITransferable);
|
|
|
|
trans.init(null);
|
|
|
|
trans.addDataFlavor("image/png");
|
|
|
|
|
|
|
|
yield helpers.audit(options, [
|
|
|
|
{
|
|
|
|
setup: 'screenshot --fullpage --clipboard',
|
|
|
|
check: {
|
|
|
|
args: {
|
|
|
|
fullpage: { value: true },
|
|
|
|
clipboard: { value: true },
|
|
|
|
chrome: { value: false },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
exec: {
|
|
|
|
output: new RegExp("^Copied to clipboard.$"),
|
|
|
|
},
|
|
|
|
post: function() {
|
2015-04-02 20:54:09 +03:00
|
|
|
clip.getData(trans, clipid.kGlobalClipboard);
|
|
|
|
let str = new Object();
|
|
|
|
let strLength = new Object();
|
|
|
|
trans.getTransferData("image/png", str, strLength);
|
2013-03-13 08:51:30 +04:00
|
|
|
|
2015-04-02 20:54:09 +03:00
|
|
|
ok(str.value, "screenshot exists");
|
|
|
|
ok(strLength.value > 0, "screenshot has length");
|
2013-09-03 15:20:27 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
]);
|
2013-03-13 08:51:30 +04:00
|
|
|
|
2013-09-03 15:20:27 +04:00
|
|
|
yield helpers.closeToolbar(options);
|
|
|
|
yield helpers.closeTab(options);
|
2013-03-13 08:51:30 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 15:20:27 +04:00
|
|
|
function addWindow(windowOptions) {
|
2014-06-09 18:16:26 +04:00
|
|
|
return new Promise(resolve => {
|
|
|
|
let win = OpenBrowserWindow(windowOptions);
|
|
|
|
|
|
|
|
// This feels hacky, we should refactor it
|
|
|
|
whenDelayedStartupFinished(win, () => {
|
|
|
|
// Would like to get rid of this executeSoon, but without it the url
|
|
|
|
// (TEST_URI) provided in addTabWithToolbarRunTests hasn't loaded
|
|
|
|
executeSoon(() => {
|
|
|
|
resolve(win);
|
|
|
|
});
|
2013-03-13 08:51:30 +04:00
|
|
|
});
|
2013-12-12 00:36:24 +04:00
|
|
|
});
|
2013-03-13 08:51:30 +04:00
|
|
|
}
|