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

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

Issue 1351963002: Some more minor cleanup to ApplicationManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 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/capability_filter_unittest.cc » ('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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "mojo/application/public/cpp/application_connection.h" 11 #include "mojo/application/public/cpp/application_connection.h"
12 #include "mojo/application/public/cpp/application_delegate.h" 12 #include "mojo/application/public/cpp/application_delegate.h"
13 #include "mojo/application/public/cpp/application_impl.h" 13 #include "mojo/application/public/cpp/application_impl.h"
14 #include "mojo/application/public/cpp/interface_factory.h" 14 #include "mojo/application/public/cpp/interface_factory.h"
15 #include "mojo/application/public/interfaces/content_handler.mojom.h" 15 #include "mojo/application/public/interfaces/content_handler.mojom.h"
16 #include "mojo/application/public/interfaces/service_provider.mojom.h" 16 #include "mojo/application/public/interfaces/service_provider.mojom.h"
17 #include "mojo/public/cpp/bindings/strong_binding.h" 17 #include "mojo/public/cpp/bindings/strong_binding.h"
18 #include "mojo/shell/application_loader.h" 18 #include "mojo/shell/application_loader.h"
19 #include "mojo/shell/application_manager.h" 19 #include "mojo/shell/application_manager.h"
20 #include "mojo/shell/connect_util.h"
20 #include "mojo/shell/fetcher.h" 21 #include "mojo/shell/fetcher.h"
21 #include "mojo/shell/test.mojom.h" 22 #include "mojo/shell/test.mojom.h"
22 #include "mojo/shell/test_package_manager.h" 23 #include "mojo/shell/test_package_manager.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace mojo { 26 namespace mojo {
26 namespace shell { 27 namespace shell {
27 namespace { 28 namespace {
28 29
29 const char kTestURLString[] = "test:testService"; 30 const char kTestURLString[] = "test:testService";
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 506
506 void SetUp() override { 507 void SetUp() override {
507 application_manager_.reset(new ApplicationManager( 508 application_manager_.reset(new ApplicationManager(
508 make_scoped_ptr(new AMTestPackageManager))); 509 make_scoped_ptr(new AMTestPackageManager)));
509 test_loader_ = new TestApplicationLoader; 510 test_loader_ = new TestApplicationLoader;
510 test_loader_->set_context(&context_); 511 test_loader_->set_context(&context_);
511 application_manager_->set_default_loader( 512 application_manager_->set_default_loader(
512 scoped_ptr<ApplicationLoader>(test_loader_)); 513 scoped_ptr<ApplicationLoader>(test_loader_));
513 514
514 TestServicePtr service_proxy; 515 TestServicePtr service_proxy;
515 application_manager_->ConnectToService(GURL(kTestURLString), 516 ConnectToService(application_manager_.get(), GURL(kTestURLString),
516 &service_proxy); 517 &service_proxy);
517 test_client_.reset(new TestClient(service_proxy.Pass())); 518 test_client_.reset(new TestClient(service_proxy.Pass()));
518 } 519 }
519 520
520 void TearDown() override { 521 void TearDown() override {
521 test_client_.reset(); 522 test_client_.reset();
522 application_manager_.reset(); 523 application_manager_.reset();
523 } 524 }
524 525
525 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { 526 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) {
526 application_manager_->SetLoaderForURL( 527 application_manager_->SetLoaderForURL(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 TEST_F(ApplicationManagerTest, SetLoaders) { 583 TEST_F(ApplicationManagerTest, SetLoaders) {
583 TestApplicationLoader* default_loader = new TestApplicationLoader; 584 TestApplicationLoader* default_loader = new TestApplicationLoader;
584 TestApplicationLoader* url_loader = new TestApplicationLoader; 585 TestApplicationLoader* url_loader = new TestApplicationLoader;
585 application_manager_->set_default_loader( 586 application_manager_->set_default_loader(
586 scoped_ptr<ApplicationLoader>(default_loader)); 587 scoped_ptr<ApplicationLoader>(default_loader));
587 application_manager_->SetLoaderForURL( 588 application_manager_->SetLoaderForURL(
588 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); 589 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1"));
589 590
590 // test::test1 should go to url_loader. 591 // test::test1 should go to url_loader.
591 TestServicePtr test_service; 592 TestServicePtr test_service;
592 application_manager_->ConnectToService(GURL("test:test1"), &test_service); 593 ConnectToService(application_manager_.get(), GURL("test:test1"),
594 &test_service);
593 EXPECT_EQ(1, url_loader->num_loads()); 595 EXPECT_EQ(1, url_loader->num_loads());
594 EXPECT_EQ(0, default_loader->num_loads()); 596 EXPECT_EQ(0, default_loader->num_loads());
595 597
596 // http::test1 should go to default loader. 598 // http::test1 should go to default loader.
597 application_manager_->ConnectToService(GURL("http:test1"), &test_service); 599 ConnectToService(application_manager_.get(), GURL("http:test1"),
600 &test_service);
598 EXPECT_EQ(1, url_loader->num_loads()); 601 EXPECT_EQ(1, url_loader->num_loads());
599 EXPECT_EQ(1, default_loader->num_loads()); 602 EXPECT_EQ(1, default_loader->num_loads());
600 } 603 }
601 604
602 // Confirm that the url of a service is correctly passed to another service that 605 // Confirm that the url of a service is correctly passed to another service that
603 // it loads. 606 // it loads.
604 TEST_F(ApplicationManagerTest, ACallB) { 607 TEST_F(ApplicationManagerTest, ACallB) {
605 // Any url can load a. 608 // Any url can load a.
606 AddLoaderForURL(GURL(kTestAURLString), std::string()); 609 AddLoaderForURL(GURL(kTestAURLString), std::string());
607 610
608 // Only a can load b. 611 // Only a can load b.
609 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 612 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
610 613
611 TestAPtr a; 614 TestAPtr a;
612 application_manager_->ConnectToService(GURL(kTestAURLString), &a); 615 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
613 a->CallB(); 616 a->CallB();
614 loop_.Run(); 617 loop_.Run();
615 EXPECT_EQ(1, tester_context_.num_b_calls()); 618 EXPECT_EQ(1, tester_context_.num_b_calls());
616 EXPECT_TRUE(tester_context_.a_called_quit()); 619 EXPECT_TRUE(tester_context_.a_called_quit());
617 } 620 }
618 621
619 // A calls B which calls C. 622 // A calls B which calls C.
620 TEST_F(ApplicationManagerTest, BCallC) { 623 TEST_F(ApplicationManagerTest, BCallC) {
621 // Any url can load a. 624 // Any url can load a.
622 AddLoaderForURL(GURL(kTestAURLString), std::string()); 625 AddLoaderForURL(GURL(kTestAURLString), std::string());
623 626
624 // Only a can load b. 627 // Only a can load b.
625 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 628 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
626 629
627 TestAPtr a; 630 TestAPtr a;
628 application_manager_->ConnectToService(GURL(kTestAURLString), &a); 631 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
629 a->CallCFromB(); 632 a->CallCFromB();
630 loop_.Run(); 633 loop_.Run();
631 634
632 EXPECT_EQ(1, tester_context_.num_b_calls()); 635 EXPECT_EQ(1, tester_context_.num_b_calls());
633 EXPECT_EQ(1, tester_context_.num_c_calls()); 636 EXPECT_EQ(1, tester_context_.num_c_calls());
634 EXPECT_TRUE(tester_context_.a_called_quit()); 637 EXPECT_TRUE(tester_context_.a_called_quit());
635 } 638 }
636 639
637 // Confirm that a service impl will be deleted if the app that connected to 640 // Confirm that a service impl will be deleted if the app that connected to
638 // it goes away. 641 // it goes away.
639 TEST_F(ApplicationManagerTest, BDeleted) { 642 TEST_F(ApplicationManagerTest, BDeleted) {
640 AddLoaderForURL(GURL(kTestAURLString), std::string()); 643 AddLoaderForURL(GURL(kTestAURLString), std::string());
641 AddLoaderForURL(GURL(kTestBURLString), std::string()); 644 AddLoaderForURL(GURL(kTestBURLString), std::string());
642 645
643 TestAPtr a; 646 TestAPtr a;
644 application_manager_->ConnectToService(GURL(kTestAURLString), &a); 647 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
645 648
646 a->CallB(); 649 a->CallB();
647 loop_.Run(); 650 loop_.Run();
648 651
649 // Kills the a app. 652 // Kills the a app.
650 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(), 653 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(),
651 GURL(kTestAURLString)); 654 GURL(kTestAURLString));
652 loop_.Run(); 655 loop_.Run();
653 656
654 EXPECT_EQ(1, tester_context_.num_b_deletes()); 657 EXPECT_EQ(1, tester_context_.num_b_deletes());
655 } 658 }
656 659
657 // Confirm that the url of a service is correctly passed to another service that 660 // Confirm that the url of a service is correctly passed to another service that
658 // it loads, and that it can be rejected. 661 // it loads, and that it can be rejected.
659 TEST_F(ApplicationManagerTest, ANoLoadB) { 662 TEST_F(ApplicationManagerTest, ANoLoadB) {
660 // Any url can load a. 663 // Any url can load a.
661 AddLoaderForURL(GURL(kTestAURLString), std::string()); 664 AddLoaderForURL(GURL(kTestAURLString), std::string());
662 665
663 // Only c can load b, so this will fail. 666 // Only c can load b, so this will fail.
664 AddLoaderForURL(GURL(kTestBURLString), "test:TestC"); 667 AddLoaderForURL(GURL(kTestBURLString), "test:TestC");
665 668
666 TestAPtr a; 669 TestAPtr a;
667 application_manager_->ConnectToService(GURL(kTestAURLString), &a); 670 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
668 a->CallB(); 671 a->CallB();
669 loop_.Run(); 672 loop_.Run();
670 EXPECT_EQ(0, tester_context_.num_b_calls()); 673 EXPECT_EQ(0, tester_context_.num_b_calls());
671 674
672 EXPECT_FALSE(tester_context_.a_called_quit()); 675 EXPECT_FALSE(tester_context_.a_called_quit());
673 EXPECT_TRUE(tester_context_.tester_called_quit()); 676 EXPECT_TRUE(tester_context_.tester_called_quit());
674 } 677 }
675 678
676 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { 679 TEST_F(ApplicationManagerTest, NoServiceNoLoad) {
677 AddLoaderForURL(GURL(kTestAURLString), std::string()); 680 AddLoaderForURL(GURL(kTestAURLString), std::string());
678 681
679 // There is no TestC service implementation registered with 682 // There is no TestC service implementation registered with
680 // ApplicationManager, so this cannot succeed (but also shouldn't crash). 683 // ApplicationManager, so this cannot succeed (but also shouldn't crash).
681 TestCPtr c; 684 TestCPtr c;
682 application_manager_->ConnectToService(GURL(kTestAURLString), &c); 685 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &c);
683 c.set_connection_error_handler( 686 c.set_connection_error_handler(
684 []() { base::MessageLoop::current()->QuitWhenIdle(); }); 687 []() { base::MessageLoop::current()->QuitWhenIdle(); });
685 688
686 loop_.Run(); 689 loop_.Run();
687 EXPECT_TRUE(c.encountered_error()); 690 EXPECT_TRUE(c.encountered_error());
688 } 691 }
689 692
690 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { 693 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) {
691 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); 694 ClosingApplicationLoader* loader = new ClosingApplicationLoader();
692 application_manager_->SetLoaderForURL( 695 application_manager_->SetLoaderForURL(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 738
736 ASSERT_EQ(1, loader->num_loads()); 739 ASSERT_EQ(1, loader->num_loads());
737 EXPECT_EQ(requestor_url, loader->last_requestor_url()); 740 EXPECT_EQ(requestor_url, loader->last_requestor_url());
738 } 741 }
739 742
740 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { 743 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
741 // 1 because ApplicationManagerTest connects once at startup. 744 // 1 because ApplicationManagerTest connects once at startup.
742 EXPECT_EQ(1, test_loader_->num_loads()); 745 EXPECT_EQ(1, test_loader_->num_loads());
743 746
744 TestServicePtr test_service; 747 TestServicePtr test_service;
745 application_manager_->ConnectToService(GURL("http://www.example.org/abc?def"), 748 ConnectToService(application_manager_.get(),
746 &test_service); 749 GURL("http://www.example.org/abc?def"), &test_service);
747 EXPECT_EQ(2, test_loader_->num_loads()); 750 EXPECT_EQ(2, test_loader_->num_loads());
748 751
749 // Exactly the same URL as above. 752 // Exactly the same URL as above.
750 application_manager_->ConnectToService(GURL("http://www.example.org/abc?def"), 753 ConnectToService(application_manager_.get(),
751 &test_service); 754 GURL("http://www.example.org/abc?def"), &test_service);
752 EXPECT_EQ(2, test_loader_->num_loads()); 755 EXPECT_EQ(2, test_loader_->num_loads());
753 756
754 // The same identity as the one above because only the query string is 757 // The same identity as the one above because only the query string is
755 // different. 758 // different.
756 application_manager_->ConnectToService(GURL("http://www.example.org/abc"), 759 ConnectToService(application_manager_.get(),
757 &test_service); 760 GURL("http://www.example.org/abc"), &test_service);
758 EXPECT_EQ(2, test_loader_->num_loads()); 761 EXPECT_EQ(2, test_loader_->num_loads());
759 762
760 // A different identity because the path is different. 763 // A different identity because the path is different.
761 application_manager_->ConnectToService( 764 ConnectToService(application_manager_.get(),
762 GURL("http://www.example.org/another_path"), &test_service); 765 GURL("http://www.example.org/another_path"), &test_service);
763 EXPECT_EQ(3, test_loader_->num_loads()); 766 EXPECT_EQ(3, test_loader_->num_loads());
764 767
765 // A different identity because the domain is different. 768 // A different identity because the domain is different.
766 application_manager_->ConnectToService( 769 ConnectToService(application_manager_.get(),
767 GURL("http://www.another_domain.org/abc"), &test_service); 770 GURL("http://www.another_domain.org/abc"), &test_service);
768 EXPECT_EQ(4, test_loader_->num_loads()); 771 EXPECT_EQ(4, test_loader_->num_loads());
769 } 772 }
770 773
771 TEST(ApplicationManagerTest2, 774 TEST(ApplicationManagerTest2,
772 MultipleConnectionsToContentHandlerGetSameContentHandlerId) { 775 MultipleConnectionsToContentHandlerGetSameContentHandlerId) {
773 base::MessageLoop loop; 776 base::MessageLoop loop;
774 const GURL content_handler_url("http://test.content.handler"); 777 const GURL content_handler_url("http://test.content.handler");
775 const GURL requestor_url("http://requestor.url"); 778 const GURL requestor_url("http://requestor.url");
776 TestContext test_context; 779 TestContext test_context;
777 scoped_ptr<AMTestPackageManager> test_package_manager( 780 scoped_ptr<AMTestPackageManager> test_package_manager(
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 params->set_filter(GetPermissiveCapabilityFilter()); 915 params->set_filter(GetPermissiveCapabilityFilter());
913 params->set_connect_callback( 916 params->set_connect_callback(
914 [&content_handler_id](uint32_t t) { content_handler_id = t; }); 917 [&content_handler_id](uint32_t t) { content_handler_id = t; });
915 application_manager_->ConnectToApplication(params.Pass()); 918 application_manager_->ConnectToApplication(params.Pass());
916 EXPECT_EQ(0u, content_handler_id); 919 EXPECT_EQ(0u, content_handler_id);
917 } 920 }
918 921
919 } // namespace 922 } // namespace
920 } // namespace shell 923 } // namespace shell
921 } // namespace mojo 924 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/capability_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698