| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 3465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3476 | 3476 |
| 3477 // For oilpan we have to force a GC to ensure the event handlers have been | 3477 // For oilpan we have to force a GC to ensure the event handlers have been |
| 3478 // removed when checking below. We do a precise GC (collectAllGarbage does not | 3478 // removed when checking below. We do a precise GC (collectAllGarbage does not |
| 3479 // scan the stack) to ensure the div element dies. This is also why the | 3479 // scan the stack) to ensure the div element dies. This is also why the |
| 3480 // Document is in a Persistent since we want that to stay around. | 3480 // Document is in a Persistent since we want that to stay around. |
| 3481 ThreadState::current()->collectAllGarbage(); | 3481 ThreadState::current()->collectAllGarbage(); |
| 3482 | 3482 |
| 3483 EXPECT_FALSE(registry.hasEventHandlers(EventHandlerRegistry::ScrollEvent)); | 3483 EXPECT_FALSE(registry.hasEventHandlers(EventHandlerRegistry::ScrollEvent)); |
| 3484 } | 3484 } |
| 3485 | 3485 |
| 3486 class NonUserInputTextUpdateWebWidgetClient | |
| 3487 : public FrameTestHelpers::TestWebWidgetClient { | |
| 3488 public: | |
| 3489 NonUserInputTextUpdateWebWidgetClient() : m_textIsUpdated(false) {} | |
| 3490 | |
| 3491 // WebWidgetClient methods | |
| 3492 void didUpdateTextOfFocusedElementByNonUserInput() override { | |
| 3493 m_textIsUpdated = true; | |
| 3494 } | |
| 3495 | |
| 3496 void reset() { m_textIsUpdated = false; } | |
| 3497 | |
| 3498 bool textIsUpdated() const { return m_textIsUpdated; } | |
| 3499 | |
| 3500 private: | |
| 3501 int m_textIsUpdated; | |
| 3502 }; | |
| 3503 | |
| 3504 // This test verifies the text input flags are correctly exposed to script. | 3486 // This test verifies the text input flags are correctly exposed to script. |
| 3505 TEST_P(WebViewTest, TextInputFlags) { | 3487 TEST_P(WebViewTest, TextInputFlags) { |
| 3506 std::string url = m_baseURL + "text_input_flags.html"; | 3488 std::string url = m_baseURL + "text_input_flags.html"; |
| 3507 URLTestHelpers::registerMockedURLLoad(toKURL(url), "text_input_flags.html"); | 3489 URLTestHelpers::registerMockedURLLoad(toKURL(url), "text_input_flags.html"); |
| 3508 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true); | 3490 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true); |
| 3509 webViewImpl->setInitialFocus(false); | 3491 webViewImpl->setInitialFocus(false); |
| 3510 | 3492 |
| 3511 WebLocalFrameImpl* frame = webViewImpl->mainFrameImpl(); | 3493 WebLocalFrameImpl* frame = webViewImpl->mainFrameImpl(); |
| 3512 Document* document = frame->frame()->document(); | 3494 Document* document = frame->frame()->document(); |
| 3513 | 3495 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3551 EXPECT_EQ(WebTextInputFlagAutocapitalizeSentences, info3.flags); | 3533 EXPECT_EQ(WebTextInputFlagAutocapitalizeSentences, info3.flags); |
| 3552 | 3534 |
| 3553 // (C) Verifies the WebTextInputInfo's don't equal. | 3535 // (C) Verifies the WebTextInputInfo's don't equal. |
| 3554 EXPECT_FALSE(info1.equals(info2)); | 3536 EXPECT_FALSE(info1.equals(info2)); |
| 3555 EXPECT_FALSE(info2.equals(info3)); | 3537 EXPECT_FALSE(info2.equals(info3)); |
| 3556 | 3538 |
| 3557 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. | 3539 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. |
| 3558 m_webViewHelper.reset(); | 3540 m_webViewHelper.reset(); |
| 3559 } | 3541 } |
| 3560 | 3542 |
| 3561 // This test verifies that | |
| 3562 // WebWidgetClient::didUpdateTextOfFocusedElementByNonUserInput is called iff | |
| 3563 // value of a focused element is modified via script. | |
| 3564 TEST_P(WebViewTest, NonUserInputTextUpdate) { | |
| 3565 NonUserInputTextUpdateWebWidgetClient client; | |
| 3566 std::string url = m_baseURL + "non_user_input_text_update.html"; | |
| 3567 URLTestHelpers::registerMockedURLLoad(toKURL(url), | |
| 3568 "non_user_input_text_update.html"); | |
| 3569 WebViewImpl* webViewImpl = | |
| 3570 m_webViewHelper.initializeAndLoad(url, true, nullptr, nullptr, &client); | |
| 3571 webViewImpl->setInitialFocus(false); | |
| 3572 | |
| 3573 WebLocalFrameImpl* frame = webViewImpl->mainFrameImpl(); | |
| 3574 Document* document = frame->frame()->document(); | |
| 3575 WebInputMethodController* activeInputMethodController = | |
| 3576 frame->frameWidget()->getActiveWebInputMethodController(); | |
| 3577 | |
| 3578 // (A) <input> | |
| 3579 // (A.1) Focused and value is changed by script. | |
| 3580 client.reset(); | |
| 3581 EXPECT_FALSE(client.textIsUpdated()); | |
| 3582 | |
| 3583 HTMLInputElement* inputElement = | |
| 3584 toHTMLInputElement(document->getElementById("input")); | |
| 3585 document->setFocusedElement( | |
| 3586 inputElement, | |
| 3587 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | |
| 3588 webViewImpl->setFocus(true); | |
| 3589 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(inputElement)); | |
| 3590 | |
| 3591 // Emulate value change from script. | |
| 3592 inputElement->setValue("testA"); | |
| 3593 EXPECT_TRUE(client.textIsUpdated()); | |
| 3594 WebTextInputInfo info = webViewImpl->textInputInfo(); | |
| 3595 EXPECT_EQ("testA", std::string(info.value.utf8().data())); | |
| 3596 | |
| 3597 // (A.2) Focused and user input modifies value. | |
| 3598 client.reset(); | |
| 3599 EXPECT_FALSE(client.textIsUpdated()); | |
| 3600 | |
| 3601 WebVector<WebCompositionUnderline> emptyUnderlines; | |
| 3602 activeInputMethodController->setComposition(WebString::fromUTF8("2"), | |
| 3603 emptyUnderlines, 1, 1); | |
| 3604 activeInputMethodController->finishComposingText( | |
| 3605 WebInputMethodController::KeepSelection); | |
| 3606 EXPECT_FALSE(client.textIsUpdated()); | |
| 3607 info = webViewImpl->textInputInfo(); | |
| 3608 EXPECT_EQ("testA2", std::string(info.value.utf8().data())); | |
| 3609 | |
| 3610 // (A.3) Unfocused and value is changed by script. | |
| 3611 client.reset(); | |
| 3612 EXPECT_FALSE(client.textIsUpdated()); | |
| 3613 document->clearFocusedElement(); | |
| 3614 webViewImpl->setFocus(false); | |
| 3615 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement)); | |
| 3616 inputElement->setValue("testA3"); | |
| 3617 EXPECT_FALSE(client.textIsUpdated()); | |
| 3618 | |
| 3619 // (B) <textarea> | |
| 3620 // (B.1) Focused and value is changed by script. | |
| 3621 client.reset(); | |
| 3622 EXPECT_FALSE(client.textIsUpdated()); | |
| 3623 HTMLTextAreaElement* textAreaElement = | |
| 3624 toHTMLTextAreaElement(document->getElementById("textarea")); | |
| 3625 document->setFocusedElement( | |
| 3626 textAreaElement, | |
| 3627 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | |
| 3628 webViewImpl->setFocus(true); | |
| 3629 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement)); | |
| 3630 textAreaElement->setValue("testB"); | |
| 3631 EXPECT_TRUE(client.textIsUpdated()); | |
| 3632 info = webViewImpl->textInputInfo(); | |
| 3633 EXPECT_EQ("testB", std::string(info.value.utf8().data())); | |
| 3634 | |
| 3635 // (B.2) Focused and user input modifies value. | |
| 3636 client.reset(); | |
| 3637 EXPECT_FALSE(client.textIsUpdated()); | |
| 3638 activeInputMethodController->setComposition(WebString::fromUTF8("2"), | |
| 3639 emptyUnderlines, 1, 1); | |
| 3640 activeInputMethodController->finishComposingText( | |
| 3641 WebInputMethodController::KeepSelection); | |
| 3642 info = webViewImpl->textInputInfo(); | |
| 3643 EXPECT_EQ("testB2", std::string(info.value.utf8().data())); | |
| 3644 | |
| 3645 // (B.3) Unfocused and value is changed by script. | |
| 3646 client.reset(); | |
| 3647 EXPECT_FALSE(client.textIsUpdated()); | |
| 3648 document->clearFocusedElement(); | |
| 3649 webViewImpl->setFocus(false); | |
| 3650 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement)); | |
| 3651 inputElement->setValue("testB3"); | |
| 3652 EXPECT_FALSE(client.textIsUpdated()); | |
| 3653 | |
| 3654 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. | |
| 3655 m_webViewHelper.reset(); | |
| 3656 } | |
| 3657 | |
| 3658 // Check that the WebAutofillClient is correctly notified about first user | 3543 // Check that the WebAutofillClient is correctly notified about first user |
| 3659 // gestures after load, following various input events. | 3544 // gestures after load, following various input events. |
| 3660 TEST_P(WebViewTest, FirstUserGestureObservedKeyEvent) { | 3545 TEST_P(WebViewTest, FirstUserGestureObservedKeyEvent) { |
| 3661 URLTestHelpers::registerMockedURLFromBaseURL( | 3546 URLTestHelpers::registerMockedURLFromBaseURL( |
| 3662 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("form.html")); | 3547 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("form.html")); |
| 3663 MockAutofillClient client; | 3548 MockAutofillClient client; |
| 3664 WebViewImpl* webView = | 3549 WebViewImpl* webView = |
| 3665 m_webViewHelper.initializeAndLoad(m_baseURL + "form.html", true); | 3550 m_webViewHelper.initializeAndLoad(m_baseURL + "form.html", true); |
| 3666 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 3551 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 3667 frame->setAutofillClient(&client); | 3552 frame->setAutofillClient(&client); |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4360 .translate(50, 55) | 4245 .translate(50, 55) |
| 4361 .scale(1. / 2.f); | 4246 .scale(1. / 2.f); |
| 4362 EXPECT_EQ(expectedMatrix, | 4247 EXPECT_EQ(expectedMatrix, |
| 4363 webViewImpl->getDeviceEmulationTransformForTesting()); | 4248 webViewImpl->getDeviceEmulationTransformForTesting()); |
| 4364 // visibleContentRect doesn't change. | 4249 // visibleContentRect doesn't change. |
| 4365 EXPECT_EQ(IntRect(50, 55, 50, 75), | 4250 EXPECT_EQ(IntRect(50, 55, 50, 75), |
| 4366 *devToolsEmulator->visibleContentRectForPainting()); | 4251 *devToolsEmulator->visibleContentRectForPainting()); |
| 4367 } | 4252 } |
| 4368 | 4253 |
| 4369 } // namespace blink | 4254 } // namespace blink |
| OLD | NEW |