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

Side by Side Diff: content/browser/frame_host/render_widget_host_view_child_frame_unittest.cc

Issue 1094113003: Allow out-of-process iframes to render to compositing surfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Destroy Surface when resetting id Created 5 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/frame_host/render_widget_host_view_child_frame.h" 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "cc/surfaces/surface.h"
10 #include "cc/surfaces/surface_factory.h"
11 #include "cc/surfaces/surface_manager.h"
12 #include "cc/surfaces/surface_sequence.h"
13 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
14 #include "content/browser/frame_host/cross_process_frame_connector.h"
15 #include "content/browser/gpu/compositor_util.h"
9 #include "content/browser/renderer_host/render_widget_host_delegate.h" 16 #include "content/browser/renderer_host/render_widget_host_delegate.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 17 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
12 #include "content/public/browser/render_widget_host_view.h" 19 #include "content/public/browser/render_widget_host_view.h"
13 #include "content/public/test/mock_render_process_host.h" 20 #include "content/public/test/mock_render_process_host.h"
14 #include "content/public/test/test_browser_context.h" 21 #include "content/public/test/test_browser_context.h"
15 #include "content/test/test_render_view_host.h" 22 #include "content/test/test_render_view_host.h"
16 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
17 24
18 namespace content { 25 namespace content {
19 namespace { 26 namespace {
20 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { 27 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
21 public: 28 public:
22 MockRenderWidgetHostDelegate() {} 29 MockRenderWidgetHostDelegate() {}
23 ~MockRenderWidgetHostDelegate() override {} 30 ~MockRenderWidgetHostDelegate() override {}
24 }; 31 };
25 32
33 class MockCrossProcessFrameConnector : public CrossProcessFrameConnector {
34 public:
35 MockCrossProcessFrameConnector()
36 : CrossProcessFrameConnector(nullptr),
37 last_scale_factor_received_(0.f),
38 received_delegated_frame_(false) {}
39 ~MockCrossProcessFrameConnector() override {}
40
41 void ChildFrameCompositorFrameSwapped(
42 uint32 output_surface_id,
43 int host_id,
44 int route_id,
45 scoped_ptr<cc::CompositorFrame> frame) override {
46 received_delegated_frame_ = true;
47 last_frame_size_received_ =
48 frame->delegated_frame_data->render_pass_list.back()
49 ->output_rect.size();
50 last_scale_factor_received_ = frame->metadata.device_scale_factor;
51 }
52
53 void SetChildFrameSurface(cc::SurfaceId& surface_id,
54 gfx::Size frame_size,
55 float scale_factor,
56 cc::SurfaceSequence& sequence) override {
57 last_surface_id_received_ = surface_id;
58 last_frame_size_received_ = frame_size;
59 last_scale_factor_received_ = scale_factor;
60 }
61
62 cc::SurfaceId last_surface_id_received_;
63 gfx::Size last_frame_size_received_;
64 float last_scale_factor_received_;
65
66 bool received_delegated_frame_;
67 };
68
69 } // namespace
70
26 class RenderWidgetHostViewChildFrameTest : public testing::Test { 71 class RenderWidgetHostViewChildFrameTest : public testing::Test {
27 public: 72 public:
28 RenderWidgetHostViewChildFrameTest() {} 73 RenderWidgetHostViewChildFrameTest() {}
29 74
30 void SetUp() override { 75 void SetUp() override {
31 browser_context_.reset(new TestBrowserContext); 76 browser_context_.reset(new TestBrowserContext);
77
78 // ImageTransportFactory doesn't exist on Android.
79 #if !defined(OS_ANDROID)
80 ImageTransportFactory::InitializeForUnitTests(
81 scoped_ptr<ImageTransportFactory>(
82 new NoTransportImageTransportFactory));
83 #endif
84
32 MockRenderProcessHost* process_host = 85 MockRenderProcessHost* process_host =
33 new MockRenderProcessHost(browser_context_.get()); 86 new MockRenderProcessHost(browser_context_.get());
34 widget_host_ = new RenderWidgetHostImpl( 87 widget_host_ = new RenderWidgetHostImpl(
35 &delegate_, process_host, MSG_ROUTING_NONE, false); 88 &delegate_, process_host, MSG_ROUTING_NONE, false);
36 view_ = new RenderWidgetHostViewChildFrame(widget_host_); 89 view_ = new RenderWidgetHostViewChildFrame(widget_host_);
90
91 test_frame_connector_ = new MockCrossProcessFrameConnector();
92 view_->set_cross_process_frame_connector(test_frame_connector_);
37 } 93 }
38 94
39 void TearDown() override { 95 void TearDown() override {
40 if (view_) 96 if (view_)
41 view_->Destroy(); 97 view_->Destroy();
42 delete widget_host_; 98 delete widget_host_;
99 delete test_frame_connector_;
43 100
44 browser_context_.reset(); 101 browser_context_.reset();
45 102
46 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); 103 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
47 message_loop_.RunUntilIdle(); 104 message_loop_.RunUntilIdle();
105 #if !defined(OS_ANDROID)
106 ImageTransportFactory::Terminate();
107 #endif
48 } 108 }
49 109
110 cc::SurfaceId surface_id() { return view_->surface_id_; }
111
50 protected: 112 protected:
51 base::MessageLoopForUI message_loop_; 113 base::MessageLoopForUI message_loop_;
52 scoped_ptr<BrowserContext> browser_context_; 114 scoped_ptr<BrowserContext> browser_context_;
53 MockRenderWidgetHostDelegate delegate_; 115 MockRenderWidgetHostDelegate delegate_;
54 116
55 // Tests should set these to NULL if they've already triggered their 117 // Tests should set these to NULL if they've already triggered their
56 // destruction. 118 // destruction.
57 RenderWidgetHostImpl* widget_host_; 119 RenderWidgetHostImpl* widget_host_;
58 RenderWidgetHostViewChildFrame* view_; 120 RenderWidgetHostViewChildFrame* view_;
121 MockCrossProcessFrameConnector* test_frame_connector_;
59 122
60 private: 123 private:
61 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewChildFrameTest); 124 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewChildFrameTest);
62 }; 125 };
63 126
64 } // namespace 127 scoped_ptr<cc::CompositorFrame> CreateDelegatedFrame(float scale_factor,
128 gfx::Size size,
129 gfx::Rect damage) {
dcheng 2015/05/28 22:16:30 gfx::Rect should be passed a const ref.
kenrb 2015/05/29 19:29:36 Done.
130 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
131 frame->metadata.device_scale_factor = scale_factor;
132 frame->delegated_frame_data.reset(new cc::DelegatedFrameData);
133
134 scoped_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
135 pass->SetNew(cc::RenderPassId(1, 1), gfx::Rect(size), damage,
136 gfx::Transform());
137 frame->delegated_frame_data->render_pass_list.push_back(pass.Pass());
138 return frame.Pass();
dcheng 2015/05/28 22:16:30 This Pass() should be unnecessary due to NRVO.
kenrb 2015/05/29 19:29:36 Done.
139 }
65 140
66 TEST_F(RenderWidgetHostViewChildFrameTest, VisibilityTest) { 141 TEST_F(RenderWidgetHostViewChildFrameTest, VisibilityTest) {
67 view_->Show(); 142 view_->Show();
68 ASSERT_TRUE(view_->IsShowing()); 143 ASSERT_TRUE(view_->IsShowing());
69 144
70 view_->Hide(); 145 view_->Hide();
71 ASSERT_FALSE(view_->IsShowing()); 146 ASSERT_FALSE(view_->IsShowing());
72 } 147 }
73 148
149 //
ncarter (slow) 2015/05/28 22:32:52 //
kenrb 2015/05/29 19:29:36 Missing test description added.
150 TEST_F(RenderWidgetHostViewChildFrameTest, SwapCompositorFrame) {
151 gfx::Size view_size(100, 100);
152 gfx::Rect view_rect(view_size);
153 float scale_factor = 1.f;
154
155 view_->SetSize(view_size);
156 view_->Show();
157
158 view_->OnSwapCompositorFrame(
159 0, CreateDelegatedFrame(scale_factor, view_size, view_rect));
160
161 if (UseSurfacesEnabled()) {
162 cc::SurfaceId id = surface_id();
163 if (!id.is_null()) {
164 #if !defined(OS_ANDROID)
165 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
166 cc::SurfaceManager* manager = factory->GetSurfaceManager();
167 cc::Surface* surface = manager->GetSurfaceForId(id);
168 EXPECT_TRUE(surface);
169 // There should be a SurfaceSequence created by the RWHVChildFrame.
170 EXPECT_EQ(1u, surface->GetDestructionDependencyCount());
171 #endif
172
173 // Surface ID should have been passed to CrossProcessFrameConnector to
174 // be sent to the embedding renderer.
175 EXPECT_EQ(id, test_frame_connector_->last_surface_id_received_);
176 EXPECT_EQ(view_size, test_frame_connector_->last_frame_size_received_);
177 EXPECT_EQ(scale_factor,
178 test_frame_connector_->last_scale_factor_received_);
179 }
180 } else {
181 EXPECT_TRUE(test_frame_connector_->received_delegated_frame_);
182 EXPECT_EQ(view_size, test_frame_connector_->last_frame_size_received_);
183 EXPECT_EQ(scale_factor, test_frame_connector_->last_scale_factor_received_);
184 }
185 }
186
74 } // namespace content 187 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698