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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
| 10 #include <memory> |
10 #include <set> | 11 #include <set> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/containers/hash_tables.h" | 17 #include "base/containers/hash_tables.h" |
17 #include "base/environment.h" | 18 #include "base/environment.h" |
18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
19 #include "base/files/scoped_temp_dir.h" | 20 #include "base/files/scoped_temp_dir.h" |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
21 #include "base/macros.h" | 22 #include "base/macros.h" |
22 #include "base/memory/linked_ptr.h" | 23 #include "base/memory/linked_ptr.h" |
23 #include "base/memory/scoped_ptr.h" | |
24 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
25 #include "base/stl_util.h" | 25 #include "base/stl_util.h" |
26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
29 #include "base/test/launcher/test_launcher.h" | 29 #include "base/test/launcher/test_launcher.h" |
30 #include "base/test/test_suite.h" | 30 #include "base/test/test_suite.h" |
31 #include "base/test/test_switches.h" | 31 #include "base/test/test_switches.h" |
32 #include "base/test/test_timeouts.h" | 32 #include "base/test/test_timeouts.h" |
33 #include "base/time/time.h" | 33 #include "base/time/time.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Launches test named |test_name| using parallel launcher, | 148 // Launches test named |test_name| using parallel launcher, |
149 // given result of PRE_ test |pre_test_result|. | 149 // given result of PRE_ test |pre_test_result|. |
150 void RunDependentTest(base::TestLauncher* test_launcher, | 150 void RunDependentTest(base::TestLauncher* test_launcher, |
151 const std::string test_name, | 151 const std::string test_name, |
152 const base::TestResult& pre_test_result); | 152 const base::TestResult& pre_test_result); |
153 | 153 |
154 // Callback to receive result of a test. | 154 // Callback to receive result of a test. |
155 void GTestCallback(base::TestLauncher* test_launcher, | 155 void GTestCallback(base::TestLauncher* test_launcher, |
156 const std::vector<std::string>& test_names, | 156 const std::vector<std::string>& test_names, |
157 const std::string& test_name, | 157 const std::string& test_name, |
158 scoped_ptr<TestState> test_state, | 158 std::unique_ptr<TestState> test_state, |
159 int exit_code, | 159 int exit_code, |
160 const base::TimeDelta& elapsed_time, | 160 const base::TimeDelta& elapsed_time, |
161 bool was_timeout, | 161 bool was_timeout, |
162 const std::string& output); | 162 const std::string& output); |
163 | 163 |
164 content::TestLauncherDelegate* launcher_delegate_; | 164 content::TestLauncherDelegate* launcher_delegate_; |
165 | 165 |
166 // Store dependent test name (map is indexed by full test name). | 166 // Store dependent test name (map is indexed by full test name). |
167 typedef std::map<std::string, std::string> DependentTestMap; | 167 typedef std::map<std::string, std::string> DependentTestMap; |
168 DependentTestMap dependent_test_map_; | 168 DependentTestMap dependent_test_map_; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 std::string test_name(test_names.front()); | 345 std::string test_name(test_names.front()); |
346 std::vector<std::string> test_names_copy( | 346 std::vector<std::string> test_names_copy( |
347 test_names.begin() + 1, test_names.end()); | 347 test_names.begin() + 1, test_names.end()); |
348 | 348 |
349 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name)); | 349 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name)); |
350 | 350 |
351 base::CommandLine cmd_line(*base::CommandLine::ForCurrentProcess()); | 351 base::CommandLine cmd_line(*base::CommandLine::ForCurrentProcess()); |
352 base::TestLauncher::LaunchOptions test_launch_options; | 352 base::TestLauncher::LaunchOptions test_launch_options; |
353 test_launch_options.flags = base::TestLauncher::USE_JOB_OBJECTS | | 353 test_launch_options.flags = base::TestLauncher::USE_JOB_OBJECTS | |
354 base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB; | 354 base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB; |
355 scoped_ptr<TestState> test_state_ptr = | 355 std::unique_ptr<TestState> test_state_ptr = |
356 launcher_delegate_->PreRunTest(&cmd_line, &test_launch_options); | 356 launcher_delegate_->PreRunTest(&cmd_line, &test_launch_options); |
357 CHECK(launcher_delegate_->AdjustChildProcessCommandLine( | 357 CHECK(launcher_delegate_->AdjustChildProcessCommandLine( |
358 &cmd_line, user_data_dir_map_[test_name_no_pre])); | 358 &cmd_line, user_data_dir_map_[test_name_no_pre])); |
359 | 359 |
360 base::CommandLine new_cmd_line(cmd_line.GetProgram()); | 360 base::CommandLine new_cmd_line(cmd_line.GetProgram()); |
361 base::CommandLine::SwitchMap switches = cmd_line.GetSwitches(); | 361 base::CommandLine::SwitchMap switches = cmd_line.GetSwitches(); |
362 | 362 |
363 // Strip out gtest_output flag because otherwise we would overwrite results | 363 // Strip out gtest_output flag because otherwise we would overwrite results |
364 // of the other tests. | 364 // of the other tests. |
365 switches.erase(base::kGTestOutputFlag); | 365 switches.erase(base::kGTestOutputFlag); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 dependent_test_map_[test_name], | 408 dependent_test_map_[test_name], |
409 test_result); | 409 test_result); |
410 } | 410 } |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 void WrapperTestLauncherDelegate::GTestCallback( | 414 void WrapperTestLauncherDelegate::GTestCallback( |
415 base::TestLauncher* test_launcher, | 415 base::TestLauncher* test_launcher, |
416 const std::vector<std::string>& test_names, | 416 const std::vector<std::string>& test_names, |
417 const std::string& test_name, | 417 const std::string& test_name, |
418 scoped_ptr<TestState> test_state, | 418 std::unique_ptr<TestState> test_state, |
419 int exit_code, | 419 int exit_code, |
420 const base::TimeDelta& elapsed_time, | 420 const base::TimeDelta& elapsed_time, |
421 bool was_timeout, | 421 bool was_timeout, |
422 const std::string& output) { | 422 const std::string& output) { |
423 base::TestResult result; | 423 base::TestResult result; |
424 result.full_name = test_name; | 424 result.full_name = test_name; |
425 | 425 |
426 // TODO(phajdan.jr): Recognize crashes. | 426 // TODO(phajdan.jr): Recognize crashes. |
427 if (exit_code == 0) | 427 if (exit_code == 0) |
428 result.status = base::TestResult::TEST_SUCCESS; | 428 result.status = base::TestResult::TEST_SUCCESS; |
(...skipping 30 matching lines...) Expand all Loading... |
459 | 459 |
460 const char kHelpFlag[] = "help"; | 460 const char kHelpFlag[] = "help"; |
461 | 461 |
462 const char kLaunchAsBrowser[] = "as-browser"; | 462 const char kLaunchAsBrowser[] = "as-browser"; |
463 | 463 |
464 // See kManualTestPrefix above. | 464 // See kManualTestPrefix above. |
465 const char kRunManualTestsFlag[] = "run-manual"; | 465 const char kRunManualTestsFlag[] = "run-manual"; |
466 | 466 |
467 const char kSingleProcessTestsFlag[] = "single_process"; | 467 const char kSingleProcessTestsFlag[] = "single_process"; |
468 | 468 |
469 scoped_ptr<TestState> TestLauncherDelegate::PreRunTest( | 469 std::unique_ptr<TestState> TestLauncherDelegate::PreRunTest( |
470 base::CommandLine* command_line, | 470 base::CommandLine* command_line, |
471 base::TestLauncher::LaunchOptions* test_launch_options) { | 471 base::TestLauncher::LaunchOptions* test_launch_options) { |
472 return nullptr; | 472 return nullptr; |
473 } | 473 } |
474 | 474 |
475 void TestLauncherDelegate::OnDoneRunningTests() {} | 475 void TestLauncherDelegate::OnDoneRunningTests() {} |
476 | 476 |
477 TestLauncherDelegate::~TestLauncherDelegate() { | 477 TestLauncherDelegate::~TestLauncherDelegate() { |
478 } | 478 } |
479 | 479 |
480 int LaunchTests(TestLauncherDelegate* launcher_delegate, | 480 int LaunchTests(TestLauncherDelegate* launcher_delegate, |
481 int default_jobs, | 481 int default_jobs, |
482 int argc, | 482 int argc, |
483 char** argv) { | 483 char** argv) { |
484 DCHECK(!g_launcher_delegate); | 484 DCHECK(!g_launcher_delegate); |
485 g_launcher_delegate = launcher_delegate; | 485 g_launcher_delegate = launcher_delegate; |
486 | 486 |
487 base::CommandLine::Init(argc, argv); | 487 base::CommandLine::Init(argc, argv); |
488 const base::CommandLine* command_line = | 488 const base::CommandLine* command_line = |
489 base::CommandLine::ForCurrentProcess(); | 489 base::CommandLine::ForCurrentProcess(); |
490 | 490 |
491 if (command_line->HasSwitch(kHelpFlag)) { | 491 if (command_line->HasSwitch(kHelpFlag)) { |
492 PrintUsage(); | 492 PrintUsage(); |
493 return 0; | 493 return 0; |
494 } | 494 } |
495 | 495 |
496 scoped_ptr<ContentMainDelegate> chrome_main_delegate( | 496 std::unique_ptr<ContentMainDelegate> chrome_main_delegate( |
497 launcher_delegate->CreateContentMainDelegate()); | 497 launcher_delegate->CreateContentMainDelegate()); |
498 ContentMainParams params(chrome_main_delegate.get()); | 498 ContentMainParams params(chrome_main_delegate.get()); |
499 | 499 |
500 #if defined(OS_WIN) | 500 #if defined(OS_WIN) |
501 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 501 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
502 InitializeSandboxInfo(&sandbox_info); | 502 InitializeSandboxInfo(&sandbox_info); |
503 | 503 |
504 params.instance = GetModuleHandle(NULL); | 504 params.instance = GetModuleHandle(NULL); |
505 params.sandbox_info = &sandbox_info; | 505 params.sandbox_info = &sandbox_info; |
506 #elif !defined(OS_ANDROID) | 506 #elif !defined(OS_ANDROID) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 550 |
551 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 551 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
552 return g_launcher_delegate; | 552 return g_launcher_delegate; |
553 } | 553 } |
554 | 554 |
555 ContentMainParams* GetContentMainParams() { | 555 ContentMainParams* GetContentMainParams() { |
556 return g_params; | 556 return g_params; |
557 } | 557 } |
558 | 558 |
559 } // namespace content | 559 } // namespace content |
OLD | NEW |