1 // Copyright (c) 2014 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 "content/shell/renderer/layout_test/layout_test_content_renderer_client.h"
7 #include "base/callback.h"
8 #include "base/command_line.h"
9 #include "base/debug/debugger.h"
10 #include "components/test_runner/app_banner_client.h"
11 #include "components/test_runner/mock_credential_manager_client.h"
12 #include "components/test_runner/web_test_interfaces.h"
13 #include "components/test_runner/web_test_proxy.h"
14 #include "components/web_cache/renderer/web_cache_render_process_observer.h"
15 #include "content/public/common/content_constants.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/renderer/render_view.h"
18 #include "content/public/test/layouttest_support.h"
19 #include "content/shell/common/shell_switches.h"
20 #include "content/shell/renderer/layout_test/blink_test_helpers.h"
21 #include "content/shell/renderer/layout_test/blink_test_runner.h"
22 #include "content/shell/renderer/layout_test/layout_test_render_frame_observer.h"
23 #include "content/shell/renderer/layout_test/layout_test_render_process_observer.h"
24 #include "content/shell/renderer/layout_test/test_media_stream_renderer_factory.h"
25 #include "content/shell/renderer/shell_render_view_observer.h"
26 #include "content/test/mock_webclipboard_impl.h"
27 #include "ppapi/shared_impl/ppapi_switches.h"
28 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
29 #include "third_party/WebKit/public/web/WebPluginParams.h"
30 #include "third_party/WebKit/public/web/WebView.h"
31 #include "v8/include/v8.h"
34 #include "content/public/renderer/render_font_warmup_win.h"
35 #include "third_party/WebKit/public/web/win/WebFontRendering.h"
36 #include "third_party/skia/include/ports/SkFontMgr.h"
37 #include "ui/gfx/win/direct_write.h"
40 using blink::WebAudioDevice
;
41 using blink::WebClipboard
;
42 using blink::WebLocalFrame
;
43 using blink::WebMIDIAccessor
;
44 using blink::WebMIDIAccessorClient
;
45 using blink::WebMediaStreamCenter
;
46 using blink::WebMediaStreamCenterClient
;
47 using blink::WebPlugin
;
48 using blink::WebPluginParams
;
49 using blink::WebRTCPeerConnectionHandler
;
50 using blink::WebRTCPeerConnectionHandlerClient
;
51 using blink::WebThemeEngine
;
58 // DirectWrite only has access to %WINDIR%\Fonts by default. For developer
59 // side-loading, support kRegisterFontFiles to allow access to additional fonts.
60 void RegisterSideloadedTypefaces(SkFontMgr
* fontmgr
) {
61 std::vector
<std::string
> files
= GetSideloadFontFiles();
62 for (std::vector
<std::string
>::const_iterator
i(files
.begin());
65 SkTypeface
* typeface
= fontmgr
->createFromFile(i
->c_str());
66 DoPreSandboxWarmupForTypeface(typeface
);
67 blink::WebFontRendering::addSideloadedFontForTesting(typeface
);
74 LayoutTestContentRendererClient::LayoutTestContentRendererClient() {
75 EnableWebTestProxyCreation(
76 base::Bind(&LayoutTestContentRendererClient::WebTestProxyCreated
,
77 base::Unretained(this)));
80 if (gfx::win::ShouldUseDirectWrite())
81 RegisterSideloadedTypefaces(GetPreSandboxWarmupFontMgr());
85 LayoutTestContentRendererClient::~LayoutTestContentRendererClient() {
88 void LayoutTestContentRendererClient::RenderThreadStarted() {
89 ShellContentRendererClient::RenderThreadStarted();
90 shell_observer_
.reset(new LayoutTestRenderProcessObserver());
93 void LayoutTestContentRendererClient::RenderFrameCreated(
94 RenderFrame
* render_frame
) {
95 new LayoutTestRenderFrameObserver(render_frame
);
98 void LayoutTestContentRendererClient::RenderViewCreated(
99 RenderView
* render_view
) {
100 new ShellRenderViewObserver(render_view
);
102 BlinkTestRunner
* test_runner
= BlinkTestRunner::Get(render_view
);
103 test_runner
->Reset();
104 render_view
->GetWebView()->setSpellCheckClient(
105 test_runner
->proxy()->GetSpellCheckClient());
107 render_view
->GetWebView()->setCredentialManagerClient(
108 test_runner
->proxy()->GetCredentialManagerClientMock());
109 test_runner::WebTestDelegate
* delegate
=
110 LayoutTestRenderProcessObserver::GetInstance()->test_delegate();
111 if (delegate
== static_cast<test_runner::WebTestDelegate
*>(test_runner
))
112 LayoutTestRenderProcessObserver::GetInstance()->SetMainWindow(render_view
);
115 WebMediaStreamCenter
*
116 LayoutTestContentRendererClient::OverrideCreateWebMediaStreamCenter(
117 WebMediaStreamCenterClient
* client
) {
118 #if defined(ENABLE_WEBRTC)
119 test_runner::WebTestInterfaces
* interfaces
=
120 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
121 return interfaces
->CreateMediaStreamCenter(client
);
127 WebRTCPeerConnectionHandler
*
128 LayoutTestContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
129 WebRTCPeerConnectionHandlerClient
* client
) {
130 #if defined(ENABLE_WEBRTC)
131 test_runner::WebTestInterfaces
* interfaces
=
132 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
133 return interfaces
->CreateWebRTCPeerConnectionHandler(client
);
140 LayoutTestContentRendererClient::OverrideCreateMIDIAccessor(
141 WebMIDIAccessorClient
* client
) {
142 test_runner::WebTestInterfaces
* interfaces
=
143 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
144 return interfaces
->CreateMIDIAccessor(client
);
148 LayoutTestContentRendererClient::OverrideCreateAudioDevice(
149 double sample_rate
) {
150 test_runner::WebTestInterfaces
* interfaces
=
151 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
152 return interfaces
->CreateAudioDevice(sample_rate
);
155 WebClipboard
* LayoutTestContentRendererClient::OverrideWebClipboard() {
157 clipboard_
.reset(new MockWebClipboardImpl
);
158 return clipboard_
.get();
161 WebThemeEngine
* LayoutTestContentRendererClient::OverrideThemeEngine() {
162 return LayoutTestRenderProcessObserver::GetInstance()
167 scoped_ptr
<blink::WebAppBannerClient
>
168 LayoutTestContentRendererClient::CreateAppBannerClient(
169 RenderFrame
* render_frame
) {
170 test_runner::WebTestInterfaces
* interfaces
=
171 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
172 return interfaces
->CreateAppBannerClient();
175 scoped_ptr
<MediaStreamRendererFactory
>
176 LayoutTestContentRendererClient::CreateMediaStreamRendererFactory() {
177 #if defined(ENABLE_WEBRTC)
178 return scoped_ptr
<MediaStreamRendererFactory
>(
179 new TestMediaStreamRendererFactory());
185 void LayoutTestContentRendererClient::WebTestProxyCreated(
186 RenderView
* render_view
,
187 test_runner::WebTestProxyBase
* proxy
) {
188 BlinkTestRunner
* test_runner
= new BlinkTestRunner(render_view
);
189 test_runner
->set_proxy(proxy
);
190 if (!LayoutTestRenderProcessObserver::GetInstance()->test_delegate()) {
191 LayoutTestRenderProcessObserver::GetInstance()->SetTestDelegate(
194 proxy
->SetInterfaces(
195 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces());
196 test_runner
->proxy()->SetDelegate(
197 LayoutTestRenderProcessObserver::GetInstance()->test_delegate());
200 } // namespace content