| 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 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 EXPECT_EQ(1, url_loader->num_loads()); | 799 EXPECT_EQ(1, url_loader->num_loads()); |
| 800 EXPECT_EQ(1, scheme_loader->num_loads()); | 800 EXPECT_EQ(1, scheme_loader->num_loads()); |
| 801 } | 801 } |
| 802 | 802 |
| 803 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { | 803 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { |
| 804 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); | 804 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); |
| 805 application_manager_->SetLoaderForScheme( | 805 application_manager_->SetLoaderForScheme( |
| 806 scoped_ptr<ApplicationLoader>(loader), "test"); | 806 scoped_ptr<ApplicationLoader>(loader), "test"); |
| 807 | 807 |
| 808 bool called = false; | 808 bool called = false; |
| 809 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 809 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 810 request->url = mojo::String::From("test:test"); | 810 params->SetURLInfo(GURL("test:test")); |
| 811 application_manager_->ConnectToApplication( | 811 params->set_filter(GetPermissiveCapabilityFilter()); |
| 812 nullptr, request.Pass(), std::string(), GURL(), nullptr, nullptr, | 812 params->set_on_application_end( |
| 813 GetPermissiveCapabilityFilter(), | 813 base::Bind(&QuitClosure, base::Unretained(&called))); |
| 814 base::Bind(&QuitClosure, base::Unretained(&called)), | 814 application_manager_->ConnectToApplication(params.Pass()); |
| 815 EmptyConnectCallback()); | |
| 816 loop_.Run(); | 815 loop_.Run(); |
| 817 EXPECT_TRUE(called); | 816 EXPECT_TRUE(called); |
| 818 } | 817 } |
| 819 | 818 |
| 820 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { | 819 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { |
| 821 const GURL content_handler_url("http://test.content.handler"); | 820 const GURL content_handler_url("http://test.content.handler"); |
| 822 const GURL requestor_url("http://requestor.url"); | 821 const GURL requestor_url("http://requestor.url"); |
| 823 TestContext test_context; | 822 TestContext test_context; |
| 824 base::MessageLoop loop; | 823 base::MessageLoop loop; |
| 825 TestDelegate test_delegate; | 824 TestDelegate test_delegate; |
| 826 test_delegate.set_create_test_fetcher(true); | 825 test_delegate.set_create_test_fetcher(true); |
| 827 ApplicationManager application_manager(&test_delegate); | 826 ApplicationManager application_manager(&test_delegate); |
| 828 application_manager.set_default_loader(nullptr); | 827 application_manager.set_default_loader(nullptr); |
| 829 application_manager.RegisterContentHandler(kTestMimeType, | 828 application_manager.RegisterContentHandler(kTestMimeType, |
| 830 content_handler_url); | 829 content_handler_url); |
| 831 | 830 |
| 832 TestApplicationLoader* loader = new TestApplicationLoader; | 831 TestApplicationLoader* loader = new TestApplicationLoader; |
| 833 loader->set_context(&test_context); | 832 loader->set_context(&test_context); |
| 834 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), | 833 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), |
| 835 content_handler_url); | 834 content_handler_url); |
| 836 | 835 |
| 837 bool called = false; | 836 bool called = false; |
| 838 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 837 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 839 request->url = mojo::String::From("test:test"); | 838 params->set_originator_identity(Identity(requestor_url)); |
| 840 application_manager.ConnectToApplication( | 839 params->set_originator_filter(GetPermissiveCapabilityFilter()); |
| 841 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr, | 840 params->SetURLInfo(GURL("test:test")); |
| 842 GetPermissiveCapabilityFilter(), | 841 params->set_filter(GetPermissiveCapabilityFilter()); |
| 843 base::Bind(&QuitClosure, base::Unretained(&called)), | 842 params->set_on_application_end( |
| 844 EmptyConnectCallback()); | 843 base::Bind(&QuitClosure, base::Unretained(&called))); |
| 844 application_manager.ConnectToApplication(params.Pass()); |
| 845 loop.Run(); | 845 loop.Run(); |
| 846 EXPECT_TRUE(called); | 846 EXPECT_TRUE(called); |
| 847 | 847 |
| 848 ASSERT_EQ(1, loader->num_loads()); | 848 ASSERT_EQ(1, loader->num_loads()); |
| 849 EXPECT_EQ(requestor_url, loader->last_requestor_url()); | 849 EXPECT_EQ(requestor_url, loader->last_requestor_url()); |
| 850 } | 850 } |
| 851 | 851 |
| 852 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { | 852 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { |
| 853 // 1 because ApplicationManagerTest connects once at startup. | 853 // 1 because ApplicationManagerTest connects once at startup. |
| 854 EXPECT_EQ(1, test_loader_->num_loads()); | 854 EXPECT_EQ(1, test_loader_->num_loads()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; | 897 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; |
| 898 content_handler_loader->set_create_content_handler(true); | 898 content_handler_loader->set_create_content_handler(true); |
| 899 content_handler_loader->set_context(&test_context); | 899 content_handler_loader->set_context(&test_context); |
| 900 application_manager.SetLoaderForURL( | 900 application_manager.SetLoaderForURL( |
| 901 scoped_ptr<ApplicationLoader>(content_handler_loader), | 901 scoped_ptr<ApplicationLoader>(content_handler_loader), |
| 902 content_handler_url); | 902 content_handler_url); |
| 903 | 903 |
| 904 uint32_t content_handler_id; | 904 uint32_t content_handler_id; |
| 905 { | 905 { |
| 906 base::RunLoop run_loop; | 906 base::RunLoop run_loop; |
| 907 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 907 scoped_ptr<ConnectToApplicationParams> params( |
| 908 request->url = mojo::String::From("test:test"); | 908 new ConnectToApplicationParams); |
| 909 application_manager.ConnectToApplication( | 909 params->set_originator_identity(Identity(requestor_url)); |
| 910 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr, | 910 params->set_originator_filter(GetPermissiveCapabilityFilter()); |
| 911 GetPermissiveCapabilityFilter(), base::Closure(), | 911 params->SetURLInfo(GURL("test:test")); |
| 912 [&content_handler_id, &run_loop](uint32_t t) { | 912 params->set_filter(GetPermissiveCapabilityFilter()); |
| 913 content_handler_id = t; | 913 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { |
| 914 run_loop.Quit(); | 914 content_handler_id = t; |
| 915 }); | 915 run_loop.Quit(); |
| 916 }); |
| 917 application_manager.ConnectToApplication(params.Pass()); |
| 916 run_loop.Run(); | 918 run_loop.Run(); |
| 917 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); | 919 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); |
| 918 } | 920 } |
| 919 | 921 |
| 920 uint32_t content_handler_id2; | 922 uint32_t content_handler_id2; |
| 921 { | 923 { |
| 922 base::RunLoop run_loop; | 924 base::RunLoop run_loop; |
| 923 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 925 scoped_ptr<ConnectToApplicationParams> params( |
| 924 request->url = mojo::String::From("test:test"); | 926 new ConnectToApplicationParams); |
| 925 application_manager.ConnectToApplication( | 927 params->set_originator_identity(Identity(requestor_url)); |
| 926 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr, | 928 params->set_originator_filter(GetPermissiveCapabilityFilter()); |
| 927 GetPermissiveCapabilityFilter(), base::Closure(), | 929 params->SetURLInfo(GURL("test:test")); |
| 928 [&content_handler_id2, &run_loop](uint32_t t) { | 930 params->set_filter(GetPermissiveCapabilityFilter()); |
| 929 content_handler_id2 = t; | 931 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { |
| 930 run_loop.Quit(); | 932 content_handler_id2 = t; |
| 931 }); | 933 run_loop.Quit(); |
| 934 }); |
| 935 application_manager.ConnectToApplication(params.Pass()); |
| 932 run_loop.Run(); | 936 run_loop.Run(); |
| 933 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); | 937 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); |
| 934 } | 938 } |
| 935 EXPECT_EQ(content_handler_id, content_handler_id2); | 939 EXPECT_EQ(content_handler_id, content_handler_id2); |
| 936 } | 940 } |
| 937 | 941 |
| 938 TEST(ApplicationManagerTest2, DifferedContentHandlersGetDifferentIDs) { | 942 TEST(ApplicationManagerTest2, DifferedContentHandlersGetDifferentIDs) { |
| 939 base::MessageLoop loop; | 943 base::MessageLoop loop; |
| 940 const GURL content_handler_url("http://test.content.handler"); | 944 const GURL content_handler_url("http://test.content.handler"); |
| 941 const GURL requestor_url("http://requestor.url"); | 945 const GURL requestor_url("http://requestor.url"); |
| 942 TestContext test_context; | 946 TestContext test_context; |
| 943 TestDelegate test_delegate; | 947 TestDelegate test_delegate; |
| 944 test_delegate.set_fetcher_url(GURL("test:test")); | 948 test_delegate.set_fetcher_url(GURL("test:test")); |
| 945 test_delegate.set_create_test_fetcher(true); | 949 test_delegate.set_create_test_fetcher(true); |
| 946 ApplicationManager application_manager(&test_delegate); | 950 ApplicationManager application_manager(&test_delegate); |
| 947 application_manager.set_default_loader(nullptr); | 951 application_manager.set_default_loader(nullptr); |
| 948 application_manager.RegisterContentHandler(kTestMimeType, | 952 application_manager.RegisterContentHandler(kTestMimeType, |
| 949 content_handler_url); | 953 content_handler_url); |
| 950 | 954 |
| 951 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; | 955 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; |
| 952 content_handler_loader->set_create_content_handler(true); | 956 content_handler_loader->set_create_content_handler(true); |
| 953 content_handler_loader->set_context(&test_context); | 957 content_handler_loader->set_context(&test_context); |
| 954 application_manager.SetLoaderForURL( | 958 application_manager.SetLoaderForURL( |
| 955 scoped_ptr<ApplicationLoader>(content_handler_loader), | 959 scoped_ptr<ApplicationLoader>(content_handler_loader), |
| 956 content_handler_url); | 960 content_handler_url); |
| 957 | 961 |
| 958 uint32_t content_handler_id; | 962 uint32_t content_handler_id; |
| 959 { | 963 { |
| 960 base::RunLoop run_loop; | 964 base::RunLoop run_loop; |
| 961 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 965 scoped_ptr<ConnectToApplicationParams> params( |
| 962 request->url = mojo::String::From("test:test"); | 966 new ConnectToApplicationParams); |
| 963 application_manager.ConnectToApplication( | 967 params->set_originator_identity(Identity(requestor_url)); |
| 964 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr, | 968 params->set_originator_filter(GetPermissiveCapabilityFilter()); |
| 965 GetPermissiveCapabilityFilter(), base::Closure(), | 969 params->SetURLInfo(GURL("test:test")); |
| 966 [&content_handler_id, &run_loop](uint32_t t) { | 970 params->set_filter(GetPermissiveCapabilityFilter()); |
| 967 content_handler_id = t; | 971 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { |
| 968 run_loop.Quit(); | 972 content_handler_id = t; |
| 969 }); | 973 run_loop.Quit(); |
| 974 }); |
| 975 application_manager.ConnectToApplication(params.Pass()); |
| 970 run_loop.Run(); | 976 run_loop.Run(); |
| 971 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); | 977 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); |
| 972 } | 978 } |
| 973 | 979 |
| 974 const std::string mime_type2("test/mime-type2"); | 980 const std::string mime_type2("test/mime-type2"); |
| 975 const GURL content_handler_url2("http://test.content2.handler"); | 981 const GURL content_handler_url2("http://test.content2.handler"); |
| 976 test_delegate.set_fetcher_url(GURL("test2:test2")); | 982 test_delegate.set_fetcher_url(GURL("test2:test2")); |
| 977 test_delegate.set_mime_type(mime_type2); | 983 test_delegate.set_mime_type(mime_type2); |
| 978 application_manager.RegisterContentHandler(mime_type2, content_handler_url2); | 984 application_manager.RegisterContentHandler(mime_type2, content_handler_url2); |
| 979 | 985 |
| 980 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; | 986 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; |
| 981 content_handler_loader->set_create_content_handler(true); | 987 content_handler_loader->set_create_content_handler(true); |
| 982 content_handler_loader->set_context(&test_context); | 988 content_handler_loader->set_context(&test_context); |
| 983 application_manager.SetLoaderForURL( | 989 application_manager.SetLoaderForURL( |
| 984 scoped_ptr<ApplicationLoader>(content_handler_loader2), | 990 scoped_ptr<ApplicationLoader>(content_handler_loader2), |
| 985 content_handler_url2); | 991 content_handler_url2); |
| 986 | 992 |
| 987 uint32_t content_handler_id2; | 993 uint32_t content_handler_id2; |
| 988 { | 994 { |
| 989 base::RunLoop run_loop; | 995 base::RunLoop run_loop; |
| 990 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 996 scoped_ptr<ConnectToApplicationParams> params( |
| 991 request->url = mojo::String::From("test2:test2"); | 997 new ConnectToApplicationParams); |
| 992 application_manager.ConnectToApplication( | 998 params->set_originator_identity(Identity(requestor_url)); |
| 993 nullptr, request.Pass(), std::string(), requestor_url, nullptr, nullptr, | 999 params->set_originator_filter(GetPermissiveCapabilityFilter()); |
| 994 GetPermissiveCapabilityFilter(), base::Closure(), | 1000 params->SetURLInfo(GURL("test2:test2")); |
| 995 [&content_handler_id2, &run_loop](uint32_t t) { | 1001 params->set_filter(GetPermissiveCapabilityFilter()); |
| 996 content_handler_id2 = t; | 1002 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { |
| 997 run_loop.Quit(); | 1003 content_handler_id2 = t; |
| 998 }); | 1004 run_loop.Quit(); |
| 1005 }); |
| 1006 application_manager.ConnectToApplication(params.Pass()); |
| 999 run_loop.Run(); | 1007 run_loop.Run(); |
| 1000 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); | 1008 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); |
| 1001 } | 1009 } |
| 1002 EXPECT_NE(content_handler_id, content_handler_id2); | 1010 EXPECT_NE(content_handler_id, content_handler_id2); |
| 1003 } | 1011 } |
| 1004 | 1012 |
| 1005 TEST_F(ApplicationManagerTest, | 1013 TEST_F(ApplicationManagerTest, |
| 1006 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { | 1014 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { |
| 1007 application_manager_->SetLoaderForScheme( | 1015 application_manager_->SetLoaderForScheme( |
| 1008 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), "test"); | 1016 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), "test"); |
| 1009 | 1017 |
| 1010 uint32_t content_handler_id = 1u; | 1018 uint32_t content_handler_id = 1u; |
| 1011 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 1019 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 1012 request->url = mojo::String::From("test:test"); | 1020 params->SetURLInfo(GURL("test:test")); |
| 1013 application_manager_->ConnectToApplication( | 1021 params->set_filter(GetPermissiveCapabilityFilter()); |
| 1014 nullptr, request.Pass(), std::string(), GURL(), nullptr, nullptr, | 1022 params->set_connect_callback( |
| 1015 GetPermissiveCapabilityFilter(), base::Closure(), | |
| 1016 [&content_handler_id](uint32_t t) { content_handler_id = t; }); | 1023 [&content_handler_id](uint32_t t) { content_handler_id = t; }); |
| 1024 application_manager_->ConnectToApplication(params.Pass()); |
| 1017 EXPECT_EQ(0u, content_handler_id); | 1025 EXPECT_EQ(0u, content_handler_id); |
| 1018 } | 1026 } |
| 1019 | 1027 |
| 1020 } // namespace | 1028 } // namespace |
| 1021 } // namespace shell | 1029 } // namespace shell |
| 1022 } // namespace mojo | 1030 } // namespace mojo |
| OLD | NEW |