| 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 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2601 event.x = 20; | 2601 event.x = 20; |
| 2602 event.y = 20; | 2602 event.y = 20; |
| 2603 | 2603 |
| 2604 // Just make sure we don't hit any asserts. | 2604 // Just make sure we don't hit any asserts. |
| 2605 webViewImpl->handleInputEvent(WebCoalescedInputEvent(event)); | 2605 webViewImpl->handleInputEvent(WebCoalescedInputEvent(event)); |
| 2606 } | 2606 } |
| 2607 | 2607 |
| 2608 class MockAutofillClient : public WebAutofillClient { | 2608 class MockAutofillClient : public WebAutofillClient { |
| 2609 public: | 2609 public: |
| 2610 MockAutofillClient() | 2610 MockAutofillClient() |
| 2611 : m_ignoreTextChanges(false), | 2611 : m_textChanges(0), |
| 2612 m_textChangesFromUserGesture(0), | 2612 m_textChangesFromUserGesture(0), |
| 2613 m_textChangesWhileIgnored(0), | |
| 2614 m_textChangesWhileNotIgnored(0), | |
| 2615 m_userGestureNotificationsCount(0) {} | 2613 m_userGestureNotificationsCount(0) {} |
| 2616 | 2614 |
| 2617 ~MockAutofillClient() override {} | 2615 ~MockAutofillClient() override {} |
| 2618 | 2616 |
| 2619 void setIgnoreTextChanges(bool ignore) override { | |
| 2620 m_ignoreTextChanges = ignore; | |
| 2621 } | |
| 2622 void textFieldDidChange(const WebFormControlElement&) override { | 2617 void textFieldDidChange(const WebFormControlElement&) override { |
| 2623 if (m_ignoreTextChanges) | 2618 ++m_textChanges; |
| 2624 ++m_textChangesWhileIgnored; | |
| 2625 else | |
| 2626 ++m_textChangesWhileNotIgnored; | |
| 2627 | 2619 |
| 2628 if (UserGestureIndicator::processingUserGesture()) | 2620 if (UserGestureIndicator::processingUserGesture()) |
| 2629 ++m_textChangesFromUserGesture; | 2621 ++m_textChangesFromUserGesture; |
| 2630 } | 2622 } |
| 2631 void firstUserGestureObserved() override { | 2623 void firstUserGestureObserved() override { |
| 2632 ++m_userGestureNotificationsCount; | 2624 ++m_userGestureNotificationsCount; |
| 2633 } | 2625 } |
| 2634 | 2626 |
| 2635 void clearChangeCounts() { | 2627 void clearChangeCounts() { m_textChanges = 0; } |
| 2636 m_textChangesWhileIgnored = 0; | |
| 2637 m_textChangesWhileNotIgnored = 0; | |
| 2638 } | |
| 2639 | 2628 |
| 2629 int textChanges() { return m_textChanges; } |
| 2640 int textChangesFromUserGesture() { return m_textChangesFromUserGesture; } | 2630 int textChangesFromUserGesture() { return m_textChangesFromUserGesture; } |
| 2641 int textChangesWhileIgnored() { return m_textChangesWhileIgnored; } | |
| 2642 int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; } | |
| 2643 int getUserGestureNotificationsCount() { | 2631 int getUserGestureNotificationsCount() { |
| 2644 return m_userGestureNotificationsCount; | 2632 return m_userGestureNotificationsCount; |
| 2645 } | 2633 } |
| 2646 | 2634 |
| 2647 private: | 2635 private: |
| 2648 bool m_ignoreTextChanges; | 2636 int m_textChanges; |
| 2649 int m_textChangesFromUserGesture; | 2637 int m_textChangesFromUserGesture; |
| 2650 int m_textChangesWhileIgnored; | |
| 2651 int m_textChangesWhileNotIgnored; | |
| 2652 int m_userGestureNotificationsCount; | 2638 int m_userGestureNotificationsCount; |
| 2653 }; | 2639 }; |
| 2654 | 2640 |
| 2655 TEST_P(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) { | 2641 TEST_P(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) { |
| 2656 registerMockedHttpURLLoad("input_field_populated.html"); | 2642 registerMockedHttpURLLoad("input_field_populated.html"); |
| 2657 MockAutofillClient client; | 2643 MockAutofillClient client; |
| 2658 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 2644 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 2659 m_baseURL + "input_field_populated.html"); | 2645 m_baseURL + "input_field_populated.html"); |
| 2660 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2646 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2661 frame->setAutofillClient(&client); | 2647 frame->setAutofillClient(&client); |
| 2662 webView->setInitialFocus(false); | 2648 webView->setInitialFocus(false); |
| 2663 | 2649 |
| 2664 // Set up a composition that needs to be committed. | 2650 // Set up a composition that needs to be committed. |
| 2665 WebVector<WebCompositionUnderline> emptyUnderlines; | 2651 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2666 frame->setEditableSelectionOffsets(4, 10); | 2652 frame->setEditableSelectionOffsets(4, 10); |
| 2667 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2653 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 2668 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); | 2654 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); |
| 2669 EXPECT_EQ(4, info.selectionStart); | 2655 EXPECT_EQ(4, info.selectionStart); |
| 2670 EXPECT_EQ(10, info.selectionEnd); | 2656 EXPECT_EQ(10, info.selectionEnd); |
| 2671 EXPECT_EQ(8, info.compositionStart); | 2657 EXPECT_EQ(8, info.compositionStart); |
| 2672 EXPECT_EQ(12, info.compositionEnd); | 2658 EXPECT_EQ(12, info.compositionEnd); |
| 2673 | 2659 |
| 2674 // Clear the focus and track that the subsequent composition commit does not | 2660 // Clear the focus and track that the subsequent composition commit does not |
| 2675 // trigger a text changed notification for autofill. | 2661 // trigger a text changed notification for autofill. |
| 2676 client.clearChangeCounts(); | 2662 client.clearChangeCounts(); |
| 2677 webView->setFocus(false); | 2663 webView->setFocus(false); |
| 2678 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 2664 EXPECT_EQ(0, client.textChanges()); |
| 2679 | 2665 |
| 2680 frame->setAutofillClient(0); | 2666 frame->setAutofillClient(0); |
| 2681 } | 2667 } |
| 2682 | 2668 |
| 2683 static void verifySelectionAndComposition(WebViewImpl* webView, | 2669 static void verifySelectionAndComposition(WebViewImpl* webView, |
| 2684 int selectionStart, | 2670 int selectionStart, |
| 2685 int selectionEnd, | 2671 int selectionEnd, |
| 2686 int compositionStart, | 2672 int compositionStart, |
| 2687 int compositionEnd, | 2673 int compositionEnd, |
| 2688 const char* failMessage) { | 2674 const char* failMessage) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2733 | 2719 |
| 2734 keyEvent.setType(WebInputEvent::KeyUp); | 2720 keyEvent.setType(WebInputEvent::KeyUp); |
| 2735 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); | 2721 webView->handleInputEvent(WebCoalescedInputEvent(keyEvent)); |
| 2736 | 2722 |
| 2737 webView->advanceFocus(false); | 2723 webView->advanceFocus(false); |
| 2738 } | 2724 } |
| 2739 | 2725 |
| 2740 frame->setAutofillClient(0); | 2726 frame->setAutofillClient(0); |
| 2741 } | 2727 } |
| 2742 | 2728 |
| 2743 TEST_P(WebViewTest, FinishComposingTextTriggersAutofillTextChange) { | 2729 TEST_P(WebViewTest, FinishComposingTextDoesntTriggerAutofillTextChange) { |
| 2744 registerMockedHttpURLLoad("input_field_populated.html"); | 2730 registerMockedHttpURLLoad("input_field_populated.html"); |
| 2745 MockAutofillClient client; | 2731 MockAutofillClient client; |
| 2746 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 2732 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 2747 m_baseURL + "input_field_populated.html"); | 2733 m_baseURL + "input_field_populated.html"); |
| 2748 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2734 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2749 frame->setAutofillClient(&client); | 2735 frame->setAutofillClient(&client); |
| 2750 webView->setInitialFocus(false); | 2736 webView->setInitialFocus(false); |
| 2737 |
| 2738 WebDocument document = webView->mainFrame()->document(); |
| 2739 HTMLFormControlElement* form = |
| 2740 toHTMLFormControlElement(document.getElementById("sample")); |
| 2741 |
| 2751 WebInputMethodController* activeInputMethodController = | 2742 WebInputMethodController* activeInputMethodController = |
| 2752 frame->frameWidget()->getActiveWebInputMethodController(); | 2743 frame->frameWidget()->getActiveWebInputMethodController(); |
| 2753 // Set up a composition that needs to be committed. | 2744 // Set up a composition that needs to be committed. |
| 2754 std::string compositionText("testingtext"); | 2745 std::string compositionText("testingtext"); |
| 2755 | 2746 |
| 2756 WebVector<WebCompositionUnderline> emptyUnderlines; | 2747 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2757 activeInputMethodController->setComposition( | 2748 activeInputMethodController->setComposition( |
| 2758 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, | 2749 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, |
| 2759 compositionText.length()); | 2750 compositionText.length()); |
| 2760 | 2751 |
| 2761 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 2752 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 2762 EXPECT_EQ(0, info.selectionStart); | 2753 EXPECT_EQ(0, info.selectionStart); |
| 2763 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); | 2754 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); |
| 2764 EXPECT_EQ(0, info.compositionStart); | 2755 EXPECT_EQ(0, info.compositionStart); |
| 2765 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); | 2756 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); |
| 2766 | 2757 |
| 2758 form->setAutofilled(true); |
| 2767 client.clearChangeCounts(); | 2759 client.clearChangeCounts(); |
| 2760 |
| 2768 activeInputMethodController->finishComposingText( | 2761 activeInputMethodController->finishComposingText( |
| 2769 WebInputMethodController::KeepSelection); | 2762 WebInputMethodController::KeepSelection); |
| 2770 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 2763 EXPECT_EQ(0, client.textChanges()); |
| 2771 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); | 2764 |
| 2765 EXPECT_TRUE(form->isAutofilled()); |
| 2772 | 2766 |
| 2773 frame->setAutofillClient(0); | 2767 frame->setAutofillClient(0); |
| 2774 } | 2768 } |
| 2775 | 2769 |
| 2776 TEST_P(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) { | 2770 TEST_P(WebViewTest, |
| 2771 SetCompositionFromExistingTextDoesntTriggerAutofillTextChange) { |
| 2777 registerMockedHttpURLLoad("input_field_populated.html"); | 2772 registerMockedHttpURLLoad("input_field_populated.html"); |
| 2778 MockAutofillClient client; | 2773 MockAutofillClient client; |
| 2779 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 2774 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 2780 m_baseURL + "input_field_populated.html", true); | 2775 m_baseURL + "input_field_populated.html", true); |
| 2781 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2776 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2782 frame->setAutofillClient(&client); | 2777 frame->setAutofillClient(&client); |
| 2783 webView->setInitialFocus(false); | 2778 webView->setInitialFocus(false); |
| 2784 | 2779 |
| 2785 WebVector<WebCompositionUnderline> emptyUnderlines; | 2780 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2786 | 2781 |
| 2787 client.clearChangeCounts(); | 2782 client.clearChangeCounts(); |
| 2788 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2783 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 2789 | 2784 |
| 2790 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); | 2785 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); |
| 2791 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", | 2786 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", |
| 2792 std::string(info.value.utf8().data())); | 2787 std::string(info.value.utf8().data())); |
| 2793 EXPECT_EQ(8, info.compositionStart); | 2788 EXPECT_EQ(8, info.compositionStart); |
| 2794 EXPECT_EQ(12, info.compositionEnd); | 2789 EXPECT_EQ(12, info.compositionEnd); |
| 2795 | 2790 |
| 2796 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 2791 EXPECT_EQ(0, client.textChanges()); |
| 2797 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | |
| 2798 | 2792 |
| 2799 WebDocument document = webView->mainFrame()->document(); | 2793 WebDocument document = webView->mainFrame()->document(); |
| 2800 EXPECT_EQ(WebString::fromUTF8("none"), | 2794 EXPECT_EQ(WebString::fromUTF8("none"), |
| 2801 document.getElementById("inputEvent").firstChild().nodeValue()); | 2795 document.getElementById("inputEvent").firstChild().nodeValue()); |
| 2802 | 2796 |
| 2803 frame->setAutofillClient(0); | 2797 frame->setAutofillClient(0); |
| 2804 } | 2798 } |
| 2805 | 2799 |
| 2806 class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient { | 2800 class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient { |
| 2807 public: | 2801 public: |
| (...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4212 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); | 4206 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); |
| 4213 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); | 4207 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); |
| 4214 | 4208 |
| 4215 webView->resize(WebSize(800, 600)); | 4209 webView->resize(WebSize(800, 600)); |
| 4216 frame->printEnd(); | 4210 frame->printEnd(); |
| 4217 | 4211 |
| 4218 EXPECT_EQ(800, vwElement->offsetWidth()); | 4212 EXPECT_EQ(800, vwElement->offsetWidth()); |
| 4219 } | 4213 } |
| 4220 | 4214 |
| 4221 } // namespace blink | 4215 } // namespace blink |
| OLD | NEW |