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/accessibility/ax_view_state.h" | 15 #include "ui/accessibility/ax_view_state.h" |
16 #include "ui/base/clipboard/clipboard.h" | 16 #include "ui/base/clipboard/clipboard.h" |
17 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 17 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
18 #include "ui/base/dragdrop/drag_drop_types.h" | 18 #include "ui/base/dragdrop/drag_drop_types.h" |
19 #include "ui/base/ime/input_method_base.h" | 19 #include "ui/base/ime/input_method_base.h" |
20 #include "ui/base/ime/input_method_delegate.h" | 20 #include "ui/base/ime/input_method_delegate.h" |
21 #include "ui/base/ime/input_method_factory.h" | 21 #include "ui/base/ime/input_method_factory.h" |
22 #include "ui/base/ime/text_input_client.h" | 22 #include "ui/base/ime/text_input_client.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/ui_base_switches.h" | 24 #include "ui/base/ui_base_switches.h" |
25 #include "ui/base/ui_base_switches_util.h" | 25 #include "ui/base/ui_base_switches_util.h" |
26 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
27 #include "ui/events/event_processor.h" | 27 #include "ui/events/event_processor.h" |
28 #include "ui/events/event_utils.h" | 28 #include "ui/events/event_utils.h" |
29 #include "ui/events/keycodes/keyboard_codes.h" | 29 #include "ui/events/keycodes/keyboard_codes.h" |
30 #include "ui/events/test/event_generator.h" | |
31 #include "ui/gfx/render_text.h" | 30 #include "ui/gfx/render_text.h" |
32 #include "ui/strings/grit/ui_strings.h" | 31 #include "ui/strings/grit/ui_strings.h" |
33 #include "ui/views/controls/textfield/textfield_controller.h" | 32 #include "ui/views/controls/textfield/textfield_controller.h" |
34 #include "ui/views/controls/textfield/textfield_model.h" | 33 #include "ui/views/controls/textfield/textfield_model.h" |
35 #include "ui/views/controls/textfield/textfield_test_api.h" | 34 #include "ui/views/controls/textfield/textfield_test_api.h" |
36 #include "ui/views/focus/focus_manager.h" | 35 #include "ui/views/focus/focus_manager.h" |
37 #include "ui/views/test/test_views_delegate.h" | 36 #include "ui/views/test/test_views_delegate.h" |
38 #include "ui/views/test/views_test_base.h" | 37 #include "ui/views/test/views_test_base.h" |
39 #include "ui/views/test/widget_test.h" | 38 #include "ui/views/test/widget_test.h" |
40 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the | 430 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the |
432 // widget and the textfield must have focus to properly handle input. | 431 // widget and the textfield must have focus to properly handle input. |
433 widget_->Show(); | 432 widget_->Show(); |
434 textfield_->RequestFocus(); | 433 textfield_->RequestFocus(); |
435 | 434 |
436 // On Mac, activation is asynchronous since desktop widgets are used. We | 435 // On Mac, activation is asynchronous since desktop widgets are used. We |
437 // don't want parallel tests to steal active status either, so fake it. | 436 // don't want parallel tests to steal active status either, so fake it. |
438 #if defined(OS_MACOSX) && !defined(USE_AURA) | 437 #if defined(OS_MACOSX) && !defined(USE_AURA) |
439 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways(); | 438 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways(); |
440 #endif | 439 #endif |
441 | |
442 event_generator_.reset( | |
443 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow())); | |
444 } | 440 } |
445 | 441 |
446 ui::MenuModel* GetContextMenuModel() { | 442 ui::MenuModel* GetContextMenuModel() { |
447 test_api_->UpdateContextMenu(); | 443 test_api_->UpdateContextMenu(); |
448 return test_api_->context_menu_contents(); | 444 return test_api_->context_menu_contents(); |
449 } | 445 } |
450 | 446 |
451 // True if native Mac keystrokes should be used (to avoid ifdef litter). | 447 // True if native Mac keystrokes should be used (to avoid ifdef litter). |
452 bool TestingNativeMac() { | 448 bool TestingNativeMac() { |
453 #if defined(OS_MACOSX) | 449 #if defined(OS_MACOSX) |
(...skipping 15 matching lines...) Expand all Loading... | |
469 // By default, swap control and command for native events on Mac. This | 465 // By default, swap control and command for native events on Mac. This |
470 // handles most cases. | 466 // handles most cases. |
471 if (TestingNativeMac()) | 467 if (TestingNativeMac()) |
472 std::swap(control, command); | 468 std::swap(control, command); |
473 | 469 |
474 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) | | 470 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) | |
475 (control ? ui::EF_CONTROL_DOWN : 0) | | 471 (control ? ui::EF_CONTROL_DOWN : 0) | |
476 (command ? ui::EF_COMMAND_DOWN : 0) | | 472 (command ? ui::EF_COMMAND_DOWN : 0) | |
477 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); | 473 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); |
478 | 474 |
479 event_generator_->PressKey(key_code, flags); | 475 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); |
476 input_method_->DispatchKeyEvent(event); | |
sadrul
2015/07/19 01:07:30
Hm. It may not be obvious for someone unfamiliar w
Shu Chen
2015/07/20 05:46:09
I've reverted the change here and made EventGenera
Shu Chen
2015/07/21 03:05:52
Sadrul, I changed this back in the latest patchset
| |
480 } | 477 } |
481 | 478 |
482 void SendKeyEvent(ui::KeyboardCode key_code, | 479 void SendKeyEvent(ui::KeyboardCode key_code, |
483 bool shift, | 480 bool shift, |
484 bool control_or_command) { | 481 bool control_or_command) { |
485 SendKeyEvent(key_code, false, shift, control_or_command, false); | 482 SendKeyEvent(key_code, false, shift, control_or_command, false); |
486 } | 483 } |
487 | 484 |
488 void SendKeyEvent(ui::KeyboardCode key_code) { | 485 void SendKeyEvent(ui::KeyboardCode key_code) { |
489 SendKeyEvent(key_code, false, false); | 486 SendKeyEvent(key_code, false, false); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 | 637 |
641 // Indicates how many times OnBeforeUserAction() is called. | 638 // Indicates how many times OnBeforeUserAction() is called. |
642 int on_before_user_action_; | 639 int on_before_user_action_; |
643 | 640 |
644 // Indicates how many times OnAfterUserAction() is called. | 641 // Indicates how many times OnAfterUserAction() is called. |
645 int on_after_user_action_; | 642 int on_after_user_action_; |
646 | 643 |
647 private: | 644 private: |
648 ui::ClipboardType copied_to_clipboard_; | 645 ui::ClipboardType copied_to_clipboard_; |
649 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; | 646 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; |
650 scoped_ptr<ui::test::EventGenerator> event_generator_; | |
651 | 647 |
652 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); | 648 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); |
653 }; | 649 }; |
654 | 650 |
655 TEST_F(TextfieldTest, ModelChangesTest) { | 651 TEST_F(TextfieldTest, ModelChangesTest) { |
656 InitTextfield(); | 652 InitTextfield(); |
657 | 653 |
658 // TextfieldController::ContentsChanged() shouldn't be called when changing | 654 // TextfieldController::ContentsChanged() shouldn't be called when changing |
659 // text programmatically. | 655 // text programmatically. |
660 last_contents_.clear(); | 656 last_contents_.clear(); |
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2538 | 2534 |
2539 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2535 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
2540 ui::AXViewState state_protected; | 2536 ui::AXViewState state_protected; |
2541 textfield_->GetAccessibleState(&state_protected); | 2537 textfield_->GetAccessibleState(&state_protected); |
2542 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2538 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
2543 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2539 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
2544 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2540 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
2545 } | 2541 } |
2546 | 2542 |
2547 } // namespace views | 2543 } // namespace views |
OLD | NEW |