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/web_cache/renderer/web_cache_render_process_observer.h"
11 #include "content/public/common/content_constants.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/renderer/render_view.h"
14 #include "content/public/test/layouttest_support.h"
15 #include "content/shell/common/shell_switches.h"
16 #include "content/shell/common/webkit_test_helpers.h"
17 #include "content/shell/renderer/layout_test/layout_test_render_frame_observer.h"
18 #include "content/shell/renderer/layout_test/layout_test_render_process_observer.h"
19 #include "content/shell/renderer/layout_test/webkit_test_runner.h"
20 #include "content/shell/renderer/shell_render_view_observer.h"
21 #include "content/shell/renderer/test_runner/mock_credential_manager_client.h"
22 #include "content/shell/renderer/test_runner/web_test_interfaces.h"
23 #include "content/shell/renderer/test_runner/web_test_proxy.h"
24 #include "content/test/mock_webclipboard_impl.h"
25 #include "ppapi/shared_impl/ppapi_switches.h"
26 #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h"
27 #include "third_party/WebKit/public/web/WebPluginParams.h"
28 #include "third_party/WebKit/public/web/WebView.h"
29 #include "v8/include/v8.h"
32 #include "content/public/renderer/render_font_warmup_win.h"
33 #include "third_party/WebKit/public/web/win/WebFontRendering.h"
34 #include "third_party/skia/include/ports/SkFontMgr.h"
35 #include "ui/gfx/win/direct_write.h"
38 using blink::WebAudioDevice
;
39 using blink::WebClipboard
;
40 using blink::WebLocalFrame
;
41 using blink::WebMIDIAccessor
;
42 using blink::WebMIDIAccessorClient
;
43 using blink::WebMediaStreamCenter
;
44 using blink::WebMediaStreamCenterClient
;
45 using blink::WebPlugin
;
46 using blink::WebPluginParams
;
47 using blink::WebRTCPeerConnectionHandler
;
48 using blink::WebRTCPeerConnectionHandlerClient
;
49 using blink::WebThemeEngine
;
56 // DirectWrite only has access to %WINDIR%\Fonts by default. For developer
57 // side-loading, support kRegisterFontFiles to allow access to additional fonts.
58 void RegisterSideloadedTypefaces(SkFontMgr
* fontmgr
) {
59 std::vector
<std::string
> files
= GetSideloadFontFiles();
60 for (std::vector
<std::string
>::const_iterator
i(files
.begin());
63 SkTypeface
* typeface
= fontmgr
->createFromFile(i
->c_str());
64 DoPreSandboxWarmupForTypeface(typeface
);
65 blink::WebFontRendering::addSideloadedFontForTesting(typeface
);
72 LayoutTestContentRendererClient::LayoutTestContentRendererClient() {
73 EnableWebTestProxyCreation(
74 base::Bind(&LayoutTestContentRendererClient::WebTestProxyCreated
,
75 base::Unretained(this)));
78 if (gfx::win::ShouldUseDirectWrite())
79 RegisterSideloadedTypefaces(GetPreSandboxWarmupFontMgr());
83 LayoutTestContentRendererClient::~LayoutTestContentRendererClient() {
86 void LayoutTestContentRendererClient::RenderThreadStarted() {
87 ShellContentRendererClient::RenderThreadStarted();
88 shell_observer_
.reset(new LayoutTestRenderProcessObserver());
91 void LayoutTestContentRendererClient::RenderFrameCreated(
92 RenderFrame
* render_frame
) {
93 new LayoutTestRenderFrameObserver(render_frame
);
96 void LayoutTestContentRendererClient::RenderViewCreated(
97 RenderView
* render_view
) {
98 new ShellRenderViewObserver(render_view
);
100 WebKitTestRunner
* test_runner
= WebKitTestRunner::Get(render_view
);
101 test_runner
->Reset();
102 render_view
->GetWebView()->setSpellCheckClient(
103 test_runner
->proxy()->GetSpellCheckClient());
105 render_view
->GetWebView()->setCredentialManagerClient(
106 test_runner
->proxy()->GetCredentialManagerClientMock());
107 WebTestDelegate
* delegate
=
108 LayoutTestRenderProcessObserver::GetInstance()->test_delegate();
109 if (delegate
== static_cast<WebTestDelegate
*>(test_runner
))
110 LayoutTestRenderProcessObserver::GetInstance()->SetMainWindow(render_view
);
113 WebMediaStreamCenter
*
114 LayoutTestContentRendererClient::OverrideCreateWebMediaStreamCenter(
115 WebMediaStreamCenterClient
* client
) {
116 #if defined(ENABLE_WEBRTC)
117 WebTestInterfaces
* interfaces
=
118 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
119 return interfaces
->CreateMediaStreamCenter(client
);
125 WebRTCPeerConnectionHandler
*
126 LayoutTestContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
127 WebRTCPeerConnectionHandlerClient
* client
) {
128 #if defined(ENABLE_WEBRTC)
129 WebTestInterfaces
* interfaces
=
130 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
131 return interfaces
->CreateWebRTCPeerConnectionHandler(client
);
138 LayoutTestContentRendererClient::OverrideCreateMIDIAccessor(
139 WebMIDIAccessorClient
* client
) {
140 WebTestInterfaces
* interfaces
=
141 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
142 return interfaces
->CreateMIDIAccessor(client
);
146 LayoutTestContentRendererClient::OverrideCreateAudioDevice(
147 double sample_rate
) {
148 WebTestInterfaces
* interfaces
=
149 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
150 return interfaces
->CreateAudioDevice(sample_rate
);
153 WebClipboard
* LayoutTestContentRendererClient::OverrideWebClipboard() {
155 clipboard_
.reset(new MockWebClipboardImpl
);
156 return clipboard_
.get();
159 WebThemeEngine
* LayoutTestContentRendererClient::OverrideThemeEngine() {
160 return LayoutTestRenderProcessObserver::GetInstance()
165 void LayoutTestContentRendererClient::WebTestProxyCreated(
166 RenderView
* render_view
,
167 WebTestProxyBase
* proxy
) {
168 WebKitTestRunner
* test_runner
= new WebKitTestRunner(render_view
);
169 test_runner
->set_proxy(proxy
);
170 if (!LayoutTestRenderProcessObserver::GetInstance()->test_delegate()) {
171 LayoutTestRenderProcessObserver::GetInstance()->SetTestDelegate(
174 proxy
->SetInterfaces(
175 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces());
176 test_runner
->proxy()->SetDelegate(
177 LayoutTestRenderProcessObserver::GetInstance()->test_delegate());
180 } // namespace content