Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / shell / renderer / layout_test / layout_test_content_renderer_client.cc
blob90a06a009169dddb4bfb6e92d097d030c156414c
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"
33 using blink::WebAudioDevice;
34 using blink::WebClipboard;
35 using blink::WebLocalFrame;
36 using blink::WebMIDIAccessor;
37 using blink::WebMIDIAccessorClient;
38 using blink::WebMediaStreamCenter;
39 using blink::WebMediaStreamCenterClient;
40 using blink::WebPlugin;
41 using blink::WebPluginParams;
42 using blink::WebRTCPeerConnectionHandler;
43 using blink::WebRTCPeerConnectionHandlerClient;
44 using blink::WebThemeEngine;
46 namespace content {
48 LayoutTestContentRendererClient::LayoutTestContentRendererClient() {
49 EnableWebTestProxyCreation(
50 base::Bind(&LayoutTestContentRendererClient::WebTestProxyCreated,
51 base::Unretained(this)));
54 LayoutTestContentRendererClient::~LayoutTestContentRendererClient() {
57 void LayoutTestContentRendererClient::RenderThreadStarted() {
58 ShellContentRendererClient::RenderThreadStarted();
59 shell_observer_.reset(new LayoutTestRenderProcessObserver());
62 void LayoutTestContentRendererClient::RenderFrameCreated(
63 RenderFrame* render_frame) {
64 new LayoutTestRenderFrameObserver(render_frame);
67 void LayoutTestContentRendererClient::RenderViewCreated(
68 RenderView* render_view) {
69 new ShellRenderViewObserver(render_view);
71 BlinkTestRunner* test_runner = BlinkTestRunner::Get(render_view);
72 test_runner->Reset();
73 render_view->GetWebView()->setSpellCheckClient(
74 test_runner->proxy()->GetSpellCheckClient());
76 render_view->GetWebView()->setCredentialManagerClient(
77 test_runner->proxy()->GetCredentialManagerClientMock());
78 test_runner::WebTestDelegate* delegate =
79 LayoutTestRenderProcessObserver::GetInstance()->test_delegate();
80 if (delegate == static_cast<test_runner::WebTestDelegate*>(test_runner))
81 LayoutTestRenderProcessObserver::GetInstance()->SetMainWindow(render_view);
84 WebMediaStreamCenter*
85 LayoutTestContentRendererClient::OverrideCreateWebMediaStreamCenter(
86 WebMediaStreamCenterClient* client) {
87 #if defined(ENABLE_WEBRTC)
88 test_runner::WebTestInterfaces* interfaces =
89 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
90 return interfaces->CreateMediaStreamCenter(client);
91 #else
92 return NULL;
93 #endif
96 WebRTCPeerConnectionHandler*
97 LayoutTestContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
98 WebRTCPeerConnectionHandlerClient* client) {
99 #if defined(ENABLE_WEBRTC)
100 test_runner::WebTestInterfaces* interfaces =
101 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
102 return interfaces->CreateWebRTCPeerConnectionHandler(client);
103 #else
104 return NULL;
105 #endif
108 WebMIDIAccessor*
109 LayoutTestContentRendererClient::OverrideCreateMIDIAccessor(
110 WebMIDIAccessorClient* client) {
111 test_runner::WebTestInterfaces* interfaces =
112 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
113 return interfaces->CreateMIDIAccessor(client);
116 WebAudioDevice*
117 LayoutTestContentRendererClient::OverrideCreateAudioDevice(
118 double sample_rate) {
119 test_runner::WebTestInterfaces* interfaces =
120 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
121 return interfaces->CreateAudioDevice(sample_rate);
124 WebClipboard* LayoutTestContentRendererClient::OverrideWebClipboard() {
125 if (!clipboard_)
126 clipboard_.reset(new MockWebClipboardImpl);
127 return clipboard_.get();
130 WebThemeEngine* LayoutTestContentRendererClient::OverrideThemeEngine() {
131 return LayoutTestRenderProcessObserver::GetInstance()
132 ->test_interfaces()
133 ->ThemeEngine();
136 scoped_ptr<blink::WebAppBannerClient>
137 LayoutTestContentRendererClient::CreateAppBannerClient(
138 RenderFrame* render_frame) {
139 test_runner::WebTestInterfaces* interfaces =
140 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces();
141 return interfaces->CreateAppBannerClient();
144 scoped_ptr<MediaStreamRendererFactory>
145 LayoutTestContentRendererClient::CreateMediaStreamRendererFactory() {
146 #if defined(ENABLE_WEBRTC)
147 return scoped_ptr<MediaStreamRendererFactory>(
148 new TestMediaStreamRendererFactory());
149 #else
150 return nullptr;
151 #endif
154 void LayoutTestContentRendererClient::WebTestProxyCreated(
155 RenderView* render_view,
156 test_runner::WebTestProxyBase* proxy) {
157 BlinkTestRunner* test_runner = new BlinkTestRunner(render_view);
158 test_runner->set_proxy(proxy);
159 if (!LayoutTestRenderProcessObserver::GetInstance()->test_delegate()) {
160 LayoutTestRenderProcessObserver::GetInstance()->SetTestDelegate(
161 test_runner);
163 proxy->SetInterfaces(
164 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces());
165 test_runner->proxy()->SetDelegate(
166 LayoutTestRenderProcessObserver::GetInstance()->test_delegate());
169 } // namespace content