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 "content/common/frame_messages.h"
7 #include "content/common/view_messages.h"
8 #include "content/public/common/content_switches.h"
9 #include "content/public/test/frame_load_waiter.h"
10 #include "content/public/test/render_view_test.h"
11 #include "content/renderer/render_frame_impl.h"
12 #include "content/renderer/render_view_impl.h"
13 #include "content/test/fake_compositor_dependencies.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/WebURLRequest.h"
16 #include "third_party/WebKit/public/web/WebLocalFrame.h"
19 const int32 kSubframeRouteId
= 20;
20 const int32 kSubframeWidgetRouteId
= 21;
21 const int32 kFrameProxyRouteId
= 22;
22 const int32 kSubframeSurfaceId
= 43;
27 // RenderFrameImplTest creates a RenderFrameImpl that is a child of the
28 // main frame, and has its own RenderWidget. This behaves like an out
29 // of process frame even though it is in the same process as its parent.
30 class RenderFrameImplTest
: public RenderViewTest
{
32 ~RenderFrameImplTest() override
{}
34 void SetUp() override
{
35 RenderViewTest::SetUp();
36 EXPECT_FALSE(static_cast<RenderFrameImpl
*>(view_
->GetMainRenderFrame())
39 FrameMsg_NewFrame_WidgetParams widget_params
;
40 widget_params
.routing_id
= kSubframeWidgetRouteId
;
41 widget_params
.surface_id
= kSubframeSurfaceId
;
42 widget_params
.hidden
= false;
44 compositor_deps_
.reset(new FakeCompositorDependencies
);
46 base::CommandLine::ForCurrentProcess()->AppendSwitch(
47 switches::kSitePerProcess
);
49 LoadHTML("Parent frame <iframe name='frame'></iframe>");
51 RenderFrameImpl::FromWebFrame(
52 view_
->GetMainRenderFrame()->GetWebFrame()->firstChild())
53 ->OnSwapOut(kFrameProxyRouteId
, false, FrameReplicationState());
55 RenderFrameImpl::CreateFrame(kSubframeRouteId
, kFrameProxyRouteId
,
56 MSG_ROUTING_NONE
, MSG_ROUTING_NONE
,
57 FrameReplicationState(),
58 compositor_deps_
.get(), widget_params
);
60 frame_
= RenderFrameImpl::FromRoutingID(kSubframeRouteId
);
61 EXPECT_TRUE(frame_
->is_subframe_
);
64 // Loads the given HTML into the frame as a data: URL and blocks until
65 // the navigation is committed.
66 void LoadHTMLInFrame(const char* html
) {
67 std::string url_str
= "data:text/html;charset=utf-8,";
70 frame_
->GetWebFrame()->loadRequest(blink::WebURLRequest(url
));
71 // The load actually happens asynchronously, so we pump messages to process
72 // the pending continuation.
73 FrameLoadWaiter(frame_
).Wait();
76 RenderFrameImpl
* frame() { return frame_
; }
78 content::RenderWidget
* FrameWidget() { return frame_
->render_widget_
.get(); }
81 RenderFrameImpl
* frame_
;
82 scoped_ptr
<CompositorDependencies
> compositor_deps_
;
85 class RenderFrameTestObserver
: public RenderFrameObserver
{
87 RenderFrameTestObserver(RenderFrame
* render_frame
)
88 : RenderFrameObserver(render_frame
), visible_(false) {}
90 ~RenderFrameTestObserver() override
{}
92 void WasShown() override
{ visible_
= true; }
93 void WasHidden() override
{ visible_
= false; }
95 bool visible() { return visible_
; }
101 #if defined(OS_ANDROID)
102 // See https://crbug.com/472717
103 #define MAYBE_SubframeWidget DISABLED_SubframeWidget
104 #define MAYBE_FrameResize DISABLED_FrameResize
105 #define MAYBE_FrameWasShown DISABLED_FrameWasShown
107 #define MAYBE_SubframeWidget SubframeWidget
108 #define MAYBE_FrameResize FrameResize
109 #define MAYBE_FrameWasShown FrameWasShown
112 // Verify that a frame with a RenderFrameProxy as a parent has its own
114 TEST_F(RenderFrameImplTest
, MAYBE_SubframeWidget
) {
115 EXPECT_TRUE(FrameWidget());
116 EXPECT_NE(FrameWidget(), (content::RenderWidget
*)view_
);
119 // Verify a subframe RenderWidget properly processes its viewport being
121 TEST_F(RenderFrameImplTest
, MAYBE_FrameResize
) {
122 ViewMsg_Resize_Params resize_params
;
123 gfx::Size
size(200, 200);
124 resize_params
.screen_info
= blink::WebScreenInfo();
125 resize_params
.new_size
= size
;
126 resize_params
.physical_backing_size
= size
;
127 resize_params
.top_controls_height
= 0.f
;
128 resize_params
.top_controls_shrink_blink_size
= false;
129 resize_params
.resizer_rect
= gfx::Rect();
130 resize_params
.is_fullscreen_granted
= false;
132 scoped_ptr
<IPC::Message
> resize_message(new ViewMsg_Resize(0, resize_params
));
133 FrameWidget()->OnMessageReceived(*resize_message
);
135 EXPECT_EQ(FrameWidget()->webwidget()->size(), blink::WebSize(size
));
138 // Verify a subframe RenderWidget properly processes a WasShown message.
139 TEST_F(RenderFrameImplTest
, MAYBE_FrameWasShown
) {
140 RenderFrameTestObserver
observer(frame());
142 scoped_ptr
<IPC::Message
> was_shown_message(
143 new ViewMsg_WasShown(0, true, ui::LatencyInfo()));
144 FrameWidget()->OnMessageReceived(*was_shown_message
);
146 EXPECT_FALSE(FrameWidget()->is_hidden());
147 EXPECT_TRUE(observer
.visible());