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

Side by Side Diff: mojo/shell/application_manager_unittest.cc

Issue 1706063002: Eliminate ShellClientFactoryConnection & just have the ApplicationManager do it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@factory
Patch Set: . Created 4 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
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/connect_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mojo/shell/application_manager.h" 5 #include "mojo/shell/application_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 ~ApplicationManagerTest() override {} 391 ~ApplicationManagerTest() override {}
392 392
393 void SetUp() override { 393 void SetUp() override {
394 application_manager_.reset(new ApplicationManager(true)); 394 application_manager_.reset(new ApplicationManager(true));
395 test_loader_ = new TestApplicationLoader; 395 test_loader_ = new TestApplicationLoader;
396 test_loader_->set_context(&context_); 396 test_loader_->set_context(&context_);
397 application_manager_->set_default_loader( 397 application_manager_->set_default_loader(
398 scoped_ptr<ApplicationLoader>(test_loader_)); 398 scoped_ptr<ApplicationLoader>(test_loader_));
399 399
400 TestServicePtr service_proxy; 400 TestServicePtr service_proxy;
401 ConnectToInterface(application_manager_.get(), GURL(kTestURLString), 401 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
402 &service_proxy); 402 GURL(kTestURLString), &service_proxy);
403 test_client_.reset(new TestClient(std::move(service_proxy))); 403 test_client_.reset(new TestClient(std::move(service_proxy)));
404 } 404 }
405 405
406 void TearDown() override { 406 void TearDown() override {
407 test_client_.reset(); 407 test_client_.reset();
408 application_manager_.reset(); 408 application_manager_.reset();
409 } 409 }
410 410
411 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { 411 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) {
412 application_manager_->SetLoaderForURL( 412 application_manager_->SetLoaderForURL(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 TEST_F(ApplicationManagerTest, SetLoaders) { 468 TEST_F(ApplicationManagerTest, SetLoaders) {
469 TestApplicationLoader* default_loader = new TestApplicationLoader; 469 TestApplicationLoader* default_loader = new TestApplicationLoader;
470 TestApplicationLoader* url_loader = new TestApplicationLoader; 470 TestApplicationLoader* url_loader = new TestApplicationLoader;
471 application_manager_->set_default_loader( 471 application_manager_->set_default_loader(
472 scoped_ptr<ApplicationLoader>(default_loader)); 472 scoped_ptr<ApplicationLoader>(default_loader));
473 application_manager_->SetLoaderForURL( 473 application_manager_->SetLoaderForURL(
474 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); 474 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1"));
475 475
476 // test::test1 should go to url_loader. 476 // test::test1 should go to url_loader.
477 TestServicePtr test_service; 477 TestServicePtr test_service;
478 ConnectToInterface(application_manager_.get(), GURL("test:test1"), 478 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
479 &test_service); 479 GURL("test:test1"), &test_service);
480 EXPECT_EQ(1, url_loader->num_loads()); 480 EXPECT_EQ(1, url_loader->num_loads());
481 EXPECT_EQ(0, default_loader->num_loads()); 481 EXPECT_EQ(0, default_loader->num_loads());
482 482
483 // http::test1 should go to default loader. 483 // http::test1 should go to default loader.
484 ConnectToInterface(application_manager_.get(), GURL("http:test1"), 484 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
485 &test_service); 485 GURL("http:test1"), &test_service);
486 EXPECT_EQ(1, url_loader->num_loads()); 486 EXPECT_EQ(1, url_loader->num_loads());
487 EXPECT_EQ(1, default_loader->num_loads()); 487 EXPECT_EQ(1, default_loader->num_loads());
488 } 488 }
489 489
490 // Confirm that the url of a service is correctly passed to another service that 490 // Confirm that the url of a service is correctly passed to another service that
491 // it loads. 491 // it loads.
492 TEST_F(ApplicationManagerTest, ACallB) { 492 TEST_F(ApplicationManagerTest, ACallB) {
493 // Any url can load a. 493 // Any url can load a.
494 AddLoaderForURL(GURL(kTestAURLString), std::string()); 494 AddLoaderForURL(GURL(kTestAURLString), std::string());
495 495
496 // Only a can load b. 496 // Only a can load b.
497 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 497 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
498 498
499 TestAPtr a; 499 TestAPtr a;
500 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a); 500 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
501 GURL(kTestAURLString), &a);
501 a->CallB(); 502 a->CallB();
502 loop_.Run(); 503 loop_.Run();
503 EXPECT_EQ(1, tester_context_.num_b_calls()); 504 EXPECT_EQ(1, tester_context_.num_b_calls());
504 EXPECT_TRUE(tester_context_.a_called_quit()); 505 EXPECT_TRUE(tester_context_.a_called_quit());
505 } 506 }
506 507
507 // A calls B which calls C. 508 // A calls B which calls C.
508 TEST_F(ApplicationManagerTest, BCallC) { 509 TEST_F(ApplicationManagerTest, BCallC) {
509 // Any url can load a. 510 // Any url can load a.
510 AddLoaderForURL(GURL(kTestAURLString), std::string()); 511 AddLoaderForURL(GURL(kTestAURLString), std::string());
511 512
512 // Only a can load b. 513 // Only a can load b.
513 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 514 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
514 515
515 TestAPtr a; 516 TestAPtr a;
516 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a); 517 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
518 GURL(kTestAURLString), &a);
517 a->CallCFromB(); 519 a->CallCFromB();
518 loop_.Run(); 520 loop_.Run();
519 521
520 EXPECT_EQ(1, tester_context_.num_b_calls()); 522 EXPECT_EQ(1, tester_context_.num_b_calls());
521 EXPECT_EQ(1, tester_context_.num_c_calls()); 523 EXPECT_EQ(1, tester_context_.num_c_calls());
522 EXPECT_TRUE(tester_context_.a_called_quit()); 524 EXPECT_TRUE(tester_context_.a_called_quit());
523 } 525 }
524 526
525 // Confirm that a service impl will be deleted if the app that connected to 527 // Confirm that a service impl will be deleted if the app that connected to
526 // it goes away. 528 // it goes away.
527 TEST_F(ApplicationManagerTest, BDeleted) { 529 TEST_F(ApplicationManagerTest, BDeleted) {
528 AddLoaderForURL(GURL(kTestAURLString), std::string()); 530 AddLoaderForURL(GURL(kTestAURLString), std::string());
529 AddLoaderForURL(GURL(kTestBURLString), std::string()); 531 AddLoaderForURL(GURL(kTestBURLString), std::string());
530 532
531 TestAPtr a; 533 TestAPtr a;
532 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a); 534 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
535 GURL(kTestAURLString), &a);
533 536
534 a->CallB(); 537 a->CallB();
535 loop_.Run(); 538 loop_.Run();
536 539
537 // Kills the a app. 540 // Kills the a app.
538 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(), 541 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(),
539 GURL(kTestAURLString)); 542 GURL(kTestAURLString));
540 loop_.Run(); 543 loop_.Run();
541 544
542 EXPECT_EQ(1, tester_context_.num_b_deletes()); 545 EXPECT_EQ(1, tester_context_.num_b_deletes());
543 } 546 }
544 547
545 // Confirm that the url of a service is correctly passed to another service that 548 // Confirm that the url of a service is correctly passed to another service that
546 // it loads, and that it can be rejected. 549 // it loads, and that it can be rejected.
547 TEST_F(ApplicationManagerTest, ANoLoadB) { 550 TEST_F(ApplicationManagerTest, ANoLoadB) {
548 // Any url can load a. 551 // Any url can load a.
549 AddLoaderForURL(GURL(kTestAURLString), std::string()); 552 AddLoaderForURL(GURL(kTestAURLString), std::string());
550 553
551 // Only c can load b, so this will fail. 554 // Only c can load b, so this will fail.
552 AddLoaderForURL(GURL(kTestBURLString), "test:TestC"); 555 AddLoaderForURL(GURL(kTestBURLString), "test:TestC");
553 556
554 TestAPtr a; 557 TestAPtr a;
555 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a); 558 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
559 GURL(kTestAURLString), &a);
556 a->CallB(); 560 a->CallB();
557 loop_.Run(); 561 loop_.Run();
558 EXPECT_EQ(0, tester_context_.num_b_calls()); 562 EXPECT_EQ(0, tester_context_.num_b_calls());
559 563
560 EXPECT_FALSE(tester_context_.a_called_quit()); 564 EXPECT_FALSE(tester_context_.a_called_quit());
561 EXPECT_TRUE(tester_context_.tester_called_quit()); 565 EXPECT_TRUE(tester_context_.tester_called_quit());
562 } 566 }
563 567
564 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { 568 TEST_F(ApplicationManagerTest, NoServiceNoLoad) {
565 AddLoaderForURL(GURL(kTestAURLString), std::string()); 569 AddLoaderForURL(GURL(kTestAURLString), std::string());
566 570
567 // There is no TestC service implementation registered with 571 // There is no TestC service implementation registered with
568 // ApplicationManager, so this cannot succeed (but also shouldn't crash). 572 // ApplicationManager, so this cannot succeed (but also shouldn't crash).
569 TestCPtr c; 573 TestCPtr c;
570 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &c); 574 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
575 GURL(kTestAURLString), &c);
571 c.set_connection_error_handler( 576 c.set_connection_error_handler(
572 []() { base::MessageLoop::current()->QuitWhenIdle(); }); 577 []() { base::MessageLoop::current()->QuitWhenIdle(); });
573 578
574 loop_.Run(); 579 loop_.Run();
575 EXPECT_TRUE(c.encountered_error()); 580 EXPECT_TRUE(c.encountered_error());
576 } 581 }
577 582
578 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { 583 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) {
579 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); 584 ClosingApplicationLoader* loader = new ClosingApplicationLoader();
580 application_manager_->SetLoaderForURL( 585 application_manager_->SetLoaderForURL(
581 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); 586 scoped_ptr<ApplicationLoader>(loader), GURL("test:test"));
582 587
583 bool called = false; 588 bool called = false;
584 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); 589 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
585 params->SetTargetURL(GURL("test:test")); 590 params->SetTargetURL(GURL("test:test"));
586 params->set_on_application_end( 591 params->set_on_application_end(
587 base::Bind(&QuitClosure, base::Unretained(&called))); 592 base::Bind(&QuitClosure, base::Unretained(&called)));
588 application_manager_->ConnectToApplication(std::move(params)); 593 application_manager_->ConnectToApplication(std::move(params));
589 loop_.Run(); 594 loop_.Run();
590 EXPECT_TRUE(called); 595 EXPECT_TRUE(called);
591 } 596 }
592 597
593 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { 598 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
594 // 1 because ApplicationManagerTest connects once at startup. 599 // 1 because ApplicationManagerTest connects once at startup.
595 EXPECT_EQ(1, test_loader_->num_loads()); 600 EXPECT_EQ(1, test_loader_->num_loads());
596 601
597 TestServicePtr test_service; 602 TestServicePtr test_service;
598 ConnectToInterface(application_manager_.get(), 603 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
599 GURL("mojo:foo"), &test_service); 604 GURL("mojo:foo"), &test_service);
600 EXPECT_EQ(2, test_loader_->num_loads()); 605 EXPECT_EQ(2, test_loader_->num_loads());
601 606
602 // Exactly the same URL as above. 607 // Exactly the same URL as above.
603 ConnectToInterface(application_manager_.get(), 608 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
604 GURL("mojo:foo"), &test_service); 609 GURL("mojo:foo"), &test_service);
605 EXPECT_EQ(2, test_loader_->num_loads()); 610 EXPECT_EQ(2, test_loader_->num_loads());
606 611
607 // A different identity because the domain is different. 612 // A different identity because the domain is different.
608 ConnectToInterface(application_manager_.get(), 613 ConnectToInterface(application_manager_.get(), CreateShellIdentity(),
609 GURL("mojo:bar"), &test_service); 614 GURL("mojo:bar"), &test_service);
610 EXPECT_EQ(3, test_loader_->num_loads()); 615 EXPECT_EQ(3, test_loader_->num_loads());
611 } 616 }
612 617
613 } // namespace test 618 } // namespace test
614 } // namespace shell 619 } // namespace shell
615 } // namespace mojo 620 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/connect_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698