blob: 0a41aee8015b2985f7111cb1b3a740ffe4b8856c [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]0c5f2222013-02-20 11:26:197#include <algorithm>
[email protected]833b700d2013-02-18 19:43:008#include <clocale>
[email protected]b9fad24c2012-11-15 08:22:109#include <cmath>
10
[email protected]09ec9f92012-12-17 09:46:3611#include "base/base64.h"
[email protected]29e82702013-02-14 12:56:4012#include "base/debug/debugger.h"
[email protected]0799da02012-06-27 10:58:5113#include "base/md5.h"
[email protected]e225b922012-08-18 01:43:0414#include "base/memory/scoped_ptr.h"
[email protected]b2324b092012-11-01 10:34:1115#include "base/message_loop.h"
[email protected]0c5f2222013-02-20 11:26:1916#include "base/string_util.h"
[email protected]c272c5b2012-06-06 09:01:0617#include "base/stringprintf.h"
[email protected]0d2dfb92d2012-11-05 10:26:4518#include "base/sys_string_conversions.h"
[email protected]b2324b092012-11-01 10:34:1119#include "base/time.h"
[email protected]0d2dfb92d2012-11-05 10:26:4520#include "base/utf_string_conversions.h"
[email protected]efb5f572012-01-29 10:57:3321#include "content/public/renderer/render_view.h"
[email protected]e5196922012-12-11 22:18:2522#include "content/public/test/layouttest_support.h"
[email protected]efb5f572012-01-29 10:57:3323#include "content/shell/shell_messages.h"
[email protected]b2324b092012-11-01 10:34:1124#include "content/shell/shell_render_process_observer.h"
[email protected]55915a72012-12-18 11:55:2525#include "content/shell/webkit_test_helpers.h"
[email protected]9d9ec982013-01-10 18:53:3926#include "net/base/net_errors.h"
[email protected]0d2dfb92d2012-11-05 10:26:4527#include "net/base/net_util.h"
[email protected]0799da02012-06-27 10:58:5128#include "skia/ext/platform_canvas.h"
[email protected]2a58eb12012-12-18 07:56:4029#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
[email protected]87884c42013-01-10 01:56:2730#include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
31#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
32#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
33#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
34#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
[email protected]9d9ec982013-01-10 18:53:3935#include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h"
[email protected]0ac1a032013-02-12 12:53:3736#include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h"
[email protected]893fc6362013-02-18 13:24:0537#include "third_party/WebKit/Source/WebKit/chromium/public/WebArrayBufferView.h"
[email protected]b2324b092012-11-01 10:34:1138#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
[email protected]0ac1a032013-02-12 12:53:3739#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]001841c92012-12-11 17:00:1340#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]29e82702013-02-14 12:56:4041#include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.h"
[email protected]efb5f572012-01-29 10:57:3342#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
43#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
44#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]b2324b092012-11-01 10:34:1145#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
[email protected]efb5f572012-01-29 10:57:3346#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]b2324b092012-11-01 10:34:1147#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h"
[email protected]5f20df362013-02-15 19:48:1948#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestInterfaces.h"
[email protected]b9fad24c2012-11-15 08:22:1049#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h"
[email protected]5f20df362013-02-15 19:48:1950#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h"
[email protected]c24b40222013-02-20 11:45:4251#include "ui/gfx/rect.h"
[email protected]984a5f72012-12-13 21:41:5052#include "webkit/base/file_path_string_conversions.h"
[email protected]0799da02012-06-27 10:58:5153#include "webkit/glue/webkit_glue.h"
[email protected]324825d2012-11-30 12:37:1554#include "webkit/glue/webpreferences.h"
[email protected]efb5f572012-01-29 10:57:3355
[email protected]2a58eb12012-12-18 07:56:4056using WebKit::Platform;
[email protected]893fc6362013-02-18 13:24:0557using WebKit::WebArrayBufferView;
[email protected]b2324b092012-11-01 10:34:1158using WebKit::WebContextMenuData;
[email protected]001841c92012-12-11 17:00:1359using WebKit::WebDevToolsAgent;
[email protected]29e82702013-02-14 12:56:4060using WebKit::WebDeviceOrientation;
[email protected]efb5f572012-01-29 10:57:3361using WebKit::WebElement;
[email protected]b2324b092012-11-01 10:34:1162using WebKit::WebFrame;
63using WebKit::WebGamepads;
[email protected]0799da02012-06-27 10:58:5164using WebKit::WebRect;
[email protected]c272c5b2012-06-06 09:01:0665using WebKit::WebSize;
[email protected]b2324b092012-11-01 10:34:1166using WebKit::WebString;
[email protected]09ec9f92012-12-17 09:46:3667using WebKit::WebURL;
[email protected]9d9ec982013-01-10 18:53:3968using WebKit::WebURLError;
[email protected]b2324b092012-11-01 10:34:1169using WebKit::WebVector;
[email protected]0799da02012-06-27 10:58:5170using WebKit::WebView;
[email protected]b3dbcb5e2012-12-17 00:16:3771using WebTestRunner::WebPreferences;
[email protected]b2324b092012-11-01 10:34:1172using WebTestRunner::WebTask;
[email protected]5f20df362013-02-15 19:48:1973using WebTestRunner::WebTestInterfaces;
[email protected]9063bf62013-02-20 19:42:0174using WebTestRunner::WebTestProxyBase;
[email protected]efb5f572012-01-29 10:57:3375
[email protected]31d71b02012-01-26 03:42:3176namespace content {
77
[email protected]efb5f572012-01-29 10:57:3378namespace {
79
[email protected]b2324b092012-11-01 10:34:1180void InvokeTaskHelper(void* context) {
81 WebTask* task = reinterpret_cast<WebTask*>(context);
82 task->run();
83 delete task;
84}
85
[email protected]0799da02012-06-27 10:58:5186#if !defined(OS_MACOSX)
87void MakeBitmapOpaque(SkBitmap* bitmap) {
88 SkAutoLockPixels lock(*bitmap);
89 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config);
90 for (int y = 0; y < bitmap->height(); ++y) {
91 uint32_t* row = bitmap->getAddr32(0, y);
92 for (int x = 0; x < bitmap->width(); ++x)
93 row[x] |= 0xFF000000; // Set alpha bits to 1.
94 }
95}
96#endif
97
[email protected]b9fad24c2012-11-15 08:22:1098void CopyCanvasToBitmap(SkCanvas* canvas, SkBitmap* snapshot) {
[email protected]9d611ca2012-11-14 13:46:5699 SkDevice* device = skia::GetTopDevice(*canvas);
[email protected]0799da02012-06-27 10:58:51100 const SkBitmap& bitmap = device->accessBitmap(false);
101 bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config);
102
103#if !defined(OS_MACOSX)
104 // Only the expected PNGs for Mac have a valid alpha channel.
105 MakeBitmapOpaque(snapshot);
106#endif
107
108}
109
[email protected]efb5f572012-01-29 10:57:33110} // namespace
[email protected]cccb5cf2012-06-06 22:20:04111
[email protected]9b4c6cd2012-08-20 10:47:45112WebKitTestRunner::WebKitTestRunner(RenderView* render_view)
[email protected]5f20df362013-02-15 19:48:19113 : RenderViewObserver(render_view),
[email protected]2025a2f42013-02-18 07:25:41114 RenderViewObserverTracker<WebKitTestRunner>(render_view),
[email protected]5f20df362013-02-15 19:48:19115 is_main_window_(false) {
[email protected]31d71b02012-01-26 03:42:31116}
117
[email protected]9b4c6cd2012-08-20 10:47:45118WebKitTestRunner::~WebKitTestRunner() {
[email protected]31d71b02012-01-26 03:42:31119}
120
[email protected]b2324b092012-11-01 10:34:11121// WebTestDelegate -----------------------------------------------------------
122
[email protected]b2324b092012-11-01 10:34:11123void WebKitTestRunner::clearEditCommand() {
124 render_view()->ClearEditCommands();
125}
126
127void WebKitTestRunner::setEditCommand(const std::string& name,
128 const std::string& value) {
129 render_view()->SetEditCommandForNextKeyEvent(name, value);
130}
131
[email protected]b2324b092012-11-01 10:34:11132void WebKitTestRunner::setGamepadData(const WebGamepads& gamepads) {
[email protected]e5196922012-12-11 22:18:25133 SetMockGamepads(gamepads);
[email protected]b2324b092012-11-01 10:34:11134}
135
136void WebKitTestRunner::printMessage(const std::string& message) {
137 Send(new ShellViewHostMsg_PrintMessage(routing_id(), message));
138}
139
140void WebKitTestRunner::postTask(WebTask* task) {
[email protected]2a58eb12012-12-18 07:56:40141 Platform::current()->callOnMainThread(InvokeTaskHelper, task);
[email protected]b2324b092012-11-01 10:34:11142}
143
144void WebKitTestRunner::postDelayedTask(WebTask* task, long long ms) {
145 MessageLoop::current()->PostDelayedTask(
146 FROM_HERE,
147 base::Bind(&WebTask::run, base::Owned(task)),
148 base::TimeDelta::FromMilliseconds(ms));
149}
150
151WebString WebKitTestRunner::registerIsolatedFileSystem(
152 const WebKit::WebVector<WebKit::WebString>& absolute_filenames) {
[email protected]d30a36f2013-02-07 04:16:26153 std::vector<base::FilePath> files;
[email protected]984a5f72012-12-13 21:41:50154 for (size_t i = 0; i < absolute_filenames.size(); ++i)
155 files.push_back(webkit_base::WebStringToFilePath(absolute_filenames[i]));
156 std::string filesystem_id;
157 Send(new ShellViewHostMsg_RegisterIsolatedFileSystem(
158 routing_id(), files, &filesystem_id));
159 return WebString::fromUTF8(filesystem_id);
[email protected]b2324b092012-11-01 10:34:11160}
161
162long long WebKitTestRunner::getCurrentTimeInMillisecond() {
163 return base::TimeTicks::Now().ToInternalValue() /
164 base::Time::kMicrosecondsPerMillisecond;
165}
166
167WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path(
168 const std::string& utf8_path) {
[email protected]0d2dfb92d2012-11-05 10:26:45169#if defined(OS_WIN)
[email protected]d30a36f2013-02-07 04:16:26170 base::FilePath path(UTF8ToWide(utf8_path));
[email protected]0d2dfb92d2012-11-05 10:26:45171#else
[email protected]d30a36f2013-02-07 04:16:26172 base::FilePath path(base::SysWideToNativeMB(base::SysUTF8ToWide(utf8_path)));
[email protected]0d2dfb92d2012-11-05 10:26:45173#endif
174 if (!path.IsAbsolute()) {
175 GURL base_url =
176 net::FilePathToFileURL(current_working_directory_.Append(
177 FILE_PATH_LITERAL("foo")));
178 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path);
179 }
[email protected]984a5f72012-12-13 21:41:50180 return webkit_base::FilePathToWebString(path);
[email protected]b2324b092012-11-01 10:34:11181}
182
[email protected]09ec9f92012-12-17 09:46:36183WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) {
[email protected]d30a36f2013-02-07 04:16:26184 base::FilePath local_path;
[email protected]09ec9f92012-12-17 09:46:36185 if (!net::FileURLToFilePath(file_url, &local_path))
186 return WebURL();
187
188 std::string contents;
189 Send(new ShellViewHostMsg_ReadFileToString(
190 routing_id(), local_path, &contents));
191
192 std::string contents_base64;
193 if (!base::Base64Encode(contents, &contents_base64))
194 return WebURL();
195
196 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,";
197 return WebURL(GURL(data_url_prefix + contents_base64));
198}
199
200WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) {
201 const char kPrefix[] = "file:///tmp/LayoutTests/";
202 const int kPrefixLen = arraysize(kPrefix) - 1;
203
204 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen))
205 return WebURL(GURL(utf8_url));
206
[email protected]d30a36f2013-02-07 04:16:26207 base::FilePath replace_path =
[email protected]09ec9f92012-12-17 09:46:36208 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
209 FILE_PATH_LITERAL("LayoutTests/"));
210#if defined(OS_WIN)
211 std::string utf8_path = WideToUTF8(replace_path.value());
212#else
213 std::string utf8_path =
214 WideToUTF8(base::SysNativeMBToWide(replace_path.value()));
215#endif
216 std::string new_url =
217 std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen);
218 return WebURL(GURL(new_url));
219}
220
[email protected]b3dbcb5e2012-12-17 00:16:37221WebPreferences* WebKitTestRunner::preferences() {
222 return &prefs_;
223}
224
225void WebKitTestRunner::applyPreferences() {
226 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
[email protected]d48eab082012-12-19 09:25:47227 ExportLayoutTestSpecificPreferences(prefs_, &prefs);
[email protected]b3dbcb5e2012-12-17 00:16:37228 render_view()->SetWebkitPreferences(prefs);
[email protected]55915a72012-12-18 11:55:25229 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs));
[email protected]b3dbcb5e2012-12-17 00:16:37230}
231
[email protected]9d9ec982013-01-10 18:53:39232std::string WebKitTestRunner::makeURLErrorDescription(
233 const WebURLError& error) {
234 std::string domain = error.domain.utf8();
235 int code = error.reason;
236
237 if (domain == net::kErrorDomain) {
238 domain = "NSURLErrorDomain";
239 switch (error.reason) {
240 case net::ERR_ABORTED:
241 code = -999; // NSURLErrorCancelled
242 break;
243 case net::ERR_UNSAFE_PORT:
244 // Our unsafe port checking happens at the network stack level, but we
245 // make this translation here to match the behavior of stock WebKit.
246 domain = "WebKitErrorDomain";
247 code = 103;
248 break;
249 case net::ERR_ADDRESS_INVALID:
250 case net::ERR_ADDRESS_UNREACHABLE:
251 case net::ERR_NETWORK_ACCESS_DENIED:
252 code = -1004; // NSURLErrorCannotConnectToHost
253 break;
254 }
255 } else {
256 DLOG(WARNING) << "Unknown error domain";
257 }
258
259 return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">",
260 domain.c_str(), code, error.unreachableURL.spec().data());
261}
262
[email protected]29e82702013-02-14 12:56:40263void WebKitTestRunner::setClientWindowRect(const WebRect& rect) {
[email protected]c24b40222013-02-20 11:45:42264 Send(new ShellViewHostMsg_SetClientWindowRect(
265 routing_id(), gfx::Rect(rect)));
[email protected]29e82702013-02-14 12:56:40266}
267
268void WebKitTestRunner::showDevTools() {
[email protected]f85c5842013-02-15 14:15:06269 Send(new ShellViewHostMsg_ShowDevTools(routing_id()));
[email protected]29e82702013-02-14 12:56:40270}
271
272void WebKitTestRunner::closeDevTools() {
[email protected]f85c5842013-02-15 14:15:06273 Send(new ShellViewHostMsg_CloseDevTools(routing_id()));
[email protected]29e82702013-02-14 12:56:40274}
275
276void WebKitTestRunner::evaluateInWebInspector(long call_id,
277 const std::string& script) {
[email protected]f85c5842013-02-15 14:15:06278 WebDevToolsAgent* agent = render_view()->GetWebView()->devToolsAgent();
279 if (agent)
280 agent->evaluateInWebInspector(call_id, WebString::fromUTF8(script));
[email protected]29e82702013-02-14 12:56:40281}
282
283void WebKitTestRunner::clearAllDatabases() {
[email protected]833b700d2013-02-18 19:43:00284 Send(new ShellViewHostMsg_ClearAllDatabases(routing_id()));
[email protected]29e82702013-02-14 12:56:40285}
286
287void WebKitTestRunner::setDatabaseQuota(int quota) {
[email protected]833b700d2013-02-18 19:43:00288 Send(new ShellViewHostMsg_SetDatabaseQuota(routing_id(), quota));
[email protected]29e82702013-02-14 12:56:40289}
290
291void WebKitTestRunner::setDeviceScaleFactor(float factor) {
292 Send(new ShellViewHostMsg_NotImplemented(
293 routing_id(), "WebKitTestRunner", "setDeviceScaleFactor"));
294}
295
296void WebKitTestRunner::setFocus(bool focus) {
[email protected]c24b40222013-02-20 11:45:42297 Send(new ShellViewHostMsg_SetFocus(routing_id(), focus));
[email protected]29e82702013-02-14 12:56:40298}
299
300void WebKitTestRunner::setAcceptAllCookies(bool accept) {
[email protected]833b700d2013-02-18 19:43:00301 Send(new ShellViewHostMsg_AcceptAllCookies(routing_id(), accept));
[email protected]29e82702013-02-14 12:56:40302}
303
304std::string WebKitTestRunner::pathToLocalResource(const std::string& resource) {
[email protected]0c5f2222013-02-20 11:26:19305#if defined(OS_WIN)
306 if (resource.find("/tmp/") == 0) {
307 // We want a temp file.
308 GURL base_url = net::FilePathToFileURL(temp_path_);
309 return base_url.Resolve(resource.substr(strlen("/tmp/"))).spec();
310 }
311#endif
312
313 // Some layout tests use file://// which we resolve as a UNC path. Normalize
314 // them to just file:///.
315 std::string result = resource;
316 while (StringToLowerASCII(result).find("file:////") == 0) {
317 result = result.substr(0, strlen("file:///")) +
318 result.substr(strlen("file:////"));
319 }
320 return rewriteLayoutTestsURL(result).spec();
[email protected]29e82702013-02-14 12:56:40321}
322
323void WebKitTestRunner::setLocale(const std::string& locale) {
[email protected]833b700d2013-02-18 19:43:00324 setlocale(LC_ALL, locale.c_str());
[email protected]29e82702013-02-14 12:56:40325}
326
[email protected]29e82702013-02-14 12:56:40327void WebKitTestRunner::testFinished() {
[email protected]5f20df362013-02-15 19:48:19328 if (!is_main_window_)
329 return;
330 WebTestInterfaces* interfaces =
331 ShellRenderProcessObserver::GetInstance()->test_interfaces();
332 interfaces->setTestIsRunning(false);
[email protected]29e82702013-02-14 12:56:40333 CaptureDump();
334}
335
336void WebKitTestRunner::testTimedOut() {
[email protected]5f20df362013-02-15 19:48:19337 if (!is_main_window_)
338 return;
339 WebTestInterfaces* interfaces =
340 ShellRenderProcessObserver::GetInstance()->test_interfaces();
341 interfaces->setTestIsRunning(false);
[email protected]29e82702013-02-14 12:56:40342 Send(new ShellViewHostMsg_TestFinished(routing_id(), true));
343}
344
345bool WebKitTestRunner::isBeingDebugged() {
346 return base::debug::BeingDebugged();
347}
348
349int WebKitTestRunner::layoutTestTimeout() {
350 return layout_test_timeout_;
351}
352
353void WebKitTestRunner::closeRemainingWindows() {
[email protected]b17e3f92013-02-20 14:05:35354 // We currently always close all remaining windows at the end of each test.
355 // TODO(jochen): Reuse the renderer across tests instead of closing all
356 // windows. http://crbug.com/171128
[email protected]29e82702013-02-14 12:56:40357}
358
359int WebKitTestRunner::navigationEntryCount() {
[email protected]b17e3f92013-02-20 14:05:35360 // TODO(jochen): implement this.
[email protected]29e82702013-02-14 12:56:40361 return 0;
362}
363
[email protected]29e82702013-02-14 12:56:40364void WebKitTestRunner::goToOffset(int offset) {
[email protected]d2494ff2013-02-20 08:22:37365 Send(new ShellViewHostMsg_GoToOffset(routing_id(), offset));
[email protected]29e82702013-02-14 12:56:40366}
367
368void WebKitTestRunner::reload() {
[email protected]d2494ff2013-02-20 08:22:37369 Send(new ShellViewHostMsg_Reload(routing_id()));
[email protected]29e82702013-02-14 12:56:40370}
371
372void WebKitTestRunner::loadURLForFrame(const WebURL& url,
373 const std::string& frame_name) {
[email protected]d2494ff2013-02-20 08:22:37374 Send(new ShellViewHostMsg_LoadURLForFrame(
375 routing_id(), url, frame_name));
[email protected]29e82702013-02-14 12:56:40376}
377
378bool WebKitTestRunner::allowExternalPages() {
379 return allow_external_pages_;
380}
381
382void WebKitTestRunner::captureHistoryForWindow(
[email protected]9063bf62013-02-20 19:42:01383#if defined(WEBTESTRUNNER_NEW_HISTORY_CAPTURE)
384 WebTestProxyBase* proxy,
385#else
[email protected]29e82702013-02-14 12:56:40386 size_t windowIndex,
[email protected]9063bf62013-02-20 19:42:01387#endif
[email protected]29e82702013-02-14 12:56:40388 WebVector<WebKit::WebHistoryItem>* history,
389 size_t* currentEntryIndex) {
390 Send(new ShellViewHostMsg_NotImplemented(
391 routing_id(), "WebKitTestRunner", "captureHistoryForWindow"));
392}
393
[email protected]b2324b092012-11-01 10:34:11394// RenderViewObserver --------------------------------------------------------
395
[email protected]9b4c6cd2012-08-20 10:47:45396void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) {
[email protected]b2324b092012-11-01 10:34:11397 ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame);
[email protected]96b80b472012-07-03 19:41:56398}
399
[email protected]9b4c6cd2012-08-20 10:47:45400bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
[email protected]efb5f572012-01-29 10:57:33401 bool handled = true;
[email protected]9b4c6cd2012-08-20 10:47:45402 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message)
[email protected]0ac1a032013-02-12 12:53:37403 IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration,
404 OnSetTestConfiguration)
[email protected]efb5f572012-01-29 10:57:33405 IPC_MESSAGE_UNHANDLED(handled = false)
406 IPC_END_MESSAGE_MAP()
407
408 return handled;
409}
410
[email protected]b9fad24c2012-11-15 08:22:10411// Public methods - -----------------------------------------------------------
412
[email protected]324825d2012-11-30 12:37:15413void WebKitTestRunner::Reset() {
[email protected]b3dbcb5e2012-12-17 00:16:37414 prefs_.reset();
[email protected]324825d2012-11-30 12:37:15415 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
[email protected]d48eab082012-12-19 09:25:47416 ExportLayoutTestSpecificPreferences(prefs_, &prefs);
[email protected]324825d2012-11-30 12:37:15417 render_view()->SetWebkitPreferences(prefs);
[email protected]0ac1a032013-02-12 12:53:37418 enable_pixel_dumping_ = true;
419 layout_test_timeout_ = 30 * 1000;
420 allow_external_pages_ = false;
421 expected_pixel_hash_ = std::string();
[email protected]324825d2012-11-30 12:37:15422}
423
[email protected]b2324b092012-11-01 10:34:11424// Private methods -----------------------------------------------------------
425
[email protected]0ac1a032013-02-12 12:53:37426void WebKitTestRunner::CaptureDump() {
[email protected]5f20df362013-02-15 19:48:19427 WebTestInterfaces* interfaces =
428 ShellRenderProcessObserver::GetInstance()->test_interfaces();
429
[email protected]893fc6362013-02-18 13:24:05430 if (interfaces->testRunner()->shouldDumpAsAudio()) {
431 const WebArrayBufferView* audio_data =
432 interfaces->testRunner()->audioData();
433 std::vector<unsigned char> vector_data(
434 static_cast<const unsigned char*>(audio_data->baseAddress()),
435 static_cast<const unsigned char*>(audio_data->baseAddress()) +
436 audio_data->byteLength());
437 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data));
438 Send(new ShellViewHostMsg_TestFinished(routing_id(), false));
439 return;
440 }
441
[email protected]5f20df362013-02-15 19:48:19442 Send(
443 new ShellViewHostMsg_TextDump(routing_id(), proxy()->captureTree(false)));
444
445 if (interfaces->testRunner()->shouldGeneratePixelResults()) {
446 SkBitmap snapshot;
447 CopyCanvasToBitmap(proxy()->capturePixels(), &snapshot);
448
449 SkAutoLockPixels snapshot_lock(snapshot);
450 base::MD5Digest digest;
451#if defined(OS_ANDROID)
452 // On Android, pixel layout is RGBA, however, other Chrome platforms use
453 // BGRA.
454 const uint8_t* raw_pixels =
455 reinterpret_cast<const uint8_t*>(snapshot.getPixels());
456 size_t snapshot_size = snapshot.getSize();
457 scoped_array<uint8_t> reordered_pixels(new uint8_t[snapshot_size]);
458 for (size_t i = 0; i < snapshot_size; i += 4) {
459 reordered_pixels[i] = raw_pixels[i + 2];
460 reordered_pixels[i + 1] = raw_pixels[i + 1];
461 reordered_pixels[i + 2] = raw_pixels[i];
462 reordered_pixels[i + 3] = raw_pixels[i + 3];
463 }
464 base::MD5Sum(reordered_pixels.get(), snapshot_size, &digest);
465#else
466 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
467#endif
468 std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
469
470 if (actual_pixel_hash == expected_pixel_hash_) {
471 SkBitmap empty_image;
472 Send(new ShellViewHostMsg_ImageDump(
473 routing_id(), actual_pixel_hash, empty_image));
474 } else {
475 Send(new ShellViewHostMsg_ImageDump(
476 routing_id(), actual_pixel_hash, snapshot));
477 }
[email protected]0ac1a032013-02-12 12:53:37478 }
[email protected]5f20df362013-02-15 19:48:19479
[email protected]0ac1a032013-02-12 12:53:37480 Send(new ShellViewHostMsg_TestFinished(routing_id(), false));
481}
482
[email protected]0ac1a032013-02-12 12:53:37483void WebKitTestRunner::OnSetTestConfiguration(
[email protected]26a51632013-02-18 09:48:56484 const ShellViewMsg_SetTestConfiguration_Params& params) {
485 current_working_directory_ = params.current_working_directory;
[email protected]0c5f2222013-02-20 11:26:19486 temp_path_ = params.temp_path;
[email protected]26a51632013-02-18 09:48:56487 enable_pixel_dumping_ = params.enable_pixel_dumping;
488 layout_test_timeout_ = params.layout_test_timeout;
489 allow_external_pages_ = params.allow_external_pages;
490 expected_pixel_hash_ = params.expected_pixel_hash;
[email protected]5f20df362013-02-15 19:48:19491 is_main_window_ = true;
492
493 WebTestInterfaces* interfaces =
494 ShellRenderProcessObserver::GetInstance()->test_interfaces();
495 interfaces->setTestIsRunning(true);
[email protected]26a51632013-02-18 09:48:56496 interfaces->configureForTestWithURL(params.test_url, enable_pixel_dumping_);
[email protected]0d2dfb92d2012-11-05 10:26:45497}
498
[email protected]31d71b02012-01-26 03:42:31499} // namespace content