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

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

Issue 5972008: views: Improve cursor movements on word boundaries. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add a test with leading whitespace. Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/keyboard_codes.h" 5 #include "app/keyboard_codes.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "views/controls/textfield/native_textfield_views.h" 9 #include "views/controls/textfield/native_textfield_views.h"
10 #include "views/controls/textfield/textfield.h" 10 #include "views/controls/textfield/textfield.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 TEST_F(NativeTextfieldViewsTest, TestOnKeyPressReturnValue) { 243 TEST_F(NativeTextfieldViewsTest, TestOnKeyPressReturnValue) {
244 InitTextfield(Textfield::STYLE_DEFAULT); 244 InitTextfield(Textfield::STYLE_DEFAULT);
245 EXPECT_TRUE(SendKeyEventToTextfieldViews(app::VKEY_A)); 245 EXPECT_TRUE(SendKeyEventToTextfieldViews(app::VKEY_A));
246 // F24, up/down key won't be handled. 246 // F24, up/down key won't be handled.
247 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_F24)); 247 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_F24));
248 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_UP)); 248 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_UP));
249 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_DOWN)); 249 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_DOWN));
250 } 250 }
251 251
252 TEST_F(NativeTextfieldViewsTest, CursorMovement) {
253 InitTextfield(Textfield::STYLE_DEFAULT);
254
255 // Test with trailing whitespace.
256 textfield_->SetText(ASCIIToUTF16("one two hre "));
257
258 // Send the cursor at the end.
259 SendKeyEventToTextfieldViews(app::VKEY_END);
260
261 // Ctrl+Left should move the cursor just before the last word.
262 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
263 SendKeyEventToTextfieldViews(app::VKEY_T);
264 EXPECT_STR_EQ("one two thre ", textfield_->text());
265 EXPECT_STR_EQ("one two thre ", last_contents_);
266
267 // Ctrl+Right should move the cursor to the end of the last word.
268 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true);
269 SendKeyEventToTextfieldViews(app::VKEY_E);
270 EXPECT_STR_EQ("one two three ", textfield_->text());
271 EXPECT_STR_EQ("one two three ", last_contents_);
272
273 // Ctrl+Right again should move the cursor to the end.
274 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true);
275 SendKeyEventToTextfieldViews(app::VKEY_BACK);
276 EXPECT_STR_EQ("one two three", textfield_->text());
277 EXPECT_STR_EQ("one two three", last_contents_);
278
279 // Test with leading whitespace.
280 textfield_->SetText(ASCIIToUTF16(" ne two"));
281
282 // Send the cursor at the beginning.
283 SendKeyEventToTextfieldViews(app::VKEY_HOME);
284
285 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the
286 // first word.
287 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true);
288 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
289 SendKeyEventToTextfieldViews(app::VKEY_O);
290 EXPECT_STR_EQ(" one two", textfield_->text());
291 EXPECT_STR_EQ(" one two", last_contents_);
292
293 // Ctrl+Left to move the cursor to the beginning of the first word.
294 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
295 // Ctrl+Left again should move the cursor back to the very beginning.
296 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true);
297 SendKeyEventToTextfieldViews(app::VKEY_DELETE);
298 EXPECT_STR_EQ("one two", textfield_->text());
299 EXPECT_STR_EQ("one two", last_contents_);
300 }
301
252 } // namespace views 302 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_views.cc ('k') | views/controls/textfield/textfield_views_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698