Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: mojo/service_manager/service_manager_unittest.cc

Issue 213313004: Add creation of ServiceManager to Content (2nd try) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add shell_client to mojo_pepper_container_app Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/service_manager/service_manager_export.h ('k') | mojo/shell/android/mojo_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mojo/public/bindings/allocation_scope.h" 6 #include "mojo/public/bindings/allocation_scope.h"
6 #include "mojo/public/bindings/remote_ptr.h" 7 #include "mojo/public/bindings/remote_ptr.h"
7 #include "mojo/public/environment/environment.h" 8 #include "mojo/public/environment/environment.h"
8 #include "mojo/public/shell/application.h" 9 #include "mojo/public/shell/application.h"
9 #include "mojo/public/shell/shell.mojom.h" 10 #include "mojo/public/shell/shell.mojom.h"
10 #include "mojo/public/utility/run_loop.h"
11 #include "mojo/service_manager/service_loader.h" 11 #include "mojo/service_manager/service_loader.h"
12 #include "mojo/service_manager/service_manager.h" 12 #include "mojo/service_manager/service_manager.h"
13 #include "mojo/service_manager/test.mojom.h" 13 #include "mojo/service_manager/test.mojom.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace { 17 namespace {
18 18
19 const char kTestURLString[] = "test:testService"; 19 const char kTestURLString[] = "test:testService";
20 20
(...skipping 29 matching lines...) Expand all
50 public: 50 public:
51 explicit TestClientImpl(ScopedTestServiceHandle service_handle) 51 explicit TestClientImpl(ScopedTestServiceHandle service_handle)
52 : service_(service_handle.Pass(), this), 52 : service_(service_handle.Pass(), this),
53 quit_after_ack_(false) { 53 quit_after_ack_(false) {
54 } 54 }
55 55
56 virtual ~TestClientImpl() {} 56 virtual ~TestClientImpl() {}
57 57
58 virtual void AckTest() OVERRIDE { 58 virtual void AckTest() OVERRIDE {
59 if (quit_after_ack_) 59 if (quit_after_ack_)
60 mojo::RunLoop::current()->Quit(); 60 base::MessageLoop::current()->Quit();
61 } 61 }
62 62
63 void Test(std::string test_string) { 63 void Test(std::string test_string) {
64 AllocationScope scope; 64 AllocationScope scope;
65 quit_after_ack_ = true; 65 quit_after_ack_ = true;
66 service_->Test(mojo::String(test_string)); 66 service_->Test(mojo::String(test_string));
67 } 67 }
68 68
69 private: 69 private:
70 RemotePtr<TestService> service_; 70 RemotePtr<TestService> service_;
(...skipping 25 matching lines...) Expand all
96 } 96 }
97 97
98 virtual void LoadService(ServiceManager* manager, 98 virtual void LoadService(ServiceManager* manager,
99 const GURL& url, 99 const GURL& url,
100 ScopedShellHandle shell_handle) OVERRIDE { 100 ScopedShellHandle shell_handle) OVERRIDE {
101 test_app_.reset(new Application(shell_handle.Pass())); 101 test_app_.reset(new Application(shell_handle.Pass()));
102 test_app_->AddServiceFactory( 102 test_app_->AddServiceFactory(
103 new ServiceFactory<TestServiceImpl, TestContext>(&context_)); 103 new ServiceFactory<TestServiceImpl, TestContext>(&context_));
104 } 104 }
105 105
106 virtual void OnServiceError(ServiceManager* manager,
107 const GURL& url) OVERRIDE {
108 base::MessageLoop::current()->PostTask(FROM_HERE,
109 base::MessageLoop::QuitClosure());
110 }
111
106 bool HasFactoryForTestURL() { 112 bool HasFactoryForTestURL() {
107 ServiceManager::TestAPI manager_test_api(service_manager_.get()); 113 ServiceManager::TestAPI manager_test_api(service_manager_.get());
108 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); 114 return manager_test_api.HasFactoryForURL(GURL(kTestURLString));
109 } 115 }
110 116
111 protected: 117 protected:
112 mojo::Environment env_; 118 mojo::Environment env_;
113 mojo::RunLoop loop_; 119 base::MessageLoop loop_;
114 TestContext context_; 120 TestContext context_;
115 scoped_ptr<Application> test_app_; 121 scoped_ptr<Application> test_app_;
116 scoped_ptr<TestClientImpl> test_client_; 122 scoped_ptr<TestClientImpl> test_client_;
117 scoped_ptr<ServiceManager> service_manager_; 123 scoped_ptr<ServiceManager> service_manager_;
118 DISALLOW_COPY_AND_ASSIGN(ServiceManagerTest); 124 DISALLOW_COPY_AND_ASSIGN(ServiceManagerTest);
119 }; 125 };
120 126
121 TEST_F(ServiceManagerTest, Basic) { 127 TEST_F(ServiceManagerTest, Basic) {
122 test_client_->Test("test"); 128 test_client_->Test("test");
123 loop_.Run(); 129 loop_.Run();
124 EXPECT_EQ(std::string("test"), context_.last_test_string); 130 EXPECT_EQ(std::string("test"), context_.last_test_string);
125 } 131 }
126 132
127 TEST_F(ServiceManagerTest, ClientError) { 133 TEST_F(ServiceManagerTest, ClientError) {
128 test_client_->Test("test"); 134 test_client_->Test("test");
129 EXPECT_TRUE(HasFactoryForTestURL()); 135 EXPECT_TRUE(HasFactoryForTestURL());
130 loop_.Run(); 136 loop_.Run();
131 EXPECT_EQ(1, context_.num_impls); 137 EXPECT_EQ(1, context_.num_impls);
132 test_client_.reset(NULL); 138 test_client_.reset(NULL);
133 loop_.Run(); 139 loop_.Run();
134 EXPECT_EQ(0, context_.num_impls); 140 EXPECT_EQ(0, context_.num_impls);
135 EXPECT_FALSE(HasFactoryForTestURL()); 141 EXPECT_FALSE(HasFactoryForTestURL());
136 } 142 }
137 } // namespace mojo 143 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/service_manager/service_manager_export.h ('k') | mojo/shell/android/mojo_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698