Index: content/public/test/render_widget_test.cc |
diff --git a/content/public/test/render_widget_test.cc b/content/public/test/render_widget_test.cc |
index ce3bb806144257f9c8fac6f5437d1196884d8e2d..211a24fcfb12b87ab55258226a0ad1638856c042 100644 |
--- a/content/public/test/render_widget_test.cc |
+++ b/content/public/test/render_widget_test.cc |
@@ -32,122 +32,6 @@ const uint32 RenderWidgetTest::kRedARGB = 0xFFFF0000; |
RenderWidgetTest::RenderWidgetTest() {} |
-void RenderWidgetTest::ResizeAndPaint(const gfx::Size& page_size, |
- const gfx::Size& desired_size, |
- SkBitmap* snapshot) { |
- ASSERT_TRUE(snapshot); |
- static int g_sequence_num = 0; |
- // Use a new sequence number for each DIB. |
- scoped_ptr<TransportDIB> pixels( |
- TransportDIB::Create( |
- page_size.width() * page_size.height() * kNumBytesPerPixel, |
- ++g_sequence_num)); |
- |
- // Go ahead and map the DIB into memory, so that we can use it below to fill |
- // tmp_bitmap. Note that we need to do this before calling OnPaintAtSize, or |
- // the last reference to the shared memory will be closed and the handle will |
- // no longer be valid. |
- scoped_ptr<TransportDIB> mapped_pixels(TransportDIB::Map(pixels->handle())); |
- |
- RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); |
- impl->OnPaintAtSize(pixels->handle(), g_sequence_num, page_size, |
- desired_size); |
- ProcessPendingMessages(); |
- const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
- ViewHostMsg_PaintAtSize_ACK::ID); |
- ASSERT_NE(static_cast<IPC::Message*>(NULL), msg); |
- ViewHostMsg_PaintAtSize_ACK::Param params; |
- ViewHostMsg_PaintAtSize_ACK::Read(msg, ¶ms); |
- render_thread_->sink().ClearMessages(); |
- EXPECT_EQ(g_sequence_num, params.a); |
- gfx::Size size = params.b; |
- EXPECT_EQ(desired_size, size); |
- |
- SkBitmap tmp_bitmap; |
- tmp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
- size.width(), size.height()); |
- tmp_bitmap.setPixels(mapped_pixels->memory()); |
- // Copy the pixels from the TransportDIB object to the given snapshot. |
- ASSERT_TRUE(tmp_bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)); |
-} |
- |
-void RenderWidgetTest::TestResizeAndPaint() { |
- // Hello World message is only visible if the view size is at least |
- // kTextPositionX x kTextPositionY |
- LoadHTML(base::StringPrintf( |
- "<html><body><div style='position: absolute; top: %d; left: " |
- "%d; background-color: red;'>Hello World</div></body></html>", |
- kTextPositionY, kTextPositionX).c_str()); |
- blink::WebSize old_size = view_->GetWebView()->size(); |
- |
- SkBitmap bitmap; |
- // If we re-size the view to something smaller than where the 'Hello World' |
- // text is displayed we won't see any text in the snapshot. Hence, |
- // the snapshot should not contain any red. |
- gfx::Size size(kSmallWidth, kSmallHeight); |
- ResizeAndPaint(size, size, &bitmap); |
- // Make sure that the view has been re-sized to its old size. |
- EXPECT_TRUE(old_size == view_->GetWebView()->size()); |
- EXPECT_EQ(kSmallWidth, bitmap.width()); |
- EXPECT_EQ(kSmallHeight, bitmap.height()); |
- EXPECT_FALSE(ImageContainsColor(bitmap, kRedARGB)); |
- |
- // Since we ask for the view to be re-sized to something larger than where the |
- // 'Hello World' text is written the text should be visible in the snapshot. |
- // Hence, the snapshot should contain some red. |
- size.SetSize(kLargeWidth, kLargeHeight); |
- ResizeAndPaint(size, size, &bitmap); |
- EXPECT_TRUE(old_size == view_->GetWebView()->size()); |
- EXPECT_EQ(kLargeWidth, bitmap.width()); |
- EXPECT_EQ(kLargeHeight, bitmap.height()); |
- EXPECT_TRUE(ImageContainsColor(bitmap, kRedARGB)); |
- |
- // Even if the desired size is smaller than where the text is located we |
- // should still see the 'Hello World' message since the view size is |
- // still large enough. |
- ResizeAndPaint(size, gfx::Size(kSmallWidth, kSmallHeight), &bitmap); |
- EXPECT_TRUE(old_size == view_->GetWebView()->size()); |
- EXPECT_EQ(kSmallWidth, bitmap.width()); |
- EXPECT_EQ(kSmallHeight, bitmap.height()); |
- EXPECT_TRUE(ImageContainsColor(bitmap, kRedARGB)); |
-} |
- |
-bool RenderWidgetTest::ImageContainsColor(const SkBitmap& bitmap, |
- uint32 argb_color) { |
- SkAutoLockPixels lock(bitmap); |
- bool ready = bitmap.readyToDraw(); |
- EXPECT_TRUE(ready); |
- if (!ready) { |
- return false; |
- } |
- for (int x = 0; x < bitmap.width(); ++x) { |
- for (int y = 0; y < bitmap.height(); ++y) { |
- if (argb_color == *bitmap.getAddr32(x, y)) { |
- return true; |
- } |
- } |
- } |
- return false; |
-} |
- |
-void RenderWidgetTest::OutputBitmapToFile(const SkBitmap& bitmap, |
- const base::FilePath& file_path) { |
- scoped_refptr<base::RefCountedBytes> bitmap_data(new base::RefCountedBytes()); |
- SkAutoLockPixels lock(bitmap); |
- ASSERT_TRUE(gfx::JPEGCodec::Encode( |
- reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
- gfx::JPEGCodec::FORMAT_BGRA, |
- bitmap.width(), |
- bitmap.height(), |
- static_cast<int>(bitmap.rowBytes()), |
- 90 /* quality */, |
- &bitmap_data->data())); |
- ASSERT_LT(0, file_util::WriteFile( |
- file_path, |
- reinterpret_cast<const char*>(bitmap_data->front()), |
- bitmap_data->size())); |
-} |
- |
void RenderWidgetTest::TestOnResize() { |
RenderWidget* widget = static_cast<RenderViewImpl*>(view_); |