| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/stack_trace.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/process/memory.h" |
| 11 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 12 #include "base/test/test_suite.h" | 14 #include "base/test/test_suite.h" |
| 15 #include "base/test/test_timeouts.h" |
| 13 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/test/content_test_suite_base.h" | 17 #include "content/public/test/content_test_suite_base.h" |
| 15 #include "content/shell/app/shell_main_delegate.h" | 18 #include "content/shell/app/shell_main_delegate.h" |
| 16 #include "content/shell/browser/shell_content_browser_client.h" | |
| 17 #include "content/shell/common/shell_content_client.h" | |
| 18 #include "content/shell/common/shell_switches.h" | 19 #include "content/shell/common/shell_switches.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
| 22 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 24 #include "content/common/url_schemes.h" |
| 25 #include "content/public/common/content_paths.h" |
| 23 #include "content/public/test/nested_message_pump_android.h" | 26 #include "content/public/test/nested_message_pump_android.h" |
| 27 #include "content/shell/browser/shell_content_browser_client.h" |
| 28 #include "content/shell/common/shell_content_client.h" |
| 29 #include "ui/base/ui_base_paths.h" |
| 24 #endif | 30 #endif |
| 25 | 31 |
| 26 #if defined(OS_WIN) | |
| 27 #include "content/public/app/startup_helper_win.h" | |
| 28 #include "sandbox/win/src/sandbox_types.h" | |
| 29 #endif // defined(OS_WIN) | |
| 30 | |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 class ContentShellTestSuiteInitializer | |
| 34 : public testing::EmptyTestEventListener { | |
| 35 public: | |
| 36 ContentShellTestSuiteInitializer() { | |
| 37 } | |
| 38 | |
| 39 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | |
| 40 content_client_.reset(new ShellContentClient); | |
| 41 browser_content_client_.reset(new ShellContentBrowserClient()); | |
| 42 SetContentClient(content_client_.get()); | |
| 43 SetBrowserClientForTesting(browser_content_client_.get()); | |
| 44 } | |
| 45 | |
| 46 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | |
| 47 #if !defined(OS_ANDROID) | |
| 48 // On Android, production code doesn't reset ContentClient during shutdown. | |
| 49 // We try to do the same thing as production. Refer to crbug.com/181069. | |
| 50 browser_content_client_.reset(); | |
| 51 content_client_.reset(); | |
| 52 SetContentClient(NULL); | |
| 53 #endif | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 scoped_ptr<ShellContentClient> content_client_; | |
| 58 scoped_ptr<ShellContentBrowserClient> browser_content_client_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(ContentShellTestSuiteInitializer); | |
| 61 }; | |
| 62 | |
| 63 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
| 64 scoped_ptr<base::MessagePump> CreateMessagePumpForUI() { | 35 scoped_ptr<base::MessagePump> CreateMessagePumpForUI() { |
| 65 return scoped_ptr<base::MessagePump>(new NestedMessagePumpAndroid()); | 36 return scoped_ptr<base::MessagePump>(new NestedMessagePumpAndroid()); |
| 66 }; | 37 }; |
| 67 #endif | 38 #endif |
| 68 | 39 |
| 69 class ContentBrowserTestSuite : public ContentTestSuiteBase { | 40 class ContentBrowserTestSuite : public ContentTestSuiteBase { |
| 70 public: | 41 public: |
| 71 ContentBrowserTestSuite(int argc, char** argv) | 42 ContentBrowserTestSuite(int argc, char** argv) |
| 72 : ContentTestSuiteBase(argc, argv) { | 43 : ContentTestSuiteBase(argc, argv) { |
| 73 } | 44 } |
| 74 virtual ~ContentBrowserTestSuite() { | 45 virtual ~ContentBrowserTestSuite() { |
| 75 } | 46 } |
| 76 | 47 |
| 77 protected: | 48 protected: |
| 78 virtual void Initialize() OVERRIDE { | 49 virtual void Initialize() OVERRIDE { |
| 79 | 50 |
| 80 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
| 81 // This needs to be done before base::TestSuite::Initialize() is called, | 52 // This needs to be done before base::TestSuite::Initialize() is called, |
| 82 // as it also tries to set MessagePumpForUIFactory. | 53 // as it also tries to set MessagePumpForUIFactory. |
| 83 if (!base::MessageLoop::InitMessagePumpForUIFactory( | 54 if (!base::MessageLoop::InitMessagePumpForUIFactory( |
| 84 &CreateMessagePumpForUI)) | 55 &CreateMessagePumpForUI)) |
| 85 VLOG(0) << "MessagePumpForUIFactory already set, unable to override."; | 56 VLOG(0) << "MessagePumpForUIFactory already set, unable to override."; |
| 57 |
| 58 // For all other platforms, we call ContentMain for browser tests which goes |
| 59 // through the normal browser initialization paths. For Android, we must set |
| 60 // things up manually. |
| 61 content_client_.reset(new ShellContentClient); |
| 62 browser_content_client_.reset(new ShellContentBrowserClient()); |
| 63 SetContentClient(content_client_.get()); |
| 64 SetBrowserClientForTesting(browser_content_client_.get()); |
| 65 |
| 66 content::RegisterContentSchemes(false); |
| 67 RegisterPathProvider(); |
| 68 ui::RegisterPathProvider(); |
| 69 RegisterInProcessThreads(); |
| 86 #endif | 70 #endif |
| 87 | 71 |
| 88 ContentTestSuiteBase::Initialize(); | 72 ContentTestSuiteBase::Initialize(); |
| 89 | |
| 90 testing::TestEventListeners& listeners = | |
| 91 testing::UnitTest::GetInstance()->listeners(); | |
| 92 listeners.Append(new ContentShellTestSuiteInitializer); | |
| 93 } | |
| 94 virtual void Shutdown() OVERRIDE { | |
| 95 base::TestSuite::Shutdown(); | |
| 96 } | 73 } |
| 97 | 74 |
| 98 virtual ContentClient* CreateClientForInitialization() OVERRIDE { | 75 #if defined(OS_ANDROID) |
| 99 return new ShellContentClient(); | 76 scoped_ptr<ShellContentClient> content_client_;» |
| 100 } | 77 scoped_ptr<ShellContentBrowserClient> browser_content_client_; |
| 78 #endif |
| 101 | 79 |
| 102 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite); | 80 DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite); |
| 103 }; | 81 }; |
| 104 | 82 |
| 105 class ContentTestLauncherDelegate : public TestLauncherDelegate { | 83 class ContentTestLauncherDelegate : public TestLauncherDelegate { |
| 106 public: | 84 public: |
| 107 ContentTestLauncherDelegate() {} | 85 ContentTestLauncherDelegate() {} |
| 108 virtual ~ContentTestLauncherDelegate() {} | 86 virtual ~ContentTestLauncherDelegate() {} |
| 109 | 87 |
| 110 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { | 88 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); | 107 DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate); |
| 130 }; | 108 }; |
| 131 | 109 |
| 132 } // namespace content | 110 } // namespace content |
| 133 | 111 |
| 134 int main(int argc, char** argv) { | 112 int main(int argc, char** argv) { |
| 135 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); | 113 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); |
| 136 content::ContentTestLauncherDelegate launcher_delegate; | 114 content::ContentTestLauncherDelegate launcher_delegate; |
| 137 return LaunchTests(&launcher_delegate, default_jobs, argc, argv); | 115 return LaunchTests(&launcher_delegate, default_jobs, argc, argv); |
| 138 } | 116 } |
| OLD | NEW |