| Index: components/mus/ws/test_utils.cc
|
| diff --git a/components/mus/ws/test_utils.cc b/components/mus/ws/test_utils.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e312919c11a432c8d2ec61936731e4b080bf2fd9
|
| --- /dev/null
|
| +++ b/components/mus/ws/test_utils.cc
|
| @@ -0,0 +1,280 @@
|
| +// Copyright 2016 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 "components/mus/ws/test_utils.h"
|
| +
|
| +#include "cc/output/copy_output_request.h"
|
| +#include "components/mus/surfaces/surfaces_state.h"
|
| +#include "components/mus/ws/window_manager_factory_service.h"
|
| +#include "components/mus/ws/window_tree_host_connection.h"
|
| +#include "mojo/converters/geometry/geometry_type_converters.h"
|
| +
|
| +namespace mus {
|
| +namespace ws {
|
| +namespace test {
|
| +namespace {
|
| +
|
| +// -----------------------------------------------------------------------------
|
| +// Empty implementation of DisplayManager.
|
| +class TestDisplayManager : public DisplayManager {
|
| + public:
|
| + explicit TestDisplayManager(int32_t* cursor_id_storage)
|
| + : cursor_id_storage_(cursor_id_storage) {
|
| + display_metrics_.size_in_pixels = mojo::Size::From(gfx::Size(400, 300));
|
| + display_metrics_.device_pixel_ratio = 1.f;
|
| + }
|
| + ~TestDisplayManager() override {}
|
| +
|
| + // DisplayManager:
|
| + void Init(DisplayManagerDelegate* delegate) override {
|
| + // It is necessary to tell the delegate about the ViewportMetrics to make
|
| + // sure that the WindowTreeHostConnection is correctly initialized (and a
|
| + // root-window is created).
|
| + delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(),
|
| + display_metrics_);
|
| + }
|
| + void SchedulePaint(const ServerWindow* window,
|
| + const gfx::Rect& bounds) override {}
|
| + void SetViewportSize(const gfx::Size& size) override {}
|
| + void SetTitle(const base::string16& title) override {}
|
| + void SetCapture() override {}
|
| + void ReleaseCapture() override {}
|
| + void SetCursorById(int32_t cursor) override { *cursor_id_storage_ = cursor; }
|
| + mojom::Rotation GetRotation() override { return mojom::Rotation::VALUE_0; }
|
| + const mojom::ViewportMetrics& GetViewportMetrics() override {
|
| + return display_metrics_;
|
| + }
|
| + void UpdateTextInputState(const ui::TextInputState& state) override {}
|
| + void SetImeVisibility(bool visible) override {}
|
| + bool IsFramePending() const override { return false; }
|
| + void RequestCopyOfOutput(
|
| + scoped_ptr<cc::CopyOutputRequest> output_request) override {}
|
| +
|
| + private:
|
| + mojom::ViewportMetrics display_metrics_;
|
| +
|
| + int32_t* cursor_id_storage_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestDisplayManager);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// WindowManagerFactoryRegistryTestApi ----------------------------------------
|
| +
|
| +WindowManagerFactoryRegistryTestApi::WindowManagerFactoryRegistryTestApi(
|
| + WindowManagerFactoryRegistry* registry)
|
| + : registry_(registry) {}
|
| +
|
| +WindowManagerFactoryRegistryTestApi::~WindowManagerFactoryRegistryTestApi() {}
|
| +
|
| +void WindowManagerFactoryRegistryTestApi::AddService(
|
| + UserId user_id,
|
| + mojom::WindowManagerFactory* factory) {
|
| + scoped_ptr<WindowManagerFactoryService> service_ptr(
|
| + new WindowManagerFactoryService(registry_, user_id));
|
| + WindowManagerFactoryService* service = service_ptr.get();
|
| + registry_->AddServiceImpl(std::move(service_ptr));
|
| + service->SetWindowManagerFactoryImpl(factory);
|
| +}
|
| +
|
| +// TestDisplayManagerFactory -------------------------------------------------
|
| +
|
| +TestDisplayManagerFactory::TestDisplayManagerFactory(int32_t* cursor_id_storage)
|
| + : cursor_id_storage_(cursor_id_storage) {}
|
| +
|
| +TestDisplayManagerFactory::~TestDisplayManagerFactory() {}
|
| +
|
| +DisplayManager* TestDisplayManagerFactory::CreateDisplayManager(
|
| + mojo::Connector* connector,
|
| + const scoped_refptr<GpuState>& gpu_state,
|
| + const scoped_refptr<mus::SurfacesState>& surfaces_state) {
|
| + return new TestDisplayManager(cursor_id_storage_);
|
| +}
|
| +
|
| +// WindowTreeTestApi ---------------------------------------------------------
|
| +
|
| +WindowTreeTestApi::WindowTreeTestApi(WindowTreeImpl* tree) : tree_(tree) {}
|
| +WindowTreeTestApi::~WindowTreeTestApi() {}
|
| +
|
| +// WindowTreeHostTestApi -----------------------------------------------------
|
| +
|
| +WindowTreeHostTestApi::WindowTreeHostTestApi(WindowTreeHostImpl* tree_host)
|
| + : tree_host_(tree_host) {}
|
| +WindowTreeHostTestApi::~WindowTreeHostTestApi() {}
|
| +
|
| +// TestWindowTreeClient -------------------------------------------------------
|
| +
|
| +TestWindowTreeClient::TestWindowTreeClient()
|
| + : binding_(this), record_on_change_completed_(false) {}
|
| +TestWindowTreeClient::~TestWindowTreeClient() {}
|
| +
|
| +void TestWindowTreeClient::Bind(
|
| + mojo::InterfaceRequest<mojom::WindowTreeClient> request) {
|
| + binding_.Bind(std::move(request));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnEmbed(uint16_t connection_id,
|
| + mojom::WindowDataPtr root,
|
| + mus::mojom::WindowTreePtr tree,
|
| + Id focused_window_id,
|
| + uint32_t access_policy) {
|
| + // TODO(sky): add test coverage of |focused_window_id|.
|
| + tracker_.OnEmbed(connection_id, std::move(root));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnEmbeddedAppDisconnected(uint32_t window) {
|
| + tracker_.OnEmbeddedAppDisconnected(window);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnUnembed(Id window_id) {
|
| + tracker_.OnUnembed(window_id);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnLostCapture(Id window_id) {}
|
| +
|
| +void TestWindowTreeClient::OnTopLevelCreated(uint32_t change_id,
|
| + mojom::WindowDataPtr data) {
|
| + tracker_.OnTopLevelCreated(change_id, std::move(data));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowBoundsChanged(uint32_t window,
|
| + mojo::RectPtr old_bounds,
|
| + mojo::RectPtr new_bounds) {
|
| + tracker_.OnWindowBoundsChanged(window, std::move(old_bounds),
|
| + std::move(new_bounds));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnClientAreaChanged(
|
| + uint32_t window_id,
|
| + mojo::InsetsPtr new_client_area,
|
| + mojo::Array<mojo::RectPtr> new_additional_client_areas) {}
|
| +
|
| +void TestWindowTreeClient::OnTransientWindowAdded(
|
| + uint32_t window_id,
|
| + uint32_t transient_window_id) {}
|
| +
|
| +void TestWindowTreeClient::OnTransientWindowRemoved(
|
| + uint32_t window_id,
|
| + uint32_t transient_window_id) {}
|
| +
|
| +void TestWindowTreeClient::OnWindowViewportMetricsChanged(
|
| + mojo::Array<uint32_t> window_ids,
|
| + mojom::ViewportMetricsPtr old_metrics,
|
| + mojom::ViewportMetricsPtr new_metrics) {
|
| + tracker_.OnWindowViewportMetricsChanged(std::move(old_metrics),
|
| + std::move(new_metrics));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowHierarchyChanged(
|
| + uint32_t window,
|
| + uint32_t new_parent,
|
| + uint32_t old_parent,
|
| + mojo::Array<mojom::WindowDataPtr> windows) {
|
| + tracker_.OnWindowHierarchyChanged(window, new_parent, old_parent,
|
| + std::move(windows));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowReordered(uint32_t window_id,
|
| + uint32_t relative_window_id,
|
| + mojom::OrderDirection direction) {
|
| + tracker_.OnWindowReordered(window_id, relative_window_id, direction);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowDeleted(uint32_t window) {
|
| + tracker_.OnWindowDeleted(window);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowVisibilityChanged(uint32_t window,
|
| + bool visible) {
|
| + tracker_.OnWindowVisibilityChanged(window, visible);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowDrawnStateChanged(uint32_t window,
|
| + bool drawn) {
|
| + tracker_.OnWindowDrawnStateChanged(window, drawn);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowSharedPropertyChanged(
|
| + uint32_t window,
|
| + const mojo::String& name,
|
| + mojo::Array<uint8_t> new_data) {
|
| + tracker_.OnWindowSharedPropertyChanged(window, name, std::move(new_data));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowInputEvent(uint32_t event_id,
|
| + uint32_t window,
|
| + mojom::EventPtr event) {
|
| + tracker_.OnWindowInputEvent(window, std::move(event));
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowFocused(uint32_t focused_window_id) {
|
| + tracker_.OnWindowFocused(focused_window_id);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnWindowPredefinedCursorChanged(
|
| + uint32_t window_id,
|
| + mojom::Cursor cursor_id) {
|
| + tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id);
|
| +}
|
| +
|
| +void TestWindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) {
|
| + if (record_on_change_completed_)
|
| + tracker_.OnChangeCompleted(change_id, success);
|
| +}
|
| +
|
| +void TestWindowTreeClient::RequestClose(uint32_t window_id) {}
|
| +
|
| +void TestWindowTreeClient::GetWindowManager(
|
| + mojo::AssociatedInterfaceRequest<mojom::WindowManager> internal) {}
|
| +
|
| +// TestClientConnection --------------------------------------------------------
|
| +
|
| +TestClientConnection::TestClientConnection() : ClientConnection(&client_) {}
|
| +TestClientConnection::~TestClientConnection() {}
|
| +
|
| +mojom::WindowManager* TestClientConnection::GetWindowManager() {
|
| + NOTREACHED();
|
| + return nullptr;
|
| +}
|
| +void TestClientConnection::SetIncomingMethodCallProcessingPaused(bool paused) {
|
| + is_paused_ = paused;
|
| +}
|
| +
|
| +// TestConnectionManagerDelegate ----------------------------------------------
|
| +
|
| +TestConnectionManagerDelegate::TestConnectionManagerDelegate() {}
|
| +TestConnectionManagerDelegate::~TestConnectionManagerDelegate() {}
|
| +
|
| +void TestConnectionManagerDelegate::OnNoMoreRootConnections() {
|
| + got_on_no_more_connections_ = true;
|
| +}
|
| +
|
| +scoped_ptr<ClientConnection>
|
| +TestConnectionManagerDelegate::CreateClientConnectionForEmbedAtWindow(
|
| + ws::ConnectionManager* connection_manager,
|
| + ws::WindowTreeImpl* tree,
|
| + mojom::WindowTreeRequest tree_request,
|
| + mojom::WindowTreeClientPtr client) {
|
| + scoped_ptr<TestClientConnection> connection(new TestClientConnection);
|
| + last_connection_ = connection.get();
|
| + return std::move(connection);
|
| +}
|
| +
|
| +void TestConnectionManagerDelegate::CreateDefaultWindowTreeHosts() {
|
| + DCHECK(num_tree_hosts_to_create_);
|
| + DCHECK(connection_manager_);
|
| +
|
| + for (int i = 0; i < num_tree_hosts_to_create_; ++i) {
|
| + // WindowTreeHostImpl manages its own lifetime.
|
| + WindowTreeHostImpl* host_impl = new WindowTreeHostImpl(
|
| + connection_manager_, nullptr, scoped_refptr<GpuState>(),
|
| + scoped_refptr<mus::SurfacesState>());
|
| + host_impl->Init(nullptr);
|
| + }
|
| +}
|
| +
|
| +} // namespace test
|
| +} // namespace ws
|
| +} // namespace mus
|
|
|