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