Commit a1d50991 authored by Tatiana Buldina's avatar Tatiana Buldina Committed by Commit Bot

[ChromeDriver] Fix testTakeElementScreenshot

Fix testTakeElementScreenshot() on Windows
by setting scale to 1/devicePixelRatio

Bug: chromedriver:2667
Change-Id: Ie4b804c1d08bf8ab34e690ebcac66801a3cfa0f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716147Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Tatiana Buldina <buldina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680213}
parent 76b9ba0e
...@@ -843,15 +843,18 @@ Status ExecuteElementScreenshot(Session* session, ...@@ -843,15 +843,18 @@ Status ExecuteElementScreenshot(Session* session,
"({x: document.documentElement.scrollLeft || document.body.scrollLeft," "({x: document.documentElement.scrollLeft || document.body.scrollLeft,"
" y: document.documentElement.scrollTop || document.body.scrollTop," " y: document.documentElement.scrollTop || document.body.scrollTop,"
" height: document.documentElement.clientHeight," " height: document.documentElement.clientHeight,"
" width: document.documentElement.clientWidth})", " width: document.documentElement.clientWidth,"
" device_pixel_ratio: window.devicePixelRatio})",
&browser_info); &browser_info);
if (status.IsError()) if (status.IsError())
return status; return status;
int scroll_left = browser_info->FindKey("x")->GetInt(); double scroll_left = browser_info->FindKey("x")->GetDouble();
int scroll_top = browser_info->FindKey("y")->GetInt(); double scroll_top = browser_info->FindKey("y")->GetDouble();
double viewport_height = browser_info->FindKey("height")->GetDouble(); double viewport_height = browser_info->FindKey("height")->GetDouble();
double viewport_width = browser_info->FindKey("width")->GetDouble(); double viewport_width = browser_info->FindKey("width")->GetDouble();
double device_pixel_ratio =
browser_info->FindKey("device_pixel_ratio")->GetDouble();
std::unique_ptr<base::DictionaryValue> clip_dict = std::unique_ptr<base::DictionaryValue> clip_dict =
base::DictionaryValue::From(std::move(clip)); base::DictionaryValue::From(std::move(clip));
...@@ -861,14 +864,14 @@ Status ExecuteElementScreenshot(Session* session, ...@@ -861,14 +864,14 @@ Status ExecuteElementScreenshot(Session* session,
// element, but its x and y are relative to containing frame. We replace them // element, but its x and y are relative to containing frame. We replace them
// with the x and y relative to top-level document origin, as expected by // with the x and y relative to top-level document origin, as expected by
// CaptureScreenshot. // CaptureScreenshot.
clip_dict->SetInteger("x", location.x + scroll_left); clip_dict->SetDouble("x", location.x + scroll_left);
clip_dict->SetInteger("y", location.y + scroll_top); clip_dict->SetDouble("y", location.y + scroll_top);
clip_dict->SetDouble("scale", 1.0); clip_dict->SetDouble("scale", 1 / device_pixel_ratio);
// Crop screenshot by viewport if element is larger than viewport // Crop screenshot by viewport if element is larger than viewport
clip_dict->SetInteger( clip_dict->SetDouble(
"height", "height",
std::min(viewport_height, clip_dict->FindKey("height")->GetDouble())); std::min(viewport_height, clip_dict->FindKey("height")->GetDouble()));
clip_dict->SetInteger( clip_dict->SetDouble(
"width", "width",
std::min(viewport_width, clip_dict->FindKey("width")->GetDouble())); std::min(viewport_width, clip_dict->FindKey("width")->GetDouble()));
base::DictionaryValue screenshot_params; base::DictionaryValue screenshot_params;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment