| 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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 563 |
| 564 TEST_F(ApplicationManagerTest, Deletes) { | 564 TEST_F(ApplicationManagerTest, Deletes) { |
| 565 { | 565 { |
| 566 ApplicationManager am(make_scoped_ptr(new TestApplicationFetcher)); | 566 ApplicationManager am(make_scoped_ptr(new TestApplicationFetcher)); |
| 567 TestApplicationLoader* default_loader = new TestApplicationLoader; | 567 TestApplicationLoader* default_loader = new TestApplicationLoader; |
| 568 default_loader->set_context(&context_); | 568 default_loader->set_context(&context_); |
| 569 TestApplicationLoader* url_loader1 = new TestApplicationLoader; | 569 TestApplicationLoader* url_loader1 = new TestApplicationLoader; |
| 570 TestApplicationLoader* url_loader2 = new TestApplicationLoader; | 570 TestApplicationLoader* url_loader2 = new TestApplicationLoader; |
| 571 url_loader1->set_context(&context_); | 571 url_loader1->set_context(&context_); |
| 572 url_loader2->set_context(&context_); | 572 url_loader2->set_context(&context_); |
| 573 TestApplicationLoader* scheme_loader1 = new TestApplicationLoader; | |
| 574 TestApplicationLoader* scheme_loader2 = new TestApplicationLoader; | |
| 575 scheme_loader1->set_context(&context_); | |
| 576 scheme_loader2->set_context(&context_); | |
| 577 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); | 573 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); |
| 578 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), | 574 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), |
| 579 GURL("test:test1")); | 575 GURL("test:test1")); |
| 580 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), | 576 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), |
| 581 GURL("test:test1")); | 577 GURL("test:test1")); |
| 582 am.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader1), | |
| 583 "test"); | |
| 584 am.SetLoaderForScheme(scoped_ptr<ApplicationLoader>(scheme_loader2), | |
| 585 "test"); | |
| 586 } | 578 } |
| 587 EXPECT_EQ(5, context_.num_loader_deletes); | 579 EXPECT_EQ(3, context_.num_loader_deletes); |
| 588 } | 580 } |
| 589 | 581 |
| 590 // Confirm that both urls and schemes can have their loaders explicitly set. | 582 // Test for SetLoaderForURL() & set_default_loader(). |
| 591 TEST_F(ApplicationManagerTest, SetLoaders) { | 583 TEST_F(ApplicationManagerTest, SetLoaders) { |
| 592 TestApplicationLoader* default_loader = new TestApplicationLoader; | 584 TestApplicationLoader* default_loader = new TestApplicationLoader; |
| 593 TestApplicationLoader* url_loader = new TestApplicationLoader; | 585 TestApplicationLoader* url_loader = new TestApplicationLoader; |
| 594 TestApplicationLoader* scheme_loader = new TestApplicationLoader; | |
| 595 application_manager_->set_default_loader( | 586 application_manager_->set_default_loader( |
| 596 scoped_ptr<ApplicationLoader>(default_loader)); | 587 scoped_ptr<ApplicationLoader>(default_loader)); |
| 597 application_manager_->SetLoaderForURL( | 588 application_manager_->SetLoaderForURL( |
| 598 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); | 589 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); |
| 599 application_manager_->SetLoaderForScheme( | |
| 600 scoped_ptr<ApplicationLoader>(scheme_loader), "test"); | |
| 601 | 590 |
| 602 // test::test1 should go to url_loader. | 591 // test::test1 should go to url_loader. |
| 603 TestServicePtr test_service; | 592 TestServicePtr test_service; |
| 604 application_manager_->ConnectToService(GURL("test:test1"), &test_service); | 593 application_manager_->ConnectToService(GURL("test:test1"), &test_service); |
| 605 EXPECT_EQ(1, url_loader->num_loads()); | 594 EXPECT_EQ(1, url_loader->num_loads()); |
| 606 EXPECT_EQ(0, scheme_loader->num_loads()); | |
| 607 EXPECT_EQ(0, default_loader->num_loads()); | |
| 608 | |
| 609 // test::test2 should go to scheme loader. | |
| 610 application_manager_->ConnectToService(GURL("test:test2"), &test_service); | |
| 611 EXPECT_EQ(1, url_loader->num_loads()); | |
| 612 EXPECT_EQ(1, scheme_loader->num_loads()); | |
| 613 EXPECT_EQ(0, default_loader->num_loads()); | 595 EXPECT_EQ(0, default_loader->num_loads()); |
| 614 | 596 |
| 615 // http::test1 should go to default loader. | 597 // http::test1 should go to default loader. |
| 616 application_manager_->ConnectToService(GURL("http:test1"), &test_service); | 598 application_manager_->ConnectToService(GURL("http:test1"), &test_service); |
| 617 EXPECT_EQ(1, url_loader->num_loads()); | 599 EXPECT_EQ(1, url_loader->num_loads()); |
| 618 EXPECT_EQ(1, scheme_loader->num_loads()); | |
| 619 EXPECT_EQ(1, default_loader->num_loads()); | 600 EXPECT_EQ(1, default_loader->num_loads()); |
| 620 } | 601 } |
| 621 | 602 |
| 622 // Confirm that the url of a service is correctly passed to another service that | 603 // Confirm that the url of a service is correctly passed to another service that |
| 623 // it loads. | 604 // it loads. |
| 624 TEST_F(ApplicationManagerTest, ACallB) { | 605 TEST_F(ApplicationManagerTest, ACallB) { |
| 625 // Any url can load a. | 606 // Any url can load a. |
| 626 AddLoaderForURL(GURL(kTestAURLString), std::string()); | 607 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
| 627 | 608 |
| 628 // Only a can load b. | 609 // Only a can load b. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 // ApplicationManager, so this cannot succeed (but also shouldn't crash). | 681 // ApplicationManager, so this cannot succeed (but also shouldn't crash). |
| 701 TestCPtr c; | 682 TestCPtr c; |
| 702 application_manager_->ConnectToService(GURL(kTestAURLString), &c); | 683 application_manager_->ConnectToService(GURL(kTestAURLString), &c); |
| 703 c.set_connection_error_handler( | 684 c.set_connection_error_handler( |
| 704 []() { base::MessageLoop::current()->QuitWhenIdle(); }); | 685 []() { base::MessageLoop::current()->QuitWhenIdle(); }); |
| 705 | 686 |
| 706 loop_.Run(); | 687 loop_.Run(); |
| 707 EXPECT_TRUE(c.encountered_error()); | 688 EXPECT_TRUE(c.encountered_error()); |
| 708 } | 689 } |
| 709 | 690 |
| 710 TEST_F(ApplicationManagerTest, TestQueryWithLoaders) { | |
| 711 TestApplicationLoader* url_loader = new TestApplicationLoader; | |
| 712 TestApplicationLoader* scheme_loader = new TestApplicationLoader; | |
| 713 application_manager_->SetLoaderForURL( | |
| 714 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); | |
| 715 application_manager_->SetLoaderForScheme( | |
| 716 scoped_ptr<ApplicationLoader>(scheme_loader), "test"); | |
| 717 | |
| 718 // test::test1 should go to url_loader. | |
| 719 TestServicePtr test_service; | |
| 720 application_manager_->ConnectToService(GURL("test:test1?foo=bar"), | |
| 721 &test_service); | |
| 722 EXPECT_EQ(1, url_loader->num_loads()); | |
| 723 EXPECT_EQ(0, scheme_loader->num_loads()); | |
| 724 | |
| 725 // test::test2 should go to scheme loader. | |
| 726 application_manager_->ConnectToService(GURL("test:test2?foo=bar"), | |
| 727 &test_service); | |
| 728 EXPECT_EQ(1, url_loader->num_loads()); | |
| 729 EXPECT_EQ(1, scheme_loader->num_loads()); | |
| 730 } | |
| 731 | |
| 732 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { | 691 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { |
| 733 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); | 692 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); |
| 734 application_manager_->SetLoaderForScheme( | 693 application_manager_->SetLoaderForURL( |
| 735 scoped_ptr<ApplicationLoader>(loader), "test"); | 694 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); |
| 736 | 695 |
| 737 bool called = false; | 696 bool called = false; |
| 738 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 697 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 739 params->SetURLInfo(GURL("test:test")); | 698 params->SetURLInfo(GURL("test:test")); |
| 740 params->set_filter(GetPermissiveCapabilityFilter()); | 699 params->set_filter(GetPermissiveCapabilityFilter()); |
| 741 params->set_on_application_end( | 700 params->set_on_application_end( |
| 742 base::Bind(&QuitClosure, base::Unretained(&called))); | 701 base::Bind(&QuitClosure, base::Unretained(&called))); |
| 743 application_manager_->ConnectToApplication(params.Pass()); | 702 application_manager_->ConnectToApplication(params.Pass()); |
| 744 loop_.Run(); | 703 loop_.Run(); |
| 745 EXPECT_TRUE(called); | 704 EXPECT_TRUE(called); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 }); | 896 }); |
| 938 application_manager.ConnectToApplication(params.Pass()); | 897 application_manager.ConnectToApplication(params.Pass()); |
| 939 run_loop.Run(); | 898 run_loop.Run(); |
| 940 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); | 899 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); |
| 941 } | 900 } |
| 942 EXPECT_NE(content_handler_id, content_handler_id2); | 901 EXPECT_NE(content_handler_id, content_handler_id2); |
| 943 } | 902 } |
| 944 | 903 |
| 945 TEST_F(ApplicationManagerTest, | 904 TEST_F(ApplicationManagerTest, |
| 946 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { | 905 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { |
| 947 application_manager_->SetLoaderForScheme( | 906 application_manager_->SetLoaderForURL( |
| 948 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), "test"); | 907 scoped_ptr<ApplicationLoader>(new TestApplicationLoader), |
| 908 GURL("test:test")); |
| 949 | 909 |
| 950 uint32_t content_handler_id = 1u; | 910 uint32_t content_handler_id = 1u; |
| 951 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 911 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 952 params->SetURLInfo(GURL("test:test")); | 912 params->SetURLInfo(GURL("test:test")); |
| 953 params->set_filter(GetPermissiveCapabilityFilter()); | 913 params->set_filter(GetPermissiveCapabilityFilter()); |
| 954 params->set_connect_callback( | 914 params->set_connect_callback( |
| 955 [&content_handler_id](uint32_t t) { content_handler_id = t; }); | 915 [&content_handler_id](uint32_t t) { content_handler_id = t; }); |
| 956 application_manager_->ConnectToApplication(params.Pass()); | 916 application_manager_->ConnectToApplication(params.Pass()); |
| 957 EXPECT_EQ(0u, content_handler_id); | 917 EXPECT_EQ(0u, content_handler_id); |
| 958 } | 918 } |
| 959 | 919 |
| 960 } // namespace | 920 } // namespace |
| 961 } // namespace shell | 921 } // namespace shell |
| 962 } // namespace mojo | 922 } // namespace mojo |
| OLD | NEW |