OLD | NEW |
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" |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 EXPECT_TRUE(c.encountered_error()); | 680 EXPECT_TRUE(c.encountered_error()); |
681 } | 681 } |
682 | 682 |
683 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { | 683 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { |
684 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); | 684 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); |
685 application_manager_->SetLoaderForURL( | 685 application_manager_->SetLoaderForURL( |
686 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); | 686 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); |
687 | 687 |
688 bool called = false; | 688 bool called = false; |
689 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 689 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
690 params->SetURLInfo(GURL("test:test")); | 690 params->SetTargetURL(GURL("test:test")); |
691 params->set_filter(GetPermissiveCapabilityFilter()); | |
692 params->set_on_application_end( | 691 params->set_on_application_end( |
693 base::Bind(&QuitClosure, base::Unretained(&called))); | 692 base::Bind(&QuitClosure, base::Unretained(&called))); |
694 application_manager_->ConnectToApplication(params.Pass()); | 693 application_manager_->ConnectToApplication(params.Pass()); |
695 loop_.Run(); | 694 loop_.Run(); |
696 EXPECT_TRUE(called); | 695 EXPECT_TRUE(called); |
697 } | 696 } |
698 | 697 |
699 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { | 698 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { |
700 const GURL content_handler_url("http://test.content.handler"); | 699 const GURL content_handler_url("http://test.content.handler"); |
701 const GURL requestor_url("http://requestor.url"); | 700 const GURL requestor_url("http://requestor.url"); |
702 TestContext test_context; | 701 TestContext test_context; |
703 base::MessageLoop loop; | 702 base::MessageLoop loop; |
704 scoped_ptr<AMTestPackageManager> test_package_manager( | 703 scoped_ptr<AMTestPackageManager> test_package_manager( |
705 new AMTestPackageManager); | 704 new AMTestPackageManager); |
706 test_package_manager->set_create_test_fetcher(true); | 705 test_package_manager->set_create_test_fetcher(true); |
707 test_package_manager->RegisterContentHandler(kTestMimeType, | 706 test_package_manager->RegisterContentHandler(kTestMimeType, |
708 content_handler_url); | 707 content_handler_url); |
709 ApplicationManager application_manager(test_package_manager.Pass()); | 708 ApplicationManager application_manager(test_package_manager.Pass()); |
710 application_manager.set_default_loader(nullptr); | 709 application_manager.set_default_loader(nullptr); |
711 | 710 |
712 TestApplicationLoader* loader = new TestApplicationLoader; | 711 TestApplicationLoader* loader = new TestApplicationLoader; |
713 loader->set_context(&test_context); | 712 loader->set_context(&test_context); |
714 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), | 713 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), |
715 content_handler_url); | 714 content_handler_url); |
716 | 715 |
717 bool called = false; | 716 bool called = false; |
718 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 717 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
719 params->set_originator_identity(Identity(requestor_url)); | 718 params->set_source(Identity(requestor_url)); |
720 params->set_originator_filter(GetPermissiveCapabilityFilter()); | 719 params->SetTargetURL(GURL("test:test")); |
721 params->SetURLInfo(GURL("test:test")); | |
722 params->set_filter(GetPermissiveCapabilityFilter()); | |
723 params->set_on_application_end( | 720 params->set_on_application_end( |
724 base::Bind(&QuitClosure, base::Unretained(&called))); | 721 base::Bind(&QuitClosure, base::Unretained(&called))); |
725 application_manager.ConnectToApplication(params.Pass()); | 722 application_manager.ConnectToApplication(params.Pass()); |
726 loop.Run(); | 723 loop.Run(); |
727 EXPECT_TRUE(called); | 724 EXPECT_TRUE(called); |
728 | 725 |
729 ASSERT_EQ(1, loader->num_loads()); | 726 ASSERT_EQ(1, loader->num_loads()); |
730 EXPECT_EQ(requestor_url, loader->last_requestor_url()); | 727 EXPECT_EQ(requestor_url, loader->last_requestor_url()); |
731 } | 728 } |
732 | 729 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 content_handler_loader->set_context(&test_context); | 778 content_handler_loader->set_context(&test_context); |
782 application_manager.SetLoaderForURL( | 779 application_manager.SetLoaderForURL( |
783 scoped_ptr<ApplicationLoader>(content_handler_loader), | 780 scoped_ptr<ApplicationLoader>(content_handler_loader), |
784 content_handler_url); | 781 content_handler_url); |
785 | 782 |
786 uint32_t content_handler_id; | 783 uint32_t content_handler_id; |
787 { | 784 { |
788 base::RunLoop run_loop; | 785 base::RunLoop run_loop; |
789 scoped_ptr<ConnectToApplicationParams> params( | 786 scoped_ptr<ConnectToApplicationParams> params( |
790 new ConnectToApplicationParams); | 787 new ConnectToApplicationParams); |
791 params->set_originator_identity(Identity(requestor_url)); | 788 params->set_source(Identity(requestor_url)); |
792 params->set_originator_filter(GetPermissiveCapabilityFilter()); | 789 params->SetTargetURL(GURL("test:test")); |
793 params->SetURLInfo(GURL("test:test")); | |
794 params->set_filter(GetPermissiveCapabilityFilter()); | |
795 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { | 790 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { |
796 content_handler_id = t; | 791 content_handler_id = t; |
797 run_loop.Quit(); | 792 run_loop.Quit(); |
798 }); | 793 }); |
799 application_manager.ConnectToApplication(params.Pass()); | 794 application_manager.ConnectToApplication(params.Pass()); |
800 run_loop.Run(); | 795 run_loop.Run(); |
801 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); | 796 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); |
802 } | 797 } |
803 | 798 |
804 uint32_t content_handler_id2; | 799 uint32_t content_handler_id2; |
805 { | 800 { |
806 base::RunLoop run_loop; | 801 base::RunLoop run_loop; |
807 scoped_ptr<ConnectToApplicationParams> params( | 802 scoped_ptr<ConnectToApplicationParams> params( |
808 new ConnectToApplicationParams); | 803 new ConnectToApplicationParams); |
809 params->set_originator_identity(Identity(requestor_url)); | 804 params->set_source(Identity(requestor_url)); |
810 params->set_originator_filter(GetPermissiveCapabilityFilter()); | 805 params->SetTargetURL(GURL("test:test")); |
811 params->SetURLInfo(GURL("test:test")); | |
812 params->set_filter(GetPermissiveCapabilityFilter()); | |
813 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { | 806 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { |
814 content_handler_id2 = t; | 807 content_handler_id2 = t; |
815 run_loop.Quit(); | 808 run_loop.Quit(); |
816 }); | 809 }); |
817 application_manager.ConnectToApplication(params.Pass()); | 810 application_manager.ConnectToApplication(params.Pass()); |
818 run_loop.Run(); | 811 run_loop.Run(); |
819 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); | 812 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); |
820 } | 813 } |
821 EXPECT_EQ(content_handler_id, content_handler_id2); | 814 EXPECT_EQ(content_handler_id, content_handler_id2); |
822 } | 815 } |
(...skipping 16 matching lines...) Expand all Loading... |
839 content_handler_loader->set_context(&test_context); | 832 content_handler_loader->set_context(&test_context); |
840 application_manager.SetLoaderForURL( | 833 application_manager.SetLoaderForURL( |
841 scoped_ptr<ApplicationLoader>(content_handler_loader), | 834 scoped_ptr<ApplicationLoader>(content_handler_loader), |
842 content_handler_url); | 835 content_handler_url); |
843 | 836 |
844 uint32_t content_handler_id; | 837 uint32_t content_handler_id; |
845 { | 838 { |
846 base::RunLoop run_loop; | 839 base::RunLoop run_loop; |
847 scoped_ptr<ConnectToApplicationParams> params( | 840 scoped_ptr<ConnectToApplicationParams> params( |
848 new ConnectToApplicationParams); | 841 new ConnectToApplicationParams); |
849 params->set_originator_identity(Identity(requestor_url)); | 842 params->set_source(Identity(requestor_url)); |
850 params->set_originator_filter(GetPermissiveCapabilityFilter()); | 843 params->SetTargetURL(GURL("test:test")); |
851 params->SetURLInfo(GURL("test:test")); | |
852 params->set_filter(GetPermissiveCapabilityFilter()); | |
853 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { | 844 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { |
854 content_handler_id = t; | 845 content_handler_id = t; |
855 run_loop.Quit(); | 846 run_loop.Quit(); |
856 }); | 847 }); |
857 application_manager.ConnectToApplication(params.Pass()); | 848 application_manager.ConnectToApplication(params.Pass()); |
858 run_loop.Run(); | 849 run_loop.Run(); |
859 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); | 850 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); |
860 } | 851 } |
861 | 852 |
862 const std::string mime_type2("test/mime-type2"); | 853 const std::string mime_type2("test/mime-type2"); |
863 const GURL content_handler_url2("http://test.content2.handler"); | 854 const GURL content_handler_url2("http://test.content2.handler"); |
864 test_package_manager->set_fetcher_url(GURL("test2:test2")); | 855 test_package_manager->set_fetcher_url(GURL("test2:test2")); |
865 test_package_manager->set_mime_type(mime_type2); | 856 test_package_manager->set_mime_type(mime_type2); |
866 test_package_manager->RegisterContentHandler(mime_type2, | 857 test_package_manager->RegisterContentHandler(mime_type2, |
867 content_handler_url2); | 858 content_handler_url2); |
868 | 859 |
869 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; | 860 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; |
870 content_handler_loader->set_create_content_handler(true); | 861 content_handler_loader->set_create_content_handler(true); |
871 content_handler_loader->set_context(&test_context); | 862 content_handler_loader->set_context(&test_context); |
872 application_manager.SetLoaderForURL( | 863 application_manager.SetLoaderForURL( |
873 scoped_ptr<ApplicationLoader>(content_handler_loader2), | 864 scoped_ptr<ApplicationLoader>(content_handler_loader2), |
874 content_handler_url2); | 865 content_handler_url2); |
875 | 866 |
876 uint32_t content_handler_id2; | 867 uint32_t content_handler_id2; |
877 { | 868 { |
878 base::RunLoop run_loop; | 869 base::RunLoop run_loop; |
879 scoped_ptr<ConnectToApplicationParams> params( | 870 scoped_ptr<ConnectToApplicationParams> params( |
880 new ConnectToApplicationParams); | 871 new ConnectToApplicationParams); |
881 params->set_originator_identity(Identity(requestor_url)); | 872 params->set_source(Identity(requestor_url)); |
882 params->set_originator_filter(GetPermissiveCapabilityFilter()); | 873 params->SetTargetURL(GURL("test2:test2")); |
883 params->SetURLInfo(GURL("test2:test2")); | |
884 params->set_filter(GetPermissiveCapabilityFilter()); | |
885 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { | 874 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { |
886 content_handler_id2 = t; | 875 content_handler_id2 = t; |
887 run_loop.Quit(); | 876 run_loop.Quit(); |
888 }); | 877 }); |
889 application_manager.ConnectToApplication(params.Pass()); | 878 application_manager.ConnectToApplication(params.Pass()); |
890 run_loop.Run(); | 879 run_loop.Run(); |
891 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); | 880 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); |
892 } | 881 } |
893 EXPECT_NE(content_handler_id, content_handler_id2); | 882 EXPECT_NE(content_handler_id, content_handler_id2); |
894 } | 883 } |
895 | 884 |
896 TEST_F(ApplicationManagerTest, | 885 TEST_F(ApplicationManagerTest, |
897 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { | 886 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { |
898 application_manager_->SetLoaderForURL( | 887 application_manager_->SetLoaderForURL( |
899 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), | 888 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), |
900 GURL("test:test")); | 889 GURL("test:test")); |
901 | 890 |
902 uint32_t content_handler_id = 1u; | 891 uint32_t content_handler_id = 1u; |
903 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 892 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
904 params->SetURLInfo(GURL("test:test")); | 893 params->SetTargetURL(GURL("test:test")); |
905 params->set_filter(GetPermissiveCapabilityFilter()); | |
906 params->set_connect_callback( | 894 params->set_connect_callback( |
907 [&content_handler_id](uint32_t t) { content_handler_id = t; }); | 895 [&content_handler_id](uint32_t t) { content_handler_id = t; }); |
908 application_manager_->ConnectToApplication(params.Pass()); | 896 application_manager_->ConnectToApplication(params.Pass()); |
909 EXPECT_EQ(0u, content_handler_id); | 897 EXPECT_EQ(0u, content_handler_id); |
910 } | 898 } |
911 | 899 |
912 } // namespace | 900 } // namespace |
913 } // namespace shell | 901 } // namespace shell |
914 } // namespace mojo | 902 } // namespace mojo |
OLD | NEW |