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

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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_;
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.
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) {
103 SkAutoLockPixels image_lock(image);
104 base::MD5Digest digest;
105 base::MD5Sum(reinterpret_cast<void*>(image.getPixels()),
106 image.getSize(),
107 &digest);
108 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
109
110 std::cout << "\nActualHash: " << actual_pixel_hash << "\n";
111 if (!expected_pixel_hash_.empty())
112 std::cout << "\nExpectedHash: " << expected_pixel_hash_ << "\n";
113
114 // Only encode and dump the png if the hashes don't match. Encoding the
115 // image is really expensive.
116 if (actual_pixel_hash != expected_pixel_hash_) {
117 std::vector<unsigned char> png;
118
119 // Only the expected PNGs for Mac have a valid alpha channel.
120 #if defined(OS_MACOSX)
121 bool discard_transparency = false;
122 #else
123 bool discard_transparency = true;
124 #endif
125
126 #if !defined(OS_ANDROID)
127 // DumpRenderTree is not currently supported for Android. Also, Android
128 // uses a different byte order, so this method is not implemented on
129 // Android.
130 webkit_support::EncodeBGRAPNGWithChecksum(
131 reinterpret_cast<const unsigned char*>(image.getPixels()),
132 image.width(),
133 image.height(),
134 static_cast<int>(image.rowBytes()),
135 discard_transparency,
136 actual_pixel_hash,
137 &png);
138 #endif
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());
85 } 146 }
86 147
87 void LayoutTestControllerHost::OnNotifyDone() { 148 void LayoutTestControllerHost::OnNotifyDone() {
88 CaptureDump(); 149 CaptureDump();
89 } 150 }
90 151
91 void LayoutTestControllerHost::OnDumpAsText() { 152 void LayoutTestControllerHost::OnDumpAsText() {
92 dump_as_text_ = true; 153 dump_as_text_ = true;
93 } 154 }
94 155
95 void LayoutTestControllerHost::OnSetPrinting() { 156 void LayoutTestControllerHost::OnSetPrinting() {
96 is_printing_ = true; 157 is_printing_ = true;
97 } 158 }
98 159
99 void LayoutTestControllerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload( 160 void LayoutTestControllerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload(
100 bool should_stay_on_page) { 161 bool should_stay_on_page) {
101 should_stay_on_page_after_handling_before_unload_ = should_stay_on_page; 162 should_stay_on_page_after_handling_before_unload_ = should_stay_on_page;
102 } 163 }
103 164
104 void LayoutTestControllerHost::OnDumpChildFramesAsText() { 165 void LayoutTestControllerHost::OnDumpChildFramesAsText() {
105 dump_child_frames_ = true; 166 dump_child_frames_ = true;
106 } 167 }
107 168
108 void LayoutTestControllerHost::OnWaitUntilDone() { 169 void LayoutTestControllerHost::OnWaitUntilDone() {
109 wait_until_done_ = true; 170 wait_until_done_ = true;
110 } 171 }
111 172
112 } // namespace content 173 } // namespace content
OLDNEW
« 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