// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef ASH_TEST_ASH_TEST_HELPER_H_ #define ASH_TEST_ASH_TEST_HELPER_H_ #include #include #include #include "ash/assistant/test/test_assistant_service.h" #include "ash/public/cpp/test/test_system_tray_client.h" #include "ash/session/test_pref_service_provider.h" #include "ash/session/test_session_controller_client.h" #include "ash/shell_delegate.h" #include "ash/system/message_center/test_notifier_settings_controller.h" #include "base/test/scoped_command_line.h" #include "chromeos/services/bluetooth_config/scoped_bluetooth_config_test_helper.h" #include "chromeos/system/fake_statistics_provider.h" #include "ui/aura/test/aura_test_helper.h" class PrefService; namespace aura { class Window; } // namespace aura namespace base { class SystemMonitor; } // namespace base namespace display { class Display; } // namespace display namespace ui { class ContextFactory; } // namespace ui namespace views { class TestViewsDelegate; } // namespace views namespace ash { class AppListTestHelper; class AmbientAshTestHelper; class AshTestUiStabilizer; class TestKeyboardControllerObserver; class TestNewWindowDelegateProvider; class TestWallpaperControllerClient; namespace input_method { class MockInputMethodManager; } // namespace input_method namespace pixel_test { struct InitParams; } // namespace pixel_test // A helper class that does common initialization required for Ash. Creates a // root window and an ash::Shell instance with a test delegate. class AshTestHelper : public aura::test::AuraTestHelper { public: struct InitParams { InitParams(); InitParams(InitParams&&); InitParams& operator=(InitParams&&) = default; ~InitParams(); // True if the user should log in. bool start_session = true; // If this is not set, a TestShellDelegate will be used automatically. std::unique_ptr delegate; PrefService* local_state = nullptr; // Used only when setting up a pixel diff test. base::raw_ptr pixel_test_init_params = nullptr; }; // Instantiates/destroys an AshTestHelper. This can happen in a // single-threaded phase without a backing task environment or ViewsDelegate, // and must not create those lest the caller wish to do so. explicit AshTestHelper(ui::ContextFactory* context_factory = nullptr); AshTestHelper(const AshTestHelper&) = delete; AshTestHelper& operator=(const AshTestHelper&) = delete; ~AshTestHelper() override; // Calls through to SetUp() below, see comments there. void SetUp() override; // Tears down everything but the Screen instance, which some tests access // after this point. This will be called automatically on destruction if it // is not called manually earlier. void TearDown() override; aura::Window* GetContext() override; aura::WindowTreeHost* GetHost() override; aura::TestScreen* GetTestScreen() override; aura::client::FocusClient* GetFocusClient() override; aura::client::CaptureClient* GetCaptureClient() override; // Creates the ash::Shell and performs associated initialization according // to |init_params|. When this function returns it guarantees a task // environment and ViewsDelegate will exist, the shell will be started, and a // window will be showing. void SetUp(InitParams init_params); display::Display GetSecondaryDisplay() const; // Simulates a user sign-in. It creates a new user session, adds it to // existing user sessions and makes it the active user session. // NOTE: call `StabilizeUIForPixelTest()` after calling this function in a // pixel test. void SimulateUserLogin( const AccountId& account_id, user_manager::UserType user_type = user_manager::USER_TYPE_REGULAR); // Stabilizes the variable UI components (such as the battery view). void StabilizeUIForPixelTest(); TestSessionControllerClient* test_session_controller_client() { return session_controller_client_.get(); } void set_test_session_controller_client( std::unique_ptr session_controller_client) { session_controller_client_ = std::move(session_controller_client); } TestNotifierSettingsController* notifier_settings_controller() { return notifier_settings_controller_.get(); } TestSystemTrayClient* system_tray_client() { return system_tray_client_.get(); } TestPrefServiceProvider* prefs_provider() { return prefs_provider_.get(); } AppListTestHelper* app_list_test_helper() { return app_list_test_helper_.get(); } TestKeyboardControllerObserver* test_keyboard_controller_observer() { return test_keyboard_controller_observer_.get(); } TestAssistantService* test_assistant_service() { return assistant_service_.get(); } AmbientAshTestHelper* ambient_ash_test_helper() { return ambient_ash_test_helper_.get(); } chromeos::bluetooth_config::ScopedBluetoothConfigTestHelper* bluetooth_config_test_helper() { return &scoped_bluetooth_config_test_helper_; } private: // Scoping objects to manage init/teardown of services. class BluezDBusManagerInitializer; class PowerPolicyControllerInitializer; // Must be constructed so that `base::SystemMonitor::Get()` returns a valid // instance. std::unique_ptr system_monitor_; std::unique_ptr command_line_ = std::make_unique(); std::unique_ptr statistics_provider_ = std::make_unique(); std::unique_ptr prefs_provider_ = std::make_unique(); std::unique_ptr notifier_settings_controller_ = std::make_unique(); std::unique_ptr assistant_service_ = std::make_unique(); std::unique_ptr system_tray_client_ = std::make_unique(); std::unique_ptr app_list_test_helper_; std::unique_ptr bluez_dbus_manager_initializer_; std::unique_ptr power_policy_controller_initializer_; std::unique_ptr new_window_delegate_provider_; std::unique_ptr test_views_delegate_; std::unique_ptr session_controller_client_; std::unique_ptr test_keyboard_controller_observer_; std::unique_ptr ambient_ash_test_helper_; std::unique_ptr wallpaper_controller_client_; // Used only for pixel tests. std::unique_ptr ui_stabilizer_; chromeos::bluetooth_config::ScopedBluetoothConfigTestHelper scoped_bluetooth_config_test_helper_; // InputMethodManager is not owned by this class. It is stored in a // global that is registered via InputMethodManager::Initialize(). input_method::MockInputMethodManager* input_method_manager_ = nullptr; }; } // namespace ash #endif // ASH_TEST_ASH_TEST_HELPER_H_