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_render_process_observer.h"
7 #include "base/command_line.h"
8 #include "components/test_runner/web_test_interfaces.h"
9 #include "content/public/common/content_client.h"
10 #include "content/public/renderer/render_thread.h"
11 #include "content/public/renderer/render_view.h"
12 #include "content/public/test/layouttest_support.h"
13 #include "content/shell/common/shell_messages.h"
14 #include "content/shell/common/shell_switches.h"
15 #include "content/shell/renderer/layout_test/blink_test_runner.h"
16 #include "third_party/WebKit/public/web/WebKit.h"
17 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
18 #include "third_party/WebKit/public/web/WebView.h"
19 #include "v8/include/v8.h"
21 using blink::WebFrame
;
22 using blink::WebRuntimeFeatures
;
27 LayoutTestRenderProcessObserver
* g_instance
= NULL
;
31 LayoutTestRenderProcessObserver
*
32 LayoutTestRenderProcessObserver::GetInstance() {
36 LayoutTestRenderProcessObserver::LayoutTestRenderProcessObserver()
37 : main_test_runner_(NULL
),
38 test_delegate_(NULL
) {
41 RenderThread::Get()->AddObserver(this);
42 EnableRendererLayoutTestMode();
45 LayoutTestRenderProcessObserver::~LayoutTestRenderProcessObserver() {
46 CHECK(g_instance
== this);
50 void LayoutTestRenderProcessObserver::SetTestDelegate(
51 test_runner::WebTestDelegate
* delegate
) {
52 test_interfaces_
->SetDelegate(delegate
);
53 test_delegate_
= delegate
;
56 void LayoutTestRenderProcessObserver::SetMainWindow(RenderView
* view
) {
57 BlinkTestRunner
* test_runner
= BlinkTestRunner::Get(view
);
58 test_interfaces_
->SetWebView(view
->GetWebView(), test_runner
->proxy());
59 main_test_runner_
= test_runner
;
62 void LayoutTestRenderProcessObserver::WebKitInitialized() {
63 // We always expose GC to layout tests.
64 std::string
flags("--expose-gc");
65 v8::V8::SetFlagsFromString(flags
.c_str(), static_cast<int>(flags
.size()));
67 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
68 switches::kStableReleaseMode
)) {
69 WebRuntimeFeatures::enableTestOnlyFeatures(true);
72 test_interfaces_
.reset(new test_runner::WebTestInterfaces
);
73 test_interfaces_
->ResetAll();
74 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
75 switches::kEnableFontAntialiasing
)) {
76 blink::setFontAntialiasingEnabledForTest(true);
81 void LayoutTestRenderProcessObserver::OnRenderProcessShutdown() {
82 test_interfaces_
.reset();
85 bool LayoutTestRenderProcessObserver::OnControlMessageReceived(
86 const IPC::Message
& message
) {
88 IPC_BEGIN_MESSAGE_MAP(LayoutTestRenderProcessObserver
, message
)
89 IPC_MESSAGE_HANDLER(ShellViewMsg_SetWebKitSourceDir
, OnSetWebKitSourceDir
)
90 IPC_MESSAGE_UNHANDLED(handled
= false)
96 void LayoutTestRenderProcessObserver::OnSetWebKitSourceDir(
97 const base::FilePath
& webkit_source_dir
) {
98 webkit_source_dir_
= webkit_source_dir
;
101 } // namespace content