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..2d5c2179d54b0faafb6568346fb98fab9856e38a 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" |
@@ -435,6 +435,11 @@ class CompositingRenderWidgetHostViewBrowserTestTabCapture |
SkAutoLockPixels bitmap_lock(bitmap); |
int fails = 0; |
for (int i = 0; i < bitmap.width() && fails < 10; ++i) { |
+ // Exclude the middle 3 columns of pixels from testing since scaling could |
+ // cause these pixels to be a mix of the two colors. |
+ if (i >= (bitmap.width() / 2 - 1) && i <= (bitmap.width() / 2 + 1)) |
+ continue; |
+ |
for (int j = 0; j < bitmap.height() && fails < 10; ++j) { |
if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) |
continue; |
@@ -523,15 +528,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()); |
@@ -565,8 +567,6 @@ class CompositingRenderWidgetHostViewBrowserTestTabCapture |
box_size.height())); |
SET_UP_SURFACE_OR_PASS_TEST("\"DONE\""); |
- if (!ShouldContinueAfterTestURLLoad()) |
- return; |
RenderWidgetHostViewBase* rwhvp = GetRenderWidgetHostView(); |
if (video_frame && !rwhvp->CanCopyToVideoFrame()) { |
@@ -592,7 +592,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 +605,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 = |
@@ -662,11 +662,6 @@ class CompositingRenderWidgetHostViewBrowserTestTabCapture |
} |
} |
- protected: |
- virtual bool ShouldContinueAfterTestURLLoad() { |
- return true; |
- } |
- |
private: |
bool expected_copy_from_compositing_surface_result_; |
SkBitmap expected_copy_from_compositing_surface_bitmap_; |
@@ -679,13 +674,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 +686,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 +701,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 +716,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 +731,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 +747,162 @@ 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; } |
+ static float scale() { return 2.0f; } |
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(); |
- return false; |
- } |
- return true; |
- } |
- |
- const float kScale; |
- |
- DISALLOW_COPY_AND_ASSIGN(CompositingRenderWidgetHostViewTabCaptureHighDPI); |
+ 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_CopyToVideoFr_EntireRegion DISABLED_CopyToVideoFr_EntireRegion |
+#define MAYBE_CopyToVideoFr_CenterRegion DISABLED_CopyToVideoFr_CenterRegion |
+#define MAYBE_CopyToVideoFr_ScaledResult DISABLED_CopyToVideoFr_ScaledResult |
+#else |
+#define MAYBE_CopyToBitmap_EntireRegion CopyToBitmap_EntireRegion |
+#define MAYBE_CopyToBitmap_CenterRegion CopyToBitmap_CenterRegion |
+#define MAYBE_CopyToBitmap_ScaledResult CopyToBitmap_ScaledResult |
+#define MAYBE_CopyToVideoFr_EntireRegion CopyToVideoFr_EntireRegion |
+#define MAYBE_CopyToVideoFr_CenterRegion CopyToVideoFr_CenterRegion |
+#define MAYBE_CopyToVideoFr_ScaledResult CopyToVideoFr_ScaledResult |
+#endif |
+ |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToBitmap_EntireRegion) { |
+ ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView())); |
+ 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) { |
+ ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView())); |
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, |
- expected_bitmap_size, |
video_frame); |
} |
-IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewTabCaptureHighDPI, |
- CopyFromCompositingSurfaceVideoFrame) { |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToBitmap_ScaledResult) { |
+ ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView())); |
+ 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: |
danakj
2014/08/13 18:39:31
nit: s/:/./
miu
2014/08/13 18:48:27
Done.
|
+ gfx::Size output_size(200, 100); |
+ bool video_frame = false; |
+ PerformTestWithLeftRightRects(html_rect_size, |
+ copy_rect, |
+ output_size, |
+ video_frame); |
+} |
+ |
+IN_PROC_BROWSER_TEST_P( |
+ CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
+ MAYBE_CopyToVideoFr_EntireRegion) { |
danakj
2014/08/13 18:39:31
CopyToVideoFrame please, don't drop half the word
miu
2014/08/13 18:48:27
Done. I had truncated it because of the 80 char l
|
+ ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView())); |
+ 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_CopyToVideoFr_CenterRegion) { |
+ ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView())); |
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_CopyToVideoFr_ScaledResult) { |
+ ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView())); |
+ 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) |