blob: d28293252be849740ba1132366dcd2cd33e72e1e [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/app_banner_client.h"
jochen73e711c2015-06-03 10:01:4617#include "components/test_runner/gamepad_controller.h"
sadrul43405772015-10-15 23:12:3718#include "components/test_runner/gc_controller.h"
jochen73e711c2015-06-03 10:01:4619#include "components/test_runner/test_runner.h"
20#include "components/test_runner/text_input_controller.h"
lfg05e41372016-07-22 15:38:1021#include "components/test_runner/web_view_test_proxy.h"
[email protected]8ed8bf432014-08-11 19:47:5522#include "third_party/WebKit/public/platform/WebURL.h"
23#include "third_party/WebKit/public/web/WebCache.h"
24#include "third_party/WebKit/public/web/WebKit.h"
25#include "third_party/WebKit/public/web/WebView.h"
26
jochenf5f31752015-06-03 12:06:3427namespace test_runner {
[email protected]8ed8bf432014-08-11 19:47:5528
29TestInterfaces::TestInterfaces()
lukasza8ee983a2016-04-22 17:47:4430 : test_runner_(new TestRunner(this)),
benwells0c0d3f12015-05-25 01:03:1731 delegate_(nullptr),
lukasza8973c522016-04-27 16:32:2832 app_banner_client_(nullptr),
33 main_view_(nullptr) {
[email protected]8ed8bf432014-08-11 19:47:5534 blink::setLayoutTestMode(true);
[email protected]8ed8bf432014-08-11 19:47:5535 // NOTE: please don't put feature specific enable flags here,
36 // instead add them to RuntimeEnabledFeatures.in
37
38 ResetAll();
39}
40
41TestInterfaces::~TestInterfaces() {
[email protected]8ed8bf432014-08-11 19:47:5542 // gamepad_controller_ doesn't depend on WebView.
lukasza8973c522016-04-27 16:32:2843 test_runner_->SetMainView(nullptr);
[email protected]8ed8bf432014-08-11 19:47:5544
lukaszaf41da4b2016-04-14 22:33:2045 // gamepad_controller_ ignores SetDelegate(nullptr)
lukaszaf41da4b2016-04-14 22:33:2046 test_runner_->SetDelegate(nullptr);
[email protected]8ed8bf432014-08-11 19:47:5547}
48
lukasza8973c522016-04-27 16:32:2849void TestInterfaces::SetMainView(blink::WebView* web_view) {
[email protected]8ed8bf432014-08-11 19:47:5550 // gamepad_controller_ doesn't depend on WebView.
lukasza8973c522016-04-27 16:32:2851 main_view_ = web_view;
52 test_runner_->SetMainView(web_view);
[email protected]8ed8bf432014-08-11 19:47:5553}
54
55void TestInterfaces::SetDelegate(WebTestDelegate* delegate) {
[email protected]9c41b462014-08-19 15:51:3456 gamepad_controller_ = GamepadController::Create(delegate);
[email protected]8ed8bf432014-08-11 19:47:5557 test_runner_->SetDelegate(delegate);
58 delegate_ = delegate;
59}
60
61void TestInterfaces::BindTo(blink::WebFrame* frame) {
[email protected]9c41b462014-08-19 15:51:3462 if (gamepad_controller_)
63 gamepad_controller_->Install(frame);
sadrul43405772015-10-15 23:12:3764 GCController::Install(frame);
[email protected]8ed8bf432014-08-11 19:47:5565}
66
67void TestInterfaces::ResetTestHelperControllers() {
[email protected]9c41b462014-08-19 15:51:3468 if (gamepad_controller_)
69 gamepad_controller_->Reset();
[email protected]8ed8bf432014-08-11 19:47:5570 blink::WebCache::clear();
lukasza335bb762016-04-22 16:44:0371
lfg05e41372016-07-22 15:38:1072 for (WebViewTestProxyBase* web_view_test_proxy_base : window_list_)
73 web_view_test_proxy_base->Reset();
[email protected]8ed8bf432014-08-11 19:47:5574}
75
76void TestInterfaces::ResetAll() {
77 ResetTestHelperControllers();
78 test_runner_->Reset();
79}
80
81void TestInterfaces::SetTestIsRunning(bool running) {
82 test_runner_->SetTestIsRunning(running);
83}
84
85void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url,
86 bool generate_pixels) {
87 std::string spec = GURL(test_url).spec();
yurysda0493f2014-10-01 07:55:2388 size_t path_start = spec.rfind("LayoutTests/");
89 if (path_start != std::string::npos)
90 spec = spec.substr(path_start);
[email protected]8ed8bf432014-08-11 19:47:5591 test_runner_->setShouldGeneratePixelResults(generate_pixels);
92 if (spec.find("loading/") != std::string::npos)
93 test_runner_->setShouldDumpFrameLoadCallbacks(true);
94 if (spec.find("/dumpAsText/") != std::string::npos) {
95 test_runner_->setShouldDumpAsText(true);
96 test_runner_->setShouldGeneratePixelResults(false);
97 }
98 if (spec.find("/inspector/") != std::string::npos ||
99 spec.find("/inspector-enabled/") != std::string::npos)
abhishek.a21ca9b5602014-09-19 07:33:33100 test_runner_->ClearDevToolsLocalStorage();
[email protected]8ed8bf432014-08-11 19:47:55101 if (spec.find("/inspector/") != std::string::npos) {
102 // Subfolder name determines default panel to open.
[email protected]8ed8bf432014-08-11 19:47:55103 std::string test_path = spec.substr(spec.find("/inspector/") + 11);
pfeldman6672e7d2015-04-14 10:08:58104 base::DictionaryValue settings;
105 settings.SetString("testPath", base::GetQuotedJSONString(spec));
106 std::string settings_string;
estade8d046462015-05-16 01:02:34107 base::JSONWriter::Write(settings, &settings_string);
pfeldman6672e7d2015-04-14 10:08:58108 test_runner_->ShowDevTools(settings_string, std::string());
[email protected]8ed8bf432014-08-11 19:47:55109 }
110 if (spec.find("/viewsource/") != std::string::npos) {
111 test_runner_->setShouldEnableViewSource(true);
112 test_runner_->setShouldGeneratePixelResults(false);
113 test_runner_->setShouldDumpAsMarkup(true);
114 }
tkent2edc979d2016-05-27 04:58:25115 if (spec.find("/imported/wpt/") != std::string::npos ||
116 spec.find("/imported/csswg-test/") != std::string::npos)
117 test_runner_->set_is_web_platform_tests_mode();
[email protected]8ed8bf432014-08-11 19:47:55118}
119
benwells0c0d3f12015-05-25 01:03:17120void TestInterfaces::SetAppBannerClient(AppBannerClient* app_banner_client) {
121 app_banner_client_ = app_banner_client;
122}
123
lfg05e41372016-07-22 15:38:10124void TestInterfaces::WindowOpened(WebViewTestProxyBase* proxy) {
[email protected]8ed8bf432014-08-11 19:47:55125 window_list_.push_back(proxy);
126}
127
lfg05e41372016-07-22 15:38:10128void TestInterfaces::WindowClosed(WebViewTestProxyBase* proxy) {
129 std::vector<WebViewTestProxyBase*>::iterator pos =
[email protected]8ed8bf432014-08-11 19:47:55130 std::find(window_list_.begin(), window_list_.end(), proxy);
131 if (pos == window_list_.end()) {
132 NOTREACHED();
133 return;
134 }
135 window_list_.erase(pos);
lukasza8973c522016-04-27 16:32:28136
137 if (proxy->web_view() == main_view_)
138 SetMainView(nullptr);
[email protected]8ed8bf432014-08-11 19:47:55139}
140
[email protected]8ed8bf432014-08-11 19:47:55141TestRunner* TestInterfaces::GetTestRunner() {
142 return test_runner_.get();
143}
144
145WebTestDelegate* TestInterfaces::GetDelegate() {
146 return delegate_;
147}
148
lfg05e41372016-07-22 15:38:10149const std::vector<WebViewTestProxyBase*>& TestInterfaces::GetWindowList() {
[email protected]8ed8bf432014-08-11 19:47:55150 return window_list_;
151}
152
153blink::WebThemeEngine* TestInterfaces::GetThemeEngine() {
154 if (!test_runner_->UseMockTheme())
155 return 0;
[email protected]8ed8bf432014-08-11 19:47:55156 if (!theme_engine_.get())
157 theme_engine_.reset(new MockWebThemeEngine());
[email protected]8ed8bf432014-08-11 19:47:55158 return theme_engine_.get();
159}
160
benwells0c0d3f12015-05-25 01:03:17161AppBannerClient* TestInterfaces::GetAppBannerClient() {
162 return app_banner_client_;
163}
164
jochenf5f31752015-06-03 12:06:34165} // namespace test_runner