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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 return mapped_url; | 408 return mapped_url; |
409 } | 409 } |
410 | 410 |
411 virtual void OnApplicationError(const GURL& url) override { | 411 virtual void OnApplicationError(const GURL& url) override { |
412 } | 412 } |
413 | 413 |
414 private: | 414 private: |
415 std::map<GURL, GURL> mappings_; | 415 std::map<GURL, GURL> mappings_; |
416 }; | 416 }; |
417 | 417 |
| 418 class TestExternal : public ApplicationDelegate { |
| 419 public: |
| 420 TestExternal() |
| 421 : initialize_called_(false), |
| 422 configure_incoming_connection_called_(false) {} |
| 423 |
| 424 virtual void Initialize(ApplicationImpl* app) override { |
| 425 initialize_called_ = true; |
| 426 base::MessageLoop::current()->Quit(); |
| 427 } |
| 428 |
| 429 virtual bool ConfigureIncomingConnection( |
| 430 ApplicationConnection* connection) override { |
| 431 configure_incoming_connection_called_ = true; |
| 432 base::MessageLoop::current()->Quit(); |
| 433 return true; |
| 434 } |
| 435 |
| 436 bool initialize_called() const { return initialize_called_; } |
| 437 bool configure_incoming_connection_called() const { |
| 438 return configure_incoming_connection_called_; |
| 439 } |
| 440 |
| 441 private: |
| 442 bool initialize_called_; |
| 443 bool configure_incoming_connection_called_; |
| 444 }; |
| 445 |
418 } // namespace | 446 } // namespace |
419 | 447 |
420 class ApplicationManagerTest : public testing::Test { | 448 class ApplicationManagerTest : public testing::Test { |
421 public: | 449 public: |
422 ApplicationManagerTest() : tester_context_(&loop_) {} | 450 ApplicationManagerTest() : tester_context_(&loop_) {} |
423 | 451 |
424 ~ApplicationManagerTest() override {} | 452 ~ApplicationManagerTest() override {} |
425 | 453 |
426 void SetUp() override { | 454 void SetUp() override { |
427 application_manager_.reset(new ApplicationManager(&test_delegate_)); | 455 application_manager_.reset(new ApplicationManager(&test_delegate_)); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 application_manager_->SetLoaderForURL(make_scoped_ptr(custom_loader), | 717 application_manager_->SetLoaderForURL(make_scoped_ptr(custom_loader), |
690 GURL("mojo:foo")); | 718 GURL("mojo:foo")); |
691 test_delegate_.AddMapping(GURL("mojo:foo2"), GURL("mojo:foo")); | 719 test_delegate_.AddMapping(GURL("mojo:foo2"), GURL("mojo:foo")); |
692 | 720 |
693 TestServicePtr test_service; | 721 TestServicePtr test_service; |
694 application_manager_->ConnectToService(GURL("mojo:foo2"), &test_service); | 722 application_manager_->ConnectToService(GURL("mojo:foo2"), &test_service); |
695 EXPECT_EQ(1, custom_loader->num_loads()); | 723 EXPECT_EQ(1, custom_loader->num_loads()); |
696 custom_loader->set_context(nullptr); | 724 custom_loader->set_context(nullptr); |
697 } | 725 } |
698 | 726 |
| 727 TEST_F(ApplicationManagerTest, ExternalApp) { |
| 728 MessagePipe shell_pipe; |
| 729 TestExternal external; |
| 730 ApplicationImpl app(&external, shell_pipe.handle0.Pass()); |
| 731 application_manager_->RegisterExternalApplication( |
| 732 GURL("mojo:test"), shell_pipe.handle1.Pass()); |
| 733 loop_.Run(); |
| 734 EXPECT_TRUE(external.initialize_called()); |
| 735 application_manager_->ConnectToServiceByName( |
| 736 GURL("mojo:test"), std::string()); |
| 737 loop_.Run(); |
| 738 EXPECT_TRUE(external.configure_incoming_connection_called()); |
| 739 }; |
| 740 |
699 } // namespace mojo | 741 } // namespace mojo |
OLD | NEW |