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
parent 9212bcc0
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment