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

Side by Side Diff: mojo/services/view_manager/view_manager_unittest.cc

Issue 405163002: Add EmbedRoot to ViewManagerService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | Annotate | Revision Log
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/at_exit.h" 8 #include "base/at_exit.h"
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 bool Embed(const Id node_id, const char* url) { 174 bool Embed(const Id node_id, const char* url) {
175 changes_.clear(); 175 changes_.clear();
176 base::AutoReset<bool> auto_reset(&in_embed_, true); 176 base::AutoReset<bool> auto_reset(&in_embed_, true);
177 bool result = false; 177 bool result = false;
178 view_manager_->Embed(url, node_id, 178 view_manager_->Embed(url, node_id,
179 base::Bind(&ViewManagerProxy::GotResult, 179 base::Bind(&ViewManagerProxy::GotResult,
180 base::Unretained(this), &result)); 180 base::Unretained(this), &result));
181 RunMainLoop(); 181 RunMainLoop();
182 return result; 182 return result;
183 } 183 }
184 bool EmbedRoot(const char* url) {
185 changes_.clear();
186 base::AutoReset<bool> auto_reset(&in_embed_, true);
187 bool result = false;
188 view_manager_->EmbedRoot(url, base::Bind(&ViewManagerProxy::GotResult,
189 base::Unretained(this), &result));
190 RunMainLoop();
191 return result;
192 }
184 bool DeleteNode(Id node_id) { 193 bool DeleteNode(Id node_id) {
185 changes_.clear(); 194 changes_.clear();
186 bool result = false; 195 bool result = false;
187 view_manager_->DeleteNode(node_id, 196 view_manager_->DeleteNode(node_id,
188 base::Bind(&ViewManagerProxy::GotResult, 197 base::Bind(&ViewManagerProxy::GotResult,
189 base::Unretained(this), &result)); 198 base::Unretained(this), &result));
190 RunMainLoop(); 199 RunMainLoop();
191 return result; 200 return result;
192 } 201 }
193 bool DeleteView(Id view_id) { 202 bool DeleteView(Id view_id) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 void EmbedRootCallback(bool* result_cache, 435 void EmbedRootCallback(bool* result_cache,
427 base::RunLoop* run_loop, 436 base::RunLoop* run_loop,
428 bool result) { 437 bool result) {
429 *result_cache = result; 438 *result_cache = result;
430 run_loop->Quit(); 439 run_loop->Quit();
431 } 440 }
432 441
433 // Responsible for establishing the initial ViewManagerService connection. 442 // Responsible for establishing the initial ViewManagerService connection.
434 // Blocks until result is determined. 443 // Blocks until result is determined.
435 bool EmbedRoot(ViewManagerInitService* view_manager_init, 444 bool EmbedRoot(ViewManagerInitService* view_manager_init,
436 const std::string& url) { 445 const std::string& url,
446 size_t number_of_calls) {
437 bool result = false; 447 bool result = false;
438 base::RunLoop run_loop; 448 base::RunLoop run_loop;
439 view_manager_init->EmbedRoot(url, base::Bind(&EmbedRootCallback, 449 for (size_t i = 0; i < number_of_calls; ++i) {
440 &result, &run_loop)); 450 view_manager_init->EmbedRoot(url, base::Bind(&EmbedRootCallback,
451 &result, &run_loop));
452 }
441 run_loop.Run(); 453 run_loop.Run();
442 return result; 454 return result;
443 } 455 }
444 456
445 } // namespace 457 } // namespace
446 458
447 typedef std::vector<std::string> Changes; 459 typedef std::vector<std::string> Changes;
448 460
449 class ViewManagerTest : public testing::Test { 461 class ViewManagerTest : public testing::Test {
450 public: 462 public:
451 ViewManagerTest() : connection_(NULL), connection2_(NULL) {} 463 ViewManagerTest() : connection_(NULL), connection2_(NULL) {}
452 464
453 virtual void SetUp() OVERRIDE { 465 virtual void SetUp() OVERRIDE {
454 test_helper_.Init(); 466 test_helper_.Init();
455 467
456 test_helper_.SetLoaderForURL( 468 test_helper_.SetLoaderForURL(
457 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), 469 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()),
458 GURL(kTestServiceURL)); 470 GURL(kTestServiceURL));
459 471
460 test_helper_.SetLoaderForURL( 472 test_helper_.SetLoaderForURL(
461 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()), 473 scoped_ptr<ServiceLoader>(new EmbedServiceLoader()),
462 GURL(kTestServiceURL2)); 474 GURL(kTestServiceURL2));
463 475
464 test_helper_.service_manager()->ConnectToService( 476 test_helper_.service_manager()->ConnectToService(
465 GURL("mojo:mojo_view_manager"), 477 GURL("mojo:mojo_view_manager"),
466 &view_manager_init_); 478 &view_manager_init_);
467 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL)); 479 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL, 1));
468 480
469 connection_ = ViewManagerProxy::WaitForInstance(); 481 connection_ = ViewManagerProxy::WaitForInstance();
470 ASSERT_TRUE(connection_ != NULL); 482 ASSERT_TRUE(connection_ != NULL);
471 connection_->DoRunLoopUntilChangesCount(1); 483 connection_->DoRunLoopUntilChangesCount(1);
472 } 484 }
473 485
474 virtual void TearDown() OVERRIDE { 486 virtual void TearDown() OVERRIDE {
475 if (connection2_) 487 if (connection2_)
476 connection2_->Destroy(); 488 connection2_->Destroy();
477 if (connection_) 489 if (connection_)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 shell::ShellTestHelper test_helper_; 525 shell::ShellTestHelper test_helper_;
514 526
515 ViewManagerInitServicePtr view_manager_init_; 527 ViewManagerInitServicePtr view_manager_init_;
516 528
517 ViewManagerProxy* connection_; 529 ViewManagerProxy* connection_;
518 ViewManagerProxy* connection2_; 530 ViewManagerProxy* connection2_;
519 531
520 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); 532 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
521 }; 533 };
522 534
523 TEST_F(ViewManagerTest, SecondEmbedRoot) { 535 TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) {
524 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL)); 536 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL, 1));
525 connection_->DoRunLoopUntilChangesCount(1); 537 connection_->DoRunLoopUntilChangesCount(1);
526 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url); 538 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
527 } 539 }
528 540
541 TEST_F(ViewManagerTest, SecondEmbedRoot_Service) {
542 ASSERT_TRUE(connection_->EmbedRoot(kTestServiceURL));
543 connection_->DoRunLoopUntilChangesCount(1);
544 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
545 }
546
547 TEST_F(ViewManagerTest, MultipleEmbedRootsBeforeWTHReady) {
548 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kTestServiceURL, 2));
549 connection_->DoRunLoopUntilChangesCount(2);
550 EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
551 EXPECT_EQ(kTestServiceURL, connection_->changes()[1].embed_url);
552 }
553
529 // Verifies client gets a valid id. 554 // Verifies client gets a valid id.
530 TEST_F(ViewManagerTest, ValidId) { 555 TEST_F(ViewManagerTest, ValidId) {
531 // TODO(beng): this should really have the URL of the application that 556 // TODO(beng): this should really have the URL of the application that
532 // connected to ViewManagerInit. 557 // connected to ViewManagerInit.
533 EXPECT_EQ("OnConnectionEstablished creator=", 558 EXPECT_EQ("OnConnectionEstablished creator=",
534 ChangesToDescription1(connection_->changes())[0]); 559 ChangesToDescription1(connection_->changes())[0]);
535 560
536 // All these tests assume 1 for the client id. The only real assertion here is 561 // All these tests assume 1 for the client id. The only real assertion here is
537 // the client id is not zero, but adding this as rest of code here assumes 1. 562 // the client id is not zero, but adding this as rest of code here assumes 1.
538 EXPECT_EQ(1, connection_->changes()[0].connection_id); 563 EXPECT_EQ(1, connection_->changes()[0].connection_id);
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 // originating connection. 1419 // originating connection.
1395 1420
1396 // TODO(beng): Add tests for focus: 1421 // TODO(beng): Add tests for focus:
1397 // - focus between two nodes known to a connection 1422 // - focus between two nodes known to a connection
1398 // - focus between nodes unknown to one of the connections. 1423 // - focus between nodes unknown to one of the connections.
1399 // - focus between nodes unknown to either connection. 1424 // - focus between nodes unknown to either connection.
1400 1425
1401 } // namespace service 1426 } // namespace service
1402 } // namespace view_manager 1427 } // namespace view_manager
1403 } // namespace mojo 1428 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698