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

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

Issue 228763003: Interceptor test for the mojo spy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits 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 | « no previous file | no next file » | 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 "base/message_loop/message_loop.h"
6 #include "mojo/public/cpp/bindings/allocation_scope.h" 6 #include "mojo/public/cpp/bindings/allocation_scope.h"
7 #include "mojo/public/cpp/bindings/remote_ptr.h" 7 #include "mojo/public/cpp/bindings/remote_ptr.h"
8 #include "mojo/public/cpp/environment/environment.h" 8 #include "mojo/public/cpp/environment/environment.h"
9 #include "mojo/public/cpp/shell/application.h" 9 #include "mojo/public/cpp/shell/application.h"
10 #include "mojo/public/interfaces/shell/shell.mojom.h" 10 #include "mojo/public/interfaces/shell/shell.mojom.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ScopedShellHandle service_handle) OVERRIDE { 135 ScopedShellHandle service_handle) OVERRIDE {
136 ++num_loads_; 136 ++num_loads_;
137 } 137 }
138 virtual void OnServiceError(ServiceManager* manager, const GURL& url) 138 virtual void OnServiceError(ServiceManager* manager, const GURL& url)
139 OVERRIDE {} 139 OVERRIDE {}
140 140
141 int num_loads_; 141 int num_loads_;
142 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader); 142 DISALLOW_COPY_AND_ASSIGN(TestServiceLoader);
143 }; 143 };
144 144
145 class TestServiceInterceptor : public ServiceManager::Interceptor {
146 public:
147 TestServiceInterceptor() : call_count_(0) {}
148
149 virtual ScopedMessagePipeHandle OnConnectToClient(
150 const GURL& url, ScopedMessagePipeHandle handle) OVERRIDE {
151 ++call_count_;
152 url_ = url;
153 return handle.Pass();
154 }
155
156 std::string url_spec() const {
157 if (!url_.is_valid())
158 return "invalid url";
159 return url_.spec();
160 }
161
162 int call_count() const {
163 return call_count_;
164 }
165
166 private:
167 int call_count_;
168 GURL url_;
169 DISALLOW_COPY_AND_ASSIGN(TestServiceInterceptor);
170 };
171
145 TEST_F(ServiceManagerTest, Basic) { 172 TEST_F(ServiceManagerTest, Basic) {
146 test_client_->Test("test"); 173 test_client_->Test("test");
147 loop_.Run(); 174 loop_.Run();
148 EXPECT_EQ(std::string("test"), context_.last_test_string); 175 EXPECT_EQ(std::string("test"), context_.last_test_string);
149 } 176 }
150 177
151 TEST_F(ServiceManagerTest, ClientError) { 178 TEST_F(ServiceManagerTest, ClientError) {
152 test_client_->Test("test"); 179 test_client_->Test("test");
153 EXPECT_TRUE(HasFactoryForTestURL()); 180 EXPECT_TRUE(HasFactoryForTestURL());
154 loop_.Run(); 181 loop_.Run();
(...skipping 29 matching lines...) Expand all
184 EXPECT_EQ(0, default_loader.num_loads()); 211 EXPECT_EQ(0, default_loader.num_loads());
185 212
186 // http::test1 should go to default loader. 213 // http::test1 should go to default loader.
187 InterfacePipe<TestService, AnyInterface> pipe3; 214 InterfacePipe<TestService, AnyInterface> pipe3;
188 sm.Connect(GURL("http:test1"), pipe3.handle_to_peer.Pass()); 215 sm.Connect(GURL("http:test1"), pipe3.handle_to_peer.Pass());
189 EXPECT_EQ(1, url_loader.num_loads()); 216 EXPECT_EQ(1, url_loader.num_loads());
190 EXPECT_EQ(1, scheme_loader.num_loads()); 217 EXPECT_EQ(1, scheme_loader.num_loads());
191 EXPECT_EQ(1, default_loader.num_loads()); 218 EXPECT_EQ(1, default_loader.num_loads());
192 } 219 }
193 220
221 TEST_F(ServiceManagerTest, Interceptor) {
222 ServiceManager sm;
223 TestServiceLoader default_loader;
224 TestServiceInterceptor interceptor;
225 sm.set_default_loader(&default_loader);
226 sm.SetInterceptor(&interceptor);
227
228 std::string url("test:test3");
229 InterfacePipe<TestService, AnyInterface> pipe1;
230 sm.Connect(GURL(url), pipe1.handle_to_peer.Pass());
231 EXPECT_EQ(1, interceptor.call_count());
232 EXPECT_EQ(url, interceptor.url_spec());
233 EXPECT_EQ(1, default_loader.num_loads());
234 }
235
194 } // namespace mojo 236 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698