blob: 54023ba0c04e4efee15d1bf50bd7fcf4594aea1b [file] [log] [blame]
[email protected]31d71b02012-01-26 03:42:311// 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
3// found in the LICENSE file.
4
[email protected]9b4c6cd2012-08-20 10:47:455#include "content/shell/webkit_test_runner.h"
[email protected]31d71b02012-01-26 03:42:316
[email protected]833b700d2013-02-18 19:43:007#include <clocale>
[email protected]b9fad24c2012-11-15 08:22:108#include <cmath>
9
[email protected]09ec9f92012-12-17 09:46:3610#include "base/base64.h"
[email protected]29e82702013-02-14 12:56:4011#include "base/debug/debugger.h"
[email protected]0799da02012-06-27 10:58:5112#include "base/md5.h"
[email protected]e225b922012-08-18 01:43:0413#include "base/memory/scoped_ptr.h"
[email protected]b2324b092012-11-01 10:34:1114#include "base/message_loop.h"
[email protected]c272c5b2012-06-06 09:01:0615#include "base/stringprintf.h"
[email protected]0d2dfb92d2012-11-05 10:26:4516#include "base/sys_string_conversions.h"
[email protected]b2324b092012-11-01 10:34:1117#include "base/time.h"
[email protected]0d2dfb92d2012-11-05 10:26:4518#include "base/utf_string_conversions.h"
[email protected]efb5f572012-01-29 10:57:3319#include "content/public/renderer/render_view.h"
[email protected]e5196922012-12-11 22:18:2520#include "content/public/test/layouttest_support.h"
[email protected]efb5f572012-01-29 10:57:3321#include "content/shell/shell_messages.h"
[email protected]b2324b092012-11-01 10:34:1122#include "content/shell/shell_render_process_observer.h"
[email protected]55915a72012-12-18 11:55:2523#include "content/shell/webkit_test_helpers.h"
[email protected]9d9ec982013-01-10 18:53:3924#include "net/base/net_errors.h"
[email protected]0d2dfb92d2012-11-05 10:26:4525#include "net/base/net_util.h"
[email protected]0799da02012-06-27 10:58:5126#include "skia/ext/platform_canvas.h"
[email protected]2a58eb12012-12-18 07:56:4027#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
[email protected]87884c42013-01-10 01:56:2728#include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
29#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
30#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
31#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
32#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
[email protected]9d9ec982013-01-10 18:53:3933#include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h"
[email protected]0ac1a032013-02-12 12:53:3734#include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h"
[email protected]893fc6362013-02-18 13:24:0535#include "third_party/WebKit/Source/WebKit/chromium/public/WebArrayBufferView.h"
[email protected]b2324b092012-11-01 10:34:1136#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
[email protected]0ac1a032013-02-12 12:53:3737#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]001841c92012-12-11 17:00:1338#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]29e82702013-02-14 12:56:4039#include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.h"
[email protected]efb5f572012-01-29 10:57:3340#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
41#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
42#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]b2324b092012-11-01 10:34:1143#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]efb5f572012-01-29 10:57:3344#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]b2324b092012-11-01 10:34:1145#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h"
[email protected]5f20df362013-02-15 19:48:1946#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestInterfaces.h"
[email protected]b9fad24c2012-11-15 08:22:1047#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h"
[email protected]5f20df362013-02-15 19:48:1948#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h"
[email protected]984a5f72012-12-13 21:41:5049#include "webkit/base/file_path_string_conversions.h"
[email protected]0799da02012-06-27 10:58:5150#include "webkit/glue/webkit_glue.h"
[email protected]324825d2012-11-30 12:37:1551#include "webkit/glue/webpreferences.h"
[email protected]efb5f572012-01-29 10:57:3352
[email protected]2a58eb12012-12-18 07:56:4053using WebKit::Platform;
[email protected]893fc6362013-02-18 13:24:0554using WebKit::WebArrayBufferView;
[email protected]b2324b092012-11-01 10:34:1155using WebKit::WebContextMenuData;
[email protected]001841c92012-12-11 17:00:1356using WebKit::WebDevToolsAgent;
[email protected]29e82702013-02-14 12:56:4057using WebKit::WebDeviceOrientation;
[email protected]efb5f572012-01-29 10:57:3358using WebKit::WebElement;
[email protected]b2324b092012-11-01 10:34:1159using WebKit::WebFrame;
60using WebKit::WebGamepads;
[email protected]0799da02012-06-27 10:58:5161using WebKit::WebRect;
[email protected]c272c5b2012-06-06 09:01:0662using WebKit::WebSize;
[email protected]b2324b092012-11-01 10:34:1163using WebKit::WebString;
[email protected]09ec9f92012-12-17 09:46:3664using WebKit::WebURL;
[email protected]9d9ec982013-01-10 18:53:3965using WebKit::WebURLError;
[email protected]b2324b092012-11-01 10:34:1166using WebKit::WebVector;
[email protected]0799da02012-06-27 10:58:5167using WebKit::WebView;
[email protected]b3dbcb5e2012-12-17 00:16:3768using WebTestRunner::WebPreferences;
[email protected]b2324b092012-11-01 10:34:1169using WebTestRunner::WebTask;
[email protected]5f20df362013-02-15 19:48:1970using WebTestRunner::WebTestInterfaces;
[email protected]efb5f572012-01-29 10:57:3371
[email protected]31d71b02012-01-26 03:42:3172namespace content {
73
[email protected]efb5f572012-01-29 10:57:3374namespace {
75
[email protected]b2324b092012-11-01 10:34:1176void InvokeTaskHelper(void* context) {
77 WebTask* task = reinterpret_cast<WebTask*>(context);
78 task->run();
79 delete task;
80}
81
[email protected]0799da02012-06-27 10:58:5182#if !defined(OS_MACOSX)
83void MakeBitmapOpaque(SkBitmap* bitmap) {
84 SkAutoLockPixels lock(*bitmap);
85 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config);
86 for (int y = 0; y < bitmap->height(); ++y) {
87 uint32_t* row = bitmap->getAddr32(0, y);
88 for (int x = 0; x < bitmap->width(); ++x)
89 row[x] |= 0xFF000000; // Set alpha bits to 1.
90 }
91}
92#endif
93
[email protected]b9fad24c2012-11-15 08:22:1094void CopyCanvasToBitmap(SkCanvas* canvas, SkBitmap* snapshot) {
[email protected]9d611ca2012-11-14 13:46:5695 SkDevice* device = skia::GetTopDevice(*canvas);
[email protected]0799da02012-06-27 10:58:5196 const SkBitmap& bitmap = device->accessBitmap(false);
97 bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config);
98
99#if !defined(OS_MACOSX)
100 // Only the expected PNGs for Mac have a valid alpha channel.
101 MakeBitmapOpaque(snapshot);
102#endif
103
104}
105
[email protected]efb5f572012-01-29 10:57:33106} // namespace
[email protected]cccb5cf2012-06-06 22:20:04107
[email protected]29e82702013-02-14 12:56:40108// static
109int WebKitTestRunner::window_count_ = 0;
110
[email protected]9b4c6cd2012-08-20 10:47:45111WebKitTestRunner::WebKitTestRunner(RenderView* render_view)
[email protected]5f20df362013-02-15 19:48:19112 : RenderViewObserver(render_view),
[email protected]2025a2f42013-02-18 07:25:41113 RenderViewObserverTracker<WebKitTestRunner>(render_view),
[email protected]5f20df362013-02-15 19:48:19114 is_main_window_(false) {
[email protected]29e82702013-02-14 12:56:40115 ++window_count_;
[email protected]31d71b02012-01-26 03:42:31116}
117
[email protected]9b4c6cd2012-08-20 10:47:45118WebKitTestRunner::~WebKitTestRunner() {
[email protected]29e82702013-02-14 12:56:40119 --window_count_;
[email protected]31d71b02012-01-26 03:42:31120}
121
[email protected]b2324b092012-11-01 10:34:11122// WebTestDelegate -----------------------------------------------------------
123
[email protected]b2324b092012-11-01 10:34:11124void WebKitTestRunner::clearEditCommand() {
125 render_view()->ClearEditCommands();
126}
127
128void WebKitTestRunner::setEditCommand(const std::string& name,
129 const std::string& value) {
130 render_view()->SetEditCommandForNextKeyEvent(name, value);
131}
132
[email protected]b2324b092012-11-01 10:34:11133void WebKitTestRunner::setGamepadData(const WebGamepads& gamepads) {
[email protected]e5196922012-12-11 22:18:25134 SetMockGamepads(gamepads);
[email protected]b2324b092012-11-01 10:34:11135}
136
137void WebKitTestRunner::printMessage(const std::string& message) {
138 Send(new ShellViewHostMsg_PrintMessage(routing_id(), message));
139}
140
141void WebKitTestRunner::postTask(WebTask* task) {
[email protected]2a58eb12012-12-18 07:56:40142 Platform::current()->callOnMainThread(InvokeTaskHelper, task);
[email protected]b2324b092012-11-01 10:34:11143}
144
145void WebKitTestRunner::postDelayedTask(WebTask* task, long long ms) {
146 MessageLoop::current()->PostDelayedTask(
147 FROM_HERE,
148 base::Bind(&WebTask::run, base::Owned(task)),
149 base::TimeDelta::FromMilliseconds(ms));
150}
151
152WebString WebKitTestRunner::registerIsolatedFileSystem(
153 const WebKit::WebVector<WebKit::WebString>& absolute_filenames) {
[email protected]d30a36f2013-02-07 04:16:26154 std::vector<base::FilePath> files;
[email protected]984a5f72012-12-13 21:41:50155 for (size_t i = 0; i < absolute_filenames.size(); ++i)
156 files.push_back(webkit_base::WebStringToFilePath(absolute_filenames[i]));
157 std::string filesystem_id;
158 Send(new ShellViewHostMsg_RegisterIsolatedFileSystem(
159 routing_id(), files, &filesystem_id));
160 return WebString::fromUTF8(filesystem_id);
[email protected]b2324b092012-11-01 10:34:11161}
162
163long long WebKitTestRunner::getCurrentTimeInMillisecond() {
164 return base::TimeTicks::Now().ToInternalValue() /
165 base::Time::kMicrosecondsPerMillisecond;
166}
167
168WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path(
169 const std::string& utf8_path) {
[email protected]0d2dfb92d2012-11-05 10:26:45170#if defined(OS_WIN)
[email protected]d30a36f2013-02-07 04:16:26171 base::FilePath path(UTF8ToWide(utf8_path));
[email protected]0d2dfb92d2012-11-05 10:26:45172#else
[email protected]d30a36f2013-02-07 04:16:26173 base::FilePath path(base::SysWideToNativeMB(base::SysUTF8ToWide(utf8_path)));
[email protected]0d2dfb92d2012-11-05 10:26:45174#endif
175 if (!path.IsAbsolute()) {
176 GURL base_url =
177 net::FilePathToFileURL(current_working_directory_.Append(
178 FILE_PATH_LITERAL("foo")));
179 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path);
180 }
[email protected]984a5f72012-12-13 21:41:50181 return webkit_base::FilePathToWebString(path);
[email protected]b2324b092012-11-01 10:34:11182}
183
[email protected]09ec9f92012-12-17 09:46:36184WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) {
[email protected]d30a36f2013-02-07 04:16:26185 base::FilePath local_path;
[email protected]09ec9f92012-12-17 09:46:36186 if (!net::FileURLToFilePath(file_url, &local_path))
187 return WebURL();
188
189 std::string contents;
190 Send(new ShellViewHostMsg_ReadFileToString(
191 routing_id(), local_path, &contents));
192
193 std::string contents_base64;
194 if (!base::Base64Encode(contents, &contents_base64))
195 return WebURL();
196
197 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,";
198 return WebURL(GURL(data_url_prefix + contents_base64));
199}
200
201WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) {
202 const char kPrefix[] = "file:///tmp/LayoutTests/";
203 const int kPrefixLen = arraysize(kPrefix) - 1;
204
205 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen))
206 return WebURL(GURL(utf8_url));
207
[email protected]d30a36f2013-02-07 04:16:26208 base::FilePath replace_path =
[email protected]09ec9f92012-12-17 09:46:36209 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
210 FILE_PATH_LITERAL("LayoutTests/"));
211#if defined(OS_WIN)
212 std::string utf8_path = WideToUTF8(replace_path.value());
213#else
214 std::string utf8_path =
215 WideToUTF8(base::SysNativeMBToWide(replace_path.value()));
216#endif
217 std::string new_url =
218 std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen);
219 return WebURL(GURL(new_url));
220}
221
[email protected]b3dbcb5e2012-12-17 00:16:37222WebPreferences* WebKitTestRunner::preferences() {
223 return &prefs_;
224}
225
226void WebKitTestRunner::applyPreferences() {
227 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
[email protected]d48eab082012-12-19 09:25:47228 ExportLayoutTestSpecificPreferences(prefs_, &prefs);
[email protected]b3dbcb5e2012-12-17 00:16:37229 render_view()->SetWebkitPreferences(prefs);
[email protected]55915a72012-12-18 11:55:25230 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs));
[email protected]b3dbcb5e2012-12-17 00:16:37231}
232
[email protected]9d9ec982013-01-10 18:53:39233std::string WebKitTestRunner::makeURLErrorDescription(
234 const WebURLError& error) {
235 std::string domain = error.domain.utf8();
236 int code = error.reason;
237
238 if (domain == net::kErrorDomain) {
239 domain = "NSURLErrorDomain";
240 switch (error.reason) {
241 case net::ERR_ABORTED:
242 code = -999; // NSURLErrorCancelled
243 break;
244 case net::ERR_UNSAFE_PORT:
245 // Our unsafe port checking happens at the network stack level, but we
246 // make this translation here to match the behavior of stock WebKit.
247 domain = "WebKitErrorDomain";
248 code = 103;
249 break;
250 case net::ERR_ADDRESS_INVALID:
251 case net::ERR_ADDRESS_UNREACHABLE:
252 case net::ERR_NETWORK_ACCESS_DENIED:
253 code = -1004; // NSURLErrorCannotConnectToHost
254 break;
255 }
256 } else {
257 DLOG(WARNING) << "Unknown error domain";
258 }
259
260 return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">",
261 domain.c_str(), code, error.unreachableURL.spec().data());
262}
263
[email protected]29e82702013-02-14 12:56:40264void WebKitTestRunner::setClientWindowRect(const WebRect& rect) {
265 Send(new ShellViewHostMsg_NotImplemented(
266 routing_id(), "WebKitTestRunner", "setClientWindowRect"));
267}
268
269void WebKitTestRunner::showDevTools() {
[email protected]f85c5842013-02-15 14:15:06270 Send(new ShellViewHostMsg_ShowDevTools(routing_id()));
[email protected]29e82702013-02-14 12:56:40271}
272
273void WebKitTestRunner::closeDevTools() {
[email protected]f85c5842013-02-15 14:15:06274 Send(new ShellViewHostMsg_CloseDevTools(routing_id()));
[email protected]29e82702013-02-14 12:56:40275}
276
277void WebKitTestRunner::evaluateInWebInspector(long call_id,
278 const std::string& script) {
[email protected]f85c5842013-02-15 14:15:06279 WebDevToolsAgent* agent = render_view()->GetWebView()->devToolsAgent();
280 if (agent)
281 agent->evaluateInWebInspector(call_id, WebString::fromUTF8(script));
[email protected]29e82702013-02-14 12:56:40282}
283
284void WebKitTestRunner::clearAllDatabases() {
[email protected]833b700d2013-02-18 19:43:00285 Send(new ShellViewHostMsg_ClearAllDatabases(routing_id()));
[email protected]29e82702013-02-14 12:56:40286}
287
288void WebKitTestRunner::setDatabaseQuota(int quota) {
[email protected]833b700d2013-02-18 19:43:00289 Send(new ShellViewHostMsg_SetDatabaseQuota(routing_id(), quota));
[email protected]29e82702013-02-14 12:56:40290}
291
292void WebKitTestRunner::setDeviceScaleFactor(float factor) {
293 Send(new ShellViewHostMsg_NotImplemented(
294 routing_id(), "WebKitTestRunner", "setDeviceScaleFactor"));
295}
296
297void WebKitTestRunner::setFocus(bool focus) {
298 Send(new ShellViewHostMsg_NotImplemented(
299 routing_id(), "WebKitTestRunner", "setFocus"));
300}
301
302void WebKitTestRunner::setAcceptAllCookies(bool accept) {
[email protected]833b700d2013-02-18 19:43:00303 Send(new ShellViewHostMsg_AcceptAllCookies(routing_id(), accept));
[email protected]29e82702013-02-14 12:56:40304}
305
306std::string WebKitTestRunner::pathToLocalResource(const std::string& resource) {
307 Send(new ShellViewHostMsg_NotImplemented(
308 routing_id(), "WebKitTestRunner", "pathToLocalResource"));
309 return std::string();
310}
311
312void WebKitTestRunner::setLocale(const std::string& locale) {
[email protected]833b700d2013-02-18 19:43:00313 setlocale(LC_ALL, locale.c_str());
[email protected]29e82702013-02-14 12:56:40314}
315
316void WebKitTestRunner::setDeviceOrientation(WebDeviceOrientation& orientation) {
317 Send(new ShellViewHostMsg_NotImplemented(
318 routing_id(), "WebKitTestRunner", "setDeviceOrientation"));
319}
320
321void WebKitTestRunner::didAcquirePointerLock() {
322 Send(new ShellViewHostMsg_NotImplemented(
323 routing_id(), "WebKitTestRunner", "didAcquirePointerLock"));
324}
325
326void WebKitTestRunner::didNotAcquirePointerLock() {
327 Send(new ShellViewHostMsg_NotImplemented(
328 routing_id(), "WebKitTestRunner", "didNotAcquirePointerLock"));
329}
330
331void WebKitTestRunner::didLosePointerLock() {
332 Send(new ShellViewHostMsg_NotImplemented(
333 routing_id(), "WebKitTestRunner", "didLosePointerLock"));
334}
335
336void WebKitTestRunner::setPointerLockWillRespondAsynchronously() {
337 Send(new ShellViewHostMsg_NotImplemented(
338 routing_id(),
339 "WebKitTestRunner",
340 "setPointerLockWillRespondAsynchronously"));
341}
342
343void WebKitTestRunner::setPointerLockWillFailSynchronously() {
344 Send(new ShellViewHostMsg_NotImplemented(
345 routing_id(), "WebKitTestRunner", "setPointerLockWillFailSynchronously"));
346}
347
348int WebKitTestRunner::numberOfPendingGeolocationPermissionRequests() {
349 Send(new ShellViewHostMsg_NotImplemented(
350 routing_id(),
351 "WebKitTestRunner",
352 "numberOfPendingGeolocationPermissionRequests"));
353 return 0;
354}
355
356void WebKitTestRunner::setGeolocationPermission(bool allowed) {
357 Send(new ShellViewHostMsg_NotImplemented(
358 routing_id(), "WebKitTestRunner", "setGeolocationPermission"));
359}
360
361void WebKitTestRunner::setMockGeolocationPosition(double latitude,
362 double longitude,
363 double precision) {
364 Send(new ShellViewHostMsg_NotImplemented(
365 routing_id(), "WebKitTestRunner", "setMockGeolocationPosition"));
366}
367
368void WebKitTestRunner::setMockGeolocationPositionUnavailableError(
369 const std::string& message) {
370 Send(new ShellViewHostMsg_NotImplemented(
371 routing_id(),
372 "WebKitTestRunner",
373 "setMockGeolocationPositionUnavailableError"));
374}
375
376void WebKitTestRunner::addMockSpeechInputResult(const std::string& result,
377 double confidence,
378 const std::string& language) {
379 Send(new ShellViewHostMsg_NotImplemented(
380 routing_id(), "WebKitTestRunner", "addMockSpeechInputResult"));
381}
382
383void WebKitTestRunner::setMockSpeechInputDumpRect(bool dump_rect) {
384 Send(new ShellViewHostMsg_NotImplemented(
385 routing_id(), "WebKitTestRunner", "setMockSpeechInputDumpRect"));
386}
387
388void WebKitTestRunner::addMockSpeechRecognitionResult(
389 const std::string& transcript,
390 double confidence) {
391 Send(new ShellViewHostMsg_NotImplemented(
392 routing_id(), "WebKitTestRunner", "addMockSpeechRecognitionResult"));
393}
394
395void WebKitTestRunner::setMockSpeechRecognitionError(
396 const std::string& error,
397 const std::string& message) {
398 Send(new ShellViewHostMsg_NotImplemented(
399 routing_id(), "WebKitTestRunner", "setMockSpeechRecognitionError"));
400}
401
402bool WebKitTestRunner::wasMockSpeechRecognitionAborted() {
403 Send(new ShellViewHostMsg_NotImplemented(
404 routing_id(), "WebKitTestRunner", "wasMockSpeechRecognitionAborted"));
405 return false;
406}
407
408void WebKitTestRunner::testFinished() {
[email protected]5f20df362013-02-15 19:48:19409 if (!is_main_window_)
410 return;
411 WebTestInterfaces* interfaces =
412 ShellRenderProcessObserver::GetInstance()->test_interfaces();
413 interfaces->setTestIsRunning(false);
[email protected]29e82702013-02-14 12:56:40414 CaptureDump();
415}
416
417void WebKitTestRunner::testTimedOut() {
[email protected]5f20df362013-02-15 19:48:19418 if (!is_main_window_)
419 return;
420 WebTestInterfaces* interfaces =
421 ShellRenderProcessObserver::GetInstance()->test_interfaces();
422 interfaces->setTestIsRunning(false);
[email protected]29e82702013-02-14 12:56:40423 Send(new ShellViewHostMsg_TestFinished(routing_id(), true));
424}
425
426bool WebKitTestRunner::isBeingDebugged() {
427 return base::debug::BeingDebugged();
428}
429
430int WebKitTestRunner::layoutTestTimeout() {
431 return layout_test_timeout_;
432}
433
434void WebKitTestRunner::closeRemainingWindows() {
435 Send(new ShellViewHostMsg_NotImplemented(
436 routing_id(), "WebKitTestRunner", "closeRemainingWindows"));
437}
438
439int WebKitTestRunner::navigationEntryCount() {
[email protected]29e82702013-02-14 12:56:40440 return 0;
441}
442
443int WebKitTestRunner::windowCount() {
444 return window_count_;
445}
446
447void WebKitTestRunner::goToOffset(int offset) {
[email protected]d2494ff2013-02-20 08:22:37448 Send(new ShellViewHostMsg_GoToOffset(routing_id(), offset));
[email protected]29e82702013-02-14 12:56:40449}
450
451void WebKitTestRunner::reload() {
[email protected]d2494ff2013-02-20 08:22:37452 Send(new ShellViewHostMsg_Reload(routing_id()));
[email protected]29e82702013-02-14 12:56:40453}
454
455void WebKitTestRunner::loadURLForFrame(const WebURL& url,
456 const std::string& frame_name) {
[email protected]d2494ff2013-02-20 08:22:37457 Send(new ShellViewHostMsg_LoadURLForFrame(
458 routing_id(), url, frame_name));
[email protected]29e82702013-02-14 12:56:40459}
460
461bool WebKitTestRunner::allowExternalPages() {
462 return allow_external_pages_;
463}
464
465void WebKitTestRunner::captureHistoryForWindow(
466 size_t windowIndex,
467 WebVector<WebKit::WebHistoryItem>* history,
468 size_t* currentEntryIndex) {
469 Send(new ShellViewHostMsg_NotImplemented(
470 routing_id(), "WebKitTestRunner", "captureHistoryForWindow"));
471}
472
[email protected]b2324b092012-11-01 10:34:11473// RenderViewObserver --------------------------------------------------------
474
[email protected]9b4c6cd2012-08-20 10:47:45475void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) {
[email protected]b2324b092012-11-01 10:34:11476 ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame);
[email protected]96b80b472012-07-03 19:41:56477}
478
[email protected]9b4c6cd2012-08-20 10:47:45479bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
[email protected]efb5f572012-01-29 10:57:33480 bool handled = true;
[email protected]9b4c6cd2012-08-20 10:47:45481 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message)
[email protected]0ac1a032013-02-12 12:53:37482 IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration,
483 OnSetTestConfiguration)
[email protected]efb5f572012-01-29 10:57:33484 IPC_MESSAGE_UNHANDLED(handled = false)
485 IPC_END_MESSAGE_MAP()
486
487 return handled;
488}
489
[email protected]b9fad24c2012-11-15 08:22:10490// Public methods - -----------------------------------------------------------
491
[email protected]324825d2012-11-30 12:37:15492void WebKitTestRunner::Reset() {
[email protected]b3dbcb5e2012-12-17 00:16:37493 prefs_.reset();
[email protected]324825d2012-11-30 12:37:15494 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
[email protected]d48eab082012-12-19 09:25:47495 ExportLayoutTestSpecificPreferences(prefs_, &prefs);
[email protected]324825d2012-11-30 12:37:15496 render_view()->SetWebkitPreferences(prefs);
[email protected]0ac1a032013-02-12 12:53:37497 enable_pixel_dumping_ = true;
498 layout_test_timeout_ = 30 * 1000;
499 allow_external_pages_ = false;
500 expected_pixel_hash_ = std::string();
[email protected]324825d2012-11-30 12:37:15501}
502
[email protected]b2324b092012-11-01 10:34:11503// Private methods -----------------------------------------------------------
504
[email protected]0ac1a032013-02-12 12:53:37505void WebKitTestRunner::CaptureDump() {
[email protected]5f20df362013-02-15 19:48:19506 WebTestInterfaces* interfaces =
507 ShellRenderProcessObserver::GetInstance()->test_interfaces();
508
[email protected]893fc6362013-02-18 13:24:05509 if (interfaces->testRunner()->shouldDumpAsAudio()) {
510 const WebArrayBufferView* audio_data =
511 interfaces->testRunner()->audioData();
512 std::vector<unsigned char> vector_data(
513 static_cast<const unsigned char*>(audio_data->baseAddress()),
514 static_cast<const unsigned char*>(audio_data->baseAddress()) +
515 audio_data->byteLength());
516 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data));
517 Send(new ShellViewHostMsg_TestFinished(routing_id(), false));
518 return;
519 }
520
[email protected]5f20df362013-02-15 19:48:19521 Send(
522 new ShellViewHostMsg_TextDump(routing_id(), proxy()->captureTree(false)));
523
524 if (interfaces->testRunner()->shouldGeneratePixelResults()) {
525 SkBitmap snapshot;
526 CopyCanvasToBitmap(proxy()->capturePixels(), &snapshot);
527
528 SkAutoLockPixels snapshot_lock(snapshot);
529 base::MD5Digest digest;
530#if defined(OS_ANDROID)
531 // On Android, pixel layout is RGBA, however, other Chrome platforms use
532 // BGRA.
533 const uint8_t* raw_pixels =
534 reinterpret_cast<const uint8_t*>(snapshot.getPixels());
535 size_t snapshot_size = snapshot.getSize();
536 scoped_array<uint8_t> reordered_pixels(new uint8_t[snapshot_size]);
537 for (size_t i = 0; i < snapshot_size; i += 4) {
538 reordered_pixels[i] = raw_pixels[i + 2];
539 reordered_pixels[i + 1] = raw_pixels[i + 1];
540 reordered_pixels[i + 2] = raw_pixels[i];
541 reordered_pixels[i + 3] = raw_pixels[i + 3];
542 }
543 base::MD5Sum(reordered_pixels.get(), snapshot_size, &digest);
544#else
545 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
546#endif
547 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
548
549 if (actual_pixel_hash == expected_pixel_hash_) {
550 SkBitmap empty_image;
551 Send(new ShellViewHostMsg_ImageDump(
552 routing_id(), actual_pixel_hash, empty_image));
553 } else {
554 Send(new ShellViewHostMsg_ImageDump(
555 routing_id(), actual_pixel_hash, snapshot));
556 }
[email protected]0ac1a032013-02-12 12:53:37557 }
[email protected]5f20df362013-02-15 19:48:19558
[email protected]0ac1a032013-02-12 12:53:37559 Send(new ShellViewHostMsg_TestFinished(routing_id(), false));
560}
561
[email protected]0ac1a032013-02-12 12:53:37562void WebKitTestRunner::OnSetTestConfiguration(
[email protected]26a51632013-02-18 09:48:56563 const ShellViewMsg_SetTestConfiguration_Params& params) {
564 current_working_directory_ = params.current_working_directory;
565 enable_pixel_dumping_ = params.enable_pixel_dumping;
566 layout_test_timeout_ = params.layout_test_timeout;
567 allow_external_pages_ = params.allow_external_pages;
568 expected_pixel_hash_ = params.expected_pixel_hash;
[email protected]5f20df362013-02-15 19:48:19569 is_main_window_ = true;
570
571 WebTestInterfaces* interfaces =
572 ShellRenderProcessObserver::GetInstance()->test_interfaces();
573 interfaces->setTestIsRunning(true);
[email protected]26a51632013-02-18 09:48:56574 interfaces->configureForTestWithURL(params.test_url, enable_pixel_dumping_);
[email protected]0d2dfb92d2012-11-05 10:26:45575}
576
[email protected]31d71b02012-01-26 03:42:31577} // namespace content