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