Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: services/ui/test_wm/test_wm.cc

Issue 2500973002: Converts test_wm to use aura (Closed)
Patch Set: fix bad remove Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h"
8 #include "mojo/public/cpp/bindings/binding.h" 11 #include "mojo/public/cpp/bindings/binding.h"
9 #include "services/service_manager/public/c/main.h" 12 #include "services/service_manager/public/c/main.h"
10 #include "services/service_manager/public/cpp/connector.h" 13 #include "services/service_manager/public/cpp/connector.h"
11 #include "services/service_manager/public/cpp/service.h" 14 #include "services/service_manager/public/cpp/service.h"
12 #include "services/service_manager/public/cpp/service_context.h" 15 #include "services/service_manager/public/cpp/service_context.h"
13 #include "services/service_manager/public/cpp/service_runner.h" 16 #include "services/service_manager/public/cpp/service_runner.h"
14 #include "services/ui/public/cpp/window.h" 17 #include "ui/aura/env.h"
15 #include "services/ui/public/cpp/window_manager_delegate.h" 18 #include "ui/aura/mus/gpu_service.h"
16 #include "services/ui/public/cpp/window_tree_client.h" 19 #include "ui/aura/mus/mus_context_factory.h"
17 #include "services/ui/public/cpp/window_tree_client_delegate.h" 20 #include "ui/aura/mus/property_converter.h"
21 #include "ui/aura/mus/window_manager_delegate.h"
22 #include "ui/aura/mus/window_tree_client.h"
23 #include "ui/aura/mus/window_tree_client_delegate.h"
24 #include "ui/aura/mus/window_tree_host_mus.h"
25 #include "ui/aura/test/test_focus_client.h"
26 #include "ui/aura/window.h"
27 #include "ui/compositor/test/context_factories_for_test.h"
18 #include "ui/display/display.h" 28 #include "ui/display/display.h"
29 #include "ui/gl/test/gl_surface_test_support.h"
30 #include "ui/wm/core/capture_controller.h"
31 #include "ui/wm/core/wm_state.h"
19 32
20 namespace ui { 33 namespace ui {
21 namespace test { 34 namespace test {
22 35
23 class TestWM : public service_manager::Service, 36 class TestWM : public service_manager::Service,
24 public ui::WindowTreeClientDelegate, 37 public aura::WindowTreeClientDelegate,
25 public ui::WindowManagerDelegate { 38 public aura::WindowManagerDelegate {
26 public: 39 public:
27 TestWM() {} 40 TestWM() { gl::GLSurfaceTestSupport::InitializeOneOff(); }
28 ~TestWM() override {} 41 ~TestWM() override {
42 // WindowTreeHost uses state from WindowTreeClient, so destroy it first.
43 window_tree_host_.reset();
44
45 // WindowTreeClient destruction may callback to us.
46 window_tree_client_.reset();
47
48 gpu_service_.reset();
49
50 ui::TerminateContextFactoryForTests();
msw 2016/11/17 21:26:14 Is this still needed? I don't see InitializeContex
sky 2016/11/17 22:25:54 Done.
51 }
29 52
30 private: 53 private:
31 // service_manager::Service: 54 // service_manager::Service:
32 void OnStart() override { 55 void OnStart() override {
33 window_tree_client_.reset(new ui::WindowTreeClient(this, this)); 56 aura_env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS);
57 gpu_service_ = aura::GpuService::Create(context()->connector(), nullptr);
58 compositor_context_factory_ =
59 base::MakeUnique<aura::MusContextFactory>(gpu_service_.get());
60 aura_env_->set_context_factory(compositor_context_factory_.get());
61 window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>(this, this);
62 aura_env_->SetWindowTreeClient(window_tree_client_.get());
34 window_tree_client_->ConnectAsWindowManager(context()->connector()); 63 window_tree_client_->ConnectAsWindowManager(context()->connector());
35 } 64 }
36 65
37 bool OnConnect(const service_manager::ServiceInfo& remote_info, 66 bool OnConnect(const service_manager::ServiceInfo& remote_info,
38 service_manager::InterfaceRegistry* registry) override { 67 service_manager::InterfaceRegistry* registry) override {
39 return false; 68 return false;
40 } 69 }
41 70
42 // ui::WindowTreeClientDelegate: 71 // aura::WindowTreeClientDelegate:
43 void OnEmbed(ui::Window* root) override { 72 void OnEmbed(
73 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override {
44 // WindowTreeClients configured as the window manager should never get 74 // WindowTreeClients configured as the window manager should never get
45 // OnEmbed(). 75 // OnEmbed().
46 NOTREACHED(); 76 NOTREACHED();
47 } 77 }
48 void OnLostConnection(WindowTreeClient* client) override { 78 void OnLostConnection(aura::WindowTreeClient* client) override {
79 window_tree_host_.reset();
49 window_tree_client_.reset(); 80 window_tree_client_.reset();
50 } 81 }
51 void OnEmbedRootDestroyed(ui::Window* root) override { 82 void OnEmbedRootDestroyed(aura::Window* root) override {
52 // WindowTreeClients configured as the window manager should never get 83 // WindowTreeClients configured as the window manager should never get
53 // OnEmbedRootDestroyed(). 84 // OnEmbedRootDestroyed().
54 NOTREACHED(); 85 NOTREACHED();
55 } 86 }
56 void OnPointerEventObserved(const ui::PointerEvent& event, 87 void OnPointerEventObserved(const ui::PointerEvent& event,
57 ui::Window* target) override { 88 aura::Window* target) override {
58 // Don't care. 89 // Don't care.
59 } 90 }
91 aura::client::CaptureClient* GetCaptureClient() override {
92 return wm_state_.capture_controller();
93 }
94 aura::PropertyConverter* GetPropertyConverter() override {
95 return &property_converter_;
96 }
60 97
61 // ui::WindowManagerDelegate: 98 // aura::WindowManagerDelegate:
62 void SetWindowManagerClient(ui::WindowManagerClient* client) override { 99 void SetWindowManagerClient(aura::WindowManagerClient* client) override {
63 window_manager_client_ = client; 100 window_manager_client_ = client;
64 } 101 }
65 bool OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) override { 102 bool OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) override {
66 return true; 103 return true;
67 } 104 }
68 bool OnWmSetProperty( 105 bool OnWmSetProperty(
69 ui::Window* window, 106 aura::Window* window,
70 const std::string& name, 107 const std::string& name,
71 std::unique_ptr<std::vector<uint8_t>>* new_data) override { 108 std::unique_ptr<std::vector<uint8_t>>* new_data) override {
72 return true; 109 return true;
73 } 110 }
74 ui::Window* OnWmCreateTopLevelWindow( 111 aura::Window* OnWmCreateTopLevelWindow(
75 std::map<std::string, std::vector<uint8_t>>* properties) override { 112 std::map<std::string, std::vector<uint8_t>>* properties) override {
76 ui::Window* window = root_->window_tree()->NewWindow(properties); 113 aura::Window* window = new aura::Window(nullptr);
114 window->Init(LAYER_NOT_DRAWN);
77 window->SetBounds(gfx::Rect(10, 10, 500, 500)); 115 window->SetBounds(gfx::Rect(10, 10, 500, 500));
78 root_->AddChild(window); 116 root_->AddChild(window);
79 return window; 117 return window;
80 } 118 }
81 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, 119 void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows,
82 bool janky) override { 120 bool janky) override {
83 // Don't care. 121 // Don't care.
84 } 122 }
85 void OnWmNewDisplay(Window* window, 123 void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
86 const display::Display& display) override { 124 const display::Display& display) override {
87 // Only handles a single root. 125 // Only handles a single root.
88 DCHECK(!root_); 126 DCHECK(!root_);
89 root_ = window; 127 window_tree_host_ = std::move(window_tree_host);
128 root_ = window_tree_host_->window();
90 DCHECK(window_manager_client_); 129 DCHECK(window_manager_client_);
91 window_manager_client_->AddActivationParent(root_); 130 window_manager_client_->AddActivationParent(root_);
92 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = 131 ui::mojom::FrameDecorationValuesPtr frame_decoration_values =
93 ui::mojom::FrameDecorationValues::New(); 132 ui::mojom::FrameDecorationValues::New();
94 frame_decoration_values->max_title_bar_button_width = 0; 133 frame_decoration_values->max_title_bar_button_width = 0;
95 window_manager_client_->SetFrameDecorationValues( 134 window_manager_client_->SetFrameDecorationValues(
96 std::move(frame_decoration_values)); 135 std::move(frame_decoration_values));
136 aura::client::SetFocusClient(root_, &focus_client_);
97 } 137 }
98 void OnWmDisplayRemoved(ui::Window* window) override { window->Destroy(); } 138 void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override {
139 DCHECK_EQ(window_tree_host, window_tree_host_.get());
140 window_tree_host_.reset();
141 }
99 void OnWmDisplayModified(const display::Display& display) override {} 142 void OnWmDisplayModified(const display::Display& display) override {}
100 void OnWmPerformMoveLoop(Window* window, 143 void OnWmPerformMoveLoop(aura::Window* window,
101 mojom::MoveLoopSource source, 144 mojom::MoveLoopSource source,
102 const gfx::Point& cursor_location, 145 const gfx::Point& cursor_location,
103 const base::Callback<void(bool)>& on_done) override { 146 const base::Callback<void(bool)>& on_done) override {
104 // Don't care. 147 // Don't care.
105 } 148 }
106 void OnWmCancelMoveLoop(Window* window) override {} 149 void OnWmCancelMoveLoop(aura::Window* window) override {}
107 150
108 ui::Window* root_ = nullptr; 151 std::unique_ptr<aura::Env> aura_env_;
109 ui::WindowManagerClient* window_manager_client_ = nullptr; 152 ::wm::WMState wm_state_;
110 std::unique_ptr<ui::WindowTreeClient> window_tree_client_; 153 aura::PropertyConverter property_converter_;
154 aura::test::TestFocusClient focus_client_;
155 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_;
156 aura::Window* root_ = nullptr;
157 aura::WindowManagerClient* window_manager_client_ = nullptr;
158 std::unique_ptr<aura::WindowTreeClient> window_tree_client_;
159 std::unique_ptr<aura::GpuService> gpu_service_;
160 std::unique_ptr<aura::MusContextFactory> compositor_context_factory_;
111 161
112 DISALLOW_COPY_AND_ASSIGN(TestWM); 162 DISALLOW_COPY_AND_ASSIGN(TestWM);
113 }; 163 };
114 164
115 } // namespace test 165 } // namespace test
116 } // namespace ui 166 } // namespace ui
117 167
118 MojoResult ServiceMain(MojoHandle service_request_handle) { 168 MojoResult ServiceMain(MojoHandle service_request_handle) {
119 service_manager::ServiceRunner runner(new ui::test::TestWM); 169 service_manager::ServiceRunner runner(new ui::test::TestWM);
120 return runner.Run(service_request_handle); 170 return runner.Run(service_request_handle);
121 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698