| 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 2679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2690 event.x = 20; | 2690 event.x = 20; |
| 2691 event.y = 20; | 2691 event.y = 20; |
| 2692 | 2692 |
| 2693 // Just make sure we don't hit any asserts. | 2693 // Just make sure we don't hit any asserts. |
| 2694 webViewImpl->handleInputEvent(event); | 2694 webViewImpl->handleInputEvent(event); |
| 2695 } | 2695 } |
| 2696 | 2696 |
| 2697 class MockAutofillClient : public WebAutofillClient { | 2697 class MockAutofillClient : public WebAutofillClient { |
| 2698 public: | 2698 public: |
| 2699 MockAutofillClient() | 2699 MockAutofillClient() |
| 2700 : m_ignoreTextChanges(false), | 2700 : m_textChanges(0), |
| 2701 m_textChangesFromUserGesture(0), | 2701 m_textChangesFromUserGesture(0), |
| 2702 m_textChangesWhileIgnored(0), | |
| 2703 m_textChangesWhileNotIgnored(0), | |
| 2704 m_userGestureNotificationsCount(0) {} | 2702 m_userGestureNotificationsCount(0) {} |
| 2705 | 2703 |
| 2706 ~MockAutofillClient() override {} | 2704 ~MockAutofillClient() override {} |
| 2707 | 2705 |
| 2708 void setIgnoreTextChanges(bool ignore) override { | |
| 2709 m_ignoreTextChanges = ignore; | |
| 2710 } | |
| 2711 void textFieldDidChange(const WebFormControlElement&) override { | 2706 void textFieldDidChange(const WebFormControlElement&) override { |
| 2712 if (m_ignoreTextChanges) | 2707 ++m_textChanges; |
| 2713 ++m_textChangesWhileIgnored; | |
| 2714 else | |
| 2715 ++m_textChangesWhileNotIgnored; | |
| 2716 | 2708 |
| 2717 if (UserGestureIndicator::processingUserGesture()) | 2709 if (UserGestureIndicator::processingUserGesture()) |
| 2718 ++m_textChangesFromUserGesture; | 2710 ++m_textChangesFromUserGesture; |
| 2719 } | 2711 } |
| 2720 void firstUserGestureObserved() override { | 2712 void firstUserGestureObserved() override { |
| 2721 ++m_userGestureNotificationsCount; | 2713 ++m_userGestureNotificationsCount; |
| 2722 } | 2714 } |
| 2723 | 2715 |
| 2724 void clearChangeCounts() { | 2716 void clearChangeCounts() { m_textChanges = 0; } |
| 2725 m_textChangesWhileIgnored = 0; | |
| 2726 m_textChangesWhileNotIgnored = 0; | |
| 2727 } | |
| 2728 | 2717 |
| 2718 int textChanges() { return m_textChanges; } |
| 2729 int textChangesFromUserGesture() { return m_textChangesFromUserGesture; } | 2719 int textChangesFromUserGesture() { return m_textChangesFromUserGesture; } |
| 2730 int textChangesWhileIgnored() { return m_textChangesWhileIgnored; } | |
| 2731 int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; } | |
| 2732 int getUserGestureNotificationsCount() { | 2720 int getUserGestureNotificationsCount() { |
| 2733 return m_userGestureNotificationsCount; | 2721 return m_userGestureNotificationsCount; |
| 2734 } | 2722 } |
| 2735 | 2723 |
| 2736 private: | 2724 private: |
| 2737 bool m_ignoreTextChanges; | 2725 int m_textChanges; |
| 2738 int m_textChangesFromUserGesture; | 2726 int m_textChangesFromUserGesture; |
| 2739 int m_textChangesWhileIgnored; | |
| 2740 int m_textChangesWhileNotIgnored; | |
| 2741 int m_userGestureNotificationsCount; | 2727 int m_userGestureNotificationsCount; |
| 2742 }; | 2728 }; |
| 2743 | 2729 |
| 2744 TEST_P(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) { | 2730 TEST_P(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) { |
| 2745 URLTestHelpers::registerMockedURLFromBaseURL( | 2731 URLTestHelpers::registerMockedURLFromBaseURL( |
| 2746 WebString::fromUTF8(m_baseURL.c_str()), | 2732 WebString::fromUTF8(m_baseURL.c_str()), |
| 2747 WebString::fromUTF8("input_field_populated.html")); | 2733 WebString::fromUTF8("input_field_populated.html")); |
| 2748 MockAutofillClient client; | 2734 MockAutofillClient client; |
| 2749 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 2735 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 2750 m_baseURL + "input_field_populated.html"); | 2736 m_baseURL + "input_field_populated.html"); |
| 2751 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2737 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2752 frame->setAutofillClient(&client); | 2738 frame->setAutofillClient(&client); |
| 2753 webView->setInitialFocus(false); | 2739 webView->setInitialFocus(false); |
| 2754 | 2740 |
| 2755 // Set up a composition that needs to be committed. | 2741 // Set up a composition that needs to be committed. |
| 2756 WebVector<WebCompositionUnderline> emptyUnderlines; | 2742 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2757 frame->setEditableSelectionOffsets(4, 10); | 2743 frame->setEditableSelectionOffsets(4, 10); |
| 2758 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2744 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 2759 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); | 2745 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); |
| 2760 EXPECT_EQ(4, info.selectionStart); | 2746 EXPECT_EQ(4, info.selectionStart); |
| 2761 EXPECT_EQ(10, info.selectionEnd); | 2747 EXPECT_EQ(10, info.selectionEnd); |
| 2762 EXPECT_EQ(8, info.compositionStart); | 2748 EXPECT_EQ(8, info.compositionStart); |
| 2763 EXPECT_EQ(12, info.compositionEnd); | 2749 EXPECT_EQ(12, info.compositionEnd); |
| 2764 | 2750 |
| 2765 // Clear the focus and track that the subsequent composition commit does not | 2751 // Clear the focus and track that the subsequent composition commit does not |
| 2766 // trigger a text changed notification for autofill. | 2752 // trigger a text changed notification for autofill. |
| 2767 client.clearChangeCounts(); | 2753 client.clearChangeCounts(); |
| 2768 webView->setFocus(false); | 2754 webView->setFocus(false); |
| 2769 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 2755 EXPECT_EQ(0, client.textChanges()); |
| 2770 | 2756 |
| 2771 frame->setAutofillClient(0); | 2757 frame->setAutofillClient(0); |
| 2772 } | 2758 } |
| 2773 | 2759 |
| 2774 static void verifySelectionAndComposition(WebViewImpl* webView, | 2760 static void verifySelectionAndComposition(WebViewImpl* webView, |
| 2775 int selectionStart, | 2761 int selectionStart, |
| 2776 int selectionEnd, | 2762 int selectionEnd, |
| 2777 int compositionStart, | 2763 int compositionStart, |
| 2778 int compositionEnd, | 2764 int compositionEnd, |
| 2779 const char* failMessage) { | 2765 const char* failMessage) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2826 | 2812 |
| 2827 keyEvent.setType(WebInputEvent::KeyUp); | 2813 keyEvent.setType(WebInputEvent::KeyUp); |
| 2828 webView->handleInputEvent(keyEvent); | 2814 webView->handleInputEvent(keyEvent); |
| 2829 | 2815 |
| 2830 webView->advanceFocus(false); | 2816 webView->advanceFocus(false); |
| 2831 } | 2817 } |
| 2832 | 2818 |
| 2833 frame->setAutofillClient(0); | 2819 frame->setAutofillClient(0); |
| 2834 } | 2820 } |
| 2835 | 2821 |
| 2836 TEST_P(WebViewTest, FinishComposingTextTriggersAutofillTextChange) { | 2822 TEST_P(WebViewTest, FinishComposingTextDoesntTriggerAutofillTextChange) { |
| 2837 URLTestHelpers::registerMockedURLFromBaseURL( | 2823 URLTestHelpers::registerMockedURLFromBaseURL( |
| 2838 WebString::fromUTF8(m_baseURL.c_str()), | 2824 WebString::fromUTF8(m_baseURL.c_str()), |
| 2839 WebString::fromUTF8("input_field_populated.html")); | 2825 WebString::fromUTF8("input_field_populated.html")); |
| 2840 MockAutofillClient client; | 2826 MockAutofillClient client; |
| 2841 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 2827 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 2842 m_baseURL + "input_field_populated.html"); | 2828 m_baseURL + "input_field_populated.html"); |
| 2843 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2829 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2844 frame->setAutofillClient(&client); | 2830 frame->setAutofillClient(&client); |
| 2845 webView->setInitialFocus(false); | 2831 webView->setInitialFocus(false); |
| 2832 |
| 2833 WebDocument document = webView->mainFrame()->document(); |
| 2834 HTMLFormControlElement* form = |
| 2835 toHTMLFormControlElement(document.getElementById("sample")); |
| 2836 |
| 2846 WebInputMethodController* activeInputMethodController = | 2837 WebInputMethodController* activeInputMethodController = |
| 2847 frame->frameWidget()->getActiveWebInputMethodController(); | 2838 frame->frameWidget()->getActiveWebInputMethodController(); |
| 2848 // Set up a composition that needs to be committed. | 2839 // Set up a composition that needs to be committed. |
| 2849 std::string compositionText("testingtext"); | 2840 std::string compositionText("testingtext"); |
| 2850 | 2841 |
| 2851 WebVector<WebCompositionUnderline> emptyUnderlines; | 2842 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2852 activeInputMethodController->setComposition( | 2843 activeInputMethodController->setComposition( |
| 2853 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, | 2844 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, |
| 2854 compositionText.length()); | 2845 compositionText.length()); |
| 2855 | 2846 |
| 2856 WebTextInputInfo info = activeInputMethodController->textInputInfo(); | 2847 WebTextInputInfo info = activeInputMethodController->textInputInfo(); |
| 2857 EXPECT_EQ(0, info.selectionStart); | 2848 EXPECT_EQ(0, info.selectionStart); |
| 2858 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); | 2849 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); |
| 2859 EXPECT_EQ(0, info.compositionStart); | 2850 EXPECT_EQ(0, info.compositionStart); |
| 2860 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); | 2851 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); |
| 2861 | 2852 |
| 2853 form->setAutofilled(true); |
| 2862 client.clearChangeCounts(); | 2854 client.clearChangeCounts(); |
| 2855 |
| 2863 activeInputMethodController->finishComposingText( | 2856 activeInputMethodController->finishComposingText( |
| 2864 WebInputMethodController::KeepSelection); | 2857 WebInputMethodController::KeepSelection); |
| 2865 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 2858 EXPECT_EQ(0, client.textChanges()); |
| 2866 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); | 2859 |
| 2860 EXPECT_TRUE(form->isAutofilled()); |
| 2867 | 2861 |
| 2868 frame->setAutofillClient(0); | 2862 frame->setAutofillClient(0); |
| 2869 } | 2863 } |
| 2870 | 2864 |
| 2871 TEST_P(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) { | 2865 TEST_P(WebViewTest, |
| 2866 SetCompositionFromExistingTextDoesntTriggerAutofillTextChange) { |
| 2872 URLTestHelpers::registerMockedURLFromBaseURL( | 2867 URLTestHelpers::registerMockedURLFromBaseURL( |
| 2873 WebString::fromUTF8(m_baseURL.c_str()), | 2868 WebString::fromUTF8(m_baseURL.c_str()), |
| 2874 WebString::fromUTF8("input_field_populated.html")); | 2869 WebString::fromUTF8("input_field_populated.html")); |
| 2875 MockAutofillClient client; | 2870 MockAutofillClient client; |
| 2876 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( | 2871 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( |
| 2877 m_baseURL + "input_field_populated.html", true); | 2872 m_baseURL + "input_field_populated.html", true); |
| 2878 WebLocalFrameImpl* frame = webView->mainFrameImpl(); | 2873 WebLocalFrameImpl* frame = webView->mainFrameImpl(); |
| 2879 frame->setAutofillClient(&client); | 2874 frame->setAutofillClient(&client); |
| 2880 webView->setInitialFocus(false); | 2875 webView->setInitialFocus(false); |
| 2881 | 2876 |
| 2882 WebVector<WebCompositionUnderline> emptyUnderlines; | 2877 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2883 | 2878 |
| 2884 client.clearChangeCounts(); | 2879 client.clearChangeCounts(); |
| 2885 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 2880 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 2886 | 2881 |
| 2887 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); | 2882 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); |
| 2888 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", | 2883 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", |
| 2889 std::string(info.value.utf8().data())); | 2884 std::string(info.value.utf8().data())); |
| 2890 EXPECT_EQ(8, info.compositionStart); | 2885 EXPECT_EQ(8, info.compositionStart); |
| 2891 EXPECT_EQ(12, info.compositionEnd); | 2886 EXPECT_EQ(12, info.compositionEnd); |
| 2892 | 2887 |
| 2893 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 2888 EXPECT_EQ(0, client.textChanges()); |
| 2894 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | |
| 2895 | 2889 |
| 2896 WebDocument document = webView->mainFrame()->document(); | 2890 WebDocument document = webView->mainFrame()->document(); |
| 2897 EXPECT_EQ(WebString::fromUTF8("none"), | 2891 EXPECT_EQ(WebString::fromUTF8("none"), |
| 2898 document.getElementById("inputEvent").firstChild().nodeValue()); | 2892 document.getElementById("inputEvent").firstChild().nodeValue()); |
| 2899 | 2893 |
| 2900 frame->setAutofillClient(0); | 2894 frame->setAutofillClient(0); |
| 2901 } | 2895 } |
| 2902 | 2896 |
| 2903 class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient { | 2897 class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient { |
| 2904 public: | 2898 public: |
| (...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4366 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); | 4360 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); |
| 4367 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); | 4361 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); |
| 4368 | 4362 |
| 4369 webView->resize(WebSize(800, 600)); | 4363 webView->resize(WebSize(800, 600)); |
| 4370 frame->printEnd(); | 4364 frame->printEnd(); |
| 4371 | 4365 |
| 4372 EXPECT_EQ(800, vwElement->offsetWidth()); | 4366 EXPECT_EQ(800, vwElement->offsetWidth()); |
| 4373 } | 4367 } |
| 4374 | 4368 |
| 4375 } // namespace blink | 4369 } // namespace blink |
| OLD | NEW |