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

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

Issue 1325333002: Ignore inserting character with Search as a modifier on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: kpschoedel's comments Created 5 years, 3 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
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 // True if native Mac keystrokes should be used (to avoid ifdef litter). 451 // True if native Mac keystrokes should be used (to avoid ifdef litter).
452 bool TestingNativeMac() { 452 bool TestingNativeMac() {
453 #if defined(OS_MACOSX) 453 #if defined(OS_MACOSX)
454 return true; 454 return true;
455 #else 455 #else
456 return false; 456 return false;
457 #endif 457 #endif
458 } 458 }
459 459
460 bool TestingNativeCrOs() const {
461 #if defined(OS_CHROMEOS)
462 return true;
463 #else
464 return false;
465 #endif // defined(OS_CHROMEOS)
466 }
467
460 protected: 468 protected:
469 void SendKeyPress(ui::KeyboardCode key_code, int flags) {
470 #if defined(OS_MACOSX) && !defined(USE_AURA)
471 // The Mac EventGenerator hooks in before IME. It sends events first to an
472 // NSResponder, which is necessary to interpret keyboard events into
473 // appropriate editing commands.
474 event_generator_->PressKey(key_code, flags);
475 #else
476 // TODO(shuchen): making EventGenerator support input method and using
477 // EventGenerator here. crbug.com/512315.
478 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags);
479 input_method_->DispatchKeyEvent(&event);
480 #endif
481 }
482
461 void SendKeyEvent(ui::KeyboardCode key_code, 483 void SendKeyEvent(ui::KeyboardCode key_code,
462 bool alt, 484 bool alt,
463 bool shift, 485 bool shift,
464 bool control_or_command, 486 bool control_or_command,
465 bool caps_lock) { 487 bool caps_lock) {
466 bool control = control_or_command; 488 bool control = control_or_command;
467 bool command = false; 489 bool command = false;
468 490
469 // By default, swap control and command for native events on Mac. This 491 // By default, swap control and command for native events on Mac. This
470 // handles most cases. 492 // handles most cases.
471 if (TestingNativeMac()) 493 if (TestingNativeMac())
472 std::swap(control, command); 494 std::swap(control, command);
473 495
474 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) | 496 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) |
475 (control ? ui::EF_CONTROL_DOWN : 0) | 497 (control ? ui::EF_CONTROL_DOWN : 0) |
476 (command ? ui::EF_COMMAND_DOWN : 0) | 498 (command ? ui::EF_COMMAND_DOWN : 0) |
477 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); 499 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0);
478 500
479 #if defined(OS_MACOSX) && !defined(USE_AURA) 501 SendKeyPress(key_code, flags);
480 // The Mac EventGenerator hooks in before IME. It sends events first to an
481 // NSResponder, which is necessary to interpret keyboard events into
482 // appropriate editing commands.
483 event_generator_->PressKey(key_code, flags);
484 #else
485 // TODO(shuchen): making EventGenerator support input method and using
486 // EventGenerator here. crbug.com/512315.
487 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags);
488 input_method_->DispatchKeyEvent(&event);
489 #endif
490 } 502 }
491 503
492 void SendKeyEvent(ui::KeyboardCode key_code, 504 void SendKeyEvent(ui::KeyboardCode key_code,
493 bool shift, 505 bool shift,
494 bool control_or_command) { 506 bool control_or_command) {
495 SendKeyEvent(key_code, false, shift, control_or_command, false); 507 SendKeyEvent(key_code, false, shift, control_or_command, false);
496 } 508 }
497 509
498 void SendKeyEvent(ui::KeyboardCode key_code) { 510 void SendKeyEvent(ui::KeyboardCode key_code) {
499 SendKeyEvent(key_code, false, false); 511 SendKeyEvent(key_code, false, false);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 SendKeyEvent(ui::VKEY_1, false, true, false, true); 712 SendKeyEvent(ui::VKEY_1, false, true, false, true);
701 SendKeyEvent(ui::VKEY_1, false, false, false, true); 713 SendKeyEvent(ui::VKEY_1, false, false, false, true);
702 714
703 // On Mac, Caps+Shift remains uppercase. 715 // On Mac, Caps+Shift remains uppercase.
704 if (TestingNativeMac()) 716 if (TestingNativeMac())
705 EXPECT_STR_EQ("TeXT!1!1", textfield_->text()); 717 EXPECT_STR_EQ("TeXT!1!1", textfield_->text());
706 else 718 else
707 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); 719 EXPECT_STR_EQ("TexT!1!1", textfield_->text());
708 } 720 }
709 721
722 TEST_F(TextfieldTest, KeysWithModifiersTest) {
723 InitTextfield();
724 const int ctrl = ui::EF_CONTROL_DOWN;
725 const int alt = ui::EF_ALT_DOWN;
726 const int command = ui::EF_COMMAND_DOWN;
727 const int altgr = ui::EF_ALTGR_DOWN;
728 const int shift = ui::EF_SHIFT_DOWN;
729
730 SendKeyPress(ui::VKEY_T, shift);
731 SendKeyPress(ui::VKEY_E, shift | altgr);
732 SendKeyPress(ui::VKEY_X, 0);
733 SendKeyPress(ui::VKEY_T, ctrl);
734 SendKeyPress(ui::VKEY_1, alt);
735 SendKeyPress(ui::VKEY_2, command);
736 SendKeyPress(ui::VKEY_3, 0);
737 SendKeyPress(ui::VKEY_4, 0);
738
739 if (TestingNativeCrOs())
740 EXPECT_STR_EQ("TEx34", textfield_->text());
741 else
742 EXPECT_STR_EQ("TEx234", textfield_->text());
743 }
744
710 TEST_F(TextfieldTest, ControlAndSelectTest) { 745 TEST_F(TextfieldTest, ControlAndSelectTest) {
711 // Insert a test string in a textfield. 746 // Insert a test string in a textfield.
712 InitTextfield(); 747 InitTextfield();
713 textfield_->SetText(ASCIIToUTF16("one two three")); 748 textfield_->SetText(ASCIIToUTF16("one two three"));
714 SendHomeEvent(false); 749 SendHomeEvent(false);
715 SendKeyEvent(ui::VKEY_RIGHT, true, false); 750 SendKeyEvent(ui::VKEY_RIGHT, true, false);
716 SendKeyEvent(ui::VKEY_RIGHT, true, false); 751 SendKeyEvent(ui::VKEY_RIGHT, true, false);
717 SendKeyEvent(ui::VKEY_RIGHT, true, false); 752 SendKeyEvent(ui::VKEY_RIGHT, true, false);
718 753
719 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); 754 EXPECT_STR_EQ("one", textfield_->GetSelectedText());
(...skipping 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after
2551 2586
2552 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2587 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2553 ui::AXViewState state_protected; 2588 ui::AXViewState state_protected;
2554 textfield_->GetAccessibleState(&state_protected); 2589 textfield_->GetAccessibleState(&state_protected);
2555 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2590 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2556 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2591 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2557 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2592 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2558 } 2593 }
2559 2594
2560 } // namespace views 2595 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698