| OLD | NEW |
| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // Delete using delete key and check resulting string. | 243 // Delete using delete key and check resulting string. |
| 244 for (int i = 0; i < 5; i++) { | 244 for (int i = 0; i < 5; i++) { |
| 245 SendKeyEventToTextfieldViews(app::VKEY_DELETE); | 245 SendKeyEventToTextfieldViews(app::VKEY_DELETE); |
| 246 } | 246 } |
| 247 EXPECT_STR_EQ("this is ", textfield_->text()); | 247 EXPECT_STR_EQ("this is ", textfield_->text()); |
| 248 | 248 |
| 249 // Select all and replace with "k". | 249 // Select all and replace with "k". |
| 250 textfield_->SelectAll(); | 250 textfield_->SelectAll(); |
| 251 SendKeyEventToTextfieldViews(app::VKEY_K); | 251 SendKeyEventToTextfieldViews(app::VKEY_K); |
| 252 EXPECT_STR_EQ("k", textfield_->text()); | 252 EXPECT_STR_EQ("k", textfield_->text()); |
| 253 |
| 254 // Delete the previous word from cursor. |
| 255 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 256 SendKeyEventToTextfieldViews(app::VKEY_END); |
| 257 SendKeyEventToTextfieldViews(app::VKEY_BACK, false, true, false); |
| 258 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 259 |
| 260 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing |
| 261 // in windows. |
| 262 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true, false); |
| 263 SendKeyEventToTextfieldViews(app::VKEY_BACK, true, true, false); |
| 264 #if defined(OS_WIN) |
| 265 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 266 #else |
| 267 EXPECT_STR_EQ("three ", textfield_->text()); |
| 268 #endif |
| 269 |
| 270 // Delete the next word from cursor. |
| 271 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 272 SendKeyEventToTextfieldViews(app::VKEY_HOME); |
| 273 SendKeyEventToTextfieldViews(app::VKEY_DELETE, false, true, false); |
| 274 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 275 |
| 276 // Delete upto the end of the buffer from cursor in chromeos, do nothing |
| 277 // in windows. |
| 278 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true, false); |
| 279 SendKeyEventToTextfieldViews(app::VKEY_DELETE, true, true, false); |
| 280 #if defined(OS_WIN) |
| 281 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 282 #else |
| 283 EXPECT_STR_EQ(" two", textfield_->text()); |
| 284 #endif |
| 253 } | 285 } |
| 254 | 286 |
| 255 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 287 TEST_F(NativeTextfieldViewsTest, PasswordTest) { |
| 256 InitTextfield(Textfield::STYLE_PASSWORD); | 288 InitTextfield(Textfield::STYLE_PASSWORD); |
| 257 textfield_->SetText(ASCIIToUTF16("my password")); | 289 textfield_->SetText(ASCIIToUTF16("my password")); |
| 258 // Just to make sure the text() and callback returns | 290 // Just to make sure the text() and callback returns |
| 259 // the actual text instead of "*". | 291 // the actual text instead of "*". |
| 260 EXPECT_STR_EQ("my password", textfield_->text()); | 292 EXPECT_STR_EQ("my password", textfield_->text()); |
| 261 EXPECT_STR_EQ("my password", last_contents_); | 293 EXPECT_STR_EQ("my password", last_contents_); |
| 262 } | 294 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // Cycle back to the last textfield. | 374 // Cycle back to the last textfield. |
| 343 widget_->GetFocusManager()->AdvanceFocus(true); | 375 widget_->GetFocusManager()->AdvanceFocus(true); |
| 344 EXPECT_EQ(3, GetFocusedView()->GetID()); | 376 EXPECT_EQ(3, GetFocusedView()->GetID()); |
| 345 | 377 |
| 346 // Request focus should still work. | 378 // Request focus should still work. |
| 347 textfield_->RequestFocus(); | 379 textfield_->RequestFocus(); |
| 348 EXPECT_EQ(1, GetFocusedView()->GetID()); | 380 EXPECT_EQ(1, GetFocusedView()->GetID()); |
| 349 } | 381 } |
| 350 | 382 |
| 351 } // namespace views | 383 } // namespace views |
| OLD | NEW |