blob: 00e121de7a90b82e3c1f91838974f9fa5b24d951 [file] [log] [blame]
[email protected]f573ed6b2012-02-10 15:58:521// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]bb36d822011-09-30 20:55:092// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]7d855a12012-06-04 06:08:095#include "content/public/test/test_launcher.h"
[email protected]bb36d822011-09-30 20:55:096
[email protected]96f503fe2013-05-16 19:41:517#include "base/base_paths.h"
8#include "base/command_line.h"
[email protected]a88f6362014-03-18 04:25:359#include "base/debug/stack_trace.h"
[email protected]49f8a922014-06-11 14:35:5710#include "base/i18n/icu_util.h"
[email protected]96f503fe2013-05-16 19:41:5111#include "base/logging.h"
avi66a07722015-12-25 23:38:1212#include "base/macros.h"
[email protected]a88f6362014-03-18 04:25:3513#include "base/process/memory.h"
[email protected]0f798932013-10-28 21:54:5414#include "base/sys_info.h"
[email protected]96f503fe2013-05-16 19:41:5115#include "base/test/test_suite.h"
[email protected]a88f6362014-03-18 04:25:3516#include "base/test/test_timeouts.h"
avi66a07722015-12-25 23:38:1217#include "build/build_config.h"
[email protected]96f503fe2013-05-16 19:41:5118#include "content/public/common/content_switches.h"
19#include "content/public/test/content_test_suite_base.h"
20#include "content/shell/app/shell_main_delegate.h"
[email protected]96f503fe2013-05-16 19:41:5121#include "content/shell/common/shell_switches.h"
[email protected]8a3d2de2014-05-14 12:20:2522#include "media/base/media_switches.h"
[email protected]96f503fe2013-05-16 19:41:5123#include "testing/gtest/include/gtest/gtest.h"
24
baixo3a3c88a2014-10-28 11:52:2125#ifdef V8_USE_EXTERNAL_STARTUP_DATA
oth05c26fde2015-04-05 14:30:5726#include "gin/v8_initializer.h"
baixo3a3c88a2014-10-28 11:52:2127#endif
28
[email protected]96f503fe2013-05-16 19:41:5129#if defined(OS_ANDROID)
[email protected]aaf68892013-07-18 00:11:3030#include "base/message_loop/message_loop.h"
[email protected]1c142a52014-04-05 20:14:1731#include "content/app/mojo/mojo_init.h"
[email protected]a88f6362014-03-18 04:25:3532#include "content/common/url_schemes.h"
33#include "content/public/common/content_paths.h"
[email protected]c48fece02013-06-19 12:01:4234#include "content/public/test/nested_message_pump_android.h"
[email protected]a88f6362014-03-18 04:25:3535#include "content/shell/browser/shell_content_browser_client.h"
36#include "content/shell/common/shell_content_client.h"
37#include "ui/base/ui_base_paths.h"
[email protected]96f503fe2013-05-16 19:41:5138#endif
39
[email protected]96f503fe2013-05-16 19:41:5140namespace content {
41
[email protected]96f503fe2013-05-16 19:41:5142#if defined(OS_ANDROID)
dcheng6003e0b2016-04-09 18:42:3443std::unique_ptr<base::MessagePump> CreateMessagePumpForUI() {
44 return std::unique_ptr<base::MessagePump>(new NestedMessagePumpAndroid());
[email protected]96f503fe2013-05-16 19:41:5145};
46#endif
47
48class ContentBrowserTestSuite : public ContentTestSuiteBase {
49 public:
50 ContentBrowserTestSuite(int argc, char** argv)
51 : ContentTestSuiteBase(argc, argv) {
52 }
dchenge933b3e2014-10-21 11:44:0953 ~ContentBrowserTestSuite() override {}
[email protected]96f503fe2013-05-16 19:41:5154
55 protected:
dchenge933b3e2014-10-21 11:44:0956 void Initialize() override {
[email protected]96f503fe2013-05-16 19:41:5157#if defined(OS_ANDROID)
[email protected]49f8a922014-06-11 14:35:5758 base::i18n::AllowMultipleInitializeCallsForTesting();
59 base::i18n::InitializeICU();
60
baixo3a3c88a2014-10-28 11:52:2161#ifdef V8_USE_EXTERNAL_STARTUP_DATA
oth05c26fde2015-04-05 14:30:5762 gin::V8Initializer::LoadV8Snapshot();
erikcorryc94eff12015-06-08 11:29:1663 gin::V8Initializer::LoadV8Natives();
baixo3a3c88a2014-10-28 11:52:2164#endif
65
[email protected]96f503fe2013-05-16 19:41:5166 // This needs to be done before base::TestSuite::Initialize() is called,
67 // as it also tries to set MessagePumpForUIFactory.
68 if (!base::MessageLoop::InitMessagePumpForUIFactory(
69 &CreateMessagePumpForUI))
[email protected]efde84b02013-11-23 04:18:2070 VLOG(0) << "MessagePumpForUIFactory already set, unable to override.";
[email protected]a88f6362014-03-18 04:25:3571
72 // For all other platforms, we call ContentMain for browser tests which goes
73 // through the normal browser initialization paths. For Android, we must set
74 // things up manually.
75 content_client_.reset(new ShellContentClient);
76 browser_content_client_.reset(new ShellContentBrowserClient());
77 SetContentClient(content_client_.get());
78 SetBrowserClientForTesting(browser_content_client_.get());
79
80 content::RegisterContentSchemes(false);
81 RegisterPathProvider();
82 ui::RegisterPathProvider();
83 RegisterInProcessThreads();
[email protected]96aca422014-04-03 20:39:3284
[email protected]96aca422014-04-03 20:39:3285 InitializeMojo();
86#endif
87
[email protected]96f503fe2013-05-16 19:41:5188 ContentTestSuiteBase::Initialize();
[email protected]96f503fe2013-05-16 19:41:5189 }
90
[email protected]a88f6362014-03-18 04:25:3591#if defined(OS_ANDROID)
dcheng6003e0b2016-04-09 18:42:3492 std::unique_ptr<ShellContentClient> content_client_;
93 std::unique_ptr<ShellContentBrowserClient> browser_content_client_;
[email protected]a88f6362014-03-18 04:25:3594#endif
[email protected]96f503fe2013-05-16 19:41:5195
96 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite);
97};
98
99class ContentTestLauncherDelegate : public TestLauncherDelegate {
100 public:
101 ContentTestLauncherDelegate() {}
dchenge933b3e2014-10-21 11:44:09102 ~ContentTestLauncherDelegate() override {}
[email protected]96f503fe2013-05-16 19:41:51103
dchenge933b3e2014-10-21 11:44:09104 int RunTestSuite(int argc, char** argv) override {
[email protected]96f503fe2013-05-16 19:41:51105 return ContentBrowserTestSuite(argc, argv).Run();
106 }
107
dchenge933b3e2014-10-21 11:44:09108 bool AdjustChildProcessCommandLine(
avi83883c82014-12-23 00:08:49109 base::CommandLine* command_line,
dchenge933b3e2014-10-21 11:44:09110 const base::FilePath& temp_data_dir) override {
[email protected]96f503fe2013-05-16 19:41:51111 command_line->AppendSwitchPath(switches::kContentShellDataPath,
112 temp_data_dir);
113 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
114 return true;
115 }
116
117 protected:
dchenge933b3e2014-10-21 11:44:09118 ContentMainDelegate* CreateContentMainDelegate() override {
[email protected]96f503fe2013-05-16 19:41:51119 return new ShellMainDelegate();
120 }
121
122 private:
123 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate);
124};
125
126} // namespace content
127
[email protected]bb36d822011-09-30 20:55:09128int main(int argc, char** argv) {
[email protected]0f798932013-10-28 21:54:54129 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
[email protected]bdcf9152012-07-19 17:43:21130 content::ContentTestLauncherDelegate launcher_delegate;
[email protected]0f798932013-10-28 21:54:54131 return LaunchTests(&launcher_delegate, default_jobs, argc, argv);
[email protected]76df8e362011-09-30 21:23:58132}