[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 7d855a1 | 2012-06-04 06:08:09 | [diff] [blame] | 5 | #include "content/public/test/test_launcher.h" |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 6 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 7 | #include "base/base_paths.h" |
| 8 | #include "base/command_line.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 9 | #include "base/debug/stack_trace.h" |
[email protected] | 49f8a92 | 2014-06-11 14:35:57 | [diff] [blame] | 10 | #include "base/i18n/icu_util.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 11 | #include "base/logging.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 13 | #include "base/process/memory.h" |
[email protected] | 0f79893 | 2013-10-28 21:54:54 | [diff] [blame] | 14 | #include "base/sys_info.h" |
Mostyn Bramley-Moore | d5588cf | 2017-07-01 12:57:18 | [diff] [blame^] | 15 | #include "base/test/launcher/test_launcher.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 16 | #include "base/test/test_suite.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 17 | #include "base/test/test_timeouts.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 18 | #include "build/build_config.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 19 | #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] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 22 | #include "content/shell/common/shell_switches.h" |
[email protected] | 8a3d2de | 2014-05-14 12:20:25 | [diff] [blame] | 23 | #include "media/base/media_switches.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 24 | #include "testing/gtest/include/gtest/gtest.h" |
| 25 | |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 26 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 27 | #include "gin/v8_initializer.h" |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 28 | #endif |
| 29 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 30 | #if defined(OS_ANDROID) |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 31 | #include "base/message_loop/message_loop.h" |
[email protected] | 1c142a5 | 2014-04-05 20:14:17 | [diff] [blame] | 32 | #include "content/app/mojo/mojo_init.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 33 | #include "content/common/url_schemes.h" |
| 34 | #include "content/public/common/content_paths.h" |
[email protected] | c48fece0 | 2013-06-19 12:01:42 | [diff] [blame] | 35 | #include "content/public/test/nested_message_pump_android.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 36 | #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] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 39 | #endif |
| 40 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 41 | namespace content { |
| 42 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 43 | #if defined(OS_ANDROID) |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 44 | std::unique_ptr<base::MessagePump> CreateMessagePumpForUI() { |
| 45 | return std::unique_ptr<base::MessagePump>(new NestedMessagePumpAndroid()); |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 46 | }; |
| 47 | #endif |
| 48 | |
| 49 | class ContentBrowserTestSuite : public ContentTestSuiteBase { |
| 50 | public: |
| 51 | ContentBrowserTestSuite(int argc, char** argv) |
| 52 | : ContentTestSuiteBase(argc, argv) { |
| 53 | } |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 54 | ~ContentBrowserTestSuite() override {} |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 55 | |
| 56 | protected: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 57 | void Initialize() override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 58 | #if defined(OS_ANDROID) |
[email protected] | 49f8a92 | 2014-06-11 14:35:57 | [diff] [blame] | 59 | base::i18n::AllowMultipleInitializeCallsForTesting(); |
| 60 | base::i18n::InitializeICU(); |
| 61 | |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 62 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 63 | gin::V8Initializer::LoadV8Snapshot(); |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 64 | gin::V8Initializer::LoadV8Natives(); |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 65 | #endif |
| 66 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 67 | // 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] | efde84b0 | 2013-11-23 04:18:20 | [diff] [blame] | 71 | VLOG(0) << "MessagePumpForUIFactory already set, unable to override."; |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 72 | |
| 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] | 96aca42 | 2014-04-03 20:39:32 | [diff] [blame] | 85 | |
[email protected] | 96aca42 | 2014-04-03 20:39:32 | [diff] [blame] | 86 | InitializeMojo(); |
| 87 | #endif |
| 88 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 89 | ContentTestSuiteBase::Initialize(); |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 90 | } |
| 91 | |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 92 | #if defined(OS_ANDROID) |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 93 | std::unique_ptr<ShellContentClient> content_client_; |
| 94 | std::unique_ptr<ShellContentBrowserClient> browser_content_client_; |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 95 | #endif |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 96 | |
| 97 | DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite); |
| 98 | }; |
| 99 | |
| 100 | class ContentTestLauncherDelegate : public TestLauncherDelegate { |
| 101 | public: |
| 102 | ContentTestLauncherDelegate() {} |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 103 | ~ContentTestLauncherDelegate() override {} |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 104 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 105 | int RunTestSuite(int argc, char** argv) override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 106 | return ContentBrowserTestSuite(argc, argv).Run(); |
| 107 | } |
| 108 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 109 | bool AdjustChildProcessCommandLine( |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 110 | base::CommandLine* command_line, |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 111 | const base::FilePath& temp_data_dir) override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 112 | command_line->AppendSwitchPath(switches::kContentShellDataPath, |
| 113 | temp_data_dir); |
| 114 | command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | protected: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 119 | ContentMainDelegate* CreateContentMainDelegate() override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 120 | return new ShellMainDelegate(); |
| 121 | } |
| 122 | |
| 123 | private: |
| 124 | DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); |
| 125 | }; |
| 126 | |
| 127 | } // namespace content |
| 128 | |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 129 | int main(int argc, char** argv) { |
Mostyn Bramley-Moore | d5588cf | 2017-07-01 12:57:18 | [diff] [blame^] | 130 | base::CommandLine::Init(argc, argv); |
| 131 | size_t parallel_jobs = base::NumParallelJobs(); |
| 132 | if (parallel_jobs > 1U) { |
| 133 | parallel_jobs /= 2U; |
| 134 | } |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 135 | content::ContentTestLauncherDelegate launcher_delegate; |
Mostyn Bramley-Moore | d5588cf | 2017-07-01 12:57:18 | [diff] [blame^] | 136 | return LaunchTests(&launcher_delegate, parallel_jobs, argc, argv); |
[email protected] | 76df8e36 | 2011-09-30 21:23:58 | [diff] [blame] | 137 | } |