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