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

Side by Side Diff: content/shell/webkit_test_runner_host.cc

Issue 10860037: [content shell] rename layout_test_controller{,_host,_bindings}.* to webkit_test_runner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch for landing Created 8 years, 4 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/webkit_test_runner_host.h ('k') | no next file » | 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/webkit_test_runner_host.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "content/public/browser/render_view_host.h" 9 #include "content/public/browser/render_view_host.h"
10 #include "content/shell/shell_messages.h" 10 #include "content/shell/shell_messages.h"
11 #include "content/shell/shell_switches.h" 11 #include "content/shell/shell_switches.h"
12 #include "webkit/support/webkit_support_gfx.h" 12 #include "webkit/support/webkit_support_gfx.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 const int kTestTimeoutMilliseconds = 30 * 1000; 17 const int kTestTimeoutMilliseconds = 30 * 1000;
18 } // namespace 18 } // namespace
19 19
20 std::map<RenderViewHost*, LayoutTestControllerHost*> 20 std::map<RenderViewHost*, WebKitTestRunnerHost*>
21 LayoutTestControllerHost::controllers_; 21 WebKitTestRunnerHost::controllers_;
22 std::string LayoutTestControllerHost::expected_pixel_hash_; 22 std::string WebKitTestRunnerHost::expected_pixel_hash_;
23 23
24 // static 24 // static
25 LayoutTestControllerHost* LayoutTestControllerHost::FromRenderViewHost( 25 WebKitTestRunnerHost* WebKitTestRunnerHost::FromRenderViewHost(
26 RenderViewHost* render_view_host) { 26 RenderViewHost* render_view_host) {
27 const std::map<RenderViewHost*, LayoutTestControllerHost*>::iterator it = 27 const std::map<RenderViewHost*, WebKitTestRunnerHost*>::iterator it =
28 controllers_.find(render_view_host); 28 controllers_.find(render_view_host);
29 if (it == controllers_.end()) 29 if (it == controllers_.end())
30 return NULL; 30 return NULL;
31 return it->second; 31 return it->second;
32 } 32 }
33 33
34 // static 34 // static
35 void LayoutTestControllerHost::Init(const std::string& expected_pixel_hash) { 35 void WebKitTestRunnerHost::Init(const std::string& expected_pixel_hash) {
36 // TODO(jochen): We should only dump the results for the "main window". 36 // TODO(jochen): We should only dump the results for the "main window".
37 expected_pixel_hash_ = expected_pixel_hash; 37 expected_pixel_hash_ = expected_pixel_hash;
38 } 38 }
39 39
40 LayoutTestControllerHost::LayoutTestControllerHost( 40 WebKitTestRunnerHost::WebKitTestRunnerHost(
41 RenderViewHost* render_view_host) 41 RenderViewHost* render_view_host)
42 : RenderViewHostObserver(render_view_host), 42 : RenderViewHostObserver(render_view_host),
43 captured_dump_(false), 43 captured_dump_(false),
44 dump_as_text_(false), 44 dump_as_text_(false),
45 dump_child_frames_(false), 45 dump_child_frames_(false),
46 is_printing_(false), 46 is_printing_(false),
47 should_stay_on_page_after_handling_before_unload_(false), 47 should_stay_on_page_after_handling_before_unload_(false),
48 wait_until_done_(false) { 48 wait_until_done_(false) {
49 controllers_[render_view_host] = this; 49 controllers_[render_view_host] = this;
50 } 50 }
51 51
52 LayoutTestControllerHost::~LayoutTestControllerHost() { 52 WebKitTestRunnerHost::~WebKitTestRunnerHost() {
53 controllers_.erase(render_view_host()); 53 controllers_.erase(render_view_host());
54 watchdog_.Cancel(); 54 watchdog_.Cancel();
55 } 55 }
56 56
57 void LayoutTestControllerHost::CaptureDump() { 57 void WebKitTestRunnerHost::CaptureDump() {
58 if (captured_dump_) 58 if (captured_dump_)
59 return; 59 return;
60 captured_dump_ = true; 60 captured_dump_ = true;
61 61
62 render_view_host()->Send( 62 render_view_host()->Send(
63 new ShellViewMsg_CaptureTextDump(render_view_host()->GetRoutingID(), 63 new ShellViewMsg_CaptureTextDump(render_view_host()->GetRoutingID(),
64 dump_as_text_, 64 dump_as_text_,
65 is_printing_, 65 is_printing_,
66 dump_child_frames_)); 66 dump_child_frames_));
67 if (!dump_as_text_) { 67 if (!dump_as_text_) {
68 render_view_host()->Send( 68 render_view_host()->Send(
69 new ShellViewMsg_CaptureImageDump(render_view_host()->GetRoutingID(), 69 new ShellViewMsg_CaptureImageDump(render_view_host()->GetRoutingID(),
70 expected_pixel_hash_)); 70 expected_pixel_hash_));
71 } 71 }
72 } 72 }
73 73
74 void LayoutTestControllerHost::TimeoutHandler() { 74 void WebKitTestRunnerHost::TimeoutHandler() {
75 printf("FAIL: Timed out waiting for notifyDone to be called\n"); 75 printf("FAIL: Timed out waiting for notifyDone to be called\n");
76 fprintf(stderr, "FAIL: Timed out waiting for notifyDone to be called\n"); 76 fprintf(stderr, "FAIL: Timed out waiting for notifyDone to be called\n");
77 CaptureDump(); 77 CaptureDump();
78 } 78 }
79 79
80 bool LayoutTestControllerHost::OnMessageReceived( 80 bool WebKitTestRunnerHost::OnMessageReceived(
81 const IPC::Message& message) { 81 const IPC::Message& message) {
82 bool handled = true; 82 bool handled = true;
83 IPC_BEGIN_MESSAGE_MAP(LayoutTestControllerHost, message) 83 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunnerHost, message)
84 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad) 84 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad)
85 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) 85 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump)
86 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump) 86 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump)
87 IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotifyDone, OnNotifyDone) 87 IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotifyDone, OnNotifyDone)
88 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpAsText, OnDumpAsText) 88 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpAsText, OnDumpAsText)
89 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpChildFramesAsText, 89 IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpChildFramesAsText,
90 OnDumpChildFramesAsText) 90 OnDumpChildFramesAsText)
91 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPrinting, OnSetPrinting) 91 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SetPrinting, OnSetPrinting)
92 IPC_MESSAGE_HANDLER( 92 IPC_MESSAGE_HANDLER(
93 ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload, 93 ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload,
94 OnSetShouldStayOnPageAfterHandlingBeforeUnload) 94 OnSetShouldStayOnPageAfterHandlingBeforeUnload)
95 IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone) 95 IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone)
96 IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotImplemented, OnNotImplemented) 96 IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotImplemented, OnNotImplemented)
97 IPC_MESSAGE_UNHANDLED(handled = false) 97 IPC_MESSAGE_UNHANDLED(handled = false)
98 IPC_END_MESSAGE_MAP() 98 IPC_END_MESSAGE_MAP()
99 99
100 return handled; 100 return handled;
101 } 101 }
102 102
103 void LayoutTestControllerHost::OnDidFinishLoad() { 103 void WebKitTestRunnerHost::OnDidFinishLoad() {
104 if (wait_until_done_) 104 if (wait_until_done_)
105 return; 105 return;
106 106
107 CaptureDump(); 107 CaptureDump();
108 } 108 }
109 109
110 void LayoutTestControllerHost::OnTextDump(const std::string& dump) { 110 void WebKitTestRunnerHost::OnTextDump(const std::string& dump) {
111 printf("%s#EOF\n", dump.c_str()); 111 printf("%s#EOF\n", dump.c_str());
112 fprintf(stderr, "#EOF\n"); 112 fprintf(stderr, "#EOF\n");
113 113
114 if (dump_as_text_) 114 if (dump_as_text_)
115 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 115 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
116 } 116 }
117 117
118 void LayoutTestControllerHost::OnImageDump( 118 void WebKitTestRunnerHost::OnImageDump(
119 const std::string& actual_pixel_hash, 119 const std::string& actual_pixel_hash,
120 const SkBitmap& image) { 120 const SkBitmap& image) {
121 SkAutoLockPixels image_lock(image); 121 SkAutoLockPixels image_lock(image);
122 122
123 printf("\nActualHash: %s\n", actual_pixel_hash.c_str()); 123 printf("\nActualHash: %s\n", actual_pixel_hash.c_str());
124 if (!expected_pixel_hash_.empty()) 124 if (!expected_pixel_hash_.empty())
125 printf("\nExpectedHash: %s\n", expected_pixel_hash_.c_str()); 125 printf("\nExpectedHash: %s\n", expected_pixel_hash_.c_str());
126 126
127 // Only encode and dump the png if the hashes don't match. Encoding the 127 // Only encode and dump the png if the hashes don't match. Encoding the
128 // image is really expensive. 128 // image is really expensive.
(...skipping 30 matching lines...) Expand all
159 if (success) { 159 if (success) {
160 printf("Content-Type: image/png\n"); 160 printf("Content-Type: image/png\n");
161 printf("Content-Length: %u\n", static_cast<unsigned>(png.size())); 161 printf("Content-Length: %u\n", static_cast<unsigned>(png.size()));
162 fwrite(&png[0], 1, png.size(), stdout); 162 fwrite(&png[0], 1, png.size(), stdout);
163 } 163 }
164 } 164 }
165 165
166 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 166 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
167 } 167 }
168 168
169 void LayoutTestControllerHost::OnNotifyDone() { 169 void WebKitTestRunnerHost::OnNotifyDone() {
170 if (!wait_until_done_) 170 if (!wait_until_done_)
171 return; 171 return;
172 watchdog_.Cancel(); 172 watchdog_.Cancel();
173 CaptureDump(); 173 CaptureDump();
174 } 174 }
175 175
176 void LayoutTestControllerHost::OnDumpAsText() { 176 void WebKitTestRunnerHost::OnDumpAsText() {
177 dump_as_text_ = true; 177 dump_as_text_ = true;
178 } 178 }
179 179
180 void LayoutTestControllerHost::OnSetPrinting() { 180 void WebKitTestRunnerHost::OnSetPrinting() {
181 is_printing_ = true; 181 is_printing_ = true;
182 } 182 }
183 183
184 void LayoutTestControllerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload( 184 void WebKitTestRunnerHost::OnSetShouldStayOnPageAfterHandlingBeforeUnload(
185 bool should_stay_on_page) { 185 bool should_stay_on_page) {
186 should_stay_on_page_after_handling_before_unload_ = should_stay_on_page; 186 should_stay_on_page_after_handling_before_unload_ = should_stay_on_page;
187 } 187 }
188 188
189 void LayoutTestControllerHost::OnDumpChildFramesAsText() { 189 void WebKitTestRunnerHost::OnDumpChildFramesAsText() {
190 dump_child_frames_ = true; 190 dump_child_frames_ = true;
191 } 191 }
192 192
193 void LayoutTestControllerHost::OnWaitUntilDone() { 193 void WebKitTestRunnerHost::OnWaitUntilDone() {
194 if (wait_until_done_) 194 if (wait_until_done_)
195 return; 195 return;
196 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTimeout)) { 196 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTimeout)) {
197 watchdog_.Reset(base::Bind(&LayoutTestControllerHost::TimeoutHandler, 197 watchdog_.Reset(base::Bind(&WebKitTestRunnerHost::TimeoutHandler,
198 base::Unretained(this))); 198 base::Unretained(this)));
199 MessageLoop::current()->PostDelayedTask( 199 MessageLoop::current()->PostDelayedTask(
200 FROM_HERE, 200 FROM_HERE,
201 watchdog_.callback(), 201 watchdog_.callback(),
202 base::TimeDelta::FromMilliseconds(kTestTimeoutMilliseconds)); 202 base::TimeDelta::FromMilliseconds(kTestTimeoutMilliseconds));
203 } 203 }
204 wait_until_done_ = true; 204 wait_until_done_ = true;
205 } 205 }
206 206
207 void LayoutTestControllerHost::OnNotImplemented( 207 void WebKitTestRunnerHost::OnNotImplemented(
208 const std::string& object_name, 208 const std::string& object_name,
209 const std::string& property_name) { 209 const std::string& property_name) {
210 if (captured_dump_) 210 if (captured_dump_)
211 return; 211 return;
212 printf("FAIL: NOT IMPLEMENTED: %s.%s\n", 212 printf("FAIL: NOT IMPLEMENTED: %s.%s\n",
213 object_name.c_str(), property_name.c_str()); 213 object_name.c_str(), property_name.c_str());
214 fprintf(stderr, "FAIL: NOT IMPLEMENTED: %s.%s\n", 214 fprintf(stderr, "FAIL: NOT IMPLEMENTED: %s.%s\n",
215 object_name.c_str(), property_name.c_str()); 215 object_name.c_str(), property_name.c_str());
216 watchdog_.Cancel(); 216 watchdog_.Cancel();
217 CaptureDump(); 217 CaptureDump();
218 } 218 }
219 219
220 } // namespace content 220 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/webkit_test_runner_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698