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

Side by Side Diff: components/mus/ws/view_tree_apptest.cc

Issue 1406153004: components/mus/public/interfaces View => Window (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yet another rebase Created 5 years, 2 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "components/mus/public/interfaces/view_tree.mojom.h" 9 #include "components/mus/public/interfaces/window_tree.mojom.h"
10 #include "components/mus/public/interfaces/view_tree_host.mojom.h" 10 #include "components/mus/public/interfaces/window_tree_host.mojom.h"
11 #include "components/mus/ws/ids.h" 11 #include "components/mus/ws/ids.h"
12 #include "components/mus/ws/test_change_tracker.h" 12 #include "components/mus/ws/test_change_tracker.h"
13 #include "mojo/application/public/cpp/application_delegate.h" 13 #include "mojo/application/public/cpp/application_delegate.h"
14 #include "mojo/application/public/cpp/application_impl.h" 14 #include "mojo/application/public/cpp/application_impl.h"
15 #include "mojo/application/public/cpp/application_test_base.h" 15 #include "mojo/application/public/cpp/application_test_base.h"
16 16
17 using mojo::ApplicationConnection; 17 using mojo::ApplicationConnection;
18 using mojo::ApplicationDelegate; 18 using mojo::ApplicationDelegate;
19 using mojo::Array; 19 using mojo::Array;
20 using mojo::Callback; 20 using mojo::Callback;
21 using mojo::ERROR_CODE_NONE;
22 using mojo::ErrorCode;
23 using mojo::EventPtr; 21 using mojo::EventPtr;
24 using mojo::InterfaceRequest; 22 using mojo::InterfaceRequest;
25 using mojo::ORDER_DIRECTION_ABOVE;
26 using mojo::ORDER_DIRECTION_BELOW;
27 using mojo::OrderDirection;
28 using mojo::RectPtr; 23 using mojo::RectPtr;
29 using mojo::ServiceProvider; 24 using mojo::ServiceProvider;
30 using mojo::ServiceProviderPtr; 25 using mojo::ServiceProviderPtr;
31 using mojo::String; 26 using mojo::String;
32 using mojo::ViewDataPtr; 27 using mus::mojom::ERROR_CODE_NONE;
33 using mojo::ViewTree; 28 using mus::mojom::ErrorCode;
34 using mojo::ViewTreeClient; 29 using mus::mojom::ViewportMetricsPtr;
35 using mojo::ViewportMetricsPtr; 30 using mus::mojom::WindowDataPtr;
31 using mus::mojom::WindowTree;
32 using mus::mojom::WindowTreeClient;
36 33
37 namespace mus { 34 namespace mus {
38 35
39 namespace { 36 namespace {
40 37
41 // Creates an id used for transport from the specified parameters. 38 // Creates an id used for transport from the specified parameters.
42 Id BuildViewId(ConnectionSpecificId connection_id, 39 Id BuildViewId(ConnectionSpecificId connection_id,
43 ConnectionSpecificId view_id) { 40 ConnectionSpecificId window_id) {
44 return (connection_id << 16) | view_id; 41 return (connection_id << 16) | window_id;
45 } 42 }
46 43
47 // Callback function from ViewTree functions. ---------------------------------- 44 // Callback function from WindowTree functions.
45 // ----------------------------------
48 46
49 void BoolResultCallback(base::RunLoop* run_loop, 47 void BoolResultCallback(base::RunLoop* run_loop,
50 bool* result_cache, 48 bool* result_cache,
51 bool result) { 49 bool result) {
52 *result_cache = result; 50 *result_cache = result;
53 run_loop->Quit(); 51 run_loop->Quit();
54 } 52 }
55 53
56 void ErrorCodeResultCallback(base::RunLoop* run_loop, 54 void ErrorCodeResultCallback(base::RunLoop* run_loop,
57 ErrorCode* result_cache, 55 ErrorCode* result_cache,
58 ErrorCode result) { 56 ErrorCode result) {
59 *result_cache = result; 57 *result_cache = result;
60 run_loop->Quit(); 58 run_loop->Quit();
61 } 59 }
62 60
63 void ViewTreeResultCallback(base::RunLoop* run_loop, 61 void WindowTreeResultCallback(base::RunLoop* run_loop,
64 std::vector<TestView>* views, 62 std::vector<TestView>* views,
65 Array<ViewDataPtr> results) { 63 Array<WindowDataPtr> results) {
66 ViewDatasToTestViews(results, views); 64 WindowDatasToTestViews(results, views);
67 run_loop->Quit(); 65 run_loop->Quit();
68 } 66 }
69 67
70 void EmbedCallbackImpl(base::RunLoop* run_loop, 68 void EmbedCallbackImpl(base::RunLoop* run_loop,
71 bool* result_cache, 69 bool* result_cache,
72 bool result, 70 bool result,
73 ConnectionSpecificId connection_id) { 71 ConnectionSpecificId connection_id) {
74 *result_cache = result; 72 *result_cache = result;
75 run_loop->Quit(); 73 run_loop->Quit();
76 } 74 }
77 75
78 // ----------------------------------------------------------------------------- 76 // -----------------------------------------------------------------------------
79 77
80 bool EmbedUrl(mojo::ApplicationImpl* app, 78 bool EmbedUrl(mojo::ApplicationImpl* app,
81 ViewTree* vm, 79 WindowTree* vm,
82 const String& url, 80 const String& url,
83 Id root_id) { 81 Id root_id) {
84 bool result = false; 82 bool result = false;
85 base::RunLoop run_loop; 83 base::RunLoop run_loop;
86 { 84 {
87 mojo::URLRequestPtr request(mojo::URLRequest::New()); 85 mojo::URLRequestPtr request(mojo::URLRequest::New());
88 request->url = mojo::String::From(url); 86 request->url = mojo::String::From(url);
89 scoped_ptr<ApplicationConnection> connection = 87 scoped_ptr<ApplicationConnection> connection =
90 app->ConnectToApplication(request.Pass()); 88 app->ConnectToApplication(request.Pass());
91 mojo::ViewTreeClientPtr client; 89 mojom::WindowTreeClientPtr client;
92 connection->ConnectToService(&client); 90 connection->ConnectToService(&client);
93 vm->Embed(root_id, client.Pass(), mojo::ViewTree::ACCESS_POLICY_DEFAULT, 91 vm->Embed(root_id, client.Pass(), mojom::WindowTree::ACCESS_POLICY_DEFAULT,
94 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); 92 base::Bind(&EmbedCallbackImpl, &run_loop, &result));
95 } 93 }
96 run_loop.Run(); 94 run_loop.Run();
97 return result; 95 return result;
98 } 96 }
99 97
100 bool Embed(ViewTree* vm, Id root_id, mojo::ViewTreeClientPtr client) { 98 bool Embed(WindowTree* vm, Id root_id, mojom::WindowTreeClientPtr client) {
101 bool result = false; 99 bool result = false;
102 base::RunLoop run_loop; 100 base::RunLoop run_loop;
103 { 101 {
104 vm->Embed(root_id, client.Pass(), mojo::ViewTree::ACCESS_POLICY_DEFAULT, 102 vm->Embed(root_id, client.Pass(), mojom::WindowTree::ACCESS_POLICY_DEFAULT,
105 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); 103 base::Bind(&EmbedCallbackImpl, &run_loop, &result));
106 } 104 }
107 run_loop.Run(); 105 run_loop.Run();
108 return result; 106 return result;
109 } 107 }
110 108
111 ErrorCode CreateViewWithErrorCode(ViewTree* vm, Id view_id) { 109 ErrorCode NewWindowWithErrorCode(WindowTree* vm, Id window_id) {
112 ErrorCode result = ERROR_CODE_NONE; 110 ErrorCode result = ERROR_CODE_NONE;
113 base::RunLoop run_loop; 111 base::RunLoop run_loop;
114 vm->CreateView(view_id, 112 vm->NewWindow(window_id,
115 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); 113 base::Bind(&ErrorCodeResultCallback, &run_loop, &result));
116 run_loop.Run(); 114 run_loop.Run();
117 return result; 115 return result;
118 } 116 }
119 117
120 bool AddView(ViewTree* vm, Id parent, Id child) { 118 bool AddWindow(WindowTree* vm, Id parent, Id child) {
121 bool result = false; 119 bool result = false;
122 base::RunLoop run_loop; 120 base::RunLoop run_loop;
123 vm->AddView(parent, child, 121 vm->AddWindow(parent, child,
124 base::Bind(&BoolResultCallback, &run_loop, &result)); 122 base::Bind(&BoolResultCallback, &run_loop, &result));
125 run_loop.Run(); 123 run_loop.Run();
126 return result; 124 return result;
127 } 125 }
128 126
129 bool RemoveViewFromParent(ViewTree* vm, Id view_id) { 127 bool RemoveWindowFromParent(WindowTree* vm, Id window_id) {
130 bool result = false; 128 bool result = false;
131 base::RunLoop run_loop; 129 base::RunLoop run_loop;
132 vm->RemoveViewFromParent(view_id, 130 vm->RemoveWindowFromParent(
133 base::Bind(&BoolResultCallback, &run_loop, &result)); 131 window_id, base::Bind(&BoolResultCallback, &run_loop, &result));
134 run_loop.Run(); 132 run_loop.Run();
135 return result; 133 return result;
136 } 134 }
137 135
138 bool ReorderView(ViewTree* vm, 136 bool ReorderWindow(WindowTree* vm,
139 Id view_id, 137 Id window_id,
140 Id relative_view_id, 138 Id relative_window_id,
141 OrderDirection direction) { 139 mojom::OrderDirection direction) {
142 bool result = false; 140 bool result = false;
143 base::RunLoop run_loop; 141 base::RunLoop run_loop;
144 vm->ReorderView(view_id, relative_view_id, direction, 142 vm->ReorderWindow(window_id, relative_window_id, direction,
145 base::Bind(&BoolResultCallback, &run_loop, &result)); 143 base::Bind(&BoolResultCallback, &run_loop, &result));
146 run_loop.Run(); 144 run_loop.Run();
147 return result; 145 return result;
148 } 146 }
149 147
150 void GetViewTree(ViewTree* vm, Id view_id, std::vector<TestView>* views) { 148 void GetWindowTree(WindowTree* vm, Id window_id, std::vector<TestView>* views) {
151 base::RunLoop run_loop; 149 base::RunLoop run_loop;
152 vm->GetViewTree(view_id, 150 vm->GetWindowTree(window_id,
153 base::Bind(&ViewTreeResultCallback, &run_loop, views)); 151 base::Bind(&WindowTreeResultCallback, &run_loop, views));
154 run_loop.Run(); 152 run_loop.Run();
155 } 153 }
156 154
157 bool DeleteView(ViewTree* vm, Id view_id) { 155 bool DeleteWindow(WindowTree* vm, Id window_id) {
158 base::RunLoop run_loop; 156 base::RunLoop run_loop;
159 bool result = false; 157 bool result = false;
160 vm->DeleteView(view_id, base::Bind(&BoolResultCallback, &run_loop, &result)); 158 vm->DeleteWindow(window_id,
159 base::Bind(&BoolResultCallback, &run_loop, &result));
161 run_loop.Run(); 160 run_loop.Run();
162 return result; 161 return result;
163 } 162 }
164 163
165 bool SetViewBounds(ViewTree* vm, Id view_id, int x, int y, int w, int h) { 164 bool SetWindowBounds(WindowTree* vm, Id window_id, int x, int y, int w, int h) {
166 base::RunLoop run_loop; 165 base::RunLoop run_loop;
167 bool result = false; 166 bool result = false;
168 RectPtr rect(mojo::Rect::New()); 167 RectPtr rect(mojo::Rect::New());
169 rect->x = x; 168 rect->x = x;
170 rect->y = y; 169 rect->y = y;
171 rect->width = w; 170 rect->width = w;
172 rect->height = h; 171 rect->height = h;
173 vm->SetViewBounds(view_id, rect.Pass(), 172 vm->SetWindowBounds(window_id, rect.Pass(),
174 base::Bind(&BoolResultCallback, &run_loop, &result)); 173 base::Bind(&BoolResultCallback, &run_loop, &result));
175 run_loop.Run(); 174 run_loop.Run();
176 return result; 175 return result;
177 } 176 }
178 177
179 bool SetViewVisibility(ViewTree* vm, Id view_id, bool visible) { 178 bool SetWindowVisibility(WindowTree* vm, Id window_id, bool visible) {
180 base::RunLoop run_loop; 179 base::RunLoop run_loop;
181 bool result = false; 180 bool result = false;
182 vm->SetViewVisibility(view_id, visible, 181 vm->SetWindowVisibility(window_id, visible,
183 base::Bind(&BoolResultCallback, &run_loop, &result)); 182 base::Bind(&BoolResultCallback, &run_loop, &result));
184 run_loop.Run(); 183 run_loop.Run();
185 return result; 184 return result;
186 } 185 }
187 186
188 bool SetViewProperty(ViewTree* vm, 187 bool SetWindowProperty(WindowTree* vm,
189 Id view_id, 188 Id window_id,
190 const std::string& name, 189 const std::string& name,
191 const std::vector<uint8_t>* data) { 190 const std::vector<uint8_t>* data) {
192 base::RunLoop run_loop; 191 base::RunLoop run_loop;
193 bool result = false; 192 bool result = false;
194 Array<uint8_t> mojo_data; 193 Array<uint8_t> mojo_data;
195 if (data) 194 if (data)
196 mojo_data = Array<uint8_t>::From(*data); 195 mojo_data = Array<uint8_t>::From(*data);
197 vm->SetViewProperty(view_id, name, mojo_data.Pass(), 196 vm->SetWindowProperty(window_id, name, mojo_data.Pass(),
198 base::Bind(&BoolResultCallback, &run_loop, &result)); 197 base::Bind(&BoolResultCallback, &run_loop, &result));
199 run_loop.Run(); 198 run_loop.Run();
200 return result; 199 return result;
201 } 200 }
202 201
203 // Utility functions ----------------------------------------------------------- 202 // Utility functions -----------------------------------------------------------
204 203
205 // Waits for all messages to be received by |vm|. This is done by attempting to 204 // Waits for all messages to be received by |vm|. This is done by attempting to
206 // create a bogus view. When we get the response we know all messages have been 205 // create a bogus view. When we get the response we know all messages have been
207 // processed. 206 // processed.
208 bool WaitForAllMessages(ViewTree* vm) { 207 bool WaitForAllMessages(WindowTree* vm) {
209 ErrorCode result = ERROR_CODE_NONE; 208 ErrorCode result = ERROR_CODE_NONE;
210 base::RunLoop run_loop; 209 base::RunLoop run_loop;
211 vm->CreateView(ViewIdToTransportId(InvalidViewId()), 210 vm->NewWindow(ViewIdToTransportId(InvalidViewId()),
212 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); 211 base::Bind(&ErrorCodeResultCallback, &run_loop, &result));
213 run_loop.Run(); 212 run_loop.Run();
214 return result != ERROR_CODE_NONE; 213 return result != ERROR_CODE_NONE;
215 } 214 }
216 215
217 const Id kNullParentId = 0; 216 const Id kNullParentId = 0;
218 std::string IdToString(Id id) { 217 std::string IdToString(Id id) {
219 return (id == kNullParentId) ? "null" : base::StringPrintf( 218 return (id == kNullParentId) ? "null" : base::StringPrintf(
220 "%d,%d", HiWord(id), LoWord(id)); 219 "%d,%d", HiWord(id), LoWord(id));
221 } 220 }
222 221
223 std::string ViewParentToString(Id view, Id parent) { 222 std::string ViewParentToString(Id view, Id parent) {
224 return base::StringPrintf("view=%s parent=%s", IdToString(view).c_str(), 223 return base::StringPrintf("view=%s parent=%s", IdToString(view).c_str(),
225 IdToString(parent).c_str()); 224 IdToString(parent).c_str());
226 } 225 }
227 226
228 // ----------------------------------------------------------------------------- 227 // -----------------------------------------------------------------------------
229 228
230 // A ViewTreeClient implementation that logs all changes to a tracker. 229 // A WindowTreeClient implementation that logs all changes to a tracker.
231 class TestViewTreeClientImpl : public mojo::ViewTreeClient, 230 class TestWindowTreeClientImpl : public mojom::WindowTreeClient,
232 public TestChangeTracker::Delegate { 231 public TestChangeTracker::Delegate {
233 public: 232 public:
234 explicit TestViewTreeClientImpl(mojo::ApplicationImpl* app) 233 explicit TestWindowTreeClientImpl(mojo::ApplicationImpl* app)
235 : binding_(this), app_(app), connection_id_(0), root_view_id_(0) { 234 : binding_(this), app_(app), connection_id_(0), root_window_id_(0) {
236 tracker_.set_delegate(this); 235 tracker_.set_delegate(this);
237 } 236 }
238 237
239 void Bind(mojo::InterfaceRequest<mojo::ViewTreeClient> request) { 238 void Bind(mojo::InterfaceRequest<mojom::WindowTreeClient> request) {
240 binding_.Bind(request.Pass()); 239 binding_.Bind(request.Pass());
241 } 240 }
242 241
243 mojo::ViewTree* tree() { return tree_.get(); } 242 mojom::WindowTree* tree() { return tree_.get(); }
244 TestChangeTracker* tracker() { return &tracker_; } 243 TestChangeTracker* tracker() { return &tracker_; }
245 244
246 // Runs a nested MessageLoop until |count| changes (calls to 245 // Runs a nested MessageLoop until |count| changes (calls to
247 // ViewTreeClient functions) have been received. 246 // WindowTreeClient functions) have been received.
248 void WaitForChangeCount(size_t count) { 247 void WaitForChangeCount(size_t count) {
249 if (tracker_.changes()->size() >= count) 248 if (tracker_.changes()->size() >= count)
250 return; 249 return;
251 250
252 ASSERT_TRUE(wait_state_.get() == nullptr); 251 ASSERT_TRUE(wait_state_.get() == nullptr);
253 wait_state_.reset(new WaitState); 252 wait_state_.reset(new WaitState);
254 wait_state_->change_count = count; 253 wait_state_->change_count = count;
255 wait_state_->run_loop.Run(); 254 wait_state_->run_loop.Run();
256 wait_state_.reset(); 255 wait_state_.reset();
257 } 256 }
258 257
259 // Runs a nested MessageLoop until OnEmbed() has been encountered. 258 // Runs a nested MessageLoop until OnEmbed() has been encountered.
260 void WaitForOnEmbed() { 259 void WaitForOnEmbed() {
261 if (tree_) 260 if (tree_)
262 return; 261 return;
263 embed_run_loop_.reset(new base::RunLoop); 262 embed_run_loop_.reset(new base::RunLoop);
264 embed_run_loop_->Run(); 263 embed_run_loop_->Run();
265 embed_run_loop_.reset(); 264 embed_run_loop_.reset();
266 } 265 }
267 266
268 bool WaitForIncomingMethodCall() { 267 bool WaitForIncomingMethodCall() {
269 return binding_.WaitForIncomingMethodCall(); 268 return binding_.WaitForIncomingMethodCall();
270 } 269 }
271 270
272 Id CreateView(ConnectionSpecificId view_id) { 271 Id NewWindow(ConnectionSpecificId window_id) {
273 ErrorCode result = ERROR_CODE_NONE; 272 ErrorCode result = ERROR_CODE_NONE;
274 base::RunLoop run_loop; 273 base::RunLoop run_loop;
275 Id id = BuildViewId(connection_id_, view_id); 274 Id id = BuildViewId(connection_id_, window_id);
276 tree()->CreateView( 275 tree()->NewWindow(id,
277 id, base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); 276 base::Bind(&ErrorCodeResultCallback, &run_loop, &result));
278 run_loop.Run(); 277 run_loop.Run();
279 return result == ERROR_CODE_NONE ? id : 0; 278 return result == ERROR_CODE_NONE ? id : 0;
280 } 279 }
281 280
282 void set_root_view(Id root_view_id) { root_view_id_ = root_view_id; } 281 void set_root_view(Id root_window_id) { root_window_id_ = root_window_id; }
283 282
284 private: 283 private:
285 // Used when running a nested MessageLoop. 284 // Used when running a nested MessageLoop.
286 struct WaitState { 285 struct WaitState {
287 WaitState() : change_count(0) {} 286 WaitState() : change_count(0) {}
288 287
289 // Number of changes waiting for. 288 // Number of changes waiting for.
290 size_t change_count; 289 size_t change_count;
291 base::RunLoop run_loop; 290 base::RunLoop run_loop;
292 }; 291 };
293 292
294 // TestChangeTracker::Delegate: 293 // TestChangeTracker::Delegate:
295 void OnChangeAdded() override { 294 void OnChangeAdded() override {
296 if (wait_state_.get() && 295 if (wait_state_.get() &&
297 tracker_.changes()->size() >= wait_state_->change_count) { 296 tracker_.changes()->size() >= wait_state_->change_count) {
298 wait_state_->run_loop.Quit(); 297 wait_state_->run_loop.Quit();
299 } 298 }
300 } 299 }
301 300
302 // ViewTreeClient: 301 // WindowTreeClient:
303 void OnEmbed(ConnectionSpecificId connection_id, 302 void OnEmbed(ConnectionSpecificId connection_id,
304 ViewDataPtr root, 303 WindowDataPtr root,
305 mojo::ViewTreePtr tree, 304 mojom::WindowTreePtr tree,
306 Id focused_view_id, 305 Id focused_window_id,
307 uint32_t access_policy) override { 306 uint32_t access_policy) override {
308 // TODO(sky): add coverage of |focused_view_id|. 307 // TODO(sky): add coverage of |focused_window_id|.
309 tree_ = tree.Pass(); 308 tree_ = tree.Pass();
310 connection_id_ = connection_id; 309 connection_id_ = connection_id;
311 tracker()->OnEmbed(connection_id, root.Pass()); 310 tracker()->OnEmbed(connection_id, root.Pass());
312 if (embed_run_loop_) 311 if (embed_run_loop_)
313 embed_run_loop_->Quit(); 312 embed_run_loop_->Quit();
314 } 313 }
315 void OnEmbeddedAppDisconnected(Id view_id) override { 314 void OnEmbeddedAppDisconnected(Id window_id) override {
316 tracker()->OnEmbeddedAppDisconnected(view_id); 315 tracker()->OnEmbeddedAppDisconnected(window_id);
317 } 316 }
318 void OnUnembed() override { tracker()->OnUnembed(); } 317 void OnUnembed() override { tracker()->OnUnembed(); }
319 void OnWindowBoundsChanged(Id view_id, 318 void OnWindowBoundsChanged(Id window_id,
320 RectPtr old_bounds, 319 RectPtr old_bounds,
321 RectPtr new_bounds) override { 320 RectPtr new_bounds) override {
322 // The bounds of the root may change during startup on Android at random 321 // The bounds of the root may change during startup on Android at random
323 // times. As this doesn't matter, and shouldn't impact test exepctations, 322 // times. As this doesn't matter, and shouldn't impact test exepctations,
324 // it is ignored. 323 // it is ignored.
325 if (view_id == root_view_id_) 324 if (window_id == root_window_id_)
326 return; 325 return;
327 tracker()->OnWindowBoundsChanged(view_id, old_bounds.Pass(), 326 tracker()->OnWindowBoundsChanged(window_id, old_bounds.Pass(),
328 new_bounds.Pass()); 327 new_bounds.Pass());
329 } 328 }
330 void OnClientAreaChanged(uint32_t window_id, 329 void OnClientAreaChanged(uint32_t window_id,
331 mojo::RectPtr old_client_area, 330 mojo::RectPtr old_client_area,
332 mojo::RectPtr new_client_area) override {} 331 mojo::RectPtr new_client_area) override {}
333 void OnWindowViewportMetricsChanged(ViewportMetricsPtr old_metrics, 332 void OnWindowViewportMetricsChanged(ViewportMetricsPtr old_metrics,
334 ViewportMetricsPtr new_metrics) override { 333 ViewportMetricsPtr new_metrics) override {
335 // Don't track the metrics as they are available at an indeterministic time 334 // Don't track the metrics as they are available at an indeterministic time
336 // on Android. 335 // on Android.
337 } 336 }
338 void OnWindowHierarchyChanged(Id view, 337 void OnWindowHierarchyChanged(Id view,
339 Id new_parent, 338 Id new_parent,
340 Id old_parent, 339 Id old_parent,
341 Array<ViewDataPtr> views) override { 340 Array<WindowDataPtr> views) override {
342 tracker()->OnWindowHierarchyChanged(view, new_parent, old_parent, 341 tracker()->OnWindowHierarchyChanged(view, new_parent, old_parent,
343 views.Pass()); 342 views.Pass());
344 } 343 }
345 void OnWindowReordered(Id view_id, 344 void OnWindowReordered(Id window_id,
346 Id relative_view_id, 345 Id relative_window_id,
347 OrderDirection direction) override { 346 mojom::OrderDirection direction) override {
348 tracker()->OnWindowReordered(view_id, relative_view_id, direction); 347 tracker()->OnWindowReordered(window_id, relative_window_id, direction);
349 } 348 }
350 void OnWindowDeleted(Id view) override { tracker()->OnWindowDeleted(view); } 349 void OnWindowDeleted(Id view) override { tracker()->OnWindowDeleted(view); }
351 void OnWindowVisibilityChanged(uint32_t view, bool visible) override { 350 void OnWindowVisibilityChanged(uint32_t view, bool visible) override {
352 tracker()->OnWindowVisibilityChanged(view, visible); 351 tracker()->OnWindowVisibilityChanged(view, visible);
353 } 352 }
354 void OnWindowDrawnStateChanged(uint32_t view, bool drawn) override { 353 void OnWindowDrawnStateChanged(uint32_t view, bool drawn) override {
355 tracker()->OnWindowDrawnStateChanged(view, drawn); 354 tracker()->OnWindowDrawnStateChanged(view, drawn);
356 } 355 }
357 void OnWindowInputEvent(Id view_id, 356 void OnWindowInputEvent(Id window_id,
358 EventPtr event, 357 EventPtr event,
359 const Callback<void()>& callback) override { 358 const Callback<void()>& callback) override {
360 // Don't log input events as none of the tests care about them and they 359 // Don't log input events as none of the tests care about them and they
361 // may come in at random points. 360 // may come in at random points.
362 callback.Run(); 361 callback.Run();
363 } 362 }
364 void OnWindowSharedPropertyChanged(uint32_t view, 363 void OnWindowSharedPropertyChanged(uint32_t view,
365 const String& name, 364 const String& name,
366 Array<uint8_t> new_data) override { 365 Array<uint8_t> new_data) override {
367 tracker_.OnWindowSharedPropertyChanged(view, name, new_data.Pass()); 366 tracker_.OnWindowSharedPropertyChanged(view, name, new_data.Pass());
368 } 367 }
369 // TODO(sky): add testing coverage. 368 // TODO(sky): add testing coverage.
370 void OnWindowFocused(uint32_t focused_view_id) override {} 369 void OnWindowFocused(uint32_t focused_window_id) override {}
371 370
372 TestChangeTracker tracker_; 371 TestChangeTracker tracker_;
373 372
374 mojo::ViewTreePtr tree_; 373 mojom::WindowTreePtr tree_;
375 374
376 // If non-null we're waiting for OnEmbed() using this RunLoop. 375 // If non-null we're waiting for OnEmbed() using this RunLoop.
377 scoped_ptr<base::RunLoop> embed_run_loop_; 376 scoped_ptr<base::RunLoop> embed_run_loop_;
378 377
379 // If non-null we're waiting for a certain number of change notifications to 378 // If non-null we're waiting for a certain number of change notifications to
380 // be encountered. 379 // be encountered.
381 scoped_ptr<WaitState> wait_state_; 380 scoped_ptr<WaitState> wait_state_;
382 381
383 mojo::Binding<ViewTreeClient> binding_; 382 mojo::Binding<WindowTreeClient> binding_;
384 mojo::ApplicationImpl* app_; 383 mojo::ApplicationImpl* app_;
385 Id connection_id_; 384 Id connection_id_;
386 Id root_view_id_; 385 Id root_window_id_;
387 386
388 DISALLOW_COPY_AND_ASSIGN(TestViewTreeClientImpl); 387 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClientImpl);
389 }; 388 };
390 389
391 // ----------------------------------------------------------------------------- 390 // -----------------------------------------------------------------------------
392 391
393 // InterfaceFactory for vending TestViewTreeClientImpls. 392 // InterfaceFactory for vending TestWindowTreeClientImpls.
394 class ViewTreeClientFactory : public mojo::InterfaceFactory<ViewTreeClient> { 393 class WindowTreeClientFactory
394 : public mojo::InterfaceFactory<WindowTreeClient> {
395 public: 395 public:
396 explicit ViewTreeClientFactory(mojo::ApplicationImpl* app) : app_(app) {} 396 explicit WindowTreeClientFactory(mojo::ApplicationImpl* app) : app_(app) {}
397 ~ViewTreeClientFactory() override {} 397 ~WindowTreeClientFactory() override {}
398 398
399 // Runs a nested MessageLoop until a new instance has been created. 399 // Runs a nested MessageLoop until a new instance has been created.
400 scoped_ptr<TestViewTreeClientImpl> WaitForInstance() { 400 scoped_ptr<TestWindowTreeClientImpl> WaitForInstance() {
401 if (!client_impl_.get()) { 401 if (!client_impl_.get()) {
402 DCHECK(!run_loop_.get()); 402 DCHECK(!run_loop_.get());
403 run_loop_.reset(new base::RunLoop); 403 run_loop_.reset(new base::RunLoop);
404 run_loop_->Run(); 404 run_loop_->Run();
405 run_loop_.reset(); 405 run_loop_.reset();
406 } 406 }
407 return client_impl_.Pass(); 407 return client_impl_.Pass();
408 } 408 }
409 409
410 private: 410 private:
411 // InterfaceFactory<ViewTreeClient>: 411 // InterfaceFactory<WindowTreeClient>:
412 void Create(ApplicationConnection* connection, 412 void Create(ApplicationConnection* connection,
413 InterfaceRequest<ViewTreeClient> request) override { 413 InterfaceRequest<WindowTreeClient> request) override {
414 client_impl_.reset(new TestViewTreeClientImpl(app_)); 414 client_impl_.reset(new TestWindowTreeClientImpl(app_));
415 client_impl_->Bind(request.Pass()); 415 client_impl_->Bind(request.Pass());
416 if (run_loop_.get()) 416 if (run_loop_.get())
417 run_loop_->Quit(); 417 run_loop_->Quit();
418 } 418 }
419 419
420 mojo::ApplicationImpl* app_; 420 mojo::ApplicationImpl* app_;
421 scoped_ptr<TestViewTreeClientImpl> client_impl_; 421 scoped_ptr<TestWindowTreeClientImpl> client_impl_;
422 scoped_ptr<base::RunLoop> run_loop_; 422 scoped_ptr<base::RunLoop> run_loop_;
423 423
424 DISALLOW_COPY_AND_ASSIGN(ViewTreeClientFactory); 424 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientFactory);
425 }; 425 };
426 426
427 } // namespace 427 } // namespace
428 428
429 class ViewTreeAppTest : public mojo::test::ApplicationTestBase, 429 class WindowTreeAppTest : public mojo::test::ApplicationTestBase,
430 public ApplicationDelegate { 430 public ApplicationDelegate {
431 public: 431 public:
432 ViewTreeAppTest() 432 WindowTreeAppTest()
433 : connection_id_1_(0), connection_id_2_(0), root_view_id_(0) {} 433 : connection_id_1_(0), connection_id_2_(0), root_window_id_(0) {}
434 ~ViewTreeAppTest() override {} 434 ~WindowTreeAppTest() override {}
435 435
436 protected: 436 protected:
437 // Returns the changes from the various connections. 437 // Returns the changes from the various connections.
438 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); } 438 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); }
439 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } 439 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); }
440 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } 440 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); }
441 441
442 // Various connections. |vm1()|, being the first connection, has special 442 // Various connections. |vm1()|, being the first connection, has special
443 // permissions (it's treated as the window manager). 443 // permissions (it's treated as the window manager).
444 ViewTree* vm1() { return vm_client1_->tree(); } 444 WindowTree* vm1() { return vm_client1_->tree(); }
445 ViewTree* vm2() { return vm_client2_->tree(); } 445 WindowTree* vm2() { return vm_client2_->tree(); }
446 ViewTree* vm3() { return vm_client3_->tree(); } 446 WindowTree* vm3() { return vm_client3_->tree(); }
447 447
448 TestViewTreeClientImpl* vm_client1() { return vm_client1_.get(); } 448 TestWindowTreeClientImpl* vm_client1() { return vm_client1_.get(); }
449 TestViewTreeClientImpl* vm_client2() { return vm_client2_.get(); } 449 TestWindowTreeClientImpl* vm_client2() { return vm_client2_.get(); }
450 TestViewTreeClientImpl* vm_client3() { return vm_client3_.get(); } 450 TestWindowTreeClientImpl* vm_client3() { return vm_client3_.get(); }
451 451
452 Id root_view_id() const { return root_view_id_; } 452 Id root_window_id() const { return root_window_id_; }
453 453
454 int connection_id_1() const { return connection_id_1_; } 454 int connection_id_1() const { return connection_id_1_; }
455 int connection_id_2() const { return connection_id_2_; } 455 int connection_id_2() const { return connection_id_2_; }
456 456
457 void EstablishSecondConnectionWithRoot(Id root_id) { 457 void EstablishSecondConnectionWithRoot(Id root_id) {
458 ASSERT_TRUE(vm_client2_.get() == nullptr); 458 ASSERT_TRUE(vm_client2_.get() == nullptr);
459 vm_client2_ = 459 vm_client2_ =
460 EstablishConnectionViaEmbed(vm1(), root_id, &connection_id_2_); 460 EstablishConnectionViaEmbed(vm1(), root_id, &connection_id_2_);
461 ASSERT_GT(connection_id_2_, 0); 461 ASSERT_GT(connection_id_2_, 0);
462 ASSERT_TRUE(vm_client2_.get() != nullptr); 462 ASSERT_TRUE(vm_client2_.get() != nullptr);
463 vm_client2_->set_root_view(root_view_id_); 463 vm_client2_->set_root_view(root_window_id_);
464 } 464 }
465 465
466 void EstablishSecondConnection(bool create_initial_view) { 466 void EstablishSecondConnection(bool create_initial_view) {
467 Id view_1_1 = 0; 467 Id view_1_1 = 0;
468 if (create_initial_view) { 468 if (create_initial_view) {
469 view_1_1 = vm_client1()->CreateView(1); 469 view_1_1 = vm_client1()->NewWindow(1);
470 ASSERT_TRUE(view_1_1); 470 ASSERT_TRUE(view_1_1);
471 } 471 }
472 ASSERT_NO_FATAL_FAILURE( 472 ASSERT_NO_FATAL_FAILURE(
473 EstablishSecondConnectionWithRoot(BuildViewId(connection_id_1(), 1))); 473 EstablishSecondConnectionWithRoot(BuildViewId(connection_id_1(), 1)));
474 474
475 if (create_initial_view) { 475 if (create_initial_view) {
476 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]", 476 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]",
477 ChangeViewDescription(*changes2())); 477 ChangeViewDescription(*changes2()));
478 } 478 }
479 } 479 }
480 480
481 void EstablishThirdConnection(ViewTree* owner, Id root_id) { 481 void EstablishThirdConnection(WindowTree* owner, Id root_id) {
482 ASSERT_TRUE(vm_client3_.get() == nullptr); 482 ASSERT_TRUE(vm_client3_.get() == nullptr);
483 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr); 483 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr);
484 ASSERT_TRUE(vm_client3_.get() != nullptr); 484 ASSERT_TRUE(vm_client3_.get() != nullptr);
485 vm_client3_->set_root_view(root_view_id_); 485 vm_client3_->set_root_view(root_window_id_);
486 } 486 }
487 487
488 scoped_ptr<TestViewTreeClientImpl> WaitForViewTreeClient() { 488 scoped_ptr<TestWindowTreeClientImpl> WaitForWindowTreeClient() {
489 return client_factory_->WaitForInstance(); 489 return client_factory_->WaitForInstance();
490 } 490 }
491 491
492 // Establishes a new connection by way of Embed() on the specified 492 // Establishes a new connection by way of Embed() on the specified
493 // ViewTree. 493 // WindowTree.
494 scoped_ptr<TestViewTreeClientImpl> 494 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed(
495 EstablishConnectionViaEmbed(ViewTree* owner, Id root_id, int* connection_id) { 495 WindowTree* owner,
496 Id root_id,
497 int* connection_id) {
496 return EstablishConnectionViaEmbedWithPolicyBitmask( 498 return EstablishConnectionViaEmbedWithPolicyBitmask(
497 owner, root_id, mojo::ViewTree::ACCESS_POLICY_DEFAULT, connection_id); 499 owner, root_id, mojom::WindowTree::ACCESS_POLICY_DEFAULT,
500 connection_id);
498 } 501 }
499 502
500 scoped_ptr<TestViewTreeClientImpl> 503 scoped_ptr<TestWindowTreeClientImpl>
501 EstablishConnectionViaEmbedWithPolicyBitmask(ViewTree* owner, 504 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner,
502 Id root_id, 505 Id root_id,
503 uint32_t policy_bitmask, 506 uint32_t policy_bitmask,
504 int* connection_id) { 507 int* connection_id) {
505 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), 508 if (!EmbedUrl(application_impl(), owner, application_impl()->url(),
506 root_id)) { 509 root_id)) {
507 ADD_FAILURE() << "Embed() failed"; 510 ADD_FAILURE() << "Embed() failed";
508 return nullptr; 511 return nullptr;
509 } 512 }
510 scoped_ptr<TestViewTreeClientImpl> client = 513 scoped_ptr<TestWindowTreeClientImpl> client =
511 client_factory_->WaitForInstance(); 514 client_factory_->WaitForInstance();
512 if (!client.get()) { 515 if (!client.get()) {
513 ADD_FAILURE() << "WaitForInstance failed"; 516 ADD_FAILURE() << "WaitForInstance failed";
514 return nullptr; 517 return nullptr;
515 } 518 }
516 client->WaitForOnEmbed(); 519 client->WaitForOnEmbed();
517 520
518 EXPECT_EQ("OnEmbed", 521 EXPECT_EQ("OnEmbed",
519 SingleChangeToDescription(*client->tracker()->changes())); 522 SingleChangeToDescription(*client->tracker()->changes()));
520 if (connection_id) 523 if (connection_id)
521 *connection_id = (*client->tracker()->changes())[0].connection_id; 524 *connection_id = (*client->tracker()->changes())[0].connection_id;
522 return client.Pass(); 525 return client.Pass();
523 } 526 }
524 527
525 // ApplicationTestBase: 528 // ApplicationTestBase:
526 ApplicationDelegate* GetApplicationDelegate() override { return this; } 529 ApplicationDelegate* GetApplicationDelegate() override { return this; }
527 void SetUp() override { 530 void SetUp() override {
528 ApplicationTestBase::SetUp(); 531 ApplicationTestBase::SetUp();
529 client_factory_.reset(new ViewTreeClientFactory(application_impl())); 532 client_factory_.reset(new WindowTreeClientFactory(application_impl()));
530 mojo::URLRequestPtr request(mojo::URLRequest::New()); 533 mojo::URLRequestPtr request(mojo::URLRequest::New());
531 request->url = mojo::String::From("mojo:mus"); 534 request->url = mojo::String::From("mojo:mus");
532 535
533 mojo::ViewTreeHostFactoryPtr factory; 536 mojom::WindowTreeHostFactoryPtr factory;
534 application_impl()->ConnectToService(request.Pass(), &factory); 537 application_impl()->ConnectToService(request.Pass(), &factory);
535 538
536 mojo::ViewTreeClientPtr tree_client_ptr; 539 mojom::WindowTreeClientPtr tree_client_ptr;
537 vm_client1_.reset(new TestViewTreeClientImpl(application_impl())); 540 vm_client1_.reset(new TestWindowTreeClientImpl(application_impl()));
538 vm_client1_->Bind(GetProxy(&tree_client_ptr)); 541 vm_client1_->Bind(GetProxy(&tree_client_ptr));
539 542
540 factory->CreateWindowTreeHost(GetProxy(&host_), 543 factory->CreateWindowTreeHost(GetProxy(&host_),
541 mojo::ViewTreeHostClientPtr(), 544 mojom::WindowTreeHostClientPtr(),
542 tree_client_ptr.Pass()); 545 tree_client_ptr.Pass());
543 546
544 // Next we should get an embed call on the "window manager" client. 547 // Next we should get an embed call on the "window manager" client.
545 vm_client1_->WaitForIncomingMethodCall(); 548 vm_client1_->WaitForIncomingMethodCall();
546 549
547 ASSERT_EQ(1u, changes1()->size()); 550 ASSERT_EQ(1u, changes1()->size());
548 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); 551 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type);
549 // All these tests assume 1 for the client id. The only real assertion here 552 // All these tests assume 1 for the client id. The only real assertion here
550 // is the client id is not zero, but adding this as rest of code here 553 // is the client id is not zero, but adding this as rest of code here
551 // assumes 1. 554 // assumes 1.
552 ASSERT_GT((*changes1())[0].connection_id, 0); 555 ASSERT_GT((*changes1())[0].connection_id, 0);
553 connection_id_1_ = (*changes1())[0].connection_id; 556 connection_id_1_ = (*changes1())[0].connection_id;
554 ASSERT_FALSE((*changes1())[0].views.empty()); 557 ASSERT_FALSE((*changes1())[0].views.empty());
555 root_view_id_ = (*changes1())[0].views[0].view_id; 558 root_window_id_ = (*changes1())[0].views[0].window_id;
556 vm_client1_->set_root_view(root_view_id_); 559 vm_client1_->set_root_view(root_window_id_);
557 changes1()->clear(); 560 changes1()->clear();
558 } 561 }
559 562
560 // ApplicationDelegate implementation. 563 // ApplicationDelegate implementation.
561 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 564 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
562 connection->AddService(client_factory_.get()); 565 connection->AddService(client_factory_.get());
563 return true; 566 return true;
564 } 567 }
565 568
566 scoped_ptr<TestViewTreeClientImpl> vm_client1_; 569 scoped_ptr<TestWindowTreeClientImpl> vm_client1_;
567 scoped_ptr<TestViewTreeClientImpl> vm_client2_; 570 scoped_ptr<TestWindowTreeClientImpl> vm_client2_;
568 scoped_ptr<TestViewTreeClientImpl> vm_client3_; 571 scoped_ptr<TestWindowTreeClientImpl> vm_client3_;
569 572
570 mojo::ViewTreeHostPtr host_; 573 mojom::WindowTreeHostPtr host_;
571 574
572 private: 575 private:
573 scoped_ptr<ViewTreeClientFactory> client_factory_; 576 scoped_ptr<WindowTreeClientFactory> client_factory_;
574 int connection_id_1_; 577 int connection_id_1_;
575 int connection_id_2_; 578 int connection_id_2_;
576 Id root_view_id_; 579 Id root_window_id_;
577 580
578 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewTreeAppTest); 581 MOJO_DISALLOW_COPY_AND_ASSIGN(WindowTreeAppTest);
579 }; 582 };
580 583
581 // Verifies two clients/connections get different ids. 584 // Verifies two clients/connections get different ids.
582 TEST_F(ViewTreeAppTest, TwoClientsGetDifferentConnectionIds) { 585 TEST_F(WindowTreeAppTest, TwoClientsGetDifferentConnectionIds) {
583 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 586 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
584 587
585 ASSERT_EQ(1u, changes2()->size()); 588 ASSERT_EQ(1u, changes2()->size());
586 ASSERT_NE(connection_id_1(), connection_id_2()); 589 ASSERT_NE(connection_id_1(), connection_id_2());
587 } 590 }
588 591
589 // Verifies when Embed() is invoked any child views are removed. 592 // Verifies when Embed() is invoked any child views are removed.
590 TEST_F(ViewTreeAppTest, ViewsRemovedWhenEmbedding) { 593 TEST_F(WindowTreeAppTest, ViewsRemovedWhenEmbedding) {
591 // Two views 1 and 2. 2 is parented to 1. 594 // Two views 1 and 2. 2 is parented to 1.
592 Id view_1_1 = vm_client1()->CreateView(1); 595 Id view_1_1 = vm_client1()->NewWindow(1);
593 ASSERT_TRUE(view_1_1); 596 ASSERT_TRUE(view_1_1);
594 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 597 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
595 598
596 Id view_1_2 = vm_client1()->CreateView(2); 599 Id view_1_2 = vm_client1()->NewWindow(2);
597 ASSERT_TRUE(view_1_2); 600 ASSERT_TRUE(view_1_2);
598 ASSERT_TRUE(AddView(vm1(), view_1_1, view_1_2)); 601 ASSERT_TRUE(AddWindow(vm1(), view_1_1, view_1_2));
599 602
600 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 603 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
601 ASSERT_EQ(1u, changes2()->size()); 604 ASSERT_EQ(1u, changes2()->size());
602 ASSERT_EQ(1u, (*changes2())[0].views.size()); 605 ASSERT_EQ(1u, (*changes2())[0].views.size());
603 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]", 606 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]",
604 ChangeViewDescription(*changes2())); 607 ChangeViewDescription(*changes2()));
605 608
606 // Embed() removed view 2. 609 // Embed() removed view 2.
607 { 610 {
608 std::vector<TestView> views; 611 std::vector<TestView> views;
609 GetViewTree(vm1(), view_1_2, &views); 612 GetWindowTree(vm1(), view_1_2, &views);
610 EXPECT_EQ(ViewParentToString(view_1_2, kNullParentId), 613 EXPECT_EQ(ViewParentToString(view_1_2, kNullParentId),
611 SingleViewDescription(views)); 614 SingleViewDescription(views));
612 } 615 }
613 616
614 // vm2 should not see view 2. 617 // vm2 should not see view 2.
615 { 618 {
616 std::vector<TestView> views; 619 std::vector<TestView> views;
617 GetViewTree(vm2(), view_1_1, &views); 620 GetWindowTree(vm2(), view_1_1, &views);
618 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), 621 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId),
619 SingleViewDescription(views)); 622 SingleViewDescription(views));
620 } 623 }
621 { 624 {
622 std::vector<TestView> views; 625 std::vector<TestView> views;
623 GetViewTree(vm2(), view_1_2, &views); 626 GetWindowTree(vm2(), view_1_2, &views);
624 EXPECT_TRUE(views.empty()); 627 EXPECT_TRUE(views.empty());
625 } 628 }
626 629
627 // Views 3 and 4 in connection 2. 630 // Views 3 and 4 in connection 2.
628 Id view_2_3 = vm_client2()->CreateView(3); 631 Id view_2_3 = vm_client2()->NewWindow(3);
629 Id view_2_4 = vm_client2()->CreateView(4); 632 Id view_2_4 = vm_client2()->NewWindow(4);
630 ASSERT_TRUE(view_2_3); 633 ASSERT_TRUE(view_2_3);
631 ASSERT_TRUE(view_2_4); 634 ASSERT_TRUE(view_2_4);
632 ASSERT_TRUE(AddView(vm2(), view_2_3, view_2_4)); 635 ASSERT_TRUE(AddWindow(vm2(), view_2_3, view_2_4));
633 636
634 // Connection 3 rooted at 2. 637 // Connection 3 rooted at 2.
635 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_3)); 638 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_3));
636 639
637 // View 4 should no longer have a parent. 640 // View 4 should no longer have a parent.
638 { 641 {
639 std::vector<TestView> views; 642 std::vector<TestView> views;
640 GetViewTree(vm2(), view_2_3, &views); 643 GetWindowTree(vm2(), view_2_3, &views);
641 EXPECT_EQ(ViewParentToString(view_2_3, kNullParentId), 644 EXPECT_EQ(ViewParentToString(view_2_3, kNullParentId),
642 SingleViewDescription(views)); 645 SingleViewDescription(views));
643 646
644 views.clear(); 647 views.clear();
645 GetViewTree(vm2(), view_2_4, &views); 648 GetWindowTree(vm2(), view_2_4, &views);
646 EXPECT_EQ(ViewParentToString(view_2_4, kNullParentId), 649 EXPECT_EQ(ViewParentToString(view_2_4, kNullParentId),
647 SingleViewDescription(views)); 650 SingleViewDescription(views));
648 } 651 }
649 652
650 // And view 4 should not be visible to connection 3. 653 // And view 4 should not be visible to connection 3.
651 { 654 {
652 std::vector<TestView> views; 655 std::vector<TestView> views;
653 GetViewTree(vm3(), view_2_3, &views); 656 GetWindowTree(vm3(), view_2_3, &views);
654 EXPECT_EQ(ViewParentToString(view_2_3, kNullParentId), 657 EXPECT_EQ(ViewParentToString(view_2_3, kNullParentId),
655 SingleViewDescription(views)); 658 SingleViewDescription(views));
656 } 659 }
657 } 660 }
658 661
659 // Verifies once Embed() has been invoked the parent connection can't see any 662 // Verifies once Embed() has been invoked the parent connection can't see any
660 // children. 663 // children.
661 TEST_F(ViewTreeAppTest, CantAccessChildrenOfEmbeddedView) { 664 TEST_F(WindowTreeAppTest, CantAccessChildrenOfEmbeddedView) {
662 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 665 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
663 666
664 Id view_1_1 = BuildViewId(connection_id_1(), 1); 667 Id view_1_1 = BuildViewId(connection_id_1(), 1);
665 Id view_2_2 = vm_client2()->CreateView(2); 668 Id view_2_2 = vm_client2()->NewWindow(2);
666 ASSERT_TRUE(view_2_2); 669 ASSERT_TRUE(view_2_2);
667 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 670 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
668 671
669 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2)); 672 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2));
670 673
671 Id view_3_3 = vm_client3()->CreateView(3); 674 Id view_3_3 = vm_client3()->NewWindow(3);
672 ASSERT_TRUE(view_3_3); 675 ASSERT_TRUE(view_3_3);
673 ASSERT_TRUE(AddView(vm3(), view_2_2, view_3_3)); 676 ASSERT_TRUE(AddWindow(vm3(), view_2_2, view_3_3));
674 677
675 // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a 678 // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a
676 // different connection. 679 // different connection.
677 { 680 {
678 std::vector<TestView> views; 681 std::vector<TestView> views;
679 GetViewTree(vm2(), view_2_2, &views); 682 GetWindowTree(vm2(), view_2_2, &views);
680 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1), 683 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1),
681 SingleViewDescription(views)); 684 SingleViewDescription(views));
682 } 685 }
683 686
684 // Connection 2 shouldn't be able to get view 3 at all. 687 // Connection 2 shouldn't be able to get view 3 at all.
685 { 688 {
686 std::vector<TestView> views; 689 std::vector<TestView> views;
687 GetViewTree(vm2(), view_3_3, &views); 690 GetWindowTree(vm2(), view_3_3, &views);
688 EXPECT_TRUE(views.empty()); 691 EXPECT_TRUE(views.empty());
689 } 692 }
690 693
691 // Connection 1 should be able to see it all (its the root). 694 // Connection 1 should be able to see it all (its the root).
692 { 695 {
693 std::vector<TestView> views; 696 std::vector<TestView> views;
694 GetViewTree(vm1(), view_1_1, &views); 697 GetWindowTree(vm1(), view_1_1, &views);
695 ASSERT_EQ(3u, views.size()); 698 ASSERT_EQ(3u, views.size());
696 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString()); 699 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString());
697 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1), views[1].ToString()); 700 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1), views[1].ToString());
698 EXPECT_EQ(ViewParentToString(view_3_3, view_2_2), views[2].ToString()); 701 EXPECT_EQ(ViewParentToString(view_3_3, view_2_2), views[2].ToString());
699 } 702 }
700 } 703 }
701 704
702 // Verifies once Embed() has been invoked the parent can't mutate the children. 705 // Verifies once Embed() has been invoked the parent can't mutate the children.
703 TEST_F(ViewTreeAppTest, CantModifyChildrenOfEmbeddedView) { 706 TEST_F(WindowTreeAppTest, CantModifyChildrenOfEmbeddedView) {
704 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 707 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
705 708
706 Id view_1_1 = BuildViewId(connection_id_1(), 1); 709 Id view_1_1 = BuildViewId(connection_id_1(), 1);
707 Id view_2_2 = vm_client2()->CreateView(2); 710 Id view_2_2 = vm_client2()->NewWindow(2);
708 ASSERT_TRUE(view_2_2); 711 ASSERT_TRUE(view_2_2);
709 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 712 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
710 713
711 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2)); 714 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2));
712 715
713 Id view_2_3 = vm_client2()->CreateView(3); 716 Id view_2_3 = vm_client2()->NewWindow(3);
714 ASSERT_TRUE(view_2_3); 717 ASSERT_TRUE(view_2_3);
715 // Connection 2 shouldn't be able to add anything to the view anymore. 718 // Connection 2 shouldn't be able to add anything to the view anymore.
716 ASSERT_FALSE(AddView(vm2(), view_2_2, view_2_3)); 719 ASSERT_FALSE(AddWindow(vm2(), view_2_2, view_2_3));
717 720
718 // Create view 3 in connection 3 and add it to view 3. 721 // Create view 3 in connection 3 and add it to view 3.
719 Id view_3_3 = vm_client3()->CreateView(3); 722 Id view_3_3 = vm_client3()->NewWindow(3);
720 ASSERT_TRUE(view_3_3); 723 ASSERT_TRUE(view_3_3);
721 ASSERT_TRUE(AddView(vm3(), view_2_2, view_3_3)); 724 ASSERT_TRUE(AddWindow(vm3(), view_2_2, view_3_3));
722 725
723 // Connection 2 shouldn't be able to remove view 3. 726 // Connection 2 shouldn't be able to remove view 3.
724 ASSERT_FALSE(RemoveViewFromParent(vm2(), view_3_3)); 727 ASSERT_FALSE(RemoveWindowFromParent(vm2(), view_3_3));
725 } 728 }
726 729
727 // Verifies client gets a valid id. 730 // Verifies client gets a valid id.
728 TEST_F(ViewTreeAppTest, CreateView) { 731 TEST_F(WindowTreeAppTest, NewWindow) {
729 Id view_1_1 = vm_client1()->CreateView(1); 732 Id view_1_1 = vm_client1()->NewWindow(1);
730 ASSERT_TRUE(view_1_1); 733 ASSERT_TRUE(view_1_1);
731 EXPECT_TRUE(changes1()->empty()); 734 EXPECT_TRUE(changes1()->empty());
732 735
733 // Can't create a view with the same id. 736 // Can't create a view with the same id.
734 ASSERT_EQ(mojo::ERROR_CODE_VALUE_IN_USE, 737 ASSERT_EQ(mojom::ERROR_CODE_VALUE_IN_USE,
735 CreateViewWithErrorCode(vm1(), view_1_1)); 738 NewWindowWithErrorCode(vm1(), view_1_1));
736 EXPECT_TRUE(changes1()->empty()); 739 EXPECT_TRUE(changes1()->empty());
737 740
738 // Can't create a view with a bogus connection id. 741 // Can't create a view with a bogus connection id.
739 EXPECT_EQ( 742 EXPECT_EQ(
740 mojo::ERROR_CODE_ILLEGAL_ARGUMENT, 743 mojom::ERROR_CODE_ILLEGAL_ARGUMENT,
741 CreateViewWithErrorCode(vm1(), BuildViewId(connection_id_1() + 1, 1))); 744 NewWindowWithErrorCode(vm1(), BuildViewId(connection_id_1() + 1, 1)));
742 EXPECT_TRUE(changes1()->empty()); 745 EXPECT_TRUE(changes1()->empty());
743 } 746 }
744 747
745 // Verifies AddView fails when view is already in position. 748 // Verifies AddWindow fails when view is already in position.
746 TEST_F(ViewTreeAppTest, AddViewWithNoChange) { 749 TEST_F(WindowTreeAppTest, AddWindowWithNoChange) {
747 Id view_1_2 = vm_client1()->CreateView(2); 750 Id view_1_2 = vm_client1()->NewWindow(2);
748 Id view_1_3 = vm_client1()->CreateView(3); 751 Id view_1_3 = vm_client1()->NewWindow(3);
749 ASSERT_TRUE(view_1_2); 752 ASSERT_TRUE(view_1_2);
750 ASSERT_TRUE(view_1_3); 753 ASSERT_TRUE(view_1_3);
751 754
752 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 755 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
753 756
754 // Make 3 a child of 2. 757 // Make 3 a child of 2.
755 ASSERT_TRUE(AddView(vm1(), view_1_2, view_1_3)); 758 ASSERT_TRUE(AddWindow(vm1(), view_1_2, view_1_3));
756 759
757 // Try again, this should fail. 760 // Try again, this should fail.
758 EXPECT_FALSE(AddView(vm1(), view_1_2, view_1_3)); 761 EXPECT_FALSE(AddWindow(vm1(), view_1_2, view_1_3));
759 } 762 }
760 763
761 // Verifies AddView fails when view is already in position. 764 // Verifies AddWindow fails when view is already in position.
762 TEST_F(ViewTreeAppTest, AddAncestorFails) { 765 TEST_F(WindowTreeAppTest, AddAncestorFails) {
763 Id view_1_2 = vm_client1()->CreateView(2); 766 Id view_1_2 = vm_client1()->NewWindow(2);
764 Id view_1_3 = vm_client1()->CreateView(3); 767 Id view_1_3 = vm_client1()->NewWindow(3);
765 ASSERT_TRUE(view_1_2); 768 ASSERT_TRUE(view_1_2);
766 ASSERT_TRUE(view_1_3); 769 ASSERT_TRUE(view_1_3);
767 770
768 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 771 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
769 772
770 // Make 3 a child of 2. 773 // Make 3 a child of 2.
771 ASSERT_TRUE(AddView(vm1(), view_1_2, view_1_3)); 774 ASSERT_TRUE(AddWindow(vm1(), view_1_2, view_1_3));
772 775
773 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3. 776 // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3.
774 EXPECT_FALSE(AddView(vm1(), view_1_3, view_1_2)); 777 EXPECT_FALSE(AddWindow(vm1(), view_1_3, view_1_2));
775 } 778 }
776 779
777 // Verifies adding to root sends right notifications. 780 // Verifies adding to root sends right notifications.
778 TEST_F(ViewTreeAppTest, AddToRoot) { 781 TEST_F(WindowTreeAppTest, AddToRoot) {
779 Id view_1_21 = vm_client1()->CreateView(21); 782 Id view_1_21 = vm_client1()->NewWindow(21);
780 Id view_1_3 = vm_client1()->CreateView(3); 783 Id view_1_3 = vm_client1()->NewWindow(3);
781 ASSERT_TRUE(view_1_21); 784 ASSERT_TRUE(view_1_21);
782 ASSERT_TRUE(view_1_3); 785 ASSERT_TRUE(view_1_3);
783 786
784 Id view_1_1 = BuildViewId(connection_id_1(), 1); 787 Id view_1_1 = BuildViewId(connection_id_1(), 1);
785 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 788 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
786 changes2()->clear(); 789 changes2()->clear();
787 790
788 // Make 3 a child of 21. 791 // Make 3 a child of 21.
789 ASSERT_TRUE(AddView(vm1(), view_1_21, view_1_3)); 792 ASSERT_TRUE(AddWindow(vm1(), view_1_21, view_1_3));
790 793
791 // Make 21 a child of 1. 794 // Make 21 a child of 1.
792 ASSERT_TRUE(AddView(vm1(), view_1_1, view_1_21)); 795 ASSERT_TRUE(AddWindow(vm1(), view_1_1, view_1_21));
793 796
794 // Connection 2 should not be told anything (because the view is from a 797 // Connection 2 should not be told anything (because the view is from a
795 // different connection). Create a view to ensure we got a response from 798 // different connection). Create a view to ensure we got a response from
796 // the server. 799 // the server.
797 ASSERT_TRUE(vm_client2()->CreateView(100)); 800 ASSERT_TRUE(vm_client2()->NewWindow(100));
798 EXPECT_TRUE(changes2()->empty()); 801 EXPECT_TRUE(changes2()->empty());
799 } 802 }
800 803
801 // Verifies HierarchyChanged is correctly sent for various adds/removes. 804 // Verifies HierarchyChanged is correctly sent for various adds/removes.
802 TEST_F(ViewTreeAppTest, ViewHierarchyChangedViews) { 805 TEST_F(WindowTreeAppTest, ViewHierarchyChangedViews) {
803 // 1,2->1,11. 806 // 1,2->1,11.
804 Id view_1_2 = vm_client1()->CreateView(2); 807 Id view_1_2 = vm_client1()->NewWindow(2);
805 ASSERT_TRUE(view_1_2); 808 ASSERT_TRUE(view_1_2);
806 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_2, true)); 809 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_2, true));
807 Id view_1_11 = vm_client1()->CreateView(11); 810 Id view_1_11 = vm_client1()->NewWindow(11);
808 ASSERT_TRUE(view_1_11); 811 ASSERT_TRUE(view_1_11);
809 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_11, true)); 812 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_11, true));
810 ASSERT_TRUE(AddView(vm1(), view_1_2, view_1_11)); 813 ASSERT_TRUE(AddWindow(vm1(), view_1_2, view_1_11));
811 814
812 Id view_1_1 = BuildViewId(connection_id_1(), 1); 815 Id view_1_1 = BuildViewId(connection_id_1(), 1);
813 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 816 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
814 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_1, true)); 817 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_1, true));
815 818
816 ASSERT_TRUE(WaitForAllMessages(vm2())); 819 ASSERT_TRUE(WaitForAllMessages(vm2()));
817 changes2()->clear(); 820 changes2()->clear();
818 821
819 // 1,1->1,2->1,11 822 // 1,1->1,2->1,11
820 { 823 {
821 // Client 2 should not get anything (1,2 is from another connection). 824 // Client 2 should not get anything (1,2 is from another connection).
822 ASSERT_TRUE(AddView(vm1(), view_1_1, view_1_2)); 825 ASSERT_TRUE(AddWindow(vm1(), view_1_1, view_1_2));
823 ASSERT_TRUE(WaitForAllMessages(vm2())); 826 ASSERT_TRUE(WaitForAllMessages(vm2()));
824 EXPECT_TRUE(changes2()->empty()); 827 EXPECT_TRUE(changes2()->empty());
825 } 828 }
826 829
827 // 0,1->1,1->1,2->1,11. 830 // 0,1->1,1->1,2->1,11.
828 { 831 {
829 // Client 2 is now connected to the root, so it should have gotten a drawn 832 // Client 2 is now connected to the root, so it should have gotten a drawn
830 // notification. 833 // notification.
831 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 834 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
832 vm_client2_->WaitForChangeCount(1u); 835 vm_client2_->WaitForChangeCount(1u);
833 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_1) + " drawn=true", 836 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_1) + " drawn=true",
834 SingleChangeToDescription(*changes2())); 837 SingleChangeToDescription(*changes2()));
835 } 838 }
836 839
837 // 1,1->1,2->1,11. 840 // 1,1->1,2->1,11.
838 { 841 {
839 // Client 2 is no longer connected to the root, should get drawn state 842 // Client 2 is no longer connected to the root, should get drawn state
840 // changed. 843 // changed.
841 changes2()->clear(); 844 changes2()->clear();
842 ASSERT_TRUE(RemoveViewFromParent(vm1(), view_1_1)); 845 ASSERT_TRUE(RemoveWindowFromParent(vm1(), view_1_1));
843 vm_client2_->WaitForChangeCount(1); 846 vm_client2_->WaitForChangeCount(1);
844 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_1) + " drawn=false", 847 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_1) + " drawn=false",
845 SingleChangeToDescription(*changes2())); 848 SingleChangeToDescription(*changes2()));
846 } 849 }
847 850
848 // 1,1->1,2->1,11->1,111. 851 // 1,1->1,2->1,11->1,111.
849 Id view_1_111 = vm_client1()->CreateView(111); 852 Id view_1_111 = vm_client1()->NewWindow(111);
850 ASSERT_TRUE(view_1_111); 853 ASSERT_TRUE(view_1_111);
851 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_111, true)); 854 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_111, true));
852 { 855 {
853 changes2()->clear(); 856 changes2()->clear();
854 ASSERT_TRUE(AddView(vm1(), view_1_11, view_1_111)); 857 ASSERT_TRUE(AddWindow(vm1(), view_1_11, view_1_111));
855 ASSERT_TRUE(WaitForAllMessages(vm2())); 858 ASSERT_TRUE(WaitForAllMessages(vm2()));
856 EXPECT_TRUE(changes2()->empty()); 859 EXPECT_TRUE(changes2()->empty());
857 } 860 }
858 861
859 // 0,1->1,1->1,2->1,11->1,111 862 // 0,1->1,1->1,2->1,11->1,111
860 { 863 {
861 changes2()->clear(); 864 changes2()->clear();
862 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 865 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
863 vm_client2_->WaitForChangeCount(1); 866 vm_client2_->WaitForChangeCount(1);
864 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_1) + " drawn=true", 867 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_1) + " drawn=true",
865 SingleChangeToDescription(*changes2())); 868 SingleChangeToDescription(*changes2()));
866 } 869 }
867 } 870 }
868 871
869 TEST_F(ViewTreeAppTest, ViewHierarchyChangedAddingKnownToUnknown) { 872 TEST_F(WindowTreeAppTest, ViewHierarchyChangedAddingKnownToUnknown) {
870 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no 873 // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no
871 // parent). 874 // parent).
872 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 875 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
873 Id view_1_1 = BuildViewId(connection_id_1(), 1); 876 Id view_1_1 = BuildViewId(connection_id_1(), 1);
874 877
875 Id view_2_11 = vm_client2()->CreateView(11); 878 Id view_2_11 = vm_client2()->NewWindow(11);
876 Id view_2_2 = vm_client2()->CreateView(2); 879 Id view_2_2 = vm_client2()->NewWindow(2);
877 Id view_2_21 = vm_client2()->CreateView(21); 880 Id view_2_21 = vm_client2()->NewWindow(21);
878 ASSERT_TRUE(view_2_11); 881 ASSERT_TRUE(view_2_11);
879 ASSERT_TRUE(view_2_2); 882 ASSERT_TRUE(view_2_2);
880 ASSERT_TRUE(view_2_21); 883 ASSERT_TRUE(view_2_21);
881 884
882 // Set up the hierarchy. 885 // Set up the hierarchy.
883 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 886 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
884 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_11)); 887 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_11));
885 ASSERT_TRUE(AddView(vm2(), view_2_2, view_2_21)); 888 ASSERT_TRUE(AddWindow(vm2(), view_2_2, view_2_21));
886 889
887 // Remove 11, should result in a hierarchy change for the root. 890 // Remove 11, should result in a hierarchy change for the root.
888 { 891 {
889 changes1()->clear(); 892 changes1()->clear();
890 ASSERT_TRUE(RemoveViewFromParent(vm2(), view_2_11)); 893 ASSERT_TRUE(RemoveWindowFromParent(vm2(), view_2_11));
891 894
892 vm_client1_->WaitForChangeCount(1); 895 vm_client1_->WaitForChangeCount(1);
893 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_11) + 896 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_11) +
894 " new_parent=null old_parent=" + IdToString(view_1_1), 897 " new_parent=null old_parent=" + IdToString(view_1_1),
895 SingleChangeToDescription(*changes1())); 898 SingleChangeToDescription(*changes1()));
896 } 899 }
897 900
898 // Add 2 to 1. 901 // Add 2 to 1.
899 { 902 {
900 changes1()->clear(); 903 changes1()->clear();
901 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 904 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
902 vm_client1_->WaitForChangeCount(1); 905 vm_client1_->WaitForChangeCount(1);
903 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" + 906 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" +
904 IdToString(view_1_1) + " old_parent=null", 907 IdToString(view_1_1) + " old_parent=null",
905 SingleChangeToDescription(*changes1())); 908 SingleChangeToDescription(*changes1()));
906 EXPECT_EQ("[" + ViewParentToString(view_2_2, view_1_1) + "],[" + 909 EXPECT_EQ("[" + ViewParentToString(view_2_2, view_1_1) + "],[" +
907 ViewParentToString(view_2_21, view_2_2) + "]", 910 ViewParentToString(view_2_21, view_2_2) + "]",
908 ChangeViewDescription(*changes1())); 911 ChangeViewDescription(*changes1()));
909 } 912 }
910 } 913 }
911 914
912 TEST_F(ViewTreeAppTest, ReorderView) { 915 TEST_F(WindowTreeAppTest, ReorderWindow) {
913 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 916 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
914 917
915 Id view_2_1 = vm_client2()->CreateView(1); 918 Id view_2_1 = vm_client2()->NewWindow(1);
916 Id view_2_2 = vm_client2()->CreateView(2); 919 Id view_2_2 = vm_client2()->NewWindow(2);
917 Id view_2_3 = vm_client2()->CreateView(3); 920 Id view_2_3 = vm_client2()->NewWindow(3);
918 Id view_1_4 = vm_client1()->CreateView(4); // Peer to 1,1 921 Id view_1_4 = vm_client1()->NewWindow(4); // Peer to 1,1
919 Id view_1_5 = vm_client1()->CreateView(5); // Peer to 1,1 922 Id view_1_5 = vm_client1()->NewWindow(5); // Peer to 1,1
920 Id view_2_6 = vm_client2()->CreateView(6); // Child of 1,2. 923 Id view_2_6 = vm_client2()->NewWindow(6); // Child of 1,2.
921 Id view_2_7 = vm_client2()->CreateView(7); // Unparented. 924 Id view_2_7 = vm_client2()->NewWindow(7); // Unparented.
922 Id view_2_8 = vm_client2()->CreateView(8); // Unparented. 925 Id view_2_8 = vm_client2()->NewWindow(8); // Unparented.
923 ASSERT_TRUE(view_2_1); 926 ASSERT_TRUE(view_2_1);
924 ASSERT_TRUE(view_2_2); 927 ASSERT_TRUE(view_2_2);
925 ASSERT_TRUE(view_2_3); 928 ASSERT_TRUE(view_2_3);
926 ASSERT_TRUE(view_1_4); 929 ASSERT_TRUE(view_1_4);
927 ASSERT_TRUE(view_1_5); 930 ASSERT_TRUE(view_1_5);
928 ASSERT_TRUE(view_2_6); 931 ASSERT_TRUE(view_2_6);
929 ASSERT_TRUE(view_2_7); 932 ASSERT_TRUE(view_2_7);
930 ASSERT_TRUE(view_2_8); 933 ASSERT_TRUE(view_2_8);
931 934
932 ASSERT_TRUE(AddView(vm2(), view_2_1, view_2_2)); 935 ASSERT_TRUE(AddWindow(vm2(), view_2_1, view_2_2));
933 ASSERT_TRUE(AddView(vm2(), view_2_2, view_2_6)); 936 ASSERT_TRUE(AddWindow(vm2(), view_2_2, view_2_6));
934 ASSERT_TRUE(AddView(vm2(), view_2_1, view_2_3)); 937 ASSERT_TRUE(AddWindow(vm2(), view_2_1, view_2_3));
935 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_4)); 938 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_4));
936 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_5)); 939 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_5));
937 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_2_1)); 940 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_2_1));
938 941
939 { 942 {
940 changes1()->clear(); 943 changes1()->clear();
941 ASSERT_TRUE(ReorderView(vm2(), view_2_2, view_2_3, ORDER_DIRECTION_ABOVE)); 944 ASSERT_TRUE(
945 ReorderWindow(vm2(), view_2_2, view_2_3, mojom::ORDER_DIRECTION_ABOVE));
942 946
943 vm_client1_->WaitForChangeCount(1); 947 vm_client1_->WaitForChangeCount(1);
944 EXPECT_EQ("Reordered view=" + IdToString(view_2_2) + " relative=" + 948 EXPECT_EQ("Reordered view=" + IdToString(view_2_2) + " relative=" +
945 IdToString(view_2_3) + " direction=above", 949 IdToString(view_2_3) + " direction=above",
946 SingleChangeToDescription(*changes1())); 950 SingleChangeToDescription(*changes1()));
947 } 951 }
948 952
949 { 953 {
950 changes1()->clear(); 954 changes1()->clear();
951 ASSERT_TRUE(ReorderView(vm2(), view_2_2, view_2_3, ORDER_DIRECTION_BELOW)); 955 ASSERT_TRUE(
956 ReorderWindow(vm2(), view_2_2, view_2_3, mojom::ORDER_DIRECTION_BELOW));
952 957
953 vm_client1_->WaitForChangeCount(1); 958 vm_client1_->WaitForChangeCount(1);
954 EXPECT_EQ("Reordered view=" + IdToString(view_2_2) + " relative=" + 959 EXPECT_EQ("Reordered view=" + IdToString(view_2_2) + " relative=" +
955 IdToString(view_2_3) + " direction=below", 960 IdToString(view_2_3) + " direction=below",
956 SingleChangeToDescription(*changes1())); 961 SingleChangeToDescription(*changes1()));
957 } 962 }
958 963
959 // view2 is already below view3. 964 // view2 is already below view3.
960 EXPECT_FALSE(ReorderView(vm2(), view_2_2, view_2_3, ORDER_DIRECTION_BELOW)); 965 EXPECT_FALSE(
966 ReorderWindow(vm2(), view_2_2, view_2_3, mojom::ORDER_DIRECTION_BELOW));
961 967
962 // view4 & 5 are unknown to connection2_. 968 // view4 & 5 are unknown to connection2_.
963 EXPECT_FALSE(ReorderView(vm2(), view_1_4, view_1_5, ORDER_DIRECTION_ABOVE)); 969 EXPECT_FALSE(
970 ReorderWindow(vm2(), view_1_4, view_1_5, mojom::ORDER_DIRECTION_ABOVE));
964 971
965 // view6 & view3 have different parents. 972 // view6 & view3 have different parents.
966 EXPECT_FALSE(ReorderView(vm1(), view_2_3, view_2_6, ORDER_DIRECTION_ABOVE)); 973 EXPECT_FALSE(
974 ReorderWindow(vm1(), view_2_3, view_2_6, mojom::ORDER_DIRECTION_ABOVE));
967 975
968 // Non-existent view-ids 976 // Non-existent view-ids
969 EXPECT_FALSE(ReorderView(vm1(), BuildViewId(connection_id_1(), 27), 977 EXPECT_FALSE(ReorderWindow(vm1(), BuildViewId(connection_id_1(), 27),
970 BuildViewId(connection_id_1(), 28), 978 BuildViewId(connection_id_1(), 28),
971 ORDER_DIRECTION_ABOVE)); 979 mojom::ORDER_DIRECTION_ABOVE));
972 980
973 // view7 & view8 are un-parented. 981 // view7 & view8 are un-parented.
974 EXPECT_FALSE(ReorderView(vm1(), view_2_7, view_2_8, ORDER_DIRECTION_ABOVE)); 982 EXPECT_FALSE(
983 ReorderWindow(vm1(), view_2_7, view_2_8, mojom::ORDER_DIRECTION_ABOVE));
975 } 984 }
976 985
977 // Verifies DeleteView works. 986 // Verifies DeleteWindow works.
978 TEST_F(ViewTreeAppTest, DeleteView) { 987 TEST_F(WindowTreeAppTest, DeleteWindow) {
979 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 988 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
980 Id view_1_1 = BuildViewId(connection_id_1(), 1); 989 Id view_1_1 = BuildViewId(connection_id_1(), 1);
981 Id view_2_2 = vm_client2()->CreateView(2); 990 Id view_2_2 = vm_client2()->NewWindow(2);
982 ASSERT_TRUE(view_2_2); 991 ASSERT_TRUE(view_2_2);
983 992
984 // Make 2 a child of 1. 993 // Make 2 a child of 1.
985 { 994 {
986 changes1()->clear(); 995 changes1()->clear();
987 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 996 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
988 vm_client1_->WaitForChangeCount(1); 997 vm_client1_->WaitForChangeCount(1);
989 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" + 998 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" +
990 IdToString(view_1_1) + " old_parent=null", 999 IdToString(view_1_1) + " old_parent=null",
991 SingleChangeToDescription(*changes1())); 1000 SingleChangeToDescription(*changes1()));
992 } 1001 }
993 1002
994 // Delete 2. 1003 // Delete 2.
995 { 1004 {
996 changes1()->clear(); 1005 changes1()->clear();
997 changes2()->clear(); 1006 changes2()->clear();
998 ASSERT_TRUE(DeleteView(vm2(), view_2_2)); 1007 ASSERT_TRUE(DeleteWindow(vm2(), view_2_2));
999 EXPECT_TRUE(changes2()->empty()); 1008 EXPECT_TRUE(changes2()->empty());
1000 1009
1001 vm_client1_->WaitForChangeCount(1); 1010 vm_client1_->WaitForChangeCount(1);
1002 EXPECT_EQ("ViewDeleted view=" + IdToString(view_2_2), 1011 EXPECT_EQ("ViewDeleted view=" + IdToString(view_2_2),
1003 SingleChangeToDescription(*changes1())); 1012 SingleChangeToDescription(*changes1()));
1004 } 1013 }
1005 } 1014 }
1006 1015
1007 // Verifies DeleteView isn't allowed from a separate connection. 1016 // Verifies DeleteWindow isn't allowed from a separate connection.
1008 TEST_F(ViewTreeAppTest, DeleteViewFromAnotherConnectionDisallowed) { 1017 TEST_F(WindowTreeAppTest, DeleteWindowFromAnotherConnectionDisallowed) {
1009 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1018 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1010 EXPECT_FALSE(DeleteView(vm2(), BuildViewId(connection_id_1(), 1))); 1019 EXPECT_FALSE(DeleteWindow(vm2(), BuildViewId(connection_id_1(), 1)));
1011 } 1020 }
1012 1021
1013 // Verifies if a view was deleted and then reused that other clients are 1022 // Verifies if a view was deleted and then reused that other clients are
1014 // properly notified. 1023 // properly notified.
1015 TEST_F(ViewTreeAppTest, ReuseDeletedViewId) { 1024 TEST_F(WindowTreeAppTest, ReuseDeletedViewId) {
1016 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1025 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1017 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1026 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1018 Id view_2_2 = vm_client2()->CreateView(2); 1027 Id view_2_2 = vm_client2()->NewWindow(2);
1019 ASSERT_TRUE(view_2_2); 1028 ASSERT_TRUE(view_2_2);
1020 1029
1021 // Add 2 to 1. 1030 // Add 2 to 1.
1022 { 1031 {
1023 changes1()->clear(); 1032 changes1()->clear();
1024 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 1033 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
1025 vm_client1_->WaitForChangeCount(1); 1034 vm_client1_->WaitForChangeCount(1);
1026 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" + 1035 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" +
1027 IdToString(view_1_1) + " old_parent=null", 1036 IdToString(view_1_1) + " old_parent=null",
1028 SingleChangeToDescription(*changes1())); 1037 SingleChangeToDescription(*changes1()));
1029 EXPECT_EQ("[" + ViewParentToString(view_2_2, view_1_1) + "]", 1038 EXPECT_EQ("[" + ViewParentToString(view_2_2, view_1_1) + "]",
1030 ChangeViewDescription(*changes1())); 1039 ChangeViewDescription(*changes1()));
1031 } 1040 }
1032 1041
1033 // Delete 2. 1042 // Delete 2.
1034 { 1043 {
1035 changes1()->clear(); 1044 changes1()->clear();
1036 ASSERT_TRUE(DeleteView(vm2(), view_2_2)); 1045 ASSERT_TRUE(DeleteWindow(vm2(), view_2_2));
1037 1046
1038 vm_client1_->WaitForChangeCount(1); 1047 vm_client1_->WaitForChangeCount(1);
1039 EXPECT_EQ("ViewDeleted view=" + IdToString(view_2_2), 1048 EXPECT_EQ("ViewDeleted view=" + IdToString(view_2_2),
1040 SingleChangeToDescription(*changes1())); 1049 SingleChangeToDescription(*changes1()));
1041 } 1050 }
1042 1051
1043 // Create 2 again, and add it back to 1. Should get the same notification. 1052 // Create 2 again, and add it back to 1. Should get the same notification.
1044 view_2_2 = vm_client2()->CreateView(2); 1053 view_2_2 = vm_client2()->NewWindow(2);
1045 ASSERT_TRUE(view_2_2); 1054 ASSERT_TRUE(view_2_2);
1046 { 1055 {
1047 changes1()->clear(); 1056 changes1()->clear();
1048 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 1057 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
1049 1058
1050 vm_client1_->WaitForChangeCount(1); 1059 vm_client1_->WaitForChangeCount(1);
1051 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" + 1060 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_2_2) + " new_parent=" +
1052 IdToString(view_1_1) + " old_parent=null", 1061 IdToString(view_1_1) + " old_parent=null",
1053 SingleChangeToDescription(*changes1())); 1062 SingleChangeToDescription(*changes1()));
1054 EXPECT_EQ("[" + ViewParentToString(view_2_2, view_1_1) + "]", 1063 EXPECT_EQ("[" + ViewParentToString(view_2_2, view_1_1) + "]",
1055 ChangeViewDescription(*changes1())); 1064 ChangeViewDescription(*changes1()));
1056 } 1065 }
1057 } 1066 }
1058 1067
1059 // Assertions for GetViewTree. 1068 // Assertions for GetWindowTree.
1060 TEST_F(ViewTreeAppTest, GetViewTree) { 1069 TEST_F(WindowTreeAppTest, GetWindowTree) {
1061 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1070 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1062 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1071 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1063 1072
1064 // Create 11 in first connection and make it a child of 1. 1073 // Create 11 in first connection and make it a child of 1.
1065 Id view_1_11 = vm_client1()->CreateView(11); 1074 Id view_1_11 = vm_client1()->NewWindow(11);
1066 ASSERT_TRUE(view_1_11); 1075 ASSERT_TRUE(view_1_11);
1067 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1076 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1068 ASSERT_TRUE(AddView(vm1(), view_1_1, view_1_11)); 1077 ASSERT_TRUE(AddWindow(vm1(), view_1_1, view_1_11));
1069 1078
1070 // Create two views in second connection, 2 and 3, both children of 1. 1079 // Create two views in second connection, 2 and 3, both children of 1.
1071 Id view_2_2 = vm_client2()->CreateView(2); 1080 Id view_2_2 = vm_client2()->NewWindow(2);
1072 Id view_2_3 = vm_client2()->CreateView(3); 1081 Id view_2_3 = vm_client2()->NewWindow(3);
1073 ASSERT_TRUE(view_2_2); 1082 ASSERT_TRUE(view_2_2);
1074 ASSERT_TRUE(view_2_3); 1083 ASSERT_TRUE(view_2_3);
1075 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 1084 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
1076 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_3)); 1085 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_3));
1077 1086
1078 // Verifies GetViewTree() on the root. The root connection sees all. 1087 // Verifies GetWindowTree() on the root. The root connection sees all.
1079 { 1088 {
1080 std::vector<TestView> views; 1089 std::vector<TestView> views;
1081 GetViewTree(vm1(), root_view_id(), &views); 1090 GetWindowTree(vm1(), root_window_id(), &views);
1082 ASSERT_EQ(5u, views.size()); 1091 ASSERT_EQ(5u, views.size());
1083 EXPECT_EQ(ViewParentToString(root_view_id(), kNullParentId), 1092 EXPECT_EQ(ViewParentToString(root_window_id(), kNullParentId),
1084 views[0].ToString()); 1093 views[0].ToString());
1085 EXPECT_EQ(ViewParentToString(view_1_1, root_view_id()), 1094 EXPECT_EQ(ViewParentToString(view_1_1, root_window_id()),
1086 views[1].ToString()); 1095 views[1].ToString());
1087 EXPECT_EQ(ViewParentToString(view_1_11, view_1_1), views[2].ToString()); 1096 EXPECT_EQ(ViewParentToString(view_1_11, view_1_1), views[2].ToString());
1088 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1), views[3].ToString()); 1097 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1), views[3].ToString());
1089 EXPECT_EQ(ViewParentToString(view_2_3, view_1_1), views[4].ToString()); 1098 EXPECT_EQ(ViewParentToString(view_2_3, view_1_1), views[4].ToString());
1090 } 1099 }
1091 1100
1092 // Verifies GetViewTree() on the view 1,1 from vm2(). vm2() sees 1,1 as 1,1 1101 // Verifies GetWindowTree() on the view 1,1 from vm2(). vm2() sees 1,1 as 1,1
1093 // is vm2()'s root and vm2() sees all the views it created. 1102 // is vm2()'s root and vm2() sees all the views it created.
1094 { 1103 {
1095 std::vector<TestView> views; 1104 std::vector<TestView> views;
1096 GetViewTree(vm2(), view_1_1, &views); 1105 GetWindowTree(vm2(), view_1_1, &views);
1097 ASSERT_EQ(3u, views.size()); 1106 ASSERT_EQ(3u, views.size());
1098 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString()); 1107 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString());
1099 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1), views[1].ToString()); 1108 EXPECT_EQ(ViewParentToString(view_2_2, view_1_1), views[1].ToString());
1100 EXPECT_EQ(ViewParentToString(view_2_3, view_1_1), views[2].ToString()); 1109 EXPECT_EQ(ViewParentToString(view_2_3, view_1_1), views[2].ToString());
1101 } 1110 }
1102 1111
1103 // Connection 2 shouldn't be able to get the root tree. 1112 // Connection 2 shouldn't be able to get the root tree.
1104 { 1113 {
1105 std::vector<TestView> views; 1114 std::vector<TestView> views;
1106 GetViewTree(vm2(), root_view_id(), &views); 1115 GetWindowTree(vm2(), root_window_id(), &views);
1107 ASSERT_EQ(0u, views.size()); 1116 ASSERT_EQ(0u, views.size());
1108 } 1117 }
1109 } 1118 }
1110 1119
1111 TEST_F(ViewTreeAppTest, SetViewBounds) { 1120 TEST_F(WindowTreeAppTest, SetWindowBounds) {
1112 Id view_1_1 = vm_client1()->CreateView(1); 1121 Id view_1_1 = vm_client1()->NewWindow(1);
1113 ASSERT_TRUE(view_1_1); 1122 ASSERT_TRUE(view_1_1);
1114 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1123 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1115 1124
1116 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 1125 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
1117 1126
1118 changes2()->clear(); 1127 changes2()->clear();
1119 ASSERT_TRUE(SetViewBounds(vm1(), view_1_1, 0, 0, 100, 100)); 1128 ASSERT_TRUE(SetWindowBounds(vm1(), view_1_1, 0, 0, 100, 100));
1120 1129
1121 vm_client2_->WaitForChangeCount(1); 1130 vm_client2_->WaitForChangeCount(1);
1122 EXPECT_EQ("BoundsChanged view=" + IdToString(view_1_1) + 1131 EXPECT_EQ("BoundsChanged view=" + IdToString(view_1_1) +
1123 " old_bounds=0,0 0x0 new_bounds=0,0 100x100", 1132 " old_bounds=0,0 0x0 new_bounds=0,0 100x100",
1124 SingleChangeToDescription(*changes2())); 1133 SingleChangeToDescription(*changes2()));
1125 1134
1126 // Should not be possible to change the bounds of a view created by another 1135 // Should not be possible to change the bounds of a view created by another
1127 // connection. 1136 // connection.
1128 ASSERT_FALSE(SetViewBounds(vm2(), view_1_1, 0, 0, 0, 0)); 1137 ASSERT_FALSE(SetWindowBounds(vm2(), view_1_1, 0, 0, 0, 0));
1129 } 1138 }
1130 1139
1131 // Verify AddView fails when trying to manipulate views in other roots. 1140 // Verify AddWindow fails when trying to manipulate views in other roots.
1132 TEST_F(ViewTreeAppTest, CantMoveViewsFromOtherRoot) { 1141 TEST_F(WindowTreeAppTest, CantMoveViewsFromOtherRoot) {
1133 // Create 1 and 2 in the first connection. 1142 // Create 1 and 2 in the first connection.
1134 Id view_1_1 = vm_client1()->CreateView(1); 1143 Id view_1_1 = vm_client1()->NewWindow(1);
1135 Id view_1_2 = vm_client1()->CreateView(2); 1144 Id view_1_2 = vm_client1()->NewWindow(2);
1136 ASSERT_TRUE(view_1_1); 1145 ASSERT_TRUE(view_1_1);
1137 ASSERT_TRUE(view_1_2); 1146 ASSERT_TRUE(view_1_2);
1138 1147
1139 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 1148 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
1140 1149
1141 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2 1150 // Try to move 2 to be a child of 1 from connection 2. This should fail as 2
1142 // should not be able to access 1. 1151 // should not be able to access 1.
1143 ASSERT_FALSE(AddView(vm2(), view_1_1, view_1_2)); 1152 ASSERT_FALSE(AddWindow(vm2(), view_1_1, view_1_2));
1144 1153
1145 // Try to reparent 1 to the root. A connection is not allowed to reparent its 1154 // Try to reparent 1 to the root. A connection is not allowed to reparent its
1146 // roots. 1155 // roots.
1147 ASSERT_FALSE(AddView(vm2(), root_view_id(), view_1_1)); 1156 ASSERT_FALSE(AddWindow(vm2(), root_window_id(), view_1_1));
1148 } 1157 }
1149 1158
1150 // Verify RemoveViewFromParent fails for views that are descendants of the 1159 // Verify RemoveWindowFromParent fails for views that are descendants of the
1151 // roots. 1160 // roots.
1152 TEST_F(ViewTreeAppTest, CantRemoveViewsInOtherRoots) { 1161 TEST_F(WindowTreeAppTest, CantRemoveWindowsInOtherRoots) {
1153 // Create 1 and 2 in the first connection and parent both to the root. 1162 // Create 1 and 2 in the first connection and parent both to the root.
1154 Id view_1_1 = vm_client1()->CreateView(1); 1163 Id view_1_1 = vm_client1()->NewWindow(1);
1155 Id view_1_2 = vm_client1()->CreateView(2); 1164 Id view_1_2 = vm_client1()->NewWindow(2);
1156 ASSERT_TRUE(view_1_1); 1165 ASSERT_TRUE(view_1_1);
1157 ASSERT_TRUE(view_1_2); 1166 ASSERT_TRUE(view_1_2);
1158 1167
1159 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1168 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1160 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_2)); 1169 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_2));
1161 1170
1162 // Establish the second connection and give it the root 1. 1171 // Establish the second connection and give it the root 1.
1163 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 1172 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
1164 1173
1165 // Connection 2 should not be able to remove view 2 or 1 from its parent. 1174 // Connection 2 should not be able to remove view 2 or 1 from its parent.
1166 ASSERT_FALSE(RemoveViewFromParent(vm2(), view_1_2)); 1175 ASSERT_FALSE(RemoveWindowFromParent(vm2(), view_1_2));
1167 ASSERT_FALSE(RemoveViewFromParent(vm2(), view_1_1)); 1176 ASSERT_FALSE(RemoveWindowFromParent(vm2(), view_1_1));
1168 1177
1169 // Create views 10 and 11 in 2. 1178 // Create views 10 and 11 in 2.
1170 Id view_2_10 = vm_client2()->CreateView(10); 1179 Id view_2_10 = vm_client2()->NewWindow(10);
1171 Id view_2_11 = vm_client2()->CreateView(11); 1180 Id view_2_11 = vm_client2()->NewWindow(11);
1172 ASSERT_TRUE(view_2_10); 1181 ASSERT_TRUE(view_2_10);
1173 ASSERT_TRUE(view_2_11); 1182 ASSERT_TRUE(view_2_11);
1174 1183
1175 // Parent 11 to 10. 1184 // Parent 11 to 10.
1176 ASSERT_TRUE(AddView(vm2(), view_2_10, view_2_11)); 1185 ASSERT_TRUE(AddWindow(vm2(), view_2_10, view_2_11));
1177 // Remove 11 from 10. 1186 // Remove 11 from 10.
1178 ASSERT_TRUE(RemoveViewFromParent(vm2(), view_2_11)); 1187 ASSERT_TRUE(RemoveWindowFromParent(vm2(), view_2_11));
1179 1188
1180 // Verify nothing was actually removed. 1189 // Verify nothing was actually removed.
1181 { 1190 {
1182 std::vector<TestView> views; 1191 std::vector<TestView> views;
1183 GetViewTree(vm1(), root_view_id(), &views); 1192 GetWindowTree(vm1(), root_window_id(), &views);
1184 ASSERT_EQ(3u, views.size()); 1193 ASSERT_EQ(3u, views.size());
1185 EXPECT_EQ(ViewParentToString(root_view_id(), kNullParentId), 1194 EXPECT_EQ(ViewParentToString(root_window_id(), kNullParentId),
1186 views[0].ToString()); 1195 views[0].ToString());
1187 EXPECT_EQ(ViewParentToString(view_1_1, root_view_id()), 1196 EXPECT_EQ(ViewParentToString(view_1_1, root_window_id()),
1188 views[1].ToString()); 1197 views[1].ToString());
1189 EXPECT_EQ(ViewParentToString(view_1_2, root_view_id()), 1198 EXPECT_EQ(ViewParentToString(view_1_2, root_window_id()),
1190 views[2].ToString()); 1199 views[2].ToString());
1191 } 1200 }
1192 } 1201 }
1193 1202
1194 // Verify GetViewTree fails for views that are not descendants of the roots. 1203 // Verify GetWindowTree fails for views that are not descendants of the roots.
1195 TEST_F(ViewTreeAppTest, CantGetViewTreeOfOtherRoots) { 1204 TEST_F(WindowTreeAppTest, CantGetWindowTreeOfOtherRoots) {
1196 // Create 1 and 2 in the first connection and parent both to the root. 1205 // Create 1 and 2 in the first connection and parent both to the root.
1197 Id view_1_1 = vm_client1()->CreateView(1); 1206 Id view_1_1 = vm_client1()->NewWindow(1);
1198 Id view_1_2 = vm_client1()->CreateView(2); 1207 Id view_1_2 = vm_client1()->NewWindow(2);
1199 ASSERT_TRUE(view_1_1); 1208 ASSERT_TRUE(view_1_1);
1200 ASSERT_TRUE(view_1_2); 1209 ASSERT_TRUE(view_1_2);
1201 1210
1202 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1211 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1203 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_2)); 1212 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_2));
1204 1213
1205 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 1214 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
1206 1215
1207 std::vector<TestView> views; 1216 std::vector<TestView> views;
1208 1217
1209 // Should get nothing for the root. 1218 // Should get nothing for the root.
1210 GetViewTree(vm2(), root_view_id(), &views); 1219 GetWindowTree(vm2(), root_window_id(), &views);
1211 ASSERT_TRUE(views.empty()); 1220 ASSERT_TRUE(views.empty());
1212 1221
1213 // Should get nothing for view 2. 1222 // Should get nothing for view 2.
1214 GetViewTree(vm2(), view_1_2, &views); 1223 GetWindowTree(vm2(), view_1_2, &views);
1215 ASSERT_TRUE(views.empty()); 1224 ASSERT_TRUE(views.empty());
1216 1225
1217 // Should get view 1 if asked for. 1226 // Should get view 1 if asked for.
1218 GetViewTree(vm2(), view_1_1, &views); 1227 GetWindowTree(vm2(), view_1_1, &views);
1219 ASSERT_EQ(1u, views.size()); 1228 ASSERT_EQ(1u, views.size());
1220 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString()); 1229 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString());
1221 } 1230 }
1222 1231
1223 TEST_F(ViewTreeAppTest, EmbedWithSameViewId) { 1232 TEST_F(WindowTreeAppTest, EmbedWithSameViewId) {
1224 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1233 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1225 changes2()->clear(); 1234 changes2()->clear();
1226 1235
1227 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1236 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1228 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_1_1)); 1237 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_1_1));
1229 1238
1230 // Connection2 should have been told of the unembed and delete. 1239 // Connection2 should have been told of the unembed and delete.
1231 { 1240 {
1232 vm_client2_->WaitForChangeCount(2); 1241 vm_client2_->WaitForChangeCount(2);
1233 EXPECT_EQ("OnUnembed", ChangesToDescription1(*changes2())[0]); 1242 EXPECT_EQ("OnUnembed", ChangesToDescription1(*changes2())[0]);
1234 EXPECT_EQ("ViewDeleted view=" + IdToString(view_1_1), 1243 EXPECT_EQ("ViewDeleted view=" + IdToString(view_1_1),
1235 ChangesToDescription1(*changes2())[1]); 1244 ChangesToDescription1(*changes2())[1]);
1236 } 1245 }
1237 1246
1238 // Connection2 has no root. Verify it can't see view 1,1 anymore. 1247 // Connection2 has no root. Verify it can't see view 1,1 anymore.
1239 { 1248 {
1240 std::vector<TestView> views; 1249 std::vector<TestView> views;
1241 GetViewTree(vm2(), view_1_1, &views); 1250 GetWindowTree(vm2(), view_1_1, &views);
1242 EXPECT_TRUE(views.empty()); 1251 EXPECT_TRUE(views.empty());
1243 } 1252 }
1244 } 1253 }
1245 1254
1246 TEST_F(ViewTreeAppTest, EmbedWithSameViewId2) { 1255 TEST_F(WindowTreeAppTest, EmbedWithSameViewId2) {
1247 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1256 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1248 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1257 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1249 changes2()->clear(); 1258 changes2()->clear();
1250 1259
1251 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_1_1)); 1260 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_1_1));
1252 1261
1253 // Connection2 should have been told about the unembed and delete. 1262 // Connection2 should have been told about the unembed and delete.
1254 vm_client2_->WaitForChangeCount(2); 1263 vm_client2_->WaitForChangeCount(2);
1255 changes2()->clear(); 1264 changes2()->clear();
1256 1265
1257 // Create a view in the third connection and parent it to the root. 1266 // Create a view in the third connection and parent it to the root.
1258 Id view_3_1 = vm_client3()->CreateView(1); 1267 Id view_3_1 = vm_client3()->NewWindow(1);
1259 ASSERT_TRUE(view_3_1); 1268 ASSERT_TRUE(view_3_1);
1260 ASSERT_TRUE(AddView(vm3(), view_1_1, view_3_1)); 1269 ASSERT_TRUE(AddWindow(vm3(), view_1_1, view_3_1));
1261 1270
1262 // Connection 1 should have been told about the add (it owns the view). 1271 // Connection 1 should have been told about the add (it owns the view).
1263 { 1272 {
1264 vm_client1_->WaitForChangeCount(1); 1273 vm_client1_->WaitForChangeCount(1);
1265 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_3_1) + " new_parent=" + 1274 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_3_1) + " new_parent=" +
1266 IdToString(view_1_1) + " old_parent=null", 1275 IdToString(view_1_1) + " old_parent=null",
1267 SingleChangeToDescription(*changes1())); 1276 SingleChangeToDescription(*changes1()));
1268 } 1277 }
1269 1278
1270 // Embed 1,1 again. 1279 // Embed 1,1 again.
1271 { 1280 {
1272 changes3()->clear(); 1281 changes3()->clear();
1273 1282
1274 // We should get a new connection for the new embedding. 1283 // We should get a new connection for the new embedding.
1275 scoped_ptr<TestViewTreeClientImpl> connection4( 1284 scoped_ptr<TestWindowTreeClientImpl> connection4(
1276 EstablishConnectionViaEmbed(vm1(), view_1_1, nullptr)); 1285 EstablishConnectionViaEmbed(vm1(), view_1_1, nullptr));
1277 ASSERT_TRUE(connection4.get()); 1286 ASSERT_TRUE(connection4.get());
1278 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]", 1287 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]",
1279 ChangeViewDescription(*connection4->tracker()->changes())); 1288 ChangeViewDescription(*connection4->tracker()->changes()));
1280 1289
1281 // And 3 should get an unembed and delete. 1290 // And 3 should get an unembed and delete.
1282 vm_client3_->WaitForChangeCount(2); 1291 vm_client3_->WaitForChangeCount(2);
1283 EXPECT_EQ("OnUnembed", ChangesToDescription1(*changes3())[0]); 1292 EXPECT_EQ("OnUnembed", ChangesToDescription1(*changes3())[0]);
1284 EXPECT_EQ("ViewDeleted view=" + IdToString(view_1_1), 1293 EXPECT_EQ("ViewDeleted view=" + IdToString(view_1_1),
1285 ChangesToDescription1(*changes3())[1]); 1294 ChangesToDescription1(*changes3())[1]);
1286 } 1295 }
1287 1296
1288 // vm3() has no root. Verify it can't see view 1,1 anymore. 1297 // vm3() has no root. Verify it can't see view 1,1 anymore.
1289 { 1298 {
1290 std::vector<TestView> views; 1299 std::vector<TestView> views;
1291 GetViewTree(vm3(), view_1_1, &views); 1300 GetWindowTree(vm3(), view_1_1, &views);
1292 EXPECT_TRUE(views.empty()); 1301 EXPECT_TRUE(views.empty());
1293 } 1302 }
1294 1303
1295 // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as 1304 // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as
1296 // vm3() can no longer see 1,1. 1305 // vm3() can no longer see 1,1.
1297 { 1306 {
1298 std::vector<TestView> views; 1307 std::vector<TestView> views;
1299 GetViewTree(vm1(), view_1_1, &views); 1308 GetWindowTree(vm1(), view_1_1, &views);
1300 ASSERT_EQ(1u, views.size()); 1309 ASSERT_EQ(1u, views.size());
1301 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString()); 1310 EXPECT_EQ(ViewParentToString(view_1_1, kNullParentId), views[0].ToString());
1302 } 1311 }
1303 1312
1304 // Verify vm3() can still see the view it created 3,1. 1313 // Verify vm3() can still see the view it created 3,1.
1305 { 1314 {
1306 std::vector<TestView> views; 1315 std::vector<TestView> views;
1307 GetViewTree(vm3(), view_3_1, &views); 1316 GetWindowTree(vm3(), view_3_1, &views);
1308 ASSERT_EQ(1u, views.size()); 1317 ASSERT_EQ(1u, views.size());
1309 EXPECT_EQ(ViewParentToString(view_3_1, kNullParentId), views[0].ToString()); 1318 EXPECT_EQ(ViewParentToString(view_3_1, kNullParentId), views[0].ToString());
1310 } 1319 }
1311 } 1320 }
1312 1321
1313 // Assertions for SetViewVisibility. 1322 // Assertions for SetWindowVisibility.
1314 TEST_F(ViewTreeAppTest, SetViewVisibility) { 1323 TEST_F(WindowTreeAppTest, SetWindowVisibility) {
1315 // Create 1 and 2 in the first connection and parent both to the root. 1324 // Create 1 and 2 in the first connection and parent both to the root.
1316 Id view_1_1 = vm_client1()->CreateView(1); 1325 Id view_1_1 = vm_client1()->NewWindow(1);
1317 Id view_1_2 = vm_client1()->CreateView(2); 1326 Id view_1_2 = vm_client1()->NewWindow(2);
1318 ASSERT_TRUE(view_1_1); 1327 ASSERT_TRUE(view_1_1);
1319 ASSERT_TRUE(view_1_2); 1328 ASSERT_TRUE(view_1_2);
1320 1329
1321 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1330 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1322 { 1331 {
1323 std::vector<TestView> views; 1332 std::vector<TestView> views;
1324 GetViewTree(vm1(), root_view_id(), &views); 1333 GetWindowTree(vm1(), root_window_id(), &views);
1325 ASSERT_EQ(2u, views.size()); 1334 ASSERT_EQ(2u, views.size());
1326 EXPECT_EQ(ViewParentToString(root_view_id(), kNullParentId) + 1335 EXPECT_EQ(ViewParentToString(root_window_id(), kNullParentId) +
1327 " visible=true drawn=true", 1336 " visible=true drawn=true",
1328 views[0].ToString2()); 1337 views[0].ToString2());
1329 EXPECT_EQ(ViewParentToString(view_1_1, root_view_id()) + 1338 EXPECT_EQ(ViewParentToString(view_1_1, root_window_id()) +
1330 " visible=false drawn=false", 1339 " visible=false drawn=false",
1331 views[1].ToString2()); 1340 views[1].ToString2());
1332 } 1341 }
1333 1342
1334 // Show all the views. 1343 // Show all the views.
1335 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_1, true)); 1344 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_1, true));
1336 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_2, true)); 1345 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_2, true));
1337 { 1346 {
1338 std::vector<TestView> views; 1347 std::vector<TestView> views;
1339 GetViewTree(vm1(), root_view_id(), &views); 1348 GetWindowTree(vm1(), root_window_id(), &views);
1340 ASSERT_EQ(2u, views.size()); 1349 ASSERT_EQ(2u, views.size());
1341 EXPECT_EQ(ViewParentToString(root_view_id(), kNullParentId) + 1350 EXPECT_EQ(ViewParentToString(root_window_id(), kNullParentId) +
1342 " visible=true drawn=true", 1351 " visible=true drawn=true",
1343 views[0].ToString2()); 1352 views[0].ToString2());
1344 EXPECT_EQ(ViewParentToString(view_1_1, root_view_id()) + 1353 EXPECT_EQ(ViewParentToString(view_1_1, root_window_id()) +
1345 " visible=true drawn=true", 1354 " visible=true drawn=true",
1346 views[1].ToString2()); 1355 views[1].ToString2());
1347 } 1356 }
1348 1357
1349 // Hide 1. 1358 // Hide 1.
1350 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_1, false)); 1359 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_1, false));
1351 { 1360 {
1352 std::vector<TestView> views; 1361 std::vector<TestView> views;
1353 GetViewTree(vm1(), view_1_1, &views); 1362 GetWindowTree(vm1(), view_1_1, &views);
1354 ASSERT_EQ(1u, views.size()); 1363 ASSERT_EQ(1u, views.size());
1355 EXPECT_EQ(ViewParentToString(view_1_1, root_view_id()) + 1364 EXPECT_EQ(ViewParentToString(view_1_1, root_window_id()) +
1356 " visible=false drawn=false", 1365 " visible=false drawn=false",
1357 views[0].ToString2()); 1366 views[0].ToString2());
1358 } 1367 }
1359 1368
1360 // Attach 2 to 1. 1369 // Attach 2 to 1.
1361 ASSERT_TRUE(AddView(vm1(), view_1_1, view_1_2)); 1370 ASSERT_TRUE(AddWindow(vm1(), view_1_1, view_1_2));
1362 { 1371 {
1363 std::vector<TestView> views; 1372 std::vector<TestView> views;
1364 GetViewTree(vm1(), view_1_1, &views); 1373 GetWindowTree(vm1(), view_1_1, &views);
1365 ASSERT_EQ(2u, views.size()); 1374 ASSERT_EQ(2u, views.size());
1366 EXPECT_EQ(ViewParentToString(view_1_1, root_view_id()) + 1375 EXPECT_EQ(ViewParentToString(view_1_1, root_window_id()) +
1367 " visible=false drawn=false", 1376 " visible=false drawn=false",
1368 views[0].ToString2()); 1377 views[0].ToString2());
1369 EXPECT_EQ( 1378 EXPECT_EQ(
1370 ViewParentToString(view_1_2, view_1_1) + " visible=true drawn=false", 1379 ViewParentToString(view_1_2, view_1_1) + " visible=true drawn=false",
1371 views[1].ToString2()); 1380 views[1].ToString2());
1372 } 1381 }
1373 1382
1374 // Show 1. 1383 // Show 1.
1375 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_1, true)); 1384 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_1, true));
1376 { 1385 {
1377 std::vector<TestView> views; 1386 std::vector<TestView> views;
1378 GetViewTree(vm1(), view_1_1, &views); 1387 GetWindowTree(vm1(), view_1_1, &views);
1379 ASSERT_EQ(2u, views.size()); 1388 ASSERT_EQ(2u, views.size());
1380 EXPECT_EQ(ViewParentToString(view_1_1, root_view_id()) + 1389 EXPECT_EQ(ViewParentToString(view_1_1, root_window_id()) +
1381 " visible=true drawn=true", 1390 " visible=true drawn=true",
1382 views[0].ToString2()); 1391 views[0].ToString2());
1383 EXPECT_EQ( 1392 EXPECT_EQ(
1384 ViewParentToString(view_1_2, view_1_1) + " visible=true drawn=true", 1393 ViewParentToString(view_1_2, view_1_1) + " visible=true drawn=true",
1385 views[1].ToString2()); 1394 views[1].ToString2());
1386 } 1395 }
1387 } 1396 }
1388 1397
1389 // Assertions for SetViewVisibility sending notifications. 1398 // Assertions for SetWindowVisibility sending notifications.
1390 TEST_F(ViewTreeAppTest, SetViewVisibilityNotifications) { 1399 TEST_F(WindowTreeAppTest, SetWindowVisibilityNotifications) {
1391 // Create 1,1 and 1,2. 1,2 is made a child of 1,1 and 1,1 a child of the root. 1400 // Create 1,1 and 1,2. 1,2 is made a child of 1,1 and 1,1 a child of the root.
1392 Id view_1_1 = vm_client1()->CreateView(1); 1401 Id view_1_1 = vm_client1()->NewWindow(1);
1393 ASSERT_TRUE(view_1_1); 1402 ASSERT_TRUE(view_1_1);
1394 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_1, true)); 1403 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_1, true));
1395 Id view_1_2 = vm_client1()->CreateView(2); 1404 Id view_1_2 = vm_client1()->NewWindow(2);
1396 ASSERT_TRUE(view_1_2); 1405 ASSERT_TRUE(view_1_2);
1397 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_2, true)); 1406 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_2, true));
1398 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1407 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1399 ASSERT_TRUE(AddView(vm1(), view_1_1, view_1_2)); 1408 ASSERT_TRUE(AddWindow(vm1(), view_1_1, view_1_2));
1400 1409
1401 // Establish the second connection at 1,2. 1410 // Establish the second connection at 1,2.
1402 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnectionWithRoot(view_1_2)); 1411 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnectionWithRoot(view_1_2));
1403 1412
1404 // Add 2,3 as a child of 1,2. 1413 // Add 2,3 as a child of 1,2.
1405 Id view_2_3 = vm_client2()->CreateView(3); 1414 Id view_2_3 = vm_client2()->NewWindow(3);
1406 ASSERT_TRUE(view_2_3); 1415 ASSERT_TRUE(view_2_3);
1407 ASSERT_TRUE(SetViewVisibility(vm2(), view_2_3, true)); 1416 ASSERT_TRUE(SetWindowVisibility(vm2(), view_2_3, true));
1408 ASSERT_TRUE(AddView(vm2(), view_1_2, view_2_3)); 1417 ASSERT_TRUE(AddWindow(vm2(), view_1_2, view_2_3));
1409 WaitForAllMessages(vm1()); 1418 WaitForAllMessages(vm1());
1410 1419
1411 changes2()->clear(); 1420 changes2()->clear();
1412 // Hide 1,2 from connection 1. Connection 2 should see this. 1421 // Hide 1,2 from connection 1. Connection 2 should see this.
1413 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_2, false)); 1422 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_2, false));
1414 { 1423 {
1415 vm_client2_->WaitForChangeCount(1); 1424 vm_client2_->WaitForChangeCount(1);
1416 EXPECT_EQ( 1425 EXPECT_EQ(
1417 "VisibilityChanged view=" + IdToString(view_1_2) + " visible=false", 1426 "VisibilityChanged view=" + IdToString(view_1_2) + " visible=false",
1418 SingleChangeToDescription(*changes2())); 1427 SingleChangeToDescription(*changes2()));
1419 } 1428 }
1420 1429
1421 changes1()->clear(); 1430 changes1()->clear();
1422 // Show 1,2 from connection 2, connection 1 should be notified. 1431 // Show 1,2 from connection 2, connection 1 should be notified.
1423 ASSERT_TRUE(SetViewVisibility(vm2(), view_1_2, true)); 1432 ASSERT_TRUE(SetWindowVisibility(vm2(), view_1_2, true));
1424 { 1433 {
1425 vm_client1_->WaitForChangeCount(1); 1434 vm_client1_->WaitForChangeCount(1);
1426 EXPECT_EQ( 1435 EXPECT_EQ(
1427 "VisibilityChanged view=" + IdToString(view_1_2) + " visible=true", 1436 "VisibilityChanged view=" + IdToString(view_1_2) + " visible=true",
1428 SingleChangeToDescription(*changes1())); 1437 SingleChangeToDescription(*changes1()));
1429 } 1438 }
1430 1439
1431 changes2()->clear(); 1440 changes2()->clear();
1432 // Hide 1,1, connection 2 should be told the draw state changed. 1441 // Hide 1,1, connection 2 should be told the draw state changed.
1433 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_1, false)); 1442 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_1, false));
1434 { 1443 {
1435 vm_client2_->WaitForChangeCount(1); 1444 vm_client2_->WaitForChangeCount(1);
1436 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=false", 1445 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=false",
1437 SingleChangeToDescription(*changes2())); 1446 SingleChangeToDescription(*changes2()));
1438 } 1447 }
1439 1448
1440 changes2()->clear(); 1449 changes2()->clear();
1441 // Show 1,1 from connection 1. Connection 2 should see this. 1450 // Show 1,1 from connection 1. Connection 2 should see this.
1442 ASSERT_TRUE(SetViewVisibility(vm1(), view_1_1, true)); 1451 ASSERT_TRUE(SetWindowVisibility(vm1(), view_1_1, true));
1443 { 1452 {
1444 vm_client2_->WaitForChangeCount(1); 1453 vm_client2_->WaitForChangeCount(1);
1445 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=true", 1454 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=true",
1446 SingleChangeToDescription(*changes2())); 1455 SingleChangeToDescription(*changes2()));
1447 } 1456 }
1448 1457
1449 // Change visibility of 2,3, connection 1 should see this. 1458 // Change visibility of 2,3, connection 1 should see this.
1450 changes1()->clear(); 1459 changes1()->clear();
1451 ASSERT_TRUE(SetViewVisibility(vm2(), view_2_3, false)); 1460 ASSERT_TRUE(SetWindowVisibility(vm2(), view_2_3, false));
1452 { 1461 {
1453 vm_client1_->WaitForChangeCount(1); 1462 vm_client1_->WaitForChangeCount(1);
1454 EXPECT_EQ( 1463 EXPECT_EQ(
1455 "VisibilityChanged view=" + IdToString(view_2_3) + " visible=false", 1464 "VisibilityChanged view=" + IdToString(view_2_3) + " visible=false",
1456 SingleChangeToDescription(*changes1())); 1465 SingleChangeToDescription(*changes1()));
1457 } 1466 }
1458 1467
1459 changes2()->clear(); 1468 changes2()->clear();
1460 // Remove 1,1 from the root, connection 2 should see drawn state changed. 1469 // Remove 1,1 from the root, connection 2 should see drawn state changed.
1461 ASSERT_TRUE(RemoveViewFromParent(vm1(), view_1_1)); 1470 ASSERT_TRUE(RemoveWindowFromParent(vm1(), view_1_1));
1462 { 1471 {
1463 vm_client2_->WaitForChangeCount(1); 1472 vm_client2_->WaitForChangeCount(1);
1464 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=false", 1473 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=false",
1465 SingleChangeToDescription(*changes2())); 1474 SingleChangeToDescription(*changes2()));
1466 } 1475 }
1467 1476
1468 changes2()->clear(); 1477 changes2()->clear();
1469 // Add 1,1 back to the root, connection 2 should see drawn state changed. 1478 // Add 1,1 back to the root, connection 2 should see drawn state changed.
1470 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1479 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1471 { 1480 {
1472 vm_client2_->WaitForChangeCount(1); 1481 vm_client2_->WaitForChangeCount(1);
1473 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=true", 1482 EXPECT_EQ("DrawnStateChanged view=" + IdToString(view_1_2) + " drawn=true",
1474 SingleChangeToDescription(*changes2())); 1483 SingleChangeToDescription(*changes2()));
1475 } 1484 }
1476 } 1485 }
1477 1486
1478 TEST_F(ViewTreeAppTest, SetViewProperty) { 1487 TEST_F(WindowTreeAppTest, SetWindowProperty) {
1479 Id view_1_1 = vm_client1()->CreateView(1); 1488 Id view_1_1 = vm_client1()->NewWindow(1);
1480 ASSERT_TRUE(view_1_1); 1489 ASSERT_TRUE(view_1_1);
1481 1490
1482 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 1491 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
1483 changes2()->clear(); 1492 changes2()->clear();
1484 1493
1485 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1494 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1486 { 1495 {
1487 std::vector<TestView> views; 1496 std::vector<TestView> views;
1488 GetViewTree(vm1(), root_view_id(), &views); 1497 GetWindowTree(vm1(), root_window_id(), &views);
1489 ASSERT_EQ(2u, views.size()); 1498 ASSERT_EQ(2u, views.size());
1490 EXPECT_EQ(root_view_id(), views[0].view_id); 1499 EXPECT_EQ(root_window_id(), views[0].window_id);
1491 EXPECT_EQ(view_1_1, views[1].view_id); 1500 EXPECT_EQ(view_1_1, views[1].window_id);
1492 ASSERT_EQ(0u, views[1].properties.size()); 1501 ASSERT_EQ(0u, views[1].properties.size());
1493 } 1502 }
1494 1503
1495 // Set properties on 1. 1504 // Set properties on 1.
1496 changes2()->clear(); 1505 changes2()->clear();
1497 std::vector<uint8_t> one(1, '1'); 1506 std::vector<uint8_t> one(1, '1');
1498 ASSERT_TRUE(SetViewProperty(vm1(), view_1_1, "one", &one)); 1507 ASSERT_TRUE(SetWindowProperty(vm1(), view_1_1, "one", &one));
1499 { 1508 {
1500 vm_client2_->WaitForChangeCount(1); 1509 vm_client2_->WaitForChangeCount(1);
1501 EXPECT_EQ( 1510 EXPECT_EQ(
1502 "PropertyChanged view=" + IdToString(view_1_1) + " key=one value=1", 1511 "PropertyChanged view=" + IdToString(view_1_1) + " key=one value=1",
1503 SingleChangeToDescription(*changes2())); 1512 SingleChangeToDescription(*changes2()));
1504 } 1513 }
1505 1514
1506 // Test that our properties exist in the view tree 1515 // Test that our properties exist in the view tree
1507 { 1516 {
1508 std::vector<TestView> views; 1517 std::vector<TestView> views;
1509 GetViewTree(vm1(), view_1_1, &views); 1518 GetWindowTree(vm1(), view_1_1, &views);
1510 ASSERT_EQ(1u, views.size()); 1519 ASSERT_EQ(1u, views.size());
1511 ASSERT_EQ(1u, views[0].properties.size()); 1520 ASSERT_EQ(1u, views[0].properties.size());
1512 EXPECT_EQ(one, views[0].properties["one"]); 1521 EXPECT_EQ(one, views[0].properties["one"]);
1513 } 1522 }
1514 1523
1515 changes2()->clear(); 1524 changes2()->clear();
1516 // Set back to null. 1525 // Set back to null.
1517 ASSERT_TRUE(SetViewProperty(vm1(), view_1_1, "one", NULL)); 1526 ASSERT_TRUE(SetWindowProperty(vm1(), view_1_1, "one", NULL));
1518 { 1527 {
1519 vm_client2_->WaitForChangeCount(1); 1528 vm_client2_->WaitForChangeCount(1);
1520 EXPECT_EQ( 1529 EXPECT_EQ(
1521 "PropertyChanged view=" + IdToString(view_1_1) + " key=one value=NULL", 1530 "PropertyChanged view=" + IdToString(view_1_1) + " key=one value=NULL",
1522 SingleChangeToDescription(*changes2())); 1531 SingleChangeToDescription(*changes2()));
1523 } 1532 }
1524 } 1533 }
1525 1534
1526 TEST_F(ViewTreeAppTest, OnEmbeddedAppDisconnected) { 1535 TEST_F(WindowTreeAppTest, OnEmbeddedAppDisconnected) {
1527 // Create connection 2 and 3. 1536 // Create connection 2 and 3.
1528 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1537 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1529 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1538 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1530 Id view_2_2 = vm_client2()->CreateView(2); 1539 Id view_2_2 = vm_client2()->NewWindow(2);
1531 ASSERT_TRUE(view_2_2); 1540 ASSERT_TRUE(view_2_2);
1532 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 1541 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
1533 changes2()->clear(); 1542 changes2()->clear();
1534 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2)); 1543 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2));
1535 1544
1536 // Connection 1 should get a hierarchy change for view_2_2. 1545 // Connection 1 should get a hierarchy change for view_2_2.
1537 vm_client1_->WaitForChangeCount(1); 1546 vm_client1_->WaitForChangeCount(1);
1538 changes1()->clear(); 1547 changes1()->clear();
1539 1548
1540 // Close connection 3. Connection 2 (which had previously embedded 3) should 1549 // Close connection 3. Connection 2 (which had previously embedded 3) should
1541 // be notified of this. 1550 // be notified of this.
1542 vm_client3_.reset(); 1551 vm_client3_.reset();
1543 vm_client2_->WaitForChangeCount(1); 1552 vm_client2_->WaitForChangeCount(1);
1544 EXPECT_EQ("OnEmbeddedAppDisconnected view=" + IdToString(view_2_2), 1553 EXPECT_EQ("OnEmbeddedAppDisconnected view=" + IdToString(view_2_2),
1545 SingleChangeToDescription(*changes2())); 1554 SingleChangeToDescription(*changes2()));
1546 1555
1547 vm_client1_->WaitForChangeCount(1); 1556 vm_client1_->WaitForChangeCount(1);
1548 EXPECT_EQ("OnEmbeddedAppDisconnected view=" + IdToString(view_2_2), 1557 EXPECT_EQ("OnEmbeddedAppDisconnected view=" + IdToString(view_2_2),
1549 SingleChangeToDescription(*changes1())); 1558 SingleChangeToDescription(*changes1()));
1550 } 1559 }
1551 1560
1552 // Verifies when the parent of an Embed() is destroyed the embedded app gets 1561 // Verifies when the parent of an Embed() is destroyed the embedded app gets
1553 // a ViewDeleted (and doesn't trigger a DCHECK). 1562 // a ViewDeleted (and doesn't trigger a DCHECK).
1554 TEST_F(ViewTreeAppTest, OnParentOfEmbedDisconnects) { 1563 TEST_F(WindowTreeAppTest, OnParentOfEmbedDisconnects) {
1555 // Create connection 2 and 3. 1564 // Create connection 2 and 3.
1556 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1565 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1557 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1566 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1558 ASSERT_TRUE(AddView(vm1(), root_view_id(), view_1_1)); 1567 ASSERT_TRUE(AddWindow(vm1(), root_window_id(), view_1_1));
1559 Id view_2_2 = vm_client2()->CreateView(2); 1568 Id view_2_2 = vm_client2()->NewWindow(2);
1560 Id view_2_3 = vm_client2()->CreateView(3); 1569 Id view_2_3 = vm_client2()->NewWindow(3);
1561 ASSERT_TRUE(view_2_2); 1570 ASSERT_TRUE(view_2_2);
1562 ASSERT_TRUE(view_2_3); 1571 ASSERT_TRUE(view_2_3);
1563 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 1572 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
1564 ASSERT_TRUE(AddView(vm2(), view_2_2, view_2_3)); 1573 ASSERT_TRUE(AddWindow(vm2(), view_2_2, view_2_3));
1565 changes2()->clear(); 1574 changes2()->clear();
1566 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_3)); 1575 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_3));
1567 changes3()->clear(); 1576 changes3()->clear();
1568 1577
1569 // Close connection 2. Connection 3 should get a delete (for its root). 1578 // Close connection 2. Connection 3 should get a delete (for its root).
1570 vm_client2_.reset(); 1579 vm_client2_.reset();
1571 vm_client3_->WaitForChangeCount(1); 1580 vm_client3_->WaitForChangeCount(1);
1572 EXPECT_EQ("ViewDeleted view=" + IdToString(view_2_3), 1581 EXPECT_EQ("ViewDeleted view=" + IdToString(view_2_3),
1573 SingleChangeToDescription(*changes3())); 1582 SingleChangeToDescription(*changes3()));
1574 } 1583 }
1575 1584
1576 // Verifies ViewTreeImpl doesn't incorrectly erase from its internal 1585 // Verifies WindowTreeImpl doesn't incorrectly erase from its internal
1577 // map when a view from another connection with the same view_id is removed. 1586 // map when a view from another connection with the same window_id is removed.
1578 TEST_F(ViewTreeAppTest, DontCleanMapOnDestroy) { 1587 TEST_F(WindowTreeAppTest, DontCleanMapOnDestroy) {
1579 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1588 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1580 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1589 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1581 ASSERT_TRUE(vm_client2()->CreateView(1)); 1590 ASSERT_TRUE(vm_client2()->NewWindow(1));
1582 changes1()->clear(); 1591 changes1()->clear();
1583 vm_client2_.reset(); 1592 vm_client2_.reset();
1584 vm_client1_->WaitForChangeCount(1); 1593 vm_client1_->WaitForChangeCount(1);
1585 EXPECT_EQ("OnEmbeddedAppDisconnected view=" + IdToString(view_1_1), 1594 EXPECT_EQ("OnEmbeddedAppDisconnected view=" + IdToString(view_1_1),
1586 SingleChangeToDescription(*changes1())); 1595 SingleChangeToDescription(*changes1()));
1587 std::vector<TestView> views; 1596 std::vector<TestView> views;
1588 GetViewTree(vm1(), view_1_1, &views); 1597 GetWindowTree(vm1(), view_1_1, &views);
1589 EXPECT_FALSE(views.empty()); 1598 EXPECT_FALSE(views.empty());
1590 } 1599 }
1591 1600
1592 // Verifies Embed() works when supplying a ViewTreeClient. 1601 // Verifies Embed() works when supplying a WindowTreeClient.
1593 TEST_F(ViewTreeAppTest, EmbedSupplyingViewTreeClient) { 1602 TEST_F(WindowTreeAppTest, EmbedSupplyingWindowTreeClient) {
1594 ASSERT_TRUE(vm_client1()->CreateView(1)); 1603 ASSERT_TRUE(vm_client1()->NewWindow(1));
1595 1604
1596 TestViewTreeClientImpl client2(application_impl()); 1605 TestWindowTreeClientImpl client2(application_impl());
1597 mojo::ViewTreeClientPtr client2_ptr; 1606 mojom::WindowTreeClientPtr client2_ptr;
1598 mojo::Binding<ViewTreeClient> client2_binding(&client2, &client2_ptr); 1607 mojo::Binding<WindowTreeClient> client2_binding(&client2, &client2_ptr);
1599 ASSERT_TRUE( 1608 ASSERT_TRUE(
1600 Embed(vm1(), BuildViewId(connection_id_1(), 1), client2_ptr.Pass())); 1609 Embed(vm1(), BuildViewId(connection_id_1(), 1), client2_ptr.Pass()));
1601 client2.WaitForOnEmbed(); 1610 client2.WaitForOnEmbed();
1602 EXPECT_EQ("OnEmbed", 1611 EXPECT_EQ("OnEmbed",
1603 SingleChangeToDescription(*client2.tracker()->changes())); 1612 SingleChangeToDescription(*client2.tracker()->changes()));
1604 } 1613 }
1605 1614
1606 TEST_F(ViewTreeAppTest, EmbedFailsFromOtherConnection) { 1615 TEST_F(WindowTreeAppTest, EmbedFailsFromOtherConnection) {
1607 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1616 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1608 1617
1609 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1618 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1610 Id view_2_2 = vm_client2()->CreateView(2); 1619 Id view_2_2 = vm_client2()->NewWindow(2);
1611 ASSERT_TRUE(view_2_2); 1620 ASSERT_TRUE(view_2_2);
1612 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 1621 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
1613 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2)); 1622 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), view_2_2));
1614 1623
1615 Id view_3_3 = vm_client3()->CreateView(3); 1624 Id view_3_3 = vm_client3()->NewWindow(3);
1616 ASSERT_TRUE(view_3_3); 1625 ASSERT_TRUE(view_3_3);
1617 ASSERT_TRUE(AddView(vm3(), view_2_2, view_3_3)); 1626 ASSERT_TRUE(AddWindow(vm3(), view_2_2, view_3_3));
1618 1627
1619 // 2 should not be able to embed in view_3_3 as view_3_3 was not created by 1628 // 2 should not be able to embed in view_3_3 as view_3_3 was not created by
1620 // 2. 1629 // 2.
1621 EXPECT_FALSE( 1630 EXPECT_FALSE(
1622 EmbedUrl(application_impl(), vm2(), application_impl()->url(), view_3_3)); 1631 EmbedUrl(application_impl(), vm2(), application_impl()->url(), view_3_3));
1623 } 1632 }
1624 1633
1625 // Verifies Embed() from window manager on another connections view works. 1634 // Verifies Embed() from window manager on another connections view works.
1626 TEST_F(ViewTreeAppTest, EmbedFromOtherConnection) { 1635 TEST_F(WindowTreeAppTest, EmbedFromOtherConnection) {
1627 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1636 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1628 1637
1629 Id view_1_1 = BuildViewId(connection_id_1(), 1); 1638 Id view_1_1 = BuildViewId(connection_id_1(), 1);
1630 Id view_2_2 = vm_client2()->CreateView(2); 1639 Id view_2_2 = vm_client2()->NewWindow(2);
1631 ASSERT_TRUE(view_2_2); 1640 ASSERT_TRUE(view_2_2);
1632 ASSERT_TRUE(AddView(vm2(), view_1_1, view_2_2)); 1641 ASSERT_TRUE(AddWindow(vm2(), view_1_1, view_2_2));
1633 1642
1634 changes2()->clear(); 1643 changes2()->clear();
1635 1644
1636 // Establish a third connection in view_2_2. 1645 // Establish a third connection in view_2_2.
1637 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_2_2)); 1646 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm1(), view_2_2));
1638 1647
1639 WaitForAllMessages(vm2()); 1648 WaitForAllMessages(vm2());
1640 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2())); 1649 EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2()));
1641 } 1650 }
1642 1651
1643 TEST_F(ViewTreeAppTest, CantEmbedFromConnectionRoot) { 1652 TEST_F(WindowTreeAppTest, CantEmbedFromConnectionRoot) {
1644 // Shouldn't be able to embed into the root. 1653 // Shouldn't be able to embed into the root.
1645 ASSERT_FALSE(EmbedUrl(application_impl(), vm1(), application_impl()->url(), 1654 ASSERT_FALSE(EmbedUrl(application_impl(), vm1(), application_impl()->url(),
1646 root_view_id())); 1655 root_window_id()));
1647 1656
1648 // Even though the call above failed a ViewTreeClient was obtained. We need to 1657 // Even though the call above failed a WindowTreeClient was obtained. We need
1658 // to
1649 // wait for it else we throw off the next connect. 1659 // wait for it else we throw off the next connect.
1650 WaitForViewTreeClient(); 1660 WaitForWindowTreeClient();
1651 1661
1652 // Don't allow a connection to embed into its own root. 1662 // Don't allow a connection to embed into its own root.
1653 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); 1663 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
1654 EXPECT_FALSE(EmbedUrl(application_impl(), vm2(), application_impl()->url(), 1664 EXPECT_FALSE(EmbedUrl(application_impl(), vm2(), application_impl()->url(),
1655 BuildViewId(connection_id_1(), 1))); 1665 BuildViewId(connection_id_1(), 1)));
1656 1666
1657 // Need to wait for a ViewTreeClient for same reason as above. 1667 // Need to wait for a WindowTreeClient for same reason as above.
1658 WaitForViewTreeClient(); 1668 WaitForWindowTreeClient();
1659 1669
1660 Id view_1_2 = vm_client1()->CreateView(2); 1670 Id view_1_2 = vm_client1()->NewWindow(2);
1661 ASSERT_TRUE(view_1_2); 1671 ASSERT_TRUE(view_1_2);
1662 ASSERT_TRUE(AddView(vm1(), BuildViewId(connection_id_1(), 1), view_1_2)); 1672 ASSERT_TRUE(AddWindow(vm1(), BuildViewId(connection_id_1(), 1), view_1_2));
1663 ASSERT_TRUE(vm_client3_.get() == nullptr); 1673 ASSERT_TRUE(vm_client3_.get() == nullptr);
1664 vm_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( 1674 vm_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask(
1665 vm1(), view_1_2, mojo::ViewTree::ACCESS_POLICY_EMBED_ROOT, nullptr); 1675 vm1(), view_1_2, mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT, nullptr);
1666 ASSERT_TRUE(vm_client3_.get() != nullptr); 1676 ASSERT_TRUE(vm_client3_.get() != nullptr);
1667 vm_client3_->set_root_view(root_view_id()); 1677 vm_client3_->set_root_view(root_window_id());
1668 1678
1669 // view_1_2 is vm3's root, so even though v3 is an embed root it should not 1679 // view_1_2 is vm3's root, so even though v3 is an embed root it should not
1670 // be able to Embed into itself. 1680 // be able to Embed into itself.
1671 ASSERT_FALSE( 1681 ASSERT_FALSE(
1672 EmbedUrl(application_impl(), vm3(), application_impl()->url(), view_1_2)); 1682 EmbedUrl(application_impl(), vm3(), application_impl()->url(), view_1_2));
1673 } 1683 }
1674 1684
1675 // TODO(sky): need to better track changes to initial connection. For example, 1685 // TODO(sky): need to better track changes to initial connection. For example,
1676 // that SetBounsdViews/AddView and the like don't result in messages to the 1686 // that SetBounsdViews/AddWindow and the like don't result in messages to the
1677 // originating connection. 1687 // originating connection.
1678 1688
1679 // TODO(sky): make sure coverage of what was 1689 // TODO(sky): make sure coverage of what was
1680 // ViewManagerTest.SecondEmbedRoot_InitService and 1690 // ViewManagerTest.SecondEmbedRoot_InitService and
1681 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager 1691 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager
1682 // tests. 1692 // tests.
1683 1693
1684 } // namespace mus 1694 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/view_manager_client_apptest.cc ('k') | components/mus/ws/view_tree_host_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698