[Sync] Componentize UIModelWorker.
[chromium-blink-merge.git] / components / test_runner / test_common.cc
blobad06d5233e5a14889e49ea549d2c95eb1474d0ad
1 // Copyright 2014 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.
5 #include "components/test_runner/test_common.h"
7 #include "base/lazy_instance.h"
8 #include "base/macros.h"
9 #include "third_party/WebKit/public/platform/Platform.h"
10 #include "third_party/WebKit/public/web/WebKit.h"
12 namespace test_runner {
14 namespace {
16 const char layout_tests_pattern[] = "/LayoutTests/";
17 const std::string::size_type layout_tests_pattern_size =
18 sizeof(layout_tests_pattern) - 1;
19 const char file_url_pattern[] = "file:/";
20 const char file_test_prefix[] = "(file test):";
21 const char data_url_pattern[] = "data:";
22 const std::string::size_type data_url_pattern_size =
23 sizeof(data_url_pattern) - 1;
25 // This mock is used to initialize blink.
26 class MockBlinkPlatform : NON_EXPORTED_BASE(public blink::Platform) {
27 public:
28 MockBlinkPlatform() {
29 blink::initializeWithoutV8(this);
31 ~MockBlinkPlatform() override {}
32 void cryptographicallyRandomValues(unsigned char* buffer,
33 size_t length) override {}
34 private:
35 DISALLOW_COPY_AND_ASSIGN(MockBlinkPlatform);
38 base::LazyInstance<MockBlinkPlatform>::Leaky g_mock_blink_platform =
39 LAZY_INSTANCE_INITIALIZER;
41 } // namespace
43 std::string NormalizeLayoutTestURL(const std::string& url) {
44 std::string result = url;
45 size_t pos;
46 if (!url.find(file_url_pattern) &&
47 ((pos = url.find(layout_tests_pattern)) != std::string::npos)) {
48 // adjust file URLs to match upstream results.
49 result.replace(0, pos + layout_tests_pattern_size, file_test_prefix);
50 } else if (!url.find(data_url_pattern)) {
51 // URL-escape data URLs to match results upstream.
52 std::string path = url.substr(data_url_pattern_size);
53 result.replace(data_url_pattern_size, url.length(), path);
55 return result;
58 void EnsureBlinkInitialized() {
59 g_mock_blink_platform.Get();
62 } // namespace test_runner