Chromium Code Reviews| Index: content/shell/layout_test_controller_host.cc |
| diff --git a/content/shell/layout_test_controller_host.cc b/content/shell/layout_test_controller_host.cc |
| index 94b534cdaca0ee7a22cc96fc3bf78b3d8aefe449..14ddb48faebe6c1d7d19fdbfff1605003c2d3c92 100644 |
| --- a/content/shell/layout_test_controller_host.cc |
| +++ b/content/shell/layout_test_controller_host.cc |
| @@ -6,14 +6,17 @@ |
| #include <iostream> |
| +#include "base/md5.h" |
| #include "base/message_loop.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/shell/shell_messages.h" |
| +#include "webkit/support/webkit_support_gfx.h" |
| namespace content { |
| std::map<RenderViewHost*, LayoutTestControllerHost*> |
| LayoutTestControllerHost::controllers_; |
| +std::string LayoutTestControllerHost::expected_pixel_hash_; |
| // static |
| LayoutTestControllerHost* LayoutTestControllerHost::FromRenderViewHost( |
| @@ -25,6 +28,12 @@ LayoutTestControllerHost* LayoutTestControllerHost::FromRenderViewHost( |
| return it->second; |
| } |
| +// static |
| +void LayoutTestControllerHost::Init(const std::string& expected_pixel_hash) { |
| + // TODO(jochen): We should only dump the results for the "main window". |
| + expected_pixel_hash_ = expected_pixel_hash; |
| +} |
| + |
| LayoutTestControllerHost::LayoutTestControllerHost( |
| RenderViewHost* render_view_host) |
| : RenderViewHostObserver(render_view_host), |
| @@ -46,6 +55,10 @@ void LayoutTestControllerHost::CaptureDump() { |
| dump_as_text_, |
| is_printing_, |
| dump_child_frames_)); |
| + if (!dump_as_text_) { |
| + render_view_host()->Send( |
| + new ShellViewMsg_CaptureImageDump(render_view_host()->GetRoutingID())); |
| + } |
| } |
| bool LayoutTestControllerHost::OnMessageReceived( |
| @@ -54,6 +67,7 @@ bool LayoutTestControllerHost::OnMessageReceived( |
| IPC_BEGIN_MESSAGE_MAP(LayoutTestControllerHost, message) |
| IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad) |
| IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) |
| + IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump) |
| IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotifyDone, OnNotifyDone) |
| IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpAsText, OnDumpAsText) |
| IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpChildFramesAsText, |
| @@ -81,7 +95,55 @@ void LayoutTestControllerHost::OnTextDump(const std::string& dump) { |
| std::cout << "#EOF\n"; |
| std::cerr << "#EOF\n"; |
| + if (dump_as_text_) |
| + MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| +} |
| + |
| +void LayoutTestControllerHost::OnImageDump(const SkBitmap& image) { |
|
jochen (gone - plz use gerrit)
2012/06/26 13:40:32
compare to TestShell::dumpImage
|
| +#if !defined(OS_ANDROID) |
| + // DumpRenderTree is not currently supported for Android. Also, on Android |
| + // the required webkit_support methods are not defined, so this method just |
| + // doesn't compile. |
| + |
| + SkAutoLockPixels image_lock(image); |
| + base::MD5Digest digest; |
| + base::MD5Sum(reinterpret_cast<void*>(image.getPixels()), |
|
jam
2012/06/26 15:03:10
nit: every pointer is a void*, so shouldn't need a
|
| + image.getSize(), |
| + &digest); |
| + std::string actual_pixel_hash = base::MD5DigestToBase16(digest); |
| + |
| + std::cout << "\nActualHash: " << actual_pixel_hash << "\n"; |
| + if (!expected_pixel_hash_.empty()) |
| + std::cout << "\nExpectedHash: " << expected_pixel_hash_ << "\n"; |
| + |
| + // Only encode and dump the png if the hashes don't match. Encoding the |
| + // image is really expensive. |
| + if (actual_pixel_hash != expected_pixel_hash_) { |
| + std::vector<unsigned char> png; |
| + |
| + // Only the expected PNGs for Mac have a valid alpha channel. |
| +#if defined(OS_MACOSX) |
| + bool discard_transparency = false; |
| +#else |
| + bool discard_transparency = true; |
| +#endif |
| + |
| + webkit_support::EncodeBGRAPNGWithChecksum( |
| + reinterpret_cast<const unsigned char*>(image.getPixels()), |
| + image.width(), |
| + image.height(), |
| + static_cast<int>(image.rowBytes()), |
| + discard_transparency, |
| + actual_pixel_hash, |
| + &png); |
| + |
| + std::cout << "Content-Type: image/png\n"; |
| + std::cout << "Content-Length: " << png.size() << "\n"; |
| + std::cout.write(reinterpret_cast<const char*>(&png[0]), png.size()); |
| + } |
| + |
| MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| +#endif |
| } |
| void LayoutTestControllerHost::OnNotifyDone() { |