From a88f63686baa4751ab6638413ca7b62f8a3c2738 Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Tue, 18 Mar 2014 04:25:35 +0000 Subject: [PATCH] Run ContentMain in a browser_test's browser process. This removes duplication of code in the browser test harness for setting up the browser process, and also ensures that initialization code in ContentMainRunner runs. Most of the changes are to unit tests which run in browser test executables. These were getting all the setup that these binaries did for browser tests even though they were unit tests. Now they have to explicitly setup objects that they need. This would be done automatically if they were in a unit test binary and therefore using the unit test harness. The goal should be to move these tests to unit test binaries, and make them support launching some tests in separate processes building on the work that Pawel did. BUG=350550 R=sky@chromium.org Review URL: https://codereview.chromium.org/190663012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257597 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/drag_drop/drag_drop_interactive_uitest.cc | 25 +++- ash/test/ash_test_base.cc | 12 ++ ash/test/ash_test_base.h | 2 +- ...ative_cursor_manager_interactive_uitest.cc | 26 +++- base/i18n/icu_util.cc | 27 +++- base/i18n/icu_util.h | 3 + chrome/browser/apps/web_view_browsertest.cc | 1 + chrome/browser/chrome_browser_main.cc | 75 +++++----- chrome/browser/chrome_browser_main_mac.mm | 29 ++-- .../chromeos/login/login_browsertest.cc | 81 +---------- .../chromeos/login/login_utils_browsertest.cc | 18 +++ .../api/bluetooth/bluetooth_apitest.cc | 4 +- .../extensions/api/socket/socket_apitest.cc | 4 + .../web_navigation/web_navigation_apitest.cc | 91 ++---------- .../webrtc_audio_private_browsertest.cc | 9 +- .../extensions/app_background_page_apitest.cc | 13 +- .../desktop_notifications_unittest.cc | 4 + .../policy/policy_prefs_browsertest.cc | 4 +- .../cloud_print_proxy_process_browsertest.cc | 7 + .../content_setting_bubble_cocoa_unittest.mm | 19 ++- ...n_install_dialog_controller_browsertest.mm | 4 +- .../views/bookmarks/bookmark_bar_view_test.cc | 13 ++ chrome/chrome_tests_unit.gypi | 8 +- chrome/interactive_ui_tests.isolate | 1 + ...ome_content_renderer_client_browsertest.cc | 15 +- chrome/renderer/extensions/dispatcher.cc | 8 +- chrome/renderer/extensions/dispatcher.h | 2 +- .../media/cast_session_browsertest.cc | 5 +- .../translate/translate_script_browsertest.cc | 1 + chrome/test/base/browser_perf_tests_main.cc | 10 +- chrome/test/base/browser_tests_main.cc | 8 +- chrome/test/base/chrome_render_view_test.cc | 31 +++- chrome/test/base/chrome_render_view_test.h | 6 +- chrome/test/base/chrome_test_launcher.cc | 7 - chrome/test/base/chrome_test_suite.cc | 133 +----------------- chrome/test/base/chrome_test_suite.h | 12 -- chrome/test/base/chrome_unit_test_suite.cc | 128 ++++++++++++++++- chrome/test/base/chrome_unit_test_suite.h | 16 ++- chrome/test/base/in_process_browser_test.cc | 45 +++--- chrome/test/base/interactive_ui_tests_main.cc | 2 - chrome/test/base/view_event_test_base.cc | 6 + chrome/test/base/view_event_test_base.h | 2 + chrome/test/nacl/nacl_browsertest_util.cc | 2 +- chrome/test/nacl/nacl_browsertest_util.h | 2 +- chrome/test/ppapi/ppapi_test.cc | 18 +-- chrome/test/ppapi/ppapi_test.h | 1 + chrome/test/pyautolib/pyautolib.cc | 2 - chrome/test/pyautolib/pyautolib.h | 2 - chrome/test/ui/ui_test_suite.cc | 2 - chrome/test/ui/ui_test_suite.h | 2 - content/app/content_main_runner.cc | 15 +- .../render_widget_host_browsertest.cc | 2 +- .../render_widget_host_view_browsertest.cc | 7 +- content/content_tests.gypi | 2 +- content/public/app/content_main.h | 17 ++- content/public/test/browser_test_base.cc | 19 ++- .../public/test/content_test_suite_base.cc | 33 ++--- content/public/test/content_test_suite_base.h | 16 +-- content/public/test/render_view_test.cc | 28 +++- content/public/test/render_view_test.h | 14 +- content/public/test/test_launcher.cc | 65 ++++----- content/public/test/test_launcher.h | 2 + .../browser_plugin_browsertest.cc | 32 +++-- .../browser_plugin_browsertest.h | 6 +- .../browser_render_view_browsertest.cc | 16 +-- .../render_thread_impl_browsertest.cc | 6 + content/renderer/render_view_browsertest.cc | 8 +- .../renderer/shell_content_renderer_client.cc | 11 -- .../renderer/shell_content_renderer_client.h | 2 - content/test/content_browser_test.cc | 44 +++--- content/test/content_browser_test.h | 12 +- content/test/content_test_launcher.cc | 72 ++++------ content/test/content_test_suite.cc | 14 +- content/test/content_test_suite.h | 2 - .../desktop_capture_controller_unittest.cc | 21 ++- .../ui_controls_factory_desktop_aurax11.cc | 2 + ui/views/widget/widget_interactive_uitest.cc | 48 +++++-- 77 files changed, 764 insertions(+), 700 deletions(-) diff --git a/ash/drag_drop/drag_drop_interactive_uitest.cc b/ash/drag_drop/drag_drop_interactive_uitest.cc index bf20f7051167c0..f9b3ceeb1c7801 100644 --- a/ash/drag_drop/drag_drop_interactive_uitest.cc +++ b/ash/drag_drop/drag_drop_interactive_uitest.cc @@ -8,10 +8,14 @@ #include "ash/test/ash_test_base.h" #include "base/bind.h" #include "base/message_loop/message_loop.h" +#include "base/path_service.h" #include "base/strings/utf_string_conversions.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/resource/resource_bundle.h" #include "ui/base/test/ui_controls.h" +#include "ui/base/ui_base_paths.h" +#include "ui/gl/gl_surface.h" #include "ui/views/view.h" #include "ui/views/widget/widget.h" @@ -118,7 +122,26 @@ void DragDropAcrossMultiDisplay_Step1() { } // namespace -typedef test::AshTestBase DragDropTest; +class DragDropTest : public test::AshTestBase { + public: + DragDropTest() {} + virtual ~DragDropTest() {} + + virtual void SetUp() OVERRIDE { + gfx::GLSurface::InitializeOneOffForTests(); + + ui::RegisterPathProvider(); + ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + base::FilePath resources_pack_path; + PathService::Get(base::DIR_MODULE, &resources_pack_path); + resources_pack_path = + resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); + ResourceBundle::GetSharedInstance().AddDataPackFromPath( + resources_pack_path, ui::SCALE_FACTOR_NONE); + + test::AshTestBase::SetUp(); + } +}; #if defined(OS_WIN) #define MAYBE_DragDropAcrossMultiDisplay DISABLED_DragDropAcrossMultiDisplay diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index 9c9cbe30b8c121..1f2156bc42712e 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -48,6 +48,10 @@ #include "win8/test/test_registrar_constants.h" #endif +#if defined(USE_X11) +#include +#endif + namespace ash { namespace test { namespace { @@ -90,6 +94,14 @@ AshTestBase::AshTestBase() : setup_called_(false), teardown_called_(false), start_session_(true) { +#if defined(USE_X11) + // This is needed for tests which use this base class but are run in browser + // test binaries so don't get the default initialization in the unit test + // suite. + XInitThreads(); +#endif + + thread_bundle_.reset(new content::TestBrowserThreadBundle); // Must initialize |ash_test_helper_| here because some tests rely on // AshTestBase methods before they call AshTestBase::SetUp(). ash_test_helper_.reset(new AshTestHelper(base::MessageLoopForUI::current())); diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index 5de30dbd9c3ec6..c7bdbbbe1765aa 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -139,7 +139,7 @@ class AshTestBase : public testing::Test { bool teardown_called_; // |SetUp()| doesn't activate session if this is set to false. bool start_session_; - content::TestBrowserThreadBundle thread_bundle_; + scoped_ptr thread_bundle_; scoped_ptr ash_test_helper_; scoped_ptr event_generator_; #if defined(OS_WIN) diff --git a/ash/wm/ash_native_cursor_manager_interactive_uitest.cc b/ash/wm/ash_native_cursor_manager_interactive_uitest.cc index 9adb85281cdd82..6d2038f8afbb90 100644 --- a/ash/wm/ash_native_cursor_manager_interactive_uitest.cc +++ b/ash/wm/ash_native_cursor_manager_interactive_uitest.cc @@ -8,10 +8,14 @@ #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "ash/test/cursor_manager_test_api.h" +#include "base/path_service.h" #include "base/run_loop.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" +#include "ui/base/resource/resource_bundle.h" #include "ui/base/test/ui_controls.h" +#include "ui/base/ui_base_paths.h" +#include "ui/gl/gl_surface.h" #if defined(USE_X11) #include @@ -22,7 +26,27 @@ namespace ash { using ::wm::CursorManager; -typedef test::AshTestBase AshNativeCursorManagerTest; + +class AshNativeCursorManagerTest : public test::AshTestBase { + public: + AshNativeCursorManagerTest() {} + virtual ~AshNativeCursorManagerTest() {} + + virtual void SetUp() OVERRIDE { + gfx::GLSurface::InitializeOneOffForTests(); + + ui::RegisterPathProvider(); + ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + base::FilePath resources_pack_path; + PathService::Get(base::DIR_MODULE, &resources_pack_path); + resources_pack_path = + resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); + ResourceBundle::GetSharedInstance().AddDataPackFromPath( + resources_pack_path, ui::SCALE_FACTOR_NONE); + + test::AshTestBase::SetUp(); + } +}; namespace { diff --git a/base/i18n/icu_util.cc b/base/i18n/icu_util.cc index bbb73f9f4db88a..b623a32ef7c688 100644 --- a/base/i18n/icu_util.cc +++ b/base/i18n/icu_util.cc @@ -44,14 +44,21 @@ namespace base { namespace i18n { +namespace { + +#if !defined(NDEBUG) +// Assert that we are not called more than once. Even though calling this +// function isn't harmful (ICU can handle it), being called twice probably +// indicates a programming error. +bool g_called_once = false; +bool g_check_called_once = true; +#endif +} + bool InitializeICU() { -#ifndef NDEBUG - // Assert that we are not called more than once. Even though calling this - // function isn't harmful (ICU can handle it), being called twice probably - // indicates a programming error. - static bool called_once = false; - DCHECK(!called_once); - called_once = true; +#if !defined(NDEBUG) + DCHECK(!g_check_called_once || !g_called_once); + g_called_once = true; #endif #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) @@ -124,5 +131,11 @@ bool InitializeICU() { #endif } +void AllowMultipleInitializeCallsForTesting() { +#if !defined(NDEBUG) + g_check_called_once = false; +#endif +} + } // namespace i18n } // namespace base diff --git a/base/i18n/icu_util.h b/base/i18n/icu_util.h index ef5dede235de80..4c1c5fd38a51a4 100644 --- a/base/i18n/icu_util.h +++ b/base/i18n/icu_util.h @@ -14,6 +14,9 @@ namespace i18n { // function should be called before ICU is used. BASE_I18N_EXPORT bool InitializeICU(); +// In a test binary, the call above might occur twice. +BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting(); + } // namespace i18n } // namespace base diff --git a/chrome/browser/apps/web_view_browsertest.cc b/chrome/browser/apps/web_view_browsertest.cc index 5a3b355e4e28cf..ef7e964a2e10f3 100644 --- a/chrome/browser/apps/web_view_browsertest.cc +++ b/chrome/browser/apps/web_view_browsertest.cc @@ -276,6 +276,7 @@ class WebViewTest : public extensions::PlatformAppBrowserTest { } virtual void SetUpOnMainThread() OVERRIDE { + extensions::PlatformAppBrowserTest::SetUpOnMainThread(); const testing::TestInfo* const test_info = testing::UnitTest::GetInstance()->current_test_info(); // Mock out geolocation for geolocation specific tests. diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 2a882f9a5be86b..c03b8a86b34df1 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -868,49 +868,44 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() { // just changed it to include experiments. crash_keys::SetSwitchesFromCommandLine(CommandLine::ForCurrentProcess()); - // If we're running tests (ui_task is non-null), then the ResourceBundle - // has already been initialized. - if (parameters().ui_task && - !local_state_->IsManagedPreference(prefs::kApplicationLocale)) { - browser_process_->SetApplicationLocale("en-US"); - } else { - // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is - // needed when loading the MainMenu.nib and the language doesn't depend on - // anything since it comes from Cocoa. + // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is + // needed when loading the MainMenu.nib and the language doesn't depend on + // anything since it comes from Cocoa. #if defined(OS_MACOSX) - browser_process_->SetApplicationLocale(l10n_util::GetLocaleOverride()); + std::string locale = + parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride(); + browser_process_->SetApplicationLocale(locale); #else - const std::string locale = - local_state_->GetString(prefs::kApplicationLocale); - - // On a POSIX OS other than ChromeOS, the parameter that is passed to the - // method InitSharedInstance is ignored. - - TRACE_EVENT_BEGIN0("startup", - "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); - const std::string loaded_locale = - ResourceBundle::InitSharedInstanceWithLocale(locale, NULL); - TRACE_EVENT_END0("startup", - "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); - - if (loaded_locale.empty() && - !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { - ShowMissingLocaleMessageBox(); - return chrome::RESULT_CODE_MISSING_DATA; - } - CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; - browser_process_->SetApplicationLocale(loaded_locale); - - base::FilePath resources_pack_path; - PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); - { - TRACE_EVENT0("startup", - "ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack"); - ResourceBundle::GetSharedInstance().AddDataPackFromPath( - resources_pack_path, ui::SCALE_FACTOR_NONE); - } -#endif // defined(OS_MACOSX) + const std::string locale = + local_state_->GetString(prefs::kApplicationLocale); + + // On a POSIX OS other than ChromeOS, the parameter that is passed to the + // method InitSharedInstance is ignored. + + TRACE_EVENT_BEGIN0("startup", + "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); + const std::string loaded_locale = + ResourceBundle::InitSharedInstanceWithLocale(locale, NULL); + TRACE_EVENT_END0("startup", + "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); + + if (loaded_locale.empty() && + !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { + ShowMissingLocaleMessageBox(); + return chrome::RESULT_CODE_MISSING_DATA; } + CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; + browser_process_->SetApplicationLocale(loaded_locale); + + base::FilePath resources_pack_path; + PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); + { + TRACE_EVENT0("startup", + "ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack"); + ResourceBundle::GetSharedInstance().AddDataPackFromPath( + resources_pack_path, ui::SCALE_FACTOR_NONE); + } +#endif // defined(OS_MACOSX) #if defined(TOOLKIT_GTK) g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); diff --git a/chrome/browser/chrome_browser_main_mac.mm b/chrome/browser/chrome_browser_main_mac.mm index fa7fbbd92f1691..1535b157cd0205 100644 --- a/chrome/browser/chrome_browser_main_mac.mm +++ b/chrome/browser/chrome_browser_main_mac.mm @@ -174,27 +174,26 @@ void RecordCatSixtyFour() { // Initialize NSApplication using the custom subclass. chrome_browser_application_mac::RegisterBrowserCrApp(); - // If ui_task is not NULL, the app is actually a browser_test, so startup is - // handled outside of BrowserMain (which is what called this). + // If ui_task is not NULL, the app is actually a browser_test. if (!parameters().ui_task) { // The browser process only wants to support the language Cocoa will use, // so force the app locale to be overriden with that value. l10n_util::OverrideLocaleWithCocoaLocale(); - - // Before we load the nib, we need to start up the resource bundle so we - // have the strings avaiable for localization. - // TODO(markusheintz): Read preference pref::kApplicationLocale in order - // to enforce the application locale. - const std::string loaded_locale = - ResourceBundle::InitSharedInstanceWithLocale(std::string(), NULL); - CHECK(!loaded_locale.empty()) << "Default locale could not be found"; - - base::FilePath resources_pack_path; - PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); - ResourceBundle::GetSharedInstance().AddDataPackFromPath( - resources_pack_path, ui::SCALE_FACTOR_NONE); } + // Before we load the nib, we need to start up the resource bundle so we + // have the strings avaiable for localization. + // TODO(markusheintz): Read preference pref::kApplicationLocale in order + // to enforce the application locale. + const std::string loaded_locale = + ResourceBundle::InitSharedInstanceWithLocale(std::string(), NULL); + CHECK(!loaded_locale.empty()) << "Default locale could not be found"; + + base::FilePath resources_pack_path; + PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); + ResourceBundle::GetSharedInstance().AddDataPackFromPath( + resources_pack_path, ui::SCALE_FACTOR_NONE); + // This is a no-op if the KeystoneRegistration framework is not present. // The framework is only distributed with branded Google Chrome builds. [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone]; diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc index 410bad7ac3e08a..9ef5c37fe5f99e 100644 --- a/chrome/browser/chromeos/login/login_browsertest.cc +++ b/chrome/browser/chromeos/login/login_browsertest.cc @@ -4,9 +4,6 @@ #include "ash/shell.h" #include "base/command_line.h" -#include "chrome/browser/chrome_browser_main.h" -#include "chrome/browser/chrome_browser_main_extra_parts.h" -#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/login_display_host_impl.h" #include "chrome/browser/chromeos/login/login_wizard.h" @@ -18,11 +15,9 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/interactive_test_utils.h" +#include "chrome/test/base/tracing.h" #include "chrome/test/base/ui_test_utils.h" #include "chromeos/chromeos_switches.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.h" #include "extensions/browser/extension_system.h" #include "testing/gmock/include/gmock/gmock.h" @@ -67,58 +62,6 @@ class LoginCursorTest : public InProcessBrowserTest { } }; -// Used to add an observer to NotificationService after it's created. -class TestBrowserMainExtraParts - : public ChromeBrowserMainExtraParts, - public content::NotificationObserver { - public: - TestBrowserMainExtraParts() {} - virtual ~TestBrowserMainExtraParts() {} - - // ChromeBrowserMainExtraParts implementation. - virtual void PreEarlyInitialization() OVERRIDE { - registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, - content::NotificationService::AllSources()); - } - - void set_quit_task(const base::Closure& quit_task) { quit_task_ = quit_task; } - - private: - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE { - quit_task_.Run(); - } - - content::NotificationRegistrar registrar_; - base::Closure quit_task_; - - DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts); -}; - -class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { - public: - TestContentBrowserClient() {} - virtual ~TestContentBrowserClient() {} - - virtual content::BrowserMainParts* CreateBrowserMainParts( - const content::MainFunctionParams& parameters) OVERRIDE { - ChromeBrowserMainParts* main_parts = static_cast( - ChromeContentBrowserClient::CreateBrowserMainParts(parameters)); - - browser_main_extra_parts_ = new TestBrowserMainExtraParts(); - main_parts->AddParts(browser_main_extra_parts_); - return main_parts; - } - - TestBrowserMainExtraParts* browser_main_extra_parts_; - - private: - DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient); -}; - - class LoginSigninTest : public InProcessBrowserTest { protected: virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { @@ -126,18 +69,9 @@ class LoginSigninTest : public InProcessBrowserTest { command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); } - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { - content_browser_client_.reset(new TestContentBrowserClient()); - original_content_browser_client_ = content::SetBrowserClientForTesting( - content_browser_client_.get()); - } - - virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { - content::SetBrowserClientForTesting(original_content_browser_client_); + virtual void SetUpOnMainThread() OVERRIDE { + ASSERT_TRUE(tracing::BeginTracingWithWatch("ui", "ui", "ShowLoginWebUI", 1)); } - - scoped_ptr content_browser_client_; - content::ContentBrowserClient* original_content_browser_client_; }; // After a chrome crash, the session manager will restart chrome with @@ -188,11 +122,10 @@ IN_PROC_BROWSER_TEST_F(LoginCursorTest, CursorHidden) { // Verifies that the webui for login comes up successfully. IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) { - scoped_refptr runner = - new content::MessageLoopRunner; - content_browser_client_->browser_main_extra_parts_->set_quit_task( - runner->QuitClosure()); - runner->Run(); + base::TimeDelta no_timeout; + EXPECT_TRUE(tracing::WaitForWatchEvent(no_timeout)); + std::string json_events; + ASSERT_TRUE(tracing::EndTracing(&json_events)); } INSTANTIATE_TEST_CASE_P(LoginUserTestInstantiation, diff --git a/chrome/browser/chromeos/login/login_utils_browsertest.cc b/chrome/browser/chromeos/login/login_utils_browsertest.cc index bb3a75f08eee59..441e39c7e7a3da 100644 --- a/chrome/browser/chromeos/login/login_utils_browsertest.cc +++ b/chrome/browser/chromeos/login/login_utils_browsertest.cc @@ -16,6 +16,7 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/thread.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/input_method/input_method_configuration.h" #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" @@ -34,9 +35,11 @@ #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/rlz/rlz.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" +#include "chrome/test/base/chrome_unit_test_suite.h" #include "chrome/test/base/scoped_testing_local_state.h" #include "chrome/test/base/testing_browser_process.h" #include "chromeos/chromeos_switches.h" @@ -161,6 +164,14 @@ class LoginUtilsTest : public testing::Test, prepared_profile_(NULL) {} virtual void SetUp() OVERRIDE { + ChromeUnitTestSuite::InitializeProviders(); + ChromeUnitTestSuite::InitializeResourceBundle(); + + content_client_.reset(new ChromeContentClient); + content::SetContentClient(content_client_.get()); + browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); + content::SetBrowserClientForTesting(browser_content_client_.get()); + // This test is not a full blown InProcessBrowserTest, and doesn't have // all the usual threads running. However a lot of subsystems pulled from // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that @@ -285,6 +296,10 @@ class LoginUtilsTest : public testing::Test, browser_process_->SetBrowserPolicyConnector(NULL); QuitIOLoop(); RunUntilIdle(); + + browser_content_client_.reset(); + content_client_.reset(); + content::SetContentClient(NULL); } void TearDownOnIO() { @@ -467,6 +482,9 @@ class LoginUtilsTest : public testing::Test, // rely on this being set up. TestingBrowserProcessInitializer initializer_; + scoped_ptr content_client_; + scoped_ptr browser_content_client_; + base::Closure fake_io_thread_work_; base::WaitableEvent fake_io_thread_completion_; base::Thread fake_io_thread_; diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc index 015aae8417f1d7..8d729bf4a3cd82 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc @@ -44,9 +44,11 @@ static const char* kName = "whatsinaname"; class BluetoothApiTest : public ExtensionApiTest { public: - BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} + BluetoothApiTest() {} virtual void SetUpOnMainThread() OVERRIDE { + ExtensionApiTest::SetUpOnMainThread(); + empty_extension_ = utils::CreateEmptyExtension(); SetUpMockAdapter(); profile1_.reset(new testing::NiceMock()); profile2_.reset(new testing::NiceMock()); diff --git a/chrome/browser/extensions/api/socket/socket_apitest.cc b/chrome/browser/extensions/api/socket/socket_apitest.cc index e2c07e9a5d2a92..7d386499307b81 100644 --- a/chrome/browser/extensions/api/socket/socket_apitest.cc +++ b/chrome/browser/extensions/api/socket/socket_apitest.cc @@ -73,6 +73,10 @@ class SocketPpapiTest : public SocketApiTest { // going to move the Pepper API tests to a new place, use a string literal // for now. command_line->AppendSwitch("enable-pepper-testing"); + } + + virtual void SetUpOnMainThread() OVERRIDE { + SocketApiTest::SetUpOnMainThread(); PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir_); app_dir_ = app_dir_.AppendASCII("ppapi/tests/extensions/socket/newlib"); diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc index 6b7cc8794dcef3..60c1012d99fbf0 100644 --- a/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc +++ b/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc @@ -257,75 +257,6 @@ class TestResourceDispatcherHostDelegate DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); }; -// Used to manage the lifetime of the TestResourceDispatcherHostDelegate which -// needs to be deleted before the threads are stopped. -class TestBrowserMainExtraParts : public ChromeBrowserMainExtraParts { - public: - explicit TestBrowserMainExtraParts( - TestNavigationListener* test_navigation_listener) - : test_navigation_listener_(test_navigation_listener) { - } - virtual ~TestBrowserMainExtraParts() {} - - TestResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() { - if (!resource_dispatcher_host_delegate_.get()) { - resource_dispatcher_host_delegate_.reset( - new TestResourceDispatcherHostDelegate( - g_browser_process->prerender_tracker(), - test_navigation_listener_.get())); - } - return resource_dispatcher_host_delegate_.get(); - } - - // ChromeBrowserMainExtraParts implementation. - virtual void PostMainMessageLoopRun() OVERRIDE { - resource_dispatcher_host_delegate_.reset(); - } - - private: - scoped_refptr test_navigation_listener_; - scoped_ptr - resource_dispatcher_host_delegate_; - - DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts); -}; - -// A ContentBrowserClient that doesn't forward the RDH created signal. -class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { - public: - explicit TestContentBrowserClient( - TestNavigationListener* test_navigation_listener) - : test_navigation_listener_(test_navigation_listener) { - } - virtual ~TestContentBrowserClient() {} - - virtual void ResourceDispatcherHostCreated() OVERRIDE { - // Don't invoke ChromeContentBrowserClient::ResourceDispatcherHostCreated. - // It would notify BrowserProcessImpl which would create a - // ChromeResourceDispatcherHostDelegate and other objects. Not creating - // other objects might turn out to be a problem in the future. - content::ResourceDispatcherHost::Get()->SetDelegate( - browser_main_extra_parts_->resource_dispatcher_host_delegate()); - } - - virtual content::BrowserMainParts* CreateBrowserMainParts( - const content::MainFunctionParams& parameters) OVERRIDE { - ChromeBrowserMainParts* main_parts = static_cast( - ChromeContentBrowserClient::CreateBrowserMainParts(parameters)); - - browser_main_extra_parts_ = - new TestBrowserMainExtraParts(test_navigation_listener_.get()); - main_parts->AddParts(browser_main_extra_parts_); - return main_parts; - } - - private: - scoped_refptr test_navigation_listener_; - TestBrowserMainExtraParts* browser_main_extra_parts_; - - DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient); -}; - } // namespace class WebNavigationApiTest : public ExtensionApiTest { @@ -336,12 +267,6 @@ class WebNavigationApiTest : public ExtensionApiTest { virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { ExtensionApiTest::SetUpInProcessBrowserTestFixture(); - test_navigation_listener_ = new TestNavigationListener(); - content_browser_client_.reset( - new TestContentBrowserClient(test_navigation_listener_.get())); - original_content_browser_client_ = content::SetBrowserClientForTesting( - content_browser_client_.get()); - FrameNavigationState::set_allow_extension_scheme(true); CommandLine::ForCurrentProcess()->AppendSwitch( @@ -350,9 +275,15 @@ class WebNavigationApiTest : public ExtensionApiTest { host_resolver()->AddRule("*", "127.0.0.1"); } - virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { - ExtensionApiTest::TearDownInProcessBrowserTestFixture(); - content::SetBrowserClientForTesting(original_content_browser_client_); + virtual void SetUpOnMainThread() OVERRIDE { + ExtensionApiTest::SetUpOnMainThread(); + test_navigation_listener_ = new TestNavigationListener(); + resource_dispatcher_host_delegate_.reset( + new TestResourceDispatcherHostDelegate( + g_browser_process->prerender_tracker(), + test_navigation_listener_.get())); + content::ResourceDispatcherHost::Get()->SetDelegate( + resource_dispatcher_host_delegate_.get()); } TestNavigationListener* test_navigation_listener() { @@ -361,8 +292,8 @@ class WebNavigationApiTest : public ExtensionApiTest { private: scoped_refptr test_navigation_listener_; - scoped_ptr content_browser_client_; - content::ContentBrowserClient* original_content_browser_client_; + scoped_ptr + resource_dispatcher_host_delegate_; DISALLOW_COPY_AND_ASSIGN(WebNavigationApiTest); }; diff --git a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc index 29f766defc6d6b..94ae1820ffcb90 100644 --- a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc +++ b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc @@ -74,8 +74,13 @@ class AudioWaitingExtensionTest : public ExtensionApiTest { class WebrtcAudioPrivateTest : public AudioWaitingExtensionTest { public: WebrtcAudioPrivateTest() - : enumeration_event_(false, false), - source_url_("chrome-extension://fakeid012345678/fakepage.html") { + : enumeration_event_(false, false) { + } + + virtual void SetUpOnMainThread() OVERRIDE { + AudioWaitingExtensionTest::SetUpOnMainThread(); + // Needs to happen after chrome's schemes are added. + source_url_ = GURL("chrome-extension://fakeid012345678/fakepage.html"); } protected: diff --git a/chrome/browser/extensions/app_background_page_apitest.cc b/chrome/browser/extensions/app_background_page_apitest.cc index c423a8c7cd097f..5c8ed790ce910e 100644 --- a/chrome/browser/extensions/app_background_page_apitest.cc +++ b/chrome/browser/extensions/app_background_page_apitest.cc @@ -121,11 +121,7 @@ namespace { class AppBackgroundPageNaClTest : public AppBackgroundPageApiTest { public: AppBackgroundPageNaClTest() - : extension_(NULL) { - PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir_); - app_dir_ = app_dir_.AppendASCII( - "ppapi/tests/extensions/background_keepalive/newlib"); - } + : extension_(NULL) {} virtual ~AppBackgroundPageNaClTest() { } @@ -143,12 +139,15 @@ class AppBackgroundPageNaClTest : public AppBackgroundPageApiTest { protected: void LaunchTestingApp() { - extension_ = LoadExtension(app_dir_); + base::FilePath app_dir; + PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir); + app_dir = app_dir.AppendASCII( + "ppapi/tests/extensions/background_keepalive/newlib"); + extension_ = LoadExtension(app_dir); ASSERT_TRUE(extension_); } private: - base::FilePath app_dir_; const Extension* extension_; }; diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc index fef46d571cab99..0e96bc3dc272f8 100644 --- a/chrome/browser/notifications/desktop_notifications_unittest.cc +++ b/chrome/browser/notifications/desktop_notifications_unittest.cc @@ -11,11 +11,13 @@ #include "chrome/browser/notifications/fake_balloon_view.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/common/pref_names.h" +#include "chrome/test/base/chrome_unit_test_suite.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" #include "content/public/common/show_desktop_notification_params.h" #include "ui/base/ime/input_method_initializer.h" +#include "ui/gl/gl_surface.h" #include "ui/message_center/message_center.h" #if defined(USE_ASH) @@ -106,6 +108,8 @@ DesktopNotificationsTest::~DesktopNotificationsTest() { } void DesktopNotificationsTest::SetUp() { + ChromeUnitTestSuite::InitializeProviders(); + ChromeUnitTestSuite::InitializeResourceBundle(); ui::InitializeInputMethodForTesting(); #if defined(USE_AURA) wm_state_.reset(new wm::WMState); diff --git a/chrome/browser/policy/policy_prefs_browsertest.cc b/chrome/browser/policy/policy_prefs_browsertest.cc index b7bca5ad106fbf..1f7e72d67aef31 100644 --- a/chrome/browser/policy/policy_prefs_browsertest.cc +++ b/chrome/browser/policy/policy_prefs_browsertest.cc @@ -430,7 +430,9 @@ void VerifyControlledSettingIndicators(Browser* browser, } // namespace -TEST(PolicyPrefsTestCoverageTest, AllPoliciesHaveATestCase) { +typedef InProcessBrowserTest PolicyPrefsTestCoverageTest; + +IN_PROC_BROWSER_TEST_F(PolicyPrefsTestCoverageTest, AllPoliciesHaveATestCase) { // Verifies that all known policies have a test case in the JSON file. // This test fails when a policy is added to // components/policy/resources/policy_templates.json but a test case is not diff --git a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc index 2a06cb7045aa11..2fd58e04620dc9 100644 --- a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc +++ b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc @@ -27,6 +27,7 @@ #include "chrome/common/service_process_util.h" #include "chrome/service/service_ipc_server.h" #include "chrome/service/service_process.h" +#include "chrome/test/base/chrome_unit_test_suite.h" #include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_io_thread_state.h" @@ -36,6 +37,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "components/keyed_service/core/keyed_service.h" #include "content/public/browser/notification_service.h" +#include "content/public/common/content_paths.h" #include "content/public/test/test_browser_thread_bundle.h" #include "ipc/ipc_descriptors.h" #include "ipc/ipc_multiprocess_test.h" @@ -211,6 +213,7 @@ int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { base::MessageLoopForUI main_message_loop; main_message_loop.set_thread_name("Main Thread"); CommandLine* command_line = CommandLine::ForCurrentProcess(); + content::RegisterPathProvider(); #if defined(OS_MACOSX) if (!command_line->HasSwitch(kTestExecutablePath)) @@ -371,6 +374,10 @@ class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest, CloudPrintProxyPolicyStartupTest::CloudPrintProxyPolicyStartupTest() : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) { + // Although is really a unit test which runs in the browser_tests binary, it + // doesn't get the unit setup which normally happens in the unit test binary. + ChromeUnitTestSuite::InitializeProviders(); + ChromeUnitTestSuite::InitializeResourceBundle(); } CloudPrintProxyPolicyStartupTest::~CloudPrintProxyPolicyStartupTest() { diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm index fdf7fe74eb63d3..d55e250eb4a70e 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm @@ -8,11 +8,14 @@ #include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsobject.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/content_settings_types.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" +#include "chrome/test/base/chrome_unit_test_suite.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "content/public/common/media_stream_request.h" @@ -49,9 +52,23 @@ ContentSettingBubbleController* CreateBubbleController( ContentSettingsType settingsType); + virtual void SetUp() OVERRIDE { + ChromeUnitTestSuite::InitializeProviders(); + ChromeUnitTestSuite::InitializeResourceBundle(); + content_client_.reset(new ChromeContentClient); + content::SetContentClient(content_client_.get()); + browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); + content::SetBrowserClientForTesting(browser_content_client_.get()); + initializer_.reset(new TestingBrowserProcessInitializer); + ChromeRenderViewHostTestHarness::SetUp(); + } + + scoped_ptr content_client_; + scoped_ptr browser_content_client_; + // This is a unit test running in the browser_tests suite, so we must create // the TestingBrowserProcess manually. Must be first member. - TestingBrowserProcessInitializer initializer_; + scoped_ptr initializer_; base::scoped_nsobject parent_; diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_browsertest.mm b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_browsertest.mm index 3ba4616ffb1066..4053c75639f440 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_browsertest.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller_browsertest.mm @@ -16,7 +16,9 @@ class ExtensionInstallDialogControllerTest : public InProcessBrowserTest { public: - ExtensionInstallDialogControllerTest() { + ExtensionInstallDialogControllerTest() {} + + virtual void SetUpOnMainThread() OVERRIDE { extension_ = chrome::LoadInstallPromptExtension(); } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc index f9c3842f98750b..2def6b7ae99b0f 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc @@ -12,6 +12,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_test_helpers.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" @@ -20,6 +21,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/scoped_testing_local_state.h" @@ -118,6 +120,11 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { model_(NULL) {} virtual void SetUp() OVERRIDE { + content_client_.reset(new ChromeContentClient); + content::SetContentClient(content_client_.get()); + browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); + content::SetBrowserClientForTesting(browser_content_client_.get()); + views::MenuController::TurnOffMenuSelectionHoldForTest(); BookmarkBarView::DisableAnimationsForTesting(true); @@ -185,6 +192,10 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { ViewEventTestBase::TearDown(); BookmarkBarView::DisableAnimationsForTesting(false); + + browser_content_client_.reset(); + content_client_.reset(); + content::SetContentClient(NULL); } protected: @@ -239,6 +250,8 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { } gfx::Size bb_view_pref_; + scoped_ptr content_client_; + scoped_ptr browser_content_client_; scoped_ptr profile_; scoped_ptr browser_; scoped_ptr local_state_; diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index b9928d450aadca..70259a6d230941 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -425,7 +425,13 @@ }], ['OS=="mac"', { 'dependencies': [ - '../components/components.gyp:breakpad_stubs', + '../breakpad/breakpad.gyp:breakpad', + '../components/components.gyp:breakpad_component', + ], + 'sources': [ + 'app/chrome_breakpad_client.cc', + 'app/chrome_breakpad_client_mac.mm', + 'app/chrome_main_mac.mm', ], }], ['enable_mdns == 1', { diff --git a/chrome/interactive_ui_tests.isolate b/chrome/interactive_ui_tests.isolate index 72c21b435fccfc..3d2a1092ee7db8 100644 --- a/chrome/interactive_ui_tests.isolate +++ b/chrome/interactive_ui_tests.isolate @@ -50,6 +50,7 @@ '<(PRODUCT_DIR)/chrome_100_percent.pak', '<(PRODUCT_DIR)/locales/en-US.pak', '<(PRODUCT_DIR)/locales/fr.pak', + '<(PRODUCT_DIR)/ui_test.pak', ], }, }], diff --git a/chrome/renderer/chrome_content_renderer_client_browsertest.cc b/chrome/renderer/chrome_content_renderer_client_browsertest.cc index 77b8db4a734f5e..75e17085b2da55 100644 --- a/chrome/renderer/chrome_content_renderer_client_browsertest.cc +++ b/chrome/renderer/chrome_content_renderer_client_browsertest.cc @@ -9,6 +9,7 @@ #include "base/command_line.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" +#include "chrome/renderer/chrome_content_renderer_client.h" #include "chrome/test/base/chrome_render_view_test.h" #include "url/gurl.h" @@ -20,7 +21,9 @@ typedef ChromeRenderViewTest InstantProcessNavigationTest; TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { CommandLine::ForCurrentProcess()->AppendSwitch(switches::kInstantProcess); bool unused; - EXPECT_TRUE(chrome_content_renderer_client_.ShouldFork( + ChromeContentRendererClient* client = + static_cast(content_renderer_client_.get()); + EXPECT_TRUE(client->ShouldFork( GetMainFrame(), GURL("http://foo"), "GET", false, false, &unused)); } @@ -28,21 +31,23 @@ TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { // to potentially Instant URLs get bounced back to the browser to be rebucketed // into an Instant renderer if necessary. TEST_F(InstantProcessNavigationTest, ForkForNavigationsToSearchURLs) { + ChromeContentRendererClient* client = + static_cast(content_renderer_client_.get()); chrome_render_thread_->set_io_message_loop_proxy( base::MessageLoopProxy::current()); - chrome_content_renderer_client_.RenderThreadStarted(); + client->RenderThreadStarted(); std::vector search_urls; search_urls.push_back(GURL("http://example.com/search")); chrome_render_thread_->Send(new ChromeViewMsg_SetSearchURLs( search_urls, GURL("http://example.com/newtab"))); bool unused; - EXPECT_TRUE(chrome_content_renderer_client_.ShouldFork( + EXPECT_TRUE(client->ShouldFork( GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, &unused)); - EXPECT_TRUE(chrome_content_renderer_client_.ShouldFork( + EXPECT_TRUE(client->ShouldFork( GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, false, &unused)); - EXPECT_FALSE(chrome_content_renderer_client_.ShouldFork( + EXPECT_FALSE(client->ShouldFork( GetMainFrame(), GURL("http://example.com/"), "GET", false, false, &unused)); } diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc index ff61d1de6ea6af..8fb700f1d885b0 100644 --- a/chrome/renderer/extensions/dispatcher.cc +++ b/chrome/renderer/extensions/dispatcher.cc @@ -519,7 +519,8 @@ void Dispatcher::WebKitInitialized() { // For extensions, we want to ensure we call the IdleHandler every so often, // even if the extension keeps up activity. if (is_extension_process_) { - forced_idle_timer_.Start(FROM_HERE, + forced_idle_timer_.reset(new base::RepeatingTimer); + forced_idle_timer_->Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), RenderThread::Get(), &RenderThread::IdleHandler); } @@ -544,8 +545,8 @@ void Dispatcher::IdleNotification() { int64 forced_delay_ms = std::max( RenderThread::Get()->GetIdleNotificationDelayInMs(), kMaxExtensionIdleHandlerDelayMs); - forced_idle_timer_.Stop(); - forced_idle_timer_.Start(FROM_HERE, + forced_idle_timer_->Stop(); + forced_idle_timer_->Start(FROM_HERE, base::TimeDelta::FromMilliseconds(forced_delay_ms), RenderThread::Get(), &RenderThread::IdleHandler); } @@ -553,6 +554,7 @@ void Dispatcher::IdleNotification() { void Dispatcher::OnRenderProcessShutdown() { v8_schema_registry_.reset(); + forced_idle_timer_.reset(); } void Dispatcher::OnSetFunctionNames( diff --git a/chrome/renderer/extensions/dispatcher.h b/chrome/renderer/extensions/dispatcher.h index 57dbff9de782fe..6ce0f62ecffca2 100644 --- a/chrome/renderer/extensions/dispatcher.h +++ b/chrome/renderer/extensions/dispatcher.h @@ -279,7 +279,7 @@ class Dispatcher : public content::RenderProcessObserver { // Same as above, but on a longer timer and will run even if the process is // not idle, to ensure that IdleHandle gets called eventually. - base::RepeatingTimer forced_idle_timer_; + scoped_ptr > forced_idle_timer_; // All declared function names. std::set function_names_; diff --git a/chrome/renderer/media/cast_session_browsertest.cc b/chrome/renderer/media/cast_session_browsertest.cc index fb55553dfb7379..c9b0c43670573b 100644 --- a/chrome/renderer/media/cast_session_browsertest.cc +++ b/chrome/renderer/media/cast_session_browsertest.cc @@ -6,6 +6,7 @@ #include "base/message_loop/message_loop_proxy.h" #include "base/run_loop.h" +#include "chrome/renderer/chrome_content_renderer_client.h" #include "chrome/test/base/chrome_render_view_test.h" namespace chrome { @@ -17,7 +18,9 @@ typedef ChromeRenderViewTest CastSessionBrowserTest; TEST_F(CastSessionBrowserTest, CreateAndDestroy) { chrome_render_thread_->set_io_message_loop_proxy( base::MessageLoopProxy::current()); - chrome_content_renderer_client_.RenderThreadStarted(); + ChromeContentRendererClient* client = + static_cast(content_renderer_client_.get()); + client->RenderThreadStarted(); scoped_refptr session(new CastSession()); diff --git a/chrome/renderer/translate/translate_script_browsertest.cc b/chrome/renderer/translate/translate_script_browsertest.cc index f7b846e756aec3..feba10ef5639c1 100644 --- a/chrome/renderer/translate/translate_script_browsertest.cc +++ b/chrome/renderer/translate/translate_script_browsertest.cc @@ -10,6 +10,7 @@ #include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebScriptSource.h" #include "ui/base/resource/resource_bundle.h" +#include "v8/include/v8.h" using blink::WebFrame; using blink::WebScriptSource; diff --git a/chrome/test/base/browser_perf_tests_main.cc b/chrome/test/base/browser_perf_tests_main.cc index 9236b451b5d990..99fcdd45137fd2 100644 --- a/chrome/test/base/browser_perf_tests_main.cc +++ b/chrome/test/base/browser_perf_tests_main.cc @@ -5,18 +5,10 @@ #include "chrome/test/base/chrome_test_launcher.h" #include "chrome/test/base/chrome_test_suite.h" -class ChromeBrowserTestSuite : public ChromeTestSuite { - public: - ChromeBrowserTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {} - - protected: - virtual bool IsBrowserTestSuite() OVERRIDE { return true; } -}; - class ChromeBrowserTestSuiteRunner : public ChromeTestSuiteRunner { public: virtual int RunTestSuite(int argc, char** argv) OVERRIDE { - return ChromeBrowserTestSuite(argc, argv).Run(); + return ChromeTestSuite(argc, argv).Run(); } }; diff --git a/chrome/test/base/browser_tests_main.cc b/chrome/test/base/browser_tests_main.cc index ae99ee3550d8d5..7759a4030b9b19 100644 --- a/chrome/test/base/browser_tests_main.cc +++ b/chrome/test/base/browser_tests_main.cc @@ -8,16 +8,10 @@ #include "chrome/test/base/chrome_test_launcher.h" #include "chrome/test/base/chrome_test_suite.h" -class ChromeBrowserTestSuite : public ChromeTestSuite { - public: - ChromeBrowserTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {} - virtual bool IsBrowserTestSuite() OVERRIDE { return true; } -}; - class ChromeBrowserTestSuiteRunner : public ChromeTestSuiteRunner { public: virtual int RunTestSuite(int argc, char** argv) OVERRIDE { - return ChromeBrowserTestSuite(argc, argv).Run(); + return ChromeTestSuite(argc, argv).Run(); } }; diff --git a/chrome/test/base/chrome_render_view_test.cc b/chrome/test/base/chrome_render_view_test.cc index 522b4ad051ba5d..7e435a26e4a69d 100644 --- a/chrome/test/base/chrome_render_view_test.cc +++ b/chrome/test/base/chrome_render_view_test.cc @@ -5,12 +5,16 @@ #include "chrome/test/base/chrome_render_view_test.h" #include "base/debug/leak_annotations.h" +#include "chrome/browser/chrome_content_browser_client.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/render_messages.h" +#include "chrome/renderer/chrome_content_renderer_client.h" #include "chrome/renderer/extensions/chrome_v8_context_set.h" #include "chrome/renderer/extensions/chrome_v8_extension.h" #include "chrome/renderer/extensions/dispatcher.h" #include "chrome/renderer/extensions/event_bindings.h" #include "chrome/renderer/spellchecker/spellcheck.h" +#include "chrome/test/base/chrome_unit_test_suite.h" #include "components/autofill/content/renderer/autofill_agent.h" #include "components/autofill/content/renderer/password_autofill_agent.h" #include "components/autofill/content/renderer/test_password_autofill_agent.h" @@ -51,15 +55,13 @@ ChromeRenderViewTest::~ChromeRenderViewTest() { } void ChromeRenderViewTest::SetUp() { + ChromeUnitTestSuite::InitializeProviders(); + ChromeUnitTestSuite::InitializeResourceBundle(); + chrome_render_thread_ = new ChromeMockRenderThread(); render_thread_.reset(chrome_render_thread_); - content::SetRendererClientForTesting(&chrome_content_renderer_client_); extension_dispatcher_ = new extensions::Dispatcher(); - chrome_content_renderer_client_.SetExtensionDispatcher(extension_dispatcher_); -#if defined(ENABLE_SPELLCHECK) - chrome_content_renderer_client_.SetSpellcheck(new SpellCheck()); -#endif content::RenderViewTest::SetUp(); @@ -83,3 +85,22 @@ void ChromeRenderViewTest::TearDown() { #endif content::RenderViewTest::TearDown(); } + +content::ContentClient* ChromeRenderViewTest::CreateContentClient() { + return new ChromeContentClient(); +} + +content::ContentBrowserClient* + ChromeRenderViewTest::CreateContentBrowserClient() { + return new chrome::ChromeContentBrowserClient(); +} + +content::ContentRendererClient* + ChromeRenderViewTest::CreateContentRendererClient() { + ChromeContentRendererClient* client = new ChromeContentRendererClient(); + client->SetExtensionDispatcher(extension_dispatcher_); +#if defined(ENABLE_SPELLCHECK) + client->SetSpellcheck(new SpellCheck()); +#endif + return client; +} diff --git a/chrome/test/base/chrome_render_view_test.h b/chrome/test/base/chrome_render_view_test.h index aff4c5dcff3e36..69bd244d76e2ee 100644 --- a/chrome/test/base/chrome_render_view_test.h +++ b/chrome/test/base/chrome_render_view_test.h @@ -7,7 +7,6 @@ #include -#include "chrome/renderer/chrome_content_renderer_client.h" #include "chrome/renderer/chrome_mock_render_thread.h" #include "content/public/test/render_view_test.h" @@ -30,8 +29,11 @@ class ChromeRenderViewTest : public content::RenderViewTest { // testing::Test virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; + virtual content::ContentClient* CreateContentClient() OVERRIDE; + virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE; + virtual content::ContentRendererClient* + CreateContentRendererClient() OVERRIDE; - ChromeContentRendererClient chrome_content_renderer_client_; extensions::Dispatcher* extension_dispatcher_; autofill::TestPasswordAutofillAgent* password_autofill_; diff --git a/chrome/test/base/chrome_test_launcher.cc b/chrome/test/base/chrome_test_launcher.cc index 4508ab40c175bd..b2ee566c98065f 100644 --- a/chrome/test/base/chrome_test_launcher.cc +++ b/chrome/test/base/chrome_test_launcher.cc @@ -85,14 +85,7 @@ class ChromeTestLauncherDelegate : public content::TestLauncherDelegate { protected: virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE { -#if defined(OS_WIN) || defined (OS_LINUX) return new ChromeMainDelegate(); -#else - // This delegate is only guaranteed to link on linux and windows, so just - // bail out if we are on any other platform. - NOTREACHED(); - return NULL; -#endif } virtual void AdjustDefaultParallelJobs(int* default_jobs) OVERRIDE { diff --git a/chrome/test/base/chrome_test_suite.cc b/chrome/test/base/chrome_test_suite.cc index e8c425daa640ea..6292b85d7a49cc 100644 --- a/chrome/test/base/chrome_test_suite.cc +++ b/chrome/test/base/chrome_test_suite.cc @@ -11,24 +11,14 @@ #include "base/command_line.h" #include "base/memory/ref_counted.h" -#include "base/metrics/stats_table.h" #include "base/path_service.h" -#include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_content_browser_client.h" -#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/extensions/chrome_extensions_client.h" #include "chrome/common/url_constants.h" -#include "chrome/utility/chrome_content_utility_client.h" #include "content/public/test/test_launcher.h" -#include "extensions/common/extension_paths.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/base/resource/resource_handle.h" #if defined(OS_ANDROID) #include "base/android/jni_android.h" @@ -44,10 +34,6 @@ #include "chromeos/chromeos_paths.h" #endif -#if !defined(OS_IOS) -#include "ui/gl/gl_surface.h" -#endif - #if defined(OS_MACOSX) #include "base/mac/bundle_locations.h" #include "base/mac/scoped_nsautorelease_pool.h" @@ -57,21 +43,12 @@ #endif // !defined(OS_IOS) #endif -#if defined(OS_POSIX) -#include "base/memory/shared_memory.h" +#if !defined(OS_IOS) +#include "media/base/media.h" #endif namespace { -void RemoveSharedMemoryFile(const std::string& filename) { - // Stats uses SharedMemory under the hood. On posix, this results in a file - // on disk. -#if defined(OS_POSIX) - base::SharedMemory memory; - memory.Delete(filename); -#endif -} - bool IsCrosPythonProcess() { #if defined(OS_CHROMEOS) char buf[80]; @@ -86,47 +63,6 @@ bool IsCrosPythonProcess() { #endif // defined(OS_CHROMEOS) } -// Initializes services needed by both unit tests and browser tests. -// See also ChromeUnitTestSuite for additional services created for unit tests. -class ChromeTestSuiteInitializer : public testing::EmptyTestEventListener { - public: - ChromeTestSuiteInitializer() { - } - - virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { - content_client_.reset(new ChromeContentClient); - content::SetContentClient(content_client_.get()); - // TODO(ios): Bring this back once ChromeContentBrowserClient is building. -#if !defined(OS_IOS) - browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); - content::SetBrowserClientForTesting(browser_content_client_.get()); - utility_content_client_.reset(new chrome::ChromeContentUtilityClient()); - content::SetUtilityClientForTesting(utility_content_client_.get()); -#endif - } - - virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { - // TODO(ios): Bring this back once ChromeContentBrowserClient is building. -#if !defined(OS_IOS) - browser_content_client_.reset(); - utility_content_client_.reset(); -#endif - content_client_.reset(); - content::SetContentClient(NULL); - } - - private: - // Client implementations for the content module. - scoped_ptr content_client_; - // TODO(ios): Bring this back once ChromeContentBrowserClient is building. -#if !defined(OS_IOS) - scoped_ptr browser_content_client_; - scoped_ptr utility_content_client_; -#endif - - DISALLOW_COPY_AND_ASSIGN(ChromeTestSuiteInitializer); -}; - } // namespace ChromeTestSuite::ChromeTestSuite(int argc, char** argv) @@ -153,48 +89,23 @@ void ChromeTestSuite::Initialize() { chrome::android::RegisterJni(base::android::AttachCurrentThread()); #endif - chrome::RegisterPathProvider(); -#if defined(OS_CHROMEOS) - chromeos::RegisterPathProvider(); -#endif if (!browser_dir_.empty()) { PathService::Override(base::DIR_EXE, browser_dir_); PathService::Override(base::DIR_MODULE, browser_dir_); } #if !defined(OS_IOS) - extensions::RegisterPathProvider(); - - extensions::ExtensionsClient::Set( - extensions::ChromeExtensionsClient::GetInstance()); - - // Only want to do this for unit tests. - if (!content::GetCurrentTestLauncherDelegate()) { - // For browser tests, this won't create the right object since - // TestChromeWebUIControllerFactory is used. That's created and - // registered in ChromeBrowserMainParts as in normal startup. - content::WebUIControllerFactory::RegisterFactory( - ChromeWebUIControllerFactory::GetInstance()); - } -#endif - // Disable external libraries load if we are under python process in // ChromeOS. That means we are autotest and, if ASAN is used, // external libraries load crashes. - content::ContentTestSuiteBase::set_external_libraries_enabled( - !IsCrosPythonProcess()); + if (!IsCrosPythonProcess()) + media::InitializeMediaLibraryForTesting(); +#endif // Initialize after overriding paths as some content paths depend on correct // values for DIR_EXE and DIR_MODULE. content::ContentTestSuiteBase::Initialize(); -#if !defined(OS_IOS) - // For browser tests, a full chrome instance is initialized which will set up - // GLSurface itself. For unit tests, we need to set this up for them. - if (!IsBrowserTestSuite()) - gfx::GLSurface::InitializeOneOffForTests(); -#endif - #if defined(OS_MACOSX) && !defined(OS_IOS) // Look in the framework bundle for resources. base::FilePath path; @@ -202,46 +113,12 @@ void ChromeTestSuite::Initialize() { path = path.Append(chrome::kFrameworkName); base::mac::SetOverrideFrameworkBundlePath(path); #endif - - // Force unittests to run using en-US so if we test against string - // output, it'll pass regardless of the system language. - ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); - base::FilePath resources_pack_path; -#if defined(OS_MACOSX) && !defined(OS_IOS) - PathService::Get(base::DIR_MODULE, &resources_pack_path); - resources_pack_path = - resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); -#else - PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); -#endif - ResourceBundle::GetSharedInstance().AddDataPackFromPath( - resources_pack_path, ui::SCALE_FACTOR_NONE); - - stats_filename_ = base::StringPrintf("unit_tests-%d", - base::GetCurrentProcId()); - RemoveSharedMemoryFile(stats_filename_); - stats_table_.reset(new base::StatsTable(stats_filename_, 20, 200)); - base::StatsTable::set_current(stats_table_.get()); - - testing::TestEventListeners& listeners = - testing::UnitTest::GetInstance()->listeners(); - listeners.Append(new ChromeTestSuiteInitializer); -} - -content::ContentClient* ChromeTestSuite::CreateClientForInitialization() { - return new ChromeContentClient(); } void ChromeTestSuite::Shutdown() { - ResourceBundle::CleanupSharedInstance(); - #if defined(OS_MACOSX) && !defined(OS_IOS) base::mac::SetOverrideFrameworkBundle(NULL); #endif - base::StatsTable::set_current(NULL); - stats_table_.reset(); - RemoveSharedMemoryFile(stats_filename_); - content::ContentTestSuiteBase::Shutdown(); } diff --git a/chrome/test/base/chrome_test_suite.h b/chrome/test/base/chrome_test_suite.h index 45db32b3c7ca02..7c24d76b30adb0 100644 --- a/chrome/test/base/chrome_test_suite.h +++ b/chrome/test/base/chrome_test_suite.h @@ -11,10 +11,6 @@ #include "base/memory/scoped_ptr.h" #include "content/public/test/content_test_suite_base.h" -namespace base { -class StatsTable; -} - // Test suite for unit and browser tests. Creates services needed by both. // See also ChromeUnitTestSuite for additional services created for unit tests. class ChromeTestSuite : public content::ContentTestSuiteBase { @@ -27,12 +23,6 @@ class ChromeTestSuite : public content::ContentTestSuiteBase { virtual void Initialize() OVERRIDE; virtual void Shutdown() OVERRIDE; - virtual content::ContentClient* CreateClientForInitialization() OVERRIDE; - - // Should return true if the test suite will be running the full chrome - // browser, false if the test suite is unit tests. - virtual bool IsBrowserTestSuite() = 0; - void SetBrowserDirectory(const base::FilePath& browser_dir) { browser_dir_ = browser_dir; } @@ -40,8 +30,6 @@ class ChromeTestSuite : public content::ContentTestSuiteBase { // Alternative path to browser binaries. base::FilePath browser_dir_; - std::string stats_filename_; - scoped_ptr stats_table_; DISALLOW_COPY_AND_ASSIGN(ChromeTestSuite); }; diff --git a/chrome/test/base/chrome_unit_test_suite.cc b/chrome/test/base/chrome_unit_test_suite.cc index dcade4a71b9c30..65f453b4b95582 100644 --- a/chrome/test/base/chrome_unit_test_suite.cc +++ b/chrome/test/base/chrome_unit_test_suite.cc @@ -4,11 +4,47 @@ #include "chrome/test/base/chrome_unit_test_suite.h" +#include "base/path_service.h" +#include "base/process/process_handle.h" +#include "base/metrics/stats_table.h" +#include "base/strings/stringprintf.h" +#include "chrome/browser/chrome_content_browser_client.h" +#include "chrome/common/chrome_content_client.h" +#include "chrome/common/chrome_paths.h" #include "chrome/test/base/testing_browser_process.h" +#include "chrome/utility/chrome_content_utility_client.h" +#include "content/public/common/content_paths.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/resource/resource_handle.h" +#include "ui/base/ui_base_paths.h" + +#if defined(OS_CHROMEOS) +#include "chromeos/chromeos_paths.h" +#endif + +#if !defined(OS_IOS) +#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" +#include "chrome/common/extensions/chrome_extensions_client.h" +#include "extensions/common/extension_paths.h" +#include "ui/gl/gl_surface.h" +#endif + +#if defined(OS_POSIX) +#include "base/memory/shared_memory.h" +#endif namespace { +void RemoveSharedMemoryFile(const std::string& filename) { + // Stats uses SharedMemory under the hood. On posix, this results in a file + // on disk. +#if defined(OS_POSIX) + base::SharedMemory memory; + memory.Delete(filename); +#endif +} + // Creates a TestingBrowserProcess for each test. class ChromeUnitTestSuiteInitializer : public testing::EmptyTestEventListener { public: @@ -16,14 +52,40 @@ class ChromeUnitTestSuiteInitializer : public testing::EmptyTestEventListener { virtual ~ChromeUnitTestSuiteInitializer() {} virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { + content_client_.reset(new ChromeContentClient); + content::SetContentClient(content_client_.get()); + // TODO(ios): Bring this back once ChromeContentBrowserClient is building. +#if !defined(OS_IOS) + browser_content_client_.reset(new chrome::ChromeContentBrowserClient()); + content::SetBrowserClientForTesting(browser_content_client_.get()); + utility_content_client_.reset(new chrome::ChromeContentUtilityClient()); + content::SetUtilityClientForTesting(utility_content_client_.get()); +#endif + TestingBrowserProcess::CreateInstance(); } virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { + // TODO(ios): Bring this back once ChromeContentBrowserClient is building. +#if !defined(OS_IOS) + browser_content_client_.reset(); + utility_content_client_.reset(); +#endif + content_client_.reset(); + content::SetContentClient(NULL); + TestingBrowserProcess::DeleteInstance(); } private: + // Client implementations for the content module. + scoped_ptr content_client_; + // TODO(ios): Bring this back once ChromeContentBrowserClient is building. +#if !defined(OS_IOS) + scoped_ptr browser_content_client_; + scoped_ptr utility_content_client_; +#endif + DISALLOW_COPY_AND_ASSIGN(ChromeUnitTestSuiteInitializer); }; @@ -42,7 +104,71 @@ void ChromeUnitTestSuite::Initialize() { testing::UnitTest::GetInstance()->listeners(); listeners.Append(new ChromeUnitTestSuiteInitializer); + InitializeProviders(); + RegisterInProcessThreads(); + + stats_filename_ = base::StringPrintf("unit_tests-%d", + base::GetCurrentProcId()); + RemoveSharedMemoryFile(stats_filename_); + stats_table_.reset(new base::StatsTable(stats_filename_, 20, 200)); + base::StatsTable::set_current(stats_table_.get()); + ChromeTestSuite::Initialize(); + + // This needs to run after ChromeTestSuite::Initialize which calls content's + // intialization which calls base's which initializes ICU. + InitializeResourceBundle(); } -bool ChromeUnitTestSuite::IsBrowserTestSuite() { return false; } +void ChromeUnitTestSuite::Shutdown() { + ResourceBundle::CleanupSharedInstance(); + + base::StatsTable::set_current(NULL); + stats_table_.reset(); + RemoveSharedMemoryFile(stats_filename_); + + ChromeTestSuite::Shutdown(); +} + +void ChromeUnitTestSuite::InitializeProviders() { + { + ChromeContentClient content_client; + RegisterContentSchemes(&content_client); + } + + chrome::RegisterPathProvider(); + content::RegisterPathProvider(); + ui::RegisterPathProvider(); + +#if defined(OS_CHROMEOS) + chromeos::RegisterPathProvider(); +#endif + +#if !defined(OS_IOS) + extensions::RegisterPathProvider(); + + extensions::ExtensionsClient::Set( + extensions::ChromeExtensionsClient::GetInstance()); + + content::WebUIControllerFactory::RegisterFactory( + ChromeWebUIControllerFactory::GetInstance()); + + gfx::GLSurface::InitializeOneOffForTests(); +#endif +} + +void ChromeUnitTestSuite::InitializeResourceBundle() { + // Force unittests to run using en-US so if we test against string + // output, it'll pass regardless of the system language. + ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + base::FilePath resources_pack_path; +#if defined(OS_MACOSX) && !defined(OS_IOS) + PathService::Get(base::DIR_MODULE, &resources_pack_path); + resources_pack_path = + resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak")); +#else + PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); +#endif + ResourceBundle::GetSharedInstance().AddDataPackFromPath( + resources_pack_path, ui::SCALE_FACTOR_NONE); +} diff --git a/chrome/test/base/chrome_unit_test_suite.h b/chrome/test/base/chrome_unit_test_suite.h index 22e722e72193b0..70eabe9c6d3ad4 100644 --- a/chrome/test/base/chrome_unit_test_suite.h +++ b/chrome/test/base/chrome_unit_test_suite.h @@ -7,8 +7,13 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/files/file_path.h" #include "chrome/test/base/chrome_test_suite.h" +namespace base { +class StatsTable; +} + // Test suite for unit tests. Creates additional stub services that are not // needed for browser tests (e.g. a TestingBrowserProcess). class ChromeUnitTestSuite : public ChromeTestSuite { @@ -18,11 +23,18 @@ class ChromeUnitTestSuite : public ChromeTestSuite { // base::TestSuite overrides: virtual void Initialize() OVERRIDE; + virtual void Shutdown() OVERRIDE; - // ChromeTestSuite overrides: - virtual bool IsBrowserTestSuite() OVERRIDE; + // These methods allow unit tests which run in the browser_test binary, and so + // which don't exercise the initialization in this test suite, to do basic + // setup which this class does. + static void InitializeProviders(); + static void InitializeResourceBundle(); private: + std::string stats_filename_; + scoped_ptr stats_table_; + DISALLOW_COPY_AND_ASSIGN(ChromeUnitTestSuite); }; diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc index a8cd6e1624df15..67555edadb3c17 100644 --- a/chrome/test/base/in_process_browser_test.cc +++ b/chrome/test/base/in_process_browser_test.cc @@ -75,10 +75,6 @@ namespace { // Passed as value of kTestType. const char kBrowserTestType[] = "browser"; -// Used when running in single-process mode. -base::LazyInstance::Leaky - g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER; - // A BrowserListObserver that makes sure that all browsers created are on the // |allowed_desktop_|. class SingleDesktopTestObserver : public chrome::BrowserListObserver, @@ -133,11 +129,17 @@ InProcessBrowserTest::InProcessBrowserTest() chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); CHECK(PathService::Override(base::FILE_EXE, chrome_path)); #endif // defined(OS_MACOSX) + CreateTestServer(base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); base::FilePath src_dir; CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); - embedded_test_server()->ServeFilesFromDirectory( - src_dir.AppendASCII("chrome/test/data")); + base::FilePath test_data_dir = src_dir.AppendASCII("chrome/test/data"); + embedded_test_server()->ServeFilesFromDirectory(test_data_dir); + + // chrome::DIR_TEST_DATA isn't going to be setup until after we call + // ContentMain. However that is after tests' constructors or SetUp methods, + // which sometimes need it. So just override it. + CHECK(PathService::Override(chrome::DIR_TEST_DATA, test_data_dir)); } InProcessBrowserTest::~InProcessBrowserTest() { @@ -162,13 +164,6 @@ void InProcessBrowserTest::SetUp() { ASSERT_TRUE(SetUpUserDataDirectory()) << "Could not set up user data directory."; - // Single-process mode is not set in BrowserMain, so process it explicitly, - // and set up renderer. - if (command_line->HasSwitch(switches::kSingleProcess)) { - content::SetRendererClientForTesting( - g_chrome_content_renderer_client.Pointer()); - } - #if defined(OS_CHROMEOS) // Make sure that the log directory exists. base::FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); @@ -176,15 +171,6 @@ void InProcessBrowserTest::SetUp() { #endif // defined(OS_CHROMEOS) #if defined(OS_MACOSX) - // On Mac, without the following autorelease pool, code which is directly - // executed (as opposed to executed inside a message loop) would autorelease - // objects into a higher-level pool. This pool is not recycled in-sync with - // the message loops' pools and causes problems with code relying on - // deallocation via an autorelease pool (such as browser window closure and - // browser shutdown). To avoid this, the following pool is recycled after each - // time code is directly executed. - autorelease_pool_ = new base::mac::ScopedNSAutoreleasePool; - // Always use the MockKeychain if OS encription is used (which is when // anything sensitive gets stored, including Cookies). Without this, // many tests will hang waiting for a user to approve KeyChain access. @@ -382,10 +368,6 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { // Pump startup related events. content::RunAllPendingInMessageLoop(); -#if defined(OS_MACOSX) - autorelease_pool_->Recycle(); -#endif - chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); // Self-adds/removes itself from the BrowserList observers. scoped_ptr single_desktop_test_observer; @@ -413,6 +395,17 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { ASSERT_TRUE(storage_monitor::TestStorageMonitor::CreateForBrowserTests()); #endif +#if defined(OS_MACOSX) + // On Mac, without the following autorelease pool, code which is directly + // executed (as opposed to executed inside a message loop) would autorelease + // objects into a higher-level pool. This pool is not recycled in-sync with + // the message loops' pools and causes problems with code relying on + // deallocation via an autorelease pool (such as browser window closure and + // browser shutdown). To avoid this, the following pool is recycled after each + // time code is directly executed. + autorelease_pool_ = new base::mac::ScopedNSAutoreleasePool; +#endif + // Pump any pending events that were created as a result of creating a // browser. content::RunAllPendingInMessageLoop(); diff --git a/chrome/test/base/interactive_ui_tests_main.cc b/chrome/test/base/interactive_ui_tests_main.cc index e2106ea1c91f38..f16f4562c8b128 100644 --- a/chrome/test/base/interactive_ui_tests_main.cc +++ b/chrome/test/base/interactive_ui_tests_main.cc @@ -60,8 +60,6 @@ class InteractiveUITestSuite : public ChromeTestSuite { #endif } - virtual bool IsBrowserTestSuite() OVERRIDE { return false; } - private: #if defined(OS_WIN) scoped_ptr com_initializer_; diff --git a/chrome/test/base/view_event_test_base.cc b/chrome/test/base/view_event_test_base.cc index da226f6b22ebd3..faf6fe48798d91 100644 --- a/chrome/test/base/view_event_test_base.cc +++ b/chrome/test/base/view_event_test_base.cc @@ -8,6 +8,7 @@ #include "base/bind_helpers.h" #include "base/message_loop/message_loop.h" #include "base/strings/string_number_conversions.h" +#include "chrome/test/base/chrome_unit_test_suite.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/ui_test_utils.h" @@ -94,6 +95,11 @@ void ViewEventTestBase::Done() { base::MessageLoop::QuitClosure()); } +void ViewEventTestBase::SetUpTestCase() { + ChromeUnitTestSuite::InitializeProviders(); + ChromeUnitTestSuite::InitializeResourceBundle(); +} + void ViewEventTestBase::SetUp() { #if defined(USE_AURA) wm_state_.reset(new wm::WMState); diff --git a/chrome/test/base/view_event_test_base.h b/chrome/test/base/view_event_test_base.h index 8c7e68634d5e5a..302409d2c6e146 100644 --- a/chrome/test/base/view_event_test_base.h +++ b/chrome/test/base/view_event_test_base.h @@ -84,6 +84,8 @@ class ViewEventTestBase : public views::WidgetDelegate, // loop. void Done(); + static void SetUpTestCase(); + // Creates a window. virtual void SetUp() OVERRIDE; diff --git a/chrome/test/nacl/nacl_browsertest_util.cc b/chrome/test/nacl/nacl_browsertest_util.cc index 902bc733ddf811..2d92ea9434a5e4 100644 --- a/chrome/test/nacl/nacl_browsertest_util.cc +++ b/chrome/test/nacl/nacl_browsertest_util.cc @@ -205,7 +205,7 @@ void NaClBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { command_line->AppendSwitch(switches::kEnableNaCl); } -void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { +void NaClBrowserTestBase::SetUpOnMainThread() { // Sanity check. base::FilePath plugin_lib; ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); diff --git a/chrome/test/nacl/nacl_browsertest_util.h b/chrome/test/nacl/nacl_browsertest_util.h index b4ed58ad893ef0..2f2d73dd093aa9 100644 --- a/chrome/test/nacl/nacl_browsertest_util.h +++ b/chrome/test/nacl/nacl_browsertest_util.h @@ -64,7 +64,7 @@ class NaClBrowserTestBase : public InProcessBrowserTest { virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; + virtual void SetUpOnMainThread() OVERRIDE; // What variant are we running - newlib, glibc, pnacl, etc? // This is used to compute what directory we're pulling data from, but it can diff --git a/chrome/test/ppapi/ppapi_test.cc b/chrome/test/ppapi/ppapi_test.cc index 0074c9fac436f4..117c9742e5da20 100644 --- a/chrome/test/ppapi/ppapi_test.cc +++ b/chrome/test/ppapi/ppapi_test.cc @@ -360,10 +360,6 @@ void PPAPINaClTest::SetUpCommandLine(base::CommandLine* command_line) { RETURN_IF_NO_NACL(); PPAPITestBase::SetUpCommandLine(command_line); - base::FilePath plugin_lib; - EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); - EXPECT_TRUE(base::PathExists(plugin_lib)); - // Enable running (non-portable) NaCl outside of the Chrome web store. command_line->AppendSwitch(switches::kEnableNaCl); command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); @@ -371,6 +367,12 @@ void PPAPINaClTest::SetUpCommandLine(base::CommandLine* command_line) { command_line->AppendSwitch(switches::kUseFakeUIForMediaStream); } +void PPAPINaClTest::SetUpOnMainThread() { + base::FilePath plugin_lib; + EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); + EXPECT_TRUE(base::PathExists(plugin_lib)); +} + void PPAPINaClTest::RunTest(const std::string& test_case) { RETURN_IF_NO_NACL(); PPAPITestBase::RunTest(test_case); @@ -451,10 +453,6 @@ void PPAPINaClTestDisallowedSockets::SetUpCommandLine( base::CommandLine* command_line) { PPAPITestBase::SetUpCommandLine(command_line); - base::FilePath plugin_lib; - EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); - EXPECT_TRUE(base::PathExists(plugin_lib)); - // Enable running (non-portable) NaCl outside of the Chrome web store. command_line->AppendSwitch(switches::kEnableNaCl); } @@ -470,4 +468,8 @@ std::string PPAPINaClTestDisallowedSockets::BuildQuery( void PPAPIBrokerInfoBarTest::SetUpOnMainThread() { // The default content setting for the PPAPI broker is ASK. We purposefully // don't call PPAPITestBase::SetUpOnMainThread() to keep it that way. + + base::FilePath plugin_lib; + EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); + EXPECT_TRUE(base::PathExists(plugin_lib)); } diff --git a/chrome/test/ppapi/ppapi_test.h b/chrome/test/ppapi/ppapi_test.h index ef76639e1bdfa1..fca7538aac0020 100644 --- a/chrome/test/ppapi/ppapi_test.h +++ b/chrome/test/ppapi/ppapi_test.h @@ -130,6 +130,7 @@ class OutOfProcessPPAPIPrivateTest : public OutOfProcessPPAPITest { class PPAPINaClTest : public PPAPITestBase { public: virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; + virtual void SetUpOnMainThread() OVERRIDE; // PPAPITestBase overrides. virtual void RunTest(const std::string& test_case) OVERRIDE; virtual void RunTestAndReload(const std::string& test_case) OVERRIDE; diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc index ae12e2fd440c26..1a523953d63c12 100644 --- a/chrome/test/pyautolib/pyautolib.cc +++ b/chrome/test/pyautolib/pyautolib.cc @@ -40,8 +40,6 @@ void PyUITestSuiteBase::SetCrSourceRoot(const base::FilePath& path) { PathService::Override(base::DIR_SOURCE_ROOT, path); } -bool PyUITestSuiteBase::IsBrowserTestSuite() { return true; } - // PyUITestBase PyUITestBase::PyUITestBase(bool clear_profile, std::wstring homepage) : UITestBase() { diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h index a27b8d224d1bb6..f4bcb2768736bd 100644 --- a/chrome/test/pyautolib/pyautolib.h +++ b/chrome/test/pyautolib/pyautolib.h @@ -38,8 +38,6 @@ class PyUITestSuiteBase : public UITestSuite { void SetCrSourceRoot(const base::FilePath& path); - virtual bool IsBrowserTestSuite() OVERRIDE; - private: #if defined(OS_MACOSX) base::mac::ScopedNSAutoreleasePool pool_; diff --git a/chrome/test/ui/ui_test_suite.cc b/chrome/test/ui/ui_test_suite.cc index 24caf938d361ea..1d02df595036b2 100644 --- a/chrome/test/ui/ui_test_suite.cc +++ b/chrome/test/ui/ui_test_suite.cc @@ -39,8 +39,6 @@ void UITestSuite::Shutdown() { ChromeTestSuite::Shutdown(); } -bool UITestSuite::IsBrowserTestSuite() { return false; } - #if defined(OS_WIN) void UITestSuite::LoadCrashService() { scoped_ptr env(base::Environment::Create()); diff --git a/chrome/test/ui/ui_test_suite.h b/chrome/test/ui/ui_test_suite.h index 5e6254446c2d72..e93de67c32cd00 100644 --- a/chrome/test/ui/ui_test_suite.h +++ b/chrome/test/ui/ui_test_suite.h @@ -20,8 +20,6 @@ class UITestSuite : public ChromeTestSuite { virtual void Initialize() OVERRIDE; virtual void Shutdown() OVERRIDE; - virtual bool IsBrowserTestSuite() OVERRIDE; - private: #if defined(OS_WIN) void LoadCrashService(); diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc index 13d112abf23f03..adf27a995f24aa 100644 --- a/content/app/content_main_runner.cc +++ b/content/app/content_main_runner.cc @@ -489,7 +489,8 @@ class ContentMainRunnerImpl : public ContentMainRunner { : is_initialized_(false), is_shutdown_(false), completed_basic_startup_(false), - delegate_(NULL) { + delegate_(NULL), + ui_task_(NULL) { #if defined(OS_WIN) memset(&sandbox_info_, 0, sizeof(sandbox_info_)); #endif @@ -526,6 +527,8 @@ class ContentMainRunnerImpl : public ContentMainRunner { #endif virtual int Initialize(const ContentMainParams& params) OVERRIDE { + ui_task_ = params.ui_task; + #if defined(OS_WIN) RegisterInvalidParamHandler(); _Module.Init(NULL, static_cast(params.instance)); @@ -612,7 +615,12 @@ class ContentMainRunnerImpl : public ContentMainRunner { // A consequence of this is that you can't use the ctor/dtor-based // TRACE_EVENT methods on Linux or iOS builds till after we set this up. #if !defined(OS_ANDROID) && !defined(OS_IOS) - exit_manager_.reset(new base::AtExitManager); + if (!ui_task_) { + // When running browser tests, don't create a second AtExitManager as that + // interfers with shutdown when objects created before ContentMain is + // called are destructed when it returns. + exit_manager_.reset(new base::AtExitManager); + } #endif // !OS_ANDROID && !OS_IOS #if defined(OS_MACOSX) @@ -769,6 +777,7 @@ class ContentMainRunnerImpl : public ContentMainRunner { command_line.GetSwitchValueASCII(switches::kProcessType); MainFunctionParams main_params(command_line); + main_params.ui_task = ui_task_; #if defined(OS_WIN) main_params.sandbox_info = &sandbox_info_; #elif defined(OS_MACOSX) @@ -835,6 +844,8 @@ class ContentMainRunnerImpl : public ContentMainRunner { scoped_ptr autorelease_pool_; #endif + base::Closure* ui_task_; + DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); }; diff --git a/content/browser/renderer_host/render_widget_host_browsertest.cc b/content/browser/renderer_host/render_widget_host_browsertest.cc index b1a3398a0aad40..32715e8dc0745d 100644 --- a/content/browser/renderer_host/render_widget_host_browsertest.cc +++ b/content/browser/renderer_host/render_widget_host_browsertest.cc @@ -19,7 +19,7 @@ class RenderWidgetHostBrowserTest : public ContentBrowserTest { public: RenderWidgetHostBrowserTest() {} - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { + virtual void SetUpOnMainThread() OVERRIDE { ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); } diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc index c62c66ad8008cb..648acfb69d68b5 100644 --- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc +++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc @@ -74,9 +74,8 @@ class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { callback_invoke_count_(0), frames_captured_(0) {} - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { + virtual void SetUpOnMainThread() OVERRIDE { ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); - ContentBrowserTest::SetUpInProcessBrowserTestFixture(); } // Attempts to set up the source surface. Returns false if unsupported on the @@ -875,8 +874,8 @@ class CompositingRenderWidgetHostViewTabCaptureHighDPI public: CompositingRenderWidgetHostViewTabCaptureHighDPI() : kScale(2.f) {} - virtual void SetUpCommandLine(CommandLine* cmd) OVERRIDE { - CompositingRenderWidgetHostViewBrowserTestTabCapture::SetUpCommandLine(cmd); + virtual void SetUpOnMainThread() OVERRIDE { + CommandLine* cmd = CommandLine::ForCurrentProcess(); cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, base::StringPrintf("%f", scale())); #if defined(OS_WIN) diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 278716da95c68e..ab0877ad376b06 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -1033,7 +1033,7 @@ 'renderer/browser_plugin/mock_browser_plugin.h', 'renderer/browser_plugin/mock_browser_plugin_manager.cc', 'renderer/browser_plugin/mock_browser_plugin_manager.h', - 'renderer/browser_render_view_browsertest.cc', + 'renderer/browser_render_view_browsertest.cc', 'renderer/dom_serializer_browsertest.cc', 'renderer/gin_browsertest.cc', 'renderer/mouse_lock_dispatcher_browsertest.cc', diff --git a/content/public/app/content_main.h b/content/public/app/content_main.h index ea4c8ae76119a6..201fca72112eb2 100644 --- a/content/public/app/content_main.h +++ b/content/public/app/content_main.h @@ -7,6 +7,7 @@ #include +#include "base/callback_forward.h" #include "build/build_config.h" #include "content/common/content_export.h" @@ -23,15 +24,15 @@ class ContentMainDelegate; struct ContentMainParams { explicit ContentMainParams(ContentMainDelegate* delegate) - : delegate(delegate) + : delegate(delegate), #if defined(OS_WIN) - , instance(NULL), - sandbox_info(NULL) + instance(NULL), + sandbox_info(NULL), #elif !defined(OS_ANDROID) - , argc(0), - argv(NULL) + argc(0), + argv(NULL), #endif - { + ui_task(NULL) { } ContentMainDelegate* delegate; @@ -46,6 +47,10 @@ struct ContentMainParams { int argc; const char** argv; #endif + + // Used by browser_tests. If non-null BrowserMain schedules this task to run + // on the MessageLoop. It's owned by the test code. + base::Closure* ui_task; }; #if defined(OS_ANDROID) diff --git a/content/public/test/browser_test_base.cc b/content/public/test/browser_test_base.cc index c09043478fbc93..d5843ed551a550 100644 --- a/content/public/test/browser_test_base.cc +++ b/content/public/test/browser_test_base.cc @@ -7,12 +7,15 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/debug/stack_trace.h" +#include "base/i18n/icu_util.h" #include "base/message_loop/message_loop.h" #include "base/sys_info.h" +#include "content/public/app/content_main.h" #include "content/browser/renderer_host/render_process_host_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" #include "content/public/common/main_function_params.h" +#include "content/public/test/test_launcher.h" #include "content/public/test/test_utils.h" #include "net/base/net_errors.h" #include "net/dns/mock_host_resolver.h" @@ -27,7 +30,6 @@ #if defined(OS_MACOSX) #include "base/mac/mac_util.h" -#include "base/power_monitor/power_monitor_device_source.h" #endif #if defined(OS_ANDROID) @@ -121,13 +123,17 @@ BrowserTestBase::BrowserTestBase() : enable_pixel_output_(false), use_software_compositing_(false) { #if defined(OS_MACOSX) base::mac::SetOverrideAmIBundled(true); - base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); #endif #if defined(OS_POSIX) handle_sigterm_ = true; #endif + // This is called through base::TestSuite initially. It'll also be called + // inside BrowserMain, so tell the code to ignore the check that it's being + // called more than once + base::i18n::AllowMultipleInitializeCallsForTesting(); + embedded_test_server_.reset(new net::test_server::EmbeddedTestServer); } @@ -223,12 +229,14 @@ void BrowserTestBase::SetUp() { net::ScopedDefaultHostResolverProc scoped_local_host_resolver_proc( rule_based_resolver_.get()); SetUpInProcessBrowserTestFixture(); - MainFunctionParams params(*command_line); - params.ui_task = + + base::Closure* ui_task = new base::Closure( base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); #if defined(OS_ANDROID) + MainFunctionParams params(*command_line); + params.ui_task = ui_task; BrowserMainRunner::Create()->Initialize(params); // We are done running the test by now. During teardown we // need to be able to perform IO. @@ -238,7 +246,8 @@ void BrowserTestBase::SetUp() { base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), true)); #else - BrowserMain(params); + GetContentMainParams()->ui_task = ui_task; + ContentMain(*GetContentMainParams()); #endif TearDownInProcessBrowserTestFixture(); } diff --git a/content/public/test/content_test_suite_base.cc b/content/public/test/content_test_suite_base.cc index d7ba804cf6e2ab..53e569338734f5 100644 --- a/content/public/test/content_test_suite_base.cc +++ b/content/public/test/content_test_suite_base.cc @@ -16,7 +16,6 @@ #include "content/public/browser/render_process_host.h" #include "content/public/browser/utility_process_host.h" #include "content/public/common/content_client.h" -#include "content/public/common/content_paths.h" #include "content/renderer/in_process_renderer_thread.h" #include "content/utility/in_process_utility_thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -34,10 +33,6 @@ #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h" #endif -#if !defined(OS_IOS) -#include "media/base/media.h" -#endif - namespace content { class ContentTestSuiteBaseListener : public testing::EmptyTestEventListener { @@ -52,8 +47,7 @@ class ContentTestSuiteBaseListener : public testing::EmptyTestEventListener { }; ContentTestSuiteBase::ContentTestSuiteBase(int argc, char** argv) - : base::TestSuite(argc, argv), - external_libraries_enabled_(true) { + : base::TestSuite(argc, argv) { } void ContentTestSuiteBase::Initialize() { @@ -71,26 +65,25 @@ void ContentTestSuiteBase::Initialize() { ui::shell_dialogs::RegisterJni(env); #endif + testing::UnitTest::GetInstance()->listeners().Append( + new ContentTestSuiteBaseListener); +} + +void ContentTestSuiteBase::RegisterContentSchemes( + ContentClient* content_client) { + SetContentClient(content_client); + content::RegisterContentSchemes(false); + SetContentClient(NULL); +} + +void ContentTestSuiteBase::RegisterInProcessThreads() { #if !defined(OS_IOS) UtilityProcessHost::RegisterUtilityMainThreadFactory( CreateInProcessUtilityThread); RenderProcessHost::RegisterRendererMainThreadFactory( CreateInProcessRendererThread); GpuProcessHost::RegisterGpuMainThreadFactory(CreateInProcessGpuThread); - if (external_libraries_enabled_) - media::InitializeMediaLibraryForTesting(); #endif - - scoped_ptr client_for_init(CreateClientForInitialization()); - SetContentClient(client_for_init.get()); - RegisterContentSchemes(false); - SetContentClient(NULL); - - RegisterPathProvider(); - ui::RegisterPathProvider(); - - testing::UnitTest::GetInstance()->listeners().Append( - new ContentTestSuiteBaseListener); } } // namespace content diff --git a/content/public/test/content_test_suite_base.h b/content/public/test/content_test_suite_base.h index 7887cc3dd0d47d..1d3f5b45f1aa3f 100644 --- a/content/public/test/content_test_suite_base.h +++ b/content/public/test/content_test_suite_base.h @@ -10,7 +10,6 @@ #include "base/test/test_suite.h" namespace content { - class ContentClient; // A basis upon which test suites that use content can be built. This suite @@ -22,17 +21,16 @@ class ContentTestSuiteBase : public base::TestSuite { virtual void Initialize() OVERRIDE; - // Creates a ContentClient for use during test suite initialization. - virtual ContentClient* CreateClientForInitialization() = 0; + // The methods below are for unit test setup. + + // Registers content's schemes. During this call, the given content_client is + // registered temporarily so that it can provide additional schemes. + static void RegisterContentSchemes(ContentClient* content_client); - // If set to false, prevents Initialize() to load external libraries - // to the process. By default loading is enabled. - void set_external_libraries_enabled(bool val) { - external_libraries_enabled_ = val; - } + // Registers renderer/utility/gpu processes to run in-thread. + void RegisterInProcessThreads(); private: - bool external_libraries_enabled_; DISALLOW_COPY_AND_ASSIGN(ContentTestSuiteBase); }; diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc index 934f1aea70cc2a..d89209be2a305a 100644 --- a/content/public/test/render_view_test.cc +++ b/content/public/test/render_view_test.cc @@ -9,8 +9,11 @@ #include "content/common/frame_messages.h" #include "content/common/input_messages.h" #include "content/common/view_messages.h" +#include "content/public/browser/content_browser_client.h" #include "content/public/browser/native_web_keyboard_event.h" +#include "content/public/common/content_client.h" #include "content/public/common/renderer_preferences.h" +#include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/history_item_serialization.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" @@ -130,12 +133,12 @@ void RenderViewTest::GoForward(const blink::WebHistoryItem& item) { } void RenderViewTest::SetUp() { - // Subclasses can set the ContentClient's renderer before calling - // RenderViewTest::SetUp(). - ContentRendererClient* old_client = - SetRendererClientForTesting(&content_renderer_client_); - if (old_client) - SetRendererClientForTesting(old_client); + content_client_.reset(CreateContentClient()); + content_browser_client_.reset(CreateContentBrowserClient()); + content_renderer_client_.reset(CreateContentRendererClient()); + SetContentClient(content_client_.get()); + SetBrowserClientForTesting(content_browser_client_.get()); + SetRendererClientForTesting(content_renderer_client_.get()); // Subclasses can set render_thread_ with their own implementation before // calling RenderViewTest::SetUp(). @@ -370,6 +373,19 @@ blink::WebWidget* RenderViewTest::GetWebWidget() { return impl->webwidget(); } + +ContentClient* RenderViewTest::CreateContentClient() { + return new ContentClient; +} + +ContentBrowserClient* RenderViewTest::CreateContentBrowserClient() { + return new ContentBrowserClient; +} + +ContentRendererClient* RenderViewTest::CreateContentRendererClient() { + return new ContentRendererClient; +} + void RenderViewTest::GoToOffset(int offset, const blink::WebHistoryItem& history_item) { RenderViewImpl* impl = static_cast(view_); diff --git a/content/public/test/render_view_test.h b/content/public/test/render_view_test.h index 4dec3ab9277138..87ae5b9c80ee63 100644 --- a/content/public/test/render_view_test.h +++ b/content/public/test/render_view_test.h @@ -13,7 +13,6 @@ #include "base/strings/string16.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/common/main_function_params.h" -#include "content/public/renderer/content_renderer_client.h" #include "content/public/test/mock_render_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/public/platform/Platform.h" @@ -29,9 +28,13 @@ class Rect; } namespace content { +class ContentBrowserClient; +class ContentClient; +class ContentRendererClient; class MockRenderProcess; class RendererMainPlatformDelegate; class RendererWebKitPlatformSupportImplNoSandboxImpl; +class RenderView; class RenderViewTest : public testing::Test { public: @@ -120,6 +123,11 @@ class RenderViewTest : public testing::Test { void SendContentStateImmediately(); blink::WebWidget* GetWebWidget(); + // Allows a subclass to override the various content client implementations. + virtual ContentClient* CreateContentClient(); + virtual ContentBrowserClient* CreateContentBrowserClient(); + virtual ContentRendererClient* CreateContentRendererClient(); + // testing::Test virtual void SetUp() OVERRIDE; @@ -131,7 +139,9 @@ class RenderViewTest : public testing::Test { // the embedder's namespace. RenderView* view_; RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_; - ContentRendererClient content_renderer_client_; + scoped_ptr content_client_; + scoped_ptr content_browser_client_; + scoped_ptr content_renderer_client_; scoped_ptr render_thread_; // Used to setup the process so renderers can run. diff --git a/content/public/test/test_launcher.cc b/content/public/test/test_launcher.cc index f593328d2b320b..24880852d3f332 100644 --- a/content/public/test/test_launcher.cc +++ b/content/public/test/test_launcher.cc @@ -60,6 +60,7 @@ const char kPreTestPrefix[] = "PRE_"; const char kManualTestPrefix[] = "MANUAL_"; TestLauncherDelegate* g_launcher_delegate; +ContentMainParams* g_params; std::string RemoveAnyPrePrefixes(const std::string& test_name) { std::string result(test_name); @@ -427,35 +428,6 @@ const char kSingleProcessTestsFlag[] = "single_process"; TestLauncherDelegate::~TestLauncherDelegate() { } -#if defined(OS_WIN) || defined(OS_LINUX) -bool ShouldRunContentMain() { - CommandLine* command_line = CommandLine::ForCurrentProcess(); - return command_line->HasSwitch(switches::kProcessType) || - command_line->HasSwitch(kLaunchAsBrowser); - return false; -} - -int RunContentMain(int argc, char** argv, - TestLauncherDelegate* launcher_delegate) { - scoped_ptr chrome_main_delegate( - launcher_delegate->CreateContentMainDelegate()); - ContentMainParams params(chrome_main_delegate.get()); - -#if defined(OS_WIN) - sandbox::SandboxInterfaceInfo sandbox_info = {0}; - InitializeSandboxInfo(&sandbox_info); - - params.instance = GetModuleHandle(NULL); - params.sandbox_info = &sandbox_info; -#elif defined(OS_LINUX) - params.argc = argc; - params.argv = const_cast(argv); -#endif // defined(OS_WIN) - - return ContentMain(params); -} -#endif - int LaunchTests(TestLauncherDelegate* launcher_delegate, int default_jobs, int argc, @@ -471,24 +443,35 @@ int LaunchTests(TestLauncherDelegate* launcher_delegate, return 0; } + scoped_ptr chrome_main_delegate( + launcher_delegate->CreateContentMainDelegate()); + ContentMainParams params(chrome_main_delegate.get()); + +#if defined(OS_WIN) + sandbox::SandboxInterfaceInfo sandbox_info = {0}; + InitializeSandboxInfo(&sandbox_info); + + params.instance = GetModuleHandle(NULL); + params.sandbox_info = &sandbox_info; +#elif !defined(OS_ANDROID) + params.argc = argc; + params.argv = const_cast(argv); +#endif // defined(OS_WIN) + if (command_line->HasSwitch(kSingleProcessTestsFlag) || (command_line->HasSwitch(switches::kSingleProcess) && command_line->HasSwitch(base::kGTestFilterFlag)) || command_line->HasSwitch(base::kGTestListTestsFlag) || command_line->HasSwitch(base::kGTestHelpFlag)) { -#if defined(OS_WIN) - if (command_line->HasSwitch(kSingleProcessTestsFlag)) { - sandbox::SandboxInterfaceInfo sandbox_info; - InitializeSandboxInfo(&sandbox_info); - InitializeSandbox(&sandbox_info); - } -#endif + g_params = ¶ms; return launcher_delegate->RunTestSuite(argc, argv); } -#if defined(OS_WIN) || defined(OS_LINUX) - if (ShouldRunContentMain()) - return RunContentMain(argc, argv, launcher_delegate); +#if !defined(OS_ANDROID) + if (command_line->HasSwitch(switches::kProcessType) || + command_line->HasSwitch(kLaunchAsBrowser)) { + return ContentMain(params); + } #endif base::AtExitManager at_exit; @@ -518,4 +501,8 @@ TestLauncherDelegate* GetCurrentTestLauncherDelegate() { return g_launcher_delegate; } +ContentMainParams* GetContentMainParams() { + return g_params; +} + } // namespace content diff --git a/content/public/test/test_launcher.h b/content/public/test/test_launcher.h index 503547cdfe3ac2..8e4ced4cbcec36 100644 --- a/content/public/test/test_launcher.h +++ b/content/public/test/test_launcher.h @@ -18,6 +18,7 @@ class RunLoop; namespace content { class ContentMainDelegate; +struct ContentMainParams; extern const char kEmptyTestName[]; extern const char kHelpFlag[]; @@ -55,6 +56,7 @@ int LaunchTests(TestLauncherDelegate* launcher_delegate, char** argv) WARN_UNUSED_RESULT; TestLauncherDelegate* GetCurrentTestLauncherDelegate(); +ContentMainParams* GetContentMainParams(); } // namespace content diff --git a/content/renderer/browser_plugin/browser_plugin_browsertest.cc b/content/renderer/browser_plugin/browser_plugin_browsertest.cc index 528b7d8ac070de..7524313c8f28e5 100644 --- a/content/renderer/browser_plugin/browser_plugin_browsertest.cc +++ b/content/renderer/browser_plugin/browser_plugin_browsertest.cc @@ -10,6 +10,7 @@ #include "base/path_service.h" #include "base/pickle.h" #include "content/public/common/content_constants.h" +#include "content/public/renderer/content_renderer_client.h" #include "content/renderer/browser_plugin/browser_plugin.h" #include "content/renderer/browser_plugin/browser_plugin_manager_factory.h" #include "content/renderer/browser_plugin/mock_browser_plugin.h" @@ -21,6 +22,8 @@ #include "third_party/WebKit/public/web/WebInputEvent.h" #include "third_party/WebKit/public/web/WebScriptSource.h" +namespace content { + namespace { const char kHTMLForBrowserPluginObject[] = "sink().GetUniqueMessageMatching( BrowserPluginHostMsg_PluginDestroyed::ID)); @@ -424,14 +426,14 @@ TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) { // correctly. TEST_F(BrowserPluginTest, PartitionAttribute) { std::string html = base::StringPrintf(kHTMLForPartitionedPluginObject, - content::kBrowserPluginMimeType); + kBrowserPluginMimeType); LoadHTML(html.c_str()); std::string partition_value = ExecuteScriptAndReturnString( "document.getElementById('browserplugin').partition"); EXPECT_STREQ("someid", partition_value.c_str()); html = base::StringPrintf(kHTMLForPartitionedPersistedPluginObject, - content::kBrowserPluginMimeType); + kBrowserPluginMimeType); LoadHTML(html.c_str()); partition_value = ExecuteScriptAndReturnString( "document.getElementById('browserplugin').partition"); @@ -451,7 +453,7 @@ TEST_F(BrowserPluginTest, PartitionAttribute) { // Load a browser tag without 'src' defined. html = base::StringPrintf(kHTMLForSourcelessPluginObject, - content::kBrowserPluginMimeType); + kBrowserPluginMimeType); LoadHTML(html.c_str()); // Ensure we don't parse just "persist:" string and return exception. @@ -468,7 +470,7 @@ TEST_F(BrowserPluginTest, PartitionAttribute) { // partition attribute is invalid. TEST_F(BrowserPluginTest, InvalidPartition) { std::string html = base::StringPrintf(kHTMLForInvalidPartitionedPluginObject, - content::kBrowserPluginMimeType); + kBrowserPluginMimeType); LoadHTML(html.c_str()); // Attempt to navigate with an invalid partition. { @@ -514,7 +516,7 @@ TEST_F(BrowserPluginTest, InvalidPartition) { // cannot be modified. TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, - content::kBrowserPluginMimeType); + kBrowserPluginMimeType); LoadHTML(html.c_str()); ExecuteJavaScript( @@ -560,7 +562,7 @@ TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { TEST_F(BrowserPluginTest, AutoSizeAttributes) { std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject, - content::kBrowserPluginMimeType); + kBrowserPluginMimeType); LoadHTML(html.c_str()); const char* kSetAutoSizeParametersAndNavigate = "var browserplugin = document.getElementById('browserplugin');" diff --git a/content/renderer/browser_plugin/browser_plugin_browsertest.h b/content/renderer/browser_plugin/browser_plugin_browsertest.h index 28676901378675..415afc3734bc2d 100644 --- a/content/renderer/browser_plugin/browser_plugin_browsertest.h +++ b/content/renderer/browser_plugin/browser_plugin_browsertest.h @@ -9,7 +9,6 @@ #include "base/memory/scoped_ptr.h" #include "content/common/browser_plugin/browser_plugin_messages.h" -#include "content/public/renderer/content_renderer_client.h" #include "content/public/test/render_view_test.h" #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h" #include "content/renderer/render_view_impl.h" @@ -22,7 +21,6 @@ class RenderThreadImpl; namespace content { class MockBrowserPlugin; -class TestContentRendererClient; class BrowserPluginTest : public RenderViewTest { public: @@ -31,6 +29,8 @@ class BrowserPluginTest : public RenderViewTest { virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; + virtual ContentRendererClient* CreateContentRendererClient() OVERRIDE; + MockBrowserPluginManager* browser_plugin_manager() const { return static_cast( static_cast(view_)->GetBrowserPluginManager()); @@ -43,8 +43,6 @@ class BrowserPluginTest : public RenderViewTest { // Returns NULL if there is no plugin. MockBrowserPlugin* GetCurrentPluginWithAttachParams( BrowserPluginHostMsg_Attach_Params* params); - private: - scoped_ptr test_content_renderer_client_; }; } // namespace content diff --git a/content/renderer/browser_render_view_browsertest.cc b/content/renderer/browser_render_view_browsertest.cc index 57bb7a8a06c12c..f5e2a62447fbba 100644 --- a/content/renderer/browser_render_view_browsertest.cc +++ b/content/renderer/browser_render_view_browsertest.cc @@ -137,7 +137,7 @@ void ClearCache(net::URLRequestContextGetter* getter, class RenderViewBrowserTest : public ContentBrowserTest { public: - RenderViewBrowserTest() : renderer_client_(NULL) {} + RenderViewBrowserTest() {} virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { // This method is needed to allow interaction with in-process renderer @@ -145,13 +145,10 @@ class RenderViewBrowserTest : public ContentBrowserTest { command_line->AppendSwitch(switches::kSingleProcess); } - virtual void SetUp() OVERRIDE { + virtual void SetUpOnMainThread() OVERRIDE { // Override setting of renderer client. - renderer_client_ = new TestShellContentRendererClient(); - SetContentRendererClient( - scoped_ptr(renderer_client_).Pass()); - - ContentBrowserTest::SetUp(); + renderer_client_.reset(new TestShellContentRendererClient()); + SetRendererClientForTesting(renderer_client_.get()); } // Navigates to the given URL and waits for |num_navigations| to occur, and @@ -179,7 +176,7 @@ class RenderViewBrowserTest : public ContentBrowserTest { PostTaskToInProcessRendererAndWait( base::Bind(&RenderViewBrowserTest::GetLatestErrorFromRendererClient0, - renderer_client_, &result, error_code, + renderer_client_.get(), &result, error_code, stale_cache_entry_present)); return result; } @@ -193,8 +190,7 @@ class RenderViewBrowserTest : public ContentBrowserTest { error_code, stale_cache_entry_present); } - // Actually owned by the superclass, so safe to keep a bare pointer. - TestShellContentRendererClient* renderer_client_; + scoped_ptr renderer_client_; }; #if defined(OS_ANDROID) diff --git a/content/renderer/render_thread_impl_browsertest.cc b/content/renderer/render_thread_impl_browsertest.cc index 3164c615f2d522..6715ef333748a8 100644 --- a/content/renderer/render_thread_impl_browsertest.cc +++ b/content/renderer/render_thread_impl_browsertest.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "base/command_line.h" +#include "content/public/browser/content_browser_client.h" +#include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" #include "content/public/renderer/content_renderer_client.h" #include "content/renderer/render_process_impl.h" @@ -44,7 +46,11 @@ TEST_F(RenderThreadImplBrowserTest, CommandLine::ForCurrentProcess()->AppendSwitch( switches::kEnableThreadedCompositing); + ContentClient content_client; + ContentBrowserClient content_browser_client; ContentRendererClient content_renderer_client; + SetContentClient(&content_client); + SetBrowserClientForTesting(&content_browser_client); SetRendererClientForTesting(&content_renderer_client); base::MessageLoopForIO message_loop_; diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc index c669ac86b797ee..cbab25c267327a 100644 --- a/content/renderer/render_view_browsertest.cc +++ b/content/renderer/render_view_browsertest.cc @@ -21,6 +21,7 @@ #include "content/public/common/page_zoom.h" #include "content/public/common/url_constants.h" #include "content/public/common/url_utils.h" +#include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/document_state.h" #include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/navigation_state.h" @@ -2067,9 +2068,8 @@ TEST_F(RenderViewImplTest, MessageOrderInDidChangeSelection) { class SuppressErrorPageTest : public RenderViewTest { public: - virtual void SetUp() OVERRIDE { - SetRendererClientForTesting(&client_); - RenderViewTest::SetUp(); + virtual ContentRendererClient* CreateContentRendererClient() OVERRIDE { + return new TestContentRendererClient; } RenderViewImpl* view() { @@ -2099,8 +2099,6 @@ class SuppressErrorPageTest : public RenderViewTest { *error_html = "A suffusion of yellow."; } }; - - TestContentRendererClient client_; }; #if defined(OS_ANDROID) diff --git a/content/shell/renderer/shell_content_renderer_client.cc b/content/shell/renderer/shell_content_renderer_client.cc index e7046ba7547c05..927f7782f9b3f2 100644 --- a/content/shell/renderer/shell_content_renderer_client.cc +++ b/content/shell/renderer/shell_content_renderer_client.cc @@ -43,17 +43,7 @@ using WebTestRunner::WebTestProxyBase; namespace content { -namespace { -ShellContentRendererClient* g_renderer_client; -} - -ShellContentRendererClient* ShellContentRendererClient::Get() { - return g_renderer_client; -} - ShellContentRendererClient::ShellContentRendererClient() { - DCHECK(!g_renderer_client); - g_renderer_client = this; if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) { EnableWebTestProxyCreation( base::Bind(&ShellContentRendererClient::WebTestProxyCreated, @@ -62,7 +52,6 @@ ShellContentRendererClient::ShellContentRendererClient() { } ShellContentRendererClient::~ShellContentRendererClient() { - g_renderer_client = NULL; } void ShellContentRendererClient::RenderThreadStarted() { diff --git a/content/shell/renderer/shell_content_renderer_client.h b/content/shell/renderer/shell_content_renderer_client.h index 01fd91997db93f..584d7796ad7798 100644 --- a/content/shell/renderer/shell_content_renderer_client.h +++ b/content/shell/renderer/shell_content_renderer_client.h @@ -27,8 +27,6 @@ class ShellRenderProcessObserver; class ShellContentRendererClient : public ContentRendererClient { public: - static ShellContentRendererClient* Get(); - ShellContentRendererClient(); virtual ~ShellContentRendererClient(); diff --git a/content/test/content_browser_test.cc b/content/test/content_browser_test.cc index 38816138463f02..01fca9fbb21c03 100644 --- a/content/test/content_browser_test.cc +++ b/content/test/content_browser_test.cc @@ -13,7 +13,6 @@ #include "content/public/common/content_paths.h" #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" -#include "content/shell/app/shell_main_delegate.h" #include "content/shell/browser/shell.h" #include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_content_browser_client.h" @@ -22,6 +21,10 @@ #include "content/test/test_content_client.h" #include "net/test/embedded_test_server/embedded_test_server.h" +#if defined(OS_ANDROID) +#include "content/shell/app/shell_main_delegate.h" +#endif + #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" #endif @@ -43,10 +46,13 @@ ContentBrowserTest::ContentBrowserTest() FILE_PATH_LITERAL("Content Shell.app/Contents/MacOS/Content Shell")); CHECK(PathService::Override(base::FILE_EXE, content_shell_path)); #endif - CreateTestServer(base::FilePath(FILE_PATH_LITERAL("content/test/data"))); - base::FilePath content_test_data_dir; - CHECK(PathService::Get(DIR_TEST_DATA, &content_test_data_dir)); - embedded_test_server()->ServeFilesFromDirectory(content_test_data_dir); + base::FilePath content_test_data(FILE_PATH_LITERAL("content/test/data")); + CreateTestServer(content_test_data); + base::FilePath content_test_data_absolute; + CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &content_test_data_absolute)); + content_test_data_absolute = + content_test_data_absolute.Append(content_test_data); + embedded_test_server()->ServeFilesFromDirectory(content_test_data_absolute); } ContentBrowserTest::~ContentBrowserTest() { @@ -55,27 +61,19 @@ ContentBrowserTest::~ContentBrowserTest() { } void ContentBrowserTest::SetUp() { - shell_main_delegate_.reset(new ShellMainDelegate); - shell_main_delegate_->PreSandboxStartup(); - CommandLine* command_line = CommandLine::ForCurrentProcess(); command_line->AppendSwitch(switches::kContentBrowserTest); SetUpCommandLine(command_line); - // Single-process mode is not set in BrowserMain, so if a subclass hasn't - // modified it yet, process it explicitly, and set up renderer. +#if defined(OS_ANDROID) + shell_main_delegate_.reset(new ShellMainDelegate); + shell_main_delegate_->PreSandboxStartup(); if (command_line->HasSwitch(switches::kSingleProcess)) { - if (!single_process_renderer_client_) - single_process_renderer_client_.reset(new ShellContentRendererClient()); + single_process_renderer_client_.reset(new ShellContentRendererClient()); SetRendererClientForTesting(single_process_renderer_client_.get()); - } else { - // Confirm no test has called SetContentRendererClient() without - // setting up single process mode. - DCHECK(!single_process_renderer_client_); } - -#if defined(OS_MACOSX) +#elif defined(OS_MACOSX) // See InProcessBrowserTest::PrepareTestCommandLine(). base::FilePath subprocess_path; PathService::Get(base::FILE_EXE, &subprocess_path); @@ -105,7 +103,9 @@ void ContentBrowserTest::TearDown() { ui::ShutdownInputMethodForTesting(); #endif +#if defined(OS_ANDROID) shell_main_delegate_.reset(); +#endif } void ContentBrowserTest::RunTestOnMainThreadLoop() { @@ -149,14 +149,6 @@ void ContentBrowserTest::RunTestOnMainThreadLoop() { Shell::CloseAllWindows(); } -void ContentBrowserTest::SetContentRendererClient( - scoped_ptr renderer_client) { - // This routine must be called before SetUp(). - DCHECK(!setup_called_); - DCHECK(!single_process_renderer_client_); - single_process_renderer_client_ = renderer_client.Pass(); -} - Shell* ContentBrowserTest::CreateBrowser() { return Shell::CreateNewWindow( ShellContentBrowserClient::Get()->browser_context(), diff --git a/content/test/content_browser_test.h b/content/test/content_browser_test.h index 0647d4a5c225c9..457993d9cf75f9 100644 --- a/content/test/content_browser_test.h +++ b/content/test/content_browser_test.h @@ -28,10 +28,6 @@ class ContentBrowserTest : public BrowserTestBase { // BrowserTestBase: virtual void RunTestOnMainThreadLoop() OVERRIDE; - // Must be called before or during setup. - void SetContentRendererClient( - scoped_ptr renderer_client); - protected: // Creates a new window and loads about:blank. Shell* CreateBrowser(); @@ -43,14 +39,18 @@ class ContentBrowserTest : public BrowserTestBase { Shell* shell() const { return shell_; } private: - scoped_ptr shell_main_delegate_; - Shell* shell_; bool setup_called_; +#if defined(OS_ANDROID) + // For all other platforms, this is done automatically when calling into + // ContentMain. For Android we set things up manually. + scoped_ptr shell_main_delegate_; + // ContentRendererClient when running in single-process mode. scoped_ptr single_process_renderer_client_; +#endif }; } // namespace content diff --git a/content/test/content_test_launcher.cc b/content/test/content_test_launcher.cc index e61d3972b4952c..e875673c9a97c0 100644 --- a/content/test/content_test_launcher.cc +++ b/content/test/content_test_launcher.cc @@ -6,60 +6,31 @@ #include "base/base_paths.h" #include "base/command_line.h" +#include "base/debug/stack_trace.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/process/memory.h" #include "base/sys_info.h" #include "base/test/test_suite.h" +#include "base/test/test_timeouts.h" #include "content/public/common/content_switches.h" #include "content/public/test/content_test_suite_base.h" #include "content/shell/app/shell_main_delegate.h" -#include "content/shell/browser/shell_content_browser_client.h" -#include "content/shell/common/shell_content_client.h" #include "content/shell/common/shell_switches.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(OS_ANDROID) #include "base/message_loop/message_loop.h" +#include "content/common/url_schemes.h" +#include "content/public/common/content_paths.h" #include "content/public/test/nested_message_pump_android.h" +#include "content/shell/browser/shell_content_browser_client.h" +#include "content/shell/common/shell_content_client.h" +#include "ui/base/ui_base_paths.h" #endif -#if defined(OS_WIN) -#include "content/public/app/startup_helper_win.h" -#include "sandbox/win/src/sandbox_types.h" -#endif // defined(OS_WIN) - namespace content { -class ContentShellTestSuiteInitializer - : public testing::EmptyTestEventListener { - public: - ContentShellTestSuiteInitializer() { - } - - virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { - content_client_.reset(new ShellContentClient); - browser_content_client_.reset(new ShellContentBrowserClient()); - SetContentClient(content_client_.get()); - SetBrowserClientForTesting(browser_content_client_.get()); - } - - virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { -#if !defined(OS_ANDROID) - // On Android, production code doesn't reset ContentClient during shutdown. - // We try to do the same thing as production. Refer to crbug.com/181069. - browser_content_client_.reset(); - content_client_.reset(); - SetContentClient(NULL); -#endif - } - - private: - scoped_ptr content_client_; - scoped_ptr browser_content_client_; - - DISALLOW_COPY_AND_ASSIGN(ContentShellTestSuiteInitializer); -}; - #if defined(OS_ANDROID) scoped_ptr CreateMessagePumpForUI() { return scoped_ptr(new NestedMessagePumpAndroid()); @@ -83,21 +54,28 @@ class ContentBrowserTestSuite : public ContentTestSuiteBase { if (!base::MessageLoop::InitMessagePumpForUIFactory( &CreateMessagePumpForUI)) VLOG(0) << "MessagePumpForUIFactory already set, unable to override."; + + // For all other platforms, we call ContentMain for browser tests which goes + // through the normal browser initialization paths. For Android, we must set + // things up manually. + content_client_.reset(new ShellContentClient); + browser_content_client_.reset(new ShellContentBrowserClient()); + SetContentClient(content_client_.get()); + SetBrowserClientForTesting(browser_content_client_.get()); + + content::RegisterContentSchemes(false); + RegisterPathProvider(); + ui::RegisterPathProvider(); + RegisterInProcessThreads(); #endif ContentTestSuiteBase::Initialize(); - - testing::TestEventListeners& listeners = - testing::UnitTest::GetInstance()->listeners(); - listeners.Append(new ContentShellTestSuiteInitializer); - } - virtual void Shutdown() OVERRIDE { - base::TestSuite::Shutdown(); } - virtual ContentClient* CreateClientForInitialization() OVERRIDE { - return new ShellContentClient(); - } +#if defined(OS_ANDROID) + scoped_ptr content_client_; + scoped_ptr browser_content_client_; +#endif DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite); }; diff --git a/content/test/content_test_suite.cc b/content/test/content_test_suite.cc index 336d02ca76413d..ef1bfe9c3cbb20 100644 --- a/content/test/content_test_suite.cc +++ b/content/test/content_test_suite.cc @@ -7,8 +7,9 @@ #include "base/base_paths.h" #include "base/logging.h" #include "base/path_service.h" +#include "content/public/common/content_client.h" +#include "content/public/common/content_paths.h" #include "content/public/test/test_content_client_initializer.h" -#include "content/test/test_content_client.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/resource/resource_bundle.h" @@ -19,6 +20,7 @@ #if !defined(OS_IOS) #include "base/base_switches.h" #include "base/command_line.h" +#include "media/base/media.h" #include "ui/gl/gl_surface.h" #endif @@ -70,7 +72,13 @@ void ContentTestSuite::Initialize() { #endif ContentTestSuiteBase::Initialize(); + { + ContentClient client; + ContentTestSuiteBase::RegisterContentSchemes(&client); + } + RegisterPathProvider(); #if !defined(OS_IOS) + media::InitializeMediaLibraryForTesting(); // When running in a child process for Mac sandbox tests, the sandbox exists // to initialize GL, so don't do it here. if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestChildProcess)) @@ -81,8 +89,4 @@ void ContentTestSuite::Initialize() { listeners.Append(new TestInitializationListener); } -ContentClient* ContentTestSuite::CreateClientForInitialization() { - return new TestContentClient(); -} - } // namespace content diff --git a/content/test/content_test_suite.h b/content/test/content_test_suite.h index 346f4aace2b68e..f282f4ee39a884 100644 --- a/content/test/content_test_suite.h +++ b/content/test/content_test_suite.h @@ -22,8 +22,6 @@ class ContentTestSuite : public ContentTestSuiteBase { protected: virtual void Initialize() OVERRIDE; - virtual ContentClient* CreateClientForInitialization() OVERRIDE; - private: #if defined(OS_WIN) base::win::ScopedCOMInitializer com_initializer_; diff --git a/ui/views/corewm/desktop_capture_controller_unittest.cc b/ui/views/corewm/desktop_capture_controller_unittest.cc index 4a737b738569ee..3bf5f9e6897752 100644 --- a/ui/views/corewm/desktop_capture_controller_unittest.cc +++ b/ui/views/corewm/desktop_capture_controller_unittest.cc @@ -5,11 +5,15 @@ #include "ui/wm/core/capture_controller.h" #include "base/logging.h" +#include "base/path_service.h" #include "ui/aura/env.h" #include "ui/aura/test/event_generator.h" #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/window_event_dispatcher.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_paths.h" #include "ui/events/event.h" +#include "ui/gl/gl_surface.h" #include "ui/views/test/views_test_base.h" #include "ui/views/view.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" @@ -22,7 +26,22 @@ namespace views { -typedef ViewsTestBase DesktopCaptureControllerTest; +class DesktopCaptureControllerTest : public ViewsTestBase { + public: + DesktopCaptureControllerTest() {} + virtual ~DesktopCaptureControllerTest() {} + + virtual void SetUp() OVERRIDE { + gfx::GLSurface::InitializeOneOffForTests(); + base::FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + base::FilePath pak_file; + pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); + ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); + + ViewsTestBase::SetUp(); + } +}; // This class provides functionality to verify whether the View instance // received the gesture event. diff --git a/ui/views/test/ui_controls_factory_desktop_aurax11.cc b/ui/views/test/ui_controls_factory_desktop_aurax11.cc index 75abae60c865a3..6e147c64c80991 100644 --- a/ui/views/test/ui_controls_factory_desktop_aurax11.cc +++ b/ui/views/test/ui_controls_factory_desktop_aurax11.cc @@ -314,6 +314,8 @@ class UIControlsDesktopX11 : public UIControlsAura { } // namespace UIControlsAura* CreateUIControlsDesktopAura() { + // The constructor of UIControlsDesktopX11 needs XInitThreads to be called. + XInitThreads(); return new UIControlsDesktopX11(); } diff --git a/ui/views/widget/widget_interactive_uitest.cc b/ui/views/widget/widget_interactive_uitest.cc index cdae62fbb3ed32..31554bd72e7420 100644 --- a/ui/views/widget/widget_interactive_uitest.cc +++ b/ui/views/widget/widget_interactive_uitest.cc @@ -4,13 +4,17 @@ #include "base/basictypes.h" #include "base/bind.h" +#include "base/path_service.h" #include "base/run_loop.h" #include "ui/aura/client/activation_client.h" #include "ui/aura/client/focus_client.h" #include "ui/aura/env.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_paths.h" #include "ui/gfx/native_widget_types.h" +#include "ui/gl/gl_surface.h" #include "ui/views/test/widget_test.h" #include "ui/views/widget/widget.h" #include "ui/views/window/dialog_delegate.h" @@ -142,6 +146,22 @@ class NestedLoopCaptureView : public View { } // namespace +class WidgetTestInteractive : public WidgetTest { + public: + WidgetTestInteractive() {} + virtual ~WidgetTestInteractive() {} + + virtual void SetUp() OVERRIDE { + gfx::GLSurface::InitializeOneOffForTests(); + base::FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + base::FilePath pak_file; + pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); + ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); + WidgetTest::SetUp(); + } +}; + #if defined(OS_WIN) // Tests whether activation and focus change works correctly in Windows. // We test the following:- @@ -153,7 +173,7 @@ class NestedLoopCaptureView : public View { // window for widget 1 should be set and that for widget 2 should reset. // TODO(ananta) // Discuss with erg on how to write this test for linux x11 aura. -TEST_F(WidgetTest, DesktopNativeWidgetAuraActivationAndFocusTest) { +TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) { // Create widget 1 and expect the active window to be its window. View* contents_view1 = new View; contents_view1->SetFocusable(true); @@ -209,7 +229,7 @@ TEST_F(WidgetTest, DesktopNativeWidgetAuraActivationAndFocusTest) { } #endif -TEST_F(WidgetTest, CaptureAutoReset) { +TEST_F(WidgetTestInteractive, CaptureAutoReset) { Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); View* container = new View; toplevel->SetContentsView(container); @@ -238,7 +258,7 @@ TEST_F(WidgetTest, CaptureAutoReset) { RunPendingMessages(); } -TEST_F(WidgetTest, ResetCaptureOnGestureEnd) { +TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) { Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); View* container = new View; toplevel->SetContentsView(container); @@ -294,7 +314,7 @@ TEST_F(WidgetTest, ResetCaptureOnGestureEnd) { // Checks that if a mouse-press triggers a capture on a different widget (which // consumes the mouse-release event), then the target of the press does not have // capture. -TEST_F(WidgetTest, DisableCaptureWidgetFromMousePress) { +TEST_F(WidgetTestInteractive, DisableCaptureWidgetFromMousePress) { // The test creates two widgets: |first| and |second|. // The View in |first| makes |second| visible, sets capture on it, and starts // a nested loop (like a menu does). The View in |second| terminates the @@ -333,7 +353,7 @@ TEST_F(WidgetTest, DisableCaptureWidgetFromMousePress) { // Tests some grab/ungrab events. // TODO(estade): can this be enabled now that this is an interactive ui test? -TEST_F(WidgetTest, DISABLED_GrabUngrab) { +TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) { Widget* toplevel = CreateTopLevelPlatformWidget(); Widget* child1 = CreateChildNativeWidgetWithParent(toplevel); Widget* child2 = CreateChildNativeWidgetWithParent(toplevel); @@ -395,7 +415,7 @@ TEST_F(WidgetTest, DISABLED_GrabUngrab) { // Tests mouse move outside of the window into the "resize controller" and back // will still generate an OnMouseEntered and OnMouseExited event.. -TEST_F(WidgetTest, CheckResizeControllerEvents) { +TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) { Widget* toplevel = CreateTopLevelPlatformWidget(); toplevel->SetBounds(gfx::Rect(0, 0, 100, 100)); @@ -471,7 +491,7 @@ class WidgetActivationTest : public Widget { // Tests whether the widget only becomes active when the underlying window // is really active. -TEST_F(WidgetTest, WidgetNotActivatedOnFakeActivationMessages) { +TEST_F(WidgetTestInteractive, WidgetNotActivatedOnFakeActivationMessages) { WidgetActivationTest widget1; Widget::InitParams init_params = CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); @@ -523,7 +543,7 @@ class ModalDialogDelegate : public DialogDelegateView { // Tests whether the focused window is set correctly when a modal window is // created and destroyed. When it is destroyed it should focus the owner // window. -TEST_F(WidgetTest, WindowModalWindowDestroyedActivationTest) { +TEST_F(WidgetTestInteractive, WindowModalWindowDestroyedActivationTest) { // Create a top level widget. Widget top_level_widget; Widget::InitParams init_params = @@ -560,7 +580,7 @@ TEST_F(WidgetTest, WindowModalWindowDestroyedActivationTest) { } // Test that when opening a system-modal window, capture is released. -TEST_F(WidgetTest, SystemModalWindowReleasesCapture) { +TEST_F(WidgetTestInteractive, SystemModalWindowReleasesCapture) { // Create a top level widget. Widget top_level_widget; Widget::InitParams init_params = @@ -634,6 +654,16 @@ class WidgetCaptureTest : public ViewsTestBase { virtual ~WidgetCaptureTest() { } + virtual void SetUp() OVERRIDE { + gfx::GLSurface::InitializeOneOffForTests(); + base::FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + base::FilePath pak_file; + pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); + ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); + ViewsTestBase::SetUp(); + } + // Verifies Widget::SetCapture() results in updating native capture along with // invoking the right Widget function. void TestCapture(bool use_desktop_native_widget) {