OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/shell/browser/layout_test/test_info_extractor.h" | 5 #include "content/shell/browser/layout_test/test_info_extractor.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "net/base/filename_util.h" | 17 #include "net/base/filename_util.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
(...skipping 13 matching lines...) Expand all Loading... |
34 return false; | 35 return false; |
35 | 36 |
36 std::string test_location(kAndroidLayoutTestBase); | 37 std::string test_location(kAndroidLayoutTestBase); |
37 test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath))); | 38 test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath))); |
38 | 39 |
39 *url = GURL(test_location); | 40 *url = GURL(test_location); |
40 return true; | 41 return true; |
41 } | 42 } |
42 #endif // defined(OS_ANDROID) | 43 #endif // defined(OS_ANDROID) |
43 | 44 |
44 scoped_ptr<TestInfo> GetTestInfoFromLayoutTestName( | 45 std::unique_ptr<TestInfo> GetTestInfoFromLayoutTestName( |
45 const std::string& test_name) { | 46 const std::string& test_name) { |
46 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 47 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
47 std::string path_or_url = test_name; | 48 std::string path_or_url = test_name; |
48 std::string pixel_switch; | 49 std::string pixel_switch; |
49 std::string::size_type separator_position = path_or_url.find('\''); | 50 std::string::size_type separator_position = path_or_url.find('\''); |
50 if (separator_position != std::string::npos) { | 51 if (separator_position != std::string::npos) { |
51 pixel_switch = path_or_url.substr(separator_position + 1); | 52 pixel_switch = path_or_url.substr(separator_position + 1); |
52 path_or_url.erase(separator_position); | 53 path_or_url.erase(separator_position); |
53 } | 54 } |
54 separator_position = pixel_switch.find('\''); | 55 separator_position = pixel_switch.find('\''); |
55 std::string expected_pixel_hash; | 56 std::string expected_pixel_hash; |
56 if (separator_position != std::string::npos) { | 57 if (separator_position != std::string::npos) { |
57 expected_pixel_hash = pixel_switch.substr(separator_position + 1); | 58 expected_pixel_hash = pixel_switch.substr(separator_position + 1); |
58 pixel_switch.erase(separator_position); | 59 pixel_switch.erase(separator_position); |
59 } | 60 } |
60 const bool enable_pixel_dumping = | 61 const bool enable_pixel_dumping = |
61 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); | 62 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); |
62 | 63 |
63 GURL test_url; | 64 GURL test_url; |
64 #if defined(OS_ANDROID) | 65 #if defined(OS_ANDROID) |
65 if (GetTestUrlForAndroid(path_or_url, &test_url)) { | 66 if (GetTestUrlForAndroid(path_or_url, &test_url)) { |
66 return make_scoped_ptr(new TestInfo(test_url, enable_pixel_dumping, | 67 return base::WrapUnique(new TestInfo( |
67 expected_pixel_hash, base::FilePath())); | 68 test_url, enable_pixel_dumping, expected_pixel_hash, base::FilePath())); |
68 } | 69 } |
69 #endif | 70 #endif |
70 | 71 |
71 test_url = GURL(path_or_url); | 72 test_url = GURL(path_or_url); |
72 if (!(test_url.is_valid() && test_url.has_scheme())) { | 73 if (!(test_url.is_valid() && test_url.has_scheme())) { |
73 // We're outside of the message loop here, and this is a test. | 74 // We're outside of the message loop here, and this is a test. |
74 base::ThreadRestrictions::ScopedAllowIO allow_io; | 75 base::ThreadRestrictions::ScopedAllowIO allow_io; |
75 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
76 base::FilePath::StringType wide_path_or_url = | 77 base::FilePath::StringType wide_path_or_url = |
77 base::SysNativeMBToWide(path_or_url); | 78 base::SysNativeMBToWide(path_or_url); |
(...skipping 13 matching lines...) Expand all Loading... |
91 } | 92 } |
92 base::FilePath local_path; | 93 base::FilePath local_path; |
93 base::FilePath current_working_directory; | 94 base::FilePath current_working_directory; |
94 | 95 |
95 // We're outside of the message loop here, and this is a test. | 96 // We're outside of the message loop here, and this is a test. |
96 base::ThreadRestrictions::ScopedAllowIO allow_io; | 97 base::ThreadRestrictions::ScopedAllowIO allow_io; |
97 if (net::FileURLToFilePath(test_url, &local_path)) | 98 if (net::FileURLToFilePath(test_url, &local_path)) |
98 current_working_directory = local_path.DirName(); | 99 current_working_directory = local_path.DirName(); |
99 else | 100 else |
100 base::GetCurrentDirectory(¤t_working_directory); | 101 base::GetCurrentDirectory(¤t_working_directory); |
101 return make_scoped_ptr(new TestInfo(test_url, enable_pixel_dumping, | 102 return base::WrapUnique(new TestInfo(test_url, enable_pixel_dumping, |
102 expected_pixel_hash, | 103 expected_pixel_hash, |
103 current_working_directory)); | 104 current_working_directory)); |
104 } | 105 } |
105 | 106 |
106 } // namespace | 107 } // namespace |
107 | 108 |
108 TestInfo::TestInfo(const GURL& url, | 109 TestInfo::TestInfo(const GURL& url, |
109 bool enable_pixel_dumping, | 110 bool enable_pixel_dumping, |
110 const std::string& expected_pixel_hash, | 111 const std::string& expected_pixel_hash, |
111 const base::FilePath& current_working_directory) | 112 const base::FilePath& current_working_directory) |
112 : url(url), | 113 : url(url), |
113 enable_pixel_dumping(enable_pixel_dumping), | 114 enable_pixel_dumping(enable_pixel_dumping), |
114 expected_pixel_hash(expected_pixel_hash), | 115 expected_pixel_hash(expected_pixel_hash), |
115 current_working_directory(current_working_directory) {} | 116 current_working_directory(current_working_directory) {} |
116 TestInfo::~TestInfo() {} | 117 TestInfo::~TestInfo() {} |
117 | 118 |
118 TestInfoExtractor::TestInfoExtractor( | 119 TestInfoExtractor::TestInfoExtractor( |
119 const base::CommandLine::StringVector& cmd_args) | 120 const base::CommandLine::StringVector& cmd_args) |
120 : cmdline_args_(cmd_args), cmdline_position_(0) {} | 121 : cmdline_args_(cmd_args), cmdline_position_(0) {} |
121 | 122 |
122 TestInfoExtractor::~TestInfoExtractor() {} | 123 TestInfoExtractor::~TestInfoExtractor() {} |
123 | 124 |
124 scoped_ptr<TestInfo> TestInfoExtractor::GetNextTest() { | 125 std::unique_ptr<TestInfo> TestInfoExtractor::GetNextTest() { |
125 if (cmdline_position_ >= cmdline_args_.size()) | 126 if (cmdline_position_ >= cmdline_args_.size()) |
126 return nullptr; | 127 return nullptr; |
127 | 128 |
128 std::string test_string; | 129 std::string test_string; |
129 if (cmdline_args_[cmdline_position_] == FILE_PATH_LITERAL("-")) { | 130 if (cmdline_args_[cmdline_position_] == FILE_PATH_LITERAL("-")) { |
130 do { | 131 do { |
131 bool success = !!std::getline(std::cin, test_string, '\n'); | 132 bool success = !!std::getline(std::cin, test_string, '\n'); |
132 if (!success) | 133 if (!success) |
133 return nullptr; | 134 return nullptr; |
134 } while (test_string.empty()); | 135 } while (test_string.empty()); |
135 } else { | 136 } else { |
136 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
137 test_string = base::WideToUTF8(cmdline_args_[cmdline_position_++]); | 138 test_string = base::WideToUTF8(cmdline_args_[cmdline_position_++]); |
138 #else | 139 #else |
139 test_string = cmdline_args_[cmdline_position_++]; | 140 test_string = cmdline_args_[cmdline_position_++]; |
140 #endif | 141 #endif |
141 } | 142 } |
142 | 143 |
143 DCHECK(!test_string.empty()); | 144 DCHECK(!test_string.empty()); |
144 if (test_string == "QUIT") | 145 if (test_string == "QUIT") |
145 return nullptr; | 146 return nullptr; |
146 return GetTestInfoFromLayoutTestName(test_string); | 147 return GetTestInfoFromLayoutTestName(test_string); |
147 } | 148 } |
148 | 149 |
149 } // namespace content | 150 } // namespace content |
OLD | NEW |