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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/shell/layout_test_controller_host.h" 5 #include "content/shell/layout_test_controller_host.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 8
9 #include "base/md5.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
11 #include "content/shell/shell_messages.h" 12 #include "content/shell/shell_messages.h"
13 #include "webkit/support/webkit_support_gfx.h"
12 14
13 namespace content { 15 namespace content {
14 16
15 std::map<RenderViewHost*, LayoutTestControllerHost*> 17 std::map<RenderViewHost*, LayoutTestControllerHost*>
16 LayoutTestControllerHost::controllers_; 18 LayoutTestControllerHost::controllers_;
19 std::string LayoutTestControllerHost::expected_pixel_hash_;
17 20
18 // static 21 // static
19 LayoutTestControllerHost* LayoutTestControllerHost::FromRenderViewHost( 22 LayoutTestControllerHost* LayoutTestControllerHost::FromRenderViewHost(
20 RenderViewHost* render_view_host) { 23 RenderViewHost* render_view_host) {
21 const std::map<RenderViewHost*, LayoutTestControllerHost*>::iterator it = 24 const std::map<RenderViewHost*, LayoutTestControllerHost*>::iterator it =
22 controllers_.find(render_view_host); 25 controllers_.find(render_view_host);
23 if (it == controllers_.end()) 26 if (it == controllers_.end())
24 return NULL; 27 return NULL;
25 return it->second; 28 return it->second;
26 } 29 }
27 30
31 // static
32 void LayoutTestControllerHost::Init(const std::string& expected_pixel_hash) {
33 // TODO(jochen): We should only dump the results for the "main window".
34 expected_pixel_hash_ = expected_pixel_hash;
35 }
36
28 LayoutTestControllerHost::LayoutTestControllerHost( 37 LayoutTestControllerHost::LayoutTestControllerHost(
29 RenderViewHost* render_view_host) 38 RenderViewHost* render_view_host)
30 : RenderViewHostObserver(render_view_host), 39 : RenderViewHostObserver(render_view_host),
31 dump_as_text_(false), 40 dump_as_text_(false),
32 dump_child_frames_(false), 41 dump_child_frames_(false),
33 is_printing_(false), 42 is_printing_(false),
34 should_stay_on_page_after_handling_before_unload_(false), 43 should_stay_on_page_after_handling_before_unload_(false),
35 wait_until_done_(false) { 44 wait_until_done_(false) {
36 controllers_[render_view_host] = this; 45 controllers_[render_view_host] = this;
37 } 46 }
38 47
39 LayoutTestControllerHost::~LayoutTestControllerHost() { 48 LayoutTestControllerHost::~LayoutTestControllerHost() {
40 controllers_.erase(render_view_host()); 49 controllers_.erase(render_view_host());
41 } 50 }
42 51
43 void LayoutTestControllerHost::CaptureDump() { 52 void LayoutTestControllerHost::CaptureDump() {
44 render_view_host()->Send( 53 render_view_host()->Send(
45 new ShellViewMsg_CaptureTextDump(render_view_host()->GetRoutingID(), 54 new ShellViewMsg_CaptureTextDump(render_view_host()->GetRoutingID(),
46 dump_as_text_, 55 dump_as_text_,
47 is_printing_, 56 is_printing_,
48 dump_child_frames_)); 57 dump_child_frames_));
58 if (!dump_as_text_) {
59 render_view_host()->Send(
60 new ShellViewMsg_CaptureImageDump(render_view_host()->GetRoutingID()));
61 }
49 } 62 }
50 63
51 bool LayoutTestControllerHost::OnMessageReceived( 64 bool LayoutTestControllerHost::OnMessageReceived(
52 const IPC::Message& message) { 65 const IPC::Message& message) {
53 bool handled = true; 66 bool handled = true;
54 IPC_BEGIN_MESSAGE_MAP(LayoutTestControllerHost, message) 67 IPC_BEGIN_MESSAGE_MAP(LayoutTestControllerHost, message)
55 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad) 68 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad)
56 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) 69 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump)
70 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump)
57 IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotifyDone, OnNotifyDone) 71 IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotifyDone, OnNotifyDone)
58 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpAsText, OnDumpAsText) 72 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpAsText, OnDumpAsText)
59 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpChildFramesAsText, 73 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpChildFramesAsText,
60 OnDumpChildFramesAsText) 74 OnDumpChildFramesAsText)
61 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPrinting, OnSetPrinting) 75 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPrinting, OnSetPrinting)
62 IPC_MESSAGE_HANDLER( 76 IPC_MESSAGE_HANDLER(
63 ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload, 77 ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload,
64 OnSetShouldStayOnPageAfterHandlingBeforeUnload) 78 OnSetShouldStayOnPageAfterHandlingBeforeUnload)
65 IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone) 79 IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone)
66 IPC_MESSAGE_UNHANDLED(handled = false) 80 IPC_MESSAGE_UNHANDLED(handled = false)
67 IPC_END_MESSAGE_MAP() 81 IPC_END_MESSAGE_MAP()
68 82
69 return handled; 83 return handled;
70 } 84 }
71 85
72 void LayoutTestControllerHost::OnDidFinishLoad() { 86 void LayoutTestControllerHost::OnDidFinishLoad() {
73 if (wait_until_done_) 87 if (wait_until_done_)
74 return; 88 return;
75 89
76 CaptureDump(); 90 CaptureDump();
77 } 91 }
78 92
79 void LayoutTestControllerHost::OnTextDump(const std::string& dump) { 93 void LayoutTestControllerHost::OnTextDump(const std::string& dump) {
80 std::cout << dump; 94 std::cout << dump;
81 std::cout << "#EOF\n"; 95 std::cout << "#EOF\n";
82 std::cerr << "#EOF\n"; 96 std::cerr << "#EOF\n";
83 97
98 if (dump_as_text_)
99 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
100 }
101
102 void LayoutTestControllerHost::OnImageDump(const SkBitmap& image) {
jochen (gone - plz use gerrit) 2012/06/26 13:40:32 compare to TestShell::dumpImage
103 #if !defined(OS_ANDROID)
104 // DumpRenderTree is not currently supported for Android. Also, on Android
105 // the required webkit_support methods are not defined, so this method just
106 // doesn't compile.
107
108 SkAutoLockPixels image_lock(image);
109 base::MD5Digest digest;
110 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
111 image.getSize(),
112 &digest);
113 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
114
115 std::cout << "\nActualHash: " << actual_pixel_hash << "\n";
116 if (!expected_pixel_hash_.empty())
117 std::cout << "\nExpectedHash: " << expected_pixel_hash_ << "\n";
118
119 // Only encode and dump the png if the hashes don't match. Encoding the
120 // image is really expensive.
121 if (actual_pixel_hash != expected_pixel_hash_) {
122 std::vector<unsigned char> png;
123
124 // Only the expected PNGs for Mac have a valid alpha channel.
125 #if defined(OS_MACOSX)
126 bool discard_transparency = false;
127 #else
128 bool discard_transparency = true;
129 #endif
130
131 webkit_support::EncodeBGRAPNGWithChecksum(
132 reinterpret_cast<const unsigned char*>(image.getPixels()),
133 image.width(),
134 image.height(),
135 static_cast<int>(image.rowBytes()),
136 discard_transparency,
137 actual_pixel_hash,
138 &png);
139
140 std::cout << "Content-Type: image/png\n";
141 std::cout << "Content-Length: " << png.size() << "\n";
142 std::cout.write(reinterpret_cast<const char*>(&png[0]), png.size());
143 }
144
84 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 145 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
146 #endif
85 } 147 }
86 148
87 void LayoutTestControllerHost::OnNotifyDone() { 149 void LayoutTestControllerHost::OnNotifyDone() {
88 CaptureDump(); 150 CaptureDump();
89 } 151 }
90 152
91 void LayoutTestControllerHost::OnDumpAsText() { 153 void LayoutTestControllerHost::OnDumpAsText() {
92 dump_as_text_ = true; 154 dump_as_text_ = true;
93 } 155 }
94 156
95 void LayoutTestControllerHost::OnSetPrinting() { 157 void LayoutTestControllerHost::OnSetPrinting() {
96 is_printing_ = true; 158 is_printing_ = true;
97 } 159 }
98 160
99 void LayoutTestControllerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload( 161 void LayoutTestControllerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload(
100 bool should_stay_on_page) { 162 bool should_stay_on_page) {
101 should_stay_on_page_after_handling_before_unload_ = should_stay_on_page; 163 should_stay_on_page_after_handling_before_unload_ = should_stay_on_page;
102 } 164 }
103 165
104 void LayoutTestControllerHost::OnDumpChildFramesAsText() { 166 void LayoutTestControllerHost::OnDumpChildFramesAsText() {
105 dump_child_frames_ = true; 167 dump_child_frames_ = true;
106 } 168 }
107 169
108 void LayoutTestControllerHost::OnWaitUntilDone() { 170 void LayoutTestControllerHost::OnWaitUntilDone() {
109 wait_until_done_ = true; 171 wait_until_done_ = true;
110 } 172 }
111 173
112 } // namespace content 174 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698