blob: 25f612bb5e2d8ffab3db08b9d37a44533928951b [file] [log] [blame]
// Copyright (c) 2012 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.
#include <memory>
#include "base/macros.h"
#include "ui/aura/env.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
namespace ui {
class ContextFactory;
class ScopedAnimationDurationScaleMode;
namespace wm {
class WMState;
namespace aura {
class Env;
class TestScreen;
class TestWindowTree;
class TestWindowTreeClientSetup;
class Window;
class WindowManagerDelegate;
class WindowTreeClient;
class WindowTreeClientDelegate;
namespace client {
class CaptureClient;
class DefaultCaptureClient;
class FocusClient;
namespace test {
class TestWindowParentingClient;
// A helper class owned by tests that does common initialization required for
// Aura use. This class creates a root window with clients and other objects
// that are necessary to run test on Aura.
class AuraTestHelper {
// Returns the current AuraTestHelper, or nullptr if it's not alive.
static AuraTestHelper* GetInstance();
// Makes aura target mus with a mock WindowTree (TestWindowTree). Must be
// called before SetUp().
void EnableMusWithTestWindowTree(
WindowTreeClientDelegate* window_tree_delegate,
WindowManagerDelegate* window_manager_delegate);
// Makes aura target mus with the specified WindowTreeClient. Must be called
// before SetUp().
void EnableMusWithWindowTreeClient(WindowTreeClient* window_tree_client);
// Creates and initializes (shows and sizes) the RootWindow for use in tests.
void SetUp(ui::ContextFactory* context_factory,
ui::ContextFactoryPrivate* context_factory_private);
// Clean up objects that are created for tests. This also deletes the Env
// object.
void TearDown();
// Flushes message loop.
void RunAllPendingInMessageLoop();
Window* root_window() { return host_->window(); }
ui::EventSink* event_sink() { return host_->event_sink(); }
WindowTreeHost* host() { return host_.get(); }
TestScreen* test_screen() { return test_screen_.get(); }
// This function only returns a valid value if EnableMusWithTestWindowTree()
// was called.
TestWindowTree* window_tree();
// Returns a WindowTreeClient only if one of the EnableMus functions is
// called.
WindowTreeClient* window_tree_client();
client::FocusClient* focus_client() { return focus_client_.get(); }
client::CaptureClient* capture_client();
enum class Mode {
// Classic aura.
// Mus with a test WindowTree implementation that does not target the real
// service:ui.
// Mus without creating a WindowTree. This is used when the test wants to
// create the WindowTreeClient itself. This mode is enabled by way of
// EnableMusWithWindowTreeClient().
// Initializes a WindowTreeClient with a test WindowTree.
void InitWindowTreeClient();
Mode mode_ = Mode::LOCAL;
bool setup_called_;
bool teardown_called_;
std::unique_ptr<TestWindowTreeClientSetup> window_tree_client_setup_;
std::unique_ptr<aura::Env> env_;
std::unique_ptr<wm::WMState> wm_state_;
std::unique_ptr<WindowTreeHost> host_;
std::unique_ptr<TestWindowParentingClient> parenting_client_;
std::unique_ptr<client::DefaultCaptureClient> capture_client_;
std::unique_ptr<client::FocusClient> focus_client_;
std::unique_ptr<TestScreen> test_screen_;
std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
WindowTreeClientDelegate* window_tree_delegate_ = nullptr;
WindowManagerDelegate* window_manager_delegate_ = nullptr;
WindowTreeClient* window_tree_client_ = nullptr;
} // namespace test
} // namespace aura