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/shell/application_manager.h" | 5 #include "mojo/shell/application_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 public: | 102 public: |
103 explicit TestApplicationLoader(TestContext* context) | 103 explicit TestApplicationLoader(TestContext* context) |
104 : context_(context), num_loads_(0) {} | 104 : context_(context), num_loads_(0) {} |
105 | 105 |
106 ~TestApplicationLoader() override { | 106 ~TestApplicationLoader() override { |
107 ++context_->num_loader_deletes; | 107 ++context_->num_loader_deletes; |
108 shell_connection_.reset(); | 108 shell_connection_.reset(); |
109 } | 109 } |
110 | 110 |
111 int num_loads() const { return num_loads_; } | 111 int num_loads() const { return num_loads_; } |
112 const GURL& last_requestor_url() const { return last_requestor_url_; } | 112 const std::string& last_requestor_name() const { |
| 113 return last_requestor_name_; |
| 114 } |
113 | 115 |
114 private: | 116 private: |
115 // ApplicationLoader implementation. | 117 // ApplicationLoader implementation. |
116 void Load(const GURL& url, | 118 void Load(const std::string& name, |
117 InterfaceRequest<mojom::ShellClient> request) override { | 119 InterfaceRequest<mojom::ShellClient> request) override { |
118 ++num_loads_; | 120 ++num_loads_; |
119 shell_connection_.reset(new ShellConnection(this, std::move(request))); | 121 shell_connection_.reset(new ShellConnection(this, std::move(request))); |
120 } | 122 } |
121 | 123 |
122 // mojo::ShellClient implementation. | 124 // mojo::ShellClient implementation. |
123 bool AcceptConnection(Connection* connection) override { | 125 bool AcceptConnection(Connection* connection) override { |
124 connection->AddInterface<TestService>(this); | 126 connection->AddInterface<TestService>(this); |
125 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); | 127 last_requestor_name_ = connection->GetRemoteApplicationName(); |
126 return true; | 128 return true; |
127 } | 129 } |
128 | 130 |
129 // InterfaceFactory<TestService> implementation. | 131 // InterfaceFactory<TestService> implementation. |
130 void Create(Connection* connection, | 132 void Create(Connection* connection, |
131 InterfaceRequest<TestService> request) override { | 133 InterfaceRequest<TestService> request) override { |
132 new TestServiceImpl(context_, std::move(request)); | 134 new TestServiceImpl(context_, std::move(request)); |
133 } | 135 } |
134 | 136 |
135 scoped_ptr<ShellConnection> shell_connection_; | 137 scoped_ptr<ShellConnection> shell_connection_; |
136 TestContext* context_; | 138 TestContext* context_; |
137 int num_loads_; | 139 int num_loads_; |
138 GURL last_requestor_url_; | 140 std::string last_requestor_name_; |
139 | 141 |
140 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); | 142 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); |
141 }; | 143 }; |
142 | 144 |
143 class ClosingApplicationLoader : public ApplicationLoader { | 145 class ClosingApplicationLoader : public ApplicationLoader { |
144 private: | 146 private: |
145 // ApplicationLoader implementation. | 147 // ApplicationLoader implementation. |
146 void Load(const GURL& url, | 148 void Load(const std::string& name, |
147 InterfaceRequest<mojom::ShellClient> request) override { | 149 InterfaceRequest<mojom::ShellClient> request) override { |
148 } | 150 } |
149 }; | 151 }; |
150 | 152 |
151 class TesterContext { | 153 class TesterContext { |
152 public: | 154 public: |
153 explicit TesterContext(base::MessageLoop* loop) | 155 explicit TesterContext(base::MessageLoop* loop) |
154 : num_b_calls_(0), | 156 : num_b_calls_(0), |
155 num_c_calls_(0), | 157 num_c_calls_(0), |
156 num_a_deletes_(0), | 158 num_a_deletes_(0), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 int num_c_calls_; | 238 int num_c_calls_; |
237 int num_a_deletes_; | 239 int num_a_deletes_; |
238 int num_b_deletes_; | 240 int num_b_deletes_; |
239 int num_c_deletes_; | 241 int num_c_deletes_; |
240 bool tester_called_quit_; | 242 bool tester_called_quit_; |
241 bool a_called_quit_; | 243 bool a_called_quit_; |
242 | 244 |
243 base::MessageLoop* loop_; | 245 base::MessageLoop* loop_; |
244 }; | 246 }; |
245 | 247 |
246 // Used to test that the requestor url will be correctly passed. | 248 // Used to test that the requestor name will be correctly passed. |
247 class TestAImpl : public TestA { | 249 class TestAImpl : public TestA { |
248 public: | 250 public: |
249 TestAImpl(Connector* connector, | 251 TestAImpl(Connector* connector, |
250 TesterContext* test_context, | 252 TesterContext* test_context, |
251 InterfaceRequest<TestA> request, | 253 InterfaceRequest<TestA> request, |
252 InterfaceFactory<TestC>* factory) | 254 InterfaceFactory<TestC>* factory) |
253 : test_context_(test_context), binding_(this, std::move(request)) { | 255 : test_context_(test_context), binding_(this, std::move(request)) { |
254 connection_ = connector->Connect(kTestBURLString); | 256 connection_ = connector->Connect(kTestBURLString); |
255 connection_->AddInterface<TestC>(factory); | 257 connection_->AddInterface<TestC>(factory); |
256 connection_->GetInterface(&b_); | 258 connection_->GetInterface(&b_); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 TesterContext* test_context_; | 335 TesterContext* test_context_; |
334 StrongBinding<TestC> binding_; | 336 StrongBinding<TestC> binding_; |
335 }; | 337 }; |
336 | 338 |
337 class Tester : public ShellClient, | 339 class Tester : public ShellClient, |
338 public ApplicationLoader, | 340 public ApplicationLoader, |
339 public InterfaceFactory<TestA>, | 341 public InterfaceFactory<TestA>, |
340 public InterfaceFactory<TestB>, | 342 public InterfaceFactory<TestB>, |
341 public InterfaceFactory<TestC> { | 343 public InterfaceFactory<TestC> { |
342 public: | 344 public: |
343 Tester(TesterContext* context, const std::string& requestor_url) | 345 Tester(TesterContext* context, const std::string& requestor_name) |
344 : context_(context), requestor_url_(requestor_url) {} | 346 : context_(context), requestor_name_(requestor_name) {} |
345 ~Tester() override {} | 347 ~Tester() override {} |
346 | 348 |
347 private: | 349 private: |
348 void Load(const GURL& url, | 350 void Load(const std::string& name, |
349 InterfaceRequest<mojom::ShellClient> request) override { | 351 InterfaceRequest<mojom::ShellClient> request) override { |
350 app_.reset(new ShellConnection(this, std::move(request))); | 352 app_.reset(new ShellConnection(this, std::move(request))); |
351 } | 353 } |
352 | 354 |
353 bool AcceptConnection(Connection* connection) override { | 355 bool AcceptConnection(Connection* connection) override { |
354 if (!requestor_url_.empty() && | 356 if (!requestor_name_.empty() && |
355 requestor_url_ != connection->GetRemoteApplicationURL()) { | 357 requestor_name_ != connection->GetRemoteApplicationName()) { |
356 context_->set_tester_called_quit(); | 358 context_->set_tester_called_quit(); |
357 context_->QuitSoon(); | 359 context_->QuitSoon(); |
358 base::MessageLoop::current()->QuitWhenIdle(); | 360 base::MessageLoop::current()->QuitWhenIdle(); |
359 return false; | 361 return false; |
360 } | 362 } |
361 // If we're coming from A, then add B, otherwise A. | 363 // If we're coming from A, then add B, otherwise A. |
362 if (connection->GetRemoteApplicationURL() == kTestAURLString) | 364 if (connection->GetRemoteApplicationName() == kTestAURLString) |
363 connection->AddInterface<TestB>(this); | 365 connection->AddInterface<TestB>(this); |
364 else | 366 else |
365 connection->AddInterface<TestA>(this); | 367 connection->AddInterface<TestA>(this); |
366 return true; | 368 return true; |
367 } | 369 } |
368 | 370 |
369 void Create(Connection* connection, | 371 void Create(Connection* connection, |
370 InterfaceRequest<TestA> request) override { | 372 InterfaceRequest<TestA> request) override { |
371 a_bindings_.push_back( | 373 a_bindings_.push_back( |
372 new TestAImpl(app_->connector(), context_, std::move(request), this)); | 374 new TestAImpl(app_->connector(), context_, std::move(request), this)); |
373 } | 375 } |
374 | 376 |
375 void Create(Connection* connection, | 377 void Create(Connection* connection, |
376 InterfaceRequest<TestB> request) override { | 378 InterfaceRequest<TestB> request) override { |
377 new TestBImpl(connection, context_, std::move(request)); | 379 new TestBImpl(connection, context_, std::move(request)); |
378 } | 380 } |
379 | 381 |
380 void Create(Connection* connection, | 382 void Create(Connection* connection, |
381 InterfaceRequest<TestC> request) override { | 383 InterfaceRequest<TestC> request) override { |
382 new TestCImpl(connection, context_, std::move(request)); | 384 new TestCImpl(connection, context_, std::move(request)); |
383 } | 385 } |
384 | 386 |
385 TesterContext* context_; | 387 TesterContext* context_; |
386 scoped_ptr<ShellConnection> app_; | 388 scoped_ptr<ShellConnection> app_; |
387 std::string requestor_url_; | 389 std::string requestor_name_; |
388 ScopedVector<TestAImpl> a_bindings_; | 390 ScopedVector<TestAImpl> a_bindings_; |
389 }; | 391 }; |
390 | 392 |
391 void OnConnect(base::RunLoop* loop, uint32_t instance_id) { | 393 void OnConnect(base::RunLoop* loop, uint32_t instance_id) { |
392 loop->Quit(); | 394 loop->Quit(); |
393 } | 395 } |
394 | 396 |
395 class ApplicationManagerTest : public testing::Test { | 397 class ApplicationManagerTest : public testing::Test { |
396 public: | 398 public: |
397 ApplicationManagerTest() : tester_context_(&loop_) {} | 399 ApplicationManagerTest() : tester_context_(&loop_) {} |
398 | 400 |
399 ~ApplicationManagerTest() override {} | 401 ~ApplicationManagerTest() override {} |
400 | 402 |
401 void SetUp() override { | 403 void SetUp() override { |
402 application_manager_.reset( | 404 application_manager_.reset( |
403 new ApplicationManager(nullptr, nullptr, true, nullptr)); | 405 new ApplicationManager(nullptr, nullptr, nullptr)); |
404 test_loader_ = new TestApplicationLoader(&context_); | 406 test_loader_ = new TestApplicationLoader(&context_); |
405 application_manager_->set_default_loader( | 407 application_manager_->set_default_loader( |
406 scoped_ptr<ApplicationLoader>(test_loader_)); | 408 scoped_ptr<ApplicationLoader>(test_loader_)); |
407 | 409 |
408 TestServicePtr service_proxy; | 410 TestServicePtr service_proxy; |
409 ConnectToInterface(GURL(kTestURLString), &service_proxy); | 411 ConnectToInterface(kTestURLString, &service_proxy); |
410 test_client_.reset(new TestClient(std::move(service_proxy))); | 412 test_client_.reset(new TestClient(std::move(service_proxy))); |
411 } | 413 } |
412 | 414 |
413 void TearDown() override { | 415 void TearDown() override { |
414 test_client_.reset(); | 416 test_client_.reset(); |
415 application_manager_.reset(); | 417 application_manager_.reset(); |
416 } | 418 } |
417 | 419 |
418 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { | 420 void AddLoaderForName(const std::string& name, |
419 application_manager_->SetLoaderForURL( | 421 const std::string& requestor_name) { |
420 make_scoped_ptr(new Tester(&tester_context_, requestor_url)), url); | 422 application_manager_->SetLoaderForName( |
| 423 make_scoped_ptr(new Tester(&tester_context_, requestor_name)), name); |
421 } | 424 } |
422 | 425 |
423 bool HasRunningInstanceForURL(const GURL& url) { | 426 bool HasRunningInstanceForName(const std::string& name) { |
424 ApplicationManager::TestAPI manager_test_api(application_manager_.get()); | 427 ApplicationManager::TestAPI manager_test_api(application_manager_.get()); |
425 return manager_test_api.HasRunningInstanceForURL(url); | 428 return manager_test_api.HasRunningInstanceForName(name); |
426 } | 429 } |
427 | 430 |
428 protected: | 431 protected: |
429 template <typename Interface> | 432 template <typename Interface> |
430 void ConnectToInterface(const GURL& url, InterfacePtr<Interface>* ptr) { | 433 void ConnectToInterface(const std::string& name, |
| 434 InterfacePtr<Interface>* ptr) { |
431 base::RunLoop loop; | 435 base::RunLoop loop; |
432 mojom::InterfaceProviderPtr remote_interfaces; | 436 mojom::InterfaceProviderPtr remote_interfaces; |
433 scoped_ptr<ConnectParams> params(new ConnectParams); | 437 scoped_ptr<ConnectParams> params(new ConnectParams); |
434 params->set_source(CreateShellIdentity()); | 438 params->set_source(CreateShellIdentity()); |
435 params->set_target(Identity(url)); | 439 params->set_target(Identity(name)); |
436 params->set_remote_interfaces(GetProxy(&remote_interfaces)); | 440 params->set_remote_interfaces(GetProxy(&remote_interfaces)); |
437 params->set_connect_callback( | 441 params->set_connect_callback( |
438 base::Bind(&OnConnect, base::Unretained(&loop))); | 442 base::Bind(&OnConnect, base::Unretained(&loop))); |
439 application_manager_->Connect(std::move(params)); | 443 application_manager_->Connect(std::move(params)); |
440 loop.Run(); | 444 loop.Run(); |
441 | 445 |
442 mojo::GetInterface(remote_interfaces.get(), ptr); | 446 mojo::GetInterface(remote_interfaces.get(), ptr); |
443 } | 447 } |
444 | 448 |
445 base::ShadowingAtExitManager at_exit_; | 449 base::ShadowingAtExitManager at_exit_; |
446 TestApplicationLoader* test_loader_; | 450 TestApplicationLoader* test_loader_; |
447 TesterContext tester_context_; | 451 TesterContext tester_context_; |
448 TestContext context_; | 452 TestContext context_; |
449 base::MessageLoop loop_; | 453 base::MessageLoop loop_; |
450 scoped_ptr<TestClient> test_client_; | 454 scoped_ptr<TestClient> test_client_; |
451 scoped_ptr<ApplicationManager> application_manager_; | 455 scoped_ptr<ApplicationManager> application_manager_; |
452 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest); | 456 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest); |
453 }; | 457 }; |
454 | 458 |
455 TEST_F(ApplicationManagerTest, Basic) { | 459 TEST_F(ApplicationManagerTest, Basic) { |
456 test_client_->Test("test"); | 460 test_client_->Test("test"); |
457 loop_.Run(); | 461 loop_.Run(); |
458 EXPECT_EQ(std::string("test"), context_.last_test_string); | 462 EXPECT_EQ(std::string("test"), context_.last_test_string); |
459 } | 463 } |
460 | 464 |
461 TEST_F(ApplicationManagerTest, ClientError) { | 465 TEST_F(ApplicationManagerTest, ClientError) { |
462 test_client_->Test("test"); | 466 test_client_->Test("test"); |
463 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); | 467 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString)); |
464 loop_.Run(); | 468 loop_.Run(); |
465 EXPECT_EQ(1, context_.num_impls); | 469 EXPECT_EQ(1, context_.num_impls); |
466 test_client_.reset(); | 470 test_client_.reset(); |
467 loop_.Run(); | 471 loop_.Run(); |
468 EXPECT_EQ(0, context_.num_impls); | 472 EXPECT_EQ(0, context_.num_impls); |
469 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); | 473 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString)); |
470 } | 474 } |
471 | 475 |
472 TEST_F(ApplicationManagerTest, Deletes) { | 476 TEST_F(ApplicationManagerTest, Deletes) { |
473 { | 477 { |
474 ApplicationManager am(nullptr, nullptr, true, nullptr); | 478 ApplicationManager am(nullptr, nullptr, nullptr); |
475 TestApplicationLoader* default_loader = | 479 TestApplicationLoader* default_loader = |
476 new TestApplicationLoader(&context_); | 480 new TestApplicationLoader(&context_); |
477 TestApplicationLoader* url_loader1 = new TestApplicationLoader(&context_); | 481 TestApplicationLoader* name_loader1 = new TestApplicationLoader(&context_); |
478 TestApplicationLoader* url_loader2 = new TestApplicationLoader(&context_); | 482 TestApplicationLoader* name_loader2 = new TestApplicationLoader(&context_); |
479 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); | 483 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); |
480 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), | 484 am.SetLoaderForName(scoped_ptr<ApplicationLoader>(name_loader1), |
481 GURL("test:test1")); | 485 "test:test1"); |
482 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), | 486 am.SetLoaderForName(scoped_ptr<ApplicationLoader>(name_loader2), |
483 GURL("test:test1")); | 487 "test:test1"); |
484 } | 488 } |
485 EXPECT_EQ(3, context_.num_loader_deletes); | 489 EXPECT_EQ(3, context_.num_loader_deletes); |
486 } | 490 } |
487 | 491 |
488 // Test for SetLoaderForURL() & set_default_loader(). | 492 // Test for SetLoaderForName() & set_default_loader(). |
489 TEST_F(ApplicationManagerTest, SetLoaders) { | 493 TEST_F(ApplicationManagerTest, SetLoaders) { |
490 TestApplicationLoader* default_loader = new TestApplicationLoader(&context_); | 494 TestApplicationLoader* default_loader = new TestApplicationLoader(&context_); |
491 TestApplicationLoader* url_loader = new TestApplicationLoader(&context_); | 495 TestApplicationLoader* name_loader = new TestApplicationLoader(&context_); |
492 application_manager_->set_default_loader( | 496 application_manager_->set_default_loader( |
493 scoped_ptr<ApplicationLoader>(default_loader)); | 497 scoped_ptr<ApplicationLoader>(default_loader)); |
494 application_manager_->SetLoaderForURL( | 498 application_manager_->SetLoaderForName( |
495 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); | 499 scoped_ptr<ApplicationLoader>(name_loader), "test:test1"); |
496 | 500 |
497 // test::test1 should go to url_loader. | 501 // test::test1 should go to name_loader. |
498 TestServicePtr test_service; | 502 TestServicePtr test_service; |
499 ConnectToInterface(GURL("test:test1"), &test_service); | 503 ConnectToInterface("test:test1", &test_service); |
500 EXPECT_EQ(1, url_loader->num_loads()); | 504 EXPECT_EQ(1, name_loader->num_loads()); |
501 EXPECT_EQ(0, default_loader->num_loads()); | 505 EXPECT_EQ(0, default_loader->num_loads()); |
502 | 506 |
503 // http::test1 should go to default loader. | 507 // http::test1 should go to default loader. |
504 ConnectToInterface(GURL("http:test1"), &test_service); | 508 ConnectToInterface("http:test1", &test_service); |
505 EXPECT_EQ(1, url_loader->num_loads()); | 509 EXPECT_EQ(1, name_loader->num_loads()); |
506 EXPECT_EQ(1, default_loader->num_loads()); | 510 EXPECT_EQ(1, default_loader->num_loads()); |
507 } | 511 } |
508 | 512 |
509 // Confirm that the url of a service is correctly passed to another service that | 513 // Confirm that the name of a service is correctly passed to another service |
510 // it loads. | 514 // that it loads. |
511 // TODO(beng): these tests are disabled due to the new async connect flow. | 515 // TODO(beng): these tests are disabled due to the new async connect flow. |
512 // they should be re-written as shell apptests. | 516 // they should be re-written as shell apptests. |
513 TEST_F(ApplicationManagerTest, DISABLED_ACallB) { | 517 TEST_F(ApplicationManagerTest, DISABLED_ACallB) { |
514 // Any url can load a. | 518 // Any name can load a. |
515 AddLoaderForURL(GURL(kTestAURLString), std::string()); | 519 AddLoaderForName(kTestAURLString, std::string()); |
516 | 520 |
517 // Only a can load b. | 521 // Only a can load b. |
518 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); | 522 AddLoaderForName(kTestBURLString, kTestAURLString); |
519 | 523 |
520 TestAPtr a; | 524 TestAPtr a; |
521 ConnectToInterface(GURL(kTestAURLString), &a); | 525 ConnectToInterface(kTestAURLString, &a); |
522 a->CallB(); | 526 a->CallB(); |
523 loop_.Run(); | 527 loop_.Run(); |
524 EXPECT_EQ(1, tester_context_.num_b_calls()); | 528 EXPECT_EQ(1, tester_context_.num_b_calls()); |
525 EXPECT_TRUE(tester_context_.a_called_quit()); | 529 EXPECT_TRUE(tester_context_.a_called_quit()); |
526 } | 530 } |
527 | 531 |
528 // A calls B which calls C. | 532 // A calls B which calls C. |
529 TEST_F(ApplicationManagerTest, DISABLED_BCallC) { | 533 TEST_F(ApplicationManagerTest, DISABLED_BCallC) { |
530 // Any url can load a. | 534 // Any name can load a. |
531 AddLoaderForURL(GURL(kTestAURLString), std::string()); | 535 AddLoaderForName(kTestAURLString, std::string()); |
532 | 536 |
533 // Only a can load b. | 537 // Only a can load b. |
534 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); | 538 AddLoaderForName(kTestBURLString, kTestAURLString); |
535 | 539 |
536 TestAPtr a; | 540 TestAPtr a; |
537 ConnectToInterface(GURL(kTestAURLString), &a); | 541 ConnectToInterface(kTestAURLString, &a); |
538 a->CallCFromB(); | 542 a->CallCFromB(); |
539 loop_.Run(); | 543 loop_.Run(); |
540 | 544 |
541 EXPECT_EQ(1, tester_context_.num_b_calls()); | 545 EXPECT_EQ(1, tester_context_.num_b_calls()); |
542 EXPECT_EQ(1, tester_context_.num_c_calls()); | 546 EXPECT_EQ(1, tester_context_.num_c_calls()); |
543 EXPECT_TRUE(tester_context_.a_called_quit()); | 547 EXPECT_TRUE(tester_context_.a_called_quit()); |
544 } | 548 } |
545 | 549 |
546 // Confirm that a service impl will be deleted if the app that connected to | 550 // Confirm that a service impl will be deleted if the app that connected to |
547 // it goes away. | 551 // it goes away. |
548 TEST_F(ApplicationManagerTest, DISABLED_BDeleted) { | 552 TEST_F(ApplicationManagerTest, DISABLED_BDeleted) { |
549 AddLoaderForURL(GURL(kTestAURLString), std::string()); | 553 AddLoaderForName(kTestAURLString, std::string()); |
550 AddLoaderForURL(GURL(kTestBURLString), std::string()); | 554 AddLoaderForName(kTestBURLString, std::string()); |
551 | 555 |
552 TestAPtr a; | 556 TestAPtr a; |
553 ConnectToInterface(GURL(kTestAURLString), &a); | 557 ConnectToInterface(kTestAURLString, &a); |
554 | 558 |
555 a->CallB(); | 559 a->CallB(); |
556 loop_.Run(); | 560 loop_.Run(); |
557 | 561 |
558 // Kills the a app. | 562 // Kills the a app. |
559 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(), | 563 application_manager_->SetLoaderForName(scoped_ptr<ApplicationLoader>(), |
560 GURL(kTestAURLString)); | 564 kTestAURLString); |
561 loop_.Run(); | 565 loop_.Run(); |
562 | 566 |
563 EXPECT_EQ(1, tester_context_.num_b_deletes()); | 567 EXPECT_EQ(1, tester_context_.num_b_deletes()); |
564 } | 568 } |
565 | 569 |
566 // Confirm that the url of a service is correctly passed to another service that | 570 // Confirm that the name of a service is correctly passed to another service |
567 // it loads, and that it can be rejected. | 571 // that it loads, and that it can be rejected. |
568 TEST_F(ApplicationManagerTest, DISABLED_ANoLoadB) { | 572 TEST_F(ApplicationManagerTest, DISABLED_ANoLoadB) { |
569 // Any url can load a. | 573 // Any name can load a. |
570 AddLoaderForURL(GURL(kTestAURLString), std::string()); | 574 AddLoaderForName(kTestAURLString, std::string()); |
571 | 575 |
572 // Only c can load b, so this will fail. | 576 // Only c can load b, so this will fail. |
573 AddLoaderForURL(GURL(kTestBURLString), "test:TestC"); | 577 AddLoaderForName(kTestBURLString, "test:TestC"); |
574 | 578 |
575 TestAPtr a; | 579 TestAPtr a; |
576 ConnectToInterface(GURL(kTestAURLString), &a); | 580 ConnectToInterface(kTestAURLString, &a); |
577 a->CallB(); | 581 a->CallB(); |
578 loop_.Run(); | 582 loop_.Run(); |
579 EXPECT_EQ(0, tester_context_.num_b_calls()); | 583 EXPECT_EQ(0, tester_context_.num_b_calls()); |
580 | 584 |
581 EXPECT_FALSE(tester_context_.a_called_quit()); | 585 EXPECT_FALSE(tester_context_.a_called_quit()); |
582 EXPECT_TRUE(tester_context_.tester_called_quit()); | 586 EXPECT_TRUE(tester_context_.tester_called_quit()); |
583 } | 587 } |
584 | 588 |
585 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { | 589 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { |
586 AddLoaderForURL(GURL(kTestAURLString), std::string()); | 590 AddLoaderForName(kTestAURLString, std::string()); |
587 | 591 |
588 // There is no TestC service implementation registered with | 592 // There is no TestC service implementation registered with |
589 // ApplicationManager, so this cannot succeed (but also shouldn't crash). | 593 // ApplicationManager, so this cannot succeed (but also shouldn't crash). |
590 TestCPtr c; | 594 TestCPtr c; |
591 ConnectToInterface(GURL(kTestAURLString), &c); | 595 ConnectToInterface(kTestAURLString, &c); |
592 c.set_connection_error_handler( | 596 c.set_connection_error_handler( |
593 []() { base::MessageLoop::current()->QuitWhenIdle(); }); | 597 []() { base::MessageLoop::current()->QuitWhenIdle(); }); |
594 | 598 |
595 loop_.Run(); | 599 loop_.Run(); |
596 EXPECT_TRUE(c.encountered_error()); | 600 EXPECT_TRUE(c.encountered_error()); |
597 } | 601 } |
598 | 602 |
599 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { | 603 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { |
600 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); | 604 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); |
601 application_manager_->SetLoaderForURL( | 605 application_manager_->SetLoaderForName( |
602 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); | 606 scoped_ptr<ApplicationLoader>(loader), "test:test"); |
603 | 607 |
604 bool called = false; | 608 bool called = false; |
605 scoped_ptr<ConnectParams> params(new ConnectParams); | 609 scoped_ptr<ConnectParams> params(new ConnectParams); |
606 params->set_source(CreateShellIdentity()); | 610 params->set_source(CreateShellIdentity()); |
607 params->set_target( | 611 params->set_target(Identity("test:test", "", mojom::Connector::kUserRoot)); |
608 Identity(GURL("test:test"), "", mojom::Connector::kUserRoot)); | |
609 application_manager_->SetInstanceQuitCallback( | 612 application_manager_->SetInstanceQuitCallback( |
610 base::Bind(&QuitClosure, params->target(), &called)); | 613 base::Bind(&QuitClosure, params->target(), &called)); |
611 application_manager_->Connect(std::move(params)); | 614 application_manager_->Connect(std::move(params)); |
612 loop_.Run(); | 615 loop_.Run(); |
613 EXPECT_TRUE(called); | 616 EXPECT_TRUE(called); |
614 } | 617 } |
615 | 618 |
616 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { | 619 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { |
617 // 1 because ApplicationManagerTest connects once at startup. | 620 // 1 because ApplicationManagerTest connects once at startup. |
618 EXPECT_EQ(1, test_loader_->num_loads()); | 621 EXPECT_EQ(1, test_loader_->num_loads()); |
619 | 622 |
620 TestServicePtr test_service; | 623 TestServicePtr test_service; |
621 ConnectToInterface(GURL("test:foo"), &test_service); | 624 ConnectToInterface("test:foo", &test_service); |
622 EXPECT_EQ(2, test_loader_->num_loads()); | 625 EXPECT_EQ(2, test_loader_->num_loads()); |
623 | 626 |
624 // Exactly the same URL as above. | 627 // Exactly the same name as above. |
625 ConnectToInterface(GURL("test:foo"), &test_service); | 628 ConnectToInterface("test:foo", &test_service); |
626 EXPECT_EQ(2, test_loader_->num_loads()); | 629 EXPECT_EQ(2, test_loader_->num_loads()); |
627 | 630 |
628 // A different identity because the domain is different. | 631 // A different identity because the domain is different. |
629 ConnectToInterface(GURL("test:bar"), &test_service); | 632 ConnectToInterface("test:bar", &test_service); |
630 EXPECT_EQ(3, test_loader_->num_loads()); | 633 EXPECT_EQ(3, test_loader_->num_loads()); |
631 } | 634 } |
632 | 635 |
633 } // namespace test | 636 } // namespace test |
634 } // namespace shell | 637 } // namespace shell |
635 } // namespace mojo | 638 } // namespace mojo |
OLD | NEW |