| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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_runner_for_specific_view.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <limits> | |
| 9 #include <utility> | |
| 10 | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/strings/string_number_conversions.h" | |
| 15 #include "base/strings/stringprintf.h" | |
| 16 #include "build/build_config.h" | |
| 17 #include "components/test_runner/layout_and_paint_async_then.h" | |
| 18 #include "components/test_runner/layout_dump.h" | |
| 19 #include "components/test_runner/mock_content_settings_client.h" | |
| 20 #include "components/test_runner/mock_credential_manager_client.h" | |
| 21 #include "components/test_runner/mock_screen_orientation_client.h" | |
| 22 #include "components/test_runner/mock_web_speech_recognizer.h" | |
| 23 #include "components/test_runner/mock_web_user_media_client.h" | |
| 24 #include "components/test_runner/pixel_dump.h" | |
| 25 #include "components/test_runner/spell_check_client.h" | |
| 26 #include "components/test_runner/test_common.h" | |
| 27 #include "components/test_runner/test_interfaces.h" | |
| 28 #include "components/test_runner/test_preferences.h" | |
| 29 #include "components/test_runner/test_runner.h" | |
| 30 #include "components/test_runner/web_test_delegate.h" | |
| 31 #include "components/test_runner/web_view_test_proxy.h" | |
| 32 #include "gin/arguments.h" | |
| 33 #include "gin/array_buffer.h" | |
| 34 #include "gin/handle.h" | |
| 35 #include "gin/object_template_builder.h" | |
| 36 #include "gin/wrappable.h" | |
| 37 #include "third_party/WebKit/public/platform/WebCanvas.h" | |
| 38 #include "third_party/WebKit/public/platform/WebData.h" | |
| 39 #include "third_party/WebKit/public/platform/WebPasswordCredential.h" | |
| 40 #include "third_party/WebKit/public/platform/WebPoint.h" | |
| 41 #include "third_party/WebKit/public/platform/WebURLResponse.h" | |
| 42 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eMotionData.h" | |
| 43 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic
eOrientationData.h" | |
| 44 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRegistration.h" | |
| 45 #include "third_party/WebKit/public/web/WebArrayBuffer.h" | |
| 46 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h" | |
| 47 #include "third_party/WebKit/public/web/WebDataSource.h" | |
| 48 #include "third_party/WebKit/public/web/WebDocument.h" | |
| 49 #include "third_party/WebKit/public/web/WebFindOptions.h" | |
| 50 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 51 #include "third_party/WebKit/public/web/WebFrameWidget.h" | |
| 52 #include "third_party/WebKit/public/web/WebInputElement.h" | |
| 53 #include "third_party/WebKit/public/web/WebKit.h" | |
| 54 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 55 #include "third_party/WebKit/public/web/WebPageImportanceSignals.h" | |
| 56 #include "third_party/WebKit/public/web/WebScriptSource.h" | |
| 57 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | |
| 58 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" | |
| 59 #include "third_party/WebKit/public/web/WebSettings.h" | |
| 60 #include "third_party/WebKit/public/web/WebSurroundingText.h" | |
| 61 #include "third_party/WebKit/public/web/WebView.h" | |
| 62 #include "third_party/skia/include/core/SkBitmap.h" | |
| 63 #include "third_party/skia/include/core/SkCanvas.h" | |
| 64 #include "ui/gfx/geometry/rect.h" | |
| 65 #include "ui/gfx/geometry/rect_f.h" | |
| 66 #include "ui/gfx/geometry/size.h" | |
| 67 #include "ui/gfx/skia_util.h" | |
| 68 #include "ui/gfx/switches.h" | |
| 69 | |
| 70 #if defined(__linux__) || defined(ANDROID) | |
| 71 #include "third_party/WebKit/public/web/linux/WebFontRendering.h" | |
| 72 #endif | |
| 73 | |
| 74 using namespace blink; | |
| 75 | |
| 76 namespace test_runner { | |
| 77 | |
| 78 TestRunnerForSpecificView::TestRunnerForSpecificView( | |
| 79 WebViewTestProxyBase* web_view_test_proxy_base) | |
| 80 : web_view_test_proxy_base_(web_view_test_proxy_base), weak_factory_(this) { | |
| 81 Reset(); | |
| 82 } | |
| 83 | |
| 84 TestRunnerForSpecificView::~TestRunnerForSpecificView() {} | |
| 85 | |
| 86 void TestRunnerForSpecificView::Install(blink::WebLocalFrame* frame) { | |
| 87 web_view_test_proxy_base_->test_interfaces()->GetTestRunner()->Install( | |
| 88 frame, weak_factory_.GetWeakPtr()); | |
| 89 } | |
| 90 | |
| 91 void TestRunnerForSpecificView::Reset() { | |
| 92 pointer_locked_ = false; | |
| 93 pointer_lock_planned_result_ = PointerLockWillSucceed; | |
| 94 | |
| 95 if (web_view() && web_view()->mainFrame()) { | |
| 96 RemoveWebPageOverlay(); | |
| 97 SetTabKeyCyclesThroughElements(true); | |
| 98 | |
| 99 #if !defined(OS_MACOSX) && !defined(OS_WIN) | |
| 100 // (Constants copied because we can't depend on the header that defined | |
| 101 // them from this file.) | |
| 102 web_view()->setSelectionColors( | |
| 103 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232); | |
| 104 #endif | |
| 105 web_view()->setVisibilityState(WebPageVisibilityStateVisible, true); | |
| 106 if (web_view()->mainFrame()->isWebLocalFrame()) { | |
| 107 web_view()->mainFrame()->enableViewSourceMode(false); | |
| 108 web_view()->setTextZoomFactor(1); | |
| 109 web_view()->setZoomLevel(0); | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 bool TestRunnerForSpecificView::RequestPointerLock() { | |
| 115 switch (pointer_lock_planned_result_) { | |
| 116 case PointerLockWillSucceed: | |
| 117 PostDelayedTask( | |
| 118 0, | |
| 119 base::Bind(&TestRunnerForSpecificView::DidAcquirePointerLockInternal, | |
| 120 weak_factory_.GetWeakPtr())); | |
| 121 return true; | |
| 122 case PointerLockWillRespondAsync: | |
| 123 DCHECK(!pointer_locked_); | |
| 124 return true; | |
| 125 case PointerLockWillFailSync: | |
| 126 DCHECK(!pointer_locked_); | |
| 127 return false; | |
| 128 default: | |
| 129 NOTREACHED(); | |
| 130 return false; | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 void TestRunnerForSpecificView::RequestPointerUnlock() { | |
| 135 PostDelayedTask( | |
| 136 0, base::Bind(&TestRunnerForSpecificView::DidLosePointerLockInternal, | |
| 137 weak_factory_.GetWeakPtr())); | |
| 138 } | |
| 139 | |
| 140 bool TestRunnerForSpecificView::isPointerLocked() { | |
| 141 return pointer_locked_; | |
| 142 } | |
| 143 | |
| 144 void TestRunnerForSpecificView::PostTask(const base::Closure& callback) { | |
| 145 delegate()->PostTask(callback); | |
| 146 } | |
| 147 | |
| 148 void TestRunnerForSpecificView::PostDelayedTask(long long delay, | |
| 149 const base::Closure& callback) { | |
| 150 delegate()->PostDelayedTask(callback, delay); | |
| 151 } | |
| 152 | |
| 153 void TestRunnerForSpecificView::PostV8Callback( | |
| 154 const v8::Local<v8::Function>& callback) { | |
| 155 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8Callback, | |
| 156 weak_factory_.GetWeakPtr(), | |
| 157 v8::UniquePersistent<v8::Function>( | |
| 158 blink::mainThreadIsolate(), callback))); | |
| 159 } | |
| 160 | |
| 161 void TestRunnerForSpecificView::PostV8CallbackWithArgs( | |
| 162 v8::UniquePersistent<v8::Function> callback, | |
| 163 int argc, | |
| 164 v8::Local<v8::Value> argv[]) { | |
| 165 std::vector<v8::UniquePersistent<v8::Value>> args; | |
| 166 for (int i = 0; i < argc; i++) { | |
| 167 args.push_back( | |
| 168 v8::UniquePersistent<v8::Value>(blink::mainThreadIsolate(), argv[i])); | |
| 169 } | |
| 170 | |
| 171 PostTask(base::Bind(&TestRunnerForSpecificView::InvokeV8CallbackWithArgs, | |
| 172 weak_factory_.GetWeakPtr(), std::move(callback), | |
| 173 std::move(args))); | |
| 174 } | |
| 175 | |
| 176 void TestRunnerForSpecificView::InvokeV8Callback( | |
| 177 const v8::UniquePersistent<v8::Function>& callback) { | |
| 178 std::vector<v8::UniquePersistent<v8::Value>> empty_args; | |
| 179 InvokeV8CallbackWithArgs(callback, std::move(empty_args)); | |
| 180 } | |
| 181 | |
| 182 void TestRunnerForSpecificView::InvokeV8CallbackWithArgs( | |
| 183 const v8::UniquePersistent<v8::Function>& callback, | |
| 184 const std::vector<v8::UniquePersistent<v8::Value>>& args) { | |
| 185 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 186 v8::HandleScope handle_scope(isolate); | |
| 187 | |
| 188 WebFrame* frame = web_view()->mainFrame(); | |
| 189 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | |
| 190 if (context.IsEmpty()) | |
| 191 return; | |
| 192 v8::Context::Scope context_scope(context); | |
| 193 | |
| 194 std::vector<v8::Local<v8::Value>> local_args; | |
| 195 for (const auto& arg : args) { | |
| 196 local_args.push_back(v8::Local<v8::Value>::New(isolate, arg)); | |
| 197 } | |
| 198 | |
| 199 frame->callFunctionEvenIfScriptDisabled( | |
| 200 v8::Local<v8::Function>::New(isolate, callback), context->Global(), | |
| 201 local_args.size(), local_args.data()); | |
| 202 } | |
| 203 | |
| 204 base::Closure TestRunnerForSpecificView::CreateClosureThatPostsV8Callback( | |
| 205 const v8::Local<v8::Function>& callback) { | |
| 206 return base::Bind(&TestRunnerForSpecificView::PostTask, | |
| 207 weak_factory_.GetWeakPtr(), | |
| 208 base::Bind(&TestRunnerForSpecificView::InvokeV8Callback, | |
| 209 weak_factory_.GetWeakPtr(), | |
| 210 v8::UniquePersistent<v8::Function>( | |
| 211 blink::mainThreadIsolate(), callback))); | |
| 212 } | |
| 213 | |
| 214 void TestRunnerForSpecificView::LayoutAndPaintAsync() { | |
| 215 // TODO(lfg, lukasza): TestRunnerForSpecificView assumes that there's a single | |
| 216 // WebWidget for the entire view, but with out-of-process iframes there may be | |
| 217 // multiple WebWidgets, one for each local root. We should look into making | |
| 218 // this structure more generic. | |
| 219 test_runner::LayoutAndPaintAsyncThen( | |
| 220 web_view()->mainFrame()->toWebLocalFrame()->frameWidget(), | |
| 221 base::Closure()); | |
| 222 } | |
| 223 | |
| 224 void TestRunnerForSpecificView::LayoutAndPaintAsyncThen( | |
| 225 v8::Local<v8::Function> callback) { | |
| 226 test_runner::LayoutAndPaintAsyncThen( | |
| 227 web_view()->mainFrame()->toWebLocalFrame()->frameWidget(), | |
| 228 CreateClosureThatPostsV8Callback(callback)); | |
| 229 } | |
| 230 | |
| 231 void TestRunnerForSpecificView::CapturePixelsAsyncThen( | |
| 232 v8::Local<v8::Function> callback) { | |
| 233 v8::UniquePersistent<v8::Function> persistent_callback( | |
| 234 blink::mainThreadIsolate(), callback); | |
| 235 | |
| 236 web_view_test_proxy_base_->test_interfaces() | |
| 237 ->GetTestRunner() | |
| 238 ->DumpPixelsAsync( | |
| 239 web_view(), | |
| 240 base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback, | |
| 241 weak_factory_.GetWeakPtr(), | |
| 242 base::Passed(std::move(persistent_callback)))); | |
| 243 } | |
| 244 | |
| 245 void TestRunnerForSpecificView::CapturePixelsCallback( | |
| 246 v8::UniquePersistent<v8::Function> callback, | |
| 247 const SkBitmap& snapshot) { | |
| 248 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 249 v8::HandleScope handle_scope(isolate); | |
| 250 | |
| 251 v8::Local<v8::Context> context = | |
| 252 web_view()->mainFrame()->mainWorldScriptContext(); | |
| 253 if (context.IsEmpty()) | |
| 254 return; | |
| 255 | |
| 256 v8::Context::Scope context_scope(context); | |
| 257 v8::Local<v8::Value> argv[3]; | |
| 258 SkAutoLockPixels snapshot_lock(snapshot); | |
| 259 | |
| 260 // Size can be 0 for cases where copyImageAt was called on position | |
| 261 // that doesn't have an image. | |
| 262 int width = snapshot.info().width(); | |
| 263 argv[0] = v8::Number::New(isolate, width); | |
| 264 | |
| 265 int height = snapshot.info().height(); | |
| 266 argv[1] = v8::Number::New(isolate, height); | |
| 267 | |
| 268 // Skia's internal byte order is platform-dependent. Always convert to RGBA | |
| 269 // in order to provide a consistent ordering to the layout tests. | |
| 270 const SkImageInfo bufferInfo = | |
| 271 snapshot.info().makeColorType(kRGBA_8888_SkColorType); | |
| 272 const size_t bufferRowBytes = bufferInfo.minRowBytes(); | |
| 273 blink::WebArrayBuffer buffer = | |
| 274 blink::WebArrayBuffer::create(bufferInfo.getSafeSize(bufferRowBytes), 1); | |
| 275 if (!snapshot.readPixels(bufferInfo, | |
| 276 buffer.data(), | |
| 277 bufferRowBytes, | |
| 278 0, 0)) { | |
| 279 // We only expect readPixels to fail for null bitmaps. | |
| 280 DCHECK(snapshot.isNull()); | |
| 281 } | |
| 282 | |
| 283 argv[2] = blink::WebArrayBufferConverter::toV8Value( | |
| 284 &buffer, context->Global(), isolate); | |
| 285 | |
| 286 PostV8CallbackWithArgs(std::move(callback), arraysize(argv), argv); | |
| 287 } | |
| 288 | |
| 289 void TestRunnerForSpecificView::CopyImageAtAndCapturePixelsAsyncThen( | |
| 290 int x, | |
| 291 int y, | |
| 292 v8::Local<v8::Function> callback) { | |
| 293 v8::UniquePersistent<v8::Function> persistent_callback( | |
| 294 blink::mainThreadIsolate(), callback); | |
| 295 | |
| 296 CopyImageAtAndCapturePixels( | |
| 297 web_view(), x, y, | |
| 298 base::Bind(&TestRunnerForSpecificView::CapturePixelsCallback, | |
| 299 weak_factory_.GetWeakPtr(), | |
| 300 base::Passed(std::move(persistent_callback)))); | |
| 301 } | |
| 302 | |
| 303 void TestRunnerForSpecificView::GetManifestThen( | |
| 304 v8::Local<v8::Function> callback) { | |
| 305 v8::UniquePersistent<v8::Function> persistent_callback( | |
| 306 blink::mainThreadIsolate(), callback); | |
| 307 | |
| 308 delegate()->FetchManifest( | |
| 309 web_view(), web_view()->mainFrame()->document().manifestURL(), | |
| 310 base::Bind(&TestRunnerForSpecificView::GetManifestCallback, | |
| 311 weak_factory_.GetWeakPtr(), | |
| 312 base::Passed(std::move(persistent_callback)))); | |
| 313 } | |
| 314 | |
| 315 void TestRunnerForSpecificView::GetManifestCallback( | |
| 316 v8::UniquePersistent<v8::Function> callback, | |
| 317 const blink::WebURLResponse& response, | |
| 318 const std::string& data) { | |
| 319 PostV8CallbackWithArgs(std::move(callback), 0, nullptr); | |
| 320 } | |
| 321 | |
| 322 void TestRunnerForSpecificView::GetBluetoothManualChooserEvents( | |
| 323 v8::Local<v8::Function> callback) { | |
| 324 return delegate()->GetBluetoothManualChooserEvents(base::Bind( | |
| 325 &TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback, | |
| 326 weak_factory_.GetWeakPtr(), | |
| 327 base::Passed(v8::UniquePersistent<v8::Function>( | |
| 328 blink::mainThreadIsolate(), callback)))); | |
| 329 } | |
| 330 | |
| 331 void TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback( | |
| 332 v8::UniquePersistent<v8::Function> callback, | |
| 333 const std::vector<std::string>& events) { | |
| 334 // Build the V8 context. | |
| 335 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 336 v8::HandleScope handle_scope(isolate); | |
| 337 v8::Local<v8::Context> context = | |
| 338 web_view()->mainFrame()->mainWorldScriptContext(); | |
| 339 if (context.IsEmpty()) | |
| 340 return; | |
| 341 v8::Context::Scope context_scope(context); | |
| 342 | |
| 343 // Convert the argument. | |
| 344 v8::Local<v8::Value> arg; | |
| 345 if (!gin::TryConvertToV8(isolate, events, &arg)) | |
| 346 return; | |
| 347 | |
| 348 // Call the callback. | |
| 349 PostV8CallbackWithArgs(std::move(callback), 1, &arg); | |
| 350 } | |
| 351 | |
| 352 void TestRunnerForSpecificView::SetBluetoothFakeAdapter( | |
| 353 const std::string& adapter_name, | |
| 354 v8::Local<v8::Function> callback) { | |
| 355 delegate()->SetBluetoothFakeAdapter( | |
| 356 adapter_name, CreateClosureThatPostsV8Callback(callback)); | |
| 357 } | |
| 358 | |
| 359 void TestRunnerForSpecificView::SetBluetoothManualChooser(bool enable) { | |
| 360 delegate()->SetBluetoothManualChooser(enable); | |
| 361 } | |
| 362 | |
| 363 void TestRunnerForSpecificView::SendBluetoothManualChooserEvent( | |
| 364 const std::string& event, | |
| 365 const std::string& argument) { | |
| 366 delegate()->SendBluetoothManualChooserEvent(event, argument); | |
| 367 } | |
| 368 | |
| 369 void TestRunnerForSpecificView::SetBackingScaleFactor( | |
| 370 double value, | |
| 371 v8::Local<v8::Function> callback) { | |
| 372 delegate()->SetDeviceScaleFactor(value); | |
| 373 | |
| 374 // TODO(oshima): remove this callback argument when all platforms are migrated | |
| 375 // to use-zoom-for-dsf by default | |
| 376 v8::UniquePersistent<v8::Function> global_callback(blink::mainThreadIsolate(), | |
| 377 callback); | |
| 378 v8::Local<v8::Value> arg = v8::Boolean::New( | |
| 379 blink::mainThreadIsolate(), delegate()->IsUseZoomForDSFEnabled()); | |
| 380 PostV8CallbackWithArgs(std::move(global_callback), 1, &arg); | |
| 381 } | |
| 382 | |
| 383 void TestRunnerForSpecificView::EnableUseZoomForDSF( | |
| 384 v8::Local<v8::Function> callback) { | |
| 385 delegate()->EnableUseZoomForDSF(); | |
| 386 PostV8Callback(callback); | |
| 387 } | |
| 388 | |
| 389 void TestRunnerForSpecificView::SetColorProfile( | |
| 390 const std::string& name, | |
| 391 v8::Local<v8::Function> callback) { | |
| 392 delegate()->SetDeviceColorProfile(name); | |
| 393 PostV8Callback(callback); | |
| 394 } | |
| 395 | |
| 396 void TestRunnerForSpecificView::DispatchBeforeInstallPromptEvent( | |
| 397 const std::vector<std::string>& event_platforms, | |
| 398 v8::Local<v8::Function> callback) { | |
| 399 delegate()->DispatchBeforeInstallPromptEvent( | |
| 400 event_platforms, | |
| 401 base::Bind( | |
| 402 &TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback, | |
| 403 weak_factory_.GetWeakPtr(), | |
| 404 base::Passed(v8::UniquePersistent<v8::Function>( | |
| 405 blink::mainThreadIsolate(), callback)))); | |
| 406 } | |
| 407 | |
| 408 void TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback( | |
| 409 v8::UniquePersistent<v8::Function> callback, | |
| 410 bool canceled) { | |
| 411 v8::Isolate* isolate = blink::mainThreadIsolate(); | |
| 412 v8::HandleScope handle_scope(isolate); | |
| 413 | |
| 414 v8::Local<v8::Context> context = | |
| 415 web_view()->mainFrame()->mainWorldScriptContext(); | |
| 416 if (context.IsEmpty()) | |
| 417 return; | |
| 418 | |
| 419 v8::Context::Scope context_scope(context); | |
| 420 v8::Local<v8::Value> arg; | |
| 421 arg = v8::Boolean::New(isolate, canceled); | |
| 422 | |
| 423 PostV8CallbackWithArgs(std::move(callback), 1, &arg); | |
| 424 } | |
| 425 | |
| 426 void TestRunnerForSpecificView::RunIdleTasks(v8::Local<v8::Function> callback) { | |
| 427 delegate()->RunIdleTasks(CreateClosureThatPostsV8Callback(callback)); | |
| 428 } | |
| 429 | |
| 430 void TestRunnerForSpecificView::SetTabKeyCyclesThroughElements( | |
| 431 bool tab_key_cycles_through_elements) { | |
| 432 web_view()->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements); | |
| 433 } | |
| 434 | |
| 435 void TestRunnerForSpecificView::ExecCommand(gin::Arguments* args) { | |
| 436 std::string command; | |
| 437 args->GetNext(&command); | |
| 438 | |
| 439 std::string value; | |
| 440 if (args->Length() >= 3) { | |
| 441 // Ignore the second parameter (which is userInterface) | |
| 442 // since this command emulates a manual action. | |
| 443 args->Skip(); | |
| 444 args->GetNext(&value); | |
| 445 } | |
| 446 | |
| 447 // Note: webkit's version does not return the boolean, so neither do we. | |
| 448 web_view()->focusedFrame()->executeCommand(WebString::fromUTF8(command), | |
| 449 WebString::fromUTF8(value)); | |
| 450 } | |
| 451 | |
| 452 bool TestRunnerForSpecificView::IsCommandEnabled(const std::string& command) { | |
| 453 return web_view()->focusedFrame()->isCommandEnabled( | |
| 454 WebString::fromUTF8(command)); | |
| 455 } | |
| 456 | |
| 457 bool TestRunnerForSpecificView::HasCustomPageSizeStyle(int page_index) { | |
| 458 // TODO(dcheng): This class has many implicit assumptions that the frames it | |
| 459 // operates on are always local. | |
| 460 WebFrame* frame = web_view()->mainFrame(); | |
| 461 if (!frame || frame->isWebRemoteFrame()) | |
| 462 return false; | |
| 463 return frame->toWebLocalFrame()->hasCustomPageSizeStyle(page_index); | |
| 464 } | |
| 465 | |
| 466 void TestRunnerForSpecificView::ForceRedSelectionColors() { | |
| 467 web_view()->setSelectionColors( | |
| 468 0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0); | |
| 469 } | |
| 470 | |
| 471 void TestRunnerForSpecificView::SetPageVisibility( | |
| 472 const std::string& new_visibility) { | |
| 473 if (new_visibility == "visible") | |
| 474 web_view()->setVisibilityState(WebPageVisibilityStateVisible, false); | |
| 475 else if (new_visibility == "hidden") | |
| 476 web_view()->setVisibilityState(WebPageVisibilityStateHidden, false); | |
| 477 else if (new_visibility == "prerender") | |
| 478 web_view()->setVisibilityState(WebPageVisibilityStatePrerender, false); | |
| 479 } | |
| 480 | |
| 481 void TestRunnerForSpecificView::SetTextDirection( | |
| 482 const std::string& direction_name) { | |
| 483 // Map a direction name to a WebTextDirection value. | |
| 484 WebTextDirection direction; | |
| 485 if (direction_name == "auto") | |
| 486 direction = WebTextDirectionDefault; | |
| 487 else if (direction_name == "rtl") | |
| 488 direction = WebTextDirectionRightToLeft; | |
| 489 else if (direction_name == "ltr") | |
| 490 direction = WebTextDirectionLeftToRight; | |
| 491 else | |
| 492 return; | |
| 493 | |
| 494 web_view()->setTextDirection(direction); | |
| 495 } | |
| 496 | |
| 497 void TestRunnerForSpecificView::DumpPageImportanceSignals() { | |
| 498 blink::WebPageImportanceSignals* signals = | |
| 499 web_view()->pageImportanceSignals(); | |
| 500 if (!signals) | |
| 501 return; | |
| 502 | |
| 503 std::string message = base::StringPrintf( | |
| 504 "WebPageImportanceSignals:\n" | |
| 505 " hadFormInteraction: %s\n" | |
| 506 " issuedNonGetFetchFromScript: %s\n", | |
| 507 signals->hadFormInteraction() ? "true" : "false", | |
| 508 signals->issuedNonGetFetchFromScript() ? "true" : "false"); | |
| 509 if (delegate()) | |
| 510 delegate()->PrintMessage(message); | |
| 511 } | |
| 512 | |
| 513 void TestRunnerForSpecificView::AddWebPageOverlay() { | |
| 514 web_view()->setPageOverlayColor(SK_ColorCYAN); | |
| 515 } | |
| 516 | |
| 517 void TestRunnerForSpecificView::RemoveWebPageOverlay() { | |
| 518 web_view()->setPageOverlayColor(SK_ColorTRANSPARENT); | |
| 519 } | |
| 520 | |
| 521 void TestRunnerForSpecificView::ForceNextWebGLContextCreationToFail() { | |
| 522 web_view()->forceNextWebGLContextCreationToFail(); | |
| 523 } | |
| 524 | |
| 525 void TestRunnerForSpecificView::ForceNextDrawingBufferCreationToFail() { | |
| 526 web_view()->forceNextDrawingBufferCreationToFail(); | |
| 527 } | |
| 528 | |
| 529 void TestRunnerForSpecificView::SetWindowIsKey(bool value) { | |
| 530 web_view_test_proxy_base_->test_interfaces()->GetTestRunner()->SetFocus( | |
| 531 web_view(), value); | |
| 532 } | |
| 533 | |
| 534 void TestRunnerForSpecificView::DidAcquirePointerLock() { | |
| 535 DidAcquirePointerLockInternal(); | |
| 536 } | |
| 537 | |
| 538 void TestRunnerForSpecificView::DidNotAcquirePointerLock() { | |
| 539 DidNotAcquirePointerLockInternal(); | |
| 540 } | |
| 541 | |
| 542 void TestRunnerForSpecificView::DidLosePointerLock() { | |
| 543 DidLosePointerLockInternal(); | |
| 544 } | |
| 545 | |
| 546 void TestRunnerForSpecificView::SetPointerLockWillFailSynchronously() { | |
| 547 pointer_lock_planned_result_ = PointerLockWillFailSync; | |
| 548 } | |
| 549 | |
| 550 void TestRunnerForSpecificView::SetPointerLockWillRespondAsynchronously() { | |
| 551 pointer_lock_planned_result_ = PointerLockWillRespondAsync; | |
| 552 } | |
| 553 | |
| 554 void TestRunnerForSpecificView::DidAcquirePointerLockInternal() { | |
| 555 pointer_locked_ = true; | |
| 556 web_view()->didAcquirePointerLock(); | |
| 557 | |
| 558 // Reset planned result to default. | |
| 559 pointer_lock_planned_result_ = PointerLockWillSucceed; | |
| 560 } | |
| 561 | |
| 562 void TestRunnerForSpecificView::DidNotAcquirePointerLockInternal() { | |
| 563 DCHECK(!pointer_locked_); | |
| 564 pointer_locked_ = false; | |
| 565 web_view()->didNotAcquirePointerLock(); | |
| 566 | |
| 567 // Reset planned result to default. | |
| 568 pointer_lock_planned_result_ = PointerLockWillSucceed; | |
| 569 } | |
| 570 | |
| 571 void TestRunnerForSpecificView::DidLosePointerLockInternal() { | |
| 572 bool was_locked = pointer_locked_; | |
| 573 pointer_locked_ = false; | |
| 574 if (was_locked) | |
| 575 web_view()->didLosePointerLock(); | |
| 576 } | |
| 577 | |
| 578 bool TestRunnerForSpecificView::CallShouldCloseOnWebView() { | |
| 579 if (!web_view()->mainFrame()->toWebLocalFrame()) { | |
| 580 CHECK(false) << "This function cannot be called if the main frame is not a " | |
| 581 "local frame."; | |
| 582 } | |
| 583 | |
| 584 return web_view()->mainFrame()->toWebLocalFrame()->dispatchBeforeUnloadEvent( | |
| 585 false); | |
| 586 } | |
| 587 | |
| 588 void TestRunnerForSpecificView::SetDomainRelaxationForbiddenForURLScheme( | |
| 589 bool forbidden, | |
| 590 const std::string& scheme) { | |
| 591 web_view()->setDomainRelaxationForbidden(forbidden, | |
| 592 WebString::fromUTF8(scheme)); | |
| 593 } | |
| 594 | |
| 595 v8::Local<v8::Value> | |
| 596 TestRunnerForSpecificView::EvaluateScriptInIsolatedWorldAndReturnValue( | |
| 597 int world_id, | |
| 598 const std::string& script) { | |
| 599 WebVector<v8::Local<v8::Value>> values; | |
| 600 WebScriptSource source(WebString::fromUTF8(script)); | |
| 601 // This relies on the iframe focusing itself when it loads. This is a bit | |
| 602 // sketchy, but it seems to be what other tests do. | |
| 603 web_view()->focusedFrame()->executeScriptInIsolatedWorld(world_id, &source, 1, | |
| 604 &values); | |
| 605 // Since only one script was added, only one result is expected | |
| 606 if (values.size() == 1 && !values[0].IsEmpty()) | |
| 607 return values[0]; | |
| 608 return v8::Local<v8::Value>(); | |
| 609 } | |
| 610 | |
| 611 void TestRunnerForSpecificView::EvaluateScriptInIsolatedWorld( | |
| 612 int world_id, | |
| 613 const std::string& script) { | |
| 614 WebScriptSource source(WebString::fromUTF8(script)); | |
| 615 web_view()->focusedFrame()->executeScriptInIsolatedWorld(world_id, &source, | |
| 616 1); | |
| 617 } | |
| 618 | |
| 619 void TestRunnerForSpecificView::SetIsolatedWorldSecurityOrigin( | |
| 620 int world_id, | |
| 621 v8::Local<v8::Value> origin) { | |
| 622 if (!(origin->IsString() || !origin->IsNull())) | |
| 623 return; | |
| 624 | |
| 625 WebSecurityOrigin web_origin; | |
| 626 if (origin->IsString()) { | |
| 627 web_origin = WebSecurityOrigin::createFromString( | |
| 628 V8StringToWebString(origin.As<v8::String>())); | |
| 629 } | |
| 630 web_view()->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id, | |
| 631 web_origin); | |
| 632 } | |
| 633 | |
| 634 void TestRunnerForSpecificView::SetIsolatedWorldContentSecurityPolicy( | |
| 635 int world_id, | |
| 636 const std::string& policy) { | |
| 637 web_view()->focusedFrame()->setIsolatedWorldContentSecurityPolicy( | |
| 638 world_id, WebString::fromUTF8(policy)); | |
| 639 } | |
| 640 | |
| 641 void TestRunner::InsertStyleSheet(const std::string& source_code) { | |
| 642 WebLocalFrame::frameForCurrentContext()->document().insertStyleSheet( | |
| 643 WebString::fromUTF8(source_code)); | |
| 644 } | |
| 645 | |
| 646 bool TestRunnerForSpecificView::FindString( | |
| 647 const std::string& search_text, | |
| 648 const std::vector<std::string>& options_array) { | |
| 649 WebFindOptions find_options; | |
| 650 bool wrap_around = false; | |
| 651 find_options.matchCase = true; | |
| 652 find_options.findNext = true; | |
| 653 | |
| 654 for (const std::string& option : options_array) { | |
| 655 if (option == "CaseInsensitive") | |
| 656 find_options.matchCase = false; | |
| 657 else if (option == "Backwards") | |
| 658 find_options.forward = false; | |
| 659 else if (option == "StartInSelection") | |
| 660 find_options.findNext = false; | |
| 661 else if (option == "AtWordStarts") | |
| 662 find_options.wordStart = true; | |
| 663 else if (option == "TreatMedialCapitalAsWordStart") | |
| 664 find_options.medialCapitalAsWordStart = true; | |
| 665 else if (option == "WrapAround") | |
| 666 wrap_around = true; | |
| 667 } | |
| 668 | |
| 669 WebLocalFrame* frame = web_view()->mainFrame()->toWebLocalFrame(); | |
| 670 const bool find_result = frame->find(0, WebString::fromUTF8(search_text), | |
| 671 find_options, wrap_around, 0); | |
| 672 frame->stopFinding(WebLocalFrame::StopFindActionKeepSelection); | |
| 673 return find_result; | |
| 674 } | |
| 675 | |
| 676 std::string TestRunnerForSpecificView::SelectionAsMarkup() { | |
| 677 if (!web_view()->mainFrame()->toWebLocalFrame()) { | |
| 678 CHECK(false) << "This function cannot be called if the main frame is not a " | |
| 679 "local frame."; | |
| 680 } | |
| 681 return web_view()->mainFrame()->toWebLocalFrame()->selectionAsMarkup().utf8(); | |
| 682 } | |
| 683 | |
| 684 void TestRunnerForSpecificView::SetViewSourceForFrame(const std::string& name, | |
| 685 bool enabled) { | |
| 686 WebFrame* target_frame = | |
| 687 web_view()->findFrameByName(WebString::fromUTF8(name)); | |
| 688 if (target_frame) | |
| 689 target_frame->enableViewSourceMode(enabled); | |
| 690 } | |
| 691 | |
| 692 blink::WebView* TestRunnerForSpecificView::web_view() { | |
| 693 return web_view_test_proxy_base_->web_view(); | |
| 694 } | |
| 695 | |
| 696 WebTestDelegate* TestRunnerForSpecificView::delegate() { | |
| 697 return web_view_test_proxy_base_->delegate(); | |
| 698 } | |
| 699 | |
| 700 } // namespace test_runner | |
| OLD | NEW |