OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/test_runner/test_common.h" | 5 #include "components/test_runner/test_common.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "third_party/WebKit/public/platform/Platform.h" | 12 #include "third_party/WebKit/public/platform/Platform.h" |
13 #include "third_party/WebKit/public/web/WebKit.h" | 13 #include "third_party/WebKit/public/web/WebKit.h" |
| 14 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
14 | 15 |
15 namespace test_runner { | 16 namespace test_runner { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 const char layout_tests_pattern[] = "/LayoutTests/"; | 20 const char layout_tests_pattern[] = "/LayoutTests/"; |
20 const std::string::size_type layout_tests_pattern_size = | 21 const std::string::size_type layout_tests_pattern_size = |
21 sizeof(layout_tests_pattern) - 1; | 22 sizeof(layout_tests_pattern) - 1; |
22 const char file_url_pattern[] = "file:/"; | 23 const char file_url_pattern[] = "file:/"; |
23 const char file_test_prefix[] = "(file test):"; | 24 const char file_test_prefix[] = "(file test):"; |
(...skipping 13 matching lines...) Expand all Loading... |
37 const char* name) override {} | 38 const char* name) override {} |
38 void unregisterMemoryDumpProvider(blink::WebMemoryDumpProvider*) override {} | 39 void unregisterMemoryDumpProvider(blink::WebMemoryDumpProvider*) override {} |
39 | 40 |
40 private: | 41 private: |
41 DISALLOW_COPY_AND_ASSIGN(MockBlinkPlatform); | 42 DISALLOW_COPY_AND_ASSIGN(MockBlinkPlatform); |
42 }; | 43 }; |
43 | 44 |
44 base::LazyInstance<MockBlinkPlatform>::Leaky g_mock_blink_platform = | 45 base::LazyInstance<MockBlinkPlatform>::Leaky g_mock_blink_platform = |
45 LAZY_INSTANCE_INITIALIZER; | 46 LAZY_INSTANCE_INITIALIZER; |
46 | 47 |
| 48 const char* kIllegalString = "illegal value"; |
| 49 const char* kPolicyIgnore = "Ignore"; |
| 50 const char* kPolicyDownload = "download"; |
| 51 const char* kPolicyCurrentTab = "current tab"; |
| 52 const char* kPolicyNewBackgroundTab = "new background tab"; |
| 53 const char* kPolicyNewForegroundTab = "new foreground tab"; |
| 54 const char* kPolicyNewWindow = "new window"; |
| 55 const char* kPolicyNewPopup = "new popup"; |
| 56 |
47 } // namespace | 57 } // namespace |
48 | 58 |
49 std::string NormalizeLayoutTestURL(const std::string& url) { | 59 std::string NormalizeLayoutTestURL(const std::string& url) { |
50 std::string result = url; | 60 std::string result = url; |
51 size_t pos; | 61 size_t pos; |
52 if (!url.find(file_url_pattern) && | 62 if (!url.find(file_url_pattern) && |
53 ((pos = url.find(layout_tests_pattern)) != std::string::npos)) { | 63 ((pos = url.find(layout_tests_pattern)) != std::string::npos)) { |
54 // adjust file URLs to match upstream results. | 64 // adjust file URLs to match upstream results. |
55 result.replace(0, pos + layout_tests_pattern_size, file_test_prefix); | 65 result.replace(0, pos + layout_tests_pattern_size, file_test_prefix); |
56 } else if (!url.find(data_url_pattern)) { | 66 } else if (!url.find(data_url_pattern)) { |
57 // URL-escape data URLs to match results upstream. | 67 // URL-escape data URLs to match results upstream. |
58 std::string path = url.substr(data_url_pattern_size); | 68 std::string path = url.substr(data_url_pattern_size); |
59 result.replace(data_url_pattern_size, url.length(), path); | 69 result.replace(data_url_pattern_size, url.length(), path); |
60 } | 70 } |
61 return result; | 71 return result; |
62 } | 72 } |
63 | 73 |
| 74 std::string URLDescription(const GURL& url) { |
| 75 if (url.SchemeIs(url::kFileScheme)) |
| 76 return url.ExtractFileName(); |
| 77 return url.possibly_invalid_spec(); |
| 78 } |
| 79 |
| 80 const char* WebNavigationPolicyToString( |
| 81 const blink::WebNavigationPolicy& policy) { |
| 82 switch (policy) { |
| 83 case blink::WebNavigationPolicyIgnore: |
| 84 return kPolicyIgnore; |
| 85 case blink::WebNavigationPolicyDownload: |
| 86 return kPolicyDownload; |
| 87 case blink::WebNavigationPolicyCurrentTab: |
| 88 return kPolicyCurrentTab; |
| 89 case blink::WebNavigationPolicyNewBackgroundTab: |
| 90 return kPolicyNewBackgroundTab; |
| 91 case blink::WebNavigationPolicyNewForegroundTab: |
| 92 return kPolicyNewForegroundTab; |
| 93 case blink::WebNavigationPolicyNewWindow: |
| 94 return kPolicyNewWindow; |
| 95 case blink::WebNavigationPolicyNewPopup: |
| 96 return kPolicyNewPopup; |
| 97 default: |
| 98 return kIllegalString; |
| 99 } |
| 100 } |
| 101 |
64 void EnsureBlinkInitialized() { | 102 void EnsureBlinkInitialized() { |
65 g_mock_blink_platform.Get(); | 103 g_mock_blink_platform.Get(); |
66 } | 104 } |
67 | 105 |
68 } // namespace test_runner | 106 } // namespace test_runner |
OLD | NEW |