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

Side by Side Diff: content/test/test_render_frame.cc

Issue 2821473002: Service CreateNewWindow on the UI thread with a new mojo interface (Closed)
Patch Set: MakeShared goodness Created 3 years, 8 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
« no previous file with comments | « content/test/test_render_frame.h ('k') | content/test/test_web_contents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/test/test_render_frame.h" 5 #include "content/test/test_render_frame.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "content/common/navigation_params.h" 8 #include "content/common/navigation_params.h"
8 #include "content/common/resource_request_body_impl.h" 9 #include "content/common/resource_request_body_impl.h"
10 #include "content/public/common/associated_interface_provider.h"
9 #include "content/public/common/browser_side_navigation_policy.h" 11 #include "content/public/common/browser_side_navigation_policy.h"
10 #include "content/public/common/resource_response.h" 12 #include "content/public/common/resource_response.h"
13 #include "content/public/test/mock_render_thread.h"
11 #include "third_party/WebKit/public/web/WebLocalFrame.h" 14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
12 15
13 namespace content { 16 namespace content {
14 17
18 class MockFrameHost : public mojom::FrameHost {
19 public:
20 MockFrameHost() : binding_(this) {}
21 ~MockFrameHost() override = default;
22
23 void CreateNewWindow(mojom::CreateNewWindowParamsPtr params,
24 const CreateNewWindowCallback& callback) override {
25 mojom::CreateNewWindowReplyPtr reply = mojom::CreateNewWindowReply::New();
26 MockRenderThread* mock_render_thread =
27 static_cast<MockRenderThread*>(RenderThread::Get());
28 mock_render_thread->OnCreateWindow(*params, reply.get());
29 callback.Run(std::move(reply));
30 }
31
32 void Bind(mojo::ScopedInterfaceEndpointHandle handle) {
33 binding_.Bind(
34 mojo::MakeAssociatedRequest<mojom::FrameHost>(std::move(handle)));
35 }
36
37 private:
38 mojo::AssociatedBinding<mojom::FrameHost> binding_;
39
40 DISALLOW_COPY_AND_ASSIGN(MockFrameHost);
41 };
42
15 // static 43 // static
16 RenderFrameImpl* TestRenderFrame::CreateTestRenderFrame( 44 RenderFrameImpl* TestRenderFrame::CreateTestRenderFrame(
17 const RenderFrameImpl::CreateParams& params) { 45 const RenderFrameImpl::CreateParams& params) {
18 return new TestRenderFrame(params); 46 return new TestRenderFrame(params);
19 } 47 }
20 48
21 TestRenderFrame::TestRenderFrame(const RenderFrameImpl::CreateParams& params) 49 TestRenderFrame::TestRenderFrame(const RenderFrameImpl::CreateParams& params)
22 : RenderFrameImpl(params) { 50 : RenderFrameImpl(params),
51 mock_frame_host_(base::MakeUnique<MockFrameHost>()) {
52 GetRemoteAssociatedInterfaces()->OverrideBinderForTesting(
53 mojom::FrameHost::Name_,
54 base::Bind(&MockFrameHost::Bind,
55 base::Unretained(mock_frame_host_.get())));
23 } 56 }
24 57
25 TestRenderFrame::~TestRenderFrame() { 58 TestRenderFrame::~TestRenderFrame() {
26 } 59 }
27 60
28 void TestRenderFrame::Navigate(const CommonNavigationParams& common_params, 61 void TestRenderFrame::Navigate(const CommonNavigationParams& common_params,
29 const StartNavigationParams& start_params, 62 const StartNavigationParams& start_params,
30 const RequestNavigationParams& request_params) { 63 const RequestNavigationParams& request_params) {
31 // PlzNavigate 64 // PlzNavigate
32 if (IsBrowserSideNavigationEnabled()) { 65 if (IsBrowserSideNavigationEnabled()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 info.url_request.CheckForBrowserSideNavigation() && 115 info.url_request.CheckForBrowserSideNavigation() &&
83 GetWebFrame()->Parent() && info.form.IsNull()) { 116 GetWebFrame()->Parent() && info.form.IsNull()) {
84 // RenderViewTest::LoadHTML already disables PlzNavigate for the main frame 117 // RenderViewTest::LoadHTML already disables PlzNavigate for the main frame
85 // requests. However if the loaded html has a subframe, the WebURLRequest 118 // requests. However if the loaded html has a subframe, the WebURLRequest
86 // will be created inside Blink and it won't have this flag set. 119 // will be created inside Blink and it won't have this flag set.
87 info.url_request.SetCheckForBrowserSideNavigation(false); 120 info.url_request.SetCheckForBrowserSideNavigation(false);
88 } 121 }
89 return RenderFrameImpl::DecidePolicyForNavigation(info); 122 return RenderFrameImpl::DecidePolicyForNavigation(info);
90 } 123 }
91 124
125 mojom::FrameHostAssociatedPtr TestRenderFrame::GetFrameHost() {
126 mojom::FrameHostAssociatedPtr ptr = RenderFrameImpl::GetFrameHost();
127
128 // Needed to ensure no deadlocks when waiting for sync IPC.
129 ptr.FlushForTesting();
Ken Rockot(use gerrit already) 2017/05/31 23:58:02 Can you please remind me exactly why this flush wa
Charlie Harrison 2017/06/01 01:35:12 Hey Ken, agreed this is not ideal especially if it
130 return ptr;
131 }
132
92 } // namespace content 133 } // namespace content
OLDNEW
« no previous file with comments | « content/test/test_render_frame.h ('k') | content/test/test_web_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698