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

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

Issue 11245004: [content shell] link against the TestRunner library (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch for landing Created 8 years, 1 month 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.h ('k') | content/shell/webkit_test_runner.js » ('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/webkit_test_runner.h" 5 #include "content/shell/webkit_test_runner.h"
6 6
7 #include "base/md5.h" 7 #include "base/md5.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
9 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/time.h"
10 #include "content/public/renderer/render_view.h" 12 #include "content/public/renderer/render_view.h"
11 #include "content/shell/shell_messages.h" 13 #include "content/shell/shell_messages.h"
14 #include "content/shell/shell_render_process_observer.h"
12 #include "skia/ext/platform_canvas.h" 15 #include "skia/ext/platform_canvas.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo rmSupport.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTestingSupport.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
27 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web Task.h"
22 #include "webkit/glue/webkit_glue.h" 28 #include "webkit/glue/webkit_glue.h"
23 29
30 using WebKit::WebContextMenuData;
31 using WebKit::WebElement;
24 using WebKit::WebFrame; 32 using WebKit::WebFrame;
25 using WebKit::WebElement; 33 using WebKit::WebGamepads;
26 using WebKit::WebRect; 34 using WebKit::WebRect;
27 using WebKit::WebSize; 35 using WebKit::WebSize;
28 using WebKit::WebTestingSupport; 36 using WebKit::WebString;
37 using WebKit::WebVector;
29 using WebKit::WebView; 38 using WebKit::WebView;
39 using WebTestRunner::WebTask;
30 40
31 namespace content { 41 namespace content {
32 42
33 namespace { 43 namespace {
34 44
45 void InvokeTaskHelper(void* context) {
46 WebTask* task = reinterpret_cast<WebTask*>(context);
47 task->run();
48 delete task;
49 }
50
35 std::string DumpDocumentText(WebFrame* frame) { 51 std::string DumpDocumentText(WebFrame* frame) {
36 // We use the document element's text instead of the body text here because 52 // We use the document element's text instead of the body text here because
37 // not all documents have a body, such as XML documents. 53 // not all documents have a body, such as XML documents.
38 WebElement documentElement = frame->document().documentElement(); 54 WebElement documentElement = frame->document().documentElement();
39 if (documentElement.isNull()) 55 if (documentElement.isNull())
40 return std::string(); 56 return std::string();
41 return documentElement.innerText().utf8(); 57 return documentElement.innerText().utf8();
42 } 58 }
43 59
44 std::string DumpDocumentPrintedText(WebFrame* frame) { 60 std::string DumpDocumentPrintedText(WebFrame* frame) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 #if !defined(OS_MACOSX) 147 #if !defined(OS_MACOSX)
132 // Only the expected PNGs for Mac have a valid alpha channel. 148 // Only the expected PNGs for Mac have a valid alpha channel.
133 MakeBitmapOpaque(snapshot); 149 MakeBitmapOpaque(snapshot);
134 #endif 150 #endif
135 151
136 } 152 }
137 153
138 } // namespace 154 } // namespace
139 155
140 WebKitTestRunner::WebKitTestRunner(RenderView* render_view) 156 WebKitTestRunner::WebKitTestRunner(RenderView* render_view)
141 : RenderViewObserver(render_view) { 157 : RenderViewObserver(render_view),
158 is_main_window_(false) {
142 } 159 }
143 160
144 WebKitTestRunner::~WebKitTestRunner() { 161 WebKitTestRunner::~WebKitTestRunner() {
162 if (is_main_window_)
163 ShellRenderProcessObserver::GetInstance()->SetMainWindow(NULL, this);
145 } 164 }
146 165
166 // WebTestDelegate -----------------------------------------------------------
167
168 void WebKitTestRunner::clearContextMenuData() {
169 last_context_menu_data_.reset();
170 }
171
172 WebContextMenuData* WebKitTestRunner::lastContextMenuData() const {
173 return last_context_menu_data_.get();
174 }
175
176 void WebKitTestRunner::clearEditCommand() {
177 render_view()->ClearEditCommands();
178 }
179
180 void WebKitTestRunner::setEditCommand(const std::string& name,
181 const std::string& value) {
182 render_view()->SetEditCommandForNextKeyEvent(name, value);
183 }
184
185 void WebKitTestRunner::fillSpellingSuggestionList(
186 const WebString& word, WebVector<WebString>* suggestions) {
187 if (word == WebString::fromUTF8("wellcome")) {
188 WebVector<WebString> result(suggestions->size() + 1);
189 for (size_t i = 0; i < suggestions->size(); ++i)
190 result[i] = (*suggestions)[i];
191 result[suggestions->size()] = WebString::fromUTF8("welcome");
192 suggestions->swap(result);
193 }
194 }
195
196 void WebKitTestRunner::setGamepadData(const WebGamepads& gamepads) {
197 Send(new ShellViewHostMsg_NotImplemented(
198 routing_id(), "WebTestDelegate", "setGamepadData"));
199 }
200
201 void WebKitTestRunner::printMessage(const std::string& message) {
202 Send(new ShellViewHostMsg_PrintMessage(routing_id(), message));
203 }
204
205 void WebKitTestRunner::postTask(WebTask* task) {
206 WebKit::webKitPlatformSupport()->callOnMainThread(InvokeTaskHelper, task);
207 }
208
209 void WebKitTestRunner::postDelayedTask(WebTask* task, long long ms) {
210 MessageLoop::current()->PostDelayedTask(
211 FROM_HERE,
212 base::Bind(&WebTask::run, base::Owned(task)),
213 base::TimeDelta::FromMilliseconds(ms));
214 }
215
216 WebString WebKitTestRunner::registerIsolatedFileSystem(
217 const WebKit::WebVector<WebKit::WebString>& absolute_filenames) {
218 Send(new ShellViewHostMsg_NotImplemented(
219 routing_id(), "WebTestDelegate", "registerIsolatedFileSystem"));
220 return WebString();
221 }
222
223 long long WebKitTestRunner::getCurrentTimeInMillisecond() {
224 return base::TimeTicks::Now().ToInternalValue() /
225 base::Time::kMicrosecondsPerMillisecond;
226 }
227
228 WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path(
229 const std::string& utf8_path) {
230 Send(new ShellViewHostMsg_NotImplemented(
231 routing_id(), "WebTestDelegate", "getAbsoluteWebStringFromUTF8Path"));
232 return WebString();
233 }
234
235 // RenderViewObserver --------------------------------------------------------
236
147 void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) { 237 void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) {
148 WebTestingSupport::injectInternalsObject(frame); 238 ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame);
149 } 239 }
150 240
151 void WebKitTestRunner::DidFinishLoad(WebFrame* frame) { 241 void WebKitTestRunner::DidFinishLoad(WebFrame* frame) {
152 if (!frame->parent()) 242 if (!frame->parent())
153 Send(new ShellViewHostMsg_DidFinishLoad(routing_id())); 243 Send(new ShellViewHostMsg_DidFinishLoad(routing_id()));
154 } 244 }
155 245
246 void WebKitTestRunner::DidRequestShowContextMenu(
247 WebFrame* frame,
248 const WebContextMenuData& data) {
249 last_context_menu_data_.reset(new WebContextMenuData(data));
250 }
251
156 bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { 252 bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
157 bool handled = true; 253 bool handled = true;
158 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message) 254 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message)
159 IPC_MESSAGE_HANDLER(ShellViewMsg_CaptureTextDump, OnCaptureTextDump) 255 IPC_MESSAGE_HANDLER(ShellViewMsg_CaptureTextDump, OnCaptureTextDump)
160 IPC_MESSAGE_HANDLER(ShellViewMsg_CaptureImageDump, OnCaptureImageDump) 256 IPC_MESSAGE_HANDLER(ShellViewMsg_CaptureImageDump, OnCaptureImageDump)
257 IPC_MESSAGE_HANDLER(ShellViewMsg_SetIsMainWindow, OnSetIsMainWindow)
161 IPC_MESSAGE_UNHANDLED(handled = false) 258 IPC_MESSAGE_UNHANDLED(handled = false)
162 IPC_END_MESSAGE_MAP() 259 IPC_END_MESSAGE_MAP()
163 260
164 return handled; 261 return handled;
165 } 262 }
166 263
264 // Private methods -----------------------------------------------------------
265
167 void WebKitTestRunner::OnCaptureTextDump(bool as_text, 266 void WebKitTestRunner::OnCaptureTextDump(bool as_text,
168 bool printing, 267 bool printing,
169 bool recursive) { 268 bool recursive) {
170 WebFrame* frame = render_view()->GetWebView()->mainFrame(); 269 WebFrame* frame = render_view()->GetWebView()->mainFrame();
171 std::string dump; 270 std::string dump;
172 if (as_text) { 271 if (as_text) {
173 dump = DumpFramesAsText(frame, printing, recursive); 272 dump = DumpFramesAsText(frame, printing, recursive);
174 } else { 273 } else {
175 WebFrame::RenderAsTextControls render_text_behavior = 274 WebFrame::RenderAsTextControls render_text_behavior =
176 WebFrame::RenderAsTextNormal; 275 WebFrame::RenderAsTextNormal;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (actual_pixel_hash == expected_pixel_hash) { 309 if (actual_pixel_hash == expected_pixel_hash) {
211 SkBitmap empty_image; 310 SkBitmap empty_image;
212 Send(new ShellViewHostMsg_ImageDump( 311 Send(new ShellViewHostMsg_ImageDump(
213 routing_id(), actual_pixel_hash, empty_image)); 312 routing_id(), actual_pixel_hash, empty_image));
214 return; 313 return;
215 } 314 }
216 Send(new ShellViewHostMsg_ImageDump( 315 Send(new ShellViewHostMsg_ImageDump(
217 routing_id(), actual_pixel_hash, snapshot)); 316 routing_id(), actual_pixel_hash, snapshot));
218 } 317 }
219 318
319 void WebKitTestRunner::OnSetIsMainWindow() {
320 is_main_window_ = true;
321 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view(), this);
322 }
323
220 } // namespace content 324 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/webkit_test_runner.h ('k') | content/shell/webkit_test_runner.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698