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

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

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