OLD | NEW |
| (Empty) |
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 | |
5 #include "components/test_runner/test_interfaces.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/json/json_writer.h" | |
12 #include "base/json/string_escape.h" | |
13 #include "base/logging.h" | |
14 #include "base/strings/stringprintf.h" | |
15 #include "base/values.h" | |
16 #include "components/test_runner/gamepad_controller.h" | |
17 #include "components/test_runner/gc_controller.h" | |
18 #include "components/test_runner/test_runner.h" | |
19 #include "components/test_runner/text_input_controller.h" | |
20 #include "components/test_runner/web_view_test_proxy.h" | |
21 #include "third_party/WebKit/public/platform/WebCache.h" | |
22 #include "third_party/WebKit/public/platform/WebURL.h" | |
23 #include "third_party/WebKit/public/web/WebKit.h" | |
24 #include "third_party/WebKit/public/web/WebView.h" | |
25 | |
26 namespace test_runner { | |
27 | |
28 TestInterfaces::TestInterfaces() | |
29 : test_runner_(new TestRunner(this)), | |
30 delegate_(nullptr), | |
31 main_view_(nullptr) { | |
32 blink::setLayoutTestMode(true); | |
33 // NOTE: please don't put feature specific enable flags here, | |
34 // instead add them to RuntimeEnabledFeatures.json5 | |
35 | |
36 ResetAll(); | |
37 } | |
38 | |
39 TestInterfaces::~TestInterfaces() { | |
40 // gamepad_controller_ doesn't depend on WebView. | |
41 test_runner_->SetMainView(nullptr); | |
42 | |
43 // gamepad_controller_ ignores SetDelegate(nullptr) | |
44 test_runner_->SetDelegate(nullptr); | |
45 } | |
46 | |
47 void TestInterfaces::SetMainView(blink::WebView* web_view) { | |
48 // gamepad_controller_ doesn't depend on WebView. | |
49 main_view_ = web_view; | |
50 test_runner_->SetMainView(web_view); | |
51 } | |
52 | |
53 void TestInterfaces::SetDelegate(WebTestDelegate* delegate) { | |
54 gamepad_controller_ = GamepadController::Create(delegate); | |
55 test_runner_->SetDelegate(delegate); | |
56 delegate_ = delegate; | |
57 } | |
58 | |
59 void TestInterfaces::BindTo(blink::WebFrame* frame) { | |
60 if (gamepad_controller_) | |
61 gamepad_controller_->Install(frame); | |
62 GCController::Install(frame); | |
63 } | |
64 | |
65 void TestInterfaces::ResetTestHelperControllers() { | |
66 if (gamepad_controller_) | |
67 gamepad_controller_->Reset(); | |
68 blink::WebCache::clear(); | |
69 | |
70 for (WebViewTestProxyBase* web_view_test_proxy_base : window_list_) | |
71 web_view_test_proxy_base->Reset(); | |
72 } | |
73 | |
74 void TestInterfaces::ResetAll() { | |
75 ResetTestHelperControllers(); | |
76 test_runner_->Reset(); | |
77 } | |
78 | |
79 void TestInterfaces::SetTestIsRunning(bool running) { | |
80 test_runner_->SetTestIsRunning(running); | |
81 } | |
82 | |
83 void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url, | |
84 bool generate_pixels) { | |
85 std::string spec = GURL(test_url).spec(); | |
86 size_t path_start = spec.rfind("LayoutTests/"); | |
87 if (path_start != std::string::npos) | |
88 spec = spec.substr(path_start); | |
89 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) { | |
98 test_runner_->ClearDevToolsLocalStorage(); | |
99 test_runner_->SetV8CacheDisabled(true); | |
100 } else { | |
101 test_runner_->SetV8CacheDisabled(false); | |
102 } | |
103 if (spec.find("/inspector/") != std::string::npos && | |
104 spec.find("unit_test_runner.html") == std::string::npos) { | |
105 // Subfolder name determines default panel to open. | |
106 std::string test_path = spec.substr(spec.find("/inspector/") + 11); | |
107 base::DictionaryValue settings; | |
108 settings.SetString("testPath", base::GetQuotedJSONString(spec)); | |
109 std::string settings_string; | |
110 base::JSONWriter::Write(settings, &settings_string); | |
111 test_runner_->ShowDevTools(settings_string, std::string()); | |
112 } | |
113 if (spec.find("/viewsource/") != std::string::npos) { | |
114 test_runner_->setShouldEnableViewSource(true); | |
115 test_runner_->setShouldGeneratePixelResults(false); | |
116 test_runner_->setShouldDumpAsMarkup(true); | |
117 } | |
118 if (spec.find("/external/wpt/") != std::string::npos || | |
119 spec.find("/external/csswg-test/") != std::string::npos || | |
120 spec.find("://web-platform.test") != std::string::npos) | |
121 test_runner_->set_is_web_platform_tests_mode(); | |
122 } | |
123 | |
124 void TestInterfaces::WindowOpened(WebViewTestProxyBase* proxy) { | |
125 window_list_.push_back(proxy); | |
126 } | |
127 | |
128 void TestInterfaces::WindowClosed(WebViewTestProxyBase* proxy) { | |
129 std::vector<WebViewTestProxyBase*>::iterator pos = | |
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); | |
136 | |
137 if (proxy->web_view() == main_view_) | |
138 SetMainView(nullptr); | |
139 } | |
140 | |
141 TestRunner* TestInterfaces::GetTestRunner() { | |
142 return test_runner_.get(); | |
143 } | |
144 | |
145 WebTestDelegate* TestInterfaces::GetDelegate() { | |
146 return delegate_; | |
147 } | |
148 | |
149 const std::vector<WebViewTestProxyBase*>& TestInterfaces::GetWindowList() { | |
150 return window_list_; | |
151 } | |
152 | |
153 blink::WebThemeEngine* TestInterfaces::GetThemeEngine() { | |
154 if (!test_runner_->UseMockTheme()) | |
155 return 0; | |
156 if (!theme_engine_.get()) | |
157 theme_engine_.reset(new MockWebThemeEngine()); | |
158 return theme_engine_.get(); | |
159 } | |
160 | |
161 } // namespace test_runner | |
OLD | NEW |