| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/renderer/layout_test/blink_test_runner.h" | 5 #include "content/shell/renderer/layout_test/blink_test_runner.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <clocale> | 10 #include <clocale> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 int session_id) override {} | 196 int session_id) override {} |
| 197 void Start() override {} | 197 void Start() override {} |
| 198 void Stop() override {} | 198 void Stop() override {} |
| 199 void SetVolume(double volume) override {} | 199 void SetVolume(double volume) override {} |
| 200 void SetAutomaticGainControl(bool enable) override {} | 200 void SetAutomaticGainControl(bool enable) override {} |
| 201 | 201 |
| 202 protected: | 202 protected: |
| 203 ~MockAudioCapturerSource() override {} | 203 ~MockAudioCapturerSource() override {} |
| 204 }; | 204 }; |
| 205 | 205 |
| 206 // Tests in web-platform-tests use absolute path links such as |
| 207 // <script src="/resources/testharness.js">. |
| 208 // Because we load the tests as local files, such links don't work. |
| 209 // This function fixes this issue by rewriting file: URLs which were produced |
| 210 // from such links so that they point actual files in wpt/. |
| 211 WebURL RewriteAbsolutePathInWPT(const std::string& utf8_url) { |
| 212 const char kFileScheme[] = "file:///"; |
| 213 const int kFileSchemeLen = arraysize(kFileScheme) - 1; |
| 214 if (utf8_url.compare(0, kFileSchemeLen, kFileScheme, kFileSchemeLen) != 0) |
| 215 return WebURL(); |
| 216 #if defined(OS_WIN) |
| 217 // +3 for a drive letter, :, and /. |
| 218 const int kFileSchemeAndDriveLen = kFileSchemeLen + 3; |
| 219 if (utf8_url.size() <= kFileSchemeAndDriveLen) |
| 220 return WebURL(); |
| 221 std::string path = utf8_url.substr(kFileSchemeAndDriveLen); |
| 222 #else |
| 223 std::string path = utf8_url.substr(kFileSchemeLen); |
| 224 #endif |
| 225 // LayoutTests use file: URLs in various ways. |
| 226 // - The magic URL prefix "file:///tmp/LayoutTests/" to access file: |
| 227 // resources from http resources. |
| 228 // - $TMP to download a blob URL |
| 229 // - out/$CONFIG/gen/ and third_party/WebKit/Source/devtools to load |
| 230 // DevTools code. |
| 231 // We rewite only a few patterns used in web-platform-tests to avoid to |
| 232 // rewrite non-WPT URLs. We can remove this hack if we run all WPT tests |
| 233 // with wptserve. |
| 234 if (base::StartsWith(path, "common/", base::CompareCase::SENSITIVE) || |
| 235 base::StartsWith(path, "images/", base::CompareCase::SENSITIVE) || |
| 236 base::StartsWith(path, "media/", base::CompareCase::SENSITIVE) || |
| 237 base::StartsWith(path, "resources/", base::CompareCase::SENSITIVE)) { |
| 238 base::FilePath new_path = |
| 239 LayoutTestRenderThreadObserver::GetInstance() |
| 240 ->webkit_source_dir() |
| 241 .Append(FILE_PATH_LITERAL("LayoutTests/imported/wpt/")) |
| 242 .AppendASCII(path); |
| 243 return WebURL(net::FilePathToFileURL(new_path)); |
| 244 } |
| 245 return WebURL(); |
| 246 } |
| 247 |
| 206 } // namespace | 248 } // namespace |
| 207 | 249 |
| 208 BlinkTestRunner::BlinkTestRunner(RenderView* render_view) | 250 BlinkTestRunner::BlinkTestRunner(RenderView* render_view) |
| 209 : RenderViewObserver(render_view), | 251 : RenderViewObserver(render_view), |
| 210 RenderViewObserverTracker<BlinkTestRunner>(render_view), | 252 RenderViewObserverTracker<BlinkTestRunner>(render_view), |
| 211 is_main_window_(false), | 253 is_main_window_(false), |
| 212 focus_on_next_commit_(false), | 254 focus_on_next_commit_(false), |
| 213 leak_detector_(new LeakDetector(this)) { | 255 leak_detector_(new LeakDetector(this)) { |
| 214 } | 256 } |
| 215 | 257 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 routing_id(), local_path, &contents)); | 343 routing_id(), local_path, &contents)); |
| 302 | 344 |
| 303 std::string contents_base64; | 345 std::string contents_base64; |
| 304 base::Base64Encode(contents, &contents_base64); | 346 base::Base64Encode(contents, &contents_base64); |
| 305 | 347 |
| 306 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,"; | 348 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,"; |
| 307 return WebURL(GURL(data_url_prefix + contents_base64)); | 349 return WebURL(GURL(data_url_prefix + contents_base64)); |
| 308 } | 350 } |
| 309 | 351 |
| 310 WebURL BlinkTestRunner::RewriteLayoutTestsURL(const std::string& utf8_url) { | 352 WebURL BlinkTestRunner::RewriteLayoutTestsURL(const std::string& utf8_url) { |
| 353 WebURL rewritten_url = RewriteAbsolutePathInWPT(utf8_url); |
| 354 if (!rewritten_url.isEmpty()) |
| 355 return rewritten_url; |
| 356 |
| 311 const char kPrefix[] = "file:///tmp/LayoutTests/"; | 357 const char kPrefix[] = "file:///tmp/LayoutTests/"; |
| 312 const int kPrefixLen = arraysize(kPrefix) - 1; | 358 const int kPrefixLen = arraysize(kPrefix) - 1; |
| 313 | 359 |
| 314 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen)) | 360 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen)) |
| 315 return WebURL(GURL(utf8_url)); | 361 return WebURL(GURL(utf8_url)); |
| 316 | 362 |
| 317 base::FilePath replace_path = | 363 base::FilePath replace_path = |
| 318 LayoutTestRenderThreadObserver::GetInstance()->webkit_source_dir() | 364 LayoutTestRenderThreadObserver::GetInstance()->webkit_source_dir() |
| 319 .Append(FILE_PATH_LITERAL("LayoutTests/")); | 365 .Append(FILE_PATH_LITERAL("LayoutTests/")); |
| 320 #if defined(OS_WIN) | 366 #if defined(OS_WIN) |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 get_bluetooth_events_callbacks_.pop_front(); | 999 get_bluetooth_events_callbacks_.pop_front(); |
| 954 callback.Run(events); | 1000 callback.Run(events); |
| 955 } | 1001 } |
| 956 | 1002 |
| 957 void BlinkTestRunner::ReportLeakDetectionResult( | 1003 void BlinkTestRunner::ReportLeakDetectionResult( |
| 958 const LeakDetectionResult& report) { | 1004 const LeakDetectionResult& report) { |
| 959 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); | 1005 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); |
| 960 } | 1006 } |
| 961 | 1007 |
| 962 } // namespace content | 1008 } // namespace content |
| OLD | NEW |