[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] | 0c5f222 | 2013-02-20 11:26:19 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 833b700d | 2013-02-18 19:43:00 | [diff] [blame] | 8 | #include <clocale> |
[email protected] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 9 | #include <cmath> |
| 10 | |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 11 | #include "base/base64.h" |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 12 | #include "base/debug/debugger.h" |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 13 | #include "base/md5.h" |
[email protected] | e225b92 | 2012-08-18 01:43:04 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 15 | #include "base/message_loop.h" |
[email protected] | 0c5f222 | 2013-02-20 11:26:19 | [diff] [blame] | 16 | #include "base/string_util.h" |
[email protected] | c272c5b | 2012-06-06 09:01:06 | [diff] [blame] | 17 | #include "base/stringprintf.h" |
[email protected] | 40d11e0 | 2013-03-28 17:43:14 | [diff] [blame] | 18 | #include "base/strings/sys_string_conversions.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 19 | #include "base/time.h" |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 20 | #include "base/utf_string_conversions.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 21 | #include "content/public/renderer/render_view.h" |
[email protected] | f322356c | 2013-03-01 07:54:02 | [diff] [blame] | 22 | #include "content/public/renderer/render_view_visitor.h" |
[email protected] | e519692 | 2012-12-11 22:18:25 | [diff] [blame] | 23 | #include "content/public/test/layouttest_support.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 24 | #include "content/shell/shell_messages.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 25 | #include "content/shell/shell_render_process_observer.h" |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 26 | #include "content/shell/webkit_test_helpers.h" |
[email protected] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 27 | #include "net/base/net_errors.h" |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 28 | #include "net/base/net_util.h" |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 29 | #include "skia/ext/platform_canvas.h" |
[email protected] | 2a58eb1 | 2012-12-18 07:56:40 | [diff] [blame] | 30 | #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" |
[email protected] | 87884c4 | 2013-01-10 01:56:27 | [diff] [blame] | 31 | #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
[email protected] | 613ba94c | 2013-03-08 14:14:31 | [diff] [blame] | 32 | #include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h" |
[email protected] | 87884c4 | 2013-01-10 01:56:27 | [diff] [blame] | 33 | #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
| 34 | #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 35 | #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 36 | #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
[email protected] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 37 | #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" |
[email protected] | 1afb9af | 2013-03-18 15:30:32 | [diff] [blame] | 38 | #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 39 | #include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h" |
[email protected] | 893fc636 | 2013-02-18 13:24:05 | [diff] [blame] | 40 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebArrayBufferView.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 41 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 42 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 43 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 44 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeviceOrientation.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 45 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 46 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 47 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 48 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 49 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 50 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
[email protected] | 435b763d | 2013-03-07 13:27:59 | [diff] [blame] | 51 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebTestingSupport.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 52 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 53 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h" |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 54 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestInterfaces.h" |
[email protected] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 55 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h" |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 56 | #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h" |
[email protected] | c24b4022 | 2013-02-20 11:45:42 | [diff] [blame] | 57 | #include "ui/gfx/rect.h" |
[email protected] | 984a5f7 | 2012-12-13 21:41:50 | [diff] [blame] | 58 | #include "webkit/base/file_path_string_conversions.h" |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 59 | #include "webkit/glue/glue_serialize.h" |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 60 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 61 | #include "webkit/glue/webpreferences.h" |
[email protected] | 321d9eb | 2013-04-04 18:25:26 | [diff] [blame] | 62 | #include "webkit/mocks/test_media_stream_client.h" |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 63 | |
[email protected] | 2a58eb1 | 2012-12-18 07:56:40 | [diff] [blame] | 64 | using WebKit::Platform; |
[email protected] | 893fc636 | 2013-02-18 13:24:05 | [diff] [blame] | 65 | using WebKit::WebArrayBufferView; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 66 | using WebKit::WebContextMenuData; |
[email protected] | 001841c9 | 2012-12-11 17:00:13 | [diff] [blame] | 67 | using WebKit::WebDevToolsAgent; |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 68 | using WebKit::WebDeviceOrientation; |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 69 | using WebKit::WebElement; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 70 | using WebKit::WebFrame; |
| 71 | using WebKit::WebGamepads; |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 72 | using WebKit::WebHistoryItem; |
[email protected] | 321d9eb | 2013-04-04 18:25:26 | [diff] [blame] | 73 | using WebKit::WebMediaPlayer; |
| 74 | using WebKit::WebMediaPlayerClient; |
[email protected] | 613ba94c | 2013-03-08 14:14:31 | [diff] [blame] | 75 | using WebKit::WebPoint; |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 76 | using WebKit::WebRect; |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 77 | using WebKit::WebScriptSource; |
[email protected] | c272c5b | 2012-06-06 09:01:06 | [diff] [blame] | 78 | using WebKit::WebSize; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 79 | using WebKit::WebString; |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 80 | using WebKit::WebURL; |
[email protected] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 81 | using WebKit::WebURLError; |
[email protected] | 1afb9af | 2013-03-18 15:30:32 | [diff] [blame] | 82 | using WebKit::WebURLRequest; |
[email protected] | 435b763d | 2013-03-07 13:27:59 | [diff] [blame] | 83 | using WebKit::WebTestingSupport; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 84 | using WebKit::WebVector; |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 85 | using WebKit::WebView; |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 86 | using WebTestRunner::WebPreferences; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 87 | using WebTestRunner::WebTask; |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 88 | using WebTestRunner::WebTestInterfaces; |
[email protected] | 9063bf6 | 2013-02-20 19:42:01 | [diff] [blame] | 89 | using WebTestRunner::WebTestProxyBase; |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 90 | |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 91 | namespace content { |
| 92 | |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 93 | namespace { |
| 94 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 95 | void InvokeTaskHelper(void* context) { |
| 96 | WebTask* task = reinterpret_cast<WebTask*>(context); |
| 97 | task->run(); |
| 98 | delete task; |
| 99 | } |
| 100 | |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 101 | #if !defined(OS_MACOSX) |
| 102 | void MakeBitmapOpaque(SkBitmap* bitmap) { |
| 103 | SkAutoLockPixels lock(*bitmap); |
| 104 | DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config); |
| 105 | for (int y = 0; y < bitmap->height(); ++y) { |
| 106 | uint32_t* row = bitmap->getAddr32(0, y); |
| 107 | for (int x = 0; x < bitmap->width(); ++x) |
| 108 | row[x] |= 0xFF000000; // Set alpha bits to 1. |
| 109 | } |
| 110 | } |
| 111 | #endif |
| 112 | |
[email protected] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 113 | void CopyCanvasToBitmap(SkCanvas* canvas, SkBitmap* snapshot) { |
[email protected] | 9d611ca | 2012-11-14 13:46:56 | [diff] [blame] | 114 | SkDevice* device = skia::GetTopDevice(*canvas); |
[email protected] | 0799da0 | 2012-06-27 10:58:51 | [diff] [blame] | 115 | const SkBitmap& bitmap = device->accessBitmap(false); |
| 116 | bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config); |
| 117 | |
| 118 | #if !defined(OS_MACOSX) |
| 119 | // Only the expected PNGs for Mac have a valid alpha channel. |
| 120 | MakeBitmapOpaque(snapshot); |
| 121 | #endif |
| 122 | |
| 123 | } |
| 124 | |
[email protected] | f322356c | 2013-03-01 07:54:02 | [diff] [blame] | 125 | class SyncNavigationStateVisitor : public RenderViewVisitor { |
| 126 | public: |
| 127 | SyncNavigationStateVisitor() {} |
| 128 | virtual ~SyncNavigationStateVisitor() {} |
| 129 | |
| 130 | virtual bool Visit(RenderView* render_view) OVERRIDE { |
| 131 | SyncNavigationState(render_view); |
| 132 | return true; |
| 133 | } |
| 134 | private: |
| 135 | DISALLOW_COPY_AND_ASSIGN(SyncNavigationStateVisitor); |
| 136 | }; |
| 137 | |
[email protected] | 95026a0 | 2013-03-05 08:34:30 | [diff] [blame] | 138 | class ProxyToRenderViewVisitor : public RenderViewVisitor { |
| 139 | public: |
| 140 | explicit ProxyToRenderViewVisitor(WebTestProxyBase* proxy) |
| 141 | : proxy_(proxy), |
| 142 | render_view_(NULL) { |
| 143 | } |
| 144 | virtual ~ProxyToRenderViewVisitor() {} |
| 145 | |
| 146 | RenderView* render_view() const { return render_view_; } |
| 147 | |
| 148 | virtual bool Visit(RenderView* render_view) OVERRIDE { |
| 149 | WebKitTestRunner* test_runner = WebKitTestRunner::Get(render_view); |
| 150 | if (!test_runner) { |
| 151 | NOTREACHED(); |
| 152 | return true; |
| 153 | } |
| 154 | if (test_runner->proxy() == proxy_) { |
| 155 | render_view_ = render_view; |
| 156 | return false; |
| 157 | } |
| 158 | return true; |
| 159 | } |
| 160 | private: |
| 161 | WebTestProxyBase* proxy_; |
| 162 | RenderView* render_view_; |
| 163 | |
| 164 | DISALLOW_COPY_AND_ASSIGN(ProxyToRenderViewVisitor); |
| 165 | }; |
| 166 | |
[email protected] | 2aa9b7a | 2013-04-15 11:07:47 | [diff] [blame^] | 167 | class NavigateAwayVisitor : public RenderViewVisitor { |
| 168 | public: |
| 169 | NavigateAwayVisitor(RenderView* main_render_view) |
| 170 | : main_render_view_(main_render_view) {} |
| 171 | virtual ~NavigateAwayVisitor() {} |
| 172 | |
| 173 | virtual bool Visit(RenderView* render_view) OVERRIDE { |
| 174 | if (render_view == main_render_view_) |
| 175 | return true; |
| 176 | render_view->GetWebView()->mainFrame() |
| 177 | ->loadRequest(WebURLRequest(GURL("about:blank"))); |
| 178 | return true; |
| 179 | } |
| 180 | |
| 181 | private: |
| 182 | RenderView* main_render_view_; |
| 183 | |
| 184 | DISALLOW_COPY_AND_ASSIGN(NavigateAwayVisitor); |
| 185 | }; |
| 186 | |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 187 | } // namespace |
[email protected] | cccb5cf | 2012-06-06 22:20:04 | [diff] [blame] | 188 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 189 | WebKitTestRunner::WebKitTestRunner(RenderView* render_view) |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 190 | : RenderViewObserver(render_view), |
[email protected] | 2025a2f4 | 2013-02-18 07:25:41 | [diff] [blame] | 191 | RenderViewObserverTracker<WebKitTestRunner>(render_view), |
[email protected] | ab683b2 | 2013-03-04 09:10:31 | [diff] [blame] | 192 | proxy_(NULL), |
[email protected] | 95026a0 | 2013-03-05 08:34:30 | [diff] [blame] | 193 | focused_view_(NULL), |
[email protected] | 37d9dcce | 2013-03-22 22:27:45 | [diff] [blame] | 194 | is_main_window_(false), |
| 195 | focus_on_next_commit_(false) { |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 198 | WebKitTestRunner::~WebKitTestRunner() { |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 201 | // WebTestDelegate ----------------------------------------------------------- |
| 202 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 203 | void WebKitTestRunner::clearEditCommand() { |
| 204 | render_view()->ClearEditCommands(); |
| 205 | } |
| 206 | |
| 207 | void WebKitTestRunner::setEditCommand(const std::string& name, |
| 208 | const std::string& value) { |
| 209 | render_view()->SetEditCommandForNextKeyEvent(name, value); |
| 210 | } |
| 211 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 212 | void WebKitTestRunner::setGamepadData(const WebGamepads& gamepads) { |
[email protected] | e519692 | 2012-12-11 22:18:25 | [diff] [blame] | 213 | SetMockGamepads(gamepads); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void WebKitTestRunner::printMessage(const std::string& message) { |
| 217 | Send(new ShellViewHostMsg_PrintMessage(routing_id(), message)); |
| 218 | } |
| 219 | |
| 220 | void WebKitTestRunner::postTask(WebTask* task) { |
[email protected] | 2a58eb1 | 2012-12-18 07:56:40 | [diff] [blame] | 221 | Platform::current()->callOnMainThread(InvokeTaskHelper, task); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void WebKitTestRunner::postDelayedTask(WebTask* task, long long ms) { |
| 225 | MessageLoop::current()->PostDelayedTask( |
| 226 | FROM_HERE, |
| 227 | base::Bind(&WebTask::run, base::Owned(task)), |
| 228 | base::TimeDelta::FromMilliseconds(ms)); |
| 229 | } |
| 230 | |
| 231 | WebString WebKitTestRunner::registerIsolatedFileSystem( |
| 232 | const WebKit::WebVector<WebKit::WebString>& absolute_filenames) { |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 233 | std::vector<base::FilePath> files; |
[email protected] | 984a5f7 | 2012-12-13 21:41:50 | [diff] [blame] | 234 | for (size_t i = 0; i < absolute_filenames.size(); ++i) |
| 235 | files.push_back(webkit_base::WebStringToFilePath(absolute_filenames[i])); |
| 236 | std::string filesystem_id; |
| 237 | Send(new ShellViewHostMsg_RegisterIsolatedFileSystem( |
| 238 | routing_id(), files, &filesystem_id)); |
| 239 | return WebString::fromUTF8(filesystem_id); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | long long WebKitTestRunner::getCurrentTimeInMillisecond() { |
[email protected] | 2b035f3 | 2013-03-15 20:47:53 | [diff] [blame] | 243 | return base::TimeDelta(base::Time::Now() - |
| 244 | base::Time::UnixEpoch()).ToInternalValue() / |
| 245 | base::Time::kMicrosecondsPerMillisecond; |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path( |
| 249 | const std::string& utf8_path) { |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 250 | #if defined(OS_WIN) |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 251 | base::FilePath path(UTF8ToWide(utf8_path)); |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 252 | #else |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 253 | base::FilePath path(base::SysWideToNativeMB(base::SysUTF8ToWide(utf8_path))); |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 254 | #endif |
| 255 | if (!path.IsAbsolute()) { |
| 256 | GURL base_url = |
[email protected] | 38c1555c6 | 2013-03-16 19:20:55 | [diff] [blame] | 257 | net::FilePathToFileURL(test_config_.current_working_directory.Append( |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 258 | FILE_PATH_LITERAL("foo"))); |
| 259 | net::FileURLToFilePath(base_url.Resolve(utf8_path), &path); |
| 260 | } |
[email protected] | 984a5f7 | 2012-12-13 21:41:50 | [diff] [blame] | 261 | return webkit_base::FilePathToWebString(path); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 264 | WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) { |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 265 | base::FilePath local_path; |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 266 | if (!net::FileURLToFilePath(file_url, &local_path)) |
| 267 | return WebURL(); |
| 268 | |
| 269 | std::string contents; |
| 270 | Send(new ShellViewHostMsg_ReadFileToString( |
| 271 | routing_id(), local_path, &contents)); |
| 272 | |
| 273 | std::string contents_base64; |
| 274 | if (!base::Base64Encode(contents, &contents_base64)) |
| 275 | return WebURL(); |
| 276 | |
| 277 | const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,"; |
| 278 | return WebURL(GURL(data_url_prefix + contents_base64)); |
| 279 | } |
| 280 | |
| 281 | WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) { |
| 282 | const char kPrefix[] = "file:///tmp/LayoutTests/"; |
| 283 | const int kPrefixLen = arraysize(kPrefix) - 1; |
| 284 | |
| 285 | if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen)) |
| 286 | return WebURL(GURL(utf8_url)); |
| 287 | |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 288 | base::FilePath replace_path = |
[email protected] | 09ec9f9 | 2012-12-17 09:46:36 | [diff] [blame] | 289 | ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append( |
| 290 | FILE_PATH_LITERAL("LayoutTests/")); |
| 291 | #if defined(OS_WIN) |
| 292 | std::string utf8_path = WideToUTF8(replace_path.value()); |
| 293 | #else |
| 294 | std::string utf8_path = |
| 295 | WideToUTF8(base::SysNativeMBToWide(replace_path.value())); |
| 296 | #endif |
| 297 | std::string new_url = |
| 298 | std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen); |
| 299 | return WebURL(GURL(new_url)); |
| 300 | } |
| 301 | |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 302 | WebPreferences* WebKitTestRunner::preferences() { |
| 303 | return &prefs_; |
| 304 | } |
| 305 | |
| 306 | void WebKitTestRunner::applyPreferences() { |
| 307 | webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); |
[email protected] | d48eab08 | 2012-12-19 09:25:47 | [diff] [blame] | 308 | ExportLayoutTestSpecificPreferences(prefs_, &prefs); |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 309 | render_view()->SetWebkitPreferences(prefs); |
[email protected] | 55915a7 | 2012-12-18 11:55:25 | [diff] [blame] | 310 | Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs)); |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 311 | } |
| 312 | |
[email protected] | 9d9ec98 | 2013-01-10 18:53:39 | [diff] [blame] | 313 | std::string WebKitTestRunner::makeURLErrorDescription( |
| 314 | const WebURLError& error) { |
| 315 | std::string domain = error.domain.utf8(); |
| 316 | int code = error.reason; |
| 317 | |
| 318 | if (domain == net::kErrorDomain) { |
| 319 | domain = "NSURLErrorDomain"; |
| 320 | switch (error.reason) { |
| 321 | case net::ERR_ABORTED: |
| 322 | code = -999; // NSURLErrorCancelled |
| 323 | break; |
| 324 | case net::ERR_UNSAFE_PORT: |
| 325 | // Our unsafe port checking happens at the network stack level, but we |
| 326 | // make this translation here to match the behavior of stock WebKit. |
| 327 | domain = "WebKitErrorDomain"; |
| 328 | code = 103; |
| 329 | break; |
| 330 | case net::ERR_ADDRESS_INVALID: |
| 331 | case net::ERR_ADDRESS_UNREACHABLE: |
| 332 | case net::ERR_NETWORK_ACCESS_DENIED: |
| 333 | code = -1004; // NSURLErrorCannotConnectToHost |
| 334 | break; |
| 335 | } |
| 336 | } else { |
| 337 | DLOG(WARNING) << "Unknown error domain"; |
| 338 | } |
| 339 | |
| 340 | return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">", |
| 341 | domain.c_str(), code, error.unreachableURL.spec().data()); |
| 342 | } |
| 343 | |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 344 | void WebKitTestRunner::setClientWindowRect(const WebRect& rect) { |
[email protected] | 8be1c58 | 2013-03-06 00:55:03 | [diff] [blame] | 345 | ForceResizeRenderView(render_view(), WebSize(rect.width, rect.height)); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void WebKitTestRunner::showDevTools() { |
[email protected] | f85c584 | 2013-02-15 14:15:06 | [diff] [blame] | 349 | Send(new ShellViewHostMsg_ShowDevTools(routing_id())); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | void WebKitTestRunner::closeDevTools() { |
[email protected] | f85c584 | 2013-02-15 14:15:06 | [diff] [blame] | 353 | Send(new ShellViewHostMsg_CloseDevTools(routing_id())); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void WebKitTestRunner::evaluateInWebInspector(long call_id, |
| 357 | const std::string& script) { |
[email protected] | f85c584 | 2013-02-15 14:15:06 | [diff] [blame] | 358 | WebDevToolsAgent* agent = render_view()->GetWebView()->devToolsAgent(); |
| 359 | if (agent) |
| 360 | agent->evaluateInWebInspector(call_id, WebString::fromUTF8(script)); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | void WebKitTestRunner::clearAllDatabases() { |
[email protected] | 833b700d | 2013-02-18 19:43:00 | [diff] [blame] | 364 | Send(new ShellViewHostMsg_ClearAllDatabases(routing_id())); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void WebKitTestRunner::setDatabaseQuota(int quota) { |
[email protected] | 833b700d | 2013-02-18 19:43:00 | [diff] [blame] | 368 | Send(new ShellViewHostMsg_SetDatabaseQuota(routing_id(), quota)); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | void WebKitTestRunner::setDeviceScaleFactor(float factor) { |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 372 | SetDeviceScaleFactor(render_view(), factor); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 373 | } |
| 374 | |
[email protected] | 83654ec | 2013-03-04 15:58:53 | [diff] [blame] | 375 | void WebKitTestRunner::setFocus(WebTestProxyBase* proxy, bool focus) { |
[email protected] | 95026a0 | 2013-03-05 08:34:30 | [diff] [blame] | 376 | ProxyToRenderViewVisitor visitor(proxy); |
| 377 | RenderView::ForEach(&visitor); |
| 378 | if (!visitor.render_view()) { |
| 379 | NOTREACHED(); |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | // Check whether the focused view was closed meanwhile. |
| 384 | if (!WebKitTestRunner::Get(focused_view_)) |
| 385 | focused_view_ = NULL; |
| 386 | |
| 387 | if (focus) { |
| 388 | if (focused_view_ != visitor.render_view()) { |
| 389 | if (focused_view_) |
| 390 | SetFocusAndActivate(focused_view_, false); |
| 391 | SetFocusAndActivate(visitor.render_view(), true); |
| 392 | focused_view_ = visitor.render_view(); |
| 393 | } |
| 394 | } else { |
| 395 | if (focused_view_ == visitor.render_view()) { |
| 396 | SetFocusAndActivate(visitor.render_view(), false); |
| 397 | focused_view_ = NULL; |
| 398 | } |
| 399 | } |
[email protected] | 83654ec | 2013-03-04 15:58:53 | [diff] [blame] | 400 | } |
| 401 | |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 402 | void WebKitTestRunner::setAcceptAllCookies(bool accept) { |
[email protected] | 833b700d | 2013-02-18 19:43:00 | [diff] [blame] | 403 | Send(new ShellViewHostMsg_AcceptAllCookies(routing_id(), accept)); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | std::string WebKitTestRunner::pathToLocalResource(const std::string& resource) { |
[email protected] | 0c5f222 | 2013-02-20 11:26:19 | [diff] [blame] | 407 | #if defined(OS_WIN) |
| 408 | if (resource.find("/tmp/") == 0) { |
| 409 | // We want a temp file. |
[email protected] | 38c1555c6 | 2013-03-16 19:20:55 | [diff] [blame] | 410 | GURL base_url = net::FilePathToFileURL(test_config_.temp_path); |
[email protected] | 0c5f222 | 2013-02-20 11:26:19 | [diff] [blame] | 411 | return base_url.Resolve(resource.substr(strlen("/tmp/"))).spec(); |
| 412 | } |
| 413 | #endif |
| 414 | |
| 415 | // Some layout tests use file://// which we resolve as a UNC path. Normalize |
| 416 | // them to just file:///. |
| 417 | std::string result = resource; |
| 418 | while (StringToLowerASCII(result).find("file:////") == 0) { |
| 419 | result = result.substr(0, strlen("file:///")) + |
| 420 | result.substr(strlen("file:////")); |
| 421 | } |
| 422 | return rewriteLayoutTestsURL(result).spec(); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void WebKitTestRunner::setLocale(const std::string& locale) { |
[email protected] | 833b700d | 2013-02-18 19:43:00 | [diff] [blame] | 426 | setlocale(LC_ALL, locale.c_str()); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 427 | } |
| 428 | |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 429 | void WebKitTestRunner::testFinished() { |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 430 | if (!is_main_window_) { |
| 431 | Send(new ShellViewHostMsg_TestFinishedInSecondaryWindow(routing_id())); |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 432 | return; |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 433 | } |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 434 | WebTestInterfaces* interfaces = |
| 435 | ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 436 | interfaces->setTestIsRunning(false); |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 437 | if (interfaces->testRunner()->shouldDumpBackForwardList()) { |
[email protected] | f322356c | 2013-03-01 07:54:02 | [diff] [blame] | 438 | SyncNavigationStateVisitor visitor; |
| 439 | RenderView::ForEach(&visitor); |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 440 | Send(new ShellViewHostMsg_CaptureSessionHistory(routing_id())); |
| 441 | } else { |
| 442 | CaptureDump(); |
| 443 | } |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void WebKitTestRunner::testTimedOut() { |
[email protected] | d679c86 | 2013-03-07 10:31:41 | [diff] [blame] | 447 | if (!is_main_window_) |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 448 | return; |
| 449 | WebTestInterfaces* interfaces = |
| 450 | ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 451 | interfaces->setTestIsRunning(false); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 452 | Send(new ShellViewHostMsg_TestFinished(routing_id(), true)); |
| 453 | } |
| 454 | |
| 455 | bool WebKitTestRunner::isBeingDebugged() { |
| 456 | return base::debug::BeingDebugged(); |
| 457 | } |
| 458 | |
| 459 | int WebKitTestRunner::layoutTestTimeout() { |
[email protected] | 4f92df8 | 2013-03-07 13:21:13 | [diff] [blame] | 460 | return test_config_.layout_test_timeout; |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void WebKitTestRunner::closeRemainingWindows() { |
[email protected] | 2aa9b7a | 2013-04-15 11:07:47 | [diff] [blame^] | 464 | NavigateAwayVisitor visitor(render_view()); |
| 465 | RenderView::ForEach(&visitor); |
[email protected] | b778e18 | 2013-03-04 13:32:16 | [diff] [blame] | 466 | Send(new ShellViewHostMsg_CloseRemainingWindows(routing_id())); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | int WebKitTestRunner::navigationEntryCount() { |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 470 | return GetLocalSessionHistoryLength(render_view()); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 471 | } |
| 472 | |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 473 | void WebKitTestRunner::goToOffset(int offset) { |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 474 | Send(new ShellViewHostMsg_GoToOffset(routing_id(), offset)); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | void WebKitTestRunner::reload() { |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 478 | Send(new ShellViewHostMsg_Reload(routing_id())); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | void WebKitTestRunner::loadURLForFrame(const WebURL& url, |
| 482 | const std::string& frame_name) { |
[email protected] | d2494ff | 2013-02-20 08:22:37 | [diff] [blame] | 483 | Send(new ShellViewHostMsg_LoadURLForFrame( |
| 484 | routing_id(), url, frame_name)); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | bool WebKitTestRunner::allowExternalPages() { |
[email protected] | 4f92df8 | 2013-03-07 13:21:13 | [diff] [blame] | 488 | return test_config_.allow_external_pages; |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | void WebKitTestRunner::captureHistoryForWindow( |
[email protected] | 9063bf6 | 2013-02-20 19:42:01 | [diff] [blame] | 492 | WebTestProxyBase* proxy, |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 493 | WebVector<WebKit::WebHistoryItem>* history, |
| 494 | size_t* currentEntryIndex) { |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 495 | size_t pos = 0; |
| 496 | std::vector<int>::iterator id; |
| 497 | for (id = routing_ids_.begin(); id != routing_ids_.end(); ++id, ++pos) { |
| 498 | RenderView* render_view = RenderView::FromRoutingID(*id); |
| 499 | if (!render_view) { |
| 500 | NOTREACHED(); |
| 501 | continue; |
| 502 | } |
| 503 | if (WebKitTestRunner::Get(render_view)->proxy() == proxy) |
| 504 | break; |
| 505 | } |
| 506 | |
| 507 | if (id == routing_ids_.end()) { |
| 508 | NOTREACHED(); |
| 509 | return; |
| 510 | } |
| 511 | size_t num_entries = session_histories_[pos].size(); |
| 512 | *currentEntryIndex = current_entry_indexes_[pos]; |
| 513 | WebVector<WebHistoryItem> result(num_entries); |
| 514 | for (size_t entry = 0; entry < num_entries; ++entry) { |
| 515 | result[entry] = |
| 516 | webkit_glue::HistoryItemFromString(session_histories_[pos][entry]); |
| 517 | } |
| 518 | history->swap(result); |
[email protected] | 29e8270 | 2013-02-14 12:56:40 | [diff] [blame] | 519 | } |
| 520 | |
[email protected] | 321d9eb | 2013-04-04 18:25:26 | [diff] [blame] | 521 | WebMediaPlayer* WebKitTestRunner::createWebMediaPlayer( |
| 522 | WebFrame* frame, const WebURL& url, WebMediaPlayerClient* client) |
| 523 | { |
| 524 | if (!test_media_stream_client_.get()) { |
| 525 | test_media_stream_client_.reset( |
| 526 | new webkit_glue::TestMediaStreamClient()); |
| 527 | } |
| 528 | return webkit_glue::CreateMediaPlayer( |
| 529 | frame, url, client, test_media_stream_client_.get()); |
| 530 | } |
| 531 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 532 | // RenderViewObserver -------------------------------------------------------- |
| 533 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 534 | void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) { |
[email protected] | 435b763d | 2013-03-07 13:27:59 | [diff] [blame] | 535 | WebTestingSupport::injectInternalsObject(frame); |
| 536 | ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame); |
[email protected] | 96b80b47 | 2012-07-03 19:41:56 | [diff] [blame] | 537 | } |
| 538 | |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 539 | bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 540 | bool handled = true; |
[email protected] | 9b4c6cd | 2012-08-20 10:47:45 | [diff] [blame] | 541 | IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message) |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 542 | IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration, |
| 543 | OnSetTestConfiguration) |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 544 | IPC_MESSAGE_HANDLER(ShellViewMsg_SessionHistory, OnSessionHistory) |
[email protected] | 1afb9af | 2013-03-18 15:30:32 | [diff] [blame] | 545 | IPC_MESSAGE_HANDLER(ShellViewMsg_Reset, OnReset) |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 546 | IPC_MESSAGE_HANDLER(ShellViewMsg_NotifyDone, OnNotifyDone) |
[email protected] | efb5f57 | 2012-01-29 10:57:33 | [diff] [blame] | 547 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 548 | IPC_END_MESSAGE_MAP() |
| 549 | |
| 550 | return handled; |
| 551 | } |
| 552 | |
[email protected] | 37d9dcce | 2013-03-22 22:27:45 | [diff] [blame] | 553 | void WebKitTestRunner::Navigate(const GURL& url) { |
| 554 | focus_on_next_commit_ = true; |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 555 | if (!is_main_window_ && |
| 556 | ShellRenderProcessObserver::GetInstance()->main_test_runner() == this) { |
| 557 | WebTestInterfaces* interfaces = |
| 558 | ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 559 | interfaces->setTestIsRunning(true); |
| 560 | interfaces->configureForTestWithURL(GURL(), false); |
| 561 | } |
[email protected] | 37d9dcce | 2013-03-22 22:27:45 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | void WebKitTestRunner::DidCommitProvisionalLoad(WebFrame* frame, |
| 565 | bool is_new_navigation) { |
| 566 | if (!focus_on_next_commit_) |
| 567 | return; |
| 568 | focus_on_next_commit_ = false; |
| 569 | render_view()->GetWebView()->setFocusedFrame(frame); |
| 570 | } |
| 571 | |
| 572 | void WebKitTestRunner::DidFailProvisionalLoad(WebFrame* frame, |
| 573 | const WebURLError& error) { |
| 574 | focus_on_next_commit_ = false; |
| 575 | } |
| 576 | |
[email protected] | b9fad24c | 2012-11-15 08:22:10 | [diff] [blame] | 577 | // Public methods - ----------------------------------------------------------- |
| 578 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 579 | void WebKitTestRunner::Reset() { |
[email protected] | ab683b2 | 2013-03-04 09:10:31 | [diff] [blame] | 580 | // The proxy_ is always non-NULL, it is set right after construction. |
| 581 | proxy_->reset(); |
[email protected] | b3dbcb5e | 2012-12-17 00:16:37 | [diff] [blame] | 582 | prefs_.reset(); |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 583 | routing_ids_.clear(); |
| 584 | session_histories_.clear(); |
| 585 | current_entry_indexes_.clear(); |
[email protected] | 613ba94c | 2013-03-08 14:14:31 | [diff] [blame] | 586 | |
| 587 | render_view()->ClearEditCommands(); |
| 588 | render_view()->GetWebView()->mainFrame()->setName(WebString()); |
| 589 | render_view()->GetWebView()->mainFrame()->clearOpener(); |
[email protected] | e8f35bc | 2013-03-18 15:22:01 | [diff] [blame] | 590 | render_view()->GetWebView()->setPageScaleFactorLimits(-1, -1); |
[email protected] | 613ba94c | 2013-03-08 14:14:31 | [diff] [blame] | 591 | render_view()->GetWebView()->setPageScaleFactor(1, WebPoint(0, 0)); |
| 592 | render_view()->GetWebView()->enableFixedLayoutMode(false); |
| 593 | render_view()->GetWebView()->setFixedLayoutSize(WebSize(0, 0)); |
| 594 | |
[email protected] | 435b763d | 2013-03-07 13:27:59 | [diff] [blame] | 595 | // Resetting the internals object also overrides the WebPreferences, so we |
| 596 | // have to sync them to WebKit again. |
| 597 | WebTestingSupport::resetInternalsObject( |
| 598 | render_view()->GetWebView()->mainFrame()); |
| 599 | render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences()); |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 600 | } |
| 601 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 602 | // Private methods ----------------------------------------------------------- |
| 603 | |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 604 | void WebKitTestRunner::CaptureDump() { |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 605 | WebTestInterfaces* interfaces = |
| 606 | ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 607 | |
[email protected] | 893fc636 | 2013-02-18 13:24:05 | [diff] [blame] | 608 | if (interfaces->testRunner()->shouldDumpAsAudio()) { |
| 609 | const WebArrayBufferView* audio_data = |
| 610 | interfaces->testRunner()->audioData(); |
| 611 | std::vector<unsigned char> vector_data( |
| 612 | static_cast<const unsigned char*>(audio_data->baseAddress()), |
| 613 | static_cast<const unsigned char*>(audio_data->baseAddress()) + |
| 614 | audio_data->byteLength()); |
| 615 | Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data)); |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 616 | } else { |
| 617 | Send(new ShellViewHostMsg_TextDump(routing_id(), |
| 618 | proxy()->captureTree(false))); |
[email protected] | 893fc636 | 2013-02-18 13:24:05 | [diff] [blame] | 619 | |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 620 | if (test_config_.enable_pixel_dumping && |
| 621 | interfaces->testRunner()->shouldGeneratePixelResults()) { |
| 622 | SkBitmap snapshot; |
| 623 | CopyCanvasToBitmap(proxy()->capturePixels(), &snapshot); |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 624 | |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 625 | SkAutoLockPixels snapshot_lock(snapshot); |
| 626 | base::MD5Digest digest; |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 627 | #if defined(OS_ANDROID) |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 628 | // On Android, pixel layout is RGBA, however, other Chrome platforms use |
| 629 | // BGRA. |
| 630 | const uint8_t* raw_pixels = |
| 631 | reinterpret_cast<const uint8_t*>(snapshot.getPixels()); |
| 632 | size_t snapshot_size = snapshot.getSize(); |
[email protected] | 4ddc0c9 | 2013-04-11 02:09:42 | [diff] [blame] | 633 | scoped_ptr<uint8_t[]> reordered_pixels(new uint8_t[snapshot_size]); |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 634 | for (size_t i = 0; i < snapshot_size; i += 4) { |
| 635 | reordered_pixels[i] = raw_pixels[i + 2]; |
| 636 | reordered_pixels[i + 1] = raw_pixels[i + 1]; |
| 637 | reordered_pixels[i + 2] = raw_pixels[i]; |
| 638 | reordered_pixels[i + 3] = raw_pixels[i + 3]; |
| 639 | } |
| 640 | base::MD5Sum(reordered_pixels.get(), snapshot_size, &digest); |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 641 | #else |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 642 | base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest); |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 643 | #endif |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 644 | std::string actual_pixel_hash = base::MD5DigestToBase16(digest); |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 645 | |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 646 | if (actual_pixel_hash == test_config_.expected_pixel_hash) { |
| 647 | SkBitmap empty_image; |
| 648 | Send(new ShellViewHostMsg_ImageDump( |
| 649 | routing_id(), actual_pixel_hash, empty_image)); |
| 650 | } else { |
| 651 | Send(new ShellViewHostMsg_ImageDump( |
| 652 | routing_id(), actual_pixel_hash, snapshot)); |
| 653 | } |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 654 | } |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 655 | } |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 656 | |
[email protected] | 6d74fab | 2013-03-20 15:47:33 | [diff] [blame] | 657 | MessageLoop::current()->PostTask( |
| 658 | FROM_HERE, |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 659 | base::Bind(base::IgnoreResult(&WebKitTestRunner::Send), |
| 660 | base::Unretained(this), |
| 661 | new ShellViewHostMsg_TestFinished(routing_id(), false))); |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 662 | } |
| 663 | |
[email protected] | 0ac1a03 | 2013-02-12 12:53:37 | [diff] [blame] | 664 | void WebKitTestRunner::OnSetTestConfiguration( |
[email protected] | 4f92df8 | 2013-03-07 13:21:13 | [diff] [blame] | 665 | const ShellTestConfiguration& params) { |
| 666 | test_config_ = params; |
[email protected] | 5f20df36 | 2013-02-15 19:48:19 | [diff] [blame] | 667 | is_main_window_ = true; |
[email protected] | d679c86 | 2013-03-07 10:31:41 | [diff] [blame] | 668 | |
| 669 | setFocus(proxy_, true); |
| 670 | |
| 671 | WebTestInterfaces* interfaces = |
| 672 | ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 673 | interfaces->setTestIsRunning(true); |
[email protected] | 4f92df8 | 2013-03-07 13:21:13 | [diff] [blame] | 674 | interfaces->configureForTestWithURL(params.test_url, |
| 675 | params.enable_pixel_dumping); |
[email protected] | 0d2dfb92d | 2012-11-05 10:26:45 | [diff] [blame] | 676 | } |
| 677 | |
[email protected] | 8f72269 | 2013-02-23 14:14:06 | [diff] [blame] | 678 | void WebKitTestRunner::OnSessionHistory( |
| 679 | const std::vector<int>& routing_ids, |
| 680 | const std::vector<std::vector<std::string> >& session_histories, |
| 681 | const std::vector<unsigned>& current_entry_indexes) { |
| 682 | routing_ids_ = routing_ids; |
| 683 | session_histories_ = session_histories; |
| 684 | current_entry_indexes_ = current_entry_indexes; |
| 685 | CaptureDump(); |
| 686 | } |
| 687 | |
[email protected] | 1afb9af | 2013-03-18 15:30:32 | [diff] [blame] | 688 | void WebKitTestRunner::OnReset() { |
[email protected] | 7e8c896 | 2013-03-25 14:32:48 | [diff] [blame] | 689 | ShellRenderProcessObserver::GetInstance()->test_interfaces()->resetAll(); |
| 690 | Reset(); |
[email protected] | 8b68e2bd | 2013-03-23 02:49:05 | [diff] [blame] | 691 | // Navigating to about:blank will make sure that no new loads are initiated |
| 692 | // by the renderer. |
| 693 | render_view()->GetWebView()->mainFrame() |
| 694 | ->loadRequest(WebURLRequest(GURL("about:blank"))); |
[email protected] | 1afb9af | 2013-03-18 15:30:32 | [diff] [blame] | 695 | Send(new ShellViewHostMsg_ResetDone(routing_id())); |
| 696 | } |
| 697 | |
[email protected] | 1ca4fac | 2013-04-08 14:15:11 | [diff] [blame] | 698 | void WebKitTestRunner::OnNotifyDone() { |
| 699 | render_view()->GetWebView()->mainFrame()->executeScript( |
| 700 | WebScriptSource(WebString::fromUTF8("testRunner.notifyDone();"))); |
| 701 | } |
| 702 | |
[email protected] | 31d71b0 | 2012-01-26 03:42:31 | [diff] [blame] | 703 | } // namespace content |