Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / chrome / test / base / chrome_test_launcher.cc
blob3cbe4a1c0db4a9b134add0ebb9831ee779c2d000
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
3 // found in the LICENSE file.
5 #include "chrome/test/base/chrome_test_launcher.h"
7 #include "base/command_line.h"
8 #include "base/debug/leak_annotations.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/memory/linked_ptr.h"
13 #include "base/process/process_metrics.h"
14 #include "base/run_loop.h"
15 #include "base/strings/string_util.h"
16 #include "base/test/test_file_util.h"
17 #include "chrome/app/chrome_main_delegate.h"
18 #include "chrome/common/chrome_constants.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/chrome_test_suite.h"
21 #include "chrome/test/base/test_switches.h"
22 #include "content/public/app/content_main.h"
23 #include "content/public/test/test_launcher.h"
24 #include "content/public/test/test_utils.h"
25 #include "ui/base/test/ui_controls.h"
27 #if defined(OS_MACOSX)
28 #include "chrome/browser/chrome_browser_application_mac.h"
29 #endif // defined(OS_MACOSX)
31 #if defined(USE_AURA)
32 #include "ui/aura/test/ui_controls_factory_aura.h"
33 #include "ui/base/test/ui_controls_aura.h"
34 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
35 #include "ui/views/test/ui_controls_factory_desktop_aurax11.h"
36 #endif
37 #endif
39 #if defined(OS_CHROMEOS)
40 #include "ash/test/ui_controls_factory_ash.h"
41 #endif
43 #if defined(OS_LINUX) || defined(OS_ANDROID)
44 #include "chrome/app/chrome_crash_reporter_client.h"
45 #endif
47 namespace {
49 class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
50 public:
51 explicit ChromeTestLauncherDelegate(ChromeTestSuiteRunner* runner)
52 : runner_(runner) {}
53 ~ChromeTestLauncherDelegate() override {}
55 int RunTestSuite(int argc, char** argv) override {
56 return runner_->RunTestSuite(argc, argv);
59 bool AdjustChildProcessCommandLine(
60 base::CommandLine* command_line,
61 const base::FilePath& temp_data_dir) override {
62 base::CommandLine new_command_line(command_line->GetProgram());
63 base::CommandLine::SwitchMap switches = command_line->GetSwitches();
65 // Strip out user-data-dir if present. We will add it back in again later.
66 switches.erase(switches::kUserDataDir);
68 for (base::CommandLine::SwitchMap::const_iterator iter = switches.begin();
69 iter != switches.end(); ++iter) {
70 new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
73 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
75 // file:// access for ChromeOS.
76 new_command_line.AppendSwitch(switches::kAllowFileAccess);
78 *command_line = new_command_line;
79 return true;
82 protected:
83 content::ContentMainDelegate* CreateContentMainDelegate() override {
84 return new ChromeMainDelegate();
87 void AdjustDefaultParallelJobs(int* default_jobs) override {
88 #if defined(OS_WIN)
89 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
90 switches::kAshBrowserTests)) {
91 *default_jobs = 1;
92 fprintf(stdout,
93 "Disabling test parallelization for --ash-browsertests.\n");
94 fflush(stdout);
96 #endif // defined(OS_WIN)
99 private:
100 ChromeTestSuiteRunner* runner_;
102 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
105 } // namespace
107 int LaunchChromeTests(int default_jobs,
108 ChromeTestSuiteRunner* runner,
109 int argc,
110 char** argv) {
111 #if defined(OS_MACOSX)
112 chrome_browser_application_mac::RegisterBrowserCrApp();
113 #endif
115 #if defined(OS_LINUX) || defined(OS_ANDROID)
116 // We leak this pointer intentionally. The breakpad client needs to outlive
117 // all other code.
118 chrome::ChromeCrashReporterClient* crash_client =
119 new chrome::ChromeCrashReporterClient();
120 ANNOTATE_LEAKING_OBJECT_PTR(crash_client);
121 crash_reporter::SetCrashReporterClient(crash_client);
122 #endif
124 ChromeTestLauncherDelegate launcher_delegate(runner);
125 return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv);