Index: content/browser/frame_host/render_widget_host_view_child_frame_unittest.cc |
diff --git a/content/browser/frame_host/render_widget_host_view_child_frame_unittest.cc b/content/browser/frame_host/render_widget_host_view_child_frame_unittest.cc |
index aafa97939bf7fb638599e3e52a83fa7901c334c0..2f165cc0729ebc5abb3e542449483d54da0e22b6 100644 |
--- a/content/browser/frame_host/render_widget_host_view_child_frame_unittest.cc |
+++ b/content/browser/frame_host/render_widget_host_view_child_frame_unittest.cc |
@@ -6,6 +6,13 @@ |
#include "base/basictypes.h" |
#include "base/message_loop/message_loop.h" |
+#include "cc/surfaces/surface.h" |
+#include "cc/surfaces/surface_factory.h" |
+#include "cc/surfaces/surface_manager.h" |
+#include "cc/surfaces/surface_sequence.h" |
+#include "content/browser/compositor/test/no_transport_image_transport_factory.h" |
+#include "content/browser/frame_host/cross_process_frame_connector.h" |
+#include "content/browser/gpu/compositor_util.h" |
#include "content/browser/renderer_host/render_widget_host_delegate.h" |
#include "content/browser/renderer_host/render_widget_host_impl.h" |
#include "content/common/view_messages.h" |
@@ -23,30 +30,85 @@ class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
~MockRenderWidgetHostDelegate() override {} |
}; |
+class MockCrossProcessFrameConnector : public CrossProcessFrameConnector { |
+ public: |
+ MockCrossProcessFrameConnector() |
+ : CrossProcessFrameConnector(nullptr), |
+ last_scale_factor_received_(0.f), |
+ received_delegated_frame_(false) {} |
+ ~MockCrossProcessFrameConnector() override {} |
+ |
+ void ChildFrameCompositorFrameSwapped( |
+ uint32 output_surface_id, |
+ int host_id, |
+ int route_id, |
+ scoped_ptr<cc::CompositorFrame> frame) override { |
+ received_delegated_frame_ = true; |
+ last_frame_size_received_ = |
+ frame->delegated_frame_data->render_pass_list.back() |
+ ->output_rect.size(); |
+ last_scale_factor_received_ = frame->metadata.device_scale_factor; |
+ } |
+ |
+ void SetChildFrameSurface(cc::SurfaceId& surface_id, |
+ gfx::Size frame_size, |
+ float scale_factor, |
+ cc::SurfaceSequence& sequence) override { |
+ last_surface_id_received_ = surface_id; |
+ last_frame_size_received_ = frame_size; |
+ last_scale_factor_received_ = scale_factor; |
+ } |
+ |
+ cc::SurfaceId last_surface_id_received_; |
+ gfx::Size last_frame_size_received_; |
+ float last_scale_factor_received_; |
+ |
+ bool received_delegated_frame_; |
+}; |
+ |
+} // namespace |
+ |
class RenderWidgetHostViewChildFrameTest : public testing::Test { |
public: |
RenderWidgetHostViewChildFrameTest() {} |
void SetUp() override { |
browser_context_.reset(new TestBrowserContext); |
+ |
+// ImageTransportFactory doesn't exist on Android. |
+#if !defined(OS_ANDROID) |
+ ImageTransportFactory::InitializeForUnitTests( |
+ scoped_ptr<ImageTransportFactory>( |
+ new NoTransportImageTransportFactory)); |
+#endif |
+ |
MockRenderProcessHost* process_host = |
new MockRenderProcessHost(browser_context_.get()); |
widget_host_ = new RenderWidgetHostImpl( |
&delegate_, process_host, MSG_ROUTING_NONE, false); |
view_ = new RenderWidgetHostViewChildFrame(widget_host_); |
+ |
+ test_frame_connector_ = new MockCrossProcessFrameConnector(); |
+ view_->set_cross_process_frame_connector(test_frame_connector_); |
} |
void TearDown() override { |
if (view_) |
view_->Destroy(); |
delete widget_host_; |
+ delete test_frame_connector_; |
browser_context_.reset(); |
message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
message_loop_.RunUntilIdle(); |
+#if !defined(OS_ANDROID) |
+ ImageTransportFactory::Terminate(); |
+#endif |
} |
+ cc::SurfaceId surface_id() { return view_->surface_id_; } |
+ |
protected: |
base::MessageLoopForUI message_loop_; |
scoped_ptr<BrowserContext> browser_context_; |
@@ -56,12 +118,25 @@ class RenderWidgetHostViewChildFrameTest : public testing::Test { |
// destruction. |
RenderWidgetHostImpl* widget_host_; |
RenderWidgetHostViewChildFrame* view_; |
+ MockCrossProcessFrameConnector* test_frame_connector_; |
private: |
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewChildFrameTest); |
}; |
-} // namespace |
+scoped_ptr<cc::CompositorFrame> CreateDelegatedFrame(float scale_factor, |
+ gfx::Size size, |
+ 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.
|
+ scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
+ frame->metadata.device_scale_factor = scale_factor; |
+ frame->delegated_frame_data.reset(new cc::DelegatedFrameData); |
+ |
+ scoped_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); |
+ pass->SetNew(cc::RenderPassId(1, 1), gfx::Rect(size), damage, |
+ gfx::Transform()); |
+ frame->delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
+ 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.
|
+} |
TEST_F(RenderWidgetHostViewChildFrameTest, VisibilityTest) { |
view_->Show(); |
@@ -71,4 +146,42 @@ TEST_F(RenderWidgetHostViewChildFrameTest, VisibilityTest) { |
ASSERT_FALSE(view_->IsShowing()); |
} |
+// |
ncarter (slow)
2015/05/28 22:32:52
//
kenrb
2015/05/29 19:29:36
Missing test description added.
|
+TEST_F(RenderWidgetHostViewChildFrameTest, SwapCompositorFrame) { |
+ gfx::Size view_size(100, 100); |
+ gfx::Rect view_rect(view_size); |
+ float scale_factor = 1.f; |
+ |
+ view_->SetSize(view_size); |
+ view_->Show(); |
+ |
+ view_->OnSwapCompositorFrame( |
+ 0, CreateDelegatedFrame(scale_factor, view_size, view_rect)); |
+ |
+ if (UseSurfacesEnabled()) { |
+ cc::SurfaceId id = surface_id(); |
+ if (!id.is_null()) { |
+#if !defined(OS_ANDROID) |
+ ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
+ cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
+ cc::Surface* surface = manager->GetSurfaceForId(id); |
+ EXPECT_TRUE(surface); |
+ // There should be a SurfaceSequence created by the RWHVChildFrame. |
+ EXPECT_EQ(1u, surface->GetDestructionDependencyCount()); |
+#endif |
+ |
+ // Surface ID should have been passed to CrossProcessFrameConnector to |
+ // be sent to the embedding renderer. |
+ EXPECT_EQ(id, test_frame_connector_->last_surface_id_received_); |
+ EXPECT_EQ(view_size, test_frame_connector_->last_frame_size_received_); |
+ EXPECT_EQ(scale_factor, |
+ test_frame_connector_->last_scale_factor_received_); |
+ } |
+ } else { |
+ EXPECT_TRUE(test_frame_connector_->received_delegated_frame_); |
+ EXPECT_EQ(view_size, test_frame_connector_->last_frame_size_received_); |
+ EXPECT_EQ(scale_factor, test_frame_connector_->last_scale_factor_received_); |
+ } |
+} |
+ |
} // namespace content |