OLD | NEW |
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/ids.h" | 9 #include "components/mus/ids.h" |
10 #include "components/mus/public/interfaces/view_tree.mojom.h" | 10 #include "components/mus/public/interfaces/view_tree.mojom.h" |
11 #include "components/mus/public/interfaces/view_tree_host.mojom.h" | 11 #include "components/mus/public/interfaces/view_tree_host.mojom.h" |
12 #include "components/mus/test_change_tracker.h" | 12 #include "components/mus/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::ConnectionSpecificId; | |
22 using mojo::ERROR_CODE_NONE; | 21 using mojo::ERROR_CODE_NONE; |
23 using mojo::ErrorCode; | 22 using mojo::ErrorCode; |
24 using mojo::EventPtr; | 23 using mojo::EventPtr; |
25 using mojo::Id; | |
26 using mojo::InterfaceRequest; | 24 using mojo::InterfaceRequest; |
27 using mojo::ORDER_DIRECTION_ABOVE; | 25 using mojo::ORDER_DIRECTION_ABOVE; |
28 using mojo::ORDER_DIRECTION_BELOW; | 26 using mojo::ORDER_DIRECTION_BELOW; |
29 using mojo::OrderDirection; | 27 using mojo::OrderDirection; |
30 using mojo::RectPtr; | 28 using mojo::RectPtr; |
31 using mojo::ServiceProvider; | 29 using mojo::ServiceProvider; |
32 using mojo::ServiceProviderPtr; | 30 using mojo::ServiceProviderPtr; |
33 using mojo::String; | 31 using mojo::String; |
34 using mojo::ViewDataPtr; | 32 using mojo::ViewDataPtr; |
35 using mojo::ViewTree; | 33 using mojo::ViewTree; |
36 using mojo::ViewTreeClient; | 34 using mojo::ViewTreeClient; |
37 using mojo::ViewportMetricsPtr; | 35 using mojo::ViewportMetricsPtr; |
38 | 36 |
39 namespace view_manager { | 37 namespace mus { |
40 | 38 |
41 // Creates an id used for transport from the specified parameters. | 39 // Creates an id used for transport from the specified parameters. |
42 Id BuildViewId(ConnectionSpecificId connection_id, | 40 Id BuildViewId(ConnectionSpecificId connection_id, |
43 ConnectionSpecificId view_id) { | 41 ConnectionSpecificId view_id) { |
44 return (connection_id << 16) | view_id; | 42 return (connection_id << 16) | view_id; |
45 } | 43 } |
46 | 44 |
47 // Callback function from ViewTree functions. ---------------------------------- | 45 // Callback function from ViewTree functions. ---------------------------------- |
48 | 46 |
49 void BoolResultCallback(base::RunLoop* run_loop, | 47 void BoolResultCallback(base::RunLoop* run_loop, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 ErrorCode result = ERROR_CODE_NONE; | 207 ErrorCode result = ERROR_CODE_NONE; |
210 base::RunLoop run_loop; | 208 base::RunLoop run_loop; |
211 vm->CreateView(ViewIdToTransportId(InvalidViewId()), | 209 vm->CreateView(ViewIdToTransportId(InvalidViewId()), |
212 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); | 210 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
213 run_loop.Run(); | 211 run_loop.Run(); |
214 return result != ERROR_CODE_NONE; | 212 return result != ERROR_CODE_NONE; |
215 } | 213 } |
216 | 214 |
217 const Id kNullParentId = 0; | 215 const Id kNullParentId = 0; |
218 std::string IdToString(Id id) { | 216 std::string IdToString(Id id) { |
219 return (id == kNullParentId) | 217 return (id == kNullParentId) ? "null" : base::StringPrintf( |
220 ? "null" | 218 "%d,%d", HiWord(id), LoWord(id)); |
221 : base::StringPrintf("%d,%d", mojo::HiWord(id), mojo::LoWord(id)); | |
222 } | 219 } |
223 | 220 |
224 std::string ViewParentToString(Id view, Id parent) { | 221 std::string ViewParentToString(Id view, Id parent) { |
225 return base::StringPrintf("view=%s parent=%s", IdToString(view).c_str(), | 222 return base::StringPrintf("view=%s parent=%s", IdToString(view).c_str(), |
226 IdToString(parent).c_str()); | 223 IdToString(parent).c_str()); |
227 } | 224 } |
228 | 225 |
229 // ----------------------------------------------------------------------------- | 226 // ----------------------------------------------------------------------------- |
230 | 227 |
231 // A ViewTreeClient implementation that logs all changes to a tracker. | 228 // A ViewTreeClient implementation that logs all changes to a tracker. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 if (wait_state_.get() && | 294 if (wait_state_.get() && |
298 wait_state_->change_count == tracker_.changes()->size()) { | 295 wait_state_->change_count == tracker_.changes()->size()) { |
299 wait_state_->run_loop.Quit(); | 296 wait_state_->run_loop.Quit(); |
300 } | 297 } |
301 } | 298 } |
302 | 299 |
303 // ViewTreeClient: | 300 // ViewTreeClient: |
304 void OnEmbed(ConnectionSpecificId connection_id, | 301 void OnEmbed(ConnectionSpecificId connection_id, |
305 ViewDataPtr root, | 302 ViewDataPtr root, |
306 mojo::ViewTreePtr tree, | 303 mojo::ViewTreePtr tree, |
307 mojo::Id focused_view_id, | 304 Id focused_view_id, |
308 uint32_t access_policy) override { | 305 uint32_t access_policy) override { |
309 // TODO(sky): add coverage of |focused_view_id|. | 306 // TODO(sky): add coverage of |focused_view_id|. |
310 tree_ = tree.Pass(); | 307 tree_ = tree.Pass(); |
311 connection_id_ = connection_id; | 308 connection_id_ = connection_id; |
312 tracker()->OnEmbed(connection_id, root.Pass()); | 309 tracker()->OnEmbed(connection_id, root.Pass()); |
313 if (embed_run_loop_) | 310 if (embed_run_loop_) |
314 embed_run_loop_->Quit(); | 311 embed_run_loop_->Quit(); |
315 } | 312 } |
316 void OnEmbeddedAppDisconnected(Id view_id) override { | 313 void OnEmbeddedAppDisconnected(Id view_id) override { |
317 tracker()->OnEmbeddedAppDisconnected(view_id); | 314 tracker()->OnEmbeddedAppDisconnected(view_id); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 *connection_id = (*client->tracker()->changes())[0].connection_id; | 503 *connection_id = (*client->tracker()->changes())[0].connection_id; |
507 return client.Pass(); | 504 return client.Pass(); |
508 } | 505 } |
509 | 506 |
510 // ApplicationTestBase: | 507 // ApplicationTestBase: |
511 ApplicationDelegate* GetApplicationDelegate() override { return this; } | 508 ApplicationDelegate* GetApplicationDelegate() override { return this; } |
512 void SetUp() override { | 509 void SetUp() override { |
513 ApplicationTestBase::SetUp(); | 510 ApplicationTestBase::SetUp(); |
514 client_factory_.reset(new ViewTreeClientFactory(application_impl())); | 511 client_factory_.reset(new ViewTreeClientFactory(application_impl())); |
515 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 512 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
516 request->url = mojo::String::From("mojo:view_manager"); | 513 request->url = mojo::String::From("mojo:mus"); |
517 | 514 |
518 mojo::ViewTreeHostFactoryPtr factory; | 515 mojo::ViewTreeHostFactoryPtr factory; |
519 application_impl()->ConnectToService(request.Pass(), &factory); | 516 application_impl()->ConnectToService(request.Pass(), &factory); |
520 | 517 |
521 mojo::ViewTreeClientPtr tree_client_ptr; | 518 mojo::ViewTreeClientPtr tree_client_ptr; |
522 vm_client1_.reset(new ViewTreeClientImpl(application_impl())); | 519 vm_client1_.reset(new ViewTreeClientImpl(application_impl())); |
523 vm_client1_->Bind(GetProxy(&tree_client_ptr)); | 520 vm_client1_->Bind(GetProxy(&tree_client_ptr)); |
524 | 521 |
525 factory->CreateViewTreeHost(GetProxy(&host_), mojo::ViewTreeHostClientPtr(), | 522 factory->CreateViewTreeHost(GetProxy(&host_), mojo::ViewTreeHostClientPtr(), |
526 tree_client_ptr.Pass()); | 523 tree_client_ptr.Pass()); |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 | 1652 |
1656 // TODO(sky): need to better track changes to initial connection. For example, | 1653 // TODO(sky): need to better track changes to initial connection. For example, |
1657 // that SetBounsdViews/AddView and the like don't result in messages to the | 1654 // that SetBounsdViews/AddView and the like don't result in messages to the |
1658 // originating connection. | 1655 // originating connection. |
1659 | 1656 |
1660 // TODO(sky): make sure coverage of what was | 1657 // TODO(sky): make sure coverage of what was |
1661 // ViewManagerTest.SecondEmbedRoot_InitService and | 1658 // ViewManagerTest.SecondEmbedRoot_InitService and |
1662 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager | 1659 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager |
1663 // tests. | 1660 // tests. |
1664 | 1661 |
1665 } // namespace view_manager | 1662 } // namespace mus |
OLD | NEW |