Chromium Code Reviews| 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "mojo/public/cpp/bindings/allocation_scope.h" | 6 #include "mojo/public/cpp/bindings/allocation_scope.h" |
| 7 #include "mojo/public/cpp/bindings/remote_ptr.h" | 7 #include "mojo/public/cpp/bindings/remote_ptr.h" |
| 8 #include "mojo/public/cpp/environment/environment.h" | 8 #include "mojo/public/cpp/environment/environment.h" |
| 9 #include "mojo/public/cpp/shell/application.h" | 9 #include "mojo/public/cpp/shell/application.h" |
| 10 #include "mojo/public/interfaces/shell/shell.mojom.h" | 10 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 ScopedShellHandle service_handle) OVERRIDE { | 135 ScopedShellHandle service_handle) OVERRIDE { |
| 136 ++num_loads_; | 136 ++num_loads_; |
| 137 } | 137 } |
| 138 virtual void OnServiceError(ServiceManager* manager, const GURL& url) | 138 virtual void OnServiceError(ServiceManager* manager, const GURL& url) |
| 139 OVERRIDE {} | 139 OVERRIDE {} |
| 140 | 140 |
| 141 int num_loads_; | 141 int num_loads_; |
| 142 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader); | 142 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader); |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 class TestServiceInterceptor : public ServiceManager::Interceptor { | |
| 146 public: | |
| 147 TestServiceInterceptor() : count_(0) {} | |
| 148 | |
| 149 virtual ScopedMessagePipeHandle OnConnectToClient( | |
| 150 const GURL& url, ScopedMessagePipeHandle handle) OVERRIDE { | |
| 151 ++count_; | |
| 152 url_ = url; | |
| 153 return handle.Pass(); | |
| 154 } | |
| 155 | |
| 156 std::string url_spec() const { | |
| 157 if (!url_.is_valid()) | |
| 158 return "invalid url"; | |
| 159 return url_.spec(); | |
| 160 } | |
| 161 | |
| 162 int call_count() const { | |
| 163 return count_; | |
| 164 } | |
| 165 | |
| 166 private: | |
| 167 int count_; | |
|
viettrungluu
2014/04/11 00:23:49
-> call_count_, since your accessor is called call
| |
| 168 GURL url_; | |
| 169 }; | |
|
viettrungluu
2014/04/11 00:23:49
DISALLOW_COPY_AND_ASSIGN?
| |
| 170 | |
| 145 TEST_F(ServiceManagerTest, Basic) { | 171 TEST_F(ServiceManagerTest, Basic) { |
| 146 test_client_->Test("test"); | 172 test_client_->Test("test"); |
| 147 loop_.Run(); | 173 loop_.Run(); |
| 148 EXPECT_EQ(std::string("test"), context_.last_test_string); | 174 EXPECT_EQ(std::string("test"), context_.last_test_string); |
| 149 } | 175 } |
| 150 | 176 |
| 151 TEST_F(ServiceManagerTest, ClientError) { | 177 TEST_F(ServiceManagerTest, ClientError) { |
| 152 test_client_->Test("test"); | 178 test_client_->Test("test"); |
| 153 EXPECT_TRUE(HasFactoryForTestURL()); | 179 EXPECT_TRUE(HasFactoryForTestURL()); |
| 154 loop_.Run(); | 180 loop_.Run(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 184 EXPECT_EQ(0, default_loader.num_loads()); | 210 EXPECT_EQ(0, default_loader.num_loads()); |
| 185 | 211 |
| 186 // http::test1 should go to default loader. | 212 // http::test1 should go to default loader. |
| 187 InterfacePipe<TestService, AnyInterface> pipe3; | 213 InterfacePipe<TestService, AnyInterface> pipe3; |
| 188 sm.Connect(GURL("http:test1"), pipe3.handle_to_peer.Pass()); | 214 sm.Connect(GURL("http:test1"), pipe3.handle_to_peer.Pass()); |
| 189 EXPECT_EQ(1, url_loader.num_loads()); | 215 EXPECT_EQ(1, url_loader.num_loads()); |
| 190 EXPECT_EQ(1, scheme_loader.num_loads()); | 216 EXPECT_EQ(1, scheme_loader.num_loads()); |
| 191 EXPECT_EQ(1, default_loader.num_loads()); | 217 EXPECT_EQ(1, default_loader.num_loads()); |
| 192 } | 218 } |
| 193 | 219 |
| 220 TEST_F(ServiceManagerTest, Interceptor) { | |
| 221 ServiceManager sm; | |
| 222 TestServiceLoader default_loader; | |
| 223 TestServiceInterceptor interceptor; | |
| 224 sm.set_default_loader(&default_loader); | |
| 225 sm.SetInterceptor(&interceptor); | |
| 226 | |
| 227 std::string url("test:test3"); | |
| 228 InterfacePipe<TestService, AnyInterface> pipe1; | |
| 229 sm.Connect(GURL(url), pipe1.handle_to_peer.Pass()); | |
| 230 EXPECT_EQ(1, interceptor.call_count()); | |
| 231 EXPECT_EQ(url, interceptor.url_spec()); | |
| 232 EXPECT_EQ(1, default_loader.num_loads()); | |
| 233 } | |
|
viettrungluu
2014/04/11 00:23:49
Maybe you should try a second call too?
| |
| 234 | |
| 194 } // namespace mojo | 235 } // namespace mojo |
| OLD | NEW |