| 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/common/bindings_support_impl.h" | 6 #include "mojo/common/bindings_support_impl.h" |
| 7 #include "mojo/public/bindings/lib/remote_ptr.h" | 7 #include "mojo/public/bindings/lib/remote_ptr.h" |
| 8 #include "mojo/shell/service_manager.h" | 8 #include "mojo/shell/service_manager.h" |
| 9 #include "mojom/shell.h" | 9 #include "mojom/shell.h" |
| 10 #include "mojom/test.h" | 10 #include "mojom/test.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace shell { | 14 namespace shell { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 class TestApp : public ShellClientStub { | 17 class TestApp : public ShellClient { |
| 18 public: | 18 public: |
| 19 TestApp(ScopedMessagePipeHandle shell_handle) | 19 TestApp(ScopedMessagePipeHandle shell_handle) |
| 20 : shell_(shell_handle.Pass()) { | 20 : shell_(shell_handle.Pass(), this) { |
| 21 shell_.SetPeer(this); | |
| 22 } | 21 } |
| 23 virtual ~TestApp() { | 22 virtual ~TestApp() { |
| 24 } | 23 } |
| 25 virtual void AcceptConnection(ScopedMessagePipeHandle client_handle) | 24 virtual void AcceptConnection(ScopedMessagePipeHandle client_handle) |
| 26 MOJO_OVERRIDE { | 25 MOJO_OVERRIDE { |
| 27 service_.reset(new TestServiceImpl(this, client_handle.Pass())); | 26 service_.reset(new TestServiceImpl(this, client_handle.Pass())); |
| 28 } | 27 } |
| 29 std::string GetLastTestString() { | 28 std::string GetLastTestString() { |
| 30 return service_->last_test_string_; | 29 return service_->last_test_string_; |
| 31 } | 30 } |
| 32 | 31 |
| 33 private: | 32 private: |
| 34 class TestServiceImpl : public TestServiceStub { | 33 class TestServiceImpl : public TestService { |
| 35 public: | 34 public: |
| 36 TestServiceImpl(TestApp* service, ScopedMessagePipeHandle client_handle) | 35 TestServiceImpl(TestApp* service, ScopedMessagePipeHandle client_handle) |
| 37 : service_(service), | 36 : service_(service), |
| 38 client_(client_handle.Pass()) { | 37 client_(client_handle.Pass(), this) { |
| 39 client_.SetPeer(this); | |
| 40 } | 38 } |
| 41 virtual ~TestServiceImpl() { | 39 virtual ~TestServiceImpl() { |
| 42 } | 40 } |
| 43 virtual void Test(const mojo::String& test_string) OVERRIDE { | 41 virtual void Test(const mojo::String& test_string) OVERRIDE { |
| 44 last_test_string_ = test_string.To<std::string>(); | 42 last_test_string_ = test_string.To<std::string>(); |
| 45 client_->AckTest(); | 43 client_->AckTest(); |
| 46 } | 44 } |
| 47 TestApp* service_; | 45 TestApp* service_; |
| 48 RemotePtr<TestClient> client_; | 46 RemotePtr<TestClient> client_; |
| 49 std::string last_test_string_; | 47 std::string last_test_string_; |
| 50 }; | 48 }; |
| 51 RemotePtr<Shell> shell_; | 49 RemotePtr<Shell> shell_; |
| 52 scoped_ptr<TestServiceImpl> service_; | 50 scoped_ptr<TestServiceImpl> service_; |
| 53 }; | 51 }; |
| 54 | 52 |
| 55 class TestClientImpl : public TestClientStub { | 53 class TestClientImpl : public TestClient { |
| 56 public: | 54 public: |
| 57 explicit TestClientImpl(ScopedMessagePipeHandle service_handle) | 55 explicit TestClientImpl(ScopedMessagePipeHandle service_handle) |
| 58 : service_(service_handle.Pass()), | 56 : service_(service_handle.Pass(), this), |
| 59 quit_after_ack_(false) { | 57 quit_after_ack_(false) { |
| 60 service_.SetPeer(this); | |
| 61 } | 58 } |
| 62 virtual ~TestClientImpl() { | 59 virtual ~TestClientImpl() { |
| 63 } | 60 } |
| 64 virtual void AckTest() OVERRIDE { | 61 virtual void AckTest() OVERRIDE { |
| 65 if (quit_after_ack_) | 62 if (quit_after_ack_) |
| 66 base::MessageLoop::current()->QuitNow(); | 63 base::MessageLoop::current()->QuitNow(); |
| 67 } | 64 } |
| 68 void Test(std::string test_string) { | 65 void Test(std::string test_string) { |
| 69 AllocationScope scope; | 66 AllocationScope scope; |
| 70 quit_after_ack_ = true; | 67 quit_after_ack_ = true; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 113 |
| 117 TEST_F(ServiceManagerTest, Basic) { | 114 TEST_F(ServiceManagerTest, Basic) { |
| 118 test_client_->Test("test"); | 115 test_client_->Test("test"); |
| 119 loop_.Run(); | 116 loop_.Run(); |
| 120 EXPECT_EQ(std::string("test"), test_app_->GetLastTestString()); | 117 EXPECT_EQ(std::string("test"), test_app_->GetLastTestString()); |
| 121 } | 118 } |
| 122 | 119 |
| 123 } // namespace | 120 } // namespace |
| 124 } // namespace shell | 121 } // namespace shell |
| 125 } // namespace mojo | 122 } // namespace mojo |
| OLD | NEW |