Bug 819930 - Part 2: Add a GCLI command for emulating CSS media types. r=jwalker
authorGraeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
Wed, 17 Jul 2013 17:32:45 +0100
changeset 152209 5c42e1391bd2a78f0289ce347b3a4f550c45de7d
parent 152208 66f4834afb70e9a75546a1628096c50bfb25990c
child 152210 eeab86551b262c90fa2f2c792957a373976f1e88
push id382
push userakeybl@mozilla.com
push dateMon, 21 Oct 2013 21:47:13 +0000
treeherdermozilla-release@5f1868ee45cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker
bugs819930
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 819930 - Part 2: Add a GCLI command for emulating CSS media types. r=jwalker
browser/devtools/commandline/BuiltinCommands.jsm
browser/devtools/commandline/test/Makefile.in
browser/devtools/commandline/test/browser_cmd_media.html
browser/devtools/commandline/test/browser_cmd_media.js
browser/locales/en-US/chrome/browser/devtools/gclicommands.properties
--- a/browser/devtools/commandline/BuiltinCommands.jsm
+++ b/browser/devtools/commandline/BuiltinCommands.jsm
@@ -2162,8 +2162,54 @@ gcli.addCommand({
       }
     ],
     exec: function(args, context) {
       let utils = new AppCacheUtils();
       return utils.viewEntry(args.key);
     }
   });
 }(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));
--- a/browser/devtools/commandline/test/Makefile.in
+++ b/browser/devtools/commandline/test/Makefile.in
@@ -30,16 +30,18 @@ MOCHITEST_BROWSER_FILES = \
   browser_cmd_appcache_valid_page1.html \
   browser_cmd_appcache_valid_page2.html \
   browser_cmd_appcache_valid_page3.html \
   browser_cmd_commands.js \
   browser_cmd_cookie.html \
   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 \
   browser_cmd_restart.js \
   browser_cmd_screenshot.html \
   browser_cmd_screenshot.js \
   browser_cmd_settings.js \
   browser_gcli_canon.js \
new file mode 100644
--- /dev/null
+++ b/browser/devtools/commandline/test/browser_cmd_media.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/browser/devtools/commandline/test/browser_cmd_media.js
@@ -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);
+}
--- a/browser/locales/en-US/chrome/browser/devtools/gclicommands.properties
+++ b/browser/locales/en-US/chrome/browser/devtools/gclicommands.properties
@@ -1277,8 +1277,18 @@ listenDisabledOutput=Listen is disabled 
 
 # LOCALIZATION NOTE (listenInitOutput) Text of a message output during the
 # execution of the 'listen' command. %1$S is a port number
 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