Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2664603002: Remove replaceComposition() calls in finishComposingText. (Closed)
Patch Set: Clean up Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2688 matching lines...) Expand 10 before | Expand all | Expand 10 after
2699 event.x = 20; 2699 event.x = 20;
2700 event.y = 20; 2700 event.y = 20;
2701 2701
2702 // Just make sure we don't hit any asserts. 2702 // Just make sure we don't hit any asserts.
2703 webViewImpl->handleInputEvent(event); 2703 webViewImpl->handleInputEvent(event);
2704 } 2704 }
2705 2705
2706 class MockAutofillClient : public WebAutofillClient { 2706 class MockAutofillClient : public WebAutofillClient {
2707 public: 2707 public:
2708 MockAutofillClient() 2708 MockAutofillClient()
2709 : m_ignoreTextChanges(false), 2709 : m_textChanges(0),
2710 m_textChangesFromUserGesture(0), 2710 m_textChangesFromUserGesture(0),
2711 m_textChangesWhileIgnored(0),
2712 m_textChangesWhileNotIgnored(0),
2713 m_userGestureNotificationsCount(0) {} 2711 m_userGestureNotificationsCount(0) {}
2714 2712
2715 ~MockAutofillClient() override {} 2713 ~MockAutofillClient() override {}
2716 2714
2717 void setIgnoreTextChanges(bool ignore) override {
2718 m_ignoreTextChanges = ignore;
2719 }
2720 void textFieldDidChange(const WebFormControlElement&) override { 2715 void textFieldDidChange(const WebFormControlElement&) override {
2721 if (m_ignoreTextChanges) 2716 ++m_textChanges;
2722 ++m_textChangesWhileIgnored;
2723 else
2724 ++m_textChangesWhileNotIgnored;
2725 2717
2726 if (UserGestureIndicator::processingUserGesture()) 2718 if (UserGestureIndicator::processingUserGesture())
2727 ++m_textChangesFromUserGesture; 2719 ++m_textChangesFromUserGesture;
2728 } 2720 }
2729 void firstUserGestureObserved() override { 2721 void firstUserGestureObserved() override {
2730 ++m_userGestureNotificationsCount; 2722 ++m_userGestureNotificationsCount;
2731 } 2723 }
2732 2724
2733 void clearChangeCounts() { 2725 void clearChangeCounts() { m_textChanges = 0; }
2734 m_textChangesWhileIgnored = 0;
2735 m_textChangesWhileNotIgnored = 0;
2736 }
2737 2726
2727 int textChanges() { return m_textChanges; }
2738 int textChangesFromUserGesture() { return m_textChangesFromUserGesture; } 2728 int textChangesFromUserGesture() { return m_textChangesFromUserGesture; }
2739 int textChangesWhileIgnored() { return m_textChangesWhileIgnored; }
2740 int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; }
2741 int getUserGestureNotificationsCount() { 2729 int getUserGestureNotificationsCount() {
2742 return m_userGestureNotificationsCount; 2730 return m_userGestureNotificationsCount;
2743 } 2731 }
2744 2732
2745 private: 2733 private:
2746 bool m_ignoreTextChanges; 2734 int m_textChanges;
2747 int m_textChangesFromUserGesture; 2735 int m_textChangesFromUserGesture;
2748 int m_textChangesWhileIgnored;
2749 int m_textChangesWhileNotIgnored;
2750 int m_userGestureNotificationsCount; 2736 int m_userGestureNotificationsCount;
2751 }; 2737 };
2752 2738
2753 TEST_P(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) { 2739 TEST_P(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) {
2754 URLTestHelpers::registerMockedURLFromBaseURL( 2740 URLTestHelpers::registerMockedURLFromBaseURL(
2755 WebString::fromUTF8(m_baseURL.c_str()), 2741 WebString::fromUTF8(m_baseURL.c_str()),
2756 WebString::fromUTF8("input_field_populated.html")); 2742 WebString::fromUTF8("input_field_populated.html"));
2757 MockAutofillClient client; 2743 MockAutofillClient client;
2758 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 2744 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
2759 m_baseURL + "input_field_populated.html"); 2745 m_baseURL + "input_field_populated.html");
2760 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 2746 WebLocalFrameImpl* frame = webView->mainFrameImpl();
2761 frame->setAutofillClient(&client); 2747 frame->setAutofillClient(&client);
2762 webView->setInitialFocus(false); 2748 webView->setInitialFocus(false);
2763 2749
2764 // Set up a composition that needs to be committed. 2750 // Set up a composition that needs to be committed.
2765 WebVector<WebCompositionUnderline> emptyUnderlines; 2751 WebVector<WebCompositionUnderline> emptyUnderlines;
2766 frame->setEditableSelectionOffsets(4, 10); 2752 frame->setEditableSelectionOffsets(4, 10);
2767 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); 2753 frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
2768 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); 2754 WebTextInputInfo info = frame->inputMethodController()->textInputInfo();
2769 EXPECT_EQ(4, info.selectionStart); 2755 EXPECT_EQ(4, info.selectionStart);
2770 EXPECT_EQ(10, info.selectionEnd); 2756 EXPECT_EQ(10, info.selectionEnd);
2771 EXPECT_EQ(8, info.compositionStart); 2757 EXPECT_EQ(8, info.compositionStart);
2772 EXPECT_EQ(12, info.compositionEnd); 2758 EXPECT_EQ(12, info.compositionEnd);
2773 2759
2774 // Clear the focus and track that the subsequent composition commit does not 2760 // Clear the focus and track that the subsequent composition commit does not
2775 // trigger a text changed notification for autofill. 2761 // trigger a text changed notification for autofill.
2776 client.clearChangeCounts(); 2762 client.clearChangeCounts();
2777 webView->setFocus(false); 2763 webView->setFocus(false);
2778 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); 2764 EXPECT_EQ(0, client.textChanges());
2779 2765
2780 frame->setAutofillClient(0); 2766 frame->setAutofillClient(0);
2781 } 2767 }
2782 2768
2783 static void verifySelectionAndComposition(WebViewImpl* webView, 2769 static void verifySelectionAndComposition(WebViewImpl* webView,
2784 int selectionStart, 2770 int selectionStart,
2785 int selectionEnd, 2771 int selectionEnd,
2786 int compositionStart, 2772 int compositionStart,
2787 int compositionEnd, 2773 int compositionEnd,
2788 const char* failMessage) { 2774 const char* failMessage) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2835 2821
2836 keyEvent.setType(WebInputEvent::KeyUp); 2822 keyEvent.setType(WebInputEvent::KeyUp);
2837 webView->handleInputEvent(keyEvent); 2823 webView->handleInputEvent(keyEvent);
2838 2824
2839 webView->advanceFocus(false); 2825 webView->advanceFocus(false);
2840 } 2826 }
2841 2827
2842 frame->setAutofillClient(0); 2828 frame->setAutofillClient(0);
2843 } 2829 }
2844 2830
2845 TEST_P(WebViewTest, FinishComposingTextTriggersAutofillTextChange) { 2831 TEST_P(WebViewTest, FinishComposingTextDoesntTriggerAutofillTextChange) {
2846 URLTestHelpers::registerMockedURLFromBaseURL( 2832 URLTestHelpers::registerMockedURLFromBaseURL(
2847 WebString::fromUTF8(m_baseURL.c_str()), 2833 WebString::fromUTF8(m_baseURL.c_str()),
2848 WebString::fromUTF8("input_field_populated.html")); 2834 WebString::fromUTF8("input_field_populated.html"));
2849 MockAutofillClient client; 2835 MockAutofillClient client;
2850 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 2836 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
2851 m_baseURL + "input_field_populated.html"); 2837 m_baseURL + "input_field_populated.html");
2852 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 2838 WebLocalFrameImpl* frame = webView->mainFrameImpl();
2853 frame->setAutofillClient(&client); 2839 frame->setAutofillClient(&client);
2854 webView->setInitialFocus(false); 2840 webView->setInitialFocus(false);
2841
2842 WebDocument document = webView->mainFrame()->document();
2843 HTMLFormControlElement* form =
2844 toHTMLFormControlElement(document.getElementById("sample"));
2845
2855 WebInputMethodController* activeInputMethodController = 2846 WebInputMethodController* activeInputMethodController =
2856 frame->frameWidget()->getActiveWebInputMethodController(); 2847 frame->frameWidget()->getActiveWebInputMethodController();
2857 // Set up a composition that needs to be committed. 2848 // Set up a composition that needs to be committed.
2858 std::string compositionText("testingtext"); 2849 std::string compositionText("testingtext");
2859 2850
2860 WebVector<WebCompositionUnderline> emptyUnderlines; 2851 WebVector<WebCompositionUnderline> emptyUnderlines;
2861 activeInputMethodController->setComposition( 2852 activeInputMethodController->setComposition(
2862 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0, 2853 WebString::fromUTF8(compositionText.c_str()), emptyUnderlines, 0,
2863 compositionText.length()); 2854 compositionText.length());
2864 2855
2865 WebTextInputInfo info = activeInputMethodController->textInputInfo(); 2856 WebTextInputInfo info = activeInputMethodController->textInputInfo();
2866 EXPECT_EQ(0, info.selectionStart); 2857 EXPECT_EQ(0, info.selectionStart);
2867 EXPECT_EQ((int)compositionText.length(), info.selectionEnd); 2858 EXPECT_EQ((int)compositionText.length(), info.selectionEnd);
2868 EXPECT_EQ(0, info.compositionStart); 2859 EXPECT_EQ(0, info.compositionStart);
2869 EXPECT_EQ((int)compositionText.length(), info.compositionEnd); 2860 EXPECT_EQ((int)compositionText.length(), info.compositionEnd);
2870 2861
2862 form->setAutofilled(true);
2871 client.clearChangeCounts(); 2863 client.clearChangeCounts();
2864
2872 activeInputMethodController->finishComposingText( 2865 activeInputMethodController->finishComposingText(
2873 WebInputMethodController::KeepSelection); 2866 WebInputMethodController::KeepSelection);
2874 EXPECT_EQ(0, client.textChangesWhileIgnored()); 2867 EXPECT_EQ(0, client.textChanges());
2875 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); 2868
2869 EXPECT_TRUE(form->isAutofilled());
2876 2870
2877 frame->setAutofillClient(0); 2871 frame->setAutofillClient(0);
2878 } 2872 }
2879 2873
2880 TEST_P(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) { 2874 TEST_P(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) {
yabinh 2017/01/28 06:10:59 The name should be ...DoesntTrigger...?
aelias_OOO_until_Jul13 2017/01/28 06:38:49 Done.
2881 URLTestHelpers::registerMockedURLFromBaseURL( 2875 URLTestHelpers::registerMockedURLFromBaseURL(
2882 WebString::fromUTF8(m_baseURL.c_str()), 2876 WebString::fromUTF8(m_baseURL.c_str()),
2883 WebString::fromUTF8("input_field_populated.html")); 2877 WebString::fromUTF8("input_field_populated.html"));
2884 MockAutofillClient client; 2878 MockAutofillClient client;
2885 WebViewImpl* webView = m_webViewHelper.initializeAndLoad( 2879 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(
2886 m_baseURL + "input_field_populated.html", true); 2880 m_baseURL + "input_field_populated.html", true);
2887 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 2881 WebLocalFrameImpl* frame = webView->mainFrameImpl();
2888 frame->setAutofillClient(&client); 2882 frame->setAutofillClient(&client);
2889 webView->setInitialFocus(false); 2883 webView->setInitialFocus(false);
2890 2884
2891 WebVector<WebCompositionUnderline> emptyUnderlines; 2885 WebVector<WebCompositionUnderline> emptyUnderlines;
2892 2886
2893 client.clearChangeCounts(); 2887 client.clearChangeCounts();
2894 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); 2888 frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
2895 2889
2896 WebTextInputInfo info = frame->inputMethodController()->textInputInfo(); 2890 WebTextInputInfo info = frame->inputMethodController()->textInputInfo();
2897 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", 2891 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz",
2898 std::string(info.value.utf8().data())); 2892 std::string(info.value.utf8().data()));
2899 EXPECT_EQ(8, info.compositionStart); 2893 EXPECT_EQ(8, info.compositionStart);
2900 EXPECT_EQ(12, info.compositionEnd); 2894 EXPECT_EQ(12, info.compositionEnd);
2901 2895
2902 EXPECT_EQ(0, client.textChangesWhileIgnored()); 2896 EXPECT_EQ(0, client.textChanges());
2903 EXPECT_EQ(0, client.textChangesWhileNotIgnored());
2904 2897
2905 WebDocument document = webView->mainFrame()->document(); 2898 WebDocument document = webView->mainFrame()->document();
2906 EXPECT_EQ(WebString::fromUTF8("none"), 2899 EXPECT_EQ(WebString::fromUTF8("none"),
2907 document.getElementById("inputEvent").firstChild().nodeValue()); 2900 document.getElementById("inputEvent").firstChild().nodeValue());
2908 2901
2909 frame->setAutofillClient(0); 2902 frame->setAutofillClient(0);
2910 } 2903 }
2911 2904
2912 class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient { 2905 class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient {
2913 public: 2906 public:
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after
4375 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); 4368 EXPECT_EQ(expectedWidth, vwElement->offsetWidth());
4376 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); 4369 EXPECT_EQ(expectedHeight, vwElement->offsetHeight());
4377 4370
4378 webView->resize(WebSize(800, 600)); 4371 webView->resize(WebSize(800, 600));
4379 frame->printEnd(); 4372 frame->printEnd();
4380 4373
4381 EXPECT_EQ(800, vwElement->offsetWidth()); 4374 EXPECT_EQ(800, vwElement->offsetWidth());
4382 } 4375 }
4383 4376
4384 } // namespace blink 4377 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/public/web/WebAutofillClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698