blob: c405f477facb83b38d52217ede56d7ed7d7bae6b [file] [log] [blame]
[email protected]8ed8bf432014-08-11 19:47:551// Copyright 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.
4
jochen73e711c2015-06-03 10:01:465#include "components/test_runner/test_interfaces.h"
[email protected]8ed8bf432014-08-11 19:47:556
avi5dd91f82015-12-25 22:30:467#include <stddef.h>
8
[email protected]8ed8bf432014-08-11 19:47:559#include <string>
10
pfeldman6672e7d2015-04-14 10:08:5811#include "base/json/json_writer.h"
12#include "base/json/string_escape.h"
[email protected]8ed8bf432014-08-11 19:47:5513#include "base/logging.h"
14#include "base/strings/stringprintf.h"
jochenc8337812015-05-14 01:11:5815#include "base/values.h"
jochen73e711c2015-06-03 10:01:4616#include "components/test_runner/accessibility_controller.h"
17#include "components/test_runner/app_banner_client.h"
jochen73e711c2015-06-03 10:01:4618#include "components/test_runner/gamepad_controller.h"
sadrul43405772015-10-15 23:12:3719#include "components/test_runner/gc_controller.h"
jochen73e711c2015-06-03 10:01:4620#include "components/test_runner/test_runner.h"
21#include "components/test_runner/text_input_controller.h"
22#include "components/test_runner/web_test_proxy.h"
[email protected]8ed8bf432014-08-11 19:47:5523#include "third_party/WebKit/public/platform/WebURL.h"
24#include "third_party/WebKit/public/web/WebCache.h"
25#include "third_party/WebKit/public/web/WebKit.h"
26#include "third_party/WebKit/public/web/WebView.h"
27
jochenf5f31752015-06-03 12:06:3428namespace test_runner {
[email protected]8ed8bf432014-08-11 19:47:5529
30TestInterfaces::TestInterfaces()
31 : accessibility_controller_(new AccessibilityController()),
[email protected]8ed8bf432014-08-11 19:47:5532 text_input_controller_(new TextInputController()),
33 test_runner_(new TestRunner(this)),
benwells0c0d3f12015-05-25 01:03:1734 delegate_(nullptr),
35 app_banner_client_(nullptr) {
[email protected]8ed8bf432014-08-11 19:47:5536 blink::setLayoutTestMode(true);
[email protected]8ed8bf432014-08-11 19:47:5537 // NOTE: please don't put feature specific enable flags here,
38 // instead add them to RuntimeEnabledFeatures.in
39
40 ResetAll();
41}
42
43TestInterfaces::~TestInterfaces() {
lukaszaf41da4b2016-04-14 22:33:2044 accessibility_controller_->SetWebView(nullptr);
[email protected]8ed8bf432014-08-11 19:47:5545 // gamepad_controller_ doesn't depend on WebView.
lukaszaf41da4b2016-04-14 22:33:2046 text_input_controller_->SetWebView(nullptr);
47 test_runner_->SetWebView(nullptr);
[email protected]8ed8bf432014-08-11 19:47:5548
lukaszaf41da4b2016-04-14 22:33:2049 accessibility_controller_->SetDelegate(nullptr);
lukaszaf41da4b2016-04-14 22:33:2050 // gamepad_controller_ ignores SetDelegate(nullptr)
[email protected]8ed8bf432014-08-11 19:47:5551 // text_input_controller_ doesn't depend on WebTestDelegate.
lukaszaf41da4b2016-04-14 22:33:2052 test_runner_->SetDelegate(nullptr);
[email protected]8ed8bf432014-08-11 19:47:5553}
54
55void TestInterfaces::SetWebView(blink::WebView* web_view,
56 WebTestProxyBase* proxy) {
[email protected]8ed8bf432014-08-11 19:47:5557 accessibility_controller_->SetWebView(web_view);
[email protected]8ed8bf432014-08-11 19:47:5558 // gamepad_controller_ doesn't depend on WebView.
59 text_input_controller_->SetWebView(web_view);
lukaszaf41da4b2016-04-14 22:33:2060 test_runner_->SetWebView(web_view);
[email protected]8ed8bf432014-08-11 19:47:5561}
62
63void TestInterfaces::SetDelegate(WebTestDelegate* delegate) {
64 accessibility_controller_->SetDelegate(delegate);
[email protected]9c41b462014-08-19 15:51:3465 gamepad_controller_ = GamepadController::Create(delegate);
[email protected]8ed8bf432014-08-11 19:47:5566 // text_input_controller_ doesn't depend on WebTestDelegate.
67 test_runner_->SetDelegate(delegate);
68 delegate_ = delegate;
69}
70
71void TestInterfaces::BindTo(blink::WebFrame* frame) {
72 accessibility_controller_->Install(frame);
[email protected]9c41b462014-08-19 15:51:3473 if (gamepad_controller_)
74 gamepad_controller_->Install(frame);
[email protected]8ed8bf432014-08-11 19:47:5575 text_input_controller_->Install(frame);
76 test_runner_->Install(frame);
sadrul43405772015-10-15 23:12:3777 GCController::Install(frame);
[email protected]8ed8bf432014-08-11 19:47:5578}
79
80void TestInterfaces::ResetTestHelperControllers() {
81 accessibility_controller_->Reset();
[email protected]9c41b462014-08-19 15:51:3482 if (gamepad_controller_)
83 gamepad_controller_->Reset();
[email protected]8ed8bf432014-08-11 19:47:5584 // text_input_controller_ doesn't have any state to reset.
85 blink::WebCache::clear();
lukasza335bb762016-04-22 16:44:0386
87 for (WebTestProxyBase* web_test_proxy_base : window_list_)
88 web_test_proxy_base->Reset();
[email protected]8ed8bf432014-08-11 19:47:5589}
90
91void TestInterfaces::ResetAll() {
92 ResetTestHelperControllers();
93 test_runner_->Reset();
94}
95
96void TestInterfaces::SetTestIsRunning(bool running) {
97 test_runner_->SetTestIsRunning(running);
98}
99
100void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url,
101 bool generate_pixels) {
102 std::string spec = GURL(test_url).spec();
yurysda0493f2014-10-01 07:55:23103 size_t path_start = spec.rfind("LayoutTests/");
104 if (path_start != std::string::npos)
105 spec = spec.substr(path_start);
[email protected]8ed8bf432014-08-11 19:47:55106 test_runner_->setShouldGeneratePixelResults(generate_pixels);
107 if (spec.find("loading/") != std::string::npos)
108 test_runner_->setShouldDumpFrameLoadCallbacks(true);
109 if (spec.find("/dumpAsText/") != std::string::npos) {
110 test_runner_->setShouldDumpAsText(true);
111 test_runner_->setShouldGeneratePixelResults(false);
112 }
113 if (spec.find("/inspector/") != std::string::npos ||
114 spec.find("/inspector-enabled/") != std::string::npos)
abhishek.a21ca9b5602014-09-19 07:33:33115 test_runner_->ClearDevToolsLocalStorage();
[email protected]8ed8bf432014-08-11 19:47:55116 if (spec.find("/inspector/") != std::string::npos) {
117 // Subfolder name determines default panel to open.
[email protected]8ed8bf432014-08-11 19:47:55118 std::string test_path = spec.substr(spec.find("/inspector/") + 11);
pfeldman6672e7d2015-04-14 10:08:58119 base::DictionaryValue settings;
120 settings.SetString("testPath", base::GetQuotedJSONString(spec));
121 std::string settings_string;
estade8d046462015-05-16 01:02:34122 base::JSONWriter::Write(settings, &settings_string);
pfeldman6672e7d2015-04-14 10:08:58123 test_runner_->ShowDevTools(settings_string, std::string());
[email protected]8ed8bf432014-08-11 19:47:55124 }
125 if (spec.find("/viewsource/") != std::string::npos) {
126 test_runner_->setShouldEnableViewSource(true);
127 test_runner_->setShouldGeneratePixelResults(false);
128 test_runner_->setShouldDumpAsMarkup(true);
129 }
130}
131
benwells0c0d3f12015-05-25 01:03:17132void TestInterfaces::SetAppBannerClient(AppBannerClient* app_banner_client) {
133 app_banner_client_ = app_banner_client;
134}
135
[email protected]8ed8bf432014-08-11 19:47:55136void TestInterfaces::WindowOpened(WebTestProxyBase* proxy) {
137 window_list_.push_back(proxy);
138}
139
140void TestInterfaces::WindowClosed(WebTestProxyBase* proxy) {
141 std::vector<WebTestProxyBase*>::iterator pos =
142 std::find(window_list_.begin(), window_list_.end(), proxy);
143 if (pos == window_list_.end()) {
144 NOTREACHED();
145 return;
146 }
147 window_list_.erase(pos);
148}
149
150AccessibilityController* TestInterfaces::GetAccessibilityController() {
151 return accessibility_controller_.get();
152}
153
[email protected]8ed8bf432014-08-11 19:47:55154TestRunner* TestInterfaces::GetTestRunner() {
155 return test_runner_.get();
156}
157
158WebTestDelegate* TestInterfaces::GetDelegate() {
159 return delegate_;
160}
161
[email protected]8ed8bf432014-08-11 19:47:55162const std::vector<WebTestProxyBase*>& TestInterfaces::GetWindowList() {
163 return window_list_;
164}
165
166blink::WebThemeEngine* TestInterfaces::GetThemeEngine() {
167 if (!test_runner_->UseMockTheme())
168 return 0;
[email protected]8ed8bf432014-08-11 19:47:55169 if (!theme_engine_.get())
170 theme_engine_.reset(new MockWebThemeEngine());
[email protected]8ed8bf432014-08-11 19:47:55171 return theme_engine_.get();
172}
173
benwells0c0d3f12015-05-25 01:03:17174AppBannerClient* TestInterfaces::GetAppBannerClient() {
175 return app_banner_client_;
176}
177
jochenf5f31752015-06-03 12:06:34178} // namespace test_runner