Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "content/shell/test_runner/test_runner_for_specific_view.h" | 5 #include "content/shell/test_runner/test_runner_for_specific_view.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 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 std::vector<v8::UniquePersistent<v8::Value>> empty_args; | 178 std::vector<v8::UniquePersistent<v8::Value>> empty_args; |
| 179 InvokeV8CallbackWithArgs(callback, std::move(empty_args)); | 179 InvokeV8CallbackWithArgs(callback, std::move(empty_args)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void TestRunnerForSpecificView::InvokeV8CallbackWithArgs( | 182 void TestRunnerForSpecificView::InvokeV8CallbackWithArgs( |
| 183 const v8::UniquePersistent<v8::Function>& callback, | 183 const v8::UniquePersistent<v8::Function>& callback, |
| 184 const std::vector<v8::UniquePersistent<v8::Value>>& args) { | 184 const std::vector<v8::UniquePersistent<v8::Value>>& args) { |
| 185 v8::Isolate* isolate = blink::MainThreadIsolate(); | 185 v8::Isolate* isolate = blink::MainThreadIsolate(); |
| 186 v8::HandleScope handle_scope(isolate); | 186 v8::HandleScope handle_scope(isolate); |
| 187 | 187 |
| 188 WebFrame* frame = web_view()->MainFrame(); | 188 blink::WebLocalFrame* frame = GetLocalMainFrame(); |
| 189 v8::Local<v8::Context> context = frame->MainWorldScriptContext(); | 189 v8::Local<v8::Context> context = frame->MainWorldScriptContext(); |
| 190 if (context.IsEmpty()) | 190 if (context.IsEmpty()) |
| 191 return; | 191 return; |
| 192 v8::Context::Scope context_scope(context); | 192 v8::Context::Scope context_scope(context); |
| 193 | 193 |
| 194 std::vector<v8::Local<v8::Value>> local_args; | 194 std::vector<v8::Local<v8::Value>> local_args; |
| 195 for (const auto& arg : args) { | 195 for (const auto& arg : args) { |
| 196 local_args.push_back(v8::Local<v8::Value>::New(isolate, arg)); | 196 local_args.push_back(v8::Local<v8::Value>::New(isolate, arg)); |
| 197 } | 197 } |
| 198 | 198 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 base::Passed(std::move(persistent_callback)))); | 242 base::Passed(std::move(persistent_callback)))); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void TestRunnerForSpecificView::CapturePixelsCallback( | 245 void TestRunnerForSpecificView::CapturePixelsCallback( |
| 246 v8::UniquePersistent<v8::Function> callback, | 246 v8::UniquePersistent<v8::Function> callback, |
| 247 const SkBitmap& snapshot) { | 247 const SkBitmap& snapshot) { |
| 248 v8::Isolate* isolate = blink::MainThreadIsolate(); | 248 v8::Isolate* isolate = blink::MainThreadIsolate(); |
| 249 v8::HandleScope handle_scope(isolate); | 249 v8::HandleScope handle_scope(isolate); |
| 250 | 250 |
| 251 v8::Local<v8::Context> context = | 251 v8::Local<v8::Context> context = |
| 252 web_view()->MainFrame()->MainWorldScriptContext(); | 252 GetLocalMainFrame()->MainWorldScriptContext(); |
| 253 if (context.IsEmpty()) | 253 if (context.IsEmpty()) |
| 254 return; | 254 return; |
| 255 | 255 |
| 256 v8::Context::Scope context_scope(context); | 256 v8::Context::Scope context_scope(context); |
| 257 v8::Local<v8::Value> argv[3]; | 257 v8::Local<v8::Value> argv[3]; |
| 258 | 258 |
| 259 // Size can be 0 for cases where copyImageAt was called on position | 259 // Size can be 0 for cases where copyImageAt was called on position |
| 260 // that doesn't have an image. | 260 // that doesn't have an image. |
| 261 int width = snapshot.info().width(); | 261 int width = snapshot.info().width(); |
| 262 argv[0] = v8::Number::New(isolate, width); | 262 argv[0] = v8::Number::New(isolate, width); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 blink::MainThreadIsolate(), callback)))); | 324 blink::MainThreadIsolate(), callback)))); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback( | 327 void TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback( |
| 328 v8::UniquePersistent<v8::Function> callback, | 328 v8::UniquePersistent<v8::Function> callback, |
| 329 const std::vector<std::string>& events) { | 329 const std::vector<std::string>& events) { |
| 330 // Build the V8 context. | 330 // Build the V8 context. |
| 331 v8::Isolate* isolate = blink::MainThreadIsolate(); | 331 v8::Isolate* isolate = blink::MainThreadIsolate(); |
| 332 v8::HandleScope handle_scope(isolate); | 332 v8::HandleScope handle_scope(isolate); |
| 333 v8::Local<v8::Context> context = | 333 v8::Local<v8::Context> context = |
| 334 web_view()->MainFrame()->MainWorldScriptContext(); | 334 GetLocalMainFrame()->MainWorldScriptContext(); |
| 335 if (context.IsEmpty()) | 335 if (context.IsEmpty()) |
| 336 return; | 336 return; |
| 337 v8::Context::Scope context_scope(context); | 337 v8::Context::Scope context_scope(context); |
| 338 | 338 |
| 339 // Convert the argument. | 339 // Convert the argument. |
| 340 v8::Local<v8::Value> arg; | 340 v8::Local<v8::Value> arg; |
| 341 if (!gin::TryConvertToV8(isolate, events, &arg)) | 341 if (!gin::TryConvertToV8(isolate, events, &arg)) |
| 342 return; | 342 return; |
| 343 | 343 |
| 344 // Call the callback. | 344 // Call the callback. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 blink::MainThreadIsolate(), callback)))); | 401 blink::MainThreadIsolate(), callback)))); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback( | 404 void TestRunnerForSpecificView::DispatchBeforeInstallPromptCallback( |
| 405 v8::UniquePersistent<v8::Function> callback, | 405 v8::UniquePersistent<v8::Function> callback, |
| 406 bool canceled) { | 406 bool canceled) { |
| 407 v8::Isolate* isolate = blink::MainThreadIsolate(); | 407 v8::Isolate* isolate = blink::MainThreadIsolate(); |
| 408 v8::HandleScope handle_scope(isolate); | 408 v8::HandleScope handle_scope(isolate); |
| 409 | 409 |
| 410 v8::Local<v8::Context> context = | 410 v8::Local<v8::Context> context = |
| 411 web_view()->MainFrame()->MainWorldScriptContext(); | 411 GetLocalMainFrame()->MainWorldScriptContext(); |
| 412 if (context.IsEmpty()) | 412 if (context.IsEmpty()) |
| 413 return; | 413 return; |
| 414 | 414 |
| 415 v8::Context::Scope context_scope(context); | 415 v8::Context::Scope context_scope(context); |
| 416 v8::Local<v8::Value> arg; | 416 v8::Local<v8::Value> arg; |
| 417 arg = v8::Boolean::New(isolate, canceled); | 417 arg = v8::Boolean::New(isolate, canceled); |
| 418 | 418 |
| 419 PostV8CallbackWithArgs(std::move(callback), 1, &arg); | 419 PostV8CallbackWithArgs(std::move(callback), 1, &arg); |
| 420 } | 420 } |
| 421 | 421 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 } | 565 } |
| 566 | 566 |
| 567 void TestRunnerForSpecificView::DidLosePointerLockInternal() { | 567 void TestRunnerForSpecificView::DidLosePointerLockInternal() { |
| 568 bool was_locked = pointer_locked_; | 568 bool was_locked = pointer_locked_; |
| 569 pointer_locked_ = false; | 569 pointer_locked_ = false; |
| 570 if (was_locked) | 570 if (was_locked) |
| 571 web_view()->DidLosePointerLock(); | 571 web_view()->DidLosePointerLock(); |
| 572 } | 572 } |
| 573 | 573 |
| 574 bool TestRunnerForSpecificView::CallShouldCloseOnWebView() { | 574 bool TestRunnerForSpecificView::CallShouldCloseOnWebView() { |
| 575 if (!web_view()->MainFrame()->ToWebLocalFrame()) { | 575 return GetLocalMainFrame()->DispatchBeforeUnloadEvent(false); |
| 576 CHECK(false) << "This function cannot be called if the main frame is not a " | |
| 577 "local frame."; | |
| 578 } | |
| 579 | |
| 580 return web_view()->MainFrame()->ToWebLocalFrame()->DispatchBeforeUnloadEvent( | |
| 581 false); | |
| 582 } | 576 } |
| 583 | 577 |
| 584 void TestRunnerForSpecificView::SetDomainRelaxationForbiddenForURLScheme( | 578 void TestRunnerForSpecificView::SetDomainRelaxationForbiddenForURLScheme( |
| 585 bool forbidden, | 579 bool forbidden, |
| 586 const std::string& scheme) { | 580 const std::string& scheme) { |
| 587 web_view()->SetDomainRelaxationForbidden(forbidden, | 581 web_view()->SetDomainRelaxationForbidden(forbidden, |
| 588 WebString::FromUTF8(scheme)); | 582 WebString::FromUTF8(scheme)); |
| 589 } | 583 } |
| 590 | 584 |
| 591 v8::Local<v8::Value> | 585 v8::Local<v8::Value> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 else if (option == "StartInSelection") | 649 else if (option == "StartInSelection") |
| 656 find_options.find_next = false; | 650 find_options.find_next = false; |
| 657 else if (option == "AtWordStarts") | 651 else if (option == "AtWordStarts") |
| 658 find_options.word_start = true; | 652 find_options.word_start = true; |
| 659 else if (option == "TreatMedialCapitalAsWordStart") | 653 else if (option == "TreatMedialCapitalAsWordStart") |
| 660 find_options.medial_capital_as_word_start = true; | 654 find_options.medial_capital_as_word_start = true; |
| 661 else if (option == "WrapAround") | 655 else if (option == "WrapAround") |
| 662 wrap_around = true; | 656 wrap_around = true; |
| 663 } | 657 } |
| 664 | 658 |
| 665 WebLocalFrame* frame = web_view()->MainFrame()->ToWebLocalFrame(); | 659 WebLocalFrame* frame = GetLocalMainFrame(); |
| 666 const bool find_result = frame->Find(0, WebString::FromUTF8(search_text), | 660 const bool find_result = frame->Find(0, WebString::FromUTF8(search_text), |
| 667 find_options, wrap_around, 0); | 661 find_options, wrap_around, 0); |
| 668 frame->StopFinding(WebLocalFrame::kStopFindActionKeepSelection); | 662 frame->StopFinding(WebLocalFrame::kStopFindActionKeepSelection); |
| 669 return find_result; | 663 return find_result; |
| 670 } | 664 } |
| 671 | 665 |
| 672 std::string TestRunnerForSpecificView::SelectionAsMarkup() { | 666 std::string TestRunnerForSpecificView::SelectionAsMarkup() { |
| 673 if (!web_view()->MainFrame()->ToWebLocalFrame()) { | 667 return GetLocalMainFrame()->SelectionAsMarkup().Utf8(); |
| 674 CHECK(false) << "This function cannot be called if the main frame is not a " | |
| 675 "local frame."; | |
| 676 } | |
| 677 return web_view()->MainFrame()->ToWebLocalFrame()->SelectionAsMarkup().Utf8(); | |
| 678 } | 668 } |
| 679 | 669 |
| 680 void TestRunnerForSpecificView::SetViewSourceForFrame(const std::string& name, | 670 void TestRunnerForSpecificView::SetViewSourceForFrame(const std::string& name, |
| 681 bool enabled) { | 671 bool enabled) { |
| 682 if (!web_view()->MainFrame()->IsWebLocalFrame()) { | |
| 683 CHECK(false) << "This function cannot be called if the main frame is not a " | |
| 684 "local frame."; | |
| 685 } | |
| 686 | |
| 687 WebFrame* target_frame = | 672 WebFrame* target_frame = |
| 688 web_view()->MainFrame()->ToWebLocalFrame()->FindFrameByName( | 673 GetLocalMainFrame()->FindFrameByName(WebString::FromUTF8(name)); |
| 689 WebString::FromUTF8(name)); | |
| 690 if (target_frame) | 674 if (target_frame) |
| 691 target_frame->EnableViewSourceMode(enabled); | 675 target_frame->EnableViewSourceMode(enabled); |
| 692 } | 676 } |
| 693 | 677 |
| 678 blink::WebLocalFrame* TestRunnerForSpecificView::GetLocalMainFrame() { | |
| 679 if (!web_view()->MainFrame()->IsWebLocalFrame()) { | |
| 680 // Hitting the check below uncovers a new scenario that requires OOPIF | |
| 681 // support in the layout tests harness. | |
| 682 CHECK(false) << "This function cannot be called if the main frame is not a " | |
| 683 "local frame."; | |
| 684 } | |
|
Avi (use Gerrit)
2017/06/09 18:37:24
👍
| |
| 685 return web_view()->MainFrame()->ToWebLocalFrame(); | |
| 686 } | |
| 687 | |
| 694 blink::WebView* TestRunnerForSpecificView::web_view() { | 688 blink::WebView* TestRunnerForSpecificView::web_view() { |
| 695 return web_view_test_proxy_base_->web_view(); | 689 return web_view_test_proxy_base_->web_view(); |
| 696 } | 690 } |
| 697 | 691 |
| 698 WebTestDelegate* TestRunnerForSpecificView::delegate() { | 692 WebTestDelegate* TestRunnerForSpecificView::delegate() { |
| 699 return web_view_test_proxy_base_->delegate(); | 693 return web_view_test_proxy_base_->delegate(); |
| 700 } | 694 } |
| 701 | 695 |
| 702 } // namespace test_runner | 696 } // namespace test_runner |
| OLD | NEW |