Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1728)

Unified Diff: content/shell/layout_test_controller_host.cc

Issue 10656044: Add basic support to dump pixel results (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/shell/layout_test_controller_host.h ('k') | content/shell/shell_browser_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ad0a435522236c65897c04055d06770e2ed5c26e 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_;
marja 2012/06/26 13:32:44 This NOOP line is probably not what you want (extr
jochen (gone - plz use gerrit) 2012/06/26 13:38:55 Done.
+}
+
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,6 +95,53 @@ 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) {
+ SkAutoLockPixels image_lock(image);
+ base::MD5Digest digest;
+ base::MD5Sum(reinterpret_cast<void*>(image.getPixels()),
+ 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
+
+#if !defined(OS_ANDROID)
+ // DumpRenderTree is not currently supported for Android. Also, Android
+ // uses a different byte order, so this method is not implemented on
+ // Android.
+ 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);
+#endif
+
+ 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());
}
« no previous file with comments | « content/shell/layout_test_controller_host.h ('k') | content/shell/shell_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698