| 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" |
| 11 #include "mojo/public/cpp/application/interface_factory.h" | 11 #include "mojo/public/cpp/application/interface_factory.h" |
| 12 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 12 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 13 #include "mojo/service_manager/background_service_loader.h" |
| 13 #include "mojo/service_manager/service_loader.h" | 14 #include "mojo/service_manager/service_loader.h" |
| 14 #include "mojo/service_manager/service_manager.h" | 15 #include "mojo/service_manager/service_manager.h" |
| 15 #include "mojo/service_manager/test.mojom.h" | 16 #include "mojo/service_manager/test.mojom.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const char kTestURLString[] = "test:testService"; | 22 const char kTestURLString[] = "test:testService"; |
| 22 const char kTestAURLString[] = "test:TestA"; | 23 const char kTestAURLString[] = "test:TestA"; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 InterfaceRequest<TestService> request) OVERRIDE { | 142 InterfaceRequest<TestService> request) OVERRIDE { |
| 142 BindToRequest(new TestServiceImpl(context_), &request); | 143 BindToRequest(new TestServiceImpl(context_), &request); |
| 143 } | 144 } |
| 144 | 145 |
| 145 scoped_ptr<ApplicationImpl> test_app_; | 146 scoped_ptr<ApplicationImpl> test_app_; |
| 146 TestContext* context_; | 147 TestContext* context_; |
| 147 int num_loads_; | 148 int num_loads_; |
| 148 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader); | 149 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader); |
| 149 }; | 150 }; |
| 150 | 151 |
| 151 struct TesterContext { | 152 class TesterContext { |
| 152 TesterContext() | 153 public: |
| 153 : num_b_calls(0), | 154 explicit TesterContext(base::MessageLoop* loop) |
| 154 num_c_calls(0), | 155 : num_b_calls_(0), |
| 155 num_a_deletes(0), | 156 num_c_calls_(0), |
| 156 num_b_deletes(0), | 157 num_a_deletes_(0), |
| 157 num_c_deletes(0), | 158 num_b_deletes_(0), |
| 158 tester_called_quit(false), | 159 num_c_deletes_(0), |
| 159 a_called_quit(false) {} | 160 tester_called_quit_(false), |
| 160 int num_b_calls; | 161 a_called_quit_(false), |
| 161 int num_c_calls; | 162 loop_(loop) {} |
| 162 int num_a_deletes; | 163 |
| 163 int num_b_deletes; | 164 void IncrementNumBCalls() { |
| 164 int num_c_deletes; | 165 base::AutoLock lock(lock_); |
| 165 bool tester_called_quit; | 166 num_b_calls_++; |
| 166 bool a_called_quit; | 167 } |
| 168 |
| 169 void IncrementNumCCalls() { |
| 170 base::AutoLock lock(lock_); |
| 171 num_c_calls_++; |
| 172 } |
| 173 |
| 174 void IncrementNumADeletes() { |
| 175 base::AutoLock lock(lock_); |
| 176 num_a_deletes_++; |
| 177 } |
| 178 |
| 179 void IncrementNumBDeletes() { |
| 180 base::AutoLock lock(lock_); |
| 181 num_b_deletes_++; |
| 182 } |
| 183 |
| 184 void IncrementNumCDeletes() { |
| 185 base::AutoLock lock(lock_); |
| 186 num_c_deletes_++; |
| 187 } |
| 188 |
| 189 void set_tester_called_quit() { |
| 190 base::AutoLock lock(lock_); |
| 191 tester_called_quit_ = true; |
| 192 } |
| 193 |
| 194 void set_a_called_quit() { |
| 195 base::AutoLock lock(lock_); |
| 196 a_called_quit_ = true; |
| 197 } |
| 198 |
| 199 int num_b_calls() { |
| 200 base::AutoLock lock(lock_); |
| 201 return num_b_calls_; |
| 202 } |
| 203 int num_c_calls() { |
| 204 base::AutoLock lock(lock_); |
| 205 return num_c_calls_; |
| 206 } |
| 207 int num_a_deletes() { |
| 208 base::AutoLock lock(lock_); |
| 209 return num_a_deletes_; |
| 210 } |
| 211 int num_b_deletes() { |
| 212 base::AutoLock lock(lock_); |
| 213 return num_b_deletes_; |
| 214 } |
| 215 int num_c_deletes() { |
| 216 base::AutoLock lock(lock_); |
| 217 return num_c_deletes_; |
| 218 } |
| 219 bool tester_called_quit() { |
| 220 base::AutoLock lock(lock_); |
| 221 return tester_called_quit_; |
| 222 } |
| 223 bool a_called_quit() { |
| 224 base::AutoLock lock(lock_); |
| 225 return a_called_quit_; |
| 226 } |
| 227 |
| 228 void QuitSoon() { |
| 229 loop_->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 230 } |
| 231 |
| 232 private: |
| 233 // lock_ protects all members except for loop_ which must be unchanged for the |
| 234 // lifetime of this class. |
| 235 base::Lock lock_; |
| 236 int num_b_calls_; |
| 237 int num_c_calls_; |
| 238 int num_a_deletes_; |
| 239 int num_b_deletes_; |
| 240 int num_c_deletes_; |
| 241 bool tester_called_quit_; |
| 242 bool a_called_quit_; |
| 243 |
| 244 base::MessageLoop* loop_; |
| 167 }; | 245 }; |
| 168 | 246 |
| 169 // Used to test that the requestor url will be correctly passed. | 247 // Used to test that the requestor url will be correctly passed. |
| 170 class TestAImpl : public InterfaceImpl<TestA> { | 248 class TestAImpl : public InterfaceImpl<TestA> { |
| 171 public: | 249 public: |
| 172 TestAImpl(ApplicationConnection* connection, TesterContext* test_context) | 250 TestAImpl(ApplicationConnection* connection, TesterContext* test_context) |
| 173 : test_context_(test_context) { | 251 : test_context_(test_context) { |
| 174 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_); | 252 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_); |
| 175 } | 253 } |
| 176 virtual ~TestAImpl() { test_context_->num_a_deletes++; } | 254 virtual ~TestAImpl() { test_context_->IncrementNumADeletes(); } |
| 177 | 255 |
| 178 private: | 256 private: |
| 179 virtual void CallB() OVERRIDE { | 257 virtual void CallB() OVERRIDE { |
| 180 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this))); | 258 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this))); |
| 181 } | 259 } |
| 182 | 260 |
| 183 virtual void CallCFromB() OVERRIDE { | 261 virtual void CallCFromB() OVERRIDE { |
| 184 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this))); | 262 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this))); |
| 185 } | 263 } |
| 186 | 264 |
| 187 void Quit() { | 265 void Quit() { |
| 188 test_context_->a_called_quit = true; | 266 test_context_->set_a_called_quit(); |
| 189 base::MessageLoop::current()->Quit(); | 267 test_context_->QuitSoon(); |
| 190 } | 268 } |
| 191 | 269 |
| 192 TesterContext* test_context_; | 270 TesterContext* test_context_; |
| 193 TestBPtr b_; | 271 TestBPtr b_; |
| 194 }; | 272 }; |
| 195 | 273 |
| 196 class TestBImpl : public InterfaceImpl<TestB> { | 274 class TestBImpl : public InterfaceImpl<TestB> { |
| 197 public: | 275 public: |
| 198 TestBImpl(ApplicationConnection* connection, TesterContext* test_context) | 276 TestBImpl(ApplicationConnection* connection, TesterContext* test_context) |
| 199 : test_context_(test_context) { | 277 : test_context_(test_context) { |
| 200 connection->ConnectToService(&c_); | 278 connection->ConnectToService(&c_); |
| 201 } | 279 } |
| 202 | 280 |
| 203 virtual ~TestBImpl() { | 281 virtual ~TestBImpl() { |
| 204 test_context_->num_b_deletes++; | 282 test_context_->IncrementNumBDeletes(); |
| 205 if (!base::MessageLoop::current()->is_running()) | 283 test_context_->QuitSoon(); |
| 206 return; | |
| 207 base::MessageLoop::current()->Quit(); | |
| 208 } | 284 } |
| 209 | 285 |
| 210 private: | 286 private: |
| 211 virtual void B(const mojo::Callback<void()>& callback) OVERRIDE { | 287 virtual void B(const mojo::Callback<void()>& callback) OVERRIDE { |
| 212 ++test_context_->num_b_calls; | 288 test_context_->IncrementNumBCalls(); |
| 213 callback.Run(); | 289 callback.Run(); |
| 214 } | 290 } |
| 215 | 291 |
| 216 virtual void CallC(const mojo::Callback<void()>& callback) OVERRIDE { | 292 virtual void CallC(const mojo::Callback<void()>& callback) OVERRIDE { |
| 217 ++test_context_->num_b_calls; | 293 test_context_->IncrementNumBCalls(); |
| 218 c_->C(callback); | 294 c_->C(callback); |
| 219 } | 295 } |
| 220 | 296 |
| 221 TesterContext* test_context_; | 297 TesterContext* test_context_; |
| 222 TestCPtr c_; | 298 TestCPtr c_; |
| 223 }; | 299 }; |
| 224 | 300 |
| 225 class TestCImpl : public InterfaceImpl<TestC> { | 301 class TestCImpl : public InterfaceImpl<TestC> { |
| 226 public: | 302 public: |
| 227 TestCImpl(ApplicationConnection* connection, TesterContext* test_context) | 303 TestCImpl(ApplicationConnection* connection, TesterContext* test_context) |
| 228 : test_context_(test_context) {} | 304 : test_context_(test_context) {} |
| 229 | 305 |
| 230 virtual ~TestCImpl() { test_context_->num_c_deletes++; } | 306 virtual ~TestCImpl() { test_context_->IncrementNumCDeletes(); } |
| 231 | 307 |
| 232 private: | 308 private: |
| 233 virtual void C(const mojo::Callback<void()>& callback) OVERRIDE { | 309 virtual void C(const mojo::Callback<void()>& callback) OVERRIDE { |
| 234 ++test_context_->num_c_calls; | 310 test_context_->IncrementNumCCalls(); |
| 235 callback.Run(); | 311 callback.Run(); |
| 236 } | 312 } |
| 237 TesterContext* test_context_; | 313 TesterContext* test_context_; |
| 238 }; | 314 }; |
| 239 | 315 |
| 240 class Tester : public ApplicationDelegate, | 316 class Tester : public ApplicationDelegate, |
| 241 public ServiceLoader, | 317 public ServiceLoader, |
| 242 public InterfaceFactory<TestA>, | 318 public InterfaceFactory<TestA>, |
| 243 public InterfaceFactory<TestB>, | 319 public InterfaceFactory<TestB>, |
| 244 public InterfaceFactory<TestC> { | 320 public InterfaceFactory<TestC> { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 256 app_.reset(new ApplicationImpl(this, shell_handle.Pass())); | 332 app_.reset(new ApplicationImpl(this, shell_handle.Pass())); |
| 257 } | 333 } |
| 258 | 334 |
| 259 virtual void OnServiceError(ServiceManager* manager, | 335 virtual void OnServiceError(ServiceManager* manager, |
| 260 const GURL& url) OVERRIDE {} | 336 const GURL& url) OVERRIDE {} |
| 261 | 337 |
| 262 virtual bool ConfigureIncomingConnection( | 338 virtual bool ConfigureIncomingConnection( |
| 263 ApplicationConnection* connection) OVERRIDE { | 339 ApplicationConnection* connection) OVERRIDE { |
| 264 if (!requestor_url_.empty() && | 340 if (!requestor_url_.empty() && |
| 265 requestor_url_ != connection->GetRemoteApplicationURL()) { | 341 requestor_url_ != connection->GetRemoteApplicationURL()) { |
| 266 context_->tester_called_quit = true; | 342 context_->set_tester_called_quit(); |
| 267 base::MessageLoop::current()->Quit(); | 343 context_->QuitSoon(); |
| 268 return false; | 344 return false; |
| 269 } | 345 } |
| 270 // If we're coming from A, then add B, otherwise A. | 346 // If we're coming from A, then add B, otherwise A. |
| 271 if (connection->GetRemoteApplicationURL() == kTestAURLString) | 347 if (connection->GetRemoteApplicationURL() == kTestAURLString) |
| 272 connection->AddService<TestB>(this); | 348 connection->AddService<TestB>(this); |
| 273 else | 349 else |
| 274 connection->AddService<TestA>(this); | 350 connection->AddService<TestA>(this); |
| 275 return true; | 351 return true; |
| 276 } | 352 } |
| 277 | 353 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 private: | 403 private: |
| 328 int call_count_; | 404 int call_count_; |
| 329 GURL url_; | 405 GURL url_; |
| 330 DISALLOW_COPY_AND_ASSIGN(TestServiceInterceptor); | 406 DISALLOW_COPY_AND_ASSIGN(TestServiceInterceptor); |
| 331 }; | 407 }; |
| 332 | 408 |
| 333 } // namespace | 409 } // namespace |
| 334 | 410 |
| 335 class ServiceManagerTest : public testing::Test { | 411 class ServiceManagerTest : public testing::Test { |
| 336 public: | 412 public: |
| 337 ServiceManagerTest() {} | 413 ServiceManagerTest() : tester_context_(&loop_) {} |
| 338 | 414 |
| 339 virtual ~ServiceManagerTest() {} | 415 virtual ~ServiceManagerTest() {} |
| 340 | 416 |
| 341 virtual void SetUp() OVERRIDE { | 417 virtual void SetUp() OVERRIDE { |
| 342 service_manager_.reset(new ServiceManager); | 418 service_manager_.reset(new ServiceManager); |
| 343 TestServiceLoader* default_loader = new TestServiceLoader; | 419 TestServiceLoader* default_loader = new TestServiceLoader; |
| 344 default_loader->set_context(&context_); | 420 default_loader->set_context(&context_); |
| 345 service_manager_->set_default_loader( | 421 service_manager_->set_default_loader( |
| 346 scoped_ptr<ServiceLoader>(default_loader)); | 422 scoped_ptr<ServiceLoader>(default_loader)); |
| 347 | 423 |
| 348 TestServicePtr service_proxy; | 424 TestServicePtr service_proxy; |
| 349 service_manager_->ConnectToService(GURL(kTestURLString), &service_proxy); | 425 service_manager_->ConnectToService(GURL(kTestURLString), &service_proxy); |
| 350 test_client_.reset(new TestClientImpl(service_proxy.Pass())); | 426 test_client_.reset(new TestClientImpl(service_proxy.Pass())); |
| 351 } | 427 } |
| 352 | 428 |
| 353 virtual void TearDown() OVERRIDE { | 429 virtual void TearDown() OVERRIDE { |
| 354 test_client_.reset(NULL); | 430 test_client_.reset(NULL); |
| 355 service_manager_.reset(NULL); | 431 service_manager_.reset(NULL); |
| 356 } | 432 } |
| 357 | 433 |
| 434 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { |
| 435 scoped_ptr<ServiceLoader> real_loader( |
| 436 new Tester(&tester_context_, requestor_url)); |
| 437 service_manager_->SetLoaderForURL( |
| 438 scoped_ptr<ServiceLoader>(new BackgroundServiceLoader( |
| 439 real_loader.Pass(), "", base::MessageLoop::TYPE_DEFAULT)), |
| 440 url); |
| 441 } |
| 442 |
| 358 bool HasFactoryForTestURL() { | 443 bool HasFactoryForTestURL() { |
| 359 ServiceManager::TestAPI manager_test_api(service_manager_.get()); | 444 ServiceManager::TestAPI manager_test_api(service_manager_.get()); |
| 360 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); | 445 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); |
| 361 } | 446 } |
| 362 | 447 |
| 363 protected: | 448 protected: |
| 364 base::ShadowingAtExitManager at_exit_; | 449 base::ShadowingAtExitManager at_exit_; |
| 450 TesterContext tester_context_; |
| 451 TestContext context_; |
| 365 base::MessageLoop loop_; | 452 base::MessageLoop loop_; |
| 366 TestContext context_; | |
| 367 scoped_ptr<TestClientImpl> test_client_; | 453 scoped_ptr<TestClientImpl> test_client_; |
| 368 scoped_ptr<ServiceManager> service_manager_; | 454 scoped_ptr<ServiceManager> service_manager_; |
| 369 DISALLOW_COPY_AND_ASSIGN(ServiceManagerTest); | 455 DISALLOW_COPY_AND_ASSIGN(ServiceManagerTest); |
| 370 }; | 456 }; |
| 371 | 457 |
| 372 TEST_F(ServiceManagerTest, Basic) { | 458 TEST_F(ServiceManagerTest, Basic) { |
| 373 test_client_->Test("test"); | 459 test_client_->Test("test"); |
| 374 loop_.Run(); | 460 loop_.Run(); |
| 375 EXPECT_EQ(std::string("test"), context_.last_test_string); | 461 EXPECT_EQ(std::string("test"), context_.last_test_string); |
| 376 } | 462 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 } | 495 } |
| 410 EXPECT_EQ(5, context_.num_loader_deletes); | 496 EXPECT_EQ(5, context_.num_loader_deletes); |
| 411 } | 497 } |
| 412 | 498 |
| 413 // Confirm that both urls and schemes can have their loaders explicitly set. | 499 // Confirm that both urls and schemes can have their loaders explicitly set. |
| 414 TEST_F(ServiceManagerTest, SetLoaders) { | 500 TEST_F(ServiceManagerTest, SetLoaders) { |
| 415 ServiceManager sm; | 501 ServiceManager sm; |
| 416 TestServiceLoader* default_loader = new TestServiceLoader; | 502 TestServiceLoader* default_loader = new TestServiceLoader; |
| 417 TestServiceLoader* url_loader = new TestServiceLoader; | 503 TestServiceLoader* url_loader = new TestServiceLoader; |
| 418 TestServiceLoader* scheme_loader = new TestServiceLoader; | 504 TestServiceLoader* scheme_loader = new TestServiceLoader; |
| 419 sm.set_default_loader(scoped_ptr<ServiceLoader>(default_loader)); | 505 service_manager_->set_default_loader( |
| 420 sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(url_loader), GURL("test:test1")); | 506 scoped_ptr<ServiceLoader>(default_loader)); |
| 421 sm.SetLoaderForScheme(scoped_ptr<ServiceLoader>(scheme_loader), "test"); | 507 service_manager_->SetLoaderForURL(scoped_ptr<ServiceLoader>(url_loader), |
| 508 GURL("test:test1")); |
| 509 service_manager_->SetLoaderForScheme(scoped_ptr<ServiceLoader>(scheme_loader), |
| 510 "test"); |
| 422 | 511 |
| 423 // test::test1 should go to url_loader. | 512 // test::test1 should go to url_loader. |
| 424 TestServicePtr test_service; | 513 TestServicePtr test_service; |
| 425 sm.ConnectToService(GURL("test:test1"), &test_service); | 514 service_manager_->ConnectToService(GURL("test:test1"), &test_service); |
| 426 EXPECT_EQ(1, url_loader->num_loads()); | 515 EXPECT_EQ(1, url_loader->num_loads()); |
| 427 EXPECT_EQ(0, scheme_loader->num_loads()); | 516 EXPECT_EQ(0, scheme_loader->num_loads()); |
| 428 EXPECT_EQ(0, default_loader->num_loads()); | 517 EXPECT_EQ(0, default_loader->num_loads()); |
| 429 | 518 |
| 430 // test::test2 should go to scheme loader. | 519 // test::test2 should go to scheme loader. |
| 431 sm.ConnectToService(GURL("test:test2"), &test_service); | 520 service_manager_->ConnectToService(GURL("test:test2"), &test_service); |
| 432 EXPECT_EQ(1, url_loader->num_loads()); | 521 EXPECT_EQ(1, url_loader->num_loads()); |
| 433 EXPECT_EQ(1, scheme_loader->num_loads()); | 522 EXPECT_EQ(1, scheme_loader->num_loads()); |
| 434 EXPECT_EQ(0, default_loader->num_loads()); | 523 EXPECT_EQ(0, default_loader->num_loads()); |
| 435 | 524 |
| 436 // http::test1 should go to default loader. | 525 // http::test1 should go to default loader. |
| 437 sm.ConnectToService(GURL("http:test1"), &test_service); | 526 service_manager_->ConnectToService(GURL("http:test1"), &test_service); |
| 438 EXPECT_EQ(1, url_loader->num_loads()); | 527 EXPECT_EQ(1, url_loader->num_loads()); |
| 439 EXPECT_EQ(1, scheme_loader->num_loads()); | 528 EXPECT_EQ(1, scheme_loader->num_loads()); |
| 440 EXPECT_EQ(1, default_loader->num_loads()); | 529 EXPECT_EQ(1, default_loader->num_loads()); |
| 441 } | 530 } |
| 442 | 531 |
| 443 // Confirm that the url of a service is correctly passed to another service that | 532 // Confirm that the url of a service is correctly passed to another service that |
| 444 // it loads. | 533 // it loads. |
| 445 // http://crbug.com/396300 | 534 TEST_F(ServiceManagerTest, ACallB) { |
| 446 TEST_F(ServiceManagerTest, DISABLED_ACallB) { | |
| 447 TesterContext context; | |
| 448 ServiceManager sm; | |
| 449 | |
| 450 // Any url can load a. | 535 // Any url can load a. |
| 451 sm.SetLoaderForURL( | 536 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
| 452 scoped_ptr<ServiceLoader>(new Tester(&context, std::string())), | |
| 453 GURL(kTestAURLString)); | |
| 454 | 537 |
| 455 // Only a can load b. | 538 // Only a can load b. |
| 456 sm.SetLoaderForURL( | 539 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); |
| 457 scoped_ptr<ServiceLoader>( | |
| 458 new Tester(&context, kTestAURLString)), | |
| 459 GURL(kTestBURLString)); | |
| 460 | 540 |
| 461 TestAPtr a; | 541 TestAPtr a; |
| 462 sm.ConnectToService(GURL(kTestAURLString), &a); | 542 service_manager_->ConnectToService(GURL(kTestAURLString), &a); |
| 463 a->CallB(); | 543 a->CallB(); |
| 464 loop_.Run(); | 544 loop_.Run(); |
| 465 EXPECT_EQ(1, context.num_b_calls); | 545 EXPECT_EQ(1, tester_context_.num_b_calls()); |
| 466 EXPECT_TRUE(context.a_called_quit); | 546 EXPECT_TRUE(tester_context_.a_called_quit()); |
| 467 } | 547 } |
| 468 | 548 |
| 469 // A calls B which calls C. | 549 // A calls B which calls C. |
| 470 // http://crbug.com/396300 | 550 TEST_F(ServiceManagerTest, BCallC) { |
| 471 TEST_F(ServiceManagerTest, DISABLED_BCallC) { | |
| 472 TesterContext context; | |
| 473 ServiceManager sm; | |
| 474 | |
| 475 // Any url can load a. | 551 // Any url can load a. |
| 476 sm.SetLoaderForURL( | 552 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
| 477 scoped_ptr<ServiceLoader>(new Tester(&context, std::string())), | |
| 478 GURL(kTestAURLString)); | |
| 479 | 553 |
| 480 // Only a can load b. | 554 // Only a can load b. |
| 481 sm.SetLoaderForURL( | 555 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); |
| 482 scoped_ptr<ServiceLoader>( | |
| 483 new Tester(&context, kTestAURLString)), | |
| 484 GURL(kTestBURLString)); | |
| 485 | 556 |
| 486 TestAPtr a; | 557 TestAPtr a; |
| 487 sm.ConnectToService(GURL(kTestAURLString), &a); | 558 service_manager_->ConnectToService(GURL(kTestAURLString), &a); |
| 488 a->CallCFromB(); | 559 a->CallCFromB(); |
| 489 loop_.Run(); | 560 loop_.Run(); |
| 490 | 561 |
| 491 EXPECT_EQ(1, context.num_b_calls); | 562 EXPECT_EQ(1, tester_context_.num_b_calls()); |
| 492 EXPECT_EQ(1, context.num_c_calls); | 563 EXPECT_EQ(1, tester_context_.num_c_calls()); |
| 493 EXPECT_TRUE(context.a_called_quit); | 564 EXPECT_TRUE(tester_context_.a_called_quit()); |
| 494 } | 565 } |
| 495 | 566 |
| 496 // Confirm that a service impl will be deleted if the app that connected to | 567 // Confirm that a service impl will be deleted if the app that connected to |
| 497 // it goes away. | 568 // it goes away. |
| 498 // http://crbug.com/396300 | 569 TEST_F(ServiceManagerTest, BDeleted) { |
| 499 TEST_F(ServiceManagerTest, DISABLED_BDeleted) { | 570 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
| 500 TesterContext context; | 571 AddLoaderForURL(GURL(kTestBURLString), std::string()); |
| 501 ServiceManager sm; | |
| 502 | |
| 503 sm.SetLoaderForURL( | |
| 504 scoped_ptr<ServiceLoader>(new Tester(&context, std::string())), | |
| 505 GURL(kTestAURLString)); | |
| 506 | |
| 507 sm.SetLoaderForURL( | |
| 508 scoped_ptr<ServiceLoader>( new Tester(&context, std::string())), | |
| 509 GURL(kTestBURLString)); | |
| 510 | 572 |
| 511 TestAPtr a; | 573 TestAPtr a; |
| 512 sm.ConnectToService(GURL(kTestAURLString), &a); | 574 service_manager_->ConnectToService(GURL(kTestAURLString), &a); |
| 513 | 575 |
| 514 a->CallB(); | 576 a->CallB(); |
| 515 loop_.Run(); | 577 loop_.Run(); |
| 516 | 578 |
| 517 // Kills the a app. | 579 // Kills the a app. |
| 518 sm.SetLoaderForURL(scoped_ptr<ServiceLoader>(), GURL(kTestAURLString)); | 580 service_manager_->SetLoaderForURL(scoped_ptr<ServiceLoader>(), |
| 581 GURL(kTestAURLString)); |
| 519 loop_.Run(); | 582 loop_.Run(); |
| 520 EXPECT_EQ(1, context.num_b_deletes); | 583 |
| 584 EXPECT_EQ(1, tester_context_.num_b_deletes()); |
| 521 } | 585 } |
| 522 | 586 |
| 523 // Confirm that the url of a service is correctly passed to another service that | 587 // Confirm that the url of a service is correctly passed to another service that |
| 524 // it loads, and that it can be rejected. | 588 // it loads, and that it can be rejected. |
| 525 // http://crbug.com/396300 | 589 TEST_F(ServiceManagerTest, ANoLoadB) { |
| 526 TEST_F(ServiceManagerTest, DISABLED_ANoLoadB) { | |
| 527 TesterContext context; | |
| 528 ServiceManager sm; | |
| 529 | |
| 530 // Any url can load a. | 590 // Any url can load a. |
| 531 sm.SetLoaderForURL( | 591 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
| 532 scoped_ptr<ServiceLoader>(new Tester(&context, std::string())), | |
| 533 GURL(kTestAURLString)); | |
| 534 | 592 |
| 535 // Only c can load b, so this will fail. | 593 // Only c can load b, so this will fail. |
| 536 sm.SetLoaderForURL( | 594 AddLoaderForURL(GURL(kTestBURLString), "test:TestC"); |
| 537 scoped_ptr<ServiceLoader>(new Tester(&context, "test:TestC")), | |
| 538 GURL(kTestBURLString)); | |
| 539 | 595 |
| 540 TestAPtr a; | 596 TestAPtr a; |
| 541 sm.ConnectToService(GURL(kTestAURLString), &a); | 597 service_manager_->ConnectToService(GURL(kTestAURLString), &a); |
| 542 a->CallB(); | 598 a->CallB(); |
| 543 loop_.Run(); | 599 loop_.Run(); |
| 544 EXPECT_EQ(0, context.num_b_calls); | 600 EXPECT_EQ(0, tester_context_.num_b_calls()); |
| 545 EXPECT_TRUE(context.tester_called_quit); | 601 EXPECT_TRUE(tester_context_.tester_called_quit()); |
| 546 } | 602 } |
| 547 | 603 |
| 548 TEST_F(ServiceManagerTest, NoServiceNoLoad) { | 604 TEST_F(ServiceManagerTest, NoServiceNoLoad) { |
| 549 TesterContext context; | 605 AddLoaderForURL(GURL(kTestAURLString), std::string()); |
| 550 ServiceManager sm; | |
| 551 | |
| 552 sm.SetLoaderForURL( | |
| 553 scoped_ptr<ServiceLoader>(new Tester(&context, std::string())), | |
| 554 GURL(kTestAURLString)); | |
| 555 | 606 |
| 556 // There is no TestC service implementation registered with ServiceManager, | 607 // There is no TestC service implementation registered with ServiceManager, |
| 557 // so this cannot succeed (but also shouldn't crash). | 608 // so this cannot succeed (but also shouldn't crash). |
| 558 TestCPtr c; | 609 TestCPtr c; |
| 559 sm.ConnectToService(GURL(kTestAURLString), &c); | 610 service_manager_->ConnectToService(GURL(kTestAURLString), &c); |
| 560 QuitMessageLoopErrorHandler quitter; | 611 QuitMessageLoopErrorHandler quitter; |
| 561 c.set_error_handler(&quitter); | 612 c.set_error_handler(&quitter); |
| 562 | 613 |
| 563 loop_.Run(); | 614 loop_.Run(); |
| 564 EXPECT_TRUE(c.encountered_error()); | 615 EXPECT_TRUE(c.encountered_error()); |
| 565 } | 616 } |
| 566 | 617 |
| 567 TEST_F(ServiceManagerTest, Interceptor) { | 618 TEST_F(ServiceManagerTest, Interceptor) { |
| 568 ServiceManager sm; | |
| 569 TestServiceInterceptor interceptor; | 619 TestServiceInterceptor interceptor; |
| 570 TestServiceLoader* default_loader = new TestServiceLoader; | 620 TestServiceLoader* default_loader = new TestServiceLoader; |
| 571 sm.set_default_loader(scoped_ptr<ServiceLoader>(default_loader)); | 621 service_manager_->set_default_loader( |
| 572 sm.SetInterceptor(&interceptor); | 622 scoped_ptr<ServiceLoader>(default_loader)); |
| 623 service_manager_->SetInterceptor(&interceptor); |
| 573 | 624 |
| 574 std::string url("test:test3"); | 625 std::string url("test:test3"); |
| 575 TestServicePtr test_service; | 626 TestServicePtr test_service; |
| 576 sm.ConnectToService(GURL(url), &test_service); | 627 service_manager_->ConnectToService(GURL(url), &test_service); |
| 577 | 628 |
| 578 EXPECT_EQ(1, interceptor.call_count()); | 629 EXPECT_EQ(1, interceptor.call_count()); |
| 579 EXPECT_EQ(url, interceptor.url_spec()); | 630 EXPECT_EQ(url, interceptor.url_spec()); |
| 580 EXPECT_EQ(1, default_loader->num_loads()); | 631 EXPECT_EQ(1, default_loader->num_loads()); |
| 581 } | 632 } |
| 582 | 633 |
| 583 } // namespace mojo | 634 } // namespace mojo |
| OLD | NEW |