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 "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 std::string last_test_string; | 39 std::string last_test_string; |
40 int num_impls; | 40 int num_impls; |
41 int num_loader_deletes; | 41 int num_loader_deletes; |
42 }; | 42 }; |
43 | 43 |
44 void QuitClosure(bool* value) { | 44 void QuitClosure(bool* value) { |
45 *value = true; | 45 *value = true; |
46 base::MessageLoop::current()->QuitWhenIdle(); | 46 base::MessageLoop::current()->QuitWhenIdle(); |
47 } | 47 } |
48 | 48 |
49 class QuitMessageLoopErrorHandler : public mojo::ErrorHandler { | |
50 public: | |
51 QuitMessageLoopErrorHandler() {} | |
52 ~QuitMessageLoopErrorHandler() override {} | |
53 | |
54 // |mojo::ErrorHandler| implementation: | |
55 void OnConnectionError() override { | |
56 base::MessageLoop::current()->QuitWhenIdle(); | |
57 } | |
58 | |
59 private: | |
60 DISALLOW_COPY_AND_ASSIGN(QuitMessageLoopErrorHandler); | |
61 }; | |
62 | |
63 class TestServiceImpl : public TestService { | 49 class TestServiceImpl : public TestService { |
64 public: | 50 public: |
65 TestServiceImpl(TestContext* context, InterfaceRequest<TestService> request) | 51 TestServiceImpl(TestContext* context, InterfaceRequest<TestService> request) |
66 : context_(context), binding_(this, request.Pass()) { | 52 : context_(context), binding_(this, request.Pass()) { |
67 ++context_->num_impls; | 53 ++context_->num_impls; |
68 } | 54 } |
69 | 55 |
70 ~TestServiceImpl() override { | 56 ~TestServiceImpl() override { |
71 --context_->num_impls; | 57 --context_->num_impls; |
72 if (!base::MessageLoop::current()->is_running()) | 58 if (!base::MessageLoop::current()->is_running()) |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 EXPECT_TRUE(tester_context_.tester_called_quit()); | 720 EXPECT_TRUE(tester_context_.tester_called_quit()); |
735 } | 721 } |
736 | 722 |
737 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { | 723 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { |
738 AddLoaderForURL(GURL(kTestAURLString), std::string()); | 724 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
739 | 725 |
740 // There is no TestC service implementation registered with | 726 // There is no TestC service implementation registered with |
741 // ApplicationManager, so this cannot succeed (but also shouldn't crash). | 727 // ApplicationManager, so this cannot succeed (but also shouldn't crash). |
742 TestCPtr c; | 728 TestCPtr c; |
743 application_manager_->ConnectToService(GURL(kTestAURLString), &c); | 729 application_manager_->ConnectToService(GURL(kTestAURLString), &c); |
744 QuitMessageLoopErrorHandler quitter; | 730 c.set_connection_error_handler( |
745 c.set_error_handler(&quitter); | 731 []() { base::MessageLoop::current()->QuitWhenIdle(); }); |
746 | 732 |
747 loop_.Run(); | 733 loop_.Run(); |
748 EXPECT_TRUE(c.encountered_error()); | 734 EXPECT_TRUE(c.encountered_error()); |
749 } | 735 } |
750 | 736 |
751 TEST_F(ApplicationManagerTest, MappedURLsShouldNotCauseDuplicateLoad) { | 737 TEST_F(ApplicationManagerTest, MappedURLsShouldNotCauseDuplicateLoad) { |
752 test_delegate_.AddMapping(GURL("foo:foo2"), GURL("foo:foo")); | 738 test_delegate_.AddMapping(GURL("foo:foo2"), GURL("foo:foo")); |
753 // 1 because ApplicationManagerTest connects once at startup. | 739 // 1 because ApplicationManagerTest connects once at startup. |
754 EXPECT_EQ(1, test_loader_->num_loads()); | 740 EXPECT_EQ(1, test_loader_->num_loads()); |
755 | 741 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 bool called = false; | 796 bool called = false; |
811 application_manager_->ConnectToApplication( | 797 application_manager_->ConnectToApplication( |
812 GURL("test:test"), GURL(), nullptr, nullptr, | 798 GURL("test:test"), GURL(), nullptr, nullptr, |
813 base::Bind(&QuitClosure, base::Unretained(&called))); | 799 base::Bind(&QuitClosure, base::Unretained(&called))); |
814 loop_.Run(); | 800 loop_.Run(); |
815 EXPECT_TRUE(called); | 801 EXPECT_TRUE(called); |
816 } | 802 } |
817 | 803 |
818 } // namespace | 804 } // namespace |
819 } // namespace shell | 805 } // namespace shell |
OLD | NEW |