Bug 819930 - Part 2: Add a GCLI command for emulating CSS media types. r=jwalker

This commit is contained in:
Graeme McCutcheon 2013-07-17 17:32:45 +01:00
parent 5d31223735
commit de2c18656c
5 changed files with 166 additions and 0 deletions

View File

@ -2167,3 +2167,49 @@ gcli.addCommand({
}
});
}(this));
/* CmdMedia ------------------------------------------------------- */
(function(module) {
/**
* 'media' command
*/
gcli.addCommand({
name: "media",
description: gcli.lookup("mediaDesc")
});
gcli.addCommand({
name: "media emulate",
description: gcli.lookup("mediaEmulateDesc"),
manual: gcli.lookup("mediaEmulateManual"),
params: [
{
name: "type",
description: gcli.lookup("mediaEmulateType"),
type: {
name: "selection",
data: ["braille", "embossed", "handheld", "print", "projection",
"screen", "speech", "tty", "tv"]
}
}
],
exec: function(args, context) {
let markupDocumentViewer = context.environment.chromeWindow
.gBrowser.markupDocumentViewer;
markupDocumentViewer.emulateMedium(args.type);
}
});
gcli.addCommand({
name: "media reset",
description: gcli.lookup("mediaResetDesc"),
manual: gcli.lookup("mediaEmulateManual"),
exec: function(args, context) {
let markupDocumentViewer = context.environment.chromeWindow
.gBrowser.markupDocumentViewer;
markupDocumentViewer.stopEmulatingMedium();
}
});
}(this));

View File

@ -35,6 +35,8 @@ MOCHITEST_BROWSER_FILES = \
browser_cmd_cookie.js \
browser_cmd_jsb.js \
browser_cmd_jsb_script.jsi \
browser_cmd_media.html \
browser_cmd_media.js \
browser_cmd_pagemod_export.html \
browser_cmd_pagemod_export.js \
browser_cmd_pref.js \

View File

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>GCLI Test for Bug 819930</title>
<style>
@media braille {
body {
background-color: yellow;
}
}
@media embossed {
body {
background-color: indigo;
}
}
@media screen {
body {
background-color: white;
}
}
</style>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,80 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that screenshot command works properly
const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" +
"test/browser_cmd_media.html";
let tests = {
testInput: function(options) {
return helpers.audit(options, [
{
setup: "media emulate braille",
check: {
input: "media emulate braille",
markup: "VVVVVVVVVVVVVVVVVVVVV",
status: "VALID",
args: {
type: { value: "braille"},
}
},
},
{
setup: "media reset",
check: {
input: "media reset",
markup: "VVVVVVVVVVV",
status: "VALID",
args: {
}
},
},
]);
},
testEmulateMedia: function(options) {
return helpers.audit(options, [
{
setup: "media emulate braille",
check: {
args: {
type: { value: "braille"}
}
},
exec: {
output: ""
},
post: function() {
let body = options.window.document.body;
let style = options.window.getComputedStyle(body);
is(style.backgroundColor, "rgb(255, 255, 0)", "media correctly emulated");
}
}
]);
},
testEndMediaEmulation: function(options) {
return helpers.audit(options, [
{
setup: function() {
let mDV = options.browser.markupDocumentViewer;
mDV.emulateMedium("embossed");
return helpers.setInput(options, "media reset");
},
exec: {
output: ""
},
post: function() {
let body = options.window.document.body;
let style = options.window.getComputedStyle(body);
is(style.backgroundColor, "rgb(255, 255, 255)", "media reset");
}
}
]);
}
};
function test() {
helpers.addTabWithToolbar(TEST_URI, function(options) {
return helpers.runTests(options, tests);
}).then(finish);
}

View File

@ -1282,3 +1282,13 @@ listenInitOutput=Listening on port %1$S
# LOCALIZATION NOTE (listenNoInitOutput) Text of a message output during the
# execution of the 'listen' command.
listenNoInitOutput=DebuggerServer not initialized
# LOCALIZATION NOTE (mediaDesc, mediaEmulateDesc, mediaEmulateManual,
# mediaEmulateType, mediaResetDesc, mediaResetManual) These strings describe
# the 'media' commands and all available parameters.
mediaDesc=CSS media type emulation
mediaEmulateDesc=Emulate a specified CSS media type
mediaEmulateManual=View the document as if rendered on a device supporting the given media type, with the relevant CSS rules applied.
mediaEmulateType=The media type to emulate
mediaResetDesc=Stop emulating a CSS media type
mediaResetManual=Stop emulating a CSS media type