Chromium Code Reviews| Index: services/ui/test_wm/test_wm.cc |
| diff --git a/services/ui/test_wm/test_wm.cc b/services/ui/test_wm/test_wm.cc |
| index 58ba24aed2fe9c595d9da4223c8d193e11baef3f..dc6dcce1faa15eab85bb21fb0890cff199db15fb 100644 |
| --- a/services/ui/test_wm/test_wm.cc |
| +++ b/services/ui/test_wm/test_wm.cc |
| @@ -5,32 +5,56 @@ |
| #include <memory> |
| #include <utility> |
| +#include "base/bind.h" |
| +#include "base/memory/ptr_util.h" |
| #include "mojo/public/cpp/bindings/binding.h" |
| #include "services/service_manager/public/c/main.h" |
| #include "services/service_manager/public/cpp/connector.h" |
| #include "services/service_manager/public/cpp/service.h" |
| #include "services/service_manager/public/cpp/service_context.h" |
| #include "services/service_manager/public/cpp/service_runner.h" |
| -#include "services/ui/public/cpp/window.h" |
| -#include "services/ui/public/cpp/window_manager_delegate.h" |
| -#include "services/ui/public/cpp/window_tree_client.h" |
| -#include "services/ui/public/cpp/window_tree_client_delegate.h" |
| +#include "ui/aura/env.h" |
| +#include "ui/aura/mus/property_converter.h" |
| +#include "ui/aura/mus/window_manager_delegate.h" |
| +#include "ui/aura/mus/window_port_mus.h" |
| +#include "ui/aura/mus/window_tree_client.h" |
| +#include "ui/aura/mus/window_tree_client_delegate.h" |
| +#include "ui/aura/mus/window_tree_host_mus.h" |
| +#include "ui/aura/test/test_focus_client.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/compositor/test/context_factories_for_test.h" |
| #include "ui/display/display.h" |
| +#include "ui/gl/test/gl_surface_test_support.h" |
| +#include "ui/wm/core/capture_controller.h" |
| +#include "ui/wm/core/wm_state.h" |
| namespace ui { |
| namespace test { |
| class TestWM : public service_manager::Service, |
| - public ui::WindowTreeClientDelegate, |
| - public ui::WindowManagerDelegate { |
| + public aura::WindowTreeClientDelegate, |
| + public aura::WindowManagerDelegate { |
| public: |
| - TestWM() {} |
| - ~TestWM() override {} |
| + TestWM() { gl::GLSurfaceTestSupport::InitializeOneOff(); } |
| + ~TestWM() override { |
| + // WindowTreeHost uses state from WindowTreeClient, so destroy it first. |
| + window_tree_host_.reset(); |
| + |
| + // WindowTreeClient destruction may callback to us. |
| + window_tree_client_.reset(); |
| + } |
| private: |
| // service_manager::Service: |
| void OnStart() override { |
| - window_tree_client_.reset(new ui::WindowTreeClient(this, this)); |
| + aura_env_ = aura::Env::CreateInstance( |
| + base::Bind(&TestWM::CreateWindowPort, base::Unretained(this))); |
| + const bool enable_pixel_output = false; |
| + aura_env_->set_context_factory( |
| + ui::InitializeContextFactoryForTests(enable_pixel_output)); |
|
msw
2016/11/14 19:23:10
q: Should something in this file call TerminateCon
sky
2016/11/17 20:29:33
Done.
|
| + wm_state_ = base::MakeUnique<::wm::WMState>(); |
| + window_tree_client_ = |
| + base::MakeUnique<aura::WindowTreeClient>(this, this, nullptr); |
|
msw
2016/11/14 19:23:10
optional nit: drop nullptr arg, it's the default
sky
2016/11/17 20:29:33
Done.
|
| window_tree_client_->ConnectAsWindowManager(context()->connector()); |
| } |
| @@ -39,54 +63,72 @@ class TestWM : public service_manager::Service, |
| return false; |
| } |
| - // ui::WindowTreeClientDelegate: |
| - void OnEmbed(ui::Window* root) override { |
| + // Factory function for creating WindowPort. |
| + std::unique_ptr<aura::WindowPort> CreateWindowPort(aura::Window* window) { |
| + std::unique_ptr<aura::WindowPortMus> window_port = |
| + base::MakeUnique<aura::WindowPortMus>(window_tree_client_.get(), |
| + aura::WindowMusType::LOCAL); |
| + return std::move(window_port); |
| + } |
| + |
| + // aura::WindowTreeClientDelegate: |
| + void OnEmbed( |
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override { |
| // WindowTreeClients configured as the window manager should never get |
| // OnEmbed(). |
| NOTREACHED(); |
| } |
| - void OnLostConnection(WindowTreeClient* client) override { |
| + void OnLostConnection(aura::WindowTreeClient* client) override { |
| + window_tree_host_.reset(); |
| window_tree_client_.reset(); |
| } |
| - void OnEmbedRootDestroyed(ui::Window* root) override { |
| + void OnEmbedRootDestroyed(aura::Window* root) override { |
| // WindowTreeClients configured as the window manager should never get |
| // OnEmbedRootDestroyed(). |
| NOTREACHED(); |
| } |
| void OnPointerEventObserved(const ui::PointerEvent& event, |
| - ui::Window* target) override { |
| + aura::Window* target) override { |
| // Don't care. |
| } |
| + aura::client::CaptureClient* GetCaptureClient() override { |
| + return wm_state_->capture_controller(); |
| + } |
| + aura::PropertyConverter* GetPropertyConverter() override { |
| + return &property_converter_; |
| + } |
| - // ui::WindowManagerDelegate: |
| - void SetWindowManagerClient(ui::WindowManagerClient* client) override { |
| + // aura::WindowManagerDelegate: |
| + void SetWindowManagerClient(aura::WindowManagerClient* client) override { |
| window_manager_client_ = client; |
| } |
| - bool OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) override { |
| + bool OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) override { |
| return true; |
| } |
| bool OnWmSetProperty( |
| - ui::Window* window, |
| + aura::Window* window, |
| const std::string& name, |
| std::unique_ptr<std::vector<uint8_t>>* new_data) override { |
| return true; |
| } |
| - ui::Window* OnWmCreateTopLevelWindow( |
| + aura::Window* OnWmCreateTopLevelWindow( |
| std::map<std::string, std::vector<uint8_t>>* properties) override { |
| - ui::Window* window = root_->window_tree()->NewWindow(properties); |
| + aura::Window* window = new aura::Window(nullptr); |
| + window->Init(LAYER_NOT_DRAWN); |
| window->SetBounds(gfx::Rect(10, 10, 500, 500)); |
| root_->AddChild(window); |
| return window; |
| } |
| - void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, |
| + void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows, |
| bool janky) override { |
| // Don't care. |
| } |
| - void OnWmNewDisplay(Window* window, |
| + void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| const display::Display& display) override { |
| // Only handles a single root. |
| DCHECK(!root_); |
| - root_ = window; |
| + window_tree_host_ = std::move(window_tree_host); |
| + root_ = window_tree_host_->window(); |
| DCHECK(window_manager_client_); |
| window_manager_client_->AddActivationParent(root_); |
| ui::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| @@ -94,20 +136,30 @@ class TestWM : public service_manager::Service, |
| frame_decoration_values->max_title_bar_button_width = 0; |
| window_manager_client_->SetFrameDecorationValues( |
| std::move(frame_decoration_values)); |
| + focus_client_ = base::MakeUnique<aura::test::TestFocusClient>(); |
| + aura::client::SetFocusClient(root_, focus_client_.get()); |
| + } |
| + void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override { |
| + DCHECK_EQ(window_tree_host, window_tree_host_.get()); |
| + window_tree_host_.reset(); |
| } |
| - void OnWmDisplayRemoved(ui::Window* window) override { window->Destroy(); } |
| void OnWmDisplayModified(const display::Display& display) override {} |
| - void OnWmPerformMoveLoop(Window* window, |
| + void OnWmPerformMoveLoop(aura::Window* window, |
| mojom::MoveLoopSource source, |
| const gfx::Point& cursor_location, |
| const base::Callback<void(bool)>& on_done) override { |
| // Don't care. |
| } |
| - void OnWmCancelMoveLoop(Window* window) override {} |
| + void OnWmCancelMoveLoop(aura::Window* window) override {} |
| - ui::Window* root_ = nullptr; |
| - ui::WindowManagerClient* window_manager_client_ = nullptr; |
| - std::unique_ptr<ui::WindowTreeClient> window_tree_client_; |
| + std::unique_ptr<aura::Env> aura_env_; |
| + std::unique_ptr<::wm::WMState> wm_state_; |
|
msw
2016/11/14 19:23:10
nit: avoid unique_ptr?
|
| + aura::PropertyConverter property_converter_; |
| + std::unique_ptr<aura::test::TestFocusClient> focus_client_; |
|
msw
2016/11/14 19:23:10
nit: avoid unique_ptr?
|
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; |
| + aura::Window* root_ = nullptr; |
| + aura::WindowManagerClient* window_manager_client_ = nullptr; |
| + std::unique_ptr<aura::WindowTreeClient> window_tree_client_; |
| DISALLOW_COPY_AND_ASSIGN(TestWM); |
| }; |