From a959b56acf548b990292d177c9313c49d32c3369 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Thu, 17 Sep 2015 17:12:29 +0100 Subject: [PATCH] Backed out changeset 820865a790e4 (bug 1202663) CLOSED TREE --- testing/marionette/driver.js | 7 +- testing/marionette/listener.js | 114 +++++++++++++++++---------------- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index f43530a21e2..4d61b4f8da4 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -2562,8 +2562,6 @@ GeckoDriver.prototype.clearImportedScripts = function(cmd, resp) { * PNG image encoded as base64 encoded string. */ GeckoDriver.prototype.takeScreenshot = function(cmd, resp) { - let {id, highlights, full} = cmd.parameters; - switch (this.context) { case Context.CHROME: let win = this.getCurrentWindow(); @@ -2606,7 +2604,10 @@ GeckoDriver.prototype.takeScreenshot = function(cmd, resp) { break; case Context.CONTENT: - return this.listener.takeScreenshot(id, highlights, full); + resp.body.value = yield this.listener.takeScreenshot({ + id: cmd.parameters.id, + highlights: cmd.parameters.highlights, + full: cmd.parameters.full}); break; } }; diff --git a/testing/marionette/listener.js b/testing/marionette/listener.js index 5c25c898b60..8447780b3a3 100644 --- a/testing/marionette/listener.js +++ b/testing/marionette/listener.js @@ -196,29 +196,26 @@ function removeMessageListenerId(messageName, handler) { removeMessageListener(messageName + listenerId, handler); } -let getTitleFn = dispatch(getTitle); -let getElementSizeFn = dispatch(getElementSize); -let getPageSourceFn = dispatch(getPageSource); -let getActiveElementFn = dispatch(getActiveElement); -let clickElementFn = dispatch(clickElement); -let goBackFn = dispatch(goBack); -let getElementAttributeFn = dispatch(getElementAttribute); -let getElementTextFn = dispatch(getElementText); -let getElementTagNameFn = dispatch(getElementTagName); -let getElementRectFn = dispatch(getElementRect); -let isElementEnabledFn = dispatch(isElementEnabled); -let getCurrentUrlFn = dispatch(getCurrentUrl); -let findElementContentFn = dispatch(findElementContent); -let findElementsContentFn = dispatch(findElementsContent); -let isElementSelectedFn = dispatch(isElementSelected); -let getElementLocationFn = dispatch(getElementLocation); -let clearElementFn = dispatch(clearElement); -let isElementDisplayedFn = dispatch(isElementDisplayed); -let getElementValueOfCssPropertyFn = dispatch(getElementValueOfCssProperty); -let switchToShadowRootFn = dispatch(switchToShadowRoot); -let getCookiesFn = dispatch(getCookies); -let singleTapFn = dispatch(singleTap); -let takeScreenshotFn = dispatch(takeScreenshot); +var getTitleFn = dispatch(getTitle); +var getPageSourceFn = dispatch(getPageSource); +var getActiveElementFn = dispatch(getActiveElement); +var clickElementFn = dispatch(clickElement); +var goBackFn = dispatch(goBack); +var getElementAttributeFn = dispatch(getElementAttribute); +var getElementTextFn = dispatch(getElementText); +var getElementTagNameFn = dispatch(getElementTagName); +var getElementRectFn = dispatch(getElementRect); +var isElementEnabledFn = dispatch(isElementEnabled); +var getCurrentUrlFn = dispatch(getCurrentUrl); +var findElementContentFn = dispatch(findElementContent); +var findElementsContentFn = dispatch(findElementsContent); +var isElementSelectedFn = dispatch(isElementSelected); +var clearElementFn = dispatch(clearElement); +var isElementDisplayedFn = dispatch(isElementDisplayed); +var getElementValueOfCssPropertyFn = dispatch(getElementValueOfCssProperty); +var switchToShadowRootFn = dispatch(switchToShadowRoot); +var getCookiesFn = dispatch(getCookies); +var singleTapFn = dispatch(singleTap); /** * Start all message listeners @@ -263,7 +260,7 @@ function startListeners() { addMessageListenerId("Marionette:importScript", importScript); addMessageListenerId("Marionette:getAppCacheStatus", getAppCacheStatus); addMessageListenerId("Marionette:setTestName", setTestName); - addMessageListenerId("Marionette:takeScreenshot", takeScreenshotFn); + addMessageListenerId("Marionette:takeScreenshot", takeScreenshot); addMessageListenerId("Marionette:addCookie", addCookie); addMessageListenerId("Marionette:getCookies", getCookiesFn); addMessageListenerId("Marionette:deleteAllCookies", deleteAllCookies); @@ -367,7 +364,7 @@ function deleteSession(msg) { removeMessageListenerId("Marionette:importScript", importScript); removeMessageListenerId("Marionette:getAppCacheStatus", getAppCacheStatus); removeMessageListenerId("Marionette:setTestName", setTestName); - removeMessageListenerId("Marionette:takeScreenshot", takeScreenshotFn); + removeMessageListenerId("Marionette:takeScreenshot", takeScreenshot); removeMessageListenerId("Marionette:addCookie", addCookie); removeMessageListenerId("Marionette:getCookies", getCookiesFn); removeMessageListenerId("Marionette:deleteAllCookies", deleteAllCookies); @@ -1997,35 +1994,44 @@ function importScript(msg) { * msg.json.highlights, a red box will be painted around * them to highlight their position. */ -function takeScreenshot(id, highlights, full) { +function takeScreenshot(msg) { let node = null; - if (id) { - node = elementManager.getKnownElement(id, curContainer) - } else { + if (msg.json.id) { + try { + node = elementManager.getKnownElement(msg.json.id, curContainer) + } + catch (e) { + sendResponse(e.message, e.code, e.stack, msg.json.command_id); + return; + } + } + else { node = curContainer.frame; } + let highlights = msg.json.highlights; - let document = curContainer.frame.document; - let rect, win, width, height, left, top; - + var document = curContainer.frame.document; + var rect, win, width, height, left, top; // node can be either a window or an arbitrary DOM node if (node == curContainer.frame) { // node is a window win = node; - if (full) { + if (msg.json.full) { // the full window width = document.body.scrollWidth; height = document.body.scrollHeight; top = 0; left = 0; - } else { + } + else { // only the viewport width = document.documentElement.clientWidth; height = document.documentElement.clientHeight; left = curContainer.frame.pageXOffset; top = curContainer.frame.pageYOffset; } - } else { + } + else { // node is an arbitrary DOM node win = node.ownerDocument.defaultView; rect = node.getBoundingClientRect(); @@ -2035,16 +2041,15 @@ function takeScreenshot(id, highlights, full) { left = rect.left; } - let canvas = document.createElementNS( - "http://www.w3.org/1999/xhtml", "canvas"); + var canvas = document.createElementNS("http://www.w3.org/1999/xhtml", + "canvas"); canvas.width = width; canvas.height = height; - let ctx = canvas.getContext("2d"); - - // draws the DOM contents of the window to the canvas + var ctx = canvas.getContext("2d"); + // Draws the DOM contents of the window to the canvas ctx.drawWindow(win, left, top, width, height, "rgb(255,255,255)"); - // this section is for drawing a red rectangle around each element + // This section is for drawing a red rectangle around each element // passed in via the highlights array if (highlights) { ctx.lineWidth = "2"; @@ -2052,26 +2057,25 @@ function takeScreenshot(id, highlights, full) { ctx.save(); for (var i = 0; i < highlights.length; ++i) { - let elem = elementManager.getKnownElement(highlights[i], curContainer); + var elem = elementManager.getKnownElement(highlights[i], curContainer); rect = elem.getBoundingClientRect(); - let offsetY = -top; - let offsetX = -left; + var offsetY = -top; + var offsetX = -left; - // draw the rectangle - ctx.strokeRect( - rect.left + offsetX, - rect.top + offsetY, - rect.width, - rect.height); + // Draw the rectangle + ctx.strokeRect(rect.left + offsetX, + rect.top + offsetY, + rect.width, + rect.height); } } - // return the Base64 encoded string back to the client - // so that it can save the file to disk if it is required - let dataUrl = canvas.toDataURL("image/png", ""); - let encoded = dataUrl.substring(dataUrl.indexOf(",") + 1); - return encoded; + // Return the Base64 encoded string back to the client so that it + // can save the file to disk if it is required + var dataUrl = canvas.toDataURL("image/png", ""); + var data = dataUrl.substring(dataUrl.indexOf(",") + 1); + sendResponse({value: data}, msg.json.command_id); } // Call register self when we get loaded