| 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" | |
| 15 | 14 |
| 16 namespace test_runner { | 15 namespace test_runner { |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 const char layout_tests_pattern[] = "/LayoutTests/"; | 19 const char layout_tests_pattern[] = "/LayoutTests/"; |
| 21 const std::string::size_type layout_tests_pattern_size = | 20 const std::string::size_type layout_tests_pattern_size = |
| 22 sizeof(layout_tests_pattern) - 1; | 21 sizeof(layout_tests_pattern) - 1; |
| 23 const char file_url_pattern[] = "file:/"; | 22 const char file_url_pattern[] = "file:/"; |
| 24 const char file_test_prefix[] = "(file test):"; | 23 const char file_test_prefix[] = "(file test):"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 38 const char* name) override {} | 37 const char* name) override {} |
| 39 void unregisterMemoryDumpProvider(blink::WebMemoryDumpProvider*) override {} | 38 void unregisterMemoryDumpProvider(blink::WebMemoryDumpProvider*) override {} |
| 40 | 39 |
| 41 private: | 40 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(MockBlinkPlatform); | 41 DISALLOW_COPY_AND_ASSIGN(MockBlinkPlatform); |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 base::LazyInstance<MockBlinkPlatform>::Leaky g_mock_blink_platform = | 44 base::LazyInstance<MockBlinkPlatform>::Leaky g_mock_blink_platform = |
| 46 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
| 47 | 46 |
| 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 | |
| 57 } // namespace | 47 } // namespace |
| 58 | 48 |
| 59 std::string NormalizeLayoutTestURL(const std::string& url) { | 49 std::string NormalizeLayoutTestURL(const std::string& url) { |
| 60 std::string result = url; | 50 std::string result = url; |
| 61 size_t pos; | 51 size_t pos; |
| 62 if (!url.find(file_url_pattern) && | 52 if (!url.find(file_url_pattern) && |
| 63 ((pos = url.find(layout_tests_pattern)) != std::string::npos)) { | 53 ((pos = url.find(layout_tests_pattern)) != std::string::npos)) { |
| 64 // adjust file URLs to match upstream results. | 54 // adjust file URLs to match upstream results. |
| 65 result.replace(0, pos + layout_tests_pattern_size, file_test_prefix); | 55 result.replace(0, pos + layout_tests_pattern_size, file_test_prefix); |
| 66 } else if (!url.find(data_url_pattern)) { | 56 } else if (!url.find(data_url_pattern)) { |
| 67 // URL-escape data URLs to match results upstream. | 57 // URL-escape data URLs to match results upstream. |
| 68 std::string path = url.substr(data_url_pattern_size); | 58 std::string path = url.substr(data_url_pattern_size); |
| 69 result.replace(data_url_pattern_size, url.length(), path); | 59 result.replace(data_url_pattern_size, url.length(), path); |
| 70 } | 60 } |
| 71 return result; | 61 return result; |
| 72 } | 62 } |
| 73 | 63 |
| 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 | |
| 102 void EnsureBlinkInitialized() { | 64 void EnsureBlinkInitialized() { |
| 103 g_mock_blink_platform.Get(); | 65 g_mock_blink_platform.Get(); |
| 104 } | 66 } |
| 105 | 67 |
| 106 } // namespace test_runner | 68 } // namespace test_runner |
| OLD | NEW |