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