bug 1385706: marionette: fix WebDriver:TakeScreenshot to use viewport bounds; r=ato

The WebDriver:TakeScreenshot command relied on the document element's
clientWidth/clientHeight, but should according to the WebDriver
specification use the viewport's dimensions.

Thanks-to: JinaJita <jitajina@gmail.com>
This commit is contained in:
Kristian Klausen 2019-01-09 14:47:04 +00:00 committed by Andreas Tolfsen
parent 94a824b783
commit b21f9d63a7
3 changed files with 4 additions and 13 deletions

View File

@ -72,14 +72,12 @@ capture.element = function(node, highlights = []) {
* The canvas element where the viewport has been painted on.
*/
capture.viewport = function(win, highlights = []) {
let rootNode = win.document.documentElement;
return capture.canvas(
win,
win.pageXOffset,
win.pageYOffset,
rootNode.clientWidth,
rootNode.clientHeight,
win.innerWidth,
win.innerHeight,
{highlights});
};

View File

@ -67,10 +67,7 @@ class ScreenCaptureTestCase(MarionetteTestCase):
@property
def viewport_dimensions(self):
return self.marionette.execute_script("""
return [arguments[0].clientWidth,
arguments[0].clientHeight];
""", script_args=[self.document_element])
return self.marionette.execute_script("return [window.innerWidth, window.innerHeight];")
def assert_png(self, screenshot):
"""Test that screenshot is a Base64 encoded PNG file."""

View File

@ -1,6 +1,2 @@
def document_dimensions(session):
return tuple(session.execute_script("""
let devicePixelRatio = window.devicePixelRatio;
let rect = document.documentElement.getBoundingClientRect();
return [Math.floor(rect.width * devicePixelRatio), Math.floor(rect.height * devicePixelRatio)];
"""))
return tuple(session.execute_script("return [window.innerWidth, window.innerHeight];"))