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

Unified Diff: content/public/browser/web_contents_binding_set.h

Issue 2752283004: Add the ability to override WebContentsBindingSet binders for testing (Closed)
Patch Set: . Created 3 years, 9 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
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);
};
« no previous file with comments | « content/browser/web_contents_binding_set_browsertest.cc ('k') | content/public/browser/web_contents_binding_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698