Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 EXPECT_EQ(webViewHelper.webView()->mainFrame()->firstChild(), | 328 EXPECT_EQ(webViewHelper.webView()->mainFrame()->firstChild(), |
| 329 WebLocalFrame::frameForContext(webViewHelper.webView() | 329 WebLocalFrame::frameForContext(webViewHelper.webView() |
| 330 ->mainFrame() | 330 ->mainFrame() |
| 331 ->firstChild() | 331 ->firstChild() |
| 332 ->mainWorldScriptContext())); | 332 ->mainWorldScriptContext())); |
| 333 } | 333 } |
| 334 | 334 |
| 335 class ScriptExecutionCallbackHelper : public WebScriptExecutionCallback { | 335 class ScriptExecutionCallbackHelper : public WebScriptExecutionCallback { |
| 336 public: | 336 public: |
| 337 explicit ScriptExecutionCallbackHelper(v8::Local<v8::Context> context) | 337 explicit ScriptExecutionCallbackHelper(v8::Local<v8::Context> context) |
| 338 : m_didComplete(false), m_context(context) {} | 338 : m_didComplete(false), m_boolValue(false), m_context(context) {} |
| 339 ~ScriptExecutionCallbackHelper() {} | 339 ~ScriptExecutionCallbackHelper() {} |
| 340 | 340 |
| 341 bool didComplete() const { return m_didComplete; } | 341 bool didComplete() const { return m_didComplete; } |
| 342 const String& stringValue() const { return m_stringValue; } | 342 const String& stringValue() const { return m_stringValue; } |
| 343 bool boolValue() { return m_boolValue; } | |
| 343 | 344 |
| 344 private: | 345 private: |
| 345 void completed(const WebVector<v8::Local<v8::Value>>& values) override { | 346 void completed(const WebVector<v8::Local<v8::Value>>& values) override { |
| 346 m_didComplete = true; | 347 m_didComplete = true; |
| 347 if (!values.isEmpty() && values[0]->IsString()) { | 348 if (!values.isEmpty()) { |
| 348 m_stringValue = | 349 if (values[0]->IsString()) { |
| 349 toCoreString(values[0]->ToString(m_context).ToLocalChecked()); | 350 m_stringValue = |
| 351 toCoreString(values[0]->ToString(m_context).ToLocalChecked()); | |
| 352 } else if (values[0]->IsBoolean()) { | |
| 353 m_boolValue = values[0].As<v8::Boolean>()->Value(); | |
| 354 } | |
| 350 } | 355 } |
| 351 } | 356 } |
| 352 | 357 |
| 353 bool m_didComplete; | 358 bool m_didComplete; |
| 354 String m_stringValue; | 359 String m_stringValue; |
| 360 bool m_boolValue; | |
| 355 v8::Local<v8::Context> m_context; | 361 v8::Local<v8::Context> m_context; |
| 356 }; | 362 }; |
| 357 | 363 |
| 358 TEST_P(ParameterizedWebFrameTest, RequestExecuteScript) { | 364 TEST_P(ParameterizedWebFrameTest, RequestExecuteScript) { |
| 359 registerMockedHttpURLLoad("foo.html"); | 365 registerMockedHttpURLLoad("foo.html"); |
| 360 | 366 |
| 361 FrameTestHelpers::WebViewHelper webViewHelper; | 367 FrameTestHelpers::WebViewHelper webViewHelper; |
| 362 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); | 368 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); |
| 363 | 369 |
| 364 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 370 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 365 ScriptExecutionCallbackHelper callbackHelper( | 371 ScriptExecutionCallbackHelper callbackHelper( |
| 366 webViewHelper.webView()->mainFrame()->mainWorldScriptContext()); | 372 webViewHelper.webView()->mainFrame()->mainWorldScriptContext()); |
| 367 webViewHelper.webView() | 373 webViewHelper.webView() |
| 368 ->mainFrame() | 374 ->mainFrame() |
| 369 ->toWebLocalFrame() | 375 ->toWebLocalFrame() |
| 370 ->requestExecuteScriptAndReturnValue( | 376 ->requestExecuteScriptAndReturnValue( |
| 371 WebScriptSource(WebString("'hello';")), false, &callbackHelper); | 377 WebScriptSource(WebString("'hello';")), false, &callbackHelper); |
| 372 runPendingTasks(); | 378 runPendingTasks(); |
| 373 EXPECT_TRUE(callbackHelper.didComplete()); | 379 EXPECT_TRUE(callbackHelper.didComplete()); |
| 374 EXPECT_EQ("hello", callbackHelper.stringValue()); | 380 EXPECT_EQ("hello", callbackHelper.stringValue()); |
| 375 } | 381 } |
| 376 | 382 |
| 383 TEST_P(ParameterizedWebFrameTest, RequestExecuteScriptWithUserGesture) { | |
| 384 registerMockedHttpURLLoad("foo.html"); | |
| 385 | |
| 386 FrameTestHelpers::WebViewHelper webViewHelper; | |
| 387 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); | |
| 388 | |
| 389 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
| 390 ScriptExecutionCallbackHelper callbackHelper( | |
| 391 webViewHelper.webView()->mainFrame()->mainWorldScriptContext()); | |
| 392 | |
| 393 WebLocalFrameImpl* mainFrame = webViewHelper.webView()->mainFrameImpl(); | |
| 394 Document* document = mainFrame->frame()->document(); | |
| 395 mainFrame->requestExecuteScriptAndReturnValue( | |
| 396 WebScriptSource(WebString("document.body.webkitRequestFullscreen();")), | |
| 397 true, &callbackHelper); | |
| 398 runPendingTasks(); | |
| 399 EXPECT_TRUE(callbackHelper.didComplete()); | |
| 400 EXPECT_EQ(document->body(), | |
|
Devlin
2016/10/27 23:33:28
I'd like to add this test (and a similar one for s
dcheng
2016/10/28 17:24:17
I think that's because there's no user gesture act
Devlin
2016/10/28 20:31:37
the "true" parameter in the requestExecuteScriptAn
Devlin
2016/10/31 17:00:46
FYI, I've removed this test since making it work w
| |
| 401 Fullscreen::currentFullScreenElementFrom(*document)); | |
| 402 } | |
| 403 | |
| 377 TEST_P(ParameterizedWebFrameTest, SuspendedRequestExecuteScript) { | 404 TEST_P(ParameterizedWebFrameTest, SuspendedRequestExecuteScript) { |
| 378 registerMockedHttpURLLoad("foo.html"); | 405 registerMockedHttpURLLoad("foo.html"); |
| 379 registerMockedHttpURLLoad("bar.html"); | 406 registerMockedHttpURLLoad("bar.html"); |
| 380 | 407 |
| 381 FrameTestHelpers::WebViewHelper webViewHelper; | 408 FrameTestHelpers::WebViewHelper webViewHelper; |
| 382 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); | 409 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); |
| 383 | 410 |
| 384 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 411 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 385 ScriptExecutionCallbackHelper callbackHelper( | 412 ScriptExecutionCallbackHelper callbackHelper( |
| 386 webViewHelper.webView()->mainFrame()->mainWorldScriptContext()); | 413 webViewHelper.webView()->mainFrame()->mainWorldScriptContext()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 397 EXPECT_FALSE(callbackHelper.didComplete()); | 424 EXPECT_FALSE(callbackHelper.didComplete()); |
| 398 | 425 |
| 399 // If the frame navigates, pending scripts should be removed, but the callback | 426 // If the frame navigates, pending scripts should be removed, but the callback |
| 400 // should always be ran. | 427 // should always be ran. |
| 401 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), | 428 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), |
| 402 m_baseURL + "bar.html"); | 429 m_baseURL + "bar.html"); |
| 403 EXPECT_TRUE(callbackHelper.didComplete()); | 430 EXPECT_TRUE(callbackHelper.didComplete()); |
| 404 EXPECT_EQ(String(), callbackHelper.stringValue()); | 431 EXPECT_EQ(String(), callbackHelper.stringValue()); |
| 405 } | 432 } |
| 406 | 433 |
| 434 TEST_P(ParameterizedWebFrameTest, RequestExecuteV8Function) { | |
| 435 registerMockedHttpURLLoad("foo.html"); | |
| 436 | |
| 437 FrameTestHelpers::WebViewHelper webViewHelper; | |
| 438 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); | |
| 439 | |
| 440 auto callback = [](const v8::FunctionCallbackInfo<v8::Value>& info) { | |
| 441 info.GetReturnValue().Set(v8String(info.GetIsolate(), "hello")); | |
| 442 }; | |
| 443 | |
| 444 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
| 445 v8::Local<v8::Context> context = | |
| 446 webViewHelper.webView()->mainFrame()->mainWorldScriptContext(); | |
| 447 ScriptExecutionCallbackHelper callbackHelper(context); | |
| 448 v8::Local<v8::Function> function = | |
| 449 v8::Function::New(context, callback).ToLocalChecked(); | |
| 450 webViewHelper.webView() | |
| 451 ->mainFrame() | |
| 452 ->toWebLocalFrame() | |
| 453 ->requestExecuteV8Function(context, function, | |
| 454 v8::Undefined(context->GetIsolate()), 0, | |
| 455 nullptr, &callbackHelper); | |
| 456 runPendingTasks(); | |
| 457 EXPECT_TRUE(callbackHelper.didComplete()); | |
| 458 EXPECT_EQ("hello", callbackHelper.stringValue()); | |
| 459 } | |
| 460 | |
| 461 TEST_P(ParameterizedWebFrameTest, RequestExecuteV8FunctionWhileSuspended) { | |
| 462 registerMockedHttpURLLoad("foo.html"); | |
| 463 | |
| 464 FrameTestHelpers::WebViewHelper webViewHelper; | |
| 465 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); | |
| 466 | |
| 467 auto callback = [](const v8::FunctionCallbackInfo<v8::Value>& info) { | |
| 468 info.GetReturnValue().Set(v8String(info.GetIsolate(), "hello")); | |
| 469 }; | |
| 470 | |
| 471 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
| 472 v8::Local<v8::Context> context = | |
| 473 webViewHelper.webView()->mainFrame()->mainWorldScriptContext(); | |
| 474 | |
| 475 // Suspend scheduled tasks so the script doesn't run. | |
| 476 WebLocalFrameImpl* mainFrame = webViewHelper.webView()->mainFrameImpl(); | |
| 477 mainFrame->frame()->document()->suspendScheduledTasks(); | |
| 478 | |
| 479 ScriptExecutionCallbackHelper callbackHelper(context); | |
| 480 v8::Local<v8::Function> function = | |
| 481 v8::Function::New(context, callback).ToLocalChecked(); | |
| 482 mainFrame->requestExecuteV8Function(context, function, | |
| 483 v8::Undefined(context->GetIsolate()), 0, | |
| 484 nullptr, &callbackHelper); | |
| 485 runPendingTasks(); | |
| 486 EXPECT_FALSE(callbackHelper.didComplete()); | |
| 487 | |
| 488 mainFrame->frame()->document()->resumeScheduledTasks(); | |
| 489 runPendingTasks(); | |
| 490 EXPECT_TRUE(callbackHelper.didComplete()); | |
| 491 EXPECT_EQ("hello", callbackHelper.stringValue()); | |
| 492 } | |
| 493 | |
| 494 TEST_P(ParameterizedWebFrameTest, | |
| 495 RequestExecuteV8FunctionWhileSuspendedWithUserGesture) { | |
| 496 registerMockedHttpURLLoad("foo.html"); | |
| 497 | |
| 498 FrameTestHelpers::WebViewHelper webViewHelper; | |
| 499 webViewHelper.initializeAndLoad(m_baseURL + "foo.html", true); | |
| 500 | |
| 501 auto callback = [](const v8::FunctionCallbackInfo<v8::Value>& info) { | |
| 502 info.GetReturnValue().Set(v8::Boolean::New( | |
| 503 info.GetIsolate(), UserGestureIndicator::processingUserGesture())); | |
| 504 }; | |
| 505 | |
| 506 // Suspend scheduled tasks so the script doesn't run. | |
| 507 WebLocalFrameImpl* mainFrame = webViewHelper.webView()->mainFrameImpl(); | |
| 508 Document* document = mainFrame->frame()->document(); | |
| 509 document->suspendScheduledTasks(); | |
| 510 | |
| 511 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
| 512 v8::Local<v8::Context> context = | |
| 513 webViewHelper.webView()->mainFrame()->mainWorldScriptContext(); | |
| 514 | |
| 515 std::unique_ptr<UserGestureIndicator> indicator = | |
| 516 wrapUnique(new UserGestureIndicator(DocumentUserGestureToken::create( | |
| 517 document, UserGestureToken::NewGesture))); | |
| 518 ScriptExecutionCallbackHelper callbackHelper(context); | |
| 519 v8::Local<v8::Function> function = | |
| 520 v8::Function::New(context, callback).ToLocalChecked(); | |
| 521 mainFrame->requestExecuteV8Function( | |
| 522 mainFrame->mainWorldScriptContext(), function, | |
| 523 v8::Undefined(context->GetIsolate()), 0, nullptr, &callbackHelper); | |
| 524 | |
| 525 runPendingTasks(); | |
| 526 EXPECT_FALSE(callbackHelper.didComplete()); | |
| 527 | |
| 528 mainFrame->frame()->document()->resumeScheduledTasks(); | |
| 529 runPendingTasks(); | |
| 530 EXPECT_TRUE(callbackHelper.didComplete()); | |
| 531 EXPECT_EQ(true, callbackHelper.boolValue()); | |
| 532 } | |
| 533 | |
| 407 TEST_P(ParameterizedWebFrameTest, IframeScriptRemovesSelf) { | 534 TEST_P(ParameterizedWebFrameTest, IframeScriptRemovesSelf) { |
| 408 registerMockedHttpURLLoad("single_iframe.html"); | 535 registerMockedHttpURLLoad("single_iframe.html"); |
| 409 registerMockedHttpURLLoad("visible_iframe.html"); | 536 registerMockedHttpURLLoad("visible_iframe.html"); |
| 410 | 537 |
| 411 FrameTestHelpers::WebViewHelper webViewHelper; | 538 FrameTestHelpers::WebViewHelper webViewHelper; |
| 412 webViewHelper.initializeAndLoad(m_baseURL + "single_iframe.html", true); | 539 webViewHelper.initializeAndLoad(m_baseURL + "single_iframe.html", true); |
| 413 | 540 |
| 414 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 541 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 415 ScriptExecutionCallbackHelper callbackHelper( | 542 ScriptExecutionCallbackHelper callbackHelper( |
| 416 webViewHelper.webView()->mainFrame()->mainWorldScriptContext()); | 543 webViewHelper.webView()->mainFrame()->mainWorldScriptContext()); |
| (...skipping 9844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10261 webViewHelper.webView()->handleInputEvent(endEvent); | 10388 webViewHelper.webView()->handleInputEvent(endEvent); |
| 10262 webViewHelper.webView()->handleInputEvent(updateEvent); | 10389 webViewHelper.webView()->handleInputEvent(updateEvent); |
| 10263 | 10390 |
| 10264 // Try a full Begin/Update/End cycle. | 10391 // Try a full Begin/Update/End cycle. |
| 10265 webViewHelper.webView()->handleInputEvent(beginEvent); | 10392 webViewHelper.webView()->handleInputEvent(beginEvent); |
| 10266 webViewHelper.webView()->handleInputEvent(updateEvent); | 10393 webViewHelper.webView()->handleInputEvent(updateEvent); |
| 10267 webViewHelper.webView()->handleInputEvent(endEvent); | 10394 webViewHelper.webView()->handleInputEvent(endEvent); |
| 10268 } | 10395 } |
| 10269 | 10396 |
| 10270 } // namespace blink | 10397 } // namespace blink |
| OLD | NEW |