Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "ui/base/clipboard/clipboard.h" | 15 #include "ui/base/clipboard/clipboard.h" |
| 16 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 16 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 17 #include "ui/base/dragdrop/drag_drop_types.h" | 17 #include "ui/base/dragdrop/drag_drop_types.h" |
| 18 #include "ui/base/ime/text_input_client.h" | 18 #include "ui/base/ime/text_input_client.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/ui_base_switches.h" | 20 #include "ui/base/ui_base_switches.h" |
| 21 #include "ui/base/ui_base_switches_util.h" | 21 #include "ui/base/ui_base_switches_util.h" |
| 22 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 23 #include "ui/events/keycodes/keyboard_codes.h" | 23 #include "ui/events/keycodes/keyboard_codes.h" |
| 24 #include "ui/events/test/event_generator.h" | |
| 24 #include "ui/gfx/render_text.h" | 25 #include "ui/gfx/render_text.h" |
| 25 #include "ui/strings/grit/ui_strings.h" | 26 #include "ui/strings/grit/ui_strings.h" |
| 26 #include "ui/views/controls/textfield/textfield_controller.h" | 27 #include "ui/views/controls/textfield/textfield_controller.h" |
| 27 #include "ui/views/controls/textfield/textfield_model.h" | 28 #include "ui/views/controls/textfield/textfield_model.h" |
| 28 #include "ui/views/controls/textfield/textfield_test_api.h" | 29 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 29 #include "ui/views/focus/focus_manager.h" | 30 #include "ui/views/focus/focus_manager.h" |
| 30 #include "ui/views/ime/mock_input_method.h" | 31 #include "ui/views/ime/mock_input_method.h" |
| 31 #include "ui/views/test/test_views_delegate.h" | 32 #include "ui/views/test/test_views_delegate.h" |
| 32 #include "ui/views/test/views_test_base.h" | 33 #include "ui/views/test/views_test_base.h" |
| 33 #include "ui/views/test/widget_test.h" | 34 #include "ui/views/test/widget_test.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 196 |
| 196 void InitTextfield() { | 197 void InitTextfield() { |
| 197 InitTextfields(1); | 198 InitTextfields(1); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void InitTextfields(int count) { | 201 void InitTextfields(int count) { |
| 201 ASSERT_FALSE(textfield_); | 202 ASSERT_FALSE(textfield_); |
| 202 textfield_ = new TestTextfield(); | 203 textfield_ = new TestTextfield(); |
| 203 textfield_->set_controller(this); | 204 textfield_->set_controller(this); |
| 204 widget_ = new Widget(); | 205 widget_ = new Widget(); |
| 205 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 206 |
| 207 // The widget type must be an activatable type, and we don't want to worry | |
| 208 // about the non-client view, which leaves just TYPE_WINDOW_FRAMELESS. | |
| 209 Widget::InitParams params = | |
| 210 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 211 | |
| 206 params.bounds = gfx::Rect(100, 100, 100, 100); | 212 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 207 widget_->Init(params); | 213 widget_->Init(params); |
| 208 View* container = new View(); | 214 View* container = new View(); |
| 209 widget_->SetContentsView(container); | 215 widget_->SetContentsView(container); |
| 210 container->AddChildView(textfield_); | 216 container->AddChildView(textfield_); |
| 211 textfield_->SetBoundsRect(params.bounds); | 217 textfield_->SetBoundsRect(params.bounds); |
| 212 textfield_->set_id(1); | 218 textfield_->set_id(1); |
| 213 test_api_.reset(new TextfieldTestApi(textfield_)); | 219 test_api_.reset(new TextfieldTestApi(textfield_)); |
| 214 | 220 |
| 215 for (int i = 1; i < count; i++) { | 221 for (int i = 1; i < count; i++) { |
| 216 Textfield* textfield = new Textfield(); | 222 Textfield* textfield = new Textfield(); |
| 217 container->AddChildView(textfield); | 223 container->AddChildView(textfield); |
| 218 textfield->set_id(i + 1); | 224 textfield->set_id(i + 1); |
| 219 } | 225 } |
| 220 | 226 |
| 221 model_ = test_api_->model(); | 227 model_ = test_api_->model(); |
| 222 model_->ClearEditHistory(); | 228 model_->ClearEditHistory(); |
| 223 | 229 |
| 224 input_method_ = new MockInputMethod(); | 230 input_method_ = new MockInputMethod(); |
| 225 widget_->ReplaceInputMethod(input_method_); | 231 widget_->ReplaceInputMethod(input_method_); |
| 226 | 232 |
| 227 // Activate the widget and focus the textfield for input handling. | 233 // Since the window type is activatable, showing the widget will also |
| 228 widget_->Activate(); | 234 // activate it. Calling Activate directly is insufficient, since that does |
| 235 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the | |
| 236 // widget and the textfield must have focus to properly handle input. | |
| 237 widget_->Show(); | |
| 229 textfield_->RequestFocus(); | 238 textfield_->RequestFocus(); |
| 230 | 239 |
| 231 // On Mac, activation is asynchronous since desktop widgets are used. We | 240 // On Mac, activation is asynchronous since desktop widgets are used. We |
| 232 // don't want parallel tests to steal active status either, so fake it. | 241 // don't want parallel tests to steal active status either, so fake it. |
| 233 #if defined(OS_MACOSX) && !defined(USE_AURA) | 242 #if defined(OS_MACOSX) && !defined(USE_AURA) |
| 234 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways(); | 243 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways(); |
| 235 #endif | 244 #endif |
| 245 | |
| 246 event_generator_.reset( | |
| 247 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow())); | |
| 236 } | 248 } |
| 237 | 249 |
| 238 ui::MenuModel* GetContextMenuModel() { | 250 ui::MenuModel* GetContextMenuModel() { |
| 239 test_api_->UpdateContextMenu(); | 251 test_api_->UpdateContextMenu(); |
| 240 return test_api_->context_menu_contents(); | 252 return test_api_->context_menu_contents(); |
| 241 } | 253 } |
| 242 | 254 |
| 255 // True if native Mac keystrokes should be used (to avoid ifdef litter). | |
| 256 bool TestingNativeMac() { | |
| 257 #if defined(OS_MACOSX) | |
| 258 return true; | |
| 259 #else | |
| 260 return false; | |
| 261 #endif | |
| 262 } | |
| 263 | |
| 243 protected: | 264 protected: |
| 244 void SendKeyEvent(ui::KeyboardCode key_code, | 265 void SendKeyEvent(ui::KeyboardCode key_code, |
| 245 bool alt, | 266 bool alt, |
| 246 bool shift, | 267 bool shift, |
| 247 bool control, | 268 bool control_or_command, |
| 248 bool caps_lock) { | 269 bool caps_lock) { |
| 249 int flags = (alt ? ui::EF_ALT_DOWN : 0) | | 270 bool control = control_or_command; |
| 250 (shift ? ui::EF_SHIFT_DOWN : 0) | | 271 bool command = false; |
| 272 | |
| 273 // By default, swap control and command for native events on Mac. This | |
| 274 // handles most cases. | |
| 275 if (TestingNativeMac()) | |
| 276 std::swap(control, command); | |
| 277 | |
| 278 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) | | |
| 251 (control ? ui::EF_CONTROL_DOWN : 0) | | 279 (control ? ui::EF_CONTROL_DOWN : 0) | |
| 280 (command ? ui::EF_COMMAND_DOWN : 0) | | |
| 252 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); | 281 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); |
| 253 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); | 282 |
| 254 input_method_->DispatchKeyEvent(event); | 283 event_generator_->PressKey(key_code, flags); |
| 255 } | 284 } |
| 256 | 285 |
| 257 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { | 286 void SendKeyEvent(ui::KeyboardCode key_code, |
| 258 SendKeyEvent(key_code, false, shift, control, false); | 287 bool shift, |
| 288 bool control_or_command) { | |
| 289 SendKeyEvent(key_code, false, shift, control_or_command, false); | |
| 259 } | 290 } |
| 260 | 291 |
| 261 void SendKeyEvent(ui::KeyboardCode key_code) { | 292 void SendKeyEvent(ui::KeyboardCode key_code) { |
| 262 SendKeyEvent(key_code, false, false); | 293 SendKeyEvent(key_code, false, false); |
| 263 } | 294 } |
| 264 | 295 |
| 265 void SendKeyEvent(base::char16 ch) { | 296 void SendKeyEvent(base::char16 ch) { |
| 266 if (ch < 0x80) { | 297 if (ch < 0x80) { |
| 267 ui::KeyboardCode code = | 298 ui::KeyboardCode code = |
| 268 ch == ' ' ? ui::VKEY_SPACE : | 299 ch == ' ' ? ui::VKEY_SPACE : |
| 269 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); | 300 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); |
| 270 SendKeyEvent(code); | 301 SendKeyEvent(code); |
| 271 } else { | 302 } else { |
| 303 // For unicode characters, assume they come from IME rather than the | |
| 304 // keyboard. So they are dispatched directly to the input method. | |
| 272 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); | 305 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); |
|
tapted
2015/02/02 12:46:37
I removed the TODO (and added a new comment), sinc
oshima
2015/02/02 17:59:13
Acknowledged.
| |
| 273 input_method_->DispatchKeyEvent(event); | 306 input_method_->DispatchKeyEvent(event); |
| 274 } | 307 } |
| 275 } | 308 } |
| 276 | 309 |
| 310 // Sends a platform-specific move (and select) to start of line. | |
| 311 void SendHomeEvent(bool shift) { | |
| 312 if (TestingNativeMac()) { | |
| 313 // Use Cmd+Left on native Mac. An RTL-agnostic "end" doesn't have a | |
| 314 // default key-binding on Mac. | |
| 315 SendKeyEvent(ui::VKEY_LEFT, shift /* shift */, true /* command */); | |
| 316 return; | |
| 317 } | |
| 318 SendKeyEvent(ui::VKEY_HOME, shift /* shift */, false /* control */); | |
| 319 } | |
| 320 | |
| 321 // Sends a platform-specific move (and select) to end of line. | |
| 322 void SendEndEvent(bool shift) { | |
| 323 if (TestingNativeMac()) { | |
| 324 SendKeyEvent(ui::VKEY_RIGHT, shift, true); // Cmd+Right. | |
| 325 return; | |
| 326 } | |
| 327 SendKeyEvent(ui::VKEY_END, shift, false); | |
| 328 } | |
| 329 | |
| 330 // Sends {delete, move, select} word {forward, backward}. | |
| 331 void SendWordEvent(ui::KeyboardCode key, bool shift) { | |
| 332 bool alt = false; | |
| 333 bool control = true; | |
| 334 bool caps = false; | |
| 335 if (TestingNativeMac()) { | |
| 336 // Use Alt+Left/Right/Backspace on native Mac. | |
| 337 alt = true; | |
| 338 control = false; | |
| 339 } | |
| 340 SendKeyEvent(key, alt, shift, control, caps); | |
| 341 } | |
| 342 | |
| 277 View* GetFocusedView() { | 343 View* GetFocusedView() { |
| 278 return widget_->GetFocusManager()->GetFocusedView(); | 344 return widget_->GetFocusManager()->GetFocusedView(); |
| 279 } | 345 } |
| 280 | 346 |
| 281 int GetCursorPositionX(int cursor_pos) { | 347 int GetCursorPositionX(int cursor_pos) { |
| 282 return test_api_->GetRenderText()->GetCursorBounds( | 348 return test_api_->GetRenderText()->GetCursorBounds( |
| 283 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); | 349 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); |
| 284 } | 350 } |
| 285 | 351 |
| 286 // Get the current cursor bounds. | 352 // Get the current cursor bounds. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 | 416 |
| 351 // Indicates how many times OnBeforeUserAction() is called. | 417 // Indicates how many times OnBeforeUserAction() is called. |
| 352 int on_before_user_action_; | 418 int on_before_user_action_; |
| 353 | 419 |
| 354 // Indicates how many times OnAfterUserAction() is called. | 420 // Indicates how many times OnAfterUserAction() is called. |
| 355 int on_after_user_action_; | 421 int on_after_user_action_; |
| 356 | 422 |
| 357 private: | 423 private: |
| 358 ui::ClipboardType copied_to_clipboard_; | 424 ui::ClipboardType copied_to_clipboard_; |
| 359 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; | 425 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; |
| 426 scoped_ptr<ui::test::EventGenerator> event_generator_; | |
| 360 | 427 |
| 361 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); | 428 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); |
| 362 }; | 429 }; |
| 363 | 430 |
| 364 TEST_F(TextfieldTest, ModelChangesTest) { | 431 TEST_F(TextfieldTest, ModelChangesTest) { |
| 365 InitTextfield(); | 432 InitTextfield(); |
| 366 | 433 |
| 367 // TextfieldController::ContentsChanged() shouldn't be called when changing | 434 // TextfieldController::ContentsChanged() shouldn't be called when changing |
| 368 // text programmatically. | 435 // text programmatically. |
| 369 last_contents_.clear(); | 436 last_contents_.clear(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 395 SendKeyEvent(ui::VKEY_1, false, false, false, false); | 462 SendKeyEvent(ui::VKEY_1, false, false, false, false); |
| 396 SendKeyEvent(ui::VKEY_1, false, true, false, true); | 463 SendKeyEvent(ui::VKEY_1, false, true, false, true); |
| 397 SendKeyEvent(ui::VKEY_1, false, false, false, true); | 464 SendKeyEvent(ui::VKEY_1, false, false, false, true); |
| 398 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); | 465 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); |
| 399 } | 466 } |
| 400 | 467 |
| 401 TEST_F(TextfieldTest, ControlAndSelectTest) { | 468 TEST_F(TextfieldTest, ControlAndSelectTest) { |
| 402 // Insert a test string in a textfield. | 469 // Insert a test string in a textfield. |
| 403 InitTextfield(); | 470 InitTextfield(); |
| 404 textfield_->SetText(ASCIIToUTF16("one two three")); | 471 textfield_->SetText(ASCIIToUTF16("one two three")); |
| 405 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); | 472 SendHomeEvent(false); |
| 406 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 473 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 407 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 474 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 408 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 475 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 409 | 476 |
| 410 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 477 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
| 411 | 478 |
| 412 // Test word select. | 479 // Test word select. |
| 413 SendKeyEvent(ui::VKEY_RIGHT, true, true); | 480 SendWordEvent(ui::VKEY_RIGHT, true); |
| 414 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); | 481 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); |
| 415 SendKeyEvent(ui::VKEY_RIGHT, true, true); | 482 SendWordEvent(ui::VKEY_RIGHT, true); |
| 416 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); | 483 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); |
| 417 SendKeyEvent(ui::VKEY_LEFT, true, true); | 484 SendWordEvent(ui::VKEY_LEFT, true); |
| 418 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); | 485 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); |
| 419 SendKeyEvent(ui::VKEY_LEFT, true, true); | 486 SendWordEvent(ui::VKEY_LEFT, true); |
| 420 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); | 487 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); |
| 421 | 488 |
| 422 // Replace the selected text. | 489 // Replace the selected text. |
| 423 SendKeyEvent(ui::VKEY_Z, true, false); | 490 SendKeyEvent(ui::VKEY_Z, true, false); |
| 424 SendKeyEvent(ui::VKEY_E, true, false); | 491 SendKeyEvent(ui::VKEY_E, true, false); |
| 425 SendKeyEvent(ui::VKEY_R, true, false); | 492 SendKeyEvent(ui::VKEY_R, true, false); |
| 426 SendKeyEvent(ui::VKEY_O, true, false); | 493 SendKeyEvent(ui::VKEY_O, true, false); |
| 427 SendKeyEvent(ui::VKEY_SPACE, false, false); | 494 SendKeyEvent(ui::VKEY_SPACE, false, false); |
| 428 EXPECT_STR_EQ("ZERO two three", textfield_->text()); | 495 EXPECT_STR_EQ("ZERO two three", textfield_->text()); |
| 429 | 496 |
| 430 SendKeyEvent(ui::VKEY_END, true, false); | 497 SendEndEvent(true); |
| 431 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); | 498 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); |
| 432 SendKeyEvent(ui::VKEY_HOME, true, false); | 499 SendHomeEvent(true); |
| 433 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); | 500 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); |
| 434 } | 501 } |
| 435 | 502 |
| 436 TEST_F(TextfieldTest, InsertionDeletionTest) { | 503 TEST_F(TextfieldTest, InsertionDeletionTest) { |
| 437 // Insert a test string in a textfield. | 504 // Insert a test string in a textfield. |
| 438 InitTextfield(); | 505 InitTextfield(); |
| 439 for (size_t i = 0; i < 10; i++) | 506 for (size_t i = 0; i < 10; i++) |
| 440 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); | 507 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); |
| 441 EXPECT_STR_EQ("abcdefghij", textfield_->text()); | 508 EXPECT_STR_EQ("abcdefghij", textfield_->text()); |
| 442 | 509 |
| 443 // Test the delete and backspace keys. | 510 // Test the delete and backspace keys. |
| 444 textfield_->SelectRange(gfx::Range(5)); | 511 textfield_->SelectRange(gfx::Range(5)); |
| 445 for (int i = 0; i < 3; i++) | 512 for (int i = 0; i < 3; i++) |
| 446 SendKeyEvent(ui::VKEY_BACK); | 513 SendKeyEvent(ui::VKEY_BACK); |
| 447 EXPECT_STR_EQ("abfghij", textfield_->text()); | 514 EXPECT_STR_EQ("abfghij", textfield_->text()); |
| 448 for (int i = 0; i < 3; i++) | 515 for (int i = 0; i < 3; i++) |
| 449 SendKeyEvent(ui::VKEY_DELETE); | 516 SendKeyEvent(ui::VKEY_DELETE); |
| 450 EXPECT_STR_EQ("abij", textfield_->text()); | 517 EXPECT_STR_EQ("abij", textfield_->text()); |
| 451 | 518 |
| 452 // Select all and replace with "k". | 519 // Select all and replace with "k". |
| 453 textfield_->SelectAll(false); | 520 textfield_->SelectAll(false); |
| 454 SendKeyEvent(ui::VKEY_K); | 521 SendKeyEvent(ui::VKEY_K); |
| 455 EXPECT_STR_EQ("k", textfield_->text()); | 522 EXPECT_STR_EQ("k", textfield_->text()); |
| 456 | 523 |
| 457 // Delete the previous word from cursor. | 524 // Delete the previous word from cursor. |
| 525 bool shift = false; | |
| 458 textfield_->SetText(ASCIIToUTF16("one two three four")); | 526 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 459 SendKeyEvent(ui::VKEY_END); | 527 SendEndEvent(shift); |
| 460 SendKeyEvent(ui::VKEY_BACK, false, false, true, false); | 528 SendWordEvent(ui::VKEY_BACK, shift); |
| 461 EXPECT_STR_EQ("one two three ", textfield_->text()); | 529 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 462 | 530 |
| 463 // Delete to a line break on Linux and ChromeOS, to a word break on Windows. | 531 // Delete to a line break on Linux and ChromeOS, to a word break on Windows |
| 464 SendKeyEvent(ui::VKEY_LEFT, false, false, true, false); | 532 // and Mac. |
| 465 SendKeyEvent(ui::VKEY_BACK, false, true, true, false); | 533 SendWordEvent(ui::VKEY_LEFT, shift); |
| 534 shift = true; | |
| 535 SendWordEvent(ui::VKEY_BACK, shift); | |
| 466 #if defined(OS_LINUX) | 536 #if defined(OS_LINUX) |
| 467 EXPECT_STR_EQ("three ", textfield_->text()); | 537 EXPECT_STR_EQ("three ", textfield_->text()); |
| 468 #else | 538 #else |
| 469 EXPECT_STR_EQ("one three ", textfield_->text()); | 539 EXPECT_STR_EQ("one three ", textfield_->text()); |
| 470 #endif | 540 #endif |
| 471 | 541 |
| 472 // Delete the next word from cursor. | 542 // Delete the next word from cursor. |
| 473 textfield_->SetText(ASCIIToUTF16("one two three four")); | 543 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 474 SendKeyEvent(ui::VKEY_HOME); | 544 shift = false; |
| 475 SendKeyEvent(ui::VKEY_DELETE, false, false, true, false); | 545 SendHomeEvent(shift); |
| 546 SendWordEvent(ui::VKEY_DELETE, shift); | |
| 476 EXPECT_STR_EQ(" two three four", textfield_->text()); | 547 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 477 | 548 |
| 478 // Delete to a line break on Linux and ChromeOS, to a word break on Windows. | 549 // Delete to a line break on Linux and ChromeOS, to a word break on Windows |
| 479 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); | 550 // and Mac. |
| 480 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); | 551 SendWordEvent(ui::VKEY_RIGHT, shift); |
| 552 shift = true; | |
| 553 SendWordEvent(ui::VKEY_DELETE, shift); | |
| 481 #if defined(OS_LINUX) | 554 #if defined(OS_LINUX) |
| 482 EXPECT_STR_EQ(" two", textfield_->text()); | 555 EXPECT_STR_EQ(" two", textfield_->text()); |
| 483 #else | 556 #else |
| 484 EXPECT_STR_EQ(" two four", textfield_->text()); | 557 EXPECT_STR_EQ(" two four", textfield_->text()); |
| 485 #endif | 558 #endif |
| 486 } | 559 } |
| 487 | 560 |
| 488 TEST_F(TextfieldTest, PasswordTest) { | 561 TEST_F(TextfieldTest, PasswordTest) { |
| 489 InitTextfield(); | 562 InitTextfield(); |
| 490 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 563 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1423 SendKeyEvent(0x05E1); | 1496 SendKeyEvent(0x05E1); |
| 1424 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); | 1497 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); |
| 1425 x = GetCursorBounds().x(); | 1498 x = GetCursorBounds().x(); |
| 1426 EXPECT_GE(1, std::abs(x - prev_x)); | 1499 EXPECT_GE(1, std::abs(x - prev_x)); |
| 1427 | 1500 |
| 1428 SendKeyEvent(0x05E2); | 1501 SendKeyEvent(0x05E2); |
| 1429 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); | 1502 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); |
| 1430 x = GetCursorBounds().x(); | 1503 x = GetCursorBounds().x(); |
| 1431 EXPECT_GE(1, std::abs(x - prev_x)); | 1504 EXPECT_GE(1, std::abs(x - prev_x)); |
| 1432 | 1505 |
| 1433 // Clear text. | 1506 textfield_->SetText(base::string16()); |
| 1434 SendKeyEvent(ui::VKEY_A, false, true); | |
| 1435 SendKeyEvent('\n'); | |
| 1436 | 1507 |
| 1437 // RTL-LTR string in LTR context. | 1508 // RTL-LTR string in LTR context. |
| 1438 SendKeyEvent(0x05E1); | 1509 SendKeyEvent(0x05E1); |
| 1439 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); | 1510 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); |
| 1440 x = GetCursorBounds().x(); | 1511 x = GetCursorBounds().x(); |
| 1441 EXPECT_EQ(GetDisplayRect().x(), x); | 1512 EXPECT_EQ(GetDisplayRect().x(), x); |
| 1442 prev_x = x; | 1513 prev_x = x; |
| 1443 | 1514 |
| 1444 SendKeyEvent(0x05E2); | 1515 SendKeyEvent(0x05E2); |
| 1445 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); | 1516 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1479 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); | 1550 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); |
| 1480 x = GetCursorBounds().x(); | 1551 x = GetCursorBounds().x(); |
| 1481 EXPECT_GT(prev_x, x); | 1552 EXPECT_GT(prev_x, x); |
| 1482 prev_x = x; | 1553 prev_x = x; |
| 1483 | 1554 |
| 1484 SendKeyEvent(0x05E2); | 1555 SendKeyEvent(0x05E2); |
| 1485 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); | 1556 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); |
| 1486 x = GetCursorBounds().x(); | 1557 x = GetCursorBounds().x(); |
| 1487 EXPECT_GT(prev_x, x); | 1558 EXPECT_GT(prev_x, x); |
| 1488 | 1559 |
| 1489 SendKeyEvent(ui::VKEY_A, false, true); | 1560 textfield_->SetText(base::string16()); |
| 1490 SendKeyEvent('\n'); | |
| 1491 | 1561 |
| 1492 // RTL-LTR string in RTL context. | 1562 // RTL-LTR string in RTL context. |
| 1493 SendKeyEvent(0x05E1); | 1563 SendKeyEvent(0x05E1); |
| 1494 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); | 1564 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); |
| 1495 x = GetCursorBounds().x(); | 1565 x = GetCursorBounds().x(); |
| 1496 prev_x = x; | 1566 prev_x = x; |
| 1497 | 1567 |
| 1498 SendKeyEvent(0x05E2); | 1568 SendKeyEvent(0x05E2); |
| 1499 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); | 1569 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); |
| 1500 x = GetCursorBounds().x(); | 1570 x = GetCursorBounds().x(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1645 base::string16 str; | 1715 base::string16 str; |
| 1646 for (int i = 0; i < 500; ++i) | 1716 for (int i = 0; i < 500; ++i) |
| 1647 SendKeyEvent('a'); | 1717 SendKeyEvent('a'); |
| 1648 SendKeyEvent(kHebrewLetterSamekh); | 1718 SendKeyEvent(kHebrewLetterSamekh); |
| 1649 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1719 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| 1650 | 1720 |
| 1651 // Test mouse pointing. | 1721 // Test mouse pointing. |
| 1652 MouseClick(GetCursorBounds(), -1); | 1722 MouseClick(GetCursorBounds(), -1); |
| 1653 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1723 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1654 | 1724 |
| 1655 // Clear text. | 1725 textfield_->SetText(base::string16()); |
| 1656 SendKeyEvent(ui::VKEY_A, false, true); | |
| 1657 SendKeyEvent('\n'); | |
| 1658 | 1726 |
| 1659 for (int i = 0; i < 500; ++i) | 1727 for (int i = 0; i < 500; ++i) |
| 1660 SendKeyEvent(kHebrewLetterSamekh); | 1728 SendKeyEvent(kHebrewLetterSamekh); |
| 1661 SendKeyEvent('a'); | 1729 SendKeyEvent('a'); |
| 1662 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1730 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| 1663 | 1731 |
| 1664 MouseClick(GetCursorBounds(), -1); | 1732 MouseClick(GetCursorBounds(), -1); |
| 1665 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 1733 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
| 1666 } | 1734 } |
| 1667 | 1735 |
| 1668 TEST_F(TextfieldTest, OverflowInRTLTest) { | 1736 TEST_F(TextfieldTest, OverflowInRTLTest) { |
| 1669 std::string locale = l10n_util::GetApplicationLocale(""); | 1737 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1670 base::i18n::SetICUDefaultLocale("he"); | 1738 base::i18n::SetICUDefaultLocale("he"); |
| 1671 | 1739 |
| 1672 InitTextfield(); | 1740 InitTextfield(); |
| 1673 | 1741 |
| 1674 base::string16 str; | 1742 base::string16 str; |
| 1675 for (int i = 0; i < 500; ++i) | 1743 for (int i = 0; i < 500; ++i) |
| 1676 SendKeyEvent('a'); | 1744 SendKeyEvent('a'); |
| 1677 SendKeyEvent(kHebrewLetterSamekh); | 1745 SendKeyEvent(kHebrewLetterSamekh); |
| 1678 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1746 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| 1679 | 1747 |
| 1680 MouseClick(GetCursorBounds(), 1); | 1748 MouseClick(GetCursorBounds(), 1); |
| 1681 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 1749 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
| 1682 | 1750 |
| 1683 // Clear text. | 1751 textfield_->SetText(base::string16()); |
| 1684 SendKeyEvent(ui::VKEY_A, false, true); | |
| 1685 SendKeyEvent('\n'); | |
| 1686 | 1752 |
| 1687 for (int i = 0; i < 500; ++i) | 1753 for (int i = 0; i < 500; ++i) |
| 1688 SendKeyEvent(kHebrewLetterSamekh); | 1754 SendKeyEvent(kHebrewLetterSamekh); |
| 1689 SendKeyEvent('a'); | 1755 SendKeyEvent('a'); |
| 1690 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1756 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| 1691 | 1757 |
| 1692 MouseClick(GetCursorBounds(), 1); | 1758 MouseClick(GetCursorBounds(), 1); |
| 1693 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1759 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1694 | 1760 |
| 1695 // Reset locale. | 1761 // Reset locale. |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2109 | 2175 |
| 2110 // Tap again on selection and check if touch selection handles are still | 2176 // Tap again on selection and check if touch selection handles are still |
| 2111 // present and selection is changed to a cursor at tap location. | 2177 // present and selection is changed to a cursor at tap location. |
| 2112 Tap(tap_point); | 2178 Tap(tap_point); |
| 2113 textfield_->GetSelectionRange(&range); | 2179 textfield_->GetSelectionRange(&range); |
| 2114 EXPECT_TRUE(test_api_->touch_selection_controller()); | 2180 EXPECT_TRUE(test_api_->touch_selection_controller()); |
| 2115 EXPECT_EQ(tap_range, range); | 2181 EXPECT_EQ(tap_range, range); |
| 2116 } | 2182 } |
| 2117 | 2183 |
| 2118 } // namespace views | 2184 } // namespace views |
| OLD | NEW |