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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "mojo/public/cpp/application/application_connection.h" | 8 #include "mojo/public/cpp/application/application_connection.h" |
9 #include "mojo/public/cpp/application/application_delegate.h" | 9 #include "mojo/public/cpp/application/application_delegate.h" |
10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 service_manager_->ConnectToService(GURL(kTestAURLString), &a); | 611 service_manager_->ConnectToService(GURL(kTestAURLString), &a); |
612 a->CallB(); | 612 a->CallB(); |
613 loop_.Run(); | 613 loop_.Run(); |
614 EXPECT_EQ(0, tester_context_.num_b_calls()); | 614 EXPECT_EQ(0, tester_context_.num_b_calls()); |
615 | 615 |
616 EXPECT_FALSE(tester_context_.a_called_quit()); | 616 EXPECT_FALSE(tester_context_.a_called_quit()); |
617 EXPECT_TRUE(tester_context_.tester_called_quit()); | 617 EXPECT_TRUE(tester_context_.tester_called_quit()); |
618 } | 618 } |
619 | 619 |
620 TEST_F(ServiceManagerTest, NoServiceNoLoad) { | 620 TEST_F(ServiceManagerTest, NoServiceNoLoad) { |
621 // Because we'll never successfully connect to anything here and apps are not | 621 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
622 // capable of noticing zero incoming connections and quitting, we need to use | |
623 // a quittable loader. | |
624 scoped_ptr<BackgroundShellServiceLoader> loader(MakeLoader(std::string())); | |
625 loader->set_quit_on_shutdown(); | |
626 service_manager_->SetLoaderForURL(loader.PassAs<ServiceLoader>(), | |
627 GURL(kTestAURLString)); | |
628 | |
629 | 622 |
630 // There is no TestC service implementation registered with ServiceManager, | 623 // There is no TestC service implementation registered with ServiceManager, |
631 // so this cannot succeed (but also shouldn't crash). | 624 // so this cannot succeed (but also shouldn't crash). |
632 TestCPtr c; | 625 TestCPtr c; |
633 service_manager_->ConnectToService(GURL(kTestAURLString), &c); | 626 service_manager_->ConnectToService(GURL(kTestAURLString), &c); |
634 QuitMessageLoopErrorHandler quitter; | 627 QuitMessageLoopErrorHandler quitter; |
635 c.set_error_handler(&quitter); | 628 c.set_error_handler(&quitter); |
636 | 629 |
637 loop_.Run(); | 630 loop_.Run(); |
638 EXPECT_TRUE(c.encountered_error()); | 631 EXPECT_TRUE(c.encountered_error()); |
639 } | 632 } |
640 | 633 |
641 TEST_F(ServiceManagerTest, Interceptor) { | 634 TEST_F(ServiceManagerTest, Interceptor) { |
642 TestServiceInterceptor interceptor; | 635 TestServiceInterceptor interceptor; |
643 TestServiceLoader* default_loader = new TestServiceLoader; | 636 TestServiceLoader* default_loader = new TestServiceLoader; |
644 service_manager_->set_default_loader( | 637 service_manager_->set_default_loader( |
645 scoped_ptr<ServiceLoader>(default_loader)); | 638 scoped_ptr<ServiceLoader>(default_loader)); |
646 service_manager_->SetInterceptor(&interceptor); | 639 service_manager_->SetInterceptor(&interceptor); |
647 | 640 |
648 std::string url("test:test3"); | 641 std::string url("test:test3"); |
649 TestServicePtr test_service; | 642 TestServicePtr test_service; |
650 service_manager_->ConnectToService(GURL(url), &test_service); | 643 service_manager_->ConnectToService(GURL(url), &test_service); |
651 | 644 |
652 EXPECT_EQ(1, interceptor.call_count()); | 645 EXPECT_EQ(1, interceptor.call_count()); |
653 EXPECT_EQ(url, interceptor.url_spec()); | 646 EXPECT_EQ(url, interceptor.url_spec()); |
654 EXPECT_EQ(1, default_loader->num_loads()); | 647 EXPECT_EQ(1, default_loader->num_loads()); |
655 } | 648 } |
656 | 649 |
657 } // namespace mojo | 650 } // namespace mojo |
OLD | NEW |