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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the | 425 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the |
427 // widget and the textfield must have focus to properly handle input. | 426 // widget and the textfield must have focus to properly handle input. |
428 widget_->Show(); | 427 widget_->Show(); |
429 textfield_->RequestFocus(); | 428 textfield_->RequestFocus(); |
430 | 429 |
431 // On Mac, activation is asynchronous since desktop widgets are used. We | 430 // On Mac, activation is asynchronous since desktop widgets are used. We |
432 // don't want parallel tests to steal active status either, so fake it. | 431 // don't want parallel tests to steal active status either, so fake it. |
433 #if defined(OS_MACOSX) && !defined(USE_AURA) | 432 #if defined(OS_MACOSX) && !defined(USE_AURA) |
434 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways(); | 433 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways(); |
435 #endif | 434 #endif |
436 | |
437 event_generator_.reset( | |
438 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow())); | |
439 } | 435 } |
440 | 436 |
441 ui::MenuModel* GetContextMenuModel() { | 437 ui::MenuModel* GetContextMenuModel() { |
442 test_api_->UpdateContextMenu(); | 438 test_api_->UpdateContextMenu(); |
443 return test_api_->context_menu_contents(); | 439 return test_api_->context_menu_contents(); |
444 } | 440 } |
445 | 441 |
446 // True if native Mac keystrokes should be used (to avoid ifdef litter). | 442 // True if native Mac keystrokes should be used (to avoid ifdef litter). |
447 bool TestingNativeMac() { | 443 bool TestingNativeMac() { |
448 #if defined(OS_MACOSX) | 444 #if defined(OS_MACOSX) |
(...skipping 15 matching lines...) Expand all Loading... |
464 // By default, swap control and command for native events on Mac. This | 460 // By default, swap control and command for native events on Mac. This |
465 // handles most cases. | 461 // handles most cases. |
466 if (TestingNativeMac()) | 462 if (TestingNativeMac()) |
467 std::swap(control, command); | 463 std::swap(control, command); |
468 | 464 |
469 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) | | 465 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) | |
470 (control ? ui::EF_CONTROL_DOWN : 0) | | 466 (control ? ui::EF_CONTROL_DOWN : 0) | |
471 (command ? ui::EF_COMMAND_DOWN : 0) | | 467 (command ? ui::EF_COMMAND_DOWN : 0) | |
472 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); | 468 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); |
473 | 469 |
474 event_generator_->PressKey(key_code, flags); | 470 // TODO(shuchen): making EventGenerator support input method and using |
| 471 // EventGenerator here. crbug.com/512315. |
| 472 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); |
| 473 input_method_->DispatchKeyEvent(event); |
475 } | 474 } |
476 | 475 |
477 void SendKeyEvent(ui::KeyboardCode key_code, | 476 void SendKeyEvent(ui::KeyboardCode key_code, |
478 bool shift, | 477 bool shift, |
479 bool control_or_command) { | 478 bool control_or_command) { |
480 SendKeyEvent(key_code, false, shift, control_or_command, false); | 479 SendKeyEvent(key_code, false, shift, control_or_command, false); |
481 } | 480 } |
482 | 481 |
483 void SendKeyEvent(ui::KeyboardCode key_code) { | 482 void SendKeyEvent(ui::KeyboardCode key_code) { |
484 SendKeyEvent(key_code, false, false); | 483 SendKeyEvent(key_code, false, false); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 634 |
636 // Indicates how many times OnBeforeUserAction() is called. | 635 // Indicates how many times OnBeforeUserAction() is called. |
637 int on_before_user_action_; | 636 int on_before_user_action_; |
638 | 637 |
639 // Indicates how many times OnAfterUserAction() is called. | 638 // Indicates how many times OnAfterUserAction() is called. |
640 int on_after_user_action_; | 639 int on_after_user_action_; |
641 | 640 |
642 private: | 641 private: |
643 ui::ClipboardType copied_to_clipboard_; | 642 ui::ClipboardType copied_to_clipboard_; |
644 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; | 643 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; |
645 scoped_ptr<ui::test::EventGenerator> event_generator_; | |
646 | 644 |
647 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); | 645 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); |
648 }; | 646 }; |
649 | 647 |
650 TEST_F(TextfieldTest, ModelChangesTest) { | 648 TEST_F(TextfieldTest, ModelChangesTest) { |
651 InitTextfield(); | 649 InitTextfield(); |
652 | 650 |
653 // TextfieldController::ContentsChanged() shouldn't be called when changing | 651 // TextfieldController::ContentsChanged() shouldn't be called when changing |
654 // text programmatically. | 652 // text programmatically. |
655 last_contents_.clear(); | 653 last_contents_.clear(); |
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2533 | 2531 |
2534 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2532 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
2535 ui::AXViewState state_protected; | 2533 ui::AXViewState state_protected; |
2536 textfield_->GetAccessibleState(&state_protected); | 2534 textfield_->GetAccessibleState(&state_protected); |
2537 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2535 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
2538 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2536 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
2539 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2537 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
2540 } | 2538 } |
2541 | 2539 |
2542 } // namespace views | 2540 } // namespace views |
OLD | NEW |