| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/test_runner/test_runner.h" | 5 #include "components/test_runner/test_runner.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "components/test_runner/app_banner_client.h" | 17 #include "components/test_runner/app_banner_client.h" |
| 18 #include "components/test_runner/layout_and_paint_async_then.h" | 18 #include "components/test_runner/layout_and_paint_async_then.h" |
| 19 #include "components/test_runner/layout_dump.h" | 19 #include "components/test_runner/layout_dump.h" |
| 20 #include "components/test_runner/mock_content_settings_client.h" | 20 #include "components/test_runner/mock_content_settings_client.h" |
| 21 #include "components/test_runner/mock_credential_manager_client.h" | 21 #include "components/test_runner/mock_credential_manager_client.h" |
| 22 #include "components/test_runner/mock_screen_orientation_client.h" | 22 #include "components/test_runner/mock_screen_orientation_client.h" |
| 23 #include "components/test_runner/mock_web_speech_recognizer.h" | 23 #include "components/test_runner/mock_web_speech_recognizer.h" |
| 24 #include "components/test_runner/mock_web_user_media_client.h" | 24 #include "components/test_runner/mock_web_user_media_client.h" |
| 25 #include "components/test_runner/pixel_dump.h" | 25 #include "components/test_runner/pixel_dump.h" |
| 26 #include "components/test_runner/spell_check_client.h" | 26 #include "components/test_runner/spell_check_client.h" |
| 27 #include "components/test_runner/test_common.h" |
| 27 #include "components/test_runner/test_interfaces.h" | 28 #include "components/test_runner/test_interfaces.h" |
| 28 #include "components/test_runner/test_preferences.h" | 29 #include "components/test_runner/test_preferences.h" |
| 30 #include "components/test_runner/test_runner_for_specific_view.h" |
| 29 #include "components/test_runner/web_task.h" | 31 #include "components/test_runner/web_task.h" |
| 30 #include "components/test_runner/web_test_delegate.h" | 32 #include "components/test_runner/web_test_delegate.h" |
| 31 #include "components/test_runner/web_test_proxy.h" | 33 #include "components/test_runner/web_test_proxy.h" |
| 32 #include "gin/arguments.h" | 34 #include "gin/arguments.h" |
| 33 #include "gin/array_buffer.h" | 35 #include "gin/array_buffer.h" |
| 34 #include "gin/handle.h" | 36 #include "gin/handle.h" |
| 35 #include "gin/object_template_builder.h" | 37 #include "gin/object_template_builder.h" |
| 36 #include "gin/wrappable.h" | 38 #include "gin/wrappable.h" |
| 37 #include "third_party/WebKit/public/platform/WebCanvas.h" | 39 #include "third_party/WebKit/public/platform/WebCanvas.h" |
| 38 #include "third_party/WebKit/public/platform/WebData.h" | 40 #include "third_party/WebKit/public/platform/WebData.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 69 #if defined(__linux__) || defined(ANDROID) | 71 #if defined(__linux__) || defined(ANDROID) |
| 70 #include "third_party/WebKit/public/web/linux/WebFontRendering.h" | 72 #include "third_party/WebKit/public/web/linux/WebFontRendering.h" |
| 71 #endif | 73 #endif |
| 72 | 74 |
| 73 using namespace blink; | 75 using namespace blink; |
| 74 | 76 |
| 75 namespace test_runner { | 77 namespace test_runner { |
| 76 | 78 |
| 77 namespace { | 79 namespace { |
| 78 | 80 |
| 79 WebString V8StringToWebString(v8::Local<v8::String> v8_str) { | |
| 80 int length = v8_str->Utf8Length() + 1; | |
| 81 std::unique_ptr<char[]> chars(new char[length]); | |
| 82 v8_str->WriteUtf8(chars.get(), length); | |
| 83 return WebString::fromUTF8(chars.get()); | |
| 84 } | |
| 85 | |
| 86 double GetDefaultDeviceScaleFactor() { | 81 double GetDefaultDeviceScaleFactor() { |
| 87 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 82 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 88 if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) { | 83 if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) { |
| 89 double scale; | 84 double scale; |
| 90 std::string value = | 85 std::string value = |
| 91 command_line->GetSwitchValueASCII(switches::kForceDeviceScaleFactor); | 86 command_line->GetSwitchValueASCII(switches::kForceDeviceScaleFactor); |
| 92 if (base::StringToDouble(value, &scale)) | 87 if (base::StringToDouble(value, &scale)) |
| 93 return scale; | 88 return scale; |
| 94 } | 89 } |
| 95 return 1.f; | 90 return 1.f; |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 if (close_remaining_windows_ && delegate_) | 1670 if (close_remaining_windows_ && delegate_) |
| 1676 delegate_->CloseRemainingWindows(); | 1671 delegate_->CloseRemainingWindows(); |
| 1677 else | 1672 else |
| 1678 close_remaining_windows_ = true; | 1673 close_remaining_windows_ = true; |
| 1679 } | 1674 } |
| 1680 | 1675 |
| 1681 void TestRunner::SetTestIsRunning(bool running) { | 1676 void TestRunner::SetTestIsRunning(bool running) { |
| 1682 test_is_running_ = running; | 1677 test_is_running_ = running; |
| 1683 } | 1678 } |
| 1684 | 1679 |
| 1685 void TestRunnerForSpecificView::PostTask(const base::Closure& callback) { | |
| 1686 delegate()->PostTask(new WebCallbackTask(callback)); | |
| 1687 } | |
| 1688 | |
| 1689 void TestRunnerForSpecificView::PostDelayedTask(long long delay, | |
| 1690 const base::Closure& callback) { | |
| 1691 delegate()->PostDelayedTask(new WebCallbackTask(callback), delay); | |
| 1692 } | |
| 1693 | |
| 1694 void TestRunnerForSpecificView::PostV8Callback( | |
| 1695 const v8::Local<v8::Function>& callback) { | |
| 1696 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8Callback, | |
| 1697 weak_factory_.GetWeakPtr(), | |
| 1698 v8::UniquePersistent<v8::Function>( | |
| 1699 blink::mainThreadIsolate(), callback))); | |
| 1700 } | |
| 1701 | |
| 1702 void TestRunnerForSpecificView::PostV8CallbackWithArgs( | |
| 1703 v8::UniquePersistent<v8::Function> callback, | |
| 1704 int argc, | |
| 1705 v8::Local<v8::Value> argv[]) { | |
| 1706 std::vector<v8::UniquePersistent<v8::Value>> args; | |
| 1707 for (int i = 0; i < argc; i++) { | |
| 1708 args.push_back( | |
| 1709 v8::UniquePersistent<v8::Value>(blink::mainThreadIsolate(), argv[i])); | |
| 1710 } | |
| 1711 | |
| 1712 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8CallbackWithArgs, | |
| 1713 weak_factory_.GetWeakPtr(), std::move(callback), | |
| 1714 std::move(args))); | |
| 1715 } | |
| 1716 | |
| 1717 void TestRunnerForSpecificView::InvokeV8Callback( | |
| 1718 const v8::UniquePersistent<v8::Function>& callback) { | |
| 1719 std::vector<v8::UniquePersistent<v8::Value>> empty_args; | |
| 1720 InvokeV8CallbackWithArgs(callback, std::move(empty_args)); | |
| 1721 } | |
| 1722 | |
| 1723 void TestRunnerForSpecificView::InvokeV8CallbackWithArgs( | |
| 1724 const v8::UniquePersistent<v8::Function>& callback, | |
| 1725 const std::vector<v8::UniquePersistent<v8::Value>>& args) { | |
| 1726 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 1727 v8::HandleScope handle_scope(isolate); | |
| 1728 | |
| 1729 WebFrame* frame = web_view()->mainFrame(); | |
| 1730 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | |
| 1731 if (context.IsEmpty()) | |
| 1732 return; | |
| 1733 v8::Context::Scope context_scope(context); | |
| 1734 | |
| 1735 std::vector<v8::Local<v8::Value>> local_args; | |
| 1736 for (const auto& arg : args) { | |
| 1737 local_args.push_back(v8::Local<v8::Value>::New(isolate, arg)); | |
| 1738 } | |
| 1739 | |
| 1740 frame->callFunctionEvenIfScriptDisabled( | |
| 1741 v8::Local<v8::Function>::New(isolate, callback), context->Global(), | |
| 1742 local_args.size(), local_args.data()); | |
| 1743 } | |
| 1744 | |
| 1745 base::Closure TestRunnerForSpecificView::CreateClosureThatPostsV8Callback( | |
| 1746 const v8::Local<v8::Function>& callback) { | |
| 1747 return base::Bind(&TestRunnerForSpecificView::PostTask, | |
| 1748 weak_factory_.GetWeakPtr(), | |
| 1749 base::Bind(&TestRunnerForSpecificView::InvokeV8Callback, | |
| 1750 weak_factory_.GetWeakPtr(), | |
| 1751 v8::UniquePersistent<v8::Function>( | |
| 1752 blink::mainThreadIsolate(), callback))); | |
| 1753 } | |
| 1754 | |
| 1755 bool TestRunner::shouldDumpEditingCallbacks() const { | 1680 bool TestRunner::shouldDumpEditingCallbacks() const { |
| 1756 return layout_test_runtime_flags_.dump_editting_callbacks(); | 1681 return layout_test_runtime_flags_.dump_editting_callbacks(); |
| 1757 } | 1682 } |
| 1758 | 1683 |
| 1759 void TestRunner::setShouldDumpAsText(bool value) { | 1684 void TestRunner::setShouldDumpAsText(bool value) { |
| 1760 layout_test_runtime_flags_.set_dump_as_text(value); | 1685 layout_test_runtime_flags_.set_dump_as_text(value); |
| 1761 OnLayoutTestRuntimeFlagsChanged(); | 1686 OnLayoutTestRuntimeFlagsChanged(); |
| 1762 } | 1687 } |
| 1763 | 1688 |
| 1764 void TestRunner::setShouldDumpAsMarkup(bool value) { | 1689 void TestRunner::setShouldDumpAsMarkup(bool value) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2001 } | 1926 } |
| 2002 | 1927 |
| 2003 bool TestRunner::shouldInterceptPostMessage() const { | 1928 bool TestRunner::shouldInterceptPostMessage() const { |
| 2004 return layout_test_runtime_flags_.intercept_post_message(); | 1929 return layout_test_runtime_flags_.intercept_post_message(); |
| 2005 } | 1930 } |
| 2006 | 1931 |
| 2007 bool TestRunner::shouldDumpResourcePriorities() const { | 1932 bool TestRunner::shouldDumpResourcePriorities() const { |
| 2008 return layout_test_runtime_flags_.dump_resource_priorities(); | 1933 return layout_test_runtime_flags_.dump_resource_priorities(); |
| 2009 } | 1934 } |
| 2010 | 1935 |
| 2011 bool TestRunnerForSpecificView::RequestPointerLock() { | |
| 2012 switch (pointer_lock_planned_result_) { | |
| 2013 case PointerLockWillSucceed: | |
| 2014 PostDelayedTask( | |
| 2015 0, | |
| 2016 base::Bind(&TestRunnerForSpecificView::DidAcquirePointerLockInternal, | |
| 2017 weak_factory_.GetWeakPtr())); | |
| 2018 return true; | |
| 2019 case PointerLockWillRespondAsync: | |
| 2020 DCHECK(!pointer_locked_); | |
| 2021 return true; | |
| 2022 case PointerLockWillFailSync: | |
| 2023 DCHECK(!pointer_locked_); | |
| 2024 return false; | |
| 2025 default: | |
| 2026 NOTREACHED(); | |
| 2027 return false; | |
| 2028 } | |
| 2029 } | |
| 2030 | |
| 2031 void TestRunnerForSpecificView::RequestPointerUnlock() { | |
| 2032 PostDelayedTask( | |
| 2033 0, base::Bind(&TestRunnerForSpecificView::DidLosePointerLockInternal, | |
| 2034 weak_factory_.GetWeakPtr())); | |
| 2035 } | |
| 2036 | |
| 2037 bool TestRunnerForSpecificView::isPointerLocked() { | |
| 2038 return pointer_locked_; | |
| 2039 } | |
| 2040 | |
| 2041 void TestRunner::setToolTipText(const WebString& text) { | 1936 void TestRunner::setToolTipText(const WebString& text) { |
| 2042 tooltip_text_ = text.utf8(); | 1937 tooltip_text_ = text.utf8(); |
| 2043 } | 1938 } |
| 2044 | 1939 |
| 2045 void TestRunner::setDragImage( | 1940 void TestRunner::setDragImage( |
| 2046 const blink::WebImage& drag_image) { | 1941 const blink::WebImage& drag_image) { |
| 2047 if (layout_test_runtime_flags_.dump_drag_image()) { | 1942 if (layout_test_runtime_flags_.dump_drag_image()) { |
| 2048 if (drag_image_.isNull()) | 1943 if (drag_image_.isNull()) |
| 2049 drag_image_ = drag_image; | 1944 drag_image_ = drag_image; |
| 2050 } | 1945 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 | 2096 |
| 2202 void TestRunner::SetCloseRemainingWindowsWhenComplete( | 2097 void TestRunner::SetCloseRemainingWindowsWhenComplete( |
| 2203 bool close_remaining_windows) { | 2098 bool close_remaining_windows) { |
| 2204 close_remaining_windows_ = close_remaining_windows; | 2099 close_remaining_windows_ = close_remaining_windows; |
| 2205 } | 2100 } |
| 2206 | 2101 |
| 2207 void TestRunner::ResetTestHelperControllers() { | 2102 void TestRunner::ResetTestHelperControllers() { |
| 2208 test_interfaces_->ResetTestHelperControllers(); | 2103 test_interfaces_->ResetTestHelperControllers(); |
| 2209 } | 2104 } |
| 2210 | 2105 |
| 2211 void TestRunnerForSpecificView::SetTabKeyCyclesThroughElements( | |
| 2212 bool tab_key_cycles_through_elements) { | |
| 2213 web_view()->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements); | |
| 2214 } | |
| 2215 | |
| 2216 void TestRunnerForSpecificView::ExecCommand(gin::Arguments* args) { | |
| 2217 std::string command; | |
| 2218 args->GetNext(&command); | |
| 2219 | |
| 2220 std::string value; | |
| 2221 if (args->Length() >= 3) { | |
| 2222 // Ignore the second parameter (which is userInterface) | |
| 2223 // since this command emulates a manual action. | |
| 2224 args->Skip(); | |
| 2225 args->GetNext(&value); | |
| 2226 } | |
| 2227 | |
| 2228 // Note: webkit's version does not return the boolean, so neither do we. | |
| 2229 web_view()->focusedFrame()->executeCommand(WebString::fromUTF8(command), | |
| 2230 WebString::fromUTF8(value)); | |
| 2231 } | |
| 2232 | |
| 2233 bool TestRunnerForSpecificView::IsCommandEnabled(const std::string& command) { | |
| 2234 return web_view()->focusedFrame()->isCommandEnabled( | |
| 2235 WebString::fromUTF8(command)); | |
| 2236 } | |
| 2237 | |
| 2238 bool TestRunnerForSpecificView::CallShouldCloseOnWebView() { | |
| 2239 return web_view()->mainFrame()->dispatchBeforeUnloadEvent(); | |
| 2240 } | |
| 2241 | |
| 2242 void TestRunnerForSpecificView::SetDomainRelaxationForbiddenForURLScheme( | |
| 2243 bool forbidden, | |
| 2244 const std::string& scheme) { | |
| 2245 web_view()->setDomainRelaxationForbidden(forbidden, | |
| 2246 WebString::fromUTF8(scheme)); | |
| 2247 } | |
| 2248 | |
| 2249 v8::Local<v8::Value> | |
| 2250 TestRunnerForSpecificView::EvaluateScriptInIsolatedWorldAndReturnValue( | |
| 2251 int world_id, | |
| 2252 const std::string& script) { | |
| 2253 WebVector<v8::Local<v8::Value>> values; | |
| 2254 WebScriptSource source(WebString::fromUTF8(script)); | |
| 2255 // This relies on the iframe focusing itself when it loads. This is a bit | |
| 2256 // sketchy, but it seems to be what other tests do. | |
| 2257 web_view()->focusedFrame()->executeScriptInIsolatedWorld(world_id, &source, 1, | |
| 2258 1, &values); | |
| 2259 // Since only one script was added, only one result is expected | |
| 2260 if (values.size() == 1 && !values[0].IsEmpty()) | |
| 2261 return values[0]; | |
| 2262 return v8::Local<v8::Value>(); | |
| 2263 } | |
| 2264 | |
| 2265 void TestRunnerForSpecificView::EvaluateScriptInIsolatedWorld( | |
| 2266 int world_id, | |
| 2267 const std::string& script) { | |
| 2268 WebScriptSource source(WebString::fromUTF8(script)); | |
| 2269 web_view()->focusedFrame()->executeScriptInIsolatedWorld(world_id, &source, 1, | |
| 2270 1); | |
| 2271 } | |
| 2272 | |
| 2273 void TestRunnerForSpecificView::SetIsolatedWorldSecurityOrigin( | |
| 2274 int world_id, | |
| 2275 v8::Local<v8::Value> origin) { | |
| 2276 if (!(origin->IsString() || !origin->IsNull())) | |
| 2277 return; | |
| 2278 | |
| 2279 WebSecurityOrigin web_origin; | |
| 2280 if (origin->IsString()) { | |
| 2281 web_origin = WebSecurityOrigin::createFromString( | |
| 2282 V8StringToWebString(origin.As<v8::String>())); | |
| 2283 } | |
| 2284 web_view()->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id, | |
| 2285 web_origin); | |
| 2286 } | |
| 2287 | |
| 2288 void TestRunnerForSpecificView::SetIsolatedWorldContentSecurityPolicy( | |
| 2289 int world_id, | |
| 2290 const std::string& policy) { | |
| 2291 web_view()->focusedFrame()->setIsolatedWorldContentSecurityPolicy( | |
| 2292 world_id, WebString::fromUTF8(policy)); | |
| 2293 } | |
| 2294 | |
| 2295 void TestRunner::AddOriginAccessWhitelistEntry( | 2106 void TestRunner::AddOriginAccessWhitelistEntry( |
| 2296 const std::string& source_origin, | 2107 const std::string& source_origin, |
| 2297 const std::string& destination_protocol, | 2108 const std::string& destination_protocol, |
| 2298 const std::string& destination_host, | 2109 const std::string& destination_host, |
| 2299 bool allow_destination_subdomains) { | 2110 bool allow_destination_subdomains) { |
| 2300 WebURL url((GURL(source_origin))); | 2111 WebURL url((GURL(source_origin))); |
| 2301 if (!url.isValid()) | 2112 if (!url.isValid()) |
| 2302 return; | 2113 return; |
| 2303 | 2114 |
| 2304 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 2115 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2317 if (!url.isValid()) | 2128 if (!url.isValid()) |
| 2318 return; | 2129 return; |
| 2319 | 2130 |
| 2320 WebSecurityPolicy::removeOriginAccessWhitelistEntry( | 2131 WebSecurityPolicy::removeOriginAccessWhitelistEntry( |
| 2321 url, | 2132 url, |
| 2322 WebString::fromUTF8(destination_protocol), | 2133 WebString::fromUTF8(destination_protocol), |
| 2323 WebString::fromUTF8(destination_host), | 2134 WebString::fromUTF8(destination_host), |
| 2324 allow_destination_subdomains); | 2135 allow_destination_subdomains); |
| 2325 } | 2136 } |
| 2326 | 2137 |
| 2327 bool TestRunnerForSpecificView::HasCustomPageSizeStyle(int page_index) { | |
| 2328 WebFrame* frame = web_view()->mainFrame(); | |
| 2329 if (!frame) | |
| 2330 return false; | |
| 2331 return frame->hasCustomPageSizeStyle(page_index); | |
| 2332 } | |
| 2333 | |
| 2334 void TestRunnerForSpecificView::ForceRedSelectionColors() { | |
| 2335 web_view()->setSelectionColors( | |
| 2336 0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0); | |
| 2337 } | |
| 2338 | |
| 2339 void TestRunner::InsertStyleSheet(const std::string& source_code) { | |
| 2340 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet( | |
| 2341 WebString::fromUTF8(source_code)); | |
| 2342 } | |
| 2343 | |
| 2344 bool TestRunnerForSpecificView::FindString( | |
| 2345 const std::string& search_text, | |
| 2346 const std::vector<std::string>& options_array) { | |
| 2347 WebFindOptions find_options; | |
| 2348 bool wrap_around = false; | |
| 2349 find_options.matchCase = true; | |
| 2350 find_options.findNext = true; | |
| 2351 | |
| 2352 for (const std::string& option : options_array) { | |
| 2353 if (option == "CaseInsensitive") | |
| 2354 find_options.matchCase = false; | |
| 2355 else if (option == "Backwards") | |
| 2356 find_options.forward = false; | |
| 2357 else if (option == "StartInSelection") | |
| 2358 find_options.findNext = false; | |
| 2359 else if (option == "AtWordStarts") | |
| 2360 find_options.wordStart = true; | |
| 2361 else if (option == "TreatMedialCapitalAsWordStart") | |
| 2362 find_options.medialCapitalAsWordStart = true; | |
| 2363 else if (option == "WrapAround") | |
| 2364 wrap_around = true; | |
| 2365 } | |
| 2366 | |
| 2367 WebLocalFrame* frame = web_view()->mainFrame()->toWebLocalFrame(); | |
| 2368 const bool find_result = frame->find(0, WebString::fromUTF8(search_text), | |
| 2369 find_options, wrap_around, 0); | |
| 2370 frame->stopFinding(false); | |
| 2371 return find_result; | |
| 2372 } | |
| 2373 | |
| 2374 std::string TestRunnerForSpecificView::SelectionAsMarkup() { | |
| 2375 return web_view()->mainFrame()->selectionAsMarkup().utf8(); | |
| 2376 } | |
| 2377 | |
| 2378 void TestRunner::SetTextSubpixelPositioning(bool value) { | 2138 void TestRunner::SetTextSubpixelPositioning(bool value) { |
| 2379 #if defined(__linux__) || defined(ANDROID) | 2139 #if defined(__linux__) || defined(ANDROID) |
| 2380 // Since FontConfig doesn't provide a variable to control subpixel | 2140 // Since FontConfig doesn't provide a variable to control subpixel |
| 2381 // positioning, we'll fall back to setting it globally for all fonts. | 2141 // positioning, we'll fall back to setting it globally for all fonts. |
| 2382 WebFontRendering::setSubpixelPositioning(value); | 2142 WebFontRendering::setSubpixelPositioning(value); |
| 2383 #endif | 2143 #endif |
| 2384 } | 2144 } |
| 2385 | 2145 |
| 2386 void TestRunnerForSpecificView::SetPageVisibility( | |
| 2387 const std::string& new_visibility) { | |
| 2388 if (new_visibility == "visible") | |
| 2389 web_view()->setVisibilityState(WebPageVisibilityStateVisible, false); | |
| 2390 else if (new_visibility == "hidden") | |
| 2391 web_view()->setVisibilityState(WebPageVisibilityStateHidden, false); | |
| 2392 else if (new_visibility == "prerender") | |
| 2393 web_view()->setVisibilityState(WebPageVisibilityStatePrerender, false); | |
| 2394 } | |
| 2395 | |
| 2396 void TestRunnerForSpecificView::SetTextDirection( | |
| 2397 const std::string& direction_name) { | |
| 2398 // Map a direction name to a WebTextDirection value. | |
| 2399 WebTextDirection direction; | |
| 2400 if (direction_name == "auto") | |
| 2401 direction = WebTextDirectionDefault; | |
| 2402 else if (direction_name == "rtl") | |
| 2403 direction = WebTextDirectionRightToLeft; | |
| 2404 else if (direction_name == "ltr") | |
| 2405 direction = WebTextDirectionLeftToRight; | |
| 2406 else | |
| 2407 return; | |
| 2408 | |
| 2409 web_view()->setTextDirection(direction); | |
| 2410 } | |
| 2411 | |
| 2412 void TestRunner::UseUnfortunateSynchronousResizeMode() { | 2146 void TestRunner::UseUnfortunateSynchronousResizeMode() { |
| 2413 delegate_->UseUnfortunateSynchronousResizeMode(true); | 2147 delegate_->UseUnfortunateSynchronousResizeMode(true); |
| 2414 } | 2148 } |
| 2415 | 2149 |
| 2416 bool TestRunner::EnableAutoResizeMode(int min_width, | 2150 bool TestRunner::EnableAutoResizeMode(int min_width, |
| 2417 int min_height, | 2151 int min_height, |
| 2418 int max_width, | 2152 int max_width, |
| 2419 int max_height) { | 2153 int max_height) { |
| 2420 WebSize min_size(min_width, min_height); | 2154 WebSize min_size(min_width, min_height); |
| 2421 WebSize max_size(max_width, max_height); | 2155 WebSize max_size(max_width, max_height); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2558 | 2292 |
| 2559 void TestRunner::DidOpenChooser() { | 2293 void TestRunner::DidOpenChooser() { |
| 2560 chooser_count_++; | 2294 chooser_count_++; |
| 2561 } | 2295 } |
| 2562 | 2296 |
| 2563 void TestRunner::DidCloseChooser() { | 2297 void TestRunner::DidCloseChooser() { |
| 2564 chooser_count_--; | 2298 chooser_count_--; |
| 2565 DCHECK_LE(0, chooser_count_); | 2299 DCHECK_LE(0, chooser_count_); |
| 2566 } | 2300 } |
| 2567 | 2301 |
| 2568 void TestRunnerForSpecificView::DidAcquirePointerLock() { | |
| 2569 DidAcquirePointerLockInternal(); | |
| 2570 } | |
| 2571 | |
| 2572 void TestRunnerForSpecificView::DidNotAcquirePointerLock() { | |
| 2573 DidNotAcquirePointerLockInternal(); | |
| 2574 } | |
| 2575 | |
| 2576 void TestRunnerForSpecificView::DidLosePointerLock() { | |
| 2577 DidLosePointerLockInternal(); | |
| 2578 } | |
| 2579 | |
| 2580 void TestRunnerForSpecificView::SetPointerLockWillFailSynchronously() { | |
| 2581 pointer_lock_planned_result_ = PointerLockWillFailSync; | |
| 2582 } | |
| 2583 | |
| 2584 void TestRunnerForSpecificView::SetPointerLockWillRespondAsynchronously() { | |
| 2585 pointer_lock_planned_result_ = PointerLockWillRespondAsync; | |
| 2586 } | |
| 2587 | |
| 2588 void TestRunner::SetPopupBlockingEnabled(bool block_popups) { | 2302 void TestRunner::SetPopupBlockingEnabled(bool block_popups) { |
| 2589 delegate_->Preferences()->java_script_can_open_windows_automatically = | 2303 delegate_->Preferences()->java_script_can_open_windows_automatically = |
| 2590 !block_popups; | 2304 !block_popups; |
| 2591 delegate_->ApplyPreferences(); | 2305 delegate_->ApplyPreferences(); |
| 2592 } | 2306 } |
| 2593 | 2307 |
| 2594 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) { | 2308 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) { |
| 2595 delegate_->Preferences()->java_script_can_access_clipboard = can_access; | 2309 delegate_->Preferences()->java_script_can_access_clipboard = can_access; |
| 2596 delegate_->ApplyPreferences(); | 2310 delegate_->ApplyPreferences(); |
| 2597 } | 2311 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2892 layout_test_runtime_flags_.set_dump_drag_image(true); | 2606 layout_test_runtime_flags_.set_dump_drag_image(true); |
| 2893 DumpAsTextWithPixelResults(); | 2607 DumpAsTextWithPixelResults(); |
| 2894 OnLayoutTestRuntimeFlagsChanged(); | 2608 OnLayoutTestRuntimeFlagsChanged(); |
| 2895 } | 2609 } |
| 2896 | 2610 |
| 2897 void TestRunner::DumpNavigationPolicy() { | 2611 void TestRunner::DumpNavigationPolicy() { |
| 2898 layout_test_runtime_flags_.set_dump_navigation_policy(true); | 2612 layout_test_runtime_flags_.set_dump_navigation_policy(true); |
| 2899 OnLayoutTestRuntimeFlagsChanged(); | 2613 OnLayoutTestRuntimeFlagsChanged(); |
| 2900 } | 2614 } |
| 2901 | 2615 |
| 2902 void TestRunnerForSpecificView::DumpPageImportanceSignals() { | |
| 2903 blink::WebPageImportanceSignals* signals = | |
| 2904 web_view()->pageImportanceSignals(); | |
| 2905 if (!signals) | |
| 2906 return; | |
| 2907 | |
| 2908 std::string message = base::StringPrintf( | |
| 2909 "WebPageImportanceSignals:\n" | |
| 2910 " hadFormInteraction: %s\n" | |
| 2911 " issuedNonGetFetchFromScript: %s\n", | |
| 2912 signals->hadFormInteraction() ? "true" : "false", | |
| 2913 signals->issuedNonGetFetchFromScript() ? "true" : "false"); | |
| 2914 if (delegate()) | |
| 2915 delegate()->PrintMessage(message); | |
| 2916 } | |
| 2917 | |
| 2918 void TestRunner::CloseWebInspector() { | 2616 void TestRunner::CloseWebInspector() { |
| 2919 delegate_->CloseDevTools(); | 2617 delegate_->CloseDevTools(); |
| 2920 } | 2618 } |
| 2921 | 2619 |
| 2922 bool TestRunner::IsChooserShown() { | 2620 bool TestRunner::IsChooserShown() { |
| 2923 return 0 < chooser_count_; | 2621 return 0 < chooser_count_; |
| 2924 } | 2622 } |
| 2925 | 2623 |
| 2926 void TestRunner::EvaluateInWebInspector(int call_id, | 2624 void TestRunner::EvaluateInWebInspector(int call_id, |
| 2927 const std::string& script) { | 2625 const std::string& script) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2938 } | 2636 } |
| 2939 | 2637 |
| 2940 void TestRunner::SetDatabaseQuota(int quota) { | 2638 void TestRunner::SetDatabaseQuota(int quota) { |
| 2941 delegate_->SetDatabaseQuota(quota); | 2639 delegate_->SetDatabaseQuota(quota); |
| 2942 } | 2640 } |
| 2943 | 2641 |
| 2944 void TestRunner::SetAlwaysAcceptCookies(bool accept) { | 2642 void TestRunner::SetAlwaysAcceptCookies(bool accept) { |
| 2945 delegate_->SetAcceptAllCookies(accept); | 2643 delegate_->SetAcceptAllCookies(accept); |
| 2946 } | 2644 } |
| 2947 | 2645 |
| 2948 void TestRunnerForSpecificView::SetWindowIsKey(bool value) { | |
| 2949 web_test_proxy_base_->test_interfaces()->GetTestRunner()->SetFocus(web_view(), | |
| 2950 value); | |
| 2951 } | |
| 2952 | |
| 2953 void TestRunner::SetFocus(blink::WebView* web_view, bool focus) { | 2646 void TestRunner::SetFocus(blink::WebView* web_view, bool focus) { |
| 2954 if (focus) { | 2647 if (focus) { |
| 2955 if (previously_focused_view_ != web_view) { | 2648 if (previously_focused_view_ != web_view) { |
| 2956 delegate_->SetFocus(previously_focused_view_, false); | 2649 delegate_->SetFocus(previously_focused_view_, false); |
| 2957 delegate_->SetFocus(web_view, true); | 2650 delegate_->SetFocus(web_view, true); |
| 2958 previously_focused_view_ = web_view; | 2651 previously_focused_view_ = web_view; |
| 2959 } | 2652 } |
| 2960 } else { | 2653 } else { |
| 2961 if (previously_focused_view_ == web_view) { | 2654 if (previously_focused_view_ == web_view) { |
| 2962 delegate_->SetFocus(web_view, false); | 2655 delegate_->SetFocus(web_view, false); |
| 2963 previously_focused_view_ = nullptr; | 2656 previously_focused_view_ = nullptr; |
| 2964 } | 2657 } |
| 2965 } | 2658 } |
| 2966 } | 2659 } |
| 2967 | 2660 |
| 2968 std::string TestRunner::PathToLocalResource(const std::string& path) { | 2661 std::string TestRunner::PathToLocalResource(const std::string& path) { |
| 2969 return delegate_->PathToLocalResource(path); | 2662 return delegate_->PathToLocalResource(path); |
| 2970 } | 2663 } |
| 2971 | 2664 |
| 2972 void TestRunnerForSpecificView::SetBackingScaleFactor( | |
| 2973 double value, | |
| 2974 v8::Local<v8::Function> callback) { | |
| 2975 delegate()->SetDeviceScaleFactor(value); | |
| 2976 PostV8Callback(callback); | |
| 2977 } | |
| 2978 | |
| 2979 void TestRunnerForSpecificView::EnableUseZoomForDSF( | |
| 2980 v8::Local<v8::Function> callback) { | |
| 2981 delegate()->EnableUseZoomForDSF(); | |
| 2982 PostV8Callback(callback); | |
| 2983 } | |
| 2984 | |
| 2985 void TestRunnerForSpecificView::SetColorProfile( | |
| 2986 const std::string& name, | |
| 2987 v8::Local<v8::Function> callback) { | |
| 2988 delegate()->SetDeviceColorProfile(name); | |
| 2989 PostV8Callback(callback); | |
| 2990 } | |
| 2991 | |
| 2992 void TestRunnerForSpecificView::SetBluetoothFakeAdapter( | |
| 2993 const std::string& adapter_name, | |
| 2994 v8::Local<v8::Function> callback) { | |
| 2995 delegate()->SetBluetoothFakeAdapter( | |
| 2996 adapter_name, CreateClosureThatPostsV8Callback(callback)); | |
| 2997 } | |
| 2998 | |
| 2999 void TestRunnerForSpecificView::SetBluetoothManualChooser(bool enable) { | |
| 3000 delegate()->SetBluetoothManualChooser(enable); | |
| 3001 } | |
| 3002 | |
| 3003 void TestRunnerForSpecificView::GetBluetoothManualChooserEvents( | |
| 3004 v8::Local<v8::Function> callback) { | |
| 3005 return delegate()->GetBluetoothManualChooserEvents(base::Bind( | |
| 3006 &TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback, | |
| 3007 weak_factory_.GetWeakPtr(), | |
| 3008 base::Passed(v8::UniquePersistent<v8::Function>( | |
| 3009 blink::mainThreadIsolate(), callback)))); | |
| 3010 } | |
| 3011 | |
| 3012 void TestRunnerForSpecificView::SendBluetoothManualChooserEvent( | |
| 3013 const std::string& event, | |
| 3014 const std::string& argument) { | |
| 3015 delegate()->SendBluetoothManualChooserEvent(event, argument); | |
| 3016 } | |
| 3017 | |
| 3018 void TestRunner::SetGeofencingMockProvider(bool service_available) { | 2665 void TestRunner::SetGeofencingMockProvider(bool service_available) { |
| 3019 delegate_->SetGeofencingMockProvider(service_available); | 2666 delegate_->SetGeofencingMockProvider(service_available); |
| 3020 } | 2667 } |
| 3021 | 2668 |
| 3022 void TestRunner::ClearGeofencingMockProvider() { | 2669 void TestRunner::ClearGeofencingMockProvider() { |
| 3023 delegate_->ClearGeofencingMockProvider(); | 2670 delegate_->ClearGeofencingMockProvider(); |
| 3024 } | 2671 } |
| 3025 | 2672 |
| 3026 void TestRunner::SetGeofencingMockPosition(double latitude, double longitude) { | 2673 void TestRunner::SetGeofencingMockPosition(double latitude, double longitude) { |
| 3027 delegate_->SetGeofencingMockPosition(latitude, longitude); | 2674 delegate_->SetGeofencingMockPosition(latitude, longitude); |
| 3028 } | 2675 } |
| 3029 | 2676 |
| 3030 void TestRunner::SetPermission(const std::string& name, | 2677 void TestRunner::SetPermission(const std::string& name, |
| 3031 const std::string& value, | 2678 const std::string& value, |
| 3032 const GURL& origin, | 2679 const GURL& origin, |
| 3033 const GURL& embedding_origin) { | 2680 const GURL& embedding_origin) { |
| 3034 delegate_->SetPermission(name, value, origin, embedding_origin); | 2681 delegate_->SetPermission(name, value, origin, embedding_origin); |
| 3035 } | 2682 } |
| 3036 | 2683 |
| 3037 void TestRunnerForSpecificView::DispatchBeforeInstallPromptEvent( | |
| 3038 int request_id, | |
| 3039 const std::vector<std::string>& event_platforms, | |
| 3040 v8::Local<v8::Function> callback) { | |
| 3041 delegate()->DispatchBeforeInstallPromptEvent( | |
| 3042 request_id, event_platforms, | |
| 3043 base::Bind( | |
| 3044 &TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback, | |
| 3045 weak_factory_.GetWeakPtr(), | |
| 3046 base::Passed(v8::UniquePersistent<v8::Function>( | |
| 3047 blink::mainThreadIsolate(), callback)))); | |
| 3048 } | |
| 3049 | |
| 3050 void TestRunner::ResolveBeforeInstallPromptPromise( | 2684 void TestRunner::ResolveBeforeInstallPromptPromise( |
| 3051 int request_id, | 2685 int request_id, |
| 3052 const std::string& platform) { | 2686 const std::string& platform) { |
| 3053 if (!test_interfaces_->GetAppBannerClient()) | 2687 if (!test_interfaces_->GetAppBannerClient()) |
| 3054 return; | 2688 return; |
| 3055 test_interfaces_->GetAppBannerClient()->ResolvePromise(request_id, platform); | 2689 test_interfaces_->GetAppBannerClient()->ResolvePromise(request_id, platform); |
| 3056 } | 2690 } |
| 3057 | 2691 |
| 3058 void TestRunnerForSpecificView::RunIdleTasks(v8::Local<v8::Function> callback) { | |
| 3059 delegate()->RunIdleTasks(CreateClosureThatPostsV8Callback(callback)); | |
| 3060 } | |
| 3061 | |
| 3062 void TestRunner::SetPOSIXLocale(const std::string& locale) { | 2692 void TestRunner::SetPOSIXLocale(const std::string& locale) { |
| 3063 delegate_->SetLocale(locale); | 2693 delegate_->SetLocale(locale); |
| 3064 } | 2694 } |
| 3065 | 2695 |
| 3066 void TestRunner::SetMIDIAccessorResult(bool result) { | 2696 void TestRunner::SetMIDIAccessorResult(bool result) { |
| 3067 midi_accessor_result_ = result; | 2697 midi_accessor_result_ = result; |
| 3068 } | 2698 } |
| 3069 | 2699 |
| 3070 void TestRunner::SimulateWebNotificationClick(const std::string& title, | 2700 void TestRunner::SimulateWebNotificationClick(const std::string& title, |
| 3071 int action_index) { | 2701 int action_index) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3095 const std::string& password) { | 2725 const std::string& password) { |
| 3096 credential_manager_client_->SetResponse(new WebPasswordCredential( | 2726 credential_manager_client_->SetResponse(new WebPasswordCredential( |
| 3097 WebString::fromUTF8(id), WebString::fromUTF8(password), | 2727 WebString::fromUTF8(id), WebString::fromUTF8(password), |
| 3098 WebString::fromUTF8(name), WebURL(GURL(avatar)))); | 2728 WebString::fromUTF8(name), WebURL(GURL(avatar)))); |
| 3099 } | 2729 } |
| 3100 | 2730 |
| 3101 void TestRunner::AddMockCredentialManagerError(const std::string& error) { | 2731 void TestRunner::AddMockCredentialManagerError(const std::string& error) { |
| 3102 credential_manager_client_->SetError(error); | 2732 credential_manager_client_->SetError(error); |
| 3103 } | 2733 } |
| 3104 | 2734 |
| 3105 void TestRunnerForSpecificView::AddWebPageOverlay() { | |
| 3106 web_view()->setPageOverlayColor(SK_ColorCYAN); | |
| 3107 } | |
| 3108 | |
| 3109 void TestRunnerForSpecificView::RemoveWebPageOverlay() { | |
| 3110 web_view()->setPageOverlayColor(SK_ColorTRANSPARENT); | |
| 3111 } | |
| 3112 | |
| 3113 void TestRunnerForSpecificView::LayoutAndPaintAsync() { | |
| 3114 test_runner::LayoutAndPaintAsyncThen(web_view(), base::Closure()); | |
| 3115 } | |
| 3116 | |
| 3117 void TestRunnerForSpecificView::LayoutAndPaintAsyncThen( | |
| 3118 v8::Local<v8::Function> callback) { | |
| 3119 test_runner::LayoutAndPaintAsyncThen( | |
| 3120 web_view(), CreateClosureThatPostsV8Callback(callback)); | |
| 3121 } | |
| 3122 | |
| 3123 void TestRunnerForSpecificView::GetManifestThen( | |
| 3124 v8::Local<v8::Function> callback) { | |
| 3125 v8::UniquePersistent<v8::Function> persistent_callback( | |
| 3126 blink::mainThreadIsolate(), callback); | |
| 3127 | |
| 3128 delegate()->FetchManifest( | |
| 3129 web_view(), web_view()->mainFrame()->document().manifestURL(), | |
| 3130 base::Bind(&TestRunnerForSpecificView::GetManifestCallback, | |
| 3131 weak_factory_.GetWeakPtr(), | |
| 3132 base::Passed(std::move(persistent_callback)))); | |
| 3133 } | |
| 3134 | |
| 3135 void TestRunnerForSpecificView::CapturePixelsAsyncThen( | |
| 3136 v8::Local<v8::Function> callback) { | |
| 3137 v8::UniquePersistent<v8::Function> persistent_callback( | |
| 3138 blink::mainThreadIsolate(), callback); | |
| 3139 | |
| 3140 web_test_proxy_base_->test_interfaces()->GetTestRunner()->DumpPixelsAsync( | |
| 3141 web_view(), base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback, | |
| 3142 weak_factory_.GetWeakPtr(), | |
| 3143 base::Passed(std::move(persistent_callback)))); | |
| 3144 } | |
| 3145 | |
| 3146 void TestRunner::OnLayoutTestRuntimeFlagsChanged() { | 2735 void TestRunner::OnLayoutTestRuntimeFlagsChanged() { |
| 3147 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty()) | 2736 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty()) |
| 3148 return; | 2737 return; |
| 3149 if (!test_is_running_) | 2738 if (!test_is_running_) |
| 3150 return; | 2739 return; |
| 3151 | 2740 |
| 3152 delegate_->OnLayoutTestRuntimeFlagsChanged( | 2741 delegate_->OnLayoutTestRuntimeFlagsChanged( |
| 3153 layout_test_runtime_flags_.tracked_dictionary().changed_values()); | 2742 layout_test_runtime_flags_.tracked_dictionary().changed_values()); |
| 3154 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking(); | 2743 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking(); |
| 3155 } | 2744 } |
| 3156 | 2745 |
| 3157 void TestRunnerForSpecificView::ForceNextWebGLContextCreationToFail() { | |
| 3158 web_view()->forceNextWebGLContextCreationToFail(); | |
| 3159 } | |
| 3160 | |
| 3161 void TestRunnerForSpecificView::ForceNextDrawingBufferCreationToFail() { | |
| 3162 web_view()->forceNextDrawingBufferCreationToFail(); | |
| 3163 } | |
| 3164 | |
| 3165 void TestRunnerForSpecificView::CopyImageAtAndCapturePixelsAsyncThen( | |
| 3166 int x, | |
| 3167 int y, | |
| 3168 v8::Local<v8::Function> callback) { | |
| 3169 v8::UniquePersistent<v8::Function> persistent_callback( | |
| 3170 blink::mainThreadIsolate(), callback); | |
| 3171 | |
| 3172 CopyImageAtAndCapturePixels( | |
| 3173 web_view(), x, y, | |
| 3174 base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback, | |
| 3175 weak_factory_.GetWeakPtr(), | |
| 3176 base::Passed(std::move(persistent_callback)))); | |
| 3177 } | |
| 3178 | |
| 3179 void TestRunnerForSpecificView::GetManifestCallback( | |
| 3180 v8::UniquePersistent<v8::Function> callback, | |
| 3181 const blink::WebURLResponse& response, | |
| 3182 const std::string& data) { | |
| 3183 PostV8CallbackWithArgs(std::move(callback), 0, nullptr); | |
| 3184 } | |
| 3185 | |
| 3186 void TestRunnerForSpecificView::CapturePixelsCallback( | |
| 3187 v8::UniquePersistent<v8::Function> callback, | |
| 3188 const SkBitmap& snapshot) { | |
| 3189 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 3190 v8::HandleScope handle_scope(isolate); | |
| 3191 | |
| 3192 v8::Local<v8::Context> context = | |
| 3193 web_view()->mainFrame()->mainWorldScriptContext(); | |
| 3194 if (context.IsEmpty()) | |
| 3195 return; | |
| 3196 | |
| 3197 v8::Context::Scope context_scope(context); | |
| 3198 v8::Local<v8::Value> argv[3]; | |
| 3199 SkAutoLockPixels snapshot_lock(snapshot); | |
| 3200 | |
| 3201 // Size can be 0 for cases where copyImageAt was called on position | |
| 3202 // that doesn't have an image. | |
| 3203 int width = snapshot.info().width(); | |
| 3204 argv[0] = v8::Number::New(isolate, width); | |
| 3205 | |
| 3206 int height = snapshot.info().height(); | |
| 3207 argv[1] = v8::Number::New(isolate, height); | |
| 3208 | |
| 3209 // Skia's internal byte order is platform-dependent. Always convert to RGBA | |
| 3210 // in order to provide a consistent ordering to the layout tests. | |
| 3211 const SkImageInfo bufferInfo = | |
| 3212 snapshot.info().makeColorType(kRGBA_8888_SkColorType); | |
| 3213 const size_t bufferRowBytes = bufferInfo.minRowBytes(); | |
| 3214 blink::WebArrayBuffer buffer = | |
| 3215 blink::WebArrayBuffer::create(bufferInfo.getSafeSize(bufferRowBytes), 1); | |
| 3216 if (!snapshot.readPixels(bufferInfo, | |
| 3217 buffer.data(), | |
| 3218 bufferRowBytes, | |
| 3219 0, 0)) { | |
| 3220 // We only expect readPixels to fail for null bitmaps. | |
| 3221 DCHECK(snapshot.isNull()); | |
| 3222 } | |
| 3223 | |
| 3224 argv[2] = blink::WebArrayBufferConverter::toV8Value( | |
| 3225 &buffer, context->Global(), isolate); | |
| 3226 | |
| 3227 PostV8CallbackWithArgs(std::move(callback), arraysize(argv), argv); | |
| 3228 } | |
| 3229 | |
| 3230 void TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback( | |
| 3231 v8::UniquePersistent<v8::Function> callback, | |
| 3232 bool canceled) { | |
| 3233 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 3234 v8::HandleScope handle_scope(isolate); | |
| 3235 | |
| 3236 v8::Local<v8::Context> context = | |
| 3237 web_view()->mainFrame()->mainWorldScriptContext(); | |
| 3238 if (context.IsEmpty()) | |
| 3239 return; | |
| 3240 | |
| 3241 v8::Context::Scope context_scope(context); | |
| 3242 v8::Local<v8::Value> arg; | |
| 3243 arg = v8::Boolean::New(isolate, canceled); | |
| 3244 | |
| 3245 PostV8CallbackWithArgs(std::move(callback), 1, &arg); | |
| 3246 } | |
| 3247 | |
| 3248 void TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback( | |
| 3249 v8::UniquePersistent<v8::Function> callback, | |
| 3250 const std::vector<std::string>& events) { | |
| 3251 // Build the V8 context. | |
| 3252 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 3253 v8::HandleScope handle_scope(isolate); | |
| 3254 v8::Local<v8::Context> context = | |
| 3255 web_view()->mainFrame()->mainWorldScriptContext(); | |
| 3256 if (context.IsEmpty()) | |
| 3257 return; | |
| 3258 v8::Context::Scope context_scope(context); | |
| 3259 | |
| 3260 // Convert the argument. | |
| 3261 v8::Local<v8::Value> arg; | |
| 3262 if (!gin::TryConvertToV8(isolate, events, &arg)) | |
| 3263 return; | |
| 3264 | |
| 3265 // Call the callback. | |
| 3266 PostV8CallbackWithArgs(std::move(callback), 1, &arg); | |
| 3267 } | |
| 3268 | |
| 3269 void TestRunner::LocationChangeDone() { | 2746 void TestRunner::LocationChangeDone() { |
| 3270 web_history_item_count_ = delegate_->NavigationEntryCount(); | 2747 web_history_item_count_ = delegate_->NavigationEntryCount(); |
| 3271 | 2748 |
| 3272 // No more new work after the first complete load. | 2749 // No more new work after the first complete load. |
| 3273 work_queue_.set_frozen(true); | 2750 work_queue_.set_frozen(true); |
| 3274 | 2751 |
| 3275 if (!layout_test_runtime_flags_.wait_until_done()) | 2752 if (!layout_test_runtime_flags_.wait_until_done()) |
| 3276 work_queue_.ProcessWorkSoon(); | 2753 work_queue_.ProcessWorkSoon(); |
| 3277 } | 2754 } |
| 3278 | 2755 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3300 } | 2777 } |
| 3301 | 2778 |
| 3302 void TestRunner::CompleteNotifyDone() { | 2779 void TestRunner::CompleteNotifyDone() { |
| 3303 if (layout_test_runtime_flags_.wait_until_done() && !topLoadingFrame() && | 2780 if (layout_test_runtime_flags_.wait_until_done() && !topLoadingFrame() && |
| 3304 work_queue_.is_empty()) | 2781 work_queue_.is_empty()) |
| 3305 delegate_->TestFinished(); | 2782 delegate_->TestFinished(); |
| 3306 layout_test_runtime_flags_.set_wait_until_done(false); | 2783 layout_test_runtime_flags_.set_wait_until_done(false); |
| 3307 OnLayoutTestRuntimeFlagsChanged(); | 2784 OnLayoutTestRuntimeFlagsChanged(); |
| 3308 } | 2785 } |
| 3309 | 2786 |
| 3310 void TestRunnerForSpecificView::DidAcquirePointerLockInternal() { | |
| 3311 pointer_locked_ = true; | |
| 3312 web_view()->didAcquirePointerLock(); | |
| 3313 | |
| 3314 // Reset planned result to default. | |
| 3315 pointer_lock_planned_result_ = PointerLockWillSucceed; | |
| 3316 } | |
| 3317 | |
| 3318 void TestRunnerForSpecificView::DidNotAcquirePointerLockInternal() { | |
| 3319 DCHECK(!pointer_locked_); | |
| 3320 pointer_locked_ = false; | |
| 3321 web_view()->didNotAcquirePointerLock(); | |
| 3322 | |
| 3323 // Reset planned result to default. | |
| 3324 pointer_lock_planned_result_ = PointerLockWillSucceed; | |
| 3325 } | |
| 3326 | |
| 3327 void TestRunnerForSpecificView::DidLosePointerLockInternal() { | |
| 3328 bool was_locked = pointer_locked_; | |
| 3329 pointer_locked_ = false; | |
| 3330 if (was_locked) | |
| 3331 web_view()->didLosePointerLock(); | |
| 3332 } | |
| 3333 | |
| 3334 TestRunnerForSpecificView::TestRunnerForSpecificView( | |
| 3335 WebTestProxyBase* web_test_proxy_base) | |
| 3336 : web_test_proxy_base_(web_test_proxy_base), weak_factory_(this) { | |
| 3337 Reset(); | |
| 3338 } | |
| 3339 | |
| 3340 TestRunnerForSpecificView::~TestRunnerForSpecificView() {} | |
| 3341 | |
| 3342 void TestRunnerForSpecificView::Install(blink::WebLocalFrame* frame) { | |
| 3343 web_test_proxy_base_->test_interfaces()->GetTestRunner()->Install( | |
| 3344 frame, weak_factory_.GetWeakPtr()); | |
| 3345 } | |
| 3346 | |
| 3347 void TestRunnerForSpecificView::Reset() { | |
| 3348 pointer_locked_ = false; | |
| 3349 pointer_lock_planned_result_ = PointerLockWillSucceed; | |
| 3350 | |
| 3351 if (web_view() && web_view()->mainFrame()) { | |
| 3352 RemoveWebPageOverlay(); | |
| 3353 SetTabKeyCyclesThroughElements(true); | |
| 3354 | |
| 3355 #if !defined(OS_MACOSX) && !defined(OS_WIN) | |
| 3356 // (Constants copied because we can't depend on the header that defined | |
| 3357 // them from this file.) | |
| 3358 web_view()->setSelectionColors( | |
| 3359 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232); | |
| 3360 #endif | |
| 3361 web_view()->setVisibilityState(WebPageVisibilityStateVisible, true); | |
| 3362 if (web_view()->mainFrame()->isWebLocalFrame()) { | |
| 3363 web_view()->mainFrame()->enableViewSourceMode(false); | |
| 3364 web_view()->setTextZoomFactor(1); | |
| 3365 web_view()->setZoomLevel(0); | |
| 3366 } | |
| 3367 } | |
| 3368 } | |
| 3369 | |
| 3370 void TestRunnerForSpecificView::SetViewSourceForFrame(const std::string& name, | |
| 3371 bool enabled) { | |
| 3372 WebFrame* target_frame = | |
| 3373 web_view()->findFrameByName(WebString::fromUTF8(name)); | |
| 3374 if (target_frame) | |
| 3375 target_frame->enableViewSourceMode(enabled); | |
| 3376 } | |
| 3377 | |
| 3378 blink::WebView* TestRunnerForSpecificView::web_view() { | |
| 3379 return web_test_proxy_base_->web_view(); | |
| 3380 } | |
| 3381 | |
| 3382 WebTestDelegate* TestRunnerForSpecificView::delegate() { | |
| 3383 return web_test_proxy_base_->delegate(); | |
| 3384 } | |
| 3385 | |
| 3386 } // namespace test_runner | 2787 } // namespace test_runner |
| OLD | NEW |