blob: 1f49f83922b6a748ea0d2eff01adb4da82463993 [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]b9fad24c2012-11-15 08:22:107#include <cmath>
8
[email protected]09ec9f92012-12-17 09:46:369#include "base/base64.h"
[email protected]29e82702013-02-14 12:56:4010#include "base/debug/debugger.h"
[email protected]0799da02012-06-27 10:58:5111#include "base/md5.h"
[email protected]e225b922012-08-18 01:43:0412#include "base/memory/scoped_ptr.h"
[email protected]b2324b092012-11-01 10:34:1113#include "base/message_loop.h"
[email protected]c272c5b2012-06-06 09:01:0614#include "base/stringprintf.h"
[email protected]0d2dfb92d2012-11-05 10:26:4515#include "base/sys_string_conversions.h"
[email protected]b2324b092012-11-01 10:34:1116#include "base/time.h"
[email protected]0d2dfb92d2012-11-05 10:26:4517#include "base/utf_string_conversions.h"
[email protected]efb5f572012-01-29 10:57:3318#include "content/public/renderer/render_view.h"
[email protected]e5196922012-12-11 22:18:2519#include "content/public/test/layouttest_support.h"
[email protected]efb5f572012-01-29 10:57:3320#include "content/shell/shell_messages.h"
[email protected]b2324b092012-11-01 10:34:1121#include "content/shell/shell_render_process_observer.h"
[email protected]55915a72012-12-18 11:55:2522#include "content/shell/webkit_test_helpers.h"
[email protected]9d9ec982013-01-10 18:53:3923#include "net/base/net_errors.h"
[email protected]0d2dfb92d2012-11-05 10:26:4524#include "net/base/net_util.h"
[email protected]0799da02012-06-27 10:58:5125#include "skia/ext/platform_canvas.h"
[email protected]2a58eb12012-12-18 07:56:4026#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
[email protected]87884c42013-01-10 01:56:2727#include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
28#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
29#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
30#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
31#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
[email protected]9d9ec982013-01-10 18:53:3932#include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h"
[email protected]0ac1a032013-02-12 12:53:3733#include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h"
[email protected]b2324b092012-11-01 10:34:1134#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
[email protected]0ac1a032013-02-12 12:53:3735#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]001841c92012-12-11 17:00:1336#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]29e82702013-02-14 12:56:4037#include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.h"
[email protected]efb5f572012-01-29 10:57:3338#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
39#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
40#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]b2324b092012-11-01 10:34:1141#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]efb5f572012-01-29 10:57:3342#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]b2324b092012-11-01 10:34:1143#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h"
[email protected]5f20df362013-02-15 19:48:1944#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestInterfaces.h"
[email protected]b9fad24c2012-11-15 08:22:1045#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h"
[email protected]5f20df362013-02-15 19:48:1946#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h"
[email protected]984a5f72012-12-13 21:41:5047#include "webkit/base/file_path_string_conversions.h"
[email protected]0799da02012-06-27 10:58:5148#include "webkit/glue/webkit_glue.h"
[email protected]324825d2012-11-30 12:37:1549#include "webkit/glue/webpreferences.h"
[email protected]efb5f572012-01-29 10:57:3350
[email protected]2a58eb12012-12-18 07:56:4051using WebKit::Platform;
[email protected]b2324b092012-11-01 10:34:1152using WebKit::WebContextMenuData;
[email protected]001841c92012-12-11 17:00:1353using WebKit::WebDevToolsAgent;
[email protected]29e82702013-02-14 12:56:4054using WebKit::WebDeviceOrientation;
[email protected]efb5f572012-01-29 10:57:3355using WebKit::WebElement;
[email protected]b2324b092012-11-01 10:34:1156using WebKit::WebFrame;
57using WebKit::WebGamepads;
[email protected]0799da02012-06-27 10:58:5158using WebKit::WebRect;
[email protected]c272c5b2012-06-06 09:01:0659using WebKit::WebSize;
[email protected]b2324b092012-11-01 10:34:1160using WebKit::WebString;
[email protected]09ec9f92012-12-17 09:46:3661using WebKit::WebURL;
[email protected]9d9ec982013-01-10 18:53:3962using WebKit::WebURLError;
[email protected]b2324b092012-11-01 10:34:1163using WebKit::WebVector;
[email protected]0799da02012-06-27 10:58:5164using WebKit::WebView;
[email protected]b3dbcb5e2012-12-17 00:16:3765using WebTestRunner::WebPreferences;
[email protected]b2324b092012-11-01 10:34:1166using WebTestRunner::WebTask;
[email protected]5f20df362013-02-15 19:48:1967using WebTestRunner::WebTestInterfaces;
[email protected]efb5f572012-01-29 10:57:3368
[email protected]31d71b02012-01-26 03:42:3169namespace content {
70
[email protected]efb5f572012-01-29 10:57:3371namespace {
72
[email protected]b2324b092012-11-01 10:34:1173void InvokeTaskHelper(void* context) {
74 WebTask* task = reinterpret_cast<WebTask*>(context);
75 task->run();
76 delete task;
77}
78
[email protected]0799da02012-06-27 10:58:5179#if !defined(OS_MACOSX)
80void MakeBitmapOpaque(SkBitmap* bitmap) {
81 SkAutoLockPixels lock(*bitmap);
82 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config);
83 for (int y = 0; y < bitmap->height(); ++y) {
84 uint32_t* row = bitmap->getAddr32(0, y);
85 for (int x = 0; x < bitmap->width(); ++x)
86 row[x] |= 0xFF000000; // Set alpha bits to 1.
87 }
88}
89#endif
90
[email protected]b9fad24c2012-11-15 08:22:1091void CopyCanvasToBitmap(SkCanvas* canvas, SkBitmap* snapshot) {
[email protected]9d611ca2012-11-14 13:46:5692 SkDevice* device = skia::GetTopDevice(*canvas);
[email protected]0799da02012-06-27 10:58:5193 const SkBitmap& bitmap = device->accessBitmap(false);
94 bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config);
95
96#if !defined(OS_MACOSX)
97 // Only the expected PNGs for Mac have a valid alpha channel.
98 MakeBitmapOpaque(snapshot);
99#endif
100
101}
102
[email protected]efb5f572012-01-29 10:57:33103} // namespace
[email protected]cccb5cf2012-06-06 22:20:04104
[email protected]29e82702013-02-14 12:56:40105// static
106int WebKitTestRunner::window_count_ = 0;
107
[email protected]9b4c6cd2012-08-20 10:47:45108WebKitTestRunner::WebKitTestRunner(RenderView* render_view)
[email protected]5f20df362013-02-15 19:48:19109 : RenderViewObserver(render_view),
[email protected]2025a2f42013-02-18 07:25:41110 RenderViewObserverTracker<WebKitTestRunner>(render_view),
[email protected]5f20df362013-02-15 19:48:19111 is_main_window_(false) {
[email protected]29e82702013-02-14 12:56:40112 ++window_count_;
[email protected]31d71b02012-01-26 03:42:31113}
114
[email protected]9b4c6cd2012-08-20 10:47:45115WebKitTestRunner::~WebKitTestRunner() {
[email protected]29e82702013-02-14 12:56:40116 --window_count_;
[email protected]31d71b02012-01-26 03:42:31117}
118
[email protected]b2324b092012-11-01 10:34:11119// WebTestDelegate -----------------------------------------------------------
120
[email protected]b2324b092012-11-01 10:34:11121void WebKitTestRunner::clearEditCommand() {
122 render_view()->ClearEditCommands();
123}
124
125void WebKitTestRunner::setEditCommand(const std::string& name,
126 const std::string& value) {
127 render_view()->SetEditCommandForNextKeyEvent(name, value);
128}
129
[email protected]b2324b092012-11-01 10:34:11130void WebKitTestRunner::setGamepadData(const WebGamepads& gamepads) {
[email protected]e5196922012-12-11 22:18:25131 SetMockGamepads(gamepads);
[email protected]b2324b092012-11-01 10:34:11132}
133
134void WebKitTestRunner::printMessage(const std::string& message) {
135 Send(new ShellViewHostMsg_PrintMessage(routing_id(), message));
136}
137
138void WebKitTestRunner::postTask(WebTask* task) {
[email protected]2a58eb12012-12-18 07:56:40139 Platform::current()->callOnMainThread(InvokeTaskHelper, task);
[email protected]b2324b092012-11-01 10:34:11140}
141
142void WebKitTestRunner::postDelayedTask(WebTask* task, long long ms) {
143 MessageLoop::current()->PostDelayedTask(
144 FROM_HERE,
145 base::Bind(&WebTask::run, base::Owned(task)),
146 base::TimeDelta::FromMilliseconds(ms));
147}
148
149WebString WebKitTestRunner::registerIsolatedFileSystem(
150 const WebKit::WebVector<WebKit::WebString>& absolute_filenames) {
[email protected]d30a36f2013-02-07 04:16:26151 std::vector<base::FilePath> files;
[email protected]984a5f72012-12-13 21:41:50152 for (size_t i = 0; i < absolute_filenames.size(); ++i)
153 files.push_back(webkit_base::WebStringToFilePath(absolute_filenames[i]));
154 std::string filesystem_id;
155 Send(new ShellViewHostMsg_RegisterIsolatedFileSystem(
156 routing_id(), files, &filesystem_id));
157 return WebString::fromUTF8(filesystem_id);
[email protected]b2324b092012-11-01 10:34:11158}
159
160long long WebKitTestRunner::getCurrentTimeInMillisecond() {
161 return base::TimeTicks::Now().ToInternalValue() /
162 base::Time::kMicrosecondsPerMillisecond;
163}
164
165WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path(
166 const std::string& utf8_path) {
[email protected]0d2dfb92d2012-11-05 10:26:45167#if defined(OS_WIN)
[email protected]d30a36f2013-02-07 04:16:26168 base::FilePath path(UTF8ToWide(utf8_path));
[email protected]0d2dfb92d2012-11-05 10:26:45169#else
[email protected]d30a36f2013-02-07 04:16:26170 base::FilePath path(base::SysWideToNativeMB(base::SysUTF8ToWide(utf8_path)));
[email protected]0d2dfb92d2012-11-05 10:26:45171#endif
172 if (!path.IsAbsolute()) {
173 GURL base_url =
174 net::FilePathToFileURL(current_working_directory_.Append(
175 FILE_PATH_LITERAL("foo")));
176 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path);
177 }
[email protected]984a5f72012-12-13 21:41:50178 return webkit_base::FilePathToWebString(path);
[email protected]b2324b092012-11-01 10:34:11179}
180
[email protected]09ec9f92012-12-17 09:46:36181WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) {
[email protected]d30a36f2013-02-07 04:16:26182 base::FilePath local_path;
[email protected]09ec9f92012-12-17 09:46:36183 if (!net::FileURLToFilePath(file_url, &local_path))
184 return WebURL();
185
186 std::string contents;
187 Send(new ShellViewHostMsg_ReadFileToString(
188 routing_id(), local_path, &contents));
189
190 std::string contents_base64;
191 if (!base::Base64Encode(contents, &contents_base64))
192 return WebURL();
193
194 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,";
195 return WebURL(GURL(data_url_prefix + contents_base64));
196}
197
198WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) {
199 const char kPrefix[] = "file:///tmp/LayoutTests/";
200 const int kPrefixLen = arraysize(kPrefix) - 1;
201
202 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen))
203 return WebURL(GURL(utf8_url));
204
[email protected]d30a36f2013-02-07 04:16:26205 base::FilePath replace_path =
[email protected]09ec9f92012-12-17 09:46:36206 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
207 FILE_PATH_LITERAL("LayoutTests/"));
208#if defined(OS_WIN)
209 std::string utf8_path = WideToUTF8(replace_path.value());
210#else
211 std::string utf8_path =
212 WideToUTF8(base::SysNativeMBToWide(replace_path.value()));
213#endif
214 std::string new_url =
215 std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen);
216 return WebURL(GURL(new_url));
217}
218
[email protected]b3dbcb5e2012-12-17 00:16:37219WebPreferences* WebKitTestRunner::preferences() {
220 return &prefs_;
221}
222
223void WebKitTestRunner::applyPreferences() {
224 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
[email protected]d48eab082012-12-19 09:25:47225 ExportLayoutTestSpecificPreferences(prefs_, &prefs);
[email protected]b3dbcb5e2012-12-17 00:16:37226 render_view()->SetWebkitPreferences(prefs);
[email protected]55915a72012-12-18 11:55:25227 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs));
[email protected]b3dbcb5e2012-12-17 00:16:37228}
229
[email protected]9d9ec982013-01-10 18:53:39230std::string WebKitTestRunner::makeURLErrorDescription(
231 const WebURLError& error) {
232 std::string domain = error.domain.utf8();
233 int code = error.reason;
234
235 if (domain == net::kErrorDomain) {
236 domain = "NSURLErrorDomain";
237 switch (error.reason) {
238 case net::ERR_ABORTED:
239 code = -999; // NSURLErrorCancelled
240 break;
241 case net::ERR_UNSAFE_PORT:
242 // Our unsafe port checking happens at the network stack level, but we
243 // make this translation here to match the behavior of stock WebKit.
244 domain = "WebKitErrorDomain";
245 code = 103;
246 break;
247 case net::ERR_ADDRESS_INVALID:
248 case net::ERR_ADDRESS_UNREACHABLE:
249 case net::ERR_NETWORK_ACCESS_DENIED:
250 code = -1004; // NSURLErrorCannotConnectToHost
251 break;
252 }
253 } else {
254 DLOG(WARNING) << "Unknown error domain";
255 }
256
257 return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">",
258 domain.c_str(), code, error.unreachableURL.spec().data());
259}
260
[email protected]29e82702013-02-14 12:56:40261void WebKitTestRunner::setClientWindowRect(const WebRect& rect) {
262 Send(new ShellViewHostMsg_NotImplemented(
263 routing_id(), "WebKitTestRunner", "setClientWindowRect"));
264}
265
266void WebKitTestRunner::showDevTools() {
[email protected]f85c5842013-02-15 14:15:06267 Send(new ShellViewHostMsg_ShowDevTools(routing_id()));
[email protected]29e82702013-02-14 12:56:40268}
269
270void WebKitTestRunner::closeDevTools() {
[email protected]f85c5842013-02-15 14:15:06271 Send(new ShellViewHostMsg_CloseDevTools(routing_id()));
[email protected]29e82702013-02-14 12:56:40272}
273
274void WebKitTestRunner::evaluateInWebInspector(long call_id,
275 const std::string& script) {
[email protected]f85c5842013-02-15 14:15:06276 WebDevToolsAgent* agent = render_view()->GetWebView()->devToolsAgent();
277 if (agent)
278 agent->evaluateInWebInspector(call_id, WebString::fromUTF8(script));
[email protected]29e82702013-02-14 12:56:40279}
280
281void WebKitTestRunner::clearAllDatabases() {
282 Send(new ShellViewHostMsg_NotImplemented(
283 routing_id(), "WebKitTestRunner", "clearAllDatabases"));
284}
285
286void WebKitTestRunner::setDatabaseQuota(int quota) {
287 Send(new ShellViewHostMsg_NotImplemented(
288 routing_id(), "WebKitTestRunner", "setDatabaseQuota"));
289}
290
291void WebKitTestRunner::setDeviceScaleFactor(float factor) {
292 Send(new ShellViewHostMsg_NotImplemented(
293 routing_id(), "WebKitTestRunner", "setDeviceScaleFactor"));
294}
295
296void WebKitTestRunner::setFocus(bool focus) {
297 Send(new ShellViewHostMsg_NotImplemented(
298 routing_id(), "WebKitTestRunner", "setFocus"));
299}
300
301void WebKitTestRunner::setAcceptAllCookies(bool accept) {
302 Send(new ShellViewHostMsg_NotImplemented(
303 routing_id(), "WebKitTestRunner", "setAcceptAllCookies"));
304}
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) {
313 Send(new ShellViewHostMsg_NotImplemented(
314 routing_id(), "WebKitTestRunner", "setLocale"));
315}
316
317void WebKitTestRunner::setDeviceOrientation(WebDeviceOrientation& orientation) {
318 Send(new ShellViewHostMsg_NotImplemented(
319 routing_id(), "WebKitTestRunner", "setDeviceOrientation"));
320}
321
322void WebKitTestRunner::didAcquirePointerLock() {
323 Send(new ShellViewHostMsg_NotImplemented(
324 routing_id(), "WebKitTestRunner", "didAcquirePointerLock"));
325}
326
327void WebKitTestRunner::didNotAcquirePointerLock() {
328 Send(new ShellViewHostMsg_NotImplemented(
329 routing_id(), "WebKitTestRunner", "didNotAcquirePointerLock"));
330}
331
332void WebKitTestRunner::didLosePointerLock() {
333 Send(new ShellViewHostMsg_NotImplemented(
334 routing_id(), "WebKitTestRunner", "didLosePointerLock"));
335}
336
337void WebKitTestRunner::setPointerLockWillRespondAsynchronously() {
338 Send(new ShellViewHostMsg_NotImplemented(
339 routing_id(),
340 "WebKitTestRunner",
341 "setPointerLockWillRespondAsynchronously"));
342}
343
344void WebKitTestRunner::setPointerLockWillFailSynchronously() {
345 Send(new ShellViewHostMsg_NotImplemented(
346 routing_id(), "WebKitTestRunner", "setPointerLockWillFailSynchronously"));
347}
348
349int WebKitTestRunner::numberOfPendingGeolocationPermissionRequests() {
350 Send(new ShellViewHostMsg_NotImplemented(
351 routing_id(),
352 "WebKitTestRunner",
353 "numberOfPendingGeolocationPermissionRequests"));
354 return 0;
355}
356
357void WebKitTestRunner::setGeolocationPermission(bool allowed) {
358 Send(new ShellViewHostMsg_NotImplemented(
359 routing_id(), "WebKitTestRunner", "setGeolocationPermission"));
360}
361
362void WebKitTestRunner::setMockGeolocationPosition(double latitude,
363 double longitude,
364 double precision) {
365 Send(new ShellViewHostMsg_NotImplemented(
366 routing_id(), "WebKitTestRunner", "setMockGeolocationPosition"));
367}
368
369void WebKitTestRunner::setMockGeolocationPositionUnavailableError(
370 const std::string& message) {
371 Send(new ShellViewHostMsg_NotImplemented(
372 routing_id(),
373 "WebKitTestRunner",
374 "setMockGeolocationPositionUnavailableError"));
375}
376
377void WebKitTestRunner::addMockSpeechInputResult(const std::string& result,
378 double confidence,
379 const std::string& language) {
380 Send(new ShellViewHostMsg_NotImplemented(
381 routing_id(), "WebKitTestRunner", "addMockSpeechInputResult"));
382}
383
384void WebKitTestRunner::setMockSpeechInputDumpRect(bool dump_rect) {
385 Send(new ShellViewHostMsg_NotImplemented(
386 routing_id(), "WebKitTestRunner", "setMockSpeechInputDumpRect"));
387}
388
389void WebKitTestRunner::addMockSpeechRecognitionResult(
390 const std::string& transcript,
391 double confidence) {
392 Send(new ShellViewHostMsg_NotImplemented(
393 routing_id(), "WebKitTestRunner", "addMockSpeechRecognitionResult"));
394}
395
396void WebKitTestRunner::setMockSpeechRecognitionError(
397 const std::string& error,
398 const std::string& message) {
399 Send(new ShellViewHostMsg_NotImplemented(
400 routing_id(), "WebKitTestRunner", "setMockSpeechRecognitionError"));
401}
402
403bool WebKitTestRunner::wasMockSpeechRecognitionAborted() {
404 Send(new ShellViewHostMsg_NotImplemented(
405 routing_id(), "WebKitTestRunner", "wasMockSpeechRecognitionAborted"));
406 return false;
407}
408
409void WebKitTestRunner::testFinished() {
[email protected]5f20df362013-02-15 19:48:19410 if (!is_main_window_)
411 return;
412 WebTestInterfaces* interfaces =
413 ShellRenderProcessObserver::GetInstance()->test_interfaces();
414 interfaces->setTestIsRunning(false);
[email protected]29e82702013-02-14 12:56:40415 CaptureDump();
416}
417
418void WebKitTestRunner::testTimedOut() {
[email protected]5f20df362013-02-15 19:48:19419 if (!is_main_window_)
420 return;
421 WebTestInterfaces* interfaces =
422 ShellRenderProcessObserver::GetInstance()->test_interfaces();
423 interfaces->setTestIsRunning(false);
[email protected]29e82702013-02-14 12:56:40424 Send(new ShellViewHostMsg_TestFinished(routing_id(), true));
425}
426
427bool WebKitTestRunner::isBeingDebugged() {
428 return base::debug::BeingDebugged();
429}
430
431int WebKitTestRunner::layoutTestTimeout() {
432 return layout_test_timeout_;
433}
434
435void WebKitTestRunner::closeRemainingWindows() {
436 Send(new ShellViewHostMsg_NotImplemented(
437 routing_id(), "WebKitTestRunner", "closeRemainingWindows"));
438}
439
440int WebKitTestRunner::navigationEntryCount() {
[email protected]29e82702013-02-14 12:56:40441 return 0;
442}
443
444int WebKitTestRunner::windowCount() {
445 return window_count_;
446}
447
448void WebKitTestRunner::goToOffset(int offset) {
449 Send(new ShellViewHostMsg_NotImplemented(
450 routing_id(), "WebKitTestRunner", "goToOffset"));
451}
452
453void WebKitTestRunner::reload() {
454 Send(new ShellViewHostMsg_NotImplemented(
455 routing_id(), "WebKitTestRunner", "reload"));
456}
457
458void WebKitTestRunner::loadURLForFrame(const WebURL& url,
459 const std::string& frame_name) {
460 Send(new ShellViewHostMsg_NotImplemented(
461 routing_id(), "WebKitTestRunner", "loadURLForFrame"));
462}
463
464bool WebKitTestRunner::allowExternalPages() {
465 return allow_external_pages_;
466}
467
468void WebKitTestRunner::captureHistoryForWindow(
469 size_t windowIndex,
470 WebVector<WebKit::WebHistoryItem>* history,
471 size_t* currentEntryIndex) {
472 Send(new ShellViewHostMsg_NotImplemented(
473 routing_id(), "WebKitTestRunner", "captureHistoryForWindow"));
474}
475
[email protected]b2324b092012-11-01 10:34:11476// RenderViewObserver --------------------------------------------------------
477
[email protected]9b4c6cd2012-08-20 10:47:45478void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) {
[email protected]b2324b092012-11-01 10:34:11479 ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame);
[email protected]96b80b472012-07-03 19:41:56480}
481
[email protected]9b4c6cd2012-08-20 10:47:45482bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
[email protected]efb5f572012-01-29 10:57:33483 bool handled = true;
[email protected]9b4c6cd2012-08-20 10:47:45484 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message)
[email protected]0ac1a032013-02-12 12:53:37485 IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration,
486 OnSetTestConfiguration)
[email protected]efb5f572012-01-29 10:57:33487 IPC_MESSAGE_UNHANDLED(handled = false)
488 IPC_END_MESSAGE_MAP()
489
490 return handled;
491}
492
[email protected]b9fad24c2012-11-15 08:22:10493// Public methods - -----------------------------------------------------------
494
[email protected]324825d2012-11-30 12:37:15495void WebKitTestRunner::Reset() {
[email protected]b3dbcb5e2012-12-17 00:16:37496 prefs_.reset();
[email protected]324825d2012-11-30 12:37:15497 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
[email protected]d48eab082012-12-19 09:25:47498 ExportLayoutTestSpecificPreferences(prefs_, &prefs);
[email protected]324825d2012-11-30 12:37:15499 render_view()->SetWebkitPreferences(prefs);
[email protected]0ac1a032013-02-12 12:53:37500 enable_pixel_dumping_ = true;
501 layout_test_timeout_ = 30 * 1000;
502 allow_external_pages_ = false;
503 expected_pixel_hash_ = std::string();
[email protected]324825d2012-11-30 12:37:15504}
505
[email protected]b2324b092012-11-01 10:34:11506// Private methods -----------------------------------------------------------
507
[email protected]0ac1a032013-02-12 12:53:37508void WebKitTestRunner::CaptureDump() {
[email protected]5f20df362013-02-15 19:48:19509 WebTestInterfaces* interfaces =
510 ShellRenderProcessObserver::GetInstance()->test_interfaces();
511
512 Send(
513 new ShellViewHostMsg_TextDump(routing_id(), proxy()->captureTree(false)));
514
515 if (interfaces->testRunner()->shouldGeneratePixelResults()) {
516 SkBitmap snapshot;
517 CopyCanvasToBitmap(proxy()->capturePixels(), &snapshot);
518
519 SkAutoLockPixels snapshot_lock(snapshot);
520 base::MD5Digest digest;
521#if defined(OS_ANDROID)
522 // On Android, pixel layout is RGBA, however, other Chrome platforms use
523 // BGRA.
524 const uint8_t* raw_pixels =
525 reinterpret_cast<const uint8_t*>(snapshot.getPixels());
526 size_t snapshot_size = snapshot.getSize();
527 scoped_array<uint8_t> reordered_pixels(new uint8_t[snapshot_size]);
528 for (size_t i = 0; i < snapshot_size; i += 4) {
529 reordered_pixels[i] = raw_pixels[i + 2];
530 reordered_pixels[i + 1] = raw_pixels[i + 1];
531 reordered_pixels[i + 2] = raw_pixels[i];
532 reordered_pixels[i + 3] = raw_pixels[i + 3];
533 }
534 base::MD5Sum(reordered_pixels.get(), snapshot_size, &digest);
535#else
536 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
537#endif
538 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
539
540 if (actual_pixel_hash == expected_pixel_hash_) {
541 SkBitmap empty_image;
542 Send(new ShellViewHostMsg_ImageDump(
543 routing_id(), actual_pixel_hash, empty_image));
544 } else {
545 Send(new ShellViewHostMsg_ImageDump(
546 routing_id(), actual_pixel_hash, snapshot));
547 }
[email protected]0ac1a032013-02-12 12:53:37548 }
[email protected]5f20df362013-02-15 19:48:19549
[email protected]0ac1a032013-02-12 12:53:37550 Send(new ShellViewHostMsg_TestFinished(routing_id(), false));
551}
552
[email protected]0ac1a032013-02-12 12:53:37553void WebKitTestRunner::OnSetTestConfiguration(
554 const base::FilePath& current_working_directory,
555 bool enable_pixel_dumping,
556 int layout_test_timeout,
557 bool allow_external_pages,
558 const std::string& expected_pixel_hash) {
[email protected]0d2dfb92d2012-11-05 10:26:45559 current_working_directory_ = current_working_directory;
[email protected]0ac1a032013-02-12 12:53:37560 enable_pixel_dumping_ = enable_pixel_dumping;
561 layout_test_timeout_ = layout_test_timeout;
562 allow_external_pages_ = allow_external_pages;
563 expected_pixel_hash_ = expected_pixel_hash;
[email protected]5f20df362013-02-15 19:48:19564 is_main_window_ = true;
565
566 WebTestInterfaces* interfaces =
567 ShellRenderProcessObserver::GetInstance()->test_interfaces();
568 interfaces->setTestIsRunning(true);
569 interfaces->configureForTestWithURL(
570 net::FilePathToFileURL(current_working_directory), enable_pixel_dumping);
[email protected]0d2dfb92d2012-11-05 10:26:45571}
572
[email protected]31d71b02012-01-26 03:42:31573} // namespace content