Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: content/shell/renderer/layout_test/blink_test_runner.cc

Issue 1984103003: content_shell: Redirect resource requests for some local paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/forms/autocapitalize.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <cmath> 11 #include <cmath>
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/base64.h" 15 #include "base/base64.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/debug/debugger.h" 18 #include "base/debug/debugger.h"
19 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
20 #include "base/files/file_util.h"
20 #include "base/location.h" 21 #include "base/location.h"
21 #include "base/macros.h" 22 #include "base/macros.h"
22 #include "base/md5.h" 23 #include "base/md5.h"
23 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
24 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
25 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
26 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
27 #include "base/strings/sys_string_conversions.h" 28 #include "base/strings/sys_string_conversions.h"
28 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
29 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 int session_id) override {} 197 int session_id) override {}
197 void Start() override {} 198 void Start() override {}
198 void Stop() override {} 199 void Stop() override {}
199 void SetVolume(double volume) override {} 200 void SetVolume(double volume) override {}
200 void SetAutomaticGainControl(bool enable) override {} 201 void SetAutomaticGainControl(bool enable) override {}
201 202
202 protected: 203 protected:
203 ~MockAudioCapturerSource() override {} 204 ~MockAudioCapturerSource() override {}
204 }; 205 };
205 206
207 WebURL RewriteAbsolutePathInWPT(const std::string& utf8_url) {
qyearsley 2016/05/18 17:26:56 The main reason for this is so that we don't have
tkent 2016/05/20 01:00:30 Done.
208 const char kFileScheme[] = "file:///";
209 const int kFileSchemeLen = arraysize(kFileScheme) - 1;
210 if (utf8_url.compare(0, kFileSchemeLen, kFileScheme, kFileSchemeLen) != 0)
211 return WebURL();
212 #if defined(OS_WIN)
213 // +3 for a drive letter, :, and /.
214 const int kFileSchemeAndDriveLen = kFileSchemeLen + 3;
215 if (utf8_url.size() <= kFileSchemeAndDriveLen)
216 return WebURL();
217 std::string path = utf8_url.substr(kFileSchemeAndDriveLen);
218 #else
219 std::string path = utf8_url.substr(kFileSchemeLen);
220 #endif
221 // LayoutTests use file: URLs in various ways.
222 // - The magic URL prefix "file:///tmp/LayoutTests/" to access file:
223 // resources from http resources.
224 // - $TMP to download a blob URL
225 // - out/$CONFIG/gen/ and third_party/WebKit/Source/devtools to load
226 // DevTools code.
227 // We rewite only a few patterns used in web-platform-tests because this is
228 // a short-teram workaround. We can remove this hack when we start to run
qyearsley 2016/05/18 17:26:56 short-term
tkent 2016/05/20 01:00:30 Removed.
229 // all WPT tests with wptserve.
qyearsley 2016/05/18 17:26:56 Although, we may want to still want to have most t
tkent 2016/05/20 01:00:30 I updated the comment.
230 if (base::StartsWith(path, "common/", base::CompareCase::SENSITIVE) ||
231 base::StartsWith(path, "images/", base::CompareCase::SENSITIVE) ||
232 base::StartsWith(path, "media/", base::CompareCase::SENSITIVE) ||
233 base::StartsWith(path, "resources/", base::CompareCase::SENSITIVE)) {
234 // TODO(tkent): web-platform-tests -> wpt when the renaming is completed.
235 base::FilePath new_path =
236 LayoutTestRenderThreadObserver::GetInstance()
237 ->webkit_source_dir()
238 .Append(
239 FILE_PATH_LITERAL("LayoutTests/imported/web-platform-tests/"))
240 .AppendASCII(path);
241 return WebURL(net::FilePathToFileURL(new_path));
242 }
243 return WebURL();
244 }
245
206 } // namespace 246 } // namespace
207 247
208 BlinkTestRunner::BlinkTestRunner(RenderView* render_view) 248 BlinkTestRunner::BlinkTestRunner(RenderView* render_view)
209 : RenderViewObserver(render_view), 249 : RenderViewObserver(render_view),
210 RenderViewObserverTracker<BlinkTestRunner>(render_view), 250 RenderViewObserverTracker<BlinkTestRunner>(render_view),
211 is_main_window_(false), 251 is_main_window_(false),
212 focus_on_next_commit_(false), 252 focus_on_next_commit_(false),
213 leak_detector_(new LeakDetector(this)) { 253 leak_detector_(new LeakDetector(this)) {
214 } 254 }
215 255
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 routing_id(), local_path, &contents)); 341 routing_id(), local_path, &contents));
302 342
303 std::string contents_base64; 343 std::string contents_base64;
304 base::Base64Encode(contents, &contents_base64); 344 base::Base64Encode(contents, &contents_base64);
305 345
306 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,"; 346 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,";
307 return WebURL(GURL(data_url_prefix + contents_base64)); 347 return WebURL(GURL(data_url_prefix + contents_base64));
308 } 348 }
309 349
310 WebURL BlinkTestRunner::RewriteLayoutTestsURL(const std::string& utf8_url) { 350 WebURL BlinkTestRunner::RewriteLayoutTestsURL(const std::string& utf8_url) {
351 WebURL url = RewriteAbsolutePathInWPT(utf8_url);
qyearsley 2016/05/18 17:26:56 Would rewritten_url make sense for this variable n
tkent 2016/05/20 01:00:30 Done.
352 if (!url.isEmpty())
353 return url;
354
311 const char kPrefix[] = "file:///tmp/LayoutTests/"; 355 const char kPrefix[] = "file:///tmp/LayoutTests/";
312 const int kPrefixLen = arraysize(kPrefix) - 1; 356 const int kPrefixLen = arraysize(kPrefix) - 1;
313 357
314 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen)) 358 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen))
315 return WebURL(GURL(utf8_url)); 359 return WebURL(GURL(utf8_url));
316 360
317 base::FilePath replace_path = 361 base::FilePath replace_path =
318 LayoutTestRenderThreadObserver::GetInstance()->webkit_source_dir() 362 LayoutTestRenderThreadObserver::GetInstance()->webkit_source_dir()
319 .Append(FILE_PATH_LITERAL("LayoutTests/")); 363 .Append(FILE_PATH_LITERAL("LayoutTests/"));
320 #if defined(OS_WIN) 364 #if defined(OS_WIN)
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 get_bluetooth_events_callbacks_.pop_front(); 997 get_bluetooth_events_callbacks_.pop_front();
954 callback.Run(events); 998 callback.Run(events);
955 } 999 }
956 1000
957 void BlinkTestRunner::ReportLeakDetectionResult( 1001 void BlinkTestRunner::ReportLeakDetectionResult(
958 const LeakDetectionResult& report) { 1002 const LeakDetectionResult& report) {
959 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); 1003 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report));
960 } 1004 }
961 1005
962 } // namespace content 1006 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/forms/autocapitalize.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698