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 "base/base_paths.h"
8 #include "base/command_line.h"
9 #include "base/debug/stack_trace.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "base/process/memory.h"
13 #include "base/sys_info.h"
14 #include "base/test/test_suite.h"
15 #include "base/test/test_timeouts.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/test/content_test_suite_base.h"
18 #include "content/shell/app/shell_main_delegate.h"
19 #include "content/shell/common/shell_switches.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 #if defined(OS_ANDROID)
23 #include "base/message_loop/message_loop.h"
24 #include "content/common/url_schemes.h"
25 #include "content/public/common/content_paths.h"
26 #include "content/public/test/nested_message_pump_android.h"
27 #include "content/shell/browser/shell_content_browser_client.h"
28 #include "content/shell/common/shell_content_client.h"
29 #include "ui/base/ui_base_paths.h"
34 #if defined(OS_ANDROID)
35 scoped_ptr
<base::MessagePump
> CreateMessagePumpForUI() {
36 return scoped_ptr
<base::MessagePump
>(new NestedMessagePumpAndroid());
40 class ContentBrowserTestSuite
: public ContentTestSuiteBase
{
42 ContentBrowserTestSuite(int argc
, char** argv
)
43 : ContentTestSuiteBase(argc
, argv
) {
45 virtual ~ContentBrowserTestSuite() {
49 virtual void Initialize() OVERRIDE
{
51 #if defined(OS_ANDROID)
52 // This needs to be done before base::TestSuite::Initialize() is called,
53 // as it also tries to set MessagePumpForUIFactory.
54 if (!base::MessageLoop::InitMessagePumpForUIFactory(
55 &CreateMessagePumpForUI
))
56 VLOG(0) << "MessagePumpForUIFactory already set, unable to override.";
58 // For all other platforms, we call ContentMain for browser tests which goes
59 // through the normal browser initialization paths. For Android, we must set
60 // things up manually.
61 content_client_
.reset(new ShellContentClient
);
62 browser_content_client_
.reset(new ShellContentBrowserClient());
63 SetContentClient(content_client_
.get());
64 SetBrowserClientForTesting(browser_content_client_
.get());
66 content::RegisterContentSchemes(false);
67 RegisterPathProvider();
68 ui::RegisterPathProvider();
69 RegisterInProcessThreads();
72 ContentTestSuiteBase::Initialize();
75 #if defined(OS_ANDROID)
76 scoped_ptr
<ShellContentClient
> content_client_
;
77 scoped_ptr
<ShellContentBrowserClient
> browser_content_client_
;
80 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite
);
83 class ContentTestLauncherDelegate
: public TestLauncherDelegate
{
85 ContentTestLauncherDelegate() {}
86 virtual ~ContentTestLauncherDelegate() {}
88 virtual int RunTestSuite(int argc
, char** argv
) OVERRIDE
{
89 return ContentBrowserTestSuite(argc
, argv
).Run();
92 virtual bool AdjustChildProcessCommandLine(
93 CommandLine
* command_line
, const base::FilePath
& temp_data_dir
) OVERRIDE
{
94 command_line
->AppendSwitchPath(switches::kContentShellDataPath
,
96 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
97 command_line
->AppendSwitch(switches::kUseFakeUIForMediaStream
);
102 virtual ContentMainDelegate
* CreateContentMainDelegate() OVERRIDE
{
103 return new ShellMainDelegate();
107 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate
);
110 } // namespace content
112 int main(int argc
, char** argv
) {
113 int default_jobs
= std::max(1, base::SysInfo::NumberOfProcessors() / 2);
114 content::ContentTestLauncherDelegate launcher_delegate
;
115 return LaunchTests(&launcher_delegate
, default_jobs
, argc
, argv
);