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

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/public/test/web_contents_binding_set_test_binder.h"
13 #include "content/shell/browser/shell.h"
14 #include "content/test/test_browser_associated_interfaces.mojom.h"
15
16 namespace content {
17
18 using WebContentsBindingSetBrowserTest = ContentBrowserTest;
19
20 namespace {
21
22 class TestInterfaceBinder : public WebContentsBindingSetTestBinder<
23 mojom::BrowserAssociatedInterfaceTestDriver> {
24 public:
25 explicit TestInterfaceBinder(const base::Closure& bind_callback)
26 : bind_callback_(bind_callback) {}
27 ~TestInterfaceBinder() override {}
28
29 void BindRequest(RenderFrameHost* frame_host,
30 mojom::BrowserAssociatedInterfaceTestDriverAssociatedRequest
31 request) override {
32 bind_callback_.Run();
33 }
34
35 private:
36 const base::Closure bind_callback_;
37
38 DISALLOW_COPY_AND_ASSIGN(TestInterfaceBinder);
39 };
40
41 } // namespace
42
43 IN_PROC_BROWSER_TEST_F(WebContentsBindingSetBrowserTest, OverrideForTesting) {
44 NavigateToURL(shell(), GURL("data:text/html,ho hum"));
45
46 // Ensure that we can add a WebContentsFrameBindingSet and then override its
47 // request handler.
48 auto* web_contents = static_cast<WebContentsImpl*>(shell()->web_contents());
49 WebContentsFrameBindingSet<mojom::BrowserAssociatedInterfaceTestDriver>
50 frame_bindings(web_contents, nullptr);
51
52 // Now override the binder for this interface. It quits |run_loop| whenever
53 // an incoming interface request is received.
54 base::RunLoop run_loop;
55 web_contents
56 ->OverrideBinderForTesting<mojom::BrowserAssociatedInterfaceTestDriver>(
57 base::MakeUnique<TestInterfaceBinder>(run_loop.QuitClosure()));
58
59 // Simulate an inbound request for the test interface. This should get routed
60 // to the overriding binder and allow the test to complete.
61 mojom::BrowserAssociatedInterfaceTestDriverAssociatedPtr override_client;
62 web_contents->OnAssociatedInterfaceRequest(
63 web_contents->GetMainFrame(),
64 mojom::BrowserAssociatedInterfaceTestDriver::Name_,
65 mojo::MakeIsolatedRequest(&override_client).PassHandle());
66 run_loop.Run();
67 }
68
69 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/browser/web_contents_binding_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698