| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "components/test_runner/test_common.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/rand_util.h" | |
| 12 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace test_runner { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char layout_tests_pattern[] = "/LayoutTests/"; | |
| 20 const std::string::size_type layout_tests_pattern_size = | |
| 21 sizeof(layout_tests_pattern) - 1; | |
| 22 const char file_url_pattern[] = "file:/"; | |
| 23 const char file_test_prefix[] = "(file test):"; | |
| 24 const char data_url_pattern[] = "data:"; | |
| 25 const std::string::size_type data_url_pattern_size = | |
| 26 sizeof(data_url_pattern) - 1; | |
| 27 const char* kIllegalString = "illegal value"; | |
| 28 const char* kPolicyIgnore = "Ignore"; | |
| 29 const char* kPolicyDownload = "download"; | |
| 30 const char* kPolicyCurrentTab = "current tab"; | |
| 31 const char* kPolicyNewBackgroundTab = "new background tab"; | |
| 32 const char* kPolicyNewForegroundTab = "new foreground tab"; | |
| 33 const char* kPolicyNewWindow = "new window"; | |
| 34 const char* kPolicyNewPopup = "new popup"; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 std::string NormalizeLayoutTestURL(const std::string& url) { | |
| 39 std::string result = url; | |
| 40 size_t pos; | |
| 41 if (!url.find(file_url_pattern) && | |
| 42 ((pos = url.find(layout_tests_pattern)) != std::string::npos)) { | |
| 43 // adjust file URLs to match upstream results. | |
| 44 result.replace(0, pos + layout_tests_pattern_size, file_test_prefix); | |
| 45 } else if (!url.find(data_url_pattern)) { | |
| 46 // URL-escape data URLs to match results upstream. | |
| 47 std::string path = url.substr(data_url_pattern_size); | |
| 48 result.replace(data_url_pattern_size, url.length(), path); | |
| 49 } | |
| 50 return result; | |
| 51 } | |
| 52 | |
| 53 std::string URLDescription(const GURL& url) { | |
| 54 if (url.SchemeIs(url::kFileScheme)) | |
| 55 return url.ExtractFileName(); | |
| 56 return url.possibly_invalid_spec(); | |
| 57 } | |
| 58 | |
| 59 const char* WebNavigationPolicyToString( | |
| 60 const blink::WebNavigationPolicy& policy) { | |
| 61 switch (policy) { | |
| 62 case blink::WebNavigationPolicyIgnore: | |
| 63 return kPolicyIgnore; | |
| 64 case blink::WebNavigationPolicyDownload: | |
| 65 return kPolicyDownload; | |
| 66 case blink::WebNavigationPolicyCurrentTab: | |
| 67 return kPolicyCurrentTab; | |
| 68 case blink::WebNavigationPolicyNewBackgroundTab: | |
| 69 return kPolicyNewBackgroundTab; | |
| 70 case blink::WebNavigationPolicyNewForegroundTab: | |
| 71 return kPolicyNewForegroundTab; | |
| 72 case blink::WebNavigationPolicyNewWindow: | |
| 73 return kPolicyNewWindow; | |
| 74 case blink::WebNavigationPolicyNewPopup: | |
| 75 return kPolicyNewPopup; | |
| 76 default: | |
| 77 return kIllegalString; | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 blink::WebString V8StringToWebString(v8::Local<v8::String> v8_str) { | |
| 82 int length = v8_str->Utf8Length() + 1; | |
| 83 std::unique_ptr<char[]> chars(new char[length]); | |
| 84 v8_str->WriteUtf8(chars.get(), length); | |
| 85 return blink::WebString::fromUTF8(chars.get()); | |
| 86 } | |
| 87 | |
| 88 } // namespace test_runner | |
| OLD | NEW |