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

Side by Side Diff: content/browser/web_contents_binding_set_browsertest.cc

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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/memory/ptr_util.h"
7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/browser/web_contents_binding_set.h"
9 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/shell/browser/shell.h"
13 #include "content/test/test_browser_associated_interfaces.mojom.h"
14
15 namespace content {
16
17 using WebContentsBindingSetBrowserTest = ContentBrowserTest;
18
19 namespace {
20
21 class TestInterfaceBinder : public WebContentsBindingSet::TestBinder<
22 mojom::BrowserAssociatedInterfaceTestDriver> {
23 public:
24 explicit TestInterfaceBinder(const base::Closure& bind_callback)
25 : bind_callback_(bind_callback) {}
26 ~TestInterfaceBinder() override {}
27
28 void BindRequest(RenderFrameHost* frame_host,
29 mojom::BrowserAssociatedInterfaceTestDriverAssociatedRequest
30 request) override {
31 bind_callback_.Run();
32 }
33
34 private:
35 const base::Closure bind_callback_;
36
37 DISALLOW_COPY_AND_ASSIGN(TestInterfaceBinder);
38 };
39
40 } // namespace
41
42 IN_PROC_BROWSER_TEST_F(WebContentsBindingSetBrowserTest, OverrideForTesting) {
43 NavigateToURL(shell(), GURL("data:text/html,ho hum"));
44
45 // Ensure that we can add a WebContentsFrameBindingSet and then override its
46 // request handler.
47 auto* web_contents = static_cast<WebContentsImpl*>(shell()->web_contents());
48 WebContentsFrameBindingSet<mojom::BrowserAssociatedInterfaceTestDriver>
49 frame_bindings(web_contents, nullptr);
50
51 // Now override the binder for this interface. It quits |run_loop| whenever
52 // an incoming interface request is received.
53 base::RunLoop run_loop;
54 web_contents
55 ->OverrideBinderForTesting<mojom::BrowserAssociatedInterfaceTestDriver>(
56 base::MakeUnique<TestInterfaceBinder>(run_loop.QuitClosure()));
57
58 // Simulate an inbound request for the test interface. This should get routed
59 // to the overriding binder and allow the test to complete.
60 mojom::BrowserAssociatedInterfaceTestDriverAssociatedPtr override_client;
61 web_contents->OnAssociatedInterfaceRequest(
62 web_contents->GetMainFrame(),
63 mojom::BrowserAssociatedInterfaceTestDriver::Name_,
64 mojo::GetIsolatedProxy(&override_client).PassHandle());
65 run_loop.Run();
66 }
67
68 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698