| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // wrapping a lower-level test launcher with content-specific code. | 111 // wrapping a lower-level test launcher with content-specific code. |
| 112 class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { | 112 class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { |
| 113 public: | 113 public: |
| 114 explicit WrapperTestLauncherDelegate( | 114 explicit WrapperTestLauncherDelegate( |
| 115 content::TestLauncherDelegate* launcher_delegate) | 115 content::TestLauncherDelegate* launcher_delegate) |
| 116 : launcher_delegate_(launcher_delegate) { | 116 : launcher_delegate_(launcher_delegate) { |
| 117 CHECK(temp_dir_.CreateUniqueTempDir()); | 117 CHECK(temp_dir_.CreateUniqueTempDir()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // base::TestLauncherDelegate: | 120 // base::TestLauncherDelegate: |
| 121 virtual void OnTestIterationStarting() OVERRIDE; | |
| 122 virtual std::string GetTestNameForFiltering( | |
| 123 const testing::TestCase* test_case, | |
| 124 const testing::TestInfo* test_info) OVERRIDE; | |
| 125 virtual bool ShouldRunTest(const testing::TestCase* test_case, | 121 virtual bool ShouldRunTest(const testing::TestCase* test_case, |
| 126 const testing::TestInfo* test_info) OVERRIDE; | 122 const testing::TestInfo* test_info) OVERRIDE; |
| 127 virtual size_t RunTests(base::TestLauncher* test_launcher, | 123 virtual size_t RunTests(base::TestLauncher* test_launcher, |
| 128 const std::vector<std::string>& test_names) OVERRIDE; | 124 const std::vector<std::string>& test_names) OVERRIDE; |
| 129 virtual size_t RetryTests( | 125 virtual size_t RetryTests( |
| 130 base::TestLauncher* test_launcher, | 126 base::TestLauncher* test_launcher, |
| 131 const std::vector<std::string>& test_names) OVERRIDE; | 127 const std::vector<std::string>& test_names) OVERRIDE; |
| 132 | 128 |
| 133 private: | 129 private: |
| 134 void DoRunTest(base::TestLauncher* test_launcher, | 130 void DoRunTest(base::TestLauncher* test_launcher, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 163 |
| 168 // Store names of all seen tests to properly handle PRE_ tests. | 164 // Store names of all seen tests to properly handle PRE_ tests. |
| 169 std::set<std::string> all_test_names_; | 165 std::set<std::string> all_test_names_; |
| 170 | 166 |
| 171 // Temporary directory for user data directories. | 167 // Temporary directory for user data directories. |
| 172 base::ScopedTempDir temp_dir_; | 168 base::ScopedTempDir temp_dir_; |
| 173 | 169 |
| 174 DISALLOW_COPY_AND_ASSIGN(WrapperTestLauncherDelegate); | 170 DISALLOW_COPY_AND_ASSIGN(WrapperTestLauncherDelegate); |
| 175 }; | 171 }; |
| 176 | 172 |
| 177 void WrapperTestLauncherDelegate::OnTestIterationStarting() { | |
| 178 dependent_test_map_.clear(); | |
| 179 user_data_dir_map_.clear(); | |
| 180 } | |
| 181 | |
| 182 std::string WrapperTestLauncherDelegate::GetTestNameForFiltering( | |
| 183 const testing::TestCase* test_case, | |
| 184 const testing::TestInfo* test_info) { | |
| 185 return RemoveAnyPrePrefixes( | |
| 186 std::string(test_case->name()) + "." + test_info->name()); | |
| 187 } | |
| 188 | |
| 189 bool WrapperTestLauncherDelegate::ShouldRunTest( | 173 bool WrapperTestLauncherDelegate::ShouldRunTest( |
| 190 const testing::TestCase* test_case, | 174 const testing::TestCase* test_case, |
| 191 const testing::TestInfo* test_info) { | 175 const testing::TestInfo* test_info) { |
| 192 all_test_names_.insert( | 176 all_test_names_.insert( |
| 193 std::string(test_case->name()) + "." + test_info->name()); | 177 std::string(test_case->name()) + "." + test_info->name()); |
| 194 | 178 |
| 195 if (StartsWithASCII(test_info->name(), kManualTestPrefix, true) && | 179 if (StartsWithASCII(test_info->name(), kManualTestPrefix, true) && |
| 196 !CommandLine::ForCurrentProcess()->HasSwitch(kRunManualTestsFlag)) { | 180 !CommandLine::ForCurrentProcess()->HasSwitch(kRunManualTestsFlag)) { |
| 197 return false; | 181 return false; |
| 198 } | 182 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 210 size_t dot_pos = full_name.find('.'); | 194 size_t dot_pos = full_name.find('.'); |
| 211 CHECK_NE(dot_pos, std::string::npos); | 195 CHECK_NE(dot_pos, std::string::npos); |
| 212 std::string test_case_name = full_name.substr(0, dot_pos); | 196 std::string test_case_name = full_name.substr(0, dot_pos); |
| 213 std::string test_name = full_name.substr(dot_pos + 1); | 197 std::string test_name = full_name.substr(dot_pos + 1); |
| 214 return test_case_name + "." + kPreTestPrefix + test_name; | 198 return test_case_name + "." + kPreTestPrefix + test_name; |
| 215 } | 199 } |
| 216 | 200 |
| 217 size_t WrapperTestLauncherDelegate::RunTests( | 201 size_t WrapperTestLauncherDelegate::RunTests( |
| 218 base::TestLauncher* test_launcher, | 202 base::TestLauncher* test_launcher, |
| 219 const std::vector<std::string>& test_names) { | 203 const std::vector<std::string>& test_names) { |
| 204 dependent_test_map_.clear(); |
| 205 reverse_dependent_test_map_.clear(); |
| 206 user_data_dir_map_.clear(); |
| 207 |
| 220 // Number of additional tests to run because of dependencies. | 208 // Number of additional tests to run because of dependencies. |
| 221 size_t additional_tests_to_run_count = 0; | 209 size_t additional_tests_to_run_count = 0; |
| 222 | 210 |
| 223 // Compute dependencies of tests to be run. | 211 // Compute dependencies of tests to be run. |
| 224 for (size_t i = 0; i < test_names.size(); i++) { | 212 for (size_t i = 0; i < test_names.size(); i++) { |
| 225 std::string full_name(test_names[i]); | 213 std::string full_name(test_names[i]); |
| 226 std::string pre_test_name(GetPreTestName(full_name)); | 214 std::string pre_test_name(GetPreTestName(full_name)); |
| 227 | 215 |
| 228 while (ContainsKey(all_test_names_, pre_test_name)) { | 216 while (ContainsKey(all_test_names_, pre_test_name)) { |
| 229 additional_tests_to_run_count++; | 217 additional_tests_to_run_count++; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 base::TestLauncher launcher(&delegate, default_jobs); | 508 base::TestLauncher launcher(&delegate, default_jobs); |
| 521 bool success = launcher.Run(argc, argv); | 509 bool success = launcher.Run(argc, argv); |
| 522 return (success ? 0 : 1); | 510 return (success ? 0 : 1); |
| 523 } | 511 } |
| 524 | 512 |
| 525 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 513 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
| 526 return g_launcher_delegate; | 514 return g_launcher_delegate; |
| 527 } | 515 } |
| 528 | 516 |
| 529 } // namespace content | 517 } // namespace content |
| OLD | NEW |