[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 5 | #include "content/shell/webkit_test_runner.h" |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 6 | |
[email protected] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 7 | #include <cmath> |
| 8 | |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 9 | #include "base/base64.h" |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 10 | #include "base/debug/debugger.h" |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 11 | #include "base/md5.h" |
[email protected] | e225b92 | 2012-08-18 01:43:04 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 13 | #include "base/message_loop.h" |
[email protected] | c272c5b | 2012-06-06 09:01:06 | [diff] [blame] | 14 | #include "base/stringprintf.h" |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 15 | #include "base/sys_string_conversions.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 16 | #include "base/time.h" |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 17 | #include "base/utf_string_conversions.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 18 | #include "content/public/renderer/render_view.h" |
[email protected] | e519692 | 2012-12-11 22:18:25 | [diff] [blame] | 19 | #include "content/public/test/layouttest_support.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 20 | #include "content/shell/shell_messages.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 21 | #include "content/shell/shell_render_process_observer.h" |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 22 | #include "content/shell/webkit_test_helpers.h" |
[email protected] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 23 | #include "net/base/net_errors.h" |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 24 | #include "net/base/net_util.h" |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 25 | #include "skia/ext/platform_canvas.h" |
[email protected] | 2a58eb1 | 2012-12-18 07:56:40 | [diff] [blame] | 26 | #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" |
[email protected] | 87884c4 | 2013-01-10 01:56:27 | [diff] [blame] | 27 | #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] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 32 | #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 33 | #include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 34 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 35 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 36 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 37 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 38 | #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] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 41 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 42 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 43 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h" |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 44 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestInterfaces.h" |
[email protected] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 45 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h" |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 46 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h" |
[email protected] | 984a5f7 | 2012-12-13 21:41:50 | [diff] [blame] | 47 | #include "webkit/base/file_path_string_conversions.h" |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 48 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 49 | #include "webkit/glue/webpreferences.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 50 | |
[email protected] | 2a58eb1 | 2012-12-18 07:56:40 | [diff] [blame] | 51 | using WebKit::Platform; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 52 | using WebKit::WebContextMenuData; |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 53 | using WebKit::WebDevToolsAgent; |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 54 | using WebKit::WebDeviceOrientation; |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 55 | using WebKit::WebElement; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 56 | using WebKit::WebFrame; |
| 57 | using WebKit::WebGamepads; |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 58 | using WebKit::WebRect; |
[email protected] | c272c5b | 2012-06-06 09:01:06 | [diff] [blame] | 59 | using WebKit::WebSize; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 60 | using WebKit::WebString; |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 61 | using WebKit::WebURL; |
[email protected] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 62 | using WebKit::WebURLError; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 63 | using WebKit::WebVector; |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 64 | using WebKit::WebView; |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 65 | using WebTestRunner::WebPreferences; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 66 | using WebTestRunner::WebTask; |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 67 | using WebTestRunner::WebTestInterfaces; |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 68 | |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 69 | namespace content { |
| 70 | |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 71 | namespace { |
| 72 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 73 | void InvokeTaskHelper(void* context) { |
| 74 | WebTask* task = reinterpret_cast<WebTask*>(context); |
| 75 | task->run(); |
| 76 | delete task; |
| 77 | } |
| 78 | |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 79 | #if !defined(OS_MACOSX) |
| 80 | void 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] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 91 | void CopyCanvasToBitmap(SkCanvas* canvas, SkBitmap* snapshot) { |
[email protected] | 9d611ca | 2012-11-14 13:46:56 | [diff] [blame] | 92 | SkDevice* device = skia::GetTopDevice(*canvas); |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 93 | 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] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 103 | } // namespace |
[email protected] | cccb5cf | 2012-06-06 22:20:04 | [diff] [blame] | 104 | |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 105 | // static |
| 106 | int WebKitTestRunner::window_count_ = 0; |
| 107 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 108 | WebKitTestRunner::WebKitTestRunner(RenderView* render_view) |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 109 | : RenderViewObserver(render_view), |
[email protected] | 2025a2f4 | 2013-02-18 07:25:41 | [diff] [blame^] | 110 | RenderViewObserverTracker<WebKitTestRunner>(render_view), |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 111 | is_main_window_(false) { |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 112 | ++window_count_; |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 115 | WebKitTestRunner::~WebKitTestRunner() { |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 116 | --window_count_; |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 119 | // WebTestDelegate ----------------------------------------------------------- |
| 120 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 121 | void WebKitTestRunner::clearEditCommand() { |
| 122 | render_view()->ClearEditCommands(); |
| 123 | } |
| 124 | |
| 125 | void WebKitTestRunner::setEditCommand(const std::string& name, |
| 126 | const std::string& value) { |
| 127 | render_view()->SetEditCommandForNextKeyEvent(name, value); |
| 128 | } |
| 129 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 130 | void WebKitTestRunner::setGamepadData(const WebGamepads& gamepads) { |
[email protected] | e519692 | 2012-12-11 22:18:25 | [diff] [blame] | 131 | SetMockGamepads(gamepads); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void WebKitTestRunner::printMessage(const std::string& message) { |
| 135 | Send(new ShellViewHostMsg_PrintMessage(routing_id(), message)); |
| 136 | } |
| 137 | |
| 138 | void WebKitTestRunner::postTask(WebTask* task) { |
[email protected] | 2a58eb1 | 2012-12-18 07:56:40 | [diff] [blame] | 139 | Platform::current()->callOnMainThread(InvokeTaskHelper, task); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void 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 | |
| 149 | WebString WebKitTestRunner::registerIsolatedFileSystem( |
| 150 | const WebKit::WebVector<WebKit::WebString>& absolute_filenames) { |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 151 | std::vector<base::FilePath> files; |
[email protected] | 984a5f7 | 2012-12-13 21:41:50 | [diff] [blame] | 152 | 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] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | long long WebKitTestRunner::getCurrentTimeInMillisecond() { |
| 161 | return base::TimeTicks::Now().ToInternalValue() / |
| 162 | base::Time::kMicrosecondsPerMillisecond; |
| 163 | } |
| 164 | |
| 165 | WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path( |
| 166 | const std::string& utf8_path) { |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 167 | #if defined(OS_WIN) |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 168 | base::FilePath path(UTF8ToWide(utf8_path)); |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 169 | #else |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 170 | base::FilePath path(base::SysWideToNativeMB(base::SysUTF8ToWide(utf8_path))); |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 171 | #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] | 984a5f7 | 2012-12-13 21:41:50 | [diff] [blame] | 178 | return webkit_base::FilePathToWebString(path); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 181 | WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) { |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 182 | base::FilePath local_path; |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 183 | 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 | |
| 198 | WebURL 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] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 205 | base::FilePath replace_path = |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 206 | 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] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 219 | WebPreferences* WebKitTestRunner::preferences() { |
| 220 | return &prefs_; |
| 221 | } |
| 222 | |
| 223 | void WebKitTestRunner::applyPreferences() { |
| 224 | webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); |
[email protected] | d48eab08 | 2012-12-19 09:25:47 | [diff] [blame] | 225 | ExportLayoutTestSpecificPreferences(prefs_, &prefs); |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 226 | render_view()->SetWebkitPreferences(prefs); |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 227 | Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs)); |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 230 | std::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] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 261 | void WebKitTestRunner::setClientWindowRect(const WebRect& rect) { |
| 262 | Send(new ShellViewHostMsg_NotImplemented( |
| 263 | routing_id(), "WebKitTestRunner", "setClientWindowRect")); |
| 264 | } |
| 265 | |
| 266 | void WebKitTestRunner::showDevTools() { |
[email protected] | f85c584 | 2013-02-15 14:15:06 | [diff] [blame] | 267 | Send(new ShellViewHostMsg_ShowDevTools(routing_id())); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void WebKitTestRunner::closeDevTools() { |
[email protected] | f85c584 | 2013-02-15 14:15:06 | [diff] [blame] | 271 | Send(new ShellViewHostMsg_CloseDevTools(routing_id())); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void WebKitTestRunner::evaluateInWebInspector(long call_id, |
| 275 | const std::string& script) { |
[email protected] | f85c584 | 2013-02-15 14:15:06 | [diff] [blame] | 276 | WebDevToolsAgent* agent = render_view()->GetWebView()->devToolsAgent(); |
| 277 | if (agent) |
| 278 | agent->evaluateInWebInspector(call_id, WebString::fromUTF8(script)); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void WebKitTestRunner::clearAllDatabases() { |
| 282 | Send(new ShellViewHostMsg_NotImplemented( |
| 283 | routing_id(), "WebKitTestRunner", "clearAllDatabases")); |
| 284 | } |
| 285 | |
| 286 | void WebKitTestRunner::setDatabaseQuota(int quota) { |
| 287 | Send(new ShellViewHostMsg_NotImplemented( |
| 288 | routing_id(), "WebKitTestRunner", "setDatabaseQuota")); |
| 289 | } |
| 290 | |
| 291 | void WebKitTestRunner::setDeviceScaleFactor(float factor) { |
| 292 | Send(new ShellViewHostMsg_NotImplemented( |
| 293 | routing_id(), "WebKitTestRunner", "setDeviceScaleFactor")); |
| 294 | } |
| 295 | |
| 296 | void WebKitTestRunner::setFocus(bool focus) { |
| 297 | Send(new ShellViewHostMsg_NotImplemented( |
| 298 | routing_id(), "WebKitTestRunner", "setFocus")); |
| 299 | } |
| 300 | |
| 301 | void WebKitTestRunner::setAcceptAllCookies(bool accept) { |
| 302 | Send(new ShellViewHostMsg_NotImplemented( |
| 303 | routing_id(), "WebKitTestRunner", "setAcceptAllCookies")); |
| 304 | } |
| 305 | |
| 306 | std::string WebKitTestRunner::pathToLocalResource(const std::string& resource) { |
| 307 | Send(new ShellViewHostMsg_NotImplemented( |
| 308 | routing_id(), "WebKitTestRunner", "pathToLocalResource")); |
| 309 | return std::string(); |
| 310 | } |
| 311 | |
| 312 | void WebKitTestRunner::setLocale(const std::string& locale) { |
| 313 | Send(new ShellViewHostMsg_NotImplemented( |
| 314 | routing_id(), "WebKitTestRunner", "setLocale")); |
| 315 | } |
| 316 | |
| 317 | void WebKitTestRunner::setDeviceOrientation(WebDeviceOrientation& orientation) { |
| 318 | Send(new ShellViewHostMsg_NotImplemented( |
| 319 | routing_id(), "WebKitTestRunner", "setDeviceOrientation")); |
| 320 | } |
| 321 | |
| 322 | void WebKitTestRunner::didAcquirePointerLock() { |
| 323 | Send(new ShellViewHostMsg_NotImplemented( |
| 324 | routing_id(), "WebKitTestRunner", "didAcquirePointerLock")); |
| 325 | } |
| 326 | |
| 327 | void WebKitTestRunner::didNotAcquirePointerLock() { |
| 328 | Send(new ShellViewHostMsg_NotImplemented( |
| 329 | routing_id(), "WebKitTestRunner", "didNotAcquirePointerLock")); |
| 330 | } |
| 331 | |
| 332 | void WebKitTestRunner::didLosePointerLock() { |
| 333 | Send(new ShellViewHostMsg_NotImplemented( |
| 334 | routing_id(), "WebKitTestRunner", "didLosePointerLock")); |
| 335 | } |
| 336 | |
| 337 | void WebKitTestRunner::setPointerLockWillRespondAsynchronously() { |
| 338 | Send(new ShellViewHostMsg_NotImplemented( |
| 339 | routing_id(), |
| 340 | "WebKitTestRunner", |
| 341 | "setPointerLockWillRespondAsynchronously")); |
| 342 | } |
| 343 | |
| 344 | void WebKitTestRunner::setPointerLockWillFailSynchronously() { |
| 345 | Send(new ShellViewHostMsg_NotImplemented( |
| 346 | routing_id(), "WebKitTestRunner", "setPointerLockWillFailSynchronously")); |
| 347 | } |
| 348 | |
| 349 | int WebKitTestRunner::numberOfPendingGeolocationPermissionRequests() { |
| 350 | Send(new ShellViewHostMsg_NotImplemented( |
| 351 | routing_id(), |
| 352 | "WebKitTestRunner", |
| 353 | "numberOfPendingGeolocationPermissionRequests")); |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | void WebKitTestRunner::setGeolocationPermission(bool allowed) { |
| 358 | Send(new ShellViewHostMsg_NotImplemented( |
| 359 | routing_id(), "WebKitTestRunner", "setGeolocationPermission")); |
| 360 | } |
| 361 | |
| 362 | void WebKitTestRunner::setMockGeolocationPosition(double latitude, |
| 363 | double longitude, |
| 364 | double precision) { |
| 365 | Send(new ShellViewHostMsg_NotImplemented( |
| 366 | routing_id(), "WebKitTestRunner", "setMockGeolocationPosition")); |
| 367 | } |
| 368 | |
| 369 | void WebKitTestRunner::setMockGeolocationPositionUnavailableError( |
| 370 | const std::string& message) { |
| 371 | Send(new ShellViewHostMsg_NotImplemented( |
| 372 | routing_id(), |
| 373 | "WebKitTestRunner", |
| 374 | "setMockGeolocationPositionUnavailableError")); |
| 375 | } |
| 376 | |
| 377 | void 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 | |
| 384 | void WebKitTestRunner::setMockSpeechInputDumpRect(bool dump_rect) { |
| 385 | Send(new ShellViewHostMsg_NotImplemented( |
| 386 | routing_id(), "WebKitTestRunner", "setMockSpeechInputDumpRect")); |
| 387 | } |
| 388 | |
| 389 | void WebKitTestRunner::addMockSpeechRecognitionResult( |
| 390 | const std::string& transcript, |
| 391 | double confidence) { |
| 392 | Send(new ShellViewHostMsg_NotImplemented( |
| 393 | routing_id(), "WebKitTestRunner", "addMockSpeechRecognitionResult")); |
| 394 | } |
| 395 | |
| 396 | void WebKitTestRunner::setMockSpeechRecognitionError( |
| 397 | const std::string& error, |
| 398 | const std::string& message) { |
| 399 | Send(new ShellViewHostMsg_NotImplemented( |
| 400 | routing_id(), "WebKitTestRunner", "setMockSpeechRecognitionError")); |
| 401 | } |
| 402 | |
| 403 | bool WebKitTestRunner::wasMockSpeechRecognitionAborted() { |
| 404 | Send(new ShellViewHostMsg_NotImplemented( |
| 405 | routing_id(), "WebKitTestRunner", "wasMockSpeechRecognitionAborted")); |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | void WebKitTestRunner::testFinished() { |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 410 | if (!is_main_window_) |
| 411 | return; |
| 412 | WebTestInterfaces* interfaces = |
| 413 | ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 414 | interfaces->setTestIsRunning(false); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 415 | CaptureDump(); |
| 416 | } |
| 417 | |
| 418 | void WebKitTestRunner::testTimedOut() { |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 419 | if (!is_main_window_) |
| 420 | return; |
| 421 | WebTestInterfaces* interfaces = |
| 422 | ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 423 | interfaces->setTestIsRunning(false); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 424 | Send(new ShellViewHostMsg_TestFinished(routing_id(), true)); |
| 425 | } |
| 426 | |
| 427 | bool WebKitTestRunner::isBeingDebugged() { |
| 428 | return base::debug::BeingDebugged(); |
| 429 | } |
| 430 | |
| 431 | int WebKitTestRunner::layoutTestTimeout() { |
| 432 | return layout_test_timeout_; |
| 433 | } |
| 434 | |
| 435 | void WebKitTestRunner::closeRemainingWindows() { |
| 436 | Send(new ShellViewHostMsg_NotImplemented( |
| 437 | routing_id(), "WebKitTestRunner", "closeRemainingWindows")); |
| 438 | } |
| 439 | |
| 440 | int WebKitTestRunner::navigationEntryCount() { |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | int WebKitTestRunner::windowCount() { |
| 445 | return window_count_; |
| 446 | } |
| 447 | |
| 448 | void WebKitTestRunner::goToOffset(int offset) { |
| 449 | Send(new ShellViewHostMsg_NotImplemented( |
| 450 | routing_id(), "WebKitTestRunner", "goToOffset")); |
| 451 | } |
| 452 | |
| 453 | void WebKitTestRunner::reload() { |
| 454 | Send(new ShellViewHostMsg_NotImplemented( |
| 455 | routing_id(), "WebKitTestRunner", "reload")); |
| 456 | } |
| 457 | |
| 458 | void WebKitTestRunner::loadURLForFrame(const WebURL& url, |
| 459 | const std::string& frame_name) { |
| 460 | Send(new ShellViewHostMsg_NotImplemented( |
| 461 | routing_id(), "WebKitTestRunner", "loadURLForFrame")); |
| 462 | } |
| 463 | |
| 464 | bool WebKitTestRunner::allowExternalPages() { |
| 465 | return allow_external_pages_; |
| 466 | } |
| 467 | |
| 468 | void 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] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 476 | // RenderViewObserver -------------------------------------------------------- |
| 477 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 478 | void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) { |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 479 | ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame); |
[email protected] | 96b80b47 | 2012-07-03 19:41:56 | [diff] [blame] | 480 | } |
| 481 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 482 | bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 483 | bool handled = true; |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 484 | IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message) |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 485 | IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration, |
| 486 | OnSetTestConfiguration) |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 487 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 488 | IPC_END_MESSAGE_MAP() |
| 489 | |
| 490 | return handled; |
| 491 | } |
| 492 | |
[email protected] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 493 | // Public methods - ----------------------------------------------------------- |
| 494 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 495 | void WebKitTestRunner::Reset() { |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 496 | prefs_.reset(); |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 497 | webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); |
[email protected] | d48eab08 | 2012-12-19 09:25:47 | [diff] [blame] | 498 | ExportLayoutTestSpecificPreferences(prefs_, &prefs); |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 499 | render_view()->SetWebkitPreferences(prefs); |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 500 | enable_pixel_dumping_ = true; |
| 501 | layout_test_timeout_ = 30 * 1000; |
| 502 | allow_external_pages_ = false; |
| 503 | expected_pixel_hash_ = std::string(); |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 506 | // Private methods ----------------------------------------------------------- |
| 507 | |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 508 | void WebKitTestRunner::CaptureDump() { |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 509 | 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] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 548 | } |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 549 | |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 550 | Send(new ShellViewHostMsg_TestFinished(routing_id(), false)); |
| 551 | } |
| 552 | |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 553 | void 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] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 559 | current_working_directory_ = current_working_directory; |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 560 | 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] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 564 | 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] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 571 | } |
| 572 | |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 573 | } // namespace content |