summaryrefslogtreecommitdiffstats
path: root/mojo/shell
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-03 22:35:11 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-03 22:35:11 +0000
commit33e861778cbdc7b4bb69961587dcbbdeae58c2e4 (patch)
tree5bbe6bae7f1757e55845e9cf3fb727c27d0c857b /mojo/shell
parent9212bcc0d53192bda23c6e05ad6cdb461b285908 (diff)
downloadchromium_src-33e861778cbdc7b4bb69961587dcbbdeae58c2e4.zip
chromium_src-33e861778cbdc7b4bb69961587dcbbdeae58c2e4.tar.gz
chromium_src-33e861778cbdc7b4bb69961587dcbbdeae58c2e4.tar.bz2
Modify service_connector_unitttest to use Service<>
BUG=None TEST=existing R=darin@chromium.org, darin Review URL: https://codereview.chromium.org/135683007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248596 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/shell')
-rw-r--r--mojo/shell/service_connector_unittest.cc49
1 files changed, 14 insertions, 35 deletions
diff --git a/mojo/shell/service_connector_unittest.cc b/mojo/shell/service_connector_unittest.cc
index 654e16a..6ec7f07 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_;
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