| 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" |
| 11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
| 12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
| 13 #include "mojo/public/cpp/application/interface_factory.h" | 13 #include "mojo/public/cpp/application/interface_factory.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 15 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 16 #include "shell/application_manager/application_loader.h" | 16 #include "shell/application_manager/application_loader.h" |
| 17 #include "shell/application_manager/application_manager.h" | 17 #include "shell/application_manager/application_manager.h" |
| 18 #include "shell/application_manager/test.mojom.h" | 18 #include "shell/application_manager/test.mojom.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace mojo { | 21 namespace mojo { |
| 22 namespace shell { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const char kTestURLString[] = "test:testService"; | 25 const char kTestURLString[] = "test:testService"; |
| 25 const char kTestAURLString[] = "test:TestA"; | 26 const char kTestAURLString[] = "test:TestA"; |
| 26 const char kTestBURLString[] = "test:TestB"; | 27 const char kTestBURLString[] = "test:TestB"; |
| 27 | 28 |
| 28 struct TestContext { | 29 struct TestContext { |
| 29 TestContext() : num_impls(0), num_loader_deletes(0) {} | 30 TestContext() : num_impls(0), num_loader_deletes(0) {} |
| 30 std::string last_test_string; | 31 std::string last_test_string; |
| 31 int num_impls; | 32 int num_impls; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 | 56 |
| 56 ~TestServiceImpl() override { | 57 ~TestServiceImpl() override { |
| 57 --context_->num_impls; | 58 --context_->num_impls; |
| 58 if (!base::MessageLoop::current()->is_running()) | 59 if (!base::MessageLoop::current()->is_running()) |
| 59 return; | 60 return; |
| 60 base::MessageLoop::current()->Quit(); | 61 base::MessageLoop::current()->Quit(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // TestService implementation: | 64 // TestService implementation: |
| 64 void Test(const String& test_string, | 65 void Test(const String& test_string, |
| 65 const mojo::Callback<void()>& callback) override { | 66 const Callback<void()>& callback) override { |
| 66 context_->last_test_string = test_string; | 67 context_->last_test_string = test_string; |
| 67 callback.Run(); | 68 callback.Run(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 private: | 71 private: |
| 71 TestContext* context_; | 72 TestContext* context_; |
| 72 StrongBinding<TestService> binding_; | 73 StrongBinding<TestService> binding_; |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 class TestClient { | 76 class TestClient { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 278 } |
| 278 | 279 |
| 279 ~TestBImpl() override { | 280 ~TestBImpl() override { |
| 280 test_context_->IncrementNumBDeletes(); | 281 test_context_->IncrementNumBDeletes(); |
| 281 if (base::MessageLoop::current()->is_running()) | 282 if (base::MessageLoop::current()->is_running()) |
| 282 base::MessageLoop::current()->Quit(); | 283 base::MessageLoop::current()->Quit(); |
| 283 test_context_->QuitSoon(); | 284 test_context_->QuitSoon(); |
| 284 } | 285 } |
| 285 | 286 |
| 286 private: | 287 private: |
| 287 void B(const mojo::Callback<void()>& callback) override { | 288 void B(const Callback<void()>& callback) override { |
| 288 test_context_->IncrementNumBCalls(); | 289 test_context_->IncrementNumBCalls(); |
| 289 callback.Run(); | 290 callback.Run(); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void CallC(const mojo::Callback<void()>& callback) override { | 293 void CallC(const Callback<void()>& callback) override { |
| 293 test_context_->IncrementNumBCalls(); | 294 test_context_->IncrementNumBCalls(); |
| 294 c_->C(callback); | 295 c_->C(callback); |
| 295 } | 296 } |
| 296 | 297 |
| 297 TesterContext* test_context_; | 298 TesterContext* test_context_; |
| 298 TestCPtr c_; | 299 TestCPtr c_; |
| 299 StrongBinding<TestB> binding_; | 300 StrongBinding<TestB> binding_; |
| 300 }; | 301 }; |
| 301 | 302 |
| 302 class TestCImpl : public TestC { | 303 class TestCImpl : public TestC { |
| 303 public: | 304 public: |
| 304 TestCImpl(ApplicationConnection* connection, | 305 TestCImpl(ApplicationConnection* connection, |
| 305 TesterContext* test_context, | 306 TesterContext* test_context, |
| 306 InterfaceRequest<TestC> request) | 307 InterfaceRequest<TestC> request) |
| 307 : test_context_(test_context), binding_(this, request.Pass()) {} | 308 : test_context_(test_context), binding_(this, request.Pass()) {} |
| 308 | 309 |
| 309 ~TestCImpl() override { test_context_->IncrementNumCDeletes(); } | 310 ~TestCImpl() override { test_context_->IncrementNumCDeletes(); } |
| 310 | 311 |
| 311 private: | 312 private: |
| 312 void C(const mojo::Callback<void()>& callback) override { | 313 void C(const Callback<void()>& callback) override { |
| 313 test_context_->IncrementNumCCalls(); | 314 test_context_->IncrementNumCCalls(); |
| 314 callback.Run(); | 315 callback.Run(); |
| 315 } | 316 } |
| 316 | 317 |
| 317 TesterContext* test_context_; | 318 TesterContext* test_context_; |
| 318 StrongBinding<TestC> binding_; | 319 StrongBinding<TestC> binding_; |
| 319 }; | 320 }; |
| 320 | 321 |
| 321 class Tester : public ApplicationDelegate, | 322 class Tester : public ApplicationDelegate, |
| 322 public ApplicationLoader, | 323 public ApplicationLoader, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 430 |
| 430 bool configure_incoming_connection_called() const { | 431 bool configure_incoming_connection_called() const { |
| 431 return configure_incoming_connection_called_; | 432 return configure_incoming_connection_called_; |
| 432 } | 433 } |
| 433 | 434 |
| 434 private: | 435 private: |
| 435 std::vector<std::string> initialize_args_; | 436 std::vector<std::string> initialize_args_; |
| 436 bool configure_incoming_connection_called_; | 437 bool configure_incoming_connection_called_; |
| 437 }; | 438 }; |
| 438 | 439 |
| 439 } // namespace | |
| 440 | |
| 441 class ApplicationManagerTest : public testing::Test { | 440 class ApplicationManagerTest : public testing::Test { |
| 442 public: | 441 public: |
| 443 ApplicationManagerTest() : tester_context_(&loop_) {} | 442 ApplicationManagerTest() : tester_context_(&loop_) {} |
| 444 | 443 |
| 445 ~ApplicationManagerTest() override {} | 444 ~ApplicationManagerTest() override {} |
| 446 | 445 |
| 447 void SetUp() override { | 446 void SetUp() override { |
| 448 application_manager_.reset(new ApplicationManager(&test_delegate_)); | 447 application_manager_.reset(new ApplicationManager(&test_delegate_)); |
| 449 test_loader_ = new TestApplicationLoader; | 448 test_loader_ = new TestApplicationLoader; |
| 450 test_loader_->set_context(&context_); | 449 test_loader_->set_context(&context_); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 EXPECT_EQ(1, url_loader->num_loads()); | 747 EXPECT_EQ(1, url_loader->num_loads()); |
| 749 EXPECT_EQ(0, scheme_loader->num_loads()); | 748 EXPECT_EQ(0, scheme_loader->num_loads()); |
| 750 | 749 |
| 751 // test::test2 should go to scheme loader. | 750 // test::test2 should go to scheme loader. |
| 752 application_manager_->ConnectToService(GURL("test:test2?foo=bar"), | 751 application_manager_->ConnectToService(GURL("test:test2?foo=bar"), |
| 753 &test_service); | 752 &test_service); |
| 754 EXPECT_EQ(1, url_loader->num_loads()); | 753 EXPECT_EQ(1, url_loader->num_loads()); |
| 755 EXPECT_EQ(1, scheme_loader->num_loads()); | 754 EXPECT_EQ(1, scheme_loader->num_loads()); |
| 756 } | 755 } |
| 757 | 756 |
| 757 } // namespace |
| 758 } // namespace shell |
| 758 } // namespace mojo | 759 } // namespace mojo |
| OLD | NEW |