blob: 82466e7cb396463276e20007b3031c2a0420c6a4 [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"
12#include "base/path_service.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"
[email protected]96f503fe2013-05-16 19:41:5117#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"
[email protected]96f503fe2013-05-16 19:41:5120#include "content/shell/common/shell_switches.h"
[email protected]8a3d2de2014-05-14 12:20:2521#include "media/base/media_switches.h"
[email protected]96f503fe2013-05-16 19:41:5122#include "testing/gtest/include/gtest/gtest.h"
23
baixo3a3c88a2014-10-28 11:52:2124#ifdef V8_USE_EXTERNAL_STARTUP_DATA
25#include "gin/public/isolate_holder.h"
26#endif
27
[email protected]96f503fe2013-05-16 19:41:5128#if defined(OS_ANDROID)
[email protected]aaf68892013-07-18 00:11:3029#include "base/message_loop/message_loop.h"
[email protected]1c142a52014-04-05 20:14:1730#include "content/app/mojo/mojo_init.h"
[email protected]a88f6362014-03-18 04:25:3531#include "content/common/url_schemes.h"
32#include "content/public/common/content_paths.h"
[email protected]c48fece02013-06-19 12:01:4233#include "content/public/test/nested_message_pump_android.h"
[email protected]a88f6362014-03-18 04:25:3534#include "content/shell/browser/shell_content_browser_client.h"
35#include "content/shell/common/shell_content_client.h"
36#include "ui/base/ui_base_paths.h"
[email protected]96f503fe2013-05-16 19:41:5137#endif
38
[email protected]96f503fe2013-05-16 19:41:5139namespace content {
40
[email protected]96f503fe2013-05-16 19:41:5141#if defined(OS_ANDROID)
[email protected]eed33182014-03-07 17:03:5442scoped_ptr<base::MessagePump> CreateMessagePumpForUI() {
43 return scoped_ptr<base::MessagePump>(new NestedMessagePumpAndroid());
[email protected]96f503fe2013-05-16 19:41:5144};
45#endif
46
47class ContentBrowserTestSuite : public ContentTestSuiteBase {
48 public:
49 ContentBrowserTestSuite(int argc, char** argv)
50 : ContentTestSuiteBase(argc, argv) {
51 }
dchenge933b3e2014-10-21 11:44:0952 ~ContentBrowserTestSuite() override {}
[email protected]96f503fe2013-05-16 19:41:5153
54 protected:
dchenge933b3e2014-10-21 11:44:0955 void Initialize() override {
[email protected]96f503fe2013-05-16 19:41:5156#if defined(OS_ANDROID)
[email protected]49f8a922014-06-11 14:35:5757 base::i18n::AllowMultipleInitializeCallsForTesting();
58 base::i18n::InitializeICU();
59
baixo3a3c88a2014-10-28 11:52:2160#ifdef V8_USE_EXTERNAL_STARTUP_DATA
61 gin::IsolateHolder::LoadV8Snapshot();
62#endif
63
[email protected]96f503fe2013-05-16 19:41:5164 // This needs to be done before base::TestSuite::Initialize() is called,
65 // as it also tries to set MessagePumpForUIFactory.
66 if (!base::MessageLoop::InitMessagePumpForUIFactory(
67 &CreateMessagePumpForUI))
[email protected]efde84b02013-11-23 04:18:2068 VLOG(0) << "MessagePumpForUIFactory already set, unable to override.";
[email protected]a88f6362014-03-18 04:25:3569
70 // For all other platforms, we call ContentMain for browser tests which goes
71 // through the normal browser initialization paths. For Android, we must set
72 // things up manually.
73 content_client_.reset(new ShellContentClient);
74 browser_content_client_.reset(new ShellContentBrowserClient());
75 SetContentClient(content_client_.get());
76 SetBrowserClientForTesting(browser_content_client_.get());
77
78 content::RegisterContentSchemes(false);
79 RegisterPathProvider();
80 ui::RegisterPathProvider();
81 RegisterInProcessThreads();
[email protected]96aca422014-04-03 20:39:3282
[email protected]96aca422014-04-03 20:39:3283 InitializeMojo();
84#endif
85
[email protected]96f503fe2013-05-16 19:41:5186 ContentTestSuiteBase::Initialize();
[email protected]96f503fe2013-05-16 19:41:5187 }
88
[email protected]a88f6362014-03-18 04:25:3589#if defined(OS_ANDROID)
[email protected]96aca422014-04-03 20:39:3290 scoped_ptr<ShellContentClient> content_client_;
[email protected]a88f6362014-03-18 04:25:3591 scoped_ptr<ShellContentBrowserClient> browser_content_client_;
92#endif
[email protected]96f503fe2013-05-16 19:41:5193
94 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite);
95};
96
97class ContentTestLauncherDelegate : public TestLauncherDelegate {
98 public:
99 ContentTestLauncherDelegate() {}
dchenge933b3e2014-10-21 11:44:09100 ~ContentTestLauncherDelegate() override {}
[email protected]96f503fe2013-05-16 19:41:51101
dchenge933b3e2014-10-21 11:44:09102 int RunTestSuite(int argc, char** argv) override {
[email protected]96f503fe2013-05-16 19:41:51103 return ContentBrowserTestSuite(argc, argv).Run();
104 }
105
dchenge933b3e2014-10-21 11:44:09106 bool AdjustChildProcessCommandLine(
107 CommandLine* command_line,
108 const base::FilePath& temp_data_dir) override {
[email protected]96f503fe2013-05-16 19:41:51109 command_line->AppendSwitchPath(switches::kContentShellDataPath,
110 temp_data_dir);
111 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
[email protected]50634eb2013-06-24 06:14:34112 command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);
[email protected]96f503fe2013-05-16 19:41:51113 return true;
114 }
115
116 protected:
dchenge933b3e2014-10-21 11:44:09117 ContentMainDelegate* CreateContentMainDelegate() override {
[email protected]96f503fe2013-05-16 19:41:51118 return new ShellMainDelegate();
119 }
120
121 private:
122 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate);
123};
124
125} // namespace content
126
[email protected]bb36d822011-09-30 20:55:09127int main(int argc, char** argv) {
[email protected]0f798932013-10-28 21:54:54128 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
[email protected]bdcf9152012-07-19 17:43:21129 content::ContentTestLauncherDelegate launcher_delegate;
[email protected]0f798932013-10-28 21:54:54130 return LaunchTests(&launcher_delegate, default_jobs, argc, argv);
[email protected]76df8e362011-09-30 21:23:58131}