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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/debug/leak_annotations.h"
7 #include "content/common/frame_messages.h"
8 #include "content/common/view_messages.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/frame_load_waiter.h"
11 #include "content/public/test/render_view_test.h"
12 #include "content/renderer/render_frame_impl.h"
13 #include "content/renderer/render_view_impl.h"
14 #include "content/test/fake_compositor_dependencies.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebURLRequest.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
20 const int32 kSubframeRouteId
= 20;
21 const int32 kSubframeWidgetRouteId
= 21;
22 const int32 kFrameProxyRouteId
= 22;
23 const int32 kSubframeSurfaceId
= 43;
28 // RenderFrameImplTest creates a RenderFrameImpl that is a child of the
29 // main frame, and has its own RenderWidget. This behaves like an out
30 // of process frame even though it is in the same process as its parent.
31 class RenderFrameImplTest
: public RenderViewTest
{
33 ~RenderFrameImplTest() override
{}
35 void SetUp() override
{
36 RenderViewTest::SetUp();
37 EXPECT_FALSE(static_cast<RenderFrameImpl
*>(view_
->GetMainRenderFrame())
40 FrameMsg_NewFrame_WidgetParams widget_params
;
41 widget_params
.routing_id
= kSubframeWidgetRouteId
;
42 widget_params
.surface_id
= kSubframeSurfaceId
;
43 widget_params
.hidden
= false;
45 base::CommandLine::ForCurrentProcess()->AppendSwitch(
46 switches::kSitePerProcess
);
48 LoadHTML("Parent frame <iframe name='frame'></iframe>");
50 RenderFrameImpl::FromWebFrame(
51 view_
->GetMainRenderFrame()->GetWebFrame()->firstChild())
52 ->OnSwapOut(kFrameProxyRouteId
, false, FrameReplicationState());
54 RenderFrameImpl::CreateFrame(kSubframeRouteId
, kFrameProxyRouteId
,
55 MSG_ROUTING_NONE
, MSG_ROUTING_NONE
,
56 FrameReplicationState(), &compositor_deps_
,
59 frame_
= RenderFrameImpl::FromRoutingID(kSubframeRouteId
);
60 EXPECT_TRUE(frame_
->is_subframe_
);
63 void TearDown() override
{
64 #if defined(LEAK_SANITIZER)
65 // Do this before shutting down V8 in RenderViewTest::TearDown().
66 // http://crbug.com/328552
67 __lsan_do_leak_check();
69 RenderViewTest::TearDown();
72 RenderFrameImpl
* frame() { return frame_
; }
74 content::RenderWidget
* frame_widget() const {
75 return frame_
->render_widget_
.get();
79 RenderFrameImpl
* frame_
;
80 FakeCompositorDependencies compositor_deps_
;
83 class RenderFrameTestObserver
: public RenderFrameObserver
{
85 explicit RenderFrameTestObserver(RenderFrame
* render_frame
)
86 : RenderFrameObserver(render_frame
), visible_(false) {}
88 ~RenderFrameTestObserver() override
{}
90 void WasShown() override
{ visible_
= true; }
91 void WasHidden() override
{ visible_
= false; }
93 bool visible() { return visible_
; }
99 #if defined(OS_ANDROID)
100 // See https://crbug.com/472717
101 #define MAYBE_SubframeWidget DISABLED_SubframeWidget
102 #define MAYBE_FrameResize DISABLED_FrameResize
103 #define MAYBE_FrameWasShown DISABLED_FrameWasShown
105 #define MAYBE_SubframeWidget SubframeWidget
106 #define MAYBE_FrameResize FrameResize
107 #define MAYBE_FrameWasShown FrameWasShown
110 // Verify that a frame with a RenderFrameProxy as a parent has its own
112 TEST_F(RenderFrameImplTest
, MAYBE_SubframeWidget
) {
113 EXPECT_TRUE(frame_widget());
114 EXPECT_NE(frame_widget(), (content::RenderWidget
*)view_
);
117 // Verify a subframe RenderWidget properly processes its viewport being
119 TEST_F(RenderFrameImplTest
, MAYBE_FrameResize
) {
120 ViewMsg_Resize_Params resize_params
;
121 gfx::Size
size(200, 200);
122 resize_params
.screen_info
= blink::WebScreenInfo();
123 resize_params
.new_size
= size
;
124 resize_params
.physical_backing_size
= size
;
125 resize_params
.top_controls_height
= 0.f
;
126 resize_params
.top_controls_shrink_blink_size
= false;
127 resize_params
.resizer_rect
= gfx::Rect();
128 resize_params
.is_fullscreen_granted
= false;
130 ViewMsg_Resize
resize_message(0, resize_params
);
131 frame_widget()->OnMessageReceived(resize_message
);
133 EXPECT_EQ(frame_widget()->webwidget()->size(), blink::WebSize(size
));
136 // Verify a subframe RenderWidget properly processes a WasShown message.
137 TEST_F(RenderFrameImplTest
, MAYBE_FrameWasShown
) {
138 RenderFrameTestObserver
observer(frame());
140 ViewMsg_WasShown
was_shown_message(0, true, ui::LatencyInfo());
141 frame_widget()->OnMessageReceived(was_shown_message
);
143 EXPECT_FALSE(frame_widget()->is_hidden());
144 EXPECT_TRUE(observer
.visible());