blob: de5ba9ed7db92a09b1697b945e11afafc004b2fb [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"
Mostyn Bramley-Moored5588cf2017-07-01 12:57:1815#include "base/test/launcher/test_launcher.h"
[email protected]96f503fe2013-05-16 19:41:5116#include "base/test/test_suite.h"
[email protected]a88f6362014-03-18 04:25:3517#include "base/test/test_timeouts.h"
avi66a07722015-12-25 23:38:1218#include "build/build_config.h"
[email protected]96f503fe2013-05-16 19:41:5119#include "content/public/common/content_switches.h"
20#include "content/public/test/content_test_suite_base.h"
21#include "content/shell/app/shell_main_delegate.h"
[email protected]96f503fe2013-05-16 19:41:5122#include "content/shell/common/shell_switches.h"
[email protected]8a3d2de2014-05-14 12:20:2523#include "media/base/media_switches.h"
[email protected]96f503fe2013-05-16 19:41:5124#include "testing/gtest/include/gtest/gtest.h"
25
baixo3a3c88a2014-10-28 11:52:2126#ifdef V8_USE_EXTERNAL_STARTUP_DATA
oth05c26fde2015-04-05 14:30:5727#include "gin/v8_initializer.h"
baixo3a3c88a2014-10-28 11:52:2128#endif
29
[email protected]96f503fe2013-05-16 19:41:5130#if defined(OS_ANDROID)
[email protected]aaf68892013-07-18 00:11:3031#include "base/message_loop/message_loop.h"
[email protected]1c142a52014-04-05 20:14:1732#include "content/app/mojo/mojo_init.h"
[email protected]a88f6362014-03-18 04:25:3533#include "content/common/url_schemes.h"
34#include "content/public/common/content_paths.h"
[email protected]c48fece02013-06-19 12:01:4235#include "content/public/test/nested_message_pump_android.h"
[email protected]a88f6362014-03-18 04:25:3536#include "content/shell/browser/shell_content_browser_client.h"
37#include "content/shell/common/shell_content_client.h"
38#include "ui/base/ui_base_paths.h"
[email protected]96f503fe2013-05-16 19:41:5139#endif
40
[email protected]96f503fe2013-05-16 19:41:5141namespace content {
42
[email protected]96f503fe2013-05-16 19:41:5143#if defined(OS_ANDROID)
dcheng6003e0b2016-04-09 18:42:3444std::unique_ptr<base::MessagePump> CreateMessagePumpForUI() {
45 return std::unique_ptr<base::MessagePump>(new NestedMessagePumpAndroid());
[email protected]96f503fe2013-05-16 19:41:5146};
47#endif
48
49class ContentBrowserTestSuite : public ContentTestSuiteBase {
50 public:
51 ContentBrowserTestSuite(int argc, char** argv)
52 : ContentTestSuiteBase(argc, argv) {
53 }
dchenge933b3e2014-10-21 11:44:0954 ~ContentBrowserTestSuite() override {}
[email protected]96f503fe2013-05-16 19:41:5155
56 protected:
dchenge933b3e2014-10-21 11:44:0957 void Initialize() override {
[email protected]96f503fe2013-05-16 19:41:5158#if defined(OS_ANDROID)
[email protected]49f8a922014-06-11 14:35:5759 base::i18n::AllowMultipleInitializeCallsForTesting();
60 base::i18n::InitializeICU();
61
baixo3a3c88a2014-10-28 11:52:2162#ifdef V8_USE_EXTERNAL_STARTUP_DATA
oth05c26fde2015-04-05 14:30:5763 gin::V8Initializer::LoadV8Snapshot();
erikcorryc94eff12015-06-08 11:29:1664 gin::V8Initializer::LoadV8Natives();
baixo3a3c88a2014-10-28 11:52:2165#endif
66
[email protected]96f503fe2013-05-16 19:41:5167 // This needs to be done before base::TestSuite::Initialize() is called,
68 // as it also tries to set MessagePumpForUIFactory.
69 if (!base::MessageLoop::InitMessagePumpForUIFactory(
70 &CreateMessagePumpForUI))
[email protected]efde84b02013-11-23 04:18:2071 VLOG(0) << "MessagePumpForUIFactory already set, unable to override.";
[email protected]a88f6362014-03-18 04:25:3572
73 // For all other platforms, we call ContentMain for browser tests which goes
74 // through the normal browser initialization paths. For Android, we must set
75 // things up manually.
76 content_client_.reset(new ShellContentClient);
77 browser_content_client_.reset(new ShellContentBrowserClient());
78 SetContentClient(content_client_.get());
79 SetBrowserClientForTesting(browser_content_client_.get());
80
81 content::RegisterContentSchemes(false);
82 RegisterPathProvider();
83 ui::RegisterPathProvider();
84 RegisterInProcessThreads();
[email protected]96aca422014-04-03 20:39:3285
[email protected]96aca422014-04-03 20:39:3286 InitializeMojo();
87#endif
88
[email protected]96f503fe2013-05-16 19:41:5189 ContentTestSuiteBase::Initialize();
[email protected]96f503fe2013-05-16 19:41:5190 }
91
[email protected]a88f6362014-03-18 04:25:3592#if defined(OS_ANDROID)
dcheng6003e0b2016-04-09 18:42:3493 std::unique_ptr<ShellContentClient> content_client_;
94 std::unique_ptr<ShellContentBrowserClient> browser_content_client_;
[email protected]a88f6362014-03-18 04:25:3595#endif
[email protected]96f503fe2013-05-16 19:41:5196
97 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite);
98};
99
100class ContentTestLauncherDelegate : public TestLauncherDelegate {
101 public:
102 ContentTestLauncherDelegate() {}
dchenge933b3e2014-10-21 11:44:09103 ~ContentTestLauncherDelegate() override {}
[email protected]96f503fe2013-05-16 19:41:51104
dchenge933b3e2014-10-21 11:44:09105 int RunTestSuite(int argc, char** argv) override {
[email protected]96f503fe2013-05-16 19:41:51106 return ContentBrowserTestSuite(argc, argv).Run();
107 }
108
dchenge933b3e2014-10-21 11:44:09109 bool AdjustChildProcessCommandLine(
avi83883c82014-12-23 00:08:49110 base::CommandLine* command_line,
dchenge933b3e2014-10-21 11:44:09111 const base::FilePath& temp_data_dir) override {
[email protected]96f503fe2013-05-16 19:41:51112 command_line->AppendSwitchPath(switches::kContentShellDataPath,
113 temp_data_dir);
114 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
115 return true;
116 }
117
118 protected:
dchenge933b3e2014-10-21 11:44:09119 ContentMainDelegate* CreateContentMainDelegate() override {
[email protected]96f503fe2013-05-16 19:41:51120 return new ShellMainDelegate();
121 }
122
123 private:
124 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate);
125};
126
127} // namespace content
128
[email protected]bb36d822011-09-30 20:55:09129int main(int argc, char** argv) {
Mostyn Bramley-Moored5588cf2017-07-01 12:57:18130 base::CommandLine::Init(argc, argv);
131 size_t parallel_jobs = base::NumParallelJobs();
132 if (parallel_jobs > 1U) {
133 parallel_jobs /= 2U;
134 }
[email protected]bdcf9152012-07-19 17:43:21135 content::ContentTestLauncherDelegate launcher_delegate;
Mostyn Bramley-Moored5588cf2017-07-01 12:57:18136 return LaunchTests(&launcher_delegate, parallel_jobs, argc, argv);
[email protected]76df8e362011-09-30 21:23:58137}