Index: mojo/service_manager/service_manager_unittest.cc |
diff --git a/mojo/service_manager/service_manager_unittest.cc b/mojo/service_manager/service_manager_unittest.cc |
index dc4e432967e951499c5aacc1a12029cb1b0479a6..c7b3d2a60859bcb399c38e45b7b2108467a7d12c 100644 |
--- a/mojo/service_manager/service_manager_unittest.cc |
+++ b/mojo/service_manager/service_manager_unittest.cc |
@@ -142,6 +142,33 @@ class TestServiceLoader : public ServiceLoader { |
DISALLOW_COPY_AND_ASSIGN(TestServiceLoader); |
}; |
+class TestServiceInterceptor : public ServiceManager::Interceptor { |
+ public: |
+ TestServiceInterceptor() : call_count_(0) {} |
+ |
+ virtual ScopedMessagePipeHandle OnConnectToClient( |
+ const GURL& url, ScopedMessagePipeHandle handle) OVERRIDE { |
+ ++call_count_; |
+ url_ = url; |
+ return handle.Pass(); |
+ } |
+ |
+ std::string url_spec() const { |
+ if (!url_.is_valid()) |
+ return "invalid url"; |
+ return url_.spec(); |
+ } |
+ |
+ int call_count() const { |
+ return call_count_; |
+ } |
+ |
+ private: |
+ int call_count_; |
+ GURL url_; |
+ DISALLOW_COPY_AND_ASSIGN(TestServiceInterceptor); |
+}; |
+ |
TEST_F(ServiceManagerTest, Basic) { |
test_client_->Test("test"); |
loop_.Run(); |
@@ -191,4 +218,19 @@ TEST_F(ServiceManagerTest, SetLoaders) { |
EXPECT_EQ(1, default_loader.num_loads()); |
} |
+TEST_F(ServiceManagerTest, Interceptor) { |
+ ServiceManager sm; |
+ TestServiceLoader default_loader; |
+ TestServiceInterceptor interceptor; |
+ sm.set_default_loader(&default_loader); |
+ sm.SetInterceptor(&interceptor); |
+ |
+ std::string url("test:test3"); |
+ InterfacePipe<TestService, AnyInterface> pipe1; |
+ sm.Connect(GURL(url), pipe1.handle_to_peer.Pass()); |
+ EXPECT_EQ(1, interceptor.call_count()); |
+ EXPECT_EQ(url, interceptor.url_spec()); |
+ EXPECT_EQ(1, default_loader.num_loads()); |
+} |
+ |
} // namespace mojo |