Index: content/public/browser/web_contents_binding_set.h |
diff --git a/content/public/browser/web_contents_binding_set.h b/content/public/browser/web_contents_binding_set.h |
index 1d3290f08da84962f30407f06d9636dde8efad60..d65fbd8650323ea31d0bc12f6f1a266d76ea320f 100644 |
--- a/content/public/browser/web_contents_binding_set.h |
+++ b/content/public/browser/web_contents_binding_set.h |
@@ -25,7 +25,7 @@ class WebContentsImpl; |
// Base class for something which owns a mojo::AssociatedBindingSet on behalf |
// of a WebContents. See WebContentsFrameBindingSet<T> below. |
class CONTENT_EXPORT WebContentsBindingSet { |
- protected: |
+ public: |
class CONTENT_EXPORT Binder { |
public: |
virtual ~Binder() {} |
@@ -35,6 +35,37 @@ class CONTENT_EXPORT WebContentsBindingSet { |
mojo::ScopedInterfaceEndpointHandle handle); |
}; |
+ // Helper class which test code can use with SetBinderForTesting() in order |
+ // to override interface binding behavior in tests. Once this is set on a |
+ // WebContentsBindingSet via SetBinderForTesting (see below), it will live |
+ // until either it is replaced or the WebContents is destroyed. |
+ template <typename Interface> |
+ class TestBinder : public Binder { |
jam
2017/03/20 17:07:32
can this be moved to content/public/test?
Ken Rockot(use gerrit already)
2017/03/20 17:50:47
Done
|
+ public: |
+ ~TestBinder() override {} |
+ |
+ // Call for every new incoming interface request for a frame. |
+ virtual void BindRequest( |
+ RenderFrameHost* render_frame_host, |
+ mojo::AssociatedInterfaceRequest<Interface> request) = 0; |
+ |
+ private: |
+ // Binder: |
+ void OnRequestForFrame( |
+ RenderFrameHost* render_frame_host, |
+ mojo::ScopedInterfaceEndpointHandle handle) override { |
+ mojo::AssociatedInterfaceRequest<Interface> request; |
+ request.Bind(std::move(handle)); |
+ BindRequest(render_frame_host, std::move(request)); |
+ } |
+ }; |
+ |
+ template <typename Interface> |
+ void SetBinderForTesting(std::unique_ptr<TestBinder<Interface>> binder) { |
+ binder_for_testing_ = std::move(binder); |
+ } |
+ |
+ protected: |
WebContentsBindingSet(WebContents* web_contents, |
const std::string& interface_name, |
std::unique_ptr<Binder> binder); |
@@ -49,6 +80,7 @@ class CONTENT_EXPORT WebContentsBindingSet { |
const base::Closure remove_callback_; |
std::unique_ptr<Binder> binder_; |
+ std::unique_ptr<Binder> binder_for_testing_; |
DISALLOW_COPY_AND_ASSIGN(WebContentsBindingSet); |
}; |