blob: e5f0c0762b1bf9dc8272b4d79616ec75425ba7b2 [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/gamepad_controller.h"
sadrul43405772015-10-15 23:12:3717#include "components/test_runner/gc_controller.h"
jochen73e711c2015-06-03 10:01:4618#include "components/test_runner/test_runner.h"
19#include "components/test_runner/text_input_controller.h"
lfg05e41372016-07-22 15:38:1020#include "components/test_runner/web_view_test_proxy.h"
[email protected]8ed8bf432014-08-11 19:47:5521#include "third_party/WebKit/public/platform/WebURL.h"
22#include "third_party/WebKit/public/web/WebCache.h"
23#include "third_party/WebKit/public/web/WebKit.h"
24#include "third_party/WebKit/public/web/WebView.h"
25
jochenf5f31752015-06-03 12:06:3426namespace test_runner {
[email protected]8ed8bf432014-08-11 19:47:5527
28TestInterfaces::TestInterfaces()
lukasza8ee983a2016-04-22 17:47:4429 : test_runner_(new TestRunner(this)),
benwells0c0d3f12015-05-25 01:03:1730 delegate_(nullptr),
lukasza8973c522016-04-27 16:32:2831 main_view_(nullptr) {
[email protected]8ed8bf432014-08-11 19:47:5532 blink::setLayoutTestMode(true);
[email protected]8ed8bf432014-08-11 19:47:5533 // NOTE: please don't put feature specific enable flags here,
34 // instead add them to RuntimeEnabledFeatures.in
35
36 ResetAll();
37}
38
39TestInterfaces::~TestInterfaces() {
[email protected]8ed8bf432014-08-11 19:47:5540 // gamepad_controller_ doesn't depend on WebView.
lukasza8973c522016-04-27 16:32:2841 test_runner_->SetMainView(nullptr);
[email protected]8ed8bf432014-08-11 19:47:5542
lukaszaf41da4b2016-04-14 22:33:2043 // gamepad_controller_ ignores SetDelegate(nullptr)
lukaszaf41da4b2016-04-14 22:33:2044 test_runner_->SetDelegate(nullptr);
[email protected]8ed8bf432014-08-11 19:47:5545}
46
lukasza8973c522016-04-27 16:32:2847void TestInterfaces::SetMainView(blink::WebView* web_view) {
[email protected]8ed8bf432014-08-11 19:47:5548 // gamepad_controller_ doesn't depend on WebView.
lukasza8973c522016-04-27 16:32:2849 main_view_ = web_view;
50 test_runner_->SetMainView(web_view);
[email protected]8ed8bf432014-08-11 19:47:5551}
52
53void TestInterfaces::SetDelegate(WebTestDelegate* delegate) {
[email protected]9c41b462014-08-19 15:51:3454 gamepad_controller_ = GamepadController::Create(delegate);
[email protected]8ed8bf432014-08-11 19:47:5555 test_runner_->SetDelegate(delegate);
56 delegate_ = delegate;
57}
58
59void TestInterfaces::BindTo(blink::WebFrame* frame) {
[email protected]9c41b462014-08-19 15:51:3460 if (gamepad_controller_)
61 gamepad_controller_->Install(frame);
sadrul43405772015-10-15 23:12:3762 GCController::Install(frame);
[email protected]8ed8bf432014-08-11 19:47:5563}
64
65void TestInterfaces::ResetTestHelperControllers() {
[email protected]9c41b462014-08-19 15:51:3466 if (gamepad_controller_)
67 gamepad_controller_->Reset();
[email protected]8ed8bf432014-08-11 19:47:5568 blink::WebCache::clear();
lukasza335bb762016-04-22 16:44:0369
lfg05e41372016-07-22 15:38:1070 for (WebViewTestProxyBase* web_view_test_proxy_base : window_list_)
71 web_view_test_proxy_base->Reset();
[email protected]8ed8bf432014-08-11 19:47:5572}
73
74void TestInterfaces::ResetAll() {
75 ResetTestHelperControllers();
76 test_runner_->Reset();
77}
78
79void TestInterfaces::SetTestIsRunning(bool running) {
80 test_runner_->SetTestIsRunning(running);
81}
82
83void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url,
84 bool generate_pixels) {
85 std::string spec = GURL(test_url).spec();
yurysda0493f2014-10-01 07:55:2386 size_t path_start = spec.rfind("LayoutTests/");
87 if (path_start != std::string::npos)
88 spec = spec.substr(path_start);
[email protected]8ed8bf432014-08-11 19:47:5589 test_runner_->setShouldGeneratePixelResults(generate_pixels);
90 if (spec.find("loading/") != std::string::npos)
91 test_runner_->setShouldDumpFrameLoadCallbacks(true);
92 if (spec.find("/dumpAsText/") != std::string::npos) {
93 test_runner_->setShouldDumpAsText(true);
94 test_runner_->setShouldGeneratePixelResults(false);
95 }
96 if (spec.find("/inspector/") != std::string::npos ||
97 spec.find("/inspector-enabled/") != std::string::npos)
abhishek.a21ca9b5602014-09-19 07:33:3398 test_runner_->ClearDevToolsLocalStorage();
[email protected]8ed8bf432014-08-11 19:47:5599 if (spec.find("/inspector/") != std::string::npos) {
100 // Subfolder name determines default panel to open.
[email protected]8ed8bf432014-08-11 19:47:55101 std::string test_path = spec.substr(spec.find("/inspector/") + 11);
pfeldman6672e7d2015-04-14 10:08:58102 base::DictionaryValue settings;
103 settings.SetString("testPath", base::GetQuotedJSONString(spec));
104 std::string settings_string;
estade8d046462015-05-16 01:02:34105 base::JSONWriter::Write(settings, &settings_string);
pfeldman6672e7d2015-04-14 10:08:58106 test_runner_->ShowDevTools(settings_string, std::string());
[email protected]8ed8bf432014-08-11 19:47:55107 }
108 if (spec.find("/viewsource/") != std::string::npos) {
109 test_runner_->setShouldEnableViewSource(true);
110 test_runner_->setShouldGeneratePixelResults(false);
111 test_runner_->setShouldDumpAsMarkup(true);
112 }
tkent2edc979d2016-05-27 04:58:25113 if (spec.find("/imported/wpt/") != std::string::npos ||
tkentd37f3cf2016-10-13 03:52:42114 spec.find("/imported/csswg-test/") != std::string::npos ||
115 spec.find("://web-platform.test") != std::string::npos)
tkent2edc979d2016-05-27 04:58:25116 test_runner_->set_is_web_platform_tests_mode();
[email protected]8ed8bf432014-08-11 19:47:55117}
118
lfg05e41372016-07-22 15:38:10119void TestInterfaces::WindowOpened(WebViewTestProxyBase* proxy) {
[email protected]8ed8bf432014-08-11 19:47:55120 window_list_.push_back(proxy);
121}
122
lfg05e41372016-07-22 15:38:10123void TestInterfaces::WindowClosed(WebViewTestProxyBase* proxy) {
124 std::vector<WebViewTestProxyBase*>::iterator pos =
[email protected]8ed8bf432014-08-11 19:47:55125 std::find(window_list_.begin(), window_list_.end(), proxy);
126 if (pos == window_list_.end()) {
127 NOTREACHED();
128 return;
129 }
130 window_list_.erase(pos);
lukasza8973c522016-04-27 16:32:28131
132 if (proxy->web_view() == main_view_)
133 SetMainView(nullptr);
[email protected]8ed8bf432014-08-11 19:47:55134}
135
[email protected]8ed8bf432014-08-11 19:47:55136TestRunner* TestInterfaces::GetTestRunner() {
137 return test_runner_.get();
138}
139
140WebTestDelegate* TestInterfaces::GetDelegate() {
141 return delegate_;
142}
143
lfg05e41372016-07-22 15:38:10144const std::vector<WebViewTestProxyBase*>& TestInterfaces::GetWindowList() {
[email protected]8ed8bf432014-08-11 19:47:55145 return window_list_;
146}
147
148blink::WebThemeEngine* TestInterfaces::GetThemeEngine() {
149 if (!test_runner_->UseMockTheme())
150 return 0;
[email protected]8ed8bf432014-08-11 19:47:55151 if (!theme_engine_.get())
152 theme_engine_.reset(new MockWebThemeEngine());
[email protected]8ed8bf432014-08-11 19:47:55153 return theme_engine_.get();
154}
155
jochenf5f31752015-06-03 12:06:34156} // namespace test_runner