[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" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 15 | #include "base/test/test_suite.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 16 | #include "base/test/test_timeouts.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 17 | #include "build/build_config.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 18 | #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] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 21 | #include "content/shell/common/shell_switches.h" |
[email protected] | 8a3d2de | 2014-05-14 12:20:25 | [diff] [blame] | 22 | #include "media/base/media_switches.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 23 | #include "testing/gtest/include/gtest/gtest.h" |
| 24 | |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 25 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 26 | #include "gin/v8_initializer.h" |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 27 | #endif |
| 28 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 29 | #if defined(OS_ANDROID) |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 30 | #include "base/message_loop/message_loop.h" |
[email protected] | 1c142a5 | 2014-04-05 20:14:17 | [diff] [blame] | 31 | #include "content/app/mojo/mojo_init.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 32 | #include "content/common/url_schemes.h" |
| 33 | #include "content/public/common/content_paths.h" |
[email protected] | c48fece0 | 2013-06-19 12:01:42 | [diff] [blame] | 34 | #include "content/public/test/nested_message_pump_android.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 35 | #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] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 38 | #endif |
| 39 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 40 | namespace content { |
| 41 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 42 | #if defined(OS_ANDROID) |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame^] | 43 | std::unique_ptr<base::MessagePump> CreateMessagePumpForUI() { |
| 44 | return std::unique_ptr<base::MessagePump>(new NestedMessagePumpAndroid()); |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 45 | }; |
| 46 | #endif |
| 47 | |
| 48 | class ContentBrowserTestSuite : public ContentTestSuiteBase { |
| 49 | public: |
| 50 | ContentBrowserTestSuite(int argc, char** argv) |
| 51 | : ContentTestSuiteBase(argc, argv) { |
| 52 | } |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 53 | ~ContentBrowserTestSuite() override {} |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 54 | |
| 55 | protected: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 56 | void Initialize() override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 57 | #if defined(OS_ANDROID) |
[email protected] | 49f8a92 | 2014-06-11 14:35:57 | [diff] [blame] | 58 | base::i18n::AllowMultipleInitializeCallsForTesting(); |
| 59 | base::i18n::InitializeICU(); |
| 60 | |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 61 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 62 | gin::V8Initializer::LoadV8Snapshot(); |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 63 | gin::V8Initializer::LoadV8Natives(); |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 64 | #endif |
| 65 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 66 | // 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] | efde84b0 | 2013-11-23 04:18:20 | [diff] [blame] | 70 | VLOG(0) << "MessagePumpForUIFactory already set, unable to override."; |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 71 | |
| 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] | 96aca42 | 2014-04-03 20:39:32 | [diff] [blame] | 84 | |
[email protected] | 96aca42 | 2014-04-03 20:39:32 | [diff] [blame] | 85 | InitializeMojo(); |
| 86 | #endif |
| 87 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 88 | ContentTestSuiteBase::Initialize(); |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 91 | #if defined(OS_ANDROID) |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame^] | 92 | std::unique_ptr<ShellContentClient> content_client_; |
| 93 | std::unique_ptr<ShellContentBrowserClient> browser_content_client_; |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 94 | #endif |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 95 | |
| 96 | DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite); |
| 97 | }; |
| 98 | |
| 99 | class ContentTestLauncherDelegate : public TestLauncherDelegate { |
| 100 | public: |
| 101 | ContentTestLauncherDelegate() {} |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 102 | ~ContentTestLauncherDelegate() override {} |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 103 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 104 | int RunTestSuite(int argc, char** argv) override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 105 | return ContentBrowserTestSuite(argc, argv).Run(); |
| 106 | } |
| 107 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 108 | bool AdjustChildProcessCommandLine( |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 109 | base::CommandLine* command_line, |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 110 | const base::FilePath& temp_data_dir) override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 111 | command_line->AppendSwitchPath(switches::kContentShellDataPath, |
| 112 | temp_data_dir); |
| 113 | command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | protected: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 118 | ContentMainDelegate* CreateContentMainDelegate() override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 119 | return new ShellMainDelegate(); |
| 120 | } |
| 121 | |
| 122 | private: |
| 123 | DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); |
| 124 | }; |
| 125 | |
| 126 | } // namespace content |
| 127 | |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 128 | int main(int argc, char** argv) { |
[email protected] | 0f79893 | 2013-10-28 21:54:54 | [diff] [blame] | 129 | int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 130 | content::ContentTestLauncherDelegate launcher_delegate; |
[email protected] | 0f79893 | 2013-10-28 21:54:54 | [diff] [blame] | 131 | return LaunchTests(&launcher_delegate, default_jobs, argc, argv); |
[email protected] | 76df8e36 | 2011-09-30 21:23:58 | [diff] [blame] | 132 | } |