Bug 1112913 - Screenshots should return only the view port. r=dburns
authorJulien Pagès <j.parkouss@gmail.com>
Mon, 02 Feb 2015 13:57:00 +0100
changeset 227166 daf4500bdb55a3b1349bcd3bd7b6ee77099e64f9
parent 227165 7412d0c1968f4e083671c5de674c067947a948cd
child 227167 8c0775a973314280adea57e544c500df11076a6e
child 227179 b28f97ae095a175b41e41746926e63f3d3f272bd
push id55040
push usercbook@mozilla.com
push dateTue, 03 Feb 2015 09:03:55 +0000
treeherdermozilla-inbound@daf4500bdb55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdburns
bugs1112913
milestone38.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 1112913 - Screenshots should return only the view port. r=dburns
testing/marionette/client/marionette/marionette.py
testing/marionette/marionette-listener.js
testing/marionette/marionette-server.js
--- a/testing/marionette/client/marionette/marionette.py
+++ b/testing/marionette/client/marionette/marionette.py
@@ -1549,17 +1549,18 @@ class Marionette(object):
         """
 
         return self._send_message("getCookies", "value")
 
     @property
     def application_cache(self):
         return ApplicationCache(self)
 
-    def screenshot(self, element=None, highlights=None, format="base64"):
+    def screenshot(self, element=None, highlights=None, format="base64",
+                   full=True):
         """Takes a screenshot of a web element or the current frame.
 
         The screen capture is returned as a lossless PNG image encoded
         as a base 64 string by default. If the `element` argument is defined the
         capture area will be limited to the bounding box of that
         element.  Otherwise, the capture area will be the bounding box
         of the current frame.
 
@@ -1568,25 +1569,29 @@ class Marionette(object):
 
         :param highlights: A list of HTMLElement objects to draw a red
             box around in the returned screenshot.
 
         :param format: if "base64" (the default), returns the screenshot
             as a base64-string. If "binary", the data is decoded and
             returned as raw binary.
 
+        :param full: If True (the default), the capture area will be the
+            complete frame. Else only the viewport is captured. Only applies
+            when `element` is None.
         """
 
         if element:
             element = element.id
         lights = None
         if highlights:
             lights = [highlight.id for highlight in highlights]
         screenshot_data = self._send_message("takeScreenshot", "value",
-                                  id=element, highlights=lights)
+                                             id=element, highlights=lights,
+                                             full=full)
         if format == 'base64':
             return screenshot_data
         elif format == 'binary':
             return base64.b64decode(screenshot_data.encode('ascii'))
         else:
             raise ValueError("format parameter must be either 'base64'"
                              " or 'binary', not {0}".format(repr(format)))
 
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -2098,20 +2098,30 @@ function takeScreenshot(msg) {
   let highlights = msg.json.highlights;
 
   var document = curFrame.document;
   var rect, win, width, height, left, top;
   // node can be either a window or an arbitrary DOM node
   if (node == curFrame) {
     // node is a window
     win = node;
-    width = document.body.scrollWidth;
-    height = document.body.scrollHeight;
-    top = 0;
-    left = 0;
+    if (msg.json.full) {
+      // the full window
+      width = document.body.scrollWidth;
+      height = document.body.scrollHeight;
+      top = 0;
+      left = 0;
+    }
+    else {
+      // only the viewport
+      width = document.documentElement.clientWidth;
+      height = document.documentElement.clientHeight;
+      left = curFrame.pageXOffset;
+      top = curFrame.pageYOffset;
+    }
   }
   else {
     // node is an arbitrary DOM node
     win = node.ownerDocument.defaultView;
     rect = node.getBoundingClientRect();
     width = rect.width;
     height = rect.height;
     top = rect.top;
--- a/testing/marionette/marionette-server.js
+++ b/testing/marionette/marionette-server.js
@@ -2692,17 +2692,18 @@ MarionetteServerConnection.prototype = {
       context.drawWindow(win, 0, 0, width, height, "rgb(255,255,255)", flags);
       var dataUrl = canvas.toDataURL("image/png", "");
       var data = dataUrl.substring(dataUrl.indexOf(",") + 1);
       this.sendResponse(data, this.command_id);
     }
     else {
       this.sendAsync("takeScreenshot",
                    {id: aRequest.parameters.id,
-                    highlights: aRequest.parameters.highlights},
+                    highlights: aRequest.parameters.highlights,
+                    full: aRequest.parameters.full},
                    this.command_id);
     }
   },
 
   /**
    * Get the current browser orientation.
    *
    * Will return one of the valid primary orientation values