Make hitting "Enter" submit the add/change profile dialog.
[chromium-blink-merge.git] / chrome / test / base / chrome_test_launcher.cc
blob6f77da40d205777c5f95ec27842c4e7cf2976f47
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 "content/public/test/test_launcher.h"
7 #include <stack>
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/run_loop.h"
13 #include "base/string_util.h"
14 #include "base/test/test_file_util.h"
15 #include "chrome/app/chrome_main_delegate.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/chrome_constants.h"
18 #include "chrome/test/base/chrome_test_suite.h"
19 #include "content/public/app/content_main.h"
20 #include "content/public/browser/browser_thread.h"
22 #if defined(OS_MACOSX)
23 #include "chrome/browser/chrome_browser_application_mac.h"
24 #endif // defined(OS_MACOSX)
26 #if defined(OS_WIN)
27 #include "content/public/app/startup_helper_win.h"
28 #include "sandbox/win/src/sandbox_types.h"
29 #endif // defined(OS_WIN)
31 #if defined(TOOLKIT_VIEWS)
32 #include "ui/views/focus/accelerator_handler.h"
33 #endif
35 const char kEmptyTestName[] = "InProcessBrowserTest.Empty";
37 class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
38 public:
39 ChromeTestLauncherDelegate() {}
40 virtual ~ChromeTestLauncherDelegate() {}
42 virtual std::string GetEmptyTestName() OVERRIDE {
43 return kEmptyTestName;
46 virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
47 return ChromeTestSuite(argc, argv).Run();
50 virtual bool AdjustChildProcessCommandLine(
51 CommandLine* command_line, const FilePath& temp_data_dir) OVERRIDE {
52 CommandLine new_command_line(command_line->GetProgram());
53 CommandLine::SwitchMap switches = command_line->GetSwitches();
55 // Strip out user-data-dir if present. We will add it back in again later.
56 switches.erase(switches::kUserDataDir);
58 for (CommandLine::SwitchMap::const_iterator iter = switches.begin();
59 iter != switches.end(); ++iter) {
60 new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
63 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
65 // file:// access for ChromeOS.
66 new_command_line.AppendSwitch(switches::kAllowFileAccess);
68 *command_line = new_command_line;
69 return true;
72 virtual void PreRunMessageLoop(base::RunLoop* run_loop) OVERRIDE {
73 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
74 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
75 linked_ptr<views::AcceleratorHandler> handler(
76 new views::AcceleratorHandler);
77 handlers_.push(handler);
78 run_loop->set_dispatcher(handler.get());
80 #endif
83 virtual void PostRunMessageLoop() {
84 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
85 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
86 DCHECK_EQ(handlers_.empty(), false);
87 handlers_.pop();
89 #endif
92 protected:
93 virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
94 #if defined(OS_WIN) || defined (OS_LINUX)
95 return new ChromeMainDelegate();
96 #else
97 // This delegate is only guaranteed to link on linux and windows, so just
98 // bail out if we are on any other platform.
99 NOTREACHED();
100 return NULL;
101 #endif
104 private:
105 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
106 std::stack<linked_ptr<views::AcceleratorHandler> > handlers_;
107 #endif
109 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
112 int main(int argc, char** argv) {
113 // http://crbug.com/163931 Disabled until browser_tests ready on Linux Aura.
114 #if defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS)
115 return 0;
116 #endif
118 #if defined(OS_MACOSX)
119 chrome_browser_application_mac::RegisterBrowserCrApp();
120 #endif
121 ChromeTestLauncherDelegate launcher_delegate;
122 return content::LaunchTests(&launcher_delegate, argc, argv);