summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-08 01:41:15 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-08 01:41:15 +0000
commit021b078a5f0c1592d26811f31cba302cc51ea930 (patch)
tree9e146982a42e6b0d2aff135d9cd15234cf1b29e8 /ui
parent91ebba302ee61d609df3ea775f3d02ad6dc4825a (diff)
downloadchromium_src-021b078a5f0c1592d26811f31cba302cc51ea930.zip
chromium_src-021b078a5f0c1592d26811f31cba302cc51ea930.tar.gz
chromium_src-021b078a5f0c1592d26811f31cba302cc51ea930.tar.bz2
Don't merge replace edit if previous edit is delete edit.
Enable UndoRedo_CutCopyPasteTest BUG=103988,97845 TEST=added new UndoRedo_BackspaceThenSetText, enabled CutCopyPasteTest Review URL: http://codereview.chromium.org/8823007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113525 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/views/controls/textfield/textfield_views_model.cc12
-rw-r--r--ui/views/controls/textfield/textfield_views_model_unittest.cc33
2 files changed, 33 insertions, 12 deletions
diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc
index 5c50986..77485c6 100644
--- a/ui/views/controls/textfield/textfield_views_model.cc
+++ b/ui/views/controls/textfield/textfield_views_model.cc
@@ -58,8 +58,12 @@ class Edit {
// successful, or false otherwise. Merged edit will be deleted after
// redo and should not be reused.
bool Merge(const Edit* edit) {
- if (edit->merge_with_previous()) {
- MergeSet(edit);
+ // Don't merge if previous edit is DELETE. This happens when a
+ // user deletes characters then hits return. In this case, the
+ // delete should be treated as separate edit that can be undone
+ // and should not be merged with the replace edit.
+ if (type_ != DELETE_EDIT && edit->merge_with_previous()) {
+ MergeReplace(edit);
return true;
}
return mergeable() && edit->mergeable() && DoMerge(edit);
@@ -113,10 +117,10 @@ class Edit {
// Returns the end index of the |new_text_|.
size_t new_text_end() const { return new_text_start_ + new_text_.length(); }
- // Merge the Set edit into the current edit. This is a special case to
+ // Merge the replace edit into the current edit. This is a special case to
// handle an omnibox setting autocomplete string after new character is
// typed in.
- void MergeSet(const Edit* edit) {
+ void MergeReplace(const Edit* edit) {
CHECK_EQ(REPLACE_EDIT, edit->type_);
CHECK_EQ(0U, edit->old_text_start_);
CHECK_EQ(0U, edit->new_text_start_);
diff --git a/ui/views/controls/textfield/textfield_views_model_unittest.cc b/ui/views/controls/textfield/textfield_views_model_unittest.cc
index 585d849..31f6563 100644
--- a/ui/views/controls/textfield/textfield_views_model_unittest.cc
+++ b/ui/views/controls/textfield/textfield_views_model_unittest.cc
@@ -1179,14 +1179,31 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) {
EXPECT_FALSE(model.Redo());
}
-#if defined(USE_AURA) && defined(OS_LINUX)
-// This can be re-enabled when aura on linux has clipboard support.
-// http://crbug.com/97845
-#define MAYBE_UndoRedo_CutCopyPasteTest DISABLED_UndoRedo_CutCopyPasteTest
-#else
-#define MAYBE_UndoRedo_CutCopyPasteTest UndoRedo_CutCopyPasteTest
-#endif
-TEST_F(TextfieldViewsModelTest, MAYBE_UndoRedo_CutCopyPasteTest) {
+TEST_F(TextfieldViewsModelTest, UndoRedo_BackspaceThenSetText) {
+ // This is to test the undo/redo behavior of omnibox.
+ TextfieldViewsModel model(NULL);
+ model.InsertChar('w');
+ EXPECT_STR_EQ("w", model.GetText());
+ EXPECT_EQ(1U, model.GetCursorPosition());
+ model.SetText(ASCIIToUTF16("www.google.com"));
+ EXPECT_EQ(1U, model.GetCursorPosition());
+ EXPECT_STR_EQ("www.google.com", model.GetText());
+ model.SetText(ASCIIToUTF16("www.google.com")); // Confirm the text.
+ model.MoveCursorRight(gfx::LINE_BREAK, false);
+ EXPECT_EQ(14U, model.GetCursorPosition());
+ EXPECT_TRUE(model.Backspace());
+ EXPECT_TRUE(model.Backspace());
+ EXPECT_STR_EQ("www.google.c", model.GetText());
+ // Autocomplete sets the text
+ model.SetText(ASCIIToUTF16("www.google.com/search=www.google.c"));
+ EXPECT_STR_EQ("www.google.com/search=www.google.c", model.GetText());
+ EXPECT_TRUE(model.Undo());
+ EXPECT_STR_EQ("www.google.c", model.GetText());
+ EXPECT_TRUE(model.Undo());
+ EXPECT_STR_EQ("www.google.com", model.GetText());
+}
+
+TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) {
TextfieldViewsModel model(NULL);
model.SetText(ASCIIToUTF16("ABCDE"));
EXPECT_FALSE(model.Redo()); // nothing to redo