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

Side by Side Diff: Source/WebKit/chromium/tests/WebViewTest.cpp

Issue 12340032: Merge 142927 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1410/
Patch Set: Created 7 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
« no previous file with comments | « Source/WebKit/chromium/src/WebViewImpl.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "WebView.h" 32 #include "WebView.h"
33 33
34 #include "Document.h" 34 #include "Document.h"
35 #include "Element.h" 35 #include "Element.h"
36 #include "FrameTestHelpers.h" 36 #include "FrameTestHelpers.h"
37 #include "FrameView.h" 37 #include "FrameView.h"
38 #include "HTMLDocument.h" 38 #include "HTMLDocument.h"
39 #include "URLTestHelpers.h" 39 #include "URLTestHelpers.h"
40 #include "WebAutofillClient.h"
40 #include "WebContentDetectionResult.h" 41 #include "WebContentDetectionResult.h"
41 #include "WebDocument.h" 42 #include "WebDocument.h"
42 #include "WebElement.h" 43 #include "WebElement.h"
43 #include "WebFrame.h" 44 #include "WebFrame.h"
44 #include "WebFrameClient.h" 45 #include "WebFrameClient.h"
45 #include "WebFrameImpl.h" 46 #include "WebFrameImpl.h"
46 #include "WebInputEvent.h" 47 #include "WebInputEvent.h"
47 #include "WebViewClient.h" 48 #include "WebViewClient.h"
48 #include "WebViewImpl.h" 49 #include "WebViewImpl.h"
49 #include <gtest/gtest.h> 50 #include <gtest/gtest.h>
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 size_t length; 714 size_t length;
714 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(webView); 715 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(webView);
715 716
716 EXPECT_TRUE(webViewImpl->caretOrSelectionRange(&location, &length)); 717 EXPECT_TRUE(webViewImpl->caretOrSelectionRange(&location, &length));
717 EXPECT_EQ(location, 0UL); 718 EXPECT_EQ(location, 0UL);
718 EXPECT_EQ(length, testWord.length()); 719 EXPECT_EQ(length, testWord.length());
719 720
720 webView->close(); 721 webView->close();
721 } 722 }
722 723
724 class MockAutofillClient : public WebAutofillClient {
725 public:
726 MockAutofillClient()
727 : m_ignoreTextChanges(false)
728 , m_textChangesWhileIgnored(0)
729 , m_textChangesWhileNotIgnored(0) { }
730
731 virtual ~MockAutofillClient() { }
732
733 virtual void setIgnoreTextChanges(bool ignore) OVERRIDE { m_ignoreTextChange s = ignore; }
734 virtual void textFieldDidChange(const WebInputElement&) OVERRIDE
735 {
736 if (m_ignoreTextChanges)
737 ++m_textChangesWhileIgnored;
738 else
739 ++m_textChangesWhileNotIgnored;
740 }
741
742 void clearChangeCounts()
743 {
744 m_textChangesWhileIgnored = 0;
745 m_textChangesWhileNotIgnored = 0;
746 }
747
748 int textChangesWhileIgnored() { return m_textChangesWhileIgnored; }
749 int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; }
750
751 private:
752 bool m_ignoreTextChanges;
753 int m_textChangesWhileIgnored;
754 int m_textChangesWhileNotIgnored;
755 };
756
757
758 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
759 {
760 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
761 MockAutofillClient client;
762 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input _field_populated.html");
763 webView->setAutofillClient(&client);
764 webView->setInitialFocus(false);
765
766 // Set up a composition that needs to be committed.
767 WebVector<WebCompositionUnderline> emptyUnderlines;
768 webView->setEditableSelectionOffsets(4, 10);
769 webView->setCompositionFromExistingText(8, 12, emptyUnderlines);
770 WebTextInputInfo info = webView->textInputInfo();
771 EXPECT_EQ(4, info.selectionStart);
772 EXPECT_EQ(10, info.selectionEnd);
773 EXPECT_EQ(8, info.compositionStart);
774 EXPECT_EQ(12, info.compositionEnd);
775
776 // Clear the focus and track that the subsequent composition commit does not trigger a
777 // text changed notification for autofill.
778 client.clearChangeCounts();
779 webView->setFocus(false);
780 EXPECT_EQ(1, client.textChangesWhileIgnored());
781 EXPECT_EQ(0, client.textChangesWhileNotIgnored());
782
783 webView->setAutofillClient(0);
784 webView->close();
785 }
786
787 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
788 {
789 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
790 MockAutofillClient client;
791 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input _field_populated.html");
792 webView->setAutofillClient(&client);
793 webView->setInitialFocus(false);
794
795 // Set up a composition that needs to be committed.
796 std::string compositionText("testingtext");
797
798 WebVector<WebCompositionUnderline> emptyUnderlines;
799 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU nderlines, 0, compositionText.length());
800
801 WebTextInputInfo info = webView->textInputInfo();
802 EXPECT_EQ(0, info.selectionStart);
803 EXPECT_EQ((int) compositionText.length(), info.selectionEnd);
804 EXPECT_EQ(0, info.compositionStart);
805 EXPECT_EQ((int) compositionText.length(), info.compositionEnd);
806
807 client.clearChangeCounts();
808 webView->confirmComposition();
809 EXPECT_EQ(0, client.textChangesWhileIgnored());
810 EXPECT_EQ(1, client.textChangesWhileNotIgnored());
811
812 webView->setAutofillClient(0);
813 webView->close();
814 }
815
723 } 816 }
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/WebViewImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698