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

Side by Side Diff: services/view_manager/view_manager_service_apptest.cc

Issue 905083002: Adds Embed() variant to ViewManagerService that takes ViewManagerClient (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: real comments Created 5 years, 10 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 "mojo/public/cpp/application/application_delegate.h" 8 #include "mojo/public/cpp/application/application_delegate.h"
9 #include "mojo/public/cpp/application/application_impl.h" 9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/application/application_test_base.h" 10 #include "mojo/public/cpp/application/application_test_base.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // block until call completes and return the result. 73 // block until call completes and return the result.
74 bool CreateView(ViewManagerService* vm, Id view_id) { 74 bool CreateView(ViewManagerService* vm, Id view_id) {
75 ErrorCode result = ERROR_CODE_NONE; 75 ErrorCode result = ERROR_CODE_NONE;
76 base::RunLoop run_loop; 76 base::RunLoop run_loop;
77 vm->CreateView(view_id, 77 vm->CreateView(view_id,
78 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); 78 base::Bind(&ErrorCodeResultCallback, &run_loop, &result));
79 run_loop.Run(); 79 run_loop.Run();
80 return result == ERROR_CODE_NONE; 80 return result == ERROR_CODE_NONE;
81 } 81 }
82 82
83 bool Embed(ViewManagerService* vm, Id root_id) { 83 bool EmbedUrl(ViewManagerService* vm, Id root_id) {
84 bool result = false; 84 bool result = false;
85 base::RunLoop run_loop; 85 base::RunLoop run_loop;
86 { 86 {
87 vm->Embed("mojo:view_manager_service_apptests", root_id, nullptr, nullptr, 87 vm->EmbedUrl("mojo:view_manager_service_apptests", root_id, nullptr,
88 nullptr, 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(),
88 base::Bind(&BoolResultCallback, &run_loop, &result)); 101 base::Bind(&BoolResultCallback, &run_loop, &result));
89 } 102 }
90 run_loop.Run(); 103 run_loop.Run();
91 return result; 104 return result;
92 } 105 }
93 106
94 ErrorCode CreateViewWithErrorCode(ViewManagerService* vm, Id view_id) { 107 ErrorCode CreateViewWithErrorCode(ViewManagerService* vm, Id view_id) {
95 ErrorCode result = ERROR_CODE_NONE; 108 ErrorCode result = ERROR_CODE_NONE;
96 base::RunLoop run_loop; 109 base::RunLoop run_loop;
97 vm->CreateView(view_id, 110 vm->CreateView(view_id,
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 ASSERT_TRUE(vm_client3_.get() == nullptr); 423 ASSERT_TRUE(vm_client3_.get() == nullptr);
411 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id); 424 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id);
412 ASSERT_TRUE(vm_client3_.get() != nullptr); 425 ASSERT_TRUE(vm_client3_.get() != nullptr);
413 } 426 }
414 427
415 // Establishes a new connection by way of Embed() on the specified 428 // Establishes a new connection by way of Embed() on the specified
416 // ViewManagerService. 429 // ViewManagerService.
417 scoped_ptr<ViewManagerClientImpl> EstablishConnectionViaEmbed( 430 scoped_ptr<ViewManagerClientImpl> EstablishConnectionViaEmbed(
418 ViewManagerService* owner, 431 ViewManagerService* owner,
419 Id root_id) { 432 Id root_id) {
420 if (!Embed(owner, root_id)) { 433 if (!EmbedUrl(owner, root_id)) {
421 ADD_FAILURE() << "Embed() failed"; 434 ADD_FAILURE() << "Embed() failed";
422 return nullptr; 435 return nullptr;
423 } 436 }
424 scoped_ptr<ViewManagerClientImpl> client = 437 scoped_ptr<ViewManagerClientImpl> client =
425 client_factory_.WaitForInstance(); 438 client_factory_.WaitForInstance();
426 if (!client.get()) { 439 if (!client.get()) {
427 ADD_FAILURE() << "WaitForInstance failed"; 440 ADD_FAILURE() << "WaitForInstance failed";
428 return nullptr; 441 return nullptr;
429 } 442 }
430 client->WaitForOnEmbed(); 443 client->WaitForOnEmbed();
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 // Add 1,1 back to the root, connection 2 should see drawn state changed. 1327 // Add 1,1 back to the root, connection 2 should see drawn state changed.
1315 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1))); 1328 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1)));
1316 { 1329 {
1317 vm_client2_->WaitForChangeCount(1); 1330 vm_client2_->WaitForChangeCount(1);
1318 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true", 1331 EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true",
1319 SingleChangeToDescription(*changes2())); 1332 SingleChangeToDescription(*changes2()));
1320 } 1333 }
1321 } 1334 }
1322 1335
1323 TEST_F(ViewManagerServiceAppTest, SetViewProperty) { 1336 TEST_F(ViewManagerServiceAppTest, SetViewProperty) {
1324 // Create 1 and 2 in the first connection and parent both to the root.
1325 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1))); 1337 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1)));
1326 1338
1327 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); 1339 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
1328 changes2()->clear(); 1340 changes2()->clear();
1329 1341
1330 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1))); 1342 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1)));
1331 { 1343 {
1332 std::vector<TestView> views; 1344 std::vector<TestView> views;
1333 GetViewTree(vm1(), BuildViewId(0, 1), &views); 1345 GetViewTree(vm1(), BuildViewId(0, 1), &views);
1334 ASSERT_EQ(2u, views.size()); 1346 ASSERT_EQ(2u, views.size());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 // No one should be able to see the cloned tree. 1455 // No one should be able to see the cloned tree.
1444 std::vector<TestView> views; 1456 std::vector<TestView> views;
1445 GetViewTree(vm1(), BuildViewId(1, 1), &views); 1457 GetViewTree(vm1(), BuildViewId(1, 1), &views);
1446 EXPECT_FALSE(HasClonedView(views)); 1458 EXPECT_FALSE(HasClonedView(views));
1447 views.clear(); 1459 views.clear();
1448 1460
1449 GetViewTree(vm2(), BuildViewId(1, 1), &views); 1461 GetViewTree(vm2(), BuildViewId(1, 1), &views);
1450 EXPECT_FALSE(HasClonedView(views)); 1462 EXPECT_FALSE(HasClonedView(views));
1451 } 1463 }
1452 1464
1465 // Verifies Embed() works when supplying a ViewManagerClient.
1466 TEST_F(ViewManagerServiceAppTest, EmbedSupplyingViewManagerClient) {
1467 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1)));
1468
1469 ViewManagerClientImpl client2;
1470 mojo::ViewManagerClientPtr client2_ptr;
1471 mojo::Binding<ViewManagerClient> client2_binding(&client2, &client2_ptr);
1472 ASSERT_TRUE(Embed(vm1(), BuildViewId(1, 1), client2_ptr.Pass()));
1473 client2.WaitForOnEmbed();
1474 EXPECT_EQ("OnEmbed creator=mojo:window_manager",
1475 SingleChangeToDescription(*client2.tracker()->changes()));
1476 }
1477
1453 // TODO(sky): need to better track changes to initial connection. For example, 1478 // TODO(sky): need to better track changes to initial connection. For example,
1454 // that SetBounsdViews/AddView and the like don't result in messages to the 1479 // that SetBounsdViews/AddView and the like don't result in messages to the
1455 // originating connection. 1480 // originating connection.
1456 1481
1457 // TODO(sky): make sure coverage of what was 1482 // TODO(sky): make sure coverage of what was
1458 // ViewManagerTest.SecondEmbedRoot_InitService and 1483 // ViewManagerTest.SecondEmbedRoot_InitService and
1459 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager 1484 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager
1460 // tests. 1485 // tests.
1461 1486
1462 } // namespace view_manager 1487 } // namespace view_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698