| 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/public/cpp/bindings/allocation_scope.h" | |
| 7 #include "mojo/public/cpp/environment/environment.h" | 6 #include "mojo/public/cpp/environment/environment.h" |
| 8 #include "mojo/public/cpp/shell/application.h" | 7 #include "mojo/public/cpp/shell/application.h" |
| 9 #include "mojo/public/interfaces/shell/shell.mojom.h" | 8 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| 10 #include "mojo/service_manager/service_loader.h" | 9 #include "mojo/service_manager/service_loader.h" |
| 11 #include "mojo/service_manager/service_manager.h" | 10 #include "mojo/service_manager/service_manager.h" |
| 12 #include "mojo/service_manager/test.mojom.h" | 11 #include "mojo/service_manager/test.mojom.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 namespace mojo { | 14 namespace mojo { |
| 16 namespace { | 15 namespace { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 32 | 31 |
| 33 virtual ~TestServiceImpl() { | 32 virtual ~TestServiceImpl() { |
| 34 --context_->num_impls; | 33 --context_->num_impls; |
| 35 } | 34 } |
| 36 | 35 |
| 37 // InterfaceImpl<TestService> implementation. | 36 // InterfaceImpl<TestService> implementation. |
| 38 virtual void OnConnectionError() OVERRIDE { | 37 virtual void OnConnectionError() OVERRIDE { |
| 39 } | 38 } |
| 40 | 39 |
| 41 // TestService implementation: | 40 // TestService implementation: |
| 42 virtual void Test(const mojo::String& test_string) OVERRIDE { | 41 virtual void Test(mojo::String test_string) OVERRIDE { |
| 43 context_->last_test_string = test_string.To<std::string>(); | 42 context_->last_test_string = test_string.To<std::string>(); |
| 44 client()->AckTest(); | 43 client()->AckTest(); |
| 45 } | 44 } |
| 46 | 45 |
| 47 private: | 46 private: |
| 48 TestContext* context_; | 47 TestContext* context_; |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 class TestClientImpl : public TestClient { | 50 class TestClientImpl : public TestClient { |
| 52 public: | 51 public: |
| 53 explicit TestClientImpl(TestServicePtr service) | 52 explicit TestClientImpl(TestServicePtr service) |
| 54 : service_(service.Pass()), | 53 : service_(service.Pass()), |
| 55 quit_after_ack_(false) { | 54 quit_after_ack_(false) { |
| 56 service_->SetClient(this); | 55 service_->SetClient(this); |
| 57 } | 56 } |
| 58 | 57 |
| 59 virtual ~TestClientImpl() {} | 58 virtual ~TestClientImpl() {} |
| 60 | 59 |
| 61 virtual void AckTest() OVERRIDE { | 60 virtual void AckTest() OVERRIDE { |
| 62 if (quit_after_ack_) | 61 if (quit_after_ack_) |
| 63 base::MessageLoop::current()->Quit(); | 62 base::MessageLoop::current()->Quit(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 void Test(std::string test_string) { | 65 void Test(std::string test_string) { |
| 67 AllocationScope scope; | |
| 68 quit_after_ack_ = true; | 66 quit_after_ack_ = true; |
| 69 service_->Test(test_string); | 67 service_->Test(String::From(test_string)); |
| 70 } | 68 } |
| 71 | 69 |
| 72 private: | 70 private: |
| 73 TestServicePtr service_; | 71 TestServicePtr service_; |
| 74 bool quit_after_ack_; | 72 bool quit_after_ack_; |
| 75 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); | 73 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); |
| 76 }; | 74 }; |
| 77 | 75 |
| 78 class TestServiceLoader : public ServiceLoader { | 76 class TestServiceLoader : public ServiceLoader { |
| 79 public: | 77 public: |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 272 |
| 275 std::string url("test:test3"); | 273 std::string url("test:test3"); |
| 276 MessagePipe pipe1; | 274 MessagePipe pipe1; |
| 277 sm.Connect(GURL(url), pipe1.handle0.Pass()); | 275 sm.Connect(GURL(url), pipe1.handle0.Pass()); |
| 278 EXPECT_EQ(1, interceptor.call_count()); | 276 EXPECT_EQ(1, interceptor.call_count()); |
| 279 EXPECT_EQ(url, interceptor.url_spec()); | 277 EXPECT_EQ(url, interceptor.url_spec()); |
| 280 EXPECT_EQ(1, default_loader->num_loads()); | 278 EXPECT_EQ(1, default_loader->num_loads()); |
| 281 } | 279 } |
| 282 | 280 |
| 283 } // namespace mojo | 281 } // namespace mojo |
| OLD | NEW |