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
{
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
) {
29 blink::initializeWithoutV8(this);
31 ~MockBlinkPlatform() override
{}
32 void cryptographicallyRandomValues(unsigned char* buffer
,
33 size_t length
) override
{}
35 DISALLOW_COPY_AND_ASSIGN(MockBlinkPlatform
);
38 base::LazyInstance
<MockBlinkPlatform
>::Leaky g_mock_blink_platform
=
39 LAZY_INSTANCE_INITIALIZER
;
43 std::string
NormalizeLayoutTestURL(const std::string
& url
) {
44 std::string result
= url
;
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
);
58 void EnsureBlinkInitialized() {
59 g_mock_blink_platform
.Get();
62 } // namespace test_runner