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/i18n/icu_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "base/process/memory.h"
14 #include "base/sys_info.h"
15 #include "base/test/test_suite.h"
16 #include "base/test/test_timeouts.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/test/content_test_suite_base.h"
19 #include "content/shell/app/shell_main_delegate.h"
20 #include "content/shell/common/shell_switches.h"
21 #include "media/base/media_switches.h"
22 #include "testing/gtest/include/gtest/gtest.h"
24 #if defined(OS_ANDROID)
25 #include "base/message_loop/message_loop.h"
26 #include "content/app/mojo/mojo_init.h"
27 #include "content/common/url_schemes.h"
28 #include "content/public/common/content_paths.h"
29 #include "content/public/test/nested_message_pump_android.h"
30 #include "content/shell/browser/shell_content_browser_client.h"
31 #include "content/shell/common/shell_content_client.h"
32 #include "ui/base/ui_base_paths.h"
37 #if defined(OS_ANDROID)
38 scoped_ptr
<base::MessagePump
> CreateMessagePumpForUI() {
39 return scoped_ptr
<base::MessagePump
>(new NestedMessagePumpAndroid());
43 class ContentBrowserTestSuite
: public ContentTestSuiteBase
{
45 ContentBrowserTestSuite(int argc
, char** argv
)
46 : ContentTestSuiteBase(argc
, argv
) {
48 virtual ~ContentBrowserTestSuite() {
52 virtual void Initialize() OVERRIDE
{
54 #if defined(OS_ANDROID)
55 base::i18n::AllowMultipleInitializeCallsForTesting();
56 base::i18n::InitializeICU();
58 // This needs to be done before base::TestSuite::Initialize() is called,
59 // as it also tries to set MessagePumpForUIFactory.
60 if (!base::MessageLoop::InitMessagePumpForUIFactory(
61 &CreateMessagePumpForUI
))
62 VLOG(0) << "MessagePumpForUIFactory already set, unable to override.";
64 // For all other platforms, we call ContentMain for browser tests which goes
65 // through the normal browser initialization paths. For Android, we must set
66 // things up manually.
67 content_client_
.reset(new ShellContentClient
);
68 browser_content_client_
.reset(new ShellContentBrowserClient());
69 SetContentClient(content_client_
.get());
70 SetBrowserClientForTesting(browser_content_client_
.get());
72 content::RegisterContentSchemes(false);
73 RegisterPathProvider();
74 ui::RegisterPathProvider();
75 RegisterInProcessThreads();
80 ContentTestSuiteBase::Initialize();
83 #if defined(OS_ANDROID)
84 scoped_ptr
<ShellContentClient
> content_client_
;
85 scoped_ptr
<ShellContentBrowserClient
> browser_content_client_
;
88 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite
);
91 class ContentTestLauncherDelegate
: public TestLauncherDelegate
{
93 ContentTestLauncherDelegate() {}
94 virtual ~ContentTestLauncherDelegate() {}
96 virtual int RunTestSuite(int argc
, char** argv
) OVERRIDE
{
97 return ContentBrowserTestSuite(argc
, argv
).Run();
100 virtual bool AdjustChildProcessCommandLine(
101 CommandLine
* command_line
, const base::FilePath
& temp_data_dir
) OVERRIDE
{
102 command_line
->AppendSwitchPath(switches::kContentShellDataPath
,
104 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
105 command_line
->AppendSwitch(switches::kUseFakeUIForMediaStream
);
110 virtual ContentMainDelegate
* CreateContentMainDelegate() OVERRIDE
{
111 return new ShellMainDelegate();
115 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate
);
118 } // namespace content
120 int main(int argc
, char** argv
) {
121 int default_jobs
= std::max(1, base::SysInfo::NumberOfProcessors() / 2);
122 content::ContentTestLauncherDelegate launcher_delegate
;
123 return LaunchTests(&launcher_delegate
, default_jobs
, argc
, argv
);