OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/test_launcher.h" | 5 #include "content/test/test_launcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/mac/scoped_nsautorelease_pool.h" | 15 #include "base/mac/scoped_nsautorelease_pool.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/process_util.h" | 18 #include "base/process_util.h" |
19 #include "base/scoped_temp_dir.h" | 19 #include "base/scoped_temp_dir.h" |
20 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/test/test_suite.h" | 22 #include "base/test/test_suite.h" |
23 #include "base/test/test_timeouts.h" | 23 #include "base/test/test_timeouts.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
26 #include "content/test/browser_test.h" | 26 #include "content/test/browser_test.h" |
27 #include "net/base/escape.h" | 27 #include "net/base/escape.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 | 29 |
| 30 #if defined(OS_WIN) |
| 31 #include "base/base_switches.h" |
| 32 #include "content/common/sandbox_policy.h" |
| 33 #include "sandbox/src/dep.h" |
| 34 #include "sandbox/src/sandbox_factory.h" |
| 35 #include "sandbox/src/sandbox_types.h" |
| 36 #endif |
| 37 |
30 namespace test_launcher { | 38 namespace test_launcher { |
31 | 39 |
32 namespace { | 40 namespace { |
33 | 41 |
34 // The environment variable name for the total number of test shards. | 42 // The environment variable name for the total number of test shards. |
35 static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; | 43 static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; |
36 // The environment variable name for the test shard index. | 44 // The environment variable name for the test shard index. |
37 static const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; | 45 static const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; |
38 | 46 |
39 // The default output file for XML output. | 47 // The default output file for XML output. |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 launcher_delegate->EarlyInitialize(); | 551 launcher_delegate->EarlyInitialize(); |
544 | 552 |
545 CommandLine::Init(argc, argv); | 553 CommandLine::Init(argc, argv); |
546 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 554 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
547 | 555 |
548 if (command_line->HasSwitch(kHelpFlag)) { | 556 if (command_line->HasSwitch(kHelpFlag)) { |
549 PrintUsage(); | 557 PrintUsage(); |
550 return 0; | 558 return 0; |
551 } | 559 } |
552 | 560 |
| 561 // TODO(pkasting): This "single_process vs. single-process" design is |
| 562 // terrible UI. Instead, there should be some sort of signal flag on the |
| 563 // command line, with all subsequent arguments passed through to the |
| 564 // underlying browser. |
| 565 if (command_line->HasSwitch(kSingleProcessTestsFlag) || |
| 566 command_line->HasSwitch(kSingleProcessTestsAndChromeFlag) || |
| 567 command_line->HasSwitch(kGTestListTestsFlag) || |
| 568 command_line->HasSwitch(kGTestHelpFlag)) { |
| 569 #if defined(OS_WIN) |
| 570 if (command_line->HasSwitch(kSingleProcessTestsFlag)) { |
| 571 // This is the browser process, so setup the sandbox broker. |
| 572 sandbox::BrokerServices* broker_services = |
| 573 sandbox::SandboxFactory::GetBrokerServices(); |
| 574 if (broker_services) { |
| 575 sandbox::InitBrokerServices(broker_services); |
| 576 // Precreate the desktop and window station used by the renderers. |
| 577 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
| 578 sandbox::ResultCode result = policy->CreateAlternateDesktop(true); |
| 579 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
| 580 policy->Release(); |
| 581 } |
| 582 } |
| 583 #endif |
| 584 return launcher_delegate->RunTestSuite(argc, argv); |
| 585 } |
| 586 |
553 int return_code = 0; | 587 int return_code = 0; |
554 if (launcher_delegate->Run(argc, argv, &return_code)) | 588 if (launcher_delegate->Run(argc, argv, &return_code)) |
555 return return_code; | 589 return return_code; |
556 | 590 |
| 591 base::AtExitManager at_exit; |
| 592 |
557 int32 total_shards; | 593 int32 total_shards; |
558 int32 shard_index; | 594 int32 shard_index; |
559 bool should_shard = ShouldShard(&total_shards, &shard_index); | 595 bool should_shard = ShouldShard(&total_shards, &shard_index); |
560 | 596 |
561 fprintf(stdout, | 597 fprintf(stdout, |
562 "Starting tests...\n" | 598 "Starting tests...\n" |
563 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" | 599 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" |
564 "For debugging a test inside a debugger, use the\n" | 600 "For debugging a test inside a debugger, use the\n" |
565 "--gtest_filter=<your_test_name> flag along with either\n" | 601 "--gtest_filter=<your_test_name> flag along with either\n" |
566 "--single_process (to run all tests in one launcher/browser process) or\n" | 602 "--single_process (to run all tests in one launcher/browser process) or\n" |
(...skipping 28 matching lines...) Expand all Loading... |
595 } | 631 } |
596 | 632 |
597 // Special value "-1" means "repeat indefinitely". | 633 // Special value "-1" means "repeat indefinitely". |
598 if (cycles != -1) | 634 if (cycles != -1) |
599 cycles--; | 635 cycles--; |
600 } | 636 } |
601 return exit_code; | 637 return exit_code; |
602 } | 638 } |
603 | 639 |
604 } // namespace test_launcher | 640 } // namespace test_launcher |
OLD | NEW |