Add the ability to override WebContentsBindingSet binders for testing

WebContentsBindingSet and WebContentsFrameBindingSet<T> provide a simple
way of binding Channel-associated interfaces which require RenderFrameHost
context for dispatch.

Currently there's no simple way to override incoming request handlers
for integration testing. This adds that.

BUG=577685

Review-Url: https://codereview.chromium.org/2752283004
Cr-Commit-Position: refs/heads/master@{#458231}
diff --git a/content/public/browser/web_contents_binding_set.cc b/content/public/browser/web_contents_binding_set.cc
index bf46ed6..39e9711 100644
--- a/content/public/browser/web_contents_binding_set.cc
+++ b/content/public/browser/web_contents_binding_set.cc
@@ -20,9 +20,8 @@
 WebContentsBindingSet::WebContentsBindingSet(WebContents* web_contents,
                                              const std::string& interface_name,
                                              std::unique_ptr<Binder> binder)
-    : remove_callback_(
-          static_cast<WebContentsImpl*>(web_contents)->AddBindingSet(
-              interface_name, this)),
+    : remove_callback_(static_cast<WebContentsImpl*>(web_contents)
+                           ->AddBindingSet(interface_name, this)),
       binder_(std::move(binder)) {}
 
 WebContentsBindingSet::~WebContentsBindingSet() {
@@ -30,12 +29,18 @@
 }
 
 void WebContentsBindingSet::CloseAllBindings() {
+  binder_for_testing_.reset();
   binder_.reset();
 }
 
 void WebContentsBindingSet::OnRequestForFrame(
     RenderFrameHost* render_frame_host,
     mojo::ScopedInterfaceEndpointHandle handle) {
+  if (binder_for_testing_) {
+    binder_for_testing_->OnRequestForFrame(render_frame_host,
+                                           std::move(handle));
+    return;
+  }
   DCHECK(binder_);
   binder_->OnRequestForFrame(render_frame_host, std::move(handle));
 }