[DevTools] Remove forwarded connections counting
[chromium-blink-merge.git] / content / shell / renderer / layout_test / layout_test_render_process_observer.cc
blob04d4d38bd5ab0eab0bb721334f06021f56bae054
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 "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/layout_test/webkit_test_runner.h"
15 #include "content/shell/renderer/test_runner/web_test_interfaces.h"
16 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
17 #include "third_party/WebKit/public/web/WebView.h"
18 #include "v8/include/v8.h"
20 using blink::WebFrame;
21 using blink::WebRuntimeFeatures;
23 namespace content {
25 namespace {
26 LayoutTestRenderProcessObserver* g_instance = NULL;
29 // static
30 LayoutTestRenderProcessObserver*
31 LayoutTestRenderProcessObserver::GetInstance() {
32 return g_instance;
35 LayoutTestRenderProcessObserver::LayoutTestRenderProcessObserver()
36 : main_test_runner_(NULL),
37 test_delegate_(NULL) {
38 CHECK(!g_instance);
39 g_instance = this;
40 RenderThread::Get()->AddObserver(this);
41 EnableRendererLayoutTestMode();
44 LayoutTestRenderProcessObserver::~LayoutTestRenderProcessObserver() {
45 CHECK(g_instance == this);
46 g_instance = NULL;
49 void LayoutTestRenderProcessObserver::SetTestDelegate(
50 WebTestDelegate* delegate) {
51 test_interfaces_->SetDelegate(delegate);
52 test_delegate_ = delegate;
55 void LayoutTestRenderProcessObserver::SetMainWindow(RenderView* view) {
56 WebKitTestRunner* test_runner = WebKitTestRunner::Get(view);
57 test_interfaces_->SetWebView(view->GetWebView(), test_runner->proxy());
58 main_test_runner_ = test_runner;
61 void LayoutTestRenderProcessObserver::WebKitInitialized() {
62 // We always expose GC to layout tests.
63 std::string flags("--expose-gc");
64 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
66 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
67 switches::kStableReleaseMode)) {
68 WebRuntimeFeatures::enableTestOnlyFeatures(true);
71 test_interfaces_.reset(new WebTestInterfaces);
72 test_interfaces_->ResetAll();
75 void LayoutTestRenderProcessObserver::OnRenderProcessShutdown() {
76 test_interfaces_.reset();
79 bool LayoutTestRenderProcessObserver::OnControlMessageReceived(
80 const IPC::Message& message) {
81 bool handled = true;
82 IPC_BEGIN_MESSAGE_MAP(LayoutTestRenderProcessObserver, message)
83 IPC_MESSAGE_HANDLER(ShellViewMsg_SetWebKitSourceDir, OnSetWebKitSourceDir)
84 IPC_MESSAGE_UNHANDLED(handled = false)
85 IPC_END_MESSAGE_MAP()
87 return handled;
90 void LayoutTestRenderProcessObserver::OnSetWebKitSourceDir(
91 const base::FilePath& webkit_source_dir) {
92 webkit_source_dir_ = webkit_source_dir;
95 } // namespace content