1 // Copyright (c) 2012 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/shell_render_process_observer.h"
7 #include "base/command_line.h"
8 #include "content/public/common/content_client.h"
9 #include "content/public/renderer/render_thread.h"
10 #include "content/public/renderer/render_view.h"
11 #include "content/public/test/layouttest_support.h"
12 #include "content/shell/common/shell_messages.h"
13 #include "content/shell/common/shell_switches.h"
14 #include "content/shell/renderer/shell_content_renderer_client.h"
15 #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
16 #include "content/shell/renderer/webkit_test_runner.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
;
23 using WebTestRunner::WebTestDelegate
;
24 using WebTestRunner::WebTestInterfaces
;
29 ShellRenderProcessObserver
* g_instance
= NULL
;
33 ShellRenderProcessObserver
* ShellRenderProcessObserver::GetInstance() {
37 ShellRenderProcessObserver::ShellRenderProcessObserver()
38 : main_test_runner_(NULL
),
39 test_delegate_(NULL
) {
42 RenderThread::Get()->AddObserver(this);
43 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
45 EnableRendererLayoutTestMode();
48 ShellRenderProcessObserver::~ShellRenderProcessObserver() {
49 CHECK(g_instance
== this);
53 void ShellRenderProcessObserver::SetTestDelegate(WebTestDelegate
* delegate
) {
54 test_interfaces_
->setDelegate(delegate
);
55 test_delegate_
= delegate
;
58 void ShellRenderProcessObserver::SetMainWindow(RenderView
* view
) {
59 WebKitTestRunner
* test_runner
= WebKitTestRunner::Get(view
);
60 test_interfaces_
->setWebView(view
->GetWebView(), test_runner
->proxy());
61 main_test_runner_
= test_runner
;
64 void ShellRenderProcessObserver::WebKitInitialized() {
65 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree
))
68 // We always expose GC to layout tests.
69 std::string
flags("--expose-gc");
70 v8::V8::SetFlagsFromString(flags
.c_str(), static_cast<int>(flags
.size()));
72 if (!CommandLine::ForCurrentProcess()->HasSwitch(
73 switches::kStableReleaseMode
)) {
74 WebRuntimeFeatures::enableTestOnlyFeatures(true);
77 test_interfaces_
.reset(new WebTestInterfaces
);
78 test_interfaces_
->resetAll();
81 void ShellRenderProcessObserver::OnRenderProcessShutdown() {
82 test_interfaces_
.reset();
85 bool ShellRenderProcessObserver::OnControlMessageReceived(
86 const IPC::Message
& message
) {
88 IPC_BEGIN_MESSAGE_MAP(ShellRenderProcessObserver
, message
)
89 IPC_MESSAGE_HANDLER(ShellViewMsg_SetWebKitSourceDir
, OnSetWebKitSourceDir
)
90 IPC_MESSAGE_UNHANDLED(handled
= false)
96 void ShellRenderProcessObserver::OnSetWebKitSourceDir(
97 const base::FilePath
& webkit_source_dir
) {
98 webkit_source_dir_
= webkit_source_dir
;
101 } // namespace content