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 "mojo/public/bindings/allocation_scope.h" | 5 #include "mojo/public/bindings/allocation_scope.h" |
6 #include "mojo/public/bindings/remote_ptr.h" | 6 #include "mojo/public/bindings/remote_ptr.h" |
7 #include "mojo/public/environment/environment.h" | 7 #include "mojo/public/environment/environment.h" |
8 #include "mojo/public/shell/application.h" | 8 #include "mojo/public/shell/application.h" |
9 #include "mojo/public/utility/run_loop.h" | 9 #include "mojo/public/utility/run_loop.h" |
10 #include "mojo/shell/service_connector.h" | 10 #include "mojo/shell/service_manager.h" |
11 #include "mojom/shell.h" | 11 #include "mojom/shell.h" |
12 #include "mojom/test.h" | 12 #include "mojom/test.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace shell { | 16 namespace shell { |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char kTestURLString[] = "test:testService"; | 19 const char kTestURLString[] = "test:testService"; |
20 | 20 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 service_->Test(mojo::String(test_string)); | 66 service_->Test(mojo::String(test_string)); |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 RemotePtr<TestService> service_; | 70 RemotePtr<TestService> service_; |
71 bool quit_after_ack_; | 71 bool quit_after_ack_; |
72 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); | 72 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); |
73 }; | 73 }; |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 class ServiceConnectorTest : public testing::Test, | 76 class ServiceManagerTest : public testing::Test, |
77 public ServiceConnector::Loader { | 77 public ServiceManager::Loader { |
78 public: | 78 public: |
79 ServiceConnectorTest() {} | 79 ServiceManagerTest() {} |
80 | 80 |
81 virtual ~ServiceConnectorTest() {} | 81 virtual ~ServiceManagerTest() {} |
82 | 82 |
83 virtual void SetUp() OVERRIDE { | 83 virtual void SetUp() OVERRIDE { |
84 GURL test_url(kTestURLString); | 84 GURL test_url(kTestURLString); |
85 service_connector_.reset(new ServiceConnector); | 85 service_manager_.reset(new ServiceManager); |
86 service_connector_->SetLoaderForURL(this, test_url); | 86 service_manager_->SetLoaderForURL(this, test_url); |
87 | 87 |
88 InterfacePipe<TestService, AnyInterface> pipe; | 88 InterfacePipe<TestService, AnyInterface> pipe; |
89 test_client_.reset(new TestClientImpl(pipe.handle_to_self.Pass())); | 89 test_client_.reset(new TestClientImpl(pipe.handle_to_self.Pass())); |
90 service_connector_->Connect(test_url, pipe.handle_to_peer.Pass()); | 90 service_manager_->Connect(test_url, pipe.handle_to_peer.Pass()); |
91 } | 91 } |
92 | 92 |
93 virtual void TearDown() OVERRIDE { | 93 virtual void TearDown() OVERRIDE { |
94 test_client_.reset(NULL); | 94 test_client_.reset(NULL); |
95 test_app_.reset(NULL); | 95 test_app_.reset(NULL); |
96 service_connector_.reset(NULL); | 96 service_manager_.reset(NULL); |
97 } | 97 } |
98 | 98 |
99 virtual void Load(const GURL& url, | 99 virtual void Load(const GURL& url, |
100 ScopedShellHandle shell_handle) OVERRIDE { | 100 ScopedShellHandle shell_handle) OVERRIDE { |
101 test_app_.reset(new Application(shell_handle.Pass())); | 101 test_app_.reset(new Application(shell_handle.Pass())); |
102 test_app_->AddServiceFactory( | 102 test_app_->AddServiceFactory( |
103 new ServiceFactory<TestServiceImpl, TestContext>(&context_)); | 103 new ServiceFactory<TestServiceImpl, TestContext>(&context_)); |
104 } | 104 } |
105 | 105 |
106 bool HasFactoryForTestURL() { | 106 bool HasFactoryForTestURL() { |
107 ServiceConnector::TestAPI connector_test_api(service_connector_.get()); | 107 ServiceManager::TestAPI manager_test_api(service_manager_.get()); |
108 return connector_test_api.HasFactoryForURL(GURL(kTestURLString)); | 108 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); |
109 } | 109 } |
110 | 110 |
111 protected: | 111 protected: |
112 mojo::Environment env_; | 112 mojo::Environment env_; |
113 mojo::RunLoop loop_; | 113 mojo::RunLoop loop_; |
114 TestContext context_; | 114 TestContext context_; |
115 scoped_ptr<Application> test_app_; | 115 scoped_ptr<Application> test_app_; |
116 scoped_ptr<TestClientImpl> test_client_; | 116 scoped_ptr<TestClientImpl> test_client_; |
117 scoped_ptr<ServiceConnector> service_connector_; | 117 scoped_ptr<ServiceManager> service_manager_; |
118 DISALLOW_COPY_AND_ASSIGN(ServiceConnectorTest); | 118 DISALLOW_COPY_AND_ASSIGN(ServiceManagerTest); |
119 }; | 119 }; |
120 | 120 |
121 TEST_F(ServiceConnectorTest, Basic) { | 121 TEST_F(ServiceManagerTest, Basic) { |
122 test_client_->Test("test"); | 122 test_client_->Test("test"); |
123 loop_.Run(); | 123 loop_.Run(); |
124 EXPECT_EQ(std::string("test"), context_.last_test_string); | 124 EXPECT_EQ(std::string("test"), context_.last_test_string); |
125 } | 125 } |
126 | 126 |
127 TEST_F(ServiceConnectorTest, ClientError) { | 127 TEST_F(ServiceManagerTest, ClientError) { |
128 test_client_->Test("test"); | 128 test_client_->Test("test"); |
129 EXPECT_TRUE(HasFactoryForTestURL()); | 129 EXPECT_TRUE(HasFactoryForTestURL()); |
130 loop_.Run(); | 130 loop_.Run(); |
131 EXPECT_EQ(1, context_.num_impls); | 131 EXPECT_EQ(1, context_.num_impls); |
132 test_client_.reset(NULL); | 132 test_client_.reset(NULL); |
133 loop_.Run(); | 133 loop_.Run(); |
134 EXPECT_EQ(0, context_.num_impls); | 134 EXPECT_EQ(0, context_.num_impls); |
135 EXPECT_FALSE(HasFactoryForTestURL()); | 135 EXPECT_FALSE(HasFactoryForTestURL()); |
136 } | 136 } |
137 } // namespace shell | 137 } // namespace shell |
138 } // namespace mojo | 138 } // namespace mojo |
OLD | NEW |