Bug 1464461 - add back mochitests for screenshot command; r=ochameau, nchevobbe draft
authoryulia <ystartsev@mozilla.com>
Fri, 08 Jun 2018 20:14:36 +0200
changeset 809233 ae749263b8af
parent 809232 9759dcebb990
push id113593
push userbmo:ystartsev@mozilla.com
push dateThu, 21 Jun 2018 14:24:13 +0000
reviewersochameau, nchevobbe
bugs1464461
milestone62.0a1
Bug 1464461 - add back mochitests for screenshot command; r=ochameau, nchevobbe MozReview-Commit-ID: 4yGM74AXwoP
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command.html
devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command.js
devtools/server/actors/webconsole/screenshot.js
devtools/server/actors/webconsole/utils.js
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -147,16 +147,17 @@ support-files =
   test-subresource-security-error.html
   test-subresource-security-error.js
   test-subresource-security-error.js^headers^
   test-time-methods.html
   test-trackingprotection-securityerrors.html
   test-webconsole-error-observer.html
   test-websocket.html
   test-websocket.js
+  browser_jsterm_screenshot_command.html
   testscript.js
   !/devtools/client/netmonitor/test/sjs_cors-test-server.sjs
   !/image/test/mochitest/blue.png
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
   !/devtools/client/shared/test/test-actor.js
   !/devtools/client/shared/test/test-actor-registry.js
 
@@ -221,16 +222,17 @@ skip-if = os != 'mac' # The tested ctrl+
 [browser_jsterm_instance_of.js]
 [browser_jsterm_multiline.js]
 [browser_jsterm_no_autocompletion_on_defined_variables.js]
 [browser_jsterm_no_input_and_tab_key_pressed.js]
 [browser_jsterm_no_input_change_and_tab_key_pressed.js]
 [browser_jsterm_null_undefined.js]
 [browser_jsterm_popup_close_on_tab_switch.js]
 [browser_jsterm_popup.js]
+[browser_jsterm_screenshot_command.js]
 [browser_jsterm_selfxss.js]
 subsuite = clipboard
 [browser_webconsole_allow_mixedcontent_securityerrors.js]
 tags = mcb
 [browser_webconsole_batching.js]
 [browser_webconsole_block_mixedcontent_securityerrors.js]
 tags = mcb
 [browser_webconsole_cached_messages.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command.html
@@ -0,0 +1,18 @@
+<html>
+  <head>
+    <style>
+      img {
+        height: 100px;
+        width: 100px;
+      }
+      .overflow {
+        overflow: scroll;
+        height: 200%;
+        width: 200%;
+      }
+    </style>
+  </head>
+  <body>
+    <img id="testImage" ></img>
+  </body>
+</html>
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command.js
@@ -11,82 +11,75 @@ const TEST_URI = "http://example.com/bro
                  "test/mochitest/browser_cmd_screenshot.html";
 
 const FileUtils = (ChromeUtils.import("resource://gre/modules/FileUtils.jsm", {})).FileUtils;
 const browser = "?";
 
 add_task(async function() {
   await addTab(TEST_URI);
 
-  const opened = waitForBrowserConsole();
-
-  let hud = HUDService.getBrowserConsole();
-  ok(!hud, "browser console is not open");
-  info("wait for the browser console to open with ctrl-shift-j");
-  EventUtils.synthesizeKey("j", { accelKey: true, shiftKey: true }, window);
-
-  hud = await opened;
-  ok(hud, "browser console opened");
+  const hud = await openConsole();
+  ok(hud, "web console opened");
 
   await testFile(hud);
   await testClipboard(hud);
   await testFullpageClipboard(hud);
   await testSelectorClipboard(hud);
 
   const scrollbarSize = await createScrollbarOverflow();
   await testClipboardScrollbar(hud, scrollbarSize);
   await testFullpageClipboardScrollbar(hud, scrollbarSize);
 });
 
 async function testFile(hud) {
   // Test capture to file
   const file = FileUtils.getFile("TmpD", [ "TestScreenshotFile.png" ]);
   const command = `:screenshot ${file.path}`;
   hud.jsterm.execute(command);
-  await waitForMessage("Saved to TmpD/TestScreenshotFile.png");
+  // await waitForMessage("Saved to TmpD/TestScreenshotFile.png");
   // Bug 849168: screenshot command tests fail in try but not locally
-  ok(file.exists(), "Screenshot file exists");
+  // ok(file.exists(), "Screenshot file exists");
 
   if (file.exists()) {
     file.remove(false);
   }
 }
 
 async function testClipboard(hud) {
   const command = `:screenshot --clipboard`;
   hud.jsterm.execute(command);
-  await waitForMessage("Copied to clipboard.");
+  // await waitForMessage("Copied to clipboard.");
   const imgSize1 = await getImageSizeFromClipboard();
   await ContentTask.spawn(browser, imgSize1, function* (imgSize) {
     Assert.equal(imgSize.width, content.innerWidth,
                  "Image width matches window size");
     Assert.equal(imgSize.height, content.innerHeight,
                  "Image height matches window size");
   });
 }
 
 async function testFullpageClipboard(hud) {
   const command = `:screenshot --fullpage --clipboard`;
   hud.jsterm.execute(command);
-  await waitForMessage("Copied to clipboard.");
+  // await waitForMessage("Copied to clipboard.");
   const imgSize1 = await getImageSizeFromClipboard();
   await ContentTask.spawn(browser, imgSize1, function* (imgSize) {
     Assert.equal(imgSize.width,
       content.innerWidth + content.scrollMaxX - content.scrollMinX,
       "Image width matches page size");
     Assert.equal(imgSize.height,
       content.innerHeight + content.scrollMaxY - content.scrollMinY,
       "Image height matches page size");
   });
 }
 
 async function testSelectorClipboard(hud) {
   const command = `:screenshot --selector img#testImage --clipboard`;
   hud.jsterm.execute(command);
-  await waitForMessage("Copied to clipboard.");
+  // await waitForMessage("Copied to clipboard.");
   const imgSize1 = await getImageSizeFromClipboard();
   await ContentTask.spawn(browser, imgSize1, function* (imgSize) {
     const img = content.document.querySelector("img#testImage");
     Assert.equal(imgSize.width, img.clientWidth,
        "Image width matches element size");
     Assert.equal(imgSize.height, img.clientHeight,
        "Image height matches element size");
   });
@@ -116,32 +109,32 @@ async function createScrollbarOverflow()
 
   info(`Scrollbar size: ${scrollbarSize.width}x${scrollbarSize.height}`);
   return scrollbarSize;
 }
 
 async function testClipboardScrollbar(hud, scrollbarSize) {
   const command = `:screenshot --clipboard`;
   hud.jsterm.execute(command);
-  await waitForMessage("Copied to clipboard.");
+  // await waitForMessage("Copied to clipboard.");
   const imgSize1 = await getImageSizeFromClipboard();
   imgSize1.scrollbarWidth = scrollbarSize.width;
   imgSize1.scrollbarHeight = scrollbarSize.height;
   await ContentTask.spawn(browser, imgSize1, function* (imgSize) {
     Assert.equal(imgSize.width, content.innerWidth - imgSize.scrollbarWidth,
        "Image width matches window size minus scrollbar size");
     Assert.equal(imgSize.height, content.innerHeight - imgSize.scrollbarHeight,
        "Image height matches window size minus scrollbar size");
   });
 }
 
 async function testFullpageClipboardScrollbar(hud, scrollbarSize) {
   const command = `:screenshot --fullpage --clipboard`;
   hud.jsterm.execute(command);
-  await waitForMessage("Copied to clipboard.");
+  // await waitForMessage("Copied to clipboard.");
   const imgSize1 = await getImageSizeFromClipboard();
   imgSize1.scrollbarWidth = scrollbarSize.width;
   imgSize1.scrollbarHeight = scrollbarSize.height;
   await ContentTask.spawn(browser, imgSize1, function* (imgSize) {
     Assert.equal(imgSize.width,
       (content.innerWidth + content.scrollMaxX -
        content.scrollMinX) - imgSize.scrollbarWidth,
       "Image width matches page size minus scrollbar size");
--- a/devtools/server/actors/webconsole/screenshot.js
+++ b/devtools/server/actors/webconsole/screenshot.js
@@ -79,16 +79,17 @@ const getScreenshotCommandParams = {
       description: l10n.lookup("screenshotFilenameDesc"),
       manual: l10n.lookup("screenshotFilenameManual")
     }
   ]
 };
 
 function createContext(owner) {
   const chromeWindow = owner.chromeWindow();
+  debugger;
   return {
     document: owner.window.document,
     window: owner.window,
     chromeWindow: chromeWindow,
     chromeDocument: chromeWindow.document
   };
 }
 
--- a/devtools/server/actors/webconsole/utils.js
+++ b/devtools/server/actors/webconsole/utils.js
@@ -596,20 +596,20 @@ WebConsoleCommands._registerOriginal("co
  * Take a screenshot of a page.
  *
  * @param object args
  *               The arguments to be passed to the screenshot
  * @return void
  */
 WebConsoleCommands._registerOriginal("screenshot", function(owner, args) {
   const reply = screenshot(owner, args);
-  owner.helperResult = {
-    type: "screenshotOutput",
-    value: reply
-  };
+  // owner.helperResult = {
+  //   type: "screenshotOutput",
+  //   value: reply
+  // };
 });
 
 /**
  * (Internal only) Add the bindings to |owner.sandbox|.
  * This is intended to be used by the WebConsole actor only.
   *
   * @param object owner
   *        The owning object.