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 abb97dd466354139f8803968d326d77b39bb7cd8..9a28b206efa583c1a7091035df1450d6376ae3ce 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc |
@@ -198,14 +198,18 @@ class CompositingRenderWidgetHostViewBrowserTest |
RenderWidgetHostViewBrowserTest::SetUpCommandLine(command_line); |
} |
+ virtual GURL TestUrl() { |
+ return net::FilePathToFileURL( |
+ test_dir().AppendASCII("rwhv_compositing_animation.html")); |
+ } |
+ |
virtual bool SetUpSourceSurface() OVERRIDE { |
if (!IsForceCompositingModeEnabled()) |
return false; // See comment in SetUpCommandLine(). |
#if defined(OS_MACOSX) |
CHECK(IOSurfaceSupport::Initialize()); |
#endif |
- NavigateToURL(shell(), net::FilePathToFileURL( |
- test_dir().AppendASCII("rwhv_compositing_animation.html"))); |
+ NavigateToURL(shell(), TestUrl()); |
#if !defined(USE_AURA) |
if (!GetRenderWidgetHost()->is_accelerated_compositing_active()) |
return false; // Renderer did not turn on accelerated compositing. |
@@ -418,6 +422,286 @@ IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, CopyTwice) { |
EXPECT_EQ(2, frames_captured()); |
} |
+class CompositingRenderWidgetHostViewBrowserTestTabCapture |
+ : public CompositingRenderWidgetHostViewBrowserTest { |
+ public: |
+ CompositingRenderWidgetHostViewBrowserTestTabCapture() |
+ : expected_copy_from_compositing_surface_result_(false), |
+ allowable_error_(0), |
+ test_url_("data:text/html,<!doctype html>") {} |
+ |
+ void CopyFromCompositingSurfaceCallback(bool result, const SkBitmap& bitmap) { |
+ EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); |
+ |
+ const SkBitmap& expected_bitmap = |
+ expected_copy_from_compositing_surface_bitmap_; |
+ EXPECT_EQ(expected_bitmap.width(), bitmap.width()); |
+ EXPECT_EQ(expected_bitmap.height(), bitmap.height()); |
+ EXPECT_EQ(expected_bitmap.config(), bitmap.config()); |
+ SkAutoLockPixels expected_bitmap_lock(expected_bitmap); |
+ SkAutoLockPixels bitmap_lock(bitmap); |
+ int fails = 0; |
+ for (int i = 0; i < bitmap.width() && fails < 10; ++i) { |
+ for (int j = 0; j < bitmap.height() && fails < 10; ++j) { |
+ SkColor expected_color = expected_bitmap.getColor(i, j); |
+ SkColor color = bitmap.getColor(i, j); |
+ EXPECT_NEAR(expected_color, color, allowable_error_) |
+ << "expected_color: " << std::hex << expected_color |
+ << " color: " << color |
+ << " Failed at " << std::dec << i << ", " << j; |
+ if (static_cast<int>(std::abs(expected_color - color)) > |
+ allowable_error_) |
+ ++fails; |
+ } |
+ } |
+ EXPECT_LT(fails, 10); |
+ |
+ base::MessageLoop::current()->Quit(); |
piman
2013/06/28 03:23:13
You can pass in the RunLoop's QuitClosure, so that
danakj
2013/06/28 16:50:12
Ah! Ok, I was going to use the QuitClosure, but th
danakj
2013/06/28 17:58:39
Done.
|
+ } |
+ |
+ void SetExpectedCopyFromCompositingSurfaceResult(bool result, |
+ const SkBitmap& bitmap) { |
+ expected_copy_from_compositing_surface_result_ = result; |
+ expected_copy_from_compositing_surface_bitmap_ = bitmap; |
+ } |
+ |
+ void SetAllowableError(int amount) { allowable_error_ = amount; } |
+ |
+ virtual GURL TestUrl() OVERRIDE { |
+ return GURL(test_url_); |
+ } |
+ |
+ virtual void SetUp() OVERRIDE { |
+ ui::DisableTestCompositor(); |
+ CompositingRenderWidgetHostViewBrowserTest::SetUp(); |
+ } |
+ |
+ void SetTestUrl(std::string url) { test_url_ = url; } |
+ |
+ private: |
+ bool expected_copy_from_compositing_surface_result_; |
+ SkBitmap expected_copy_from_compositing_surface_bitmap_; |
+ int allowable_error_; |
+ std::string test_url_; |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
+ CopyFromCompositingSurface_WholeSurface_Unscaled) { |
+ SetTestUrl("data:text/html,<!doctype html>" |
+ "<div class='left'></div>" |
+ "<style>" |
+ "body { background: #ff0; padding: 0; margin: 0; }" |
+ ".left { background: #0ff;" |
+ " width: 50%;" |
+ " height: 506px;" |
+ "}" |
+ "</style>"); |
+ |
+ SET_UP_SURFACE_OR_PASS_TEST(); |
+ |
+ RenderViewHost* const rwh = |
+ shell()->web_contents()->GetRenderViewHost(); |
+ RenderWidgetHostViewPort* rwhvp = |
+ static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); |
+ |
+ gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); |
+ EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); |
piman
2013/06/28 03:23:13
Is this size expected to be stable across platform
danakj
2013/06/28 16:50:12
Ya I wasn't sure, so I put this to see and run the
danakj
2013/06/28 17:58:39
Using just the top left 400x300 now. We'll see wha
|
+ |
+ gfx::Size out_size = bounds.size(); |
+ |
+ SkBitmap expected_bitmap; |
+ expected_bitmap.setConfig( |
+ SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); |
+ expected_bitmap.allocPixels(); |
+ // Left half is #0ff. |
+ expected_bitmap.eraseARGB(255, 0, 255, 255); |
+ // Right half is #0ff. |
+ { |
+ SkAutoLockPixels lock(expected_bitmap); |
+ for (int i = 0; i < out_size.width() / 2; ++i) { |
+ for (int j = 0; j < out_size.height(); ++j) { |
+ *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = |
+ SkColorSetARGB(255, 255, 255, 0);; |
+ } |
+ } |
+ } |
+ SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); |
+ |
+ base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( |
+ &CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
+ CopyFromCompositingSurfaceCallback, |
+ base::Unretained(this)); |
+ rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); |
+ |
+ base::RunLoop run_loop; |
+ run_loop.Run(); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
+ CopyFromCompositingSurface_WholeSurface_Scaled) { |
+ SetTestUrl("data:text/html,<!doctype html>" |
+ "<div class='left'></div>" |
+ "<style>" |
+ "body { background: #ff0; padding: 0; margin: 0; }" |
+ ".left { background: #0ff;" |
+ " width: 50%;" |
+ " height: 506px;" |
+ "}" |
+ "</style>"); |
+ |
+ SET_UP_SURFACE_OR_PASS_TEST(); |
+ |
+ RenderViewHost* const rwh = |
+ shell()->web_contents()->GetRenderViewHost(); |
+ RenderWidgetHostViewPort* rwhvp = |
+ static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); |
+ |
+ gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); |
+ EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); |
+ |
+ // Scale the output to 400x300. |
+ gfx::Size out_size(400, 300); |
+ |
+ SkBitmap expected_bitmap; |
+ expected_bitmap.setConfig( |
+ SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); |
+ expected_bitmap.allocPixels(); |
+ // Left half is #0ff. |
+ expected_bitmap.eraseARGB(255, 0, 255, 255); |
+ // Right half is #0ff. |
+ { |
+ SkAutoLockPixels lock(expected_bitmap); |
+ for (int i = 0; i < out_size.width() / 2; ++i) { |
+ for (int j = 0; j < out_size.height(); ++j) { |
+ *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = |
+ SkColorSetARGB(255, 255, 255, 0);; |
+ } |
+ } |
+ } |
+ SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); |
+ |
+ base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( |
+ &CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
+ CopyFromCompositingSurfaceCallback, |
+ base::Unretained(this)); |
+ rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); |
+ |
+ base::RunLoop run_loop; |
+ run_loop.Run(); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
+ CopyFromCompositingSurface_CroppedSurface_Unscaled) { |
+ SetTestUrl("data:text/html,<!doctype html>" |
+ "<div class='left'></div>" |
+ "<style>" |
+ "body { background: #ff0; padding: 0; margin: 0; }" |
+ ".left { background: #0ff;" |
+ " width: 50%;" |
+ " height: 506px;" |
+ "}" |
+ "</style>"); |
+ |
+ SET_UP_SURFACE_OR_PASS_TEST(); |
+ |
+ RenderViewHost* const rwh = |
+ shell()->web_contents()->GetRenderViewHost(); |
+ RenderWidgetHostViewPort* rwhvp = |
+ static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); |
+ |
+ gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); |
+ EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); |
+ |
+ // Grab 60x60 pixels from the center of the tab contents. |
+ bounds = gfx::Rect(bounds.CenterPoint() - gfx::Vector2d(30, 30), |
+ gfx::Size(60, 60)); |
+ gfx::Size out_size = bounds.size(); |
+ |
+ SkBitmap expected_bitmap; |
+ expected_bitmap.setConfig( |
+ SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); |
+ expected_bitmap.allocPixels(); |
+ // Left half is #0ff. |
+ expected_bitmap.eraseARGB(255, 0, 255, 255); |
+ // Right half is #0ff. |
+ { |
+ SkAutoLockPixels lock(expected_bitmap); |
+ for (int i = 0; i < out_size.width() / 2; ++i) { |
+ for (int j = 0; j < out_size.height(); ++j) { |
+ *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = |
+ SkColorSetARGB(255, 255, 255, 0);; |
+ } |
+ } |
+ } |
+ SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); |
+ |
+ base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( |
+ &CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
+ CopyFromCompositingSurfaceCallback, |
+ base::Unretained(this)); |
+ rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); |
+ |
+ base::RunLoop run_loop; |
+ run_loop.Run(); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTestTabCapture, |
+ CopyFromCompositingSurface_CroppedSurface_Scaled) { |
+ SetTestUrl("data:text/html,<!doctype html>" |
+ "<div class='left'></div>" |
+ "<style>" |
+ "body { background: #ff0; padding: 0; margin: 0; }" |
+ ".left { background: #0ff;" |
+ " width: 50%;" |
+ " height: 506px;" |
+ "}" |
+ "</style>"); |
+ |
+ SET_UP_SURFACE_OR_PASS_TEST(); |
+ |
+ RenderViewHost* const rwh = |
+ shell()->web_contents()->GetRenderViewHost(); |
+ RenderWidgetHostViewPort* rwhvp = |
+ static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); |
+ |
+ gfx::Rect bounds = gfx::Rect(rwhvp->GetViewBounds().size()); |
+ EXPECT_EQ(gfx::Rect(766, 506).ToString(), bounds.ToString()); |
+ |
+ // Grab 60x60 pixels from the center of the tab contents. |
+ bounds = gfx::Rect(bounds.CenterPoint() - gfx::Vector2d(30, 30), |
+ gfx::Size(60, 60)); |
+ |
+ // Scale to 20 x 10. |
+ gfx::Size out_size(20, 10); |
+ |
+ SkBitmap expected_bitmap; |
+ expected_bitmap.setConfig( |
+ SkBitmap::kARGB_8888_Config, out_size.width(), out_size.height()); |
+ expected_bitmap.allocPixels(); |
+ // Left half is #0ff. |
+ expected_bitmap.eraseARGB(255, 0, 255, 255); |
+ // Right half is #0ff. |
+ { |
+ SkAutoLockPixels lock(expected_bitmap); |
+ for (int i = 0; i < out_size.width() / 2; ++i) { |
+ for (int j = 0; j < out_size.height(); ++j) { |
+ *expected_bitmap.getAddr32(out_size.width() / 2 + i, j) = |
+ SkColorSetARGB(255, 255, 255, 0);; |
+ } |
+ } |
+ } |
+ SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); |
+ |
+ base::Callback<void(bool, const SkBitmap&)> callback = base::Bind( |
+ &CompositingRenderWidgetHostViewBrowserTestTabCapture:: |
+ CopyFromCompositingSurfaceCallback, |
+ base::Unretained(this)); |
+ rwhvp->CopyFromCompositingSurface(bounds, out_size, callback); |
+ |
+ base::RunLoop run_loop; |
+ run_loop.Run(); |
+} |
+ |
#endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
} // namespace |