Chromium Code Reviews| Index: mojo/shell/service_connector_unittest.cc |
| diff --git a/mojo/shell/service_connector_unittest.cc b/mojo/shell/service_connector_unittest.cc |
| index 654e16ad57c63431af2ad3b053b4889f140f8a3d..efdcb1bc32256eede56506b9c69cdb6baeb2d336 100644 |
| --- a/mojo/shell/service_connector_unittest.cc |
| +++ b/mojo/shell/service_connector_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "mojo/public/bindings/allocation_scope.h" |
| #include "mojo/public/bindings/remote_ptr.h" |
| +#include "mojo/public/shell/service.h" |
| #include "mojo/shell/service_connector.h" |
| #include "mojom/shell.h" |
| #include "mojom/test.h" |
| @@ -14,40 +15,16 @@ namespace mojo { |
| namespace shell { |
| namespace { |
| -class TestApp : public ShellClient { |
| +struct Context { |
| + std::string last_test_string; |
| +}; |
| + |
| +class TestServiceImpl : public Service<TestService, TestServiceImpl, Context> { |
| public: |
| - TestApp(ScopedMessagePipeHandle shell_handle) |
| - : shell_(shell_handle.Pass(), this) { |
| - } |
| - virtual ~TestApp() { |
| + virtual void Test(const mojo::String& test_string) OVERRIDE { |
| + context()->last_test_string = test_string.To<std::string>(); |
| + client()->AckTest(); |
| } |
| - virtual void AcceptConnection(ScopedMessagePipeHandle client_handle) |
| - MOJO_OVERRIDE { |
| - service_.reset(new TestServiceImpl(this, client_handle.Pass())); |
| - } |
| - std::string GetLastTestString() { |
| - return service_->last_test_string_; |
| - } |
| - |
| - private: |
| - class TestServiceImpl : public TestService { |
| - public: |
| - TestServiceImpl(TestApp* service, ScopedMessagePipeHandle client_handle) |
| - : service_(service), |
| - client_(client_handle.Pass(), this) { |
| - } |
| - virtual ~TestServiceImpl() { |
| - } |
| - virtual void Test(const mojo::String& test_string) OVERRIDE { |
| - last_test_string_ = test_string.To<std::string>(); |
| - client_->AckTest(); |
| - } |
| - TestApp* service_; |
| - RemotePtr<TestClient> client_; |
| - std::string last_test_string_; |
| - }; |
| - RemotePtr<Shell> shell_; |
| - scoped_ptr<TestServiceImpl> service_; |
| }; |
| class TestClientImpl : public TestClient { |
| @@ -97,12 +74,14 @@ class ServiceConnectorTest : public testing::Test, |
| virtual void Load(const GURL& url, |
| ScopedMessagePipeHandle shell_handle) OVERRIDE { |
| - test_app_.reset(new TestApp(shell_handle.Pass())); |
| + test_app_.reset(new ServiceFactory<TestServiceImpl, Context>( |
| + shell_handle.Pass(), &context_)); |
| } |
| protected: |
| base::MessageLoop loop_; |
| - scoped_ptr<TestApp> test_app_; |
| + Context context_; |
| + scoped_ptr<ServiceFactory<TestServiceImpl, Context>> test_app_; |
|
darin (slow to review)
2014/02/03 21:02:16
nit: I think some compilers will complain about th
|
| scoped_ptr<TestClientImpl> test_client_; |
| scoped_ptr<ServiceConnector> service_connector_; |
| DISALLOW_COPY_AND_ASSIGN(ServiceConnectorTest); |
| @@ -111,7 +90,7 @@ class ServiceConnectorTest : public testing::Test, |
| TEST_F(ServiceConnectorTest, Basic) { |
| test_client_->Test("test"); |
| loop_.Run(); |
| - EXPECT_EQ(std::string("test"), test_app_->GetLastTestString()); |
| + EXPECT_EQ(std::string("test"), context_.last_test_string); |
| } |
| } // namespace |