Index: content/browser/renderer_host/render_widget_host_view_browsertest.cc |
diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc |
index d12edb3a10e8f863ce5409140c834666bc3cf82b..533019fea1120118c30bf2b6a328b6ec64d46e87 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc |
@@ -29,7 +29,7 @@ |
#include "third_party/skia/include/core/SkCanvas.h" |
#include "ui/base/layout.h" |
#include "ui/base/ui_base_switches.h" |
-#include "ui/gfx/size_conversions.h" |
+#include "ui/gfx/geometry/size_conversions.h" |
#include "ui/gfx/switches.h" |
#include "ui/gl/gl_switches.h" |
@@ -523,15 +523,12 @@ class CompositingRenderWidgetHostViewBrowserTestTabCapture |
// Loads a page two boxes side-by-side, each half the width of |
// |html_rect_size|, and with different background colors. The test then |
// copies from |copy_rect| region of the page into a bitmap of size |
- // |output_size|, and compares that with a bitmap of size |
- // |expected_bitmap_size|. |
+ // |output_size|, and examines the resulting bitmap/VideoFrame. |
// Note that |output_size| may not have the same size as |copy_rect| (e.g. |
- // when the output is scaled). Also note that |expected_bitmap_size| may not |
- // be the same as |output_size| (e.g. when the device scale factor is not 1). |
+ // when the output is scaled). |
void PerformTestWithLeftRightRects(const gfx::Size& html_rect_size, |
const gfx::Rect& copy_rect, |
const gfx::Size& output_size, |
- const gfx::Size& expected_bitmap_size, |
bool video_frame) { |
const gfx::Size box_size(html_rect_size.width() / 2, |
html_rect_size.height()); |
@@ -592,7 +589,7 @@ class CompositingRenderWidgetHostViewBrowserTestTabCapture |
GiveItSomeTime(); |
SkBitmap expected_bitmap; |
- SetupLeftRightBitmap(expected_bitmap_size, &expected_bitmap); |
+ SetupLeftRightBitmap(output_size, &expected_bitmap); |
SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); |
base::RunLoop run_loop; |
@@ -605,9 +602,9 @@ class CompositingRenderWidgetHostViewBrowserTestTabCapture |
scoped_refptr<media::VideoFrame> video_frame = |
media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
- expected_bitmap_size, |
- gfx::Rect(expected_bitmap_size), |
- expected_bitmap_size, |
+ output_size, |
+ gfx::Rect(output_size), |
+ output_size, |
base::TimeDelta()); |
base::Callback<void(bool success)> callback = |
@@ -679,13 +676,11 @@ IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
CopyFromCompositingSurface_Origin_Unscaled) { |
gfx::Rect copy_rect(400, 300); |
gfx::Size output_size = copy_rect.size(); |
- gfx::Size expected_bitmap_size = output_size; |
gfx::Size html_rect_size(400, 300); |
bool video_frame = false; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
@@ -693,13 +688,11 @@ IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
CopyFromCompositingSurface_Origin_Scaled) { |
gfx::Rect copy_rect(400, 300); |
gfx::Size output_size(200, 100); |
- gfx::Size expected_bitmap_size = output_size; |
gfx::Size html_rect_size(400, 300); |
bool video_frame = false; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
@@ -710,13 +703,11 @@ IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(30, 30), |
gfx::Size(60, 60)); |
gfx::Size output_size = copy_rect.size(); |
- gfx::Size expected_bitmap_size = output_size; |
gfx::Size html_rect_size(400, 300); |
bool video_frame = false; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
@@ -727,13 +718,11 @@ IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(30, 30), |
gfx::Size(60, 60)); |
gfx::Size output_size(20, 10); |
- gfx::Size expected_bitmap_size = output_size; |
gfx::Size html_rect_size(400, 300); |
bool video_frame = false; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
@@ -744,13 +733,11 @@ IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(45, 30), |
gfx::Size(90, 60)); |
gfx::Size output_size = copy_rect.size(); |
- gfx::Size expected_bitmap_size = output_size; |
gfx::Size html_rect_size(400, 300); |
bool video_frame = true; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
@@ -762,101 +749,174 @@ IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
gfx::Size(90, 60)); |
// Scale to 30 x 20 (preserve aspect ratio). |
gfx::Size output_size(30, 20); |
- gfx::Size expected_bitmap_size = output_size; |
gfx::Size html_rect_size(400, 300); |
bool video_frame = true; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
-class CompositingRenderWidgetHostViewTabCaptureHighDPI |
+class CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI |
: public CompositingRenderWidgetHostViewBrowserTestTabCapture { |
public: |
- CompositingRenderWidgetHostViewTabCaptureHighDPI() : kScale(2.f) {} |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI() {} |
- virtual void SetUpOnMainThread() OVERRIDE { |
- base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
+ protected: |
+ virtual void SetUpCommandLine(base::CommandLine* cmd) OVERRIDE { |
+ CompositingRenderWidgetHostViewBrowserTestTabCapture::SetUpCommandLine(cmd); |
cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, |
base::StringPrintf("%f", scale())); |
-#if defined(OS_WIN) |
- gfx::ForceHighDPISupportForTesting(scale()); |
- gfx::EnableHighDPISupport(); |
-#endif |
} |
- float scale() const { return kScale; } |
- |
- private: |
virtual bool ShouldContinueAfterTestURLLoad() OVERRIDE { |
// Short-circuit a pass for platforms where setting up high-DPI fails. |
- if (ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor( |
- GetScaleFactorForView(GetRenderWidgetHostView()))) != scale()) { |
- LOG(WARNING) << "Blindly passing this test: failed to set up " |
- "scale factor: " << scale(); |
+ const float actual_scale_factor = |
+ GetScaleFactorForView(GetRenderWidgetHostView()); |
+ if (actual_scale_factor != scale()) { |
+ LOG(WARNING) << "Blindly passing this test; unable to force device scale " |
+ << "factor: seems to be " << actual_scale_factor |
+ << " but expected " << scale(); |
return false; |
} |
+ VLOG(1) << ("Successfully forced device scale factor. Moving forward with " |
+ "this test! :-)"); |
return true; |
} |
- const float kScale; |
+ static float scale() { return 2.0f; } |
- DISALLOW_COPY_AND_ASSIGN(CompositingRenderWidgetHostViewTabCaptureHighDPI); |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI); |
}; |
-IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewTabCaptureHighDPI, |
- CopyFromCompositingSurface) { |
+// ImageSkia (related to ResourceBundle) implementation crashes the process on |
+// Windows when this content_browsertest forces a device scale factor. |
+// http://crbug.com/399349 |
+#if defined(OS_WIN) |
+#define MAYBE_CopyToBitmap_EntireRegion DISABLED_CopyToBitmap_EntireRegion |
+#define MAYBE_CopyToBitmap_CenterRegion DISABLED_CopyToBitmap_CenterRegion |
+#define MAYBE_CopyToBitmap_ScaledResult DISABLED_CopyToBitmap_ScaledResult |
+#define MAYBE_CopyToVideoFrame_EntireRegion \ |
+ DISABLED_CopyToVideoFrame_EntireRegion |
+#define MAYBE_CopyToVideoFrame_CenterRegion \ |
+ DISABLED_CopyToVideoFrame_CenterRegion |
+#define MAYBE_CopyToVideoFrame_ScaledResult \ |
+ DISABLED_CopyToVideoFrame_ScaledResult |
+#else |
+#define MAYBE_CopyToBitmap_EntireRegion CopyToBitmap_EntireRegion |
+#define MAYBE_CopyToBitmap_CenterRegion CopyToBitmap_CenterRegion |
+#define MAYBE_CopyToBitmap_ScaledResult CopyToBitmap_ScaledResult |
+#define MAYBE_CopyToVideoFrame_EntireRegion CopyToVideoFrame_EntireRegion |
+#define MAYBE_CopyToVideoFrame_CenterRegion CopyToVideoFrame_CenterRegion |
+#define MAYBE_CopyToVideoFrame_ScaledResult CopyToVideoFrame_ScaledResult |
+#endif |
+ |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToBitmap_EntireRegion) { |
+ gfx::Size html_rect_size(200, 150); |
gfx::Rect copy_rect(200, 150); |
- gfx::Size output_size = copy_rect.size(); |
- gfx::Size expected_bitmap_size = |
- gfx::ToFlooredSize(gfx::ScaleSize(output_size, scale(), scale())); |
+ // Scale the output size so that, internally, scaling is not occurring. |
+ gfx::Size output_size = |
+ gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale())); |
+ bool video_frame = false; |
+ PerformTestWithLeftRightRects(html_rect_size, |
+ copy_rect, |
+ output_size, |
+ video_frame); |
+} |
+ |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToBitmap_CenterRegion) { |
gfx::Size html_rect_size(200, 150); |
+ // Grab 90x60 pixels from the center of the tab contents. |
+ gfx::Rect copy_rect = |
+ gfx::Rect(gfx::Rect(html_rect_size).CenterPoint() - gfx::Vector2d(45, 30), |
+ gfx::Size(90, 60)); |
+ // Scale the output size so that, internally, scaling is not occurring. |
+ gfx::Size output_size = |
+ gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale())); |
+ bool video_frame = false; |
+ PerformTestWithLeftRightRects(html_rect_size, |
+ copy_rect, |
+ output_size, |
+ video_frame); |
+} |
+ |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToBitmap_ScaledResult) { |
+ gfx::Size html_rect_size(200, 100); |
+ gfx::Rect copy_rect(200, 100); |
+ // Output is being down-scaled since output_size is in phyiscal pixels. |
+ gfx::Size output_size(200, 100); |
bool video_frame = false; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
-IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewTabCaptureHighDPI, |
- CopyFromCompositingSurfaceVideoFrame) { |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToVideoFrame_EntireRegion) { |
+ gfx::Size html_rect_size(200, 150); |
+ gfx::Rect copy_rect(200, 150); |
+ // Scale the output size so that, internally, scaling is not occurring. |
+ gfx::Size output_size = |
+ gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale())); |
+ bool video_frame = true; |
+ PerformTestWithLeftRightRects(html_rect_size, |
+ copy_rect, |
+ output_size, |
+ video_frame); |
+} |
+ |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToVideoFrame_CenterRegion) { |
gfx::Size html_rect_size(200, 150); |
// Grab 90x60 pixels from the center of the tab contents. |
gfx::Rect copy_rect = |
gfx::Rect(gfx::Rect(html_rect_size).CenterPoint() - gfx::Vector2d(45, 30), |
gfx::Size(90, 60)); |
- gfx::Size output_size = copy_rect.size(); |
- gfx::Size expected_bitmap_size = |
- gfx::ToFlooredSize(gfx::ScaleSize(output_size, scale(), scale())); |
+ // Scale the output size so that, internally, scaling is not occurring. |
+ gfx::Size output_size = |
+ gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale())); |
bool video_frame = true; |
PerformTestWithLeftRightRects(html_rect_size, |
copy_rect, |
output_size, |
- expected_bitmap_size, |
video_frame); |
} |
-#if !defined(USE_AURA) && !defined(OS_MACOSX) |
-// TODO(danakj): Remove this case when GTK linux is no more and move the |
-// values inline to testing::Values() below. |
-static const CompositingMode kAllCompositingModes[] = {GL_COMPOSITING}; |
-#else |
-static const CompositingMode kAllCompositingModes[] = {GL_COMPOSITING, |
- SOFTWARE_COMPOSITING}; |
-#endif |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToVideoFrame_ScaledResult) { |
+ gfx::Size html_rect_size(200, 100); |
+ gfx::Rect copy_rect(200, 100); |
+ // Output is being down-scaled since output_size is in phyiscal pixels. |
+ gfx::Size output_size(200, 100); |
+ bool video_frame = true; |
+ PerformTestWithLeftRightRects(html_rect_size, |
+ copy_rect, |
+ output_size, |
+ video_frame); |
+} |
INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing, |
CompositingRenderWidgetHostViewBrowserTest, |
- testing::ValuesIn(kAllCompositingModes)); |
+ testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing, |
CompositingRenderWidgetHostViewBrowserTestTabCapture, |
- testing::ValuesIn(kAllCompositingModes)); |
-INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing, |
- CompositingRenderWidgetHostViewTabCaptureHighDPI, |
- testing::ValuesIn(kAllCompositingModes)); |
+ testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
+INSTANTIATE_TEST_CASE_P( |
+ GLAndSoftwareCompositing, |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
#endif // !defined(OS_ANDROID) && !defined(OS_IOS) |