[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 1 | // 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 | |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 5 | #include "components/test_runner/test_interfaces.h" |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 6 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 9 | #include <string> |
| 10 | |
pfeldman | 6672e7d | 2015-04-14 10:08:58 | [diff] [blame] | 11 | #include "base/json/json_writer.h" |
| 12 | #include "base/json/string_escape.h" |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 13 | #include "base/logging.h" |
| 14 | #include "base/strings/stringprintf.h" |
jochen | c833781 | 2015-05-14 01:11:58 | [diff] [blame] | 15 | #include "base/values.h" |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 16 | #include "components/test_runner/app_banner_client.h" |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 17 | #include "components/test_runner/gamepad_controller.h" |
sadrul | 4340577 | 2015-10-15 23:12:37 | [diff] [blame] | 18 | #include "components/test_runner/gc_controller.h" |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 19 | #include "components/test_runner/test_runner.h" |
| 20 | #include "components/test_runner/text_input_controller.h" |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame^] | 21 | #include "components/test_runner/web_view_test_proxy.h" |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 22 | #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 | |
jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 27 | namespace test_runner { |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 28 | |
| 29 | TestInterfaces::TestInterfaces() |
lukasza | 8ee983a | 2016-04-22 17:47:44 | [diff] [blame] | 30 | : test_runner_(new TestRunner(this)), |
benwells | 0c0d3f1 | 2015-05-25 01:03:17 | [diff] [blame] | 31 | delegate_(nullptr), |
lukasza | 8973c52 | 2016-04-27 16:32:28 | [diff] [blame] | 32 | app_banner_client_(nullptr), |
| 33 | main_view_(nullptr) { |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 34 | blink::setLayoutTestMode(true); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 35 | // NOTE: please don't put feature specific enable flags here, |
| 36 | // instead add them to RuntimeEnabledFeatures.in |
| 37 | |
| 38 | ResetAll(); |
| 39 | } |
| 40 | |
| 41 | TestInterfaces::~TestInterfaces() { |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 42 | // gamepad_controller_ doesn't depend on WebView. |
lukasza | 8973c52 | 2016-04-27 16:32:28 | [diff] [blame] | 43 | test_runner_->SetMainView(nullptr); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 44 | |
lukasza | f41da4b | 2016-04-14 22:33:20 | [diff] [blame] | 45 | // gamepad_controller_ ignores SetDelegate(nullptr) |
lukasza | f41da4b | 2016-04-14 22:33:20 | [diff] [blame] | 46 | test_runner_->SetDelegate(nullptr); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 47 | } |
| 48 | |
lukasza | 8973c52 | 2016-04-27 16:32:28 | [diff] [blame] | 49 | void TestInterfaces::SetMainView(blink::WebView* web_view) { |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 50 | // gamepad_controller_ doesn't depend on WebView. |
lukasza | 8973c52 | 2016-04-27 16:32:28 | [diff] [blame] | 51 | main_view_ = web_view; |
| 52 | test_runner_->SetMainView(web_view); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void TestInterfaces::SetDelegate(WebTestDelegate* delegate) { |
[email protected] | 9c41b46 | 2014-08-19 15:51:34 | [diff] [blame] | 56 | gamepad_controller_ = GamepadController::Create(delegate); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 57 | test_runner_->SetDelegate(delegate); |
| 58 | delegate_ = delegate; |
| 59 | } |
| 60 | |
| 61 | void TestInterfaces::BindTo(blink::WebFrame* frame) { |
[email protected] | 9c41b46 | 2014-08-19 15:51:34 | [diff] [blame] | 62 | if (gamepad_controller_) |
| 63 | gamepad_controller_->Install(frame); |
sadrul | 4340577 | 2015-10-15 23:12:37 | [diff] [blame] | 64 | GCController::Install(frame); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void TestInterfaces::ResetTestHelperControllers() { |
[email protected] | 9c41b46 | 2014-08-19 15:51:34 | [diff] [blame] | 68 | if (gamepad_controller_) |
| 69 | gamepad_controller_->Reset(); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 70 | blink::WebCache::clear(); |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 71 | |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame^] | 72 | for (WebViewTestProxyBase* web_view_test_proxy_base : window_list_) |
| 73 | web_view_test_proxy_base->Reset(); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void TestInterfaces::ResetAll() { |
| 77 | ResetTestHelperControllers(); |
| 78 | test_runner_->Reset(); |
| 79 | } |
| 80 | |
| 81 | void TestInterfaces::SetTestIsRunning(bool running) { |
| 82 | test_runner_->SetTestIsRunning(running); |
| 83 | } |
| 84 | |
| 85 | void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url, |
| 86 | bool generate_pixels) { |
| 87 | std::string spec = GURL(test_url).spec(); |
yurys | da0493f | 2014-10-01 07:55:23 | [diff] [blame] | 88 | size_t path_start = spec.rfind("LayoutTests/"); |
| 89 | if (path_start != std::string::npos) |
| 90 | spec = spec.substr(path_start); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 91 | 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.a21 | ca9b560 | 2014-09-19 07:33:33 | [diff] [blame] | 100 | test_runner_->ClearDevToolsLocalStorage(); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 101 | if (spec.find("/inspector/") != std::string::npos) { |
| 102 | // Subfolder name determines default panel to open. |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 103 | std::string test_path = spec.substr(spec.find("/inspector/") + 11); |
pfeldman | 6672e7d | 2015-04-14 10:08:58 | [diff] [blame] | 104 | base::DictionaryValue settings; |
| 105 | settings.SetString("testPath", base::GetQuotedJSONString(spec)); |
| 106 | std::string settings_string; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 107 | base::JSONWriter::Write(settings, &settings_string); |
pfeldman | 6672e7d | 2015-04-14 10:08:58 | [diff] [blame] | 108 | test_runner_->ShowDevTools(settings_string, std::string()); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 109 | } |
| 110 | if (spec.find("/viewsource/") != std::string::npos) { |
| 111 | test_runner_->setShouldEnableViewSource(true); |
| 112 | test_runner_->setShouldGeneratePixelResults(false); |
| 113 | test_runner_->setShouldDumpAsMarkup(true); |
| 114 | } |
tkent | 2edc979d | 2016-05-27 04:58:25 | [diff] [blame] | 115 | 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] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 118 | } |
| 119 | |
benwells | 0c0d3f1 | 2015-05-25 01:03:17 | [diff] [blame] | 120 | void TestInterfaces::SetAppBannerClient(AppBannerClient* app_banner_client) { |
| 121 | app_banner_client_ = app_banner_client; |
| 122 | } |
| 123 | |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame^] | 124 | void TestInterfaces::WindowOpened(WebViewTestProxyBase* proxy) { |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 125 | window_list_.push_back(proxy); |
| 126 | } |
| 127 | |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame^] | 128 | void TestInterfaces::WindowClosed(WebViewTestProxyBase* proxy) { |
| 129 | std::vector<WebViewTestProxyBase*>::iterator pos = |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 130 | 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); |
lukasza | 8973c52 | 2016-04-27 16:32:28 | [diff] [blame] | 136 | |
| 137 | if (proxy->web_view() == main_view_) |
| 138 | SetMainView(nullptr); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 141 | TestRunner* TestInterfaces::GetTestRunner() { |
| 142 | return test_runner_.get(); |
| 143 | } |
| 144 | |
| 145 | WebTestDelegate* TestInterfaces::GetDelegate() { |
| 146 | return delegate_; |
| 147 | } |
| 148 | |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame^] | 149 | const std::vector<WebViewTestProxyBase*>& TestInterfaces::GetWindowList() { |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 150 | return window_list_; |
| 151 | } |
| 152 | |
| 153 | blink::WebThemeEngine* TestInterfaces::GetThemeEngine() { |
| 154 | if (!test_runner_->UseMockTheme()) |
| 155 | return 0; |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 156 | if (!theme_engine_.get()) |
| 157 | theme_engine_.reset(new MockWebThemeEngine()); |
[email protected] | 8ed8bf43 | 2014-08-11 19:47:55 | [diff] [blame] | 158 | return theme_engine_.get(); |
| 159 | } |
| 160 | |
benwells | 0c0d3f1 | 2015-05-25 01:03:17 | [diff] [blame] | 161 | AppBannerClient* TestInterfaces::GetAppBannerClient() { |
| 162 | return app_banner_client_; |
| 163 | } |
| 164 | |
jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 165 | } // namespace test_runner |