| 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" | |
| 6 #include "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "ui/base/keycodes/keyboard_codes.h" |
| 7 #include "views/controls/textfield/native_textfield_views.h" | 7 #include "views/controls/textfield/native_textfield_views.h" |
| 8 #include "views/controls/textfield/textfield.h" | 8 #include "views/controls/textfield/textfield.h" |
| 9 #include "views/controls/textfield/textfield_views_model.h" | 9 #include "views/controls/textfield/textfield_views_model.h" |
| 10 #include "views/event.h" | 10 #include "views/event.h" |
| 11 #include "views/focus/focus_manager.h" | 11 #include "views/focus/focus_manager.h" |
| 12 #include "views/test/views_test_base.h" | 12 #include "views/test/views_test_base.h" |
| 13 #include "views/widget/widget.h" | 13 #include "views/widget/widget.h" |
| 14 | 14 |
| 15 namespace views { | 15 namespace views { |
| 16 | 16 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 Textfield* textfield = new Textfield(style); | 81 Textfield* textfield = new Textfield(style); |
| 82 container->AddChildView(textfield); | 82 container->AddChildView(textfield); |
| 83 textfield->SetID(i + 1); | 83 textfield->SetID(i + 1); |
| 84 } | 84 } |
| 85 | 85 |
| 86 DCHECK(textfield_view_); | 86 DCHECK(textfield_view_); |
| 87 model_ = textfield_view_->model_.get(); | 87 model_ = textfield_view_->model_.get(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 protected: | 90 protected: |
| 91 bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code, | 91 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, |
| 92 bool shift, | 92 bool shift, |
| 93 bool control, | 93 bool control, |
| 94 bool capslock) { | 94 bool capslock) { |
| 95 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | | 95 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | |
| 96 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | | 96 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | |
| 97 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); | 97 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); |
| 98 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); | 98 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); |
| 99 return textfield_->OnKeyPressed(event); | 99 return textfield_->OnKeyPressed(event); |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code, | 102 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, |
| 103 bool shift, | 103 bool shift, |
| 104 bool control) { | 104 bool control) { |
| 105 return SendKeyEventToTextfieldViews(key_code, shift, control, false); | 105 return SendKeyEventToTextfieldViews(key_code, shift, control, false); |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code) { | 108 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code) { |
| 109 return SendKeyEventToTextfieldViews(key_code, false, false); | 109 return SendKeyEventToTextfieldViews(key_code, false, false); |
| 110 } | 110 } |
| 111 | 111 |
| 112 View* GetFocusedView() { | 112 View* GetFocusedView() { |
| 113 return widget_->GetFocusManager()->GetFocusedView(); | 113 return widget_->GetFocusManager()->GetFocusedView(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 // We need widget to populate wrapper class. | 116 // We need widget to populate wrapper class. |
| 117 Widget* widget_; | 117 Widget* widget_; |
| 118 | 118 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 EXPECT_EQ(string16(), last_contents_); | 150 EXPECT_EQ(string16(), last_contents_); |
| 151 | 151 |
| 152 EXPECT_EQ(string16(), textfield_->GetSelectedText()); | 152 EXPECT_EQ(string16(), textfield_->GetSelectedText()); |
| 153 textfield_->SelectAll(); | 153 textfield_->SelectAll(); |
| 154 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 154 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
| 155 EXPECT_EQ(string16(), last_contents_); | 155 EXPECT_EQ(string16(), last_contents_); |
| 156 } | 156 } |
| 157 | 157 |
| 158 TEST_F(NativeTextfieldViewsTest, KeyTest) { | 158 TEST_F(NativeTextfieldViewsTest, KeyTest) { |
| 159 InitTextfield(Textfield::STYLE_DEFAULT); | 159 InitTextfield(Textfield::STYLE_DEFAULT); |
| 160 SendKeyEventToTextfieldViews(app::VKEY_C, true, false); | 160 SendKeyEventToTextfieldViews(ui::VKEY_C, true, false); |
| 161 EXPECT_STR_EQ("C", textfield_->text()); | 161 EXPECT_STR_EQ("C", textfield_->text()); |
| 162 EXPECT_STR_EQ("C", last_contents_); | 162 EXPECT_STR_EQ("C", last_contents_); |
| 163 last_contents_.clear(); | 163 last_contents_.clear(); |
| 164 | 164 |
| 165 SendKeyEventToTextfieldViews(app::VKEY_R, false, false); | 165 SendKeyEventToTextfieldViews(ui::VKEY_R, false, false); |
| 166 EXPECT_STR_EQ("Cr", textfield_->text()); | 166 EXPECT_STR_EQ("Cr", textfield_->text()); |
| 167 EXPECT_STR_EQ("Cr", last_contents_); | 167 EXPECT_STR_EQ("Cr", last_contents_); |
| 168 | 168 |
| 169 textfield_->SetText(ASCIIToUTF16("")); | 169 textfield_->SetText(ASCIIToUTF16("")); |
| 170 SendKeyEventToTextfieldViews(app::VKEY_C, true, false, true); | 170 SendKeyEventToTextfieldViews(ui::VKEY_C, true, false, true); |
| 171 SendKeyEventToTextfieldViews(app::VKEY_C, false, false, true); | 171 SendKeyEventToTextfieldViews(ui::VKEY_C, false, false, true); |
| 172 SendKeyEventToTextfieldViews(app::VKEY_1, false, false, true); | 172 SendKeyEventToTextfieldViews(ui::VKEY_1, false, false, true); |
| 173 SendKeyEventToTextfieldViews(app::VKEY_1, true, false, true); | 173 SendKeyEventToTextfieldViews(ui::VKEY_1, true, false, true); |
| 174 SendKeyEventToTextfieldViews(app::VKEY_1, true, false, false); | 174 SendKeyEventToTextfieldViews(ui::VKEY_1, true, false, false); |
| 175 EXPECT_STR_EQ("cC1!!", textfield_->text()); | 175 EXPECT_STR_EQ("cC1!!", textfield_->text()); |
| 176 EXPECT_STR_EQ("cC1!!", last_contents_); | 176 EXPECT_STR_EQ("cC1!!", last_contents_); |
| 177 } | 177 } |
| 178 | 178 |
| 179 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { | 179 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { |
| 180 // Insert a test string in a textfield. | 180 // Insert a test string in a textfield. |
| 181 InitTextfield(Textfield::STYLE_DEFAULT); | 181 InitTextfield(Textfield::STYLE_DEFAULT); |
| 182 textfield_->SetText(ASCIIToUTF16("one two three")); | 182 textfield_->SetText(ASCIIToUTF16("one two three")); |
| 183 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, | 183 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, |
| 184 true /* shift */, false /* control */); | 184 true /* shift */, false /* control */); |
| 185 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, false); | 185 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, false); |
| 186 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, false); | 186 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, false); |
| 187 | 187 |
| 188 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 188 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
| 189 | 189 |
| 190 // Test word select. | 190 // Test word select. |
| 191 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, true); | 191 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, true); |
| 192 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); | 192 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); |
| 193 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, true, true); | 193 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, true); |
| 194 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); | 194 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); |
| 195 SendKeyEventToTextfieldViews(app::VKEY_LEFT, true, true); | 195 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, true, true); |
| 196 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); | 196 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); |
| 197 SendKeyEventToTextfieldViews(app::VKEY_LEFT, true, true); | 197 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, true, true); |
| 198 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); | 198 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); |
| 199 | 199 |
| 200 // Replace the selected text. | 200 // Replace the selected text. |
| 201 SendKeyEventToTextfieldViews(app::VKEY_Z, true, false); | 201 SendKeyEventToTextfieldViews(ui::VKEY_Z, true, false); |
| 202 SendKeyEventToTextfieldViews(app::VKEY_E, true, false); | 202 SendKeyEventToTextfieldViews(ui::VKEY_E, true, false); |
| 203 SendKeyEventToTextfieldViews(app::VKEY_R, true, false); | 203 SendKeyEventToTextfieldViews(ui::VKEY_R, true, false); |
| 204 SendKeyEventToTextfieldViews(app::VKEY_O, true, false); | 204 SendKeyEventToTextfieldViews(ui::VKEY_O, true, false); |
| 205 SendKeyEventToTextfieldViews(app::VKEY_SPACE, false, false); | 205 SendKeyEventToTextfieldViews(ui::VKEY_SPACE, false, false); |
| 206 EXPECT_STR_EQ("ZERO two three", textfield_->text()); | 206 EXPECT_STR_EQ("ZERO two three", textfield_->text()); |
| 207 | 207 |
| 208 SendKeyEventToTextfieldViews(app::VKEY_END, true, false); | 208 SendKeyEventToTextfieldViews(ui::VKEY_END, true, false); |
| 209 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); | 209 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); |
| 210 SendKeyEventToTextfieldViews(app::VKEY_HOME, true, false); | 210 SendKeyEventToTextfieldViews(ui::VKEY_HOME, true, false); |
| 211 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); | 211 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); |
| 212 } | 212 } |
| 213 | 213 |
| 214 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { | 214 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { |
| 215 // Insert a test string in a textfield. | 215 // Insert a test string in a textfield. |
| 216 InitTextfield(Textfield::STYLE_DEFAULT); | 216 InitTextfield(Textfield::STYLE_DEFAULT); |
| 217 char test_str[] = "this is a test"; | 217 char test_str[] = "this is a test"; |
| 218 for (size_t i = 0; i < sizeof(test_str); i++) { | 218 for (size_t i = 0; i < sizeof(test_str); i++) { |
| 219 // This is ugly and should be replaced by a utility standard function. | 219 // This is ugly and should be replaced by a utility standard function. |
| 220 // See comment in NativeTextfieldViews::GetPrintableChar. | 220 // See comment in NativeTextfieldViews::GetPrintableChar. |
| 221 char c = test_str[i]; | 221 char c = test_str[i]; |
| 222 app::KeyboardCode code = | 222 ui::KeyboardCode code = |
| 223 c == ' ' ? app::VKEY_SPACE : | 223 c == ' ' ? ui::VKEY_SPACE : |
| 224 static_cast<app::KeyboardCode>(app::VKEY_A + c - 'a'); | 224 static_cast<ui::KeyboardCode>(ui::VKEY_A + c - 'a'); |
| 225 SendKeyEventToTextfieldViews(code); | 225 SendKeyEventToTextfieldViews(code); |
| 226 } | 226 } |
| 227 EXPECT_STR_EQ(test_str, textfield_->text()); | 227 EXPECT_STR_EQ(test_str, textfield_->text()); |
| 228 | 228 |
| 229 // Move the cursor around. | 229 // Move the cursor around. |
| 230 for (int i = 0; i < 6; i++) { | 230 for (int i = 0; i < 6; i++) { |
| 231 SendKeyEventToTextfieldViews(app::VKEY_LEFT); | 231 SendKeyEventToTextfieldViews(ui::VKEY_LEFT); |
| 232 } | 232 } |
| 233 SendKeyEventToTextfieldViews(app::VKEY_RIGHT); | 233 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT); |
| 234 | 234 |
| 235 // Delete using backspace and check resulting string. | 235 // Delete using backspace and check resulting string. |
| 236 SendKeyEventToTextfieldViews(app::VKEY_BACK); | 236 SendKeyEventToTextfieldViews(ui::VKEY_BACK); |
| 237 EXPECT_STR_EQ("this is test", textfield_->text()); | 237 EXPECT_STR_EQ("this is test", textfield_->text()); |
| 238 | 238 |
| 239 // Delete using delete key and check resulting string. | 239 // Delete using delete key and check resulting string. |
| 240 for (int i = 0; i < 5; i++) { | 240 for (int i = 0; i < 5; i++) { |
| 241 SendKeyEventToTextfieldViews(app::VKEY_DELETE); | 241 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); |
| 242 } | 242 } |
| 243 EXPECT_STR_EQ("this is ", textfield_->text()); | 243 EXPECT_STR_EQ("this is ", textfield_->text()); |
| 244 | 244 |
| 245 // Select all and replace with "k". | 245 // Select all and replace with "k". |
| 246 textfield_->SelectAll(); | 246 textfield_->SelectAll(); |
| 247 SendKeyEventToTextfieldViews(app::VKEY_K); | 247 SendKeyEventToTextfieldViews(ui::VKEY_K); |
| 248 EXPECT_STR_EQ("k", textfield_->text()); | 248 EXPECT_STR_EQ("k", textfield_->text()); |
| 249 | 249 |
| 250 // Delete the previous word from cursor. | 250 // Delete the previous word from cursor. |
| 251 textfield_->SetText(ASCIIToUTF16("one two three four")); | 251 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 252 SendKeyEventToTextfieldViews(app::VKEY_END); | 252 SendKeyEventToTextfieldViews(ui::VKEY_END); |
| 253 SendKeyEventToTextfieldViews(app::VKEY_BACK, false, true, false); | 253 SendKeyEventToTextfieldViews(ui::VKEY_BACK, false, true, false); |
| 254 EXPECT_STR_EQ("one two three ", textfield_->text()); | 254 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 255 | 255 |
| 256 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing | 256 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing |
| 257 // in windows. | 257 // in windows. |
| 258 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true, false); | 258 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true, false); |
| 259 SendKeyEventToTextfieldViews(app::VKEY_BACK, true, true, false); | 259 SendKeyEventToTextfieldViews(ui::VKEY_BACK, true, true, false); |
| 260 #if defined(OS_WIN) | 260 #if defined(OS_WIN) |
| 261 EXPECT_STR_EQ("one two three ", textfield_->text()); | 261 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 262 #else | 262 #else |
| 263 EXPECT_STR_EQ("three ", textfield_->text()); | 263 EXPECT_STR_EQ("three ", textfield_->text()); |
| 264 #endif | 264 #endif |
| 265 | 265 |
| 266 // Delete the next word from cursor. | 266 // Delete the next word from cursor. |
| 267 textfield_->SetText(ASCIIToUTF16("one two three four")); | 267 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 268 SendKeyEventToTextfieldViews(app::VKEY_HOME); | 268 SendKeyEventToTextfieldViews(ui::VKEY_HOME); |
| 269 SendKeyEventToTextfieldViews(app::VKEY_DELETE, false, true, false); | 269 SendKeyEventToTextfieldViews(ui::VKEY_DELETE, false, true, false); |
| 270 EXPECT_STR_EQ(" two three four", textfield_->text()); | 270 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 271 | 271 |
| 272 // Delete upto the end of the buffer from cursor in chromeos, do nothing | 272 // Delete upto the end of the buffer from cursor in chromeos, do nothing |
| 273 // in windows. | 273 // in windows. |
| 274 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true, false); | 274 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true, false); |
| 275 SendKeyEventToTextfieldViews(app::VKEY_DELETE, true, true, false); | 275 SendKeyEventToTextfieldViews(ui::VKEY_DELETE, true, true, false); |
| 276 #if defined(OS_WIN) | 276 #if defined(OS_WIN) |
| 277 EXPECT_STR_EQ(" two three four", textfield_->text()); | 277 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 278 #else | 278 #else |
| 279 EXPECT_STR_EQ(" two", textfield_->text()); | 279 EXPECT_STR_EQ(" two", textfield_->text()); |
| 280 #endif | 280 #endif |
| 281 } | 281 } |
| 282 | 282 |
| 283 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 283 TEST_F(NativeTextfieldViewsTest, PasswordTest) { |
| 284 InitTextfield(Textfield::STYLE_PASSWORD); | 284 InitTextfield(Textfield::STYLE_PASSWORD); |
| 285 textfield_->SetText(ASCIIToUTF16("my password")); | 285 textfield_->SetText(ASCIIToUTF16("my password")); |
| 286 // Just to make sure the text() and callback returns | 286 // Just to make sure the text() and callback returns |
| 287 // the actual text instead of "*". | 287 // the actual text instead of "*". |
| 288 EXPECT_STR_EQ("my password", textfield_->text()); | 288 EXPECT_STR_EQ("my password", textfield_->text()); |
| 289 EXPECT_STR_EQ("my password", last_contents_); | 289 EXPECT_STR_EQ("my password", last_contents_); |
| 290 } | 290 } |
| 291 | 291 |
| 292 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { | 292 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { |
| 293 InitTextfield(Textfield::STYLE_DEFAULT); | 293 InitTextfield(Textfield::STYLE_DEFAULT); |
| 294 EXPECT_TRUE(SendKeyEventToTextfieldViews(app::VKEY_A)); | 294 EXPECT_TRUE(SendKeyEventToTextfieldViews(ui::VKEY_A)); |
| 295 // F24, up/down key won't be handled. | 295 // F24, up/down key won't be handled. |
| 296 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_F24)); | 296 EXPECT_FALSE(SendKeyEventToTextfieldViews(ui::VKEY_F24)); |
| 297 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_UP)); | 297 EXPECT_FALSE(SendKeyEventToTextfieldViews(ui::VKEY_UP)); |
| 298 EXPECT_FALSE(SendKeyEventToTextfieldViews(app::VKEY_DOWN)); | 298 EXPECT_FALSE(SendKeyEventToTextfieldViews(ui::VKEY_DOWN)); |
| 299 } | 299 } |
| 300 | 300 |
| 301 TEST_F(NativeTextfieldViewsTest, CursorMovement) { | 301 TEST_F(NativeTextfieldViewsTest, CursorMovement) { |
| 302 InitTextfield(Textfield::STYLE_DEFAULT); | 302 InitTextfield(Textfield::STYLE_DEFAULT); |
| 303 | 303 |
| 304 // Test with trailing whitespace. | 304 // Test with trailing whitespace. |
| 305 textfield_->SetText(ASCIIToUTF16("one two hre ")); | 305 textfield_->SetText(ASCIIToUTF16("one two hre ")); |
| 306 | 306 |
| 307 // Send the cursor at the end. | 307 // Send the cursor at the end. |
| 308 SendKeyEventToTextfieldViews(app::VKEY_END); | 308 SendKeyEventToTextfieldViews(ui::VKEY_END); |
| 309 | 309 |
| 310 // Ctrl+Left should move the cursor just before the last word. | 310 // Ctrl+Left should move the cursor just before the last word. |
| 311 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true); | 311 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); |
| 312 SendKeyEventToTextfieldViews(app::VKEY_T); | 312 SendKeyEventToTextfieldViews(ui::VKEY_T); |
| 313 EXPECT_STR_EQ("one two thre ", textfield_->text()); | 313 EXPECT_STR_EQ("one two thre ", textfield_->text()); |
| 314 EXPECT_STR_EQ("one two thre ", last_contents_); | 314 EXPECT_STR_EQ("one two thre ", last_contents_); |
| 315 | 315 |
| 316 // Ctrl+Right should move the cursor to the end of the last word. | 316 // Ctrl+Right should move the cursor to the end of the last word. |
| 317 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true); | 317 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true); |
| 318 SendKeyEventToTextfieldViews(app::VKEY_E); | 318 SendKeyEventToTextfieldViews(ui::VKEY_E); |
| 319 EXPECT_STR_EQ("one two three ", textfield_->text()); | 319 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 320 EXPECT_STR_EQ("one two three ", last_contents_); | 320 EXPECT_STR_EQ("one two three ", last_contents_); |
| 321 | 321 |
| 322 // Ctrl+Right again should move the cursor to the end. | 322 // Ctrl+Right again should move the cursor to the end. |
| 323 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true); | 323 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true); |
| 324 SendKeyEventToTextfieldViews(app::VKEY_BACK); | 324 SendKeyEventToTextfieldViews(ui::VKEY_BACK); |
| 325 EXPECT_STR_EQ("one two three", textfield_->text()); | 325 EXPECT_STR_EQ("one two three", textfield_->text()); |
| 326 EXPECT_STR_EQ("one two three", last_contents_); | 326 EXPECT_STR_EQ("one two three", last_contents_); |
| 327 | 327 |
| 328 // Test with leading whitespace. | 328 // Test with leading whitespace. |
| 329 textfield_->SetText(ASCIIToUTF16(" ne two")); | 329 textfield_->SetText(ASCIIToUTF16(" ne two")); |
| 330 | 330 |
| 331 // Send the cursor at the beginning. | 331 // Send the cursor at the beginning. |
| 332 SendKeyEventToTextfieldViews(app::VKEY_HOME); | 332 SendKeyEventToTextfieldViews(ui::VKEY_HOME); |
| 333 | 333 |
| 334 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the | 334 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the |
| 335 // first word. | 335 // first word. |
| 336 SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true); | 336 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true); |
| 337 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true); | 337 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); |
| 338 SendKeyEventToTextfieldViews(app::VKEY_O); | 338 SendKeyEventToTextfieldViews(ui::VKEY_O); |
| 339 EXPECT_STR_EQ(" one two", textfield_->text()); | 339 EXPECT_STR_EQ(" one two", textfield_->text()); |
| 340 EXPECT_STR_EQ(" one two", last_contents_); | 340 EXPECT_STR_EQ(" one two", last_contents_); |
| 341 | 341 |
| 342 // Ctrl+Left to move the cursor to the beginning of the first word. | 342 // Ctrl+Left to move the cursor to the beginning of the first word. |
| 343 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true); | 343 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); |
| 344 // Ctrl+Left again should move the cursor back to the very beginning. | 344 // Ctrl+Left again should move the cursor back to the very beginning. |
| 345 SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true); | 345 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); |
| 346 SendKeyEventToTextfieldViews(app::VKEY_DELETE); | 346 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); |
| 347 EXPECT_STR_EQ("one two", textfield_->text()); | 347 EXPECT_STR_EQ("one two", textfield_->text()); |
| 348 EXPECT_STR_EQ("one two", last_contents_); | 348 EXPECT_STR_EQ("one two", last_contents_); |
| 349 } | 349 } |
| 350 | 350 |
| 351 #if defined(OS_WIN) | 351 #if defined(OS_WIN) |
| 352 // TODO(oshima): Windows' FocusManager::ClearNativeFocus() resets the | 352 // TODO(oshima): Windows' FocusManager::ClearNativeFocus() resets the |
| 353 // focused view to NULL, which causes crash in this test. Figure out | 353 // focused view to NULL, which causes crash in this test. Figure out |
| 354 // why and fix this. | 354 // why and fix this. |
| 355 #define MAYBE_FocusTraversalTest DISABLED_FocusTraversalTest | 355 #define MAYBE_FocusTraversalTest DISABLED_FocusTraversalTest |
| 356 #else | 356 #else |
| (...skipping 21 matching lines...) Expand all Loading... |
| 378 // Cycle back to the last textfield. | 378 // Cycle back to the last textfield. |
| 379 widget_->GetFocusManager()->AdvanceFocus(true); | 379 widget_->GetFocusManager()->AdvanceFocus(true); |
| 380 EXPECT_EQ(3, GetFocusedView()->GetID()); | 380 EXPECT_EQ(3, GetFocusedView()->GetID()); |
| 381 | 381 |
| 382 // Request focus should still work. | 382 // Request focus should still work. |
| 383 textfield_->RequestFocus(); | 383 textfield_->RequestFocus(); |
| 384 EXPECT_EQ(1, GetFocusedView()->GetID()); | 384 EXPECT_EQ(1, GetFocusedView()->GetID()); |
| 385 } | 385 } |
| 386 | 386 |
| 387 } // namespace views | 387 } // namespace views |
| OLD | NEW |