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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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