| Index: mojo/shell/service_connector_unittest.cc
|
| diff --git a/mojo/shell/service_connector_unittest.cc b/mojo/shell/service_connector_unittest.cc
|
| index 6ec7f07a3c88f6cf52ea31cab2b5e3d8722a2102..01a8a986ac467530510c24cb3e4ac2d2bb03adec 100644
|
| --- a/mojo/shell/service_connector_unittest.cc
|
| +++ b/mojo/shell/service_connector_unittest.cc
|
| @@ -2,10 +2,11 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "base/message_loop/message_loop.h"
|
| #include "mojo/public/bindings/allocation_scope.h"
|
| #include "mojo/public/bindings/remote_ptr.h"
|
| +#include "mojo/public/environment/environment.h"
|
| #include "mojo/public/shell/service.h"
|
| +#include "mojo/public/utility/run_loop.h"
|
| #include "mojo/shell/service_connector.h"
|
| #include "mojom/shell.h"
|
| #include "mojom/test.h"
|
| @@ -15,16 +16,34 @@ namespace mojo {
|
| namespace shell {
|
| namespace {
|
|
|
| -struct Context {
|
| +const char kTestURLString[] = "test:testService";
|
| +
|
| +struct TestContext {
|
| + TestContext() : num_impls(0) {}
|
| std::string last_test_string;
|
| + int num_impls;
|
| };
|
|
|
| -class TestServiceImpl : public Service<TestService, TestServiceImpl, Context> {
|
| +class TestServiceImpl :
|
| + public Service<TestService, TestServiceImpl, TestContext> {
|
| public:
|
| + TestServiceImpl() {}
|
| +
|
| + virtual ~TestServiceImpl() {
|
| + --context()->num_impls;
|
| + }
|
| +
|
| virtual void Test(const mojo::String& test_string) OVERRIDE {
|
| context()->last_test_string = test_string.To<std::string>();
|
| client()->AckTest();
|
| }
|
| +
|
| + void Initialize(ServiceFactory<TestServiceImpl, TestContext>* service_factory,
|
| + ScopedMessagePipeHandle client_handle) {
|
| + Service<TestService, TestServiceImpl, TestContext>::Initialize(
|
| + service_factory, client_handle.Pass());
|
| + ++context()->num_impls;
|
| + }
|
| };
|
|
|
| class TestClientImpl : public TestClient {
|
| @@ -33,32 +52,35 @@ class TestClientImpl : public TestClient {
|
| : service_(service_handle.Pass(), this),
|
| quit_after_ack_(false) {
|
| }
|
| - virtual ~TestClientImpl() {
|
| - }
|
| +
|
| + virtual ~TestClientImpl() {}
|
| +
|
| virtual void AckTest() OVERRIDE {
|
| if (quit_after_ack_)
|
| - base::MessageLoop::current()->QuitNow();
|
| + mojo::RunLoop::current()->Quit();
|
| }
|
| +
|
| void Test(std::string test_string) {
|
| AllocationScope scope;
|
| quit_after_ack_ = true;
|
| service_->Test(mojo::String(test_string));
|
| }
|
| +
|
| + private:
|
| RemotePtr<TestService> service_;
|
| bool quit_after_ack_;
|
| + DISALLOW_COPY_AND_ASSIGN(TestClientImpl);
|
| };
|
|
|
| class ServiceConnectorTest : public testing::Test,
|
| public ServiceConnector::Loader {
|
| public:
|
| - ServiceConnectorTest() {
|
| - }
|
| + ServiceConnectorTest() {}
|
|
|
| - virtual ~ServiceConnectorTest() {
|
| - }
|
| + virtual ~ServiceConnectorTest() {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| - GURL test_url("test:testService");
|
| + GURL test_url(kTestURLString);
|
| service_connector_.reset(new ServiceConnector);
|
| service_connector_->SetLoaderForURL(this, test_url);
|
| MessagePipe pipe;
|
| @@ -74,14 +96,15 @@ class ServiceConnectorTest : public testing::Test,
|
|
|
| virtual void Load(const GURL& url,
|
| ScopedMessagePipeHandle shell_handle) OVERRIDE {
|
| - test_app_.reset(new ServiceFactory<TestServiceImpl, Context>(
|
| + test_app_.reset(new ServiceFactory<TestServiceImpl, TestContext>(
|
| shell_handle.Pass(), &context_));
|
| }
|
|
|
| protected:
|
| - base::MessageLoop loop_;
|
| - Context context_;
|
| - scoped_ptr<ServiceFactory<TestServiceImpl, Context> > test_app_;
|
| + mojo::Environment env_;
|
| + mojo::RunLoop loop_;
|
| + TestContext context_;
|
| + scoped_ptr<ServiceFactory<TestServiceImpl, TestContext> > test_app_;
|
| scoped_ptr<TestClientImpl> test_client_;
|
| scoped_ptr<ServiceConnector> service_connector_;
|
| DISALLOW_COPY_AND_ASSIGN(ServiceConnectorTest);
|
| @@ -93,6 +116,16 @@ TEST_F(ServiceConnectorTest, Basic) {
|
| EXPECT_EQ(std::string("test"), context_.last_test_string);
|
| }
|
|
|
| +TEST_F(ServiceConnectorTest, ClientError) {
|
| + test_client_->Test("test");
|
| + EXPECT_TRUE(service_connector_->HasFactoryForURL(GURL(kTestURLString)));
|
| + loop_.Run();
|
| + EXPECT_EQ(1, context_.num_impls);
|
| + test_client_.reset(NULL);
|
| + loop_.Run();
|
| + EXPECT_EQ(0, context_.num_impls);
|
| + EXPECT_FALSE(service_connector_->HasFactoryForURL(GURL(kTestURLString)));
|
| +}
|
| } // namespace
|
| } // namespace shell
|
| } // namespace mojo
|
|
|