OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/combobox/combobox.h" | 5 #include "ui/views/controls/combobox/combobox.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "ui/accessibility/ax_action_data.h" |
12 #include "ui/base/ime/input_method.h" | 13 #include "ui/base/ime/input_method.h" |
13 #include "ui/base/ime/text_input_client.h" | 14 #include "ui/base/ime/text_input_client.h" |
14 #include "ui/base/models/combobox_model.h" | 15 #include "ui/base/models/combobox_model.h" |
15 #include "ui/base/models/menu_model.h" | 16 #include "ui/base/models/menu_model.h" |
16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
17 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
18 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
19 #include "ui/events/keycodes/dom/dom_code.h" | 20 #include "ui/events/keycodes/dom/dom_code.h" |
20 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
21 #include "ui/events/test/event_generator.h" | 22 #include "ui/events/test/event_generator.h" |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. | 636 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. |
636 PressKey(ui::VKEY_SPACE); | 637 PressKey(ui::VKEY_SPACE); |
637 EXPECT_EQ(1, menu_show_count_); | 638 EXPECT_EQ(1, menu_show_count_); |
638 EXPECT_FALSE(listener.on_perform_action_called()); | 639 EXPECT_FALSE(listener.on_perform_action_called()); |
639 | 640 |
640 ReleaseKey(ui::VKEY_SPACE); | 641 ReleaseKey(ui::VKEY_SPACE); |
641 EXPECT_EQ(1, menu_show_count_); | 642 EXPECT_EQ(1, menu_show_count_); |
642 EXPECT_FALSE(listener.on_perform_action_called()); | 643 EXPECT_FALSE(listener.on_perform_action_called()); |
643 } | 644 } |
644 | 645 |
| 646 // Test that accessibility action events show the combobox dropdown. |
| 647 TEST_F(ComboboxTest, ShowViaAccessibleAction) { |
| 648 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 649 |
| 650 ui::AXActionData data; |
| 651 data.action = ui::AX_ACTION_DO_DEFAULT; |
| 652 combobox_->HandleAccessibleAction(data); |
| 653 EXPECT_EQ(1, menu_show_count_); |
| 654 |
| 655 combobox_->SetEnabled(false); |
| 656 combobox_->HandleAccessibleAction(data); |
| 657 EXPECT_EQ(1, menu_show_count_); // No change. |
| 658 |
| 659 combobox_->SetEnabled(true); |
| 660 data.action = ui::AX_ACTION_SHOW_CONTEXT_MENU; |
| 661 combobox_->HandleAccessibleAction(data); |
| 662 EXPECT_EQ(2, menu_show_count_); |
| 663 |
| 664 data.action = ui::AX_ACTION_BLUR; |
| 665 combobox_->HandleAccessibleAction(data); |
| 666 EXPECT_EQ(2, menu_show_count_); // No change. |
| 667 } |
| 668 |
645 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { | 669 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { |
646 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 670 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
647 | 671 |
648 TestComboboxListener listener; | 672 TestComboboxListener listener; |
649 combobox_->set_listener(&listener); | 673 combobox_->set_listener(&listener); |
650 | 674 |
651 // With STYLE_ACTION, the click event is notified after releasing and the menu | 675 // With STYLE_ACTION, the click event is notified after releasing and the menu |
652 // is not shown. On Mac, the menu should be shown. | 676 // is not shown. On Mac, the menu should be shown. |
653 PressKey(ui::VKEY_SPACE); | 677 PressKey(ui::VKEY_SPACE); |
654 #if defined(OS_MACOSX) | 678 #if defined(OS_MACOSX) |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); | 940 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
917 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 941 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
918 | 942 |
919 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 943 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
920 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 944 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
921 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 945 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
922 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 946 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
923 } | 947 } |
924 | 948 |
925 } // namespace views | 949 } // namespace views |
OLD | NEW |