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

Side by Side Diff: ui/views/controls/textfield/native_textfield_views_unittest.cc

Issue 14827004: cros: Arrow key traversal in views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <set>
5 #include <string> 6 #include <string>
6 #include <vector> 7 #include <vector>
7 8
8 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/message_loop.h" 14 #include "base/message_loop.h"
14 #include "base/pickle.h" 15 #include "base/pickle.h"
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 textfield_->clear(); 671 textfield_->clear();
671 672
672 SendKeyEvent(ui::VKEY_UP); 673 SendKeyEvent(ui::VKEY_UP);
673 EXPECT_TRUE(textfield_->key_received()); 674 EXPECT_TRUE(textfield_->key_received());
674 EXPECT_FALSE(textfield_->key_handled()); 675 EXPECT_FALSE(textfield_->key_handled());
675 textfield_->clear(); 676 textfield_->clear();
676 677
677 SendKeyEvent(ui::VKEY_DOWN); 678 SendKeyEvent(ui::VKEY_DOWN);
678 EXPECT_TRUE(textfield_->key_received()); 679 EXPECT_TRUE(textfield_->key_received());
679 EXPECT_FALSE(textfield_->key_handled()); 680 EXPECT_FALSE(textfield_->key_handled());
681 textfield_->clear();
682
683 // Empty Textfield does not handle left/right.
684 textfield_->SetText(string16());
685 SendKeyEvent(ui::VKEY_LEFT);
686 EXPECT_TRUE(textfield_->key_received());
687 EXPECT_FALSE(textfield_->key_handled());
688 textfield_->clear();
689
690 SendKeyEvent(ui::VKEY_RIGHT);
691 EXPECT_TRUE(textfield_->key_received());
692 EXPECT_FALSE(textfield_->key_handled());
693 textfield_->clear();
694
695 // Add a char. Right key should not be handled when cursor is at the end.
696 SendKeyEvent(ui::VKEY_B);
697 SendKeyEvent(ui::VKEY_RIGHT);
698 EXPECT_TRUE(textfield_->key_received());
699 EXPECT_FALSE(textfield_->key_handled());
700 textfield_->clear();
701
702 // First left key is handled to move cursor left to the beginning.
703 SendKeyEvent(ui::VKEY_LEFT);
704 EXPECT_TRUE(textfield_->key_received());
705 EXPECT_TRUE(textfield_->key_handled());
706 textfield_->clear();
707
708 // Now left key should not be handled.
709 SendKeyEvent(ui::VKEY_LEFT);
710 EXPECT_TRUE(textfield_->key_received());
711 EXPECT_FALSE(textfield_->key_handled());
712 textfield_->clear();
680 } 713 }
681 714
682 TEST_F(NativeTextfieldViewsTest, CursorMovement) { 715 TEST_F(NativeTextfieldViewsTest, CursorMovement) {
683 InitTextfield(Textfield::STYLE_DEFAULT); 716 InitTextfield(Textfield::STYLE_DEFAULT);
684 717
685 // Test with trailing whitespace. 718 // Test with trailing whitespace.
686 textfield_->SetText(ASCIIToUTF16("one two hre ")); 719 textfield_->SetText(ASCIIToUTF16("one two hre "));
687 720
688 // Send the cursor at the end. 721 // Send the cursor at the end.
689 SendKeyEvent(ui::VKEY_END); 722 SendKeyEvent(ui::VKEY_END);
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); 1207 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType());
1175 1208
1176 textfield_->SetText(ASCIIToUTF16("0123456789")); 1209 textfield_->SetText(ASCIIToUTF16("0123456789"));
1177 ui::Range range; 1210 ui::Range range;
1178 EXPECT_TRUE(client->GetTextRange(&range)); 1211 EXPECT_TRUE(client->GetTextRange(&range));
1179 EXPECT_EQ(0U, range.start()); 1212 EXPECT_EQ(0U, range.start());
1180 EXPECT_EQ(10U, range.end()); 1213 EXPECT_EQ(10U, range.end());
1181 1214
1182 EXPECT_TRUE(client->SetSelectionRange(ui::Range(1, 4))); 1215 EXPECT_TRUE(client->SetSelectionRange(ui::Range(1, 4)));
1183 EXPECT_TRUE(client->GetSelectionRange(&range)); 1216 EXPECT_TRUE(client->GetSelectionRange(&range));
1184 EXPECT_EQ(ui::Range(1,4), range); 1217 EXPECT_EQ(ui::Range(1, 4), range);
1185 1218
1186 // This code can't be compiled because of a bug in base::Callback. 1219 // This code can't be compiled because of a bug in base::Callback.
1187 #if 0 1220 #if 0
1188 GetTextHelper helper; 1221 GetTextHelper helper;
1189 base::Callback<void(string16)> callback = 1222 base::Callback<void(string16)> callback =
1190 base::Bind(&GetTextHelper::set_text, base::Unretained(&helper)); 1223 base::Bind(&GetTextHelper::set_text, base::Unretained(&helper));
1191 1224
1192 EXPECT_TRUE(client->GetTextFromRange(range, callback)); 1225 EXPECT_TRUE(client->GetTextFromRange(range, callback));
1193 EXPECT_STR_EQ("123", helper.text()); 1226 EXPECT_STR_EQ("123", helper.text());
1194 #endif 1227 #endif
1195 1228
1196 EXPECT_TRUE(client->DeleteRange(range)); 1229 EXPECT_TRUE(client->DeleteRange(range));
1197 EXPECT_STR_EQ("0456789", textfield_->text()); 1230 EXPECT_STR_EQ("0456789", textfield_->text());
1198 1231
1199 ui::CompositionText composition; 1232 ui::CompositionText composition;
1200 composition.text = UTF8ToUTF16("321"); 1233 composition.text = UTF8ToUTF16("321");
1201 // Set composition through input method. 1234 // Set composition through input method.
1202 input_method_->Clear(); 1235 input_method_->Clear();
1203 input_method_->SetCompositionTextForNextKey(composition); 1236 input_method_->SetCompositionTextForNextKey(composition);
1204 textfield_->clear(); 1237 textfield_->clear();
1205 1238
1206 on_before_user_action_ = on_after_user_action_ = 0; 1239 on_before_user_action_ = on_after_user_action_ = 0;
1207 SendKeyEvent(ui::VKEY_A); 1240 SendKeyEvent(ui::VKEY_A);
1208 EXPECT_TRUE(textfield_->key_received()); 1241 EXPECT_TRUE(textfield_->key_received());
1209 EXPECT_FALSE(textfield_->key_handled()); 1242 EXPECT_FALSE(textfield_->key_handled());
1210 EXPECT_TRUE(client->HasCompositionText()); 1243 EXPECT_TRUE(client->HasCompositionText());
1211 EXPECT_TRUE(client->GetCompositionTextRange(&range)); 1244 EXPECT_TRUE(client->GetCompositionTextRange(&range));
1212 EXPECT_STR_EQ("0321456789", textfield_->text()); 1245 EXPECT_STR_EQ("0321456789", textfield_->text());
1213 EXPECT_EQ(ui::Range(1,4), range); 1246 EXPECT_EQ(ui::Range(1, 4), range);
1214 EXPECT_EQ(2, on_before_user_action_); 1247 EXPECT_EQ(2, on_before_user_action_);
1215 EXPECT_EQ(2, on_after_user_action_); 1248 EXPECT_EQ(2, on_after_user_action_);
1216 1249
1217 input_method_->SetResultTextForNextKey(UTF8ToUTF16("123")); 1250 input_method_->SetResultTextForNextKey(UTF8ToUTF16("123"));
1218 on_before_user_action_ = on_after_user_action_ = 0; 1251 on_before_user_action_ = on_after_user_action_ = 0;
1219 textfield_->clear(); 1252 textfield_->clear();
1220 SendKeyEvent(ui::VKEY_A); 1253 SendKeyEvent(ui::VKEY_A);
1221 EXPECT_TRUE(textfield_->key_received()); 1254 EXPECT_TRUE(textfield_->key_received());
1222 EXPECT_FALSE(textfield_->key_handled()); 1255 EXPECT_FALSE(textfield_->key_handled());
1223 EXPECT_FALSE(client->HasCompositionText()); 1256 EXPECT_FALSE(client->HasCompositionText());
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 textfield_view_->OnGestureEvent(&tap_down); 1836 textfield_view_->OnGestureEvent(&tap_down);
1804 // Create a new long press event since the previous one is not marked handled. 1837 // Create a new long press event since the previous one is not marked handled.
1805 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0); 1838 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0);
1806 textfield_view_->OnGestureEvent(&long_press2); 1839 textfield_view_->OnGestureEvent(&long_press2);
1807 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1840 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1808 EXPECT_FALSE(GetTouchSelectionController()); 1841 EXPECT_FALSE(GetTouchSelectionController());
1809 } 1842 }
1810 #endif 1843 #endif
1811 1844
1812 } // namespace views 1845 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698