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/menu/menu_controller.h" | 5 #include "ui/views/controls/menu/menu_controller.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "ui/events/event_handler.h" | 9 #include "ui/events/event_handler.h" |
10 #include "ui/events/null_event_targeter.h" | 10 #include "ui/events/null_event_targeter.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 class TestMenuItemView : public MenuItemView { | 40 class TestMenuItemView : public MenuItemView { |
41 public: | 41 public: |
42 TestMenuItemView() : MenuItemView(nullptr) {} | 42 TestMenuItemView() : MenuItemView(nullptr) {} |
43 ~TestMenuItemView() override {} | 43 ~TestMenuItemView() override {} |
44 | 44 |
45 private: | 45 private: |
46 DISALLOW_COPY_AND_ASSIGN(TestMenuItemView); | 46 DISALLOW_COPY_AND_ASSIGN(TestMenuItemView); |
47 }; | 47 }; |
48 | 48 |
| 49 class SubmenuViewShown : public SubmenuView { |
| 50 public: |
| 51 SubmenuViewShown(MenuItemView* parent) : SubmenuView(parent) {} |
| 52 ~SubmenuViewShown() override {} |
| 53 bool IsShowing() override { return true; } |
| 54 |
| 55 private: |
| 56 DISALLOW_COPY_AND_ASSIGN(SubmenuViewShown); |
| 57 }; |
| 58 |
| 59 class TestMenuItemViewShown : public MenuItemView { |
| 60 public: |
| 61 TestMenuItemViewShown() : MenuItemView(nullptr) {} |
| 62 ~TestMenuItemViewShown() override {} |
| 63 SubmenuView* CreateSubmenu() override { return new SubmenuViewShown(this); } |
| 64 |
| 65 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(TestMenuItemViewShown); |
| 67 }; |
| 68 |
49 class TestPlatformEventSource : public ui::PlatformEventSource { | 69 class TestPlatformEventSource : public ui::PlatformEventSource { |
50 public: | 70 public: |
51 TestPlatformEventSource() { | 71 TestPlatformEventSource() { |
52 #if defined(USE_X11) | 72 #if defined(USE_X11) |
53 ui::DeviceDataManagerX11::CreateInstance(); | 73 ui::DeviceDataManagerX11::CreateInstance(); |
54 #endif | 74 #endif |
55 } | 75 } |
56 ~TestPlatformEventSource() override {} | 76 ~TestPlatformEventSource() override {} |
57 | 77 |
58 uint32_t Dispatch(const ui::PlatformEvent& event) { | 78 uint32_t Dispatch(const ui::PlatformEvent& event) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 #endif | 183 #endif |
164 return widget.Pass(); | 184 return widget.Pass(); |
165 } | 185 } |
166 | 186 |
167 const MenuItemView* pending_state_item() const { | 187 const MenuItemView* pending_state_item() const { |
168 return controller_->pending_state_.item; | 188 return controller_->pending_state_.item; |
169 } | 189 } |
170 | 190 |
171 void SetPendingStateItem(MenuItemView* item) { | 191 void SetPendingStateItem(MenuItemView* item) { |
172 controller_->pending_state_.item = item; | 192 controller_->pending_state_.item = item; |
| 193 controller_->pending_state_.submenu_open = true; |
173 } | 194 } |
174 | 195 |
175 void ResetSelection() { | 196 void ResetSelection() { |
176 controller_->SetSelection(nullptr, | 197 controller_->SetSelection(nullptr, |
177 MenuController::SELECTION_EXIT | | 198 MenuController::SELECTION_EXIT | |
178 MenuController::SELECTION_UPDATE_IMMEDIATELY); | 199 MenuController::SELECTION_UPDATE_IMMEDIATELY); |
179 } | 200 } |
180 | 201 |
181 void IncrementSelection(int delta) { | 202 void IncrementSelection(int delta) { |
182 controller_->IncrementSelection(delta); | 203 controller_->IncrementSelection(delta); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 EXPECT_EQ(2, pending_state_item()->GetCommand()); | 459 EXPECT_EQ(2, pending_state_item()->GetCommand()); |
439 | 460 |
440 // Select previous item. | 461 // Select previous item. |
441 IncrementSelection(-1); | 462 IncrementSelection(-1); |
442 EXPECT_EQ(1, pending_state_item()->GetCommand()); | 463 EXPECT_EQ(1, pending_state_item()->GetCommand()); |
443 | 464 |
444 // Clear references in menu controller to the menu item that is going away. | 465 // Clear references in menu controller to the menu item that is going away. |
445 ResetSelection(); | 466 ResetSelection(); |
446 } | 467 } |
447 | 468 |
| 469 TEST_F(MenuControllerTest, NextSelectedItemUp) { |
| 470 scoped_ptr<Widget> owner(CreateOwnerWidget()); |
| 471 scoped_ptr<TestMenuItemViewShown> menu_item(new TestMenuItemViewShown); |
| 472 menu_item->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One")); |
| 473 menu_item->AppendMenuItemWithLabel(2, base::ASCIIToUTF16("Two")); |
| 474 menu_item->AppendMenuItemWithLabel(3, base::ASCIIToUTF16("Three")); |
| 475 menu_item->AppendMenuItemWithLabel(4, base::ASCIIToUTF16("Four")); |
| 476 // Disabling the item "Four" gets it skipped when using keyboard to navigate. |
| 477 menu_item->GetSubmenu()->GetMenuItemAt(3)->SetEnabled(false); |
| 478 |
| 479 SetupMenu(owner.get(), menu_item.get()); |
| 480 |
| 481 // Fake initial root item selection and submenu showing. |
| 482 SetPendingStateItem(menu_item.get()); |
| 483 EXPECT_EQ(0, pending_state_item()->GetCommand()); |
| 484 |
| 485 // Move up and select a previous (in our case the last enabled) item. |
| 486 IncrementSelection(-1); |
| 487 EXPECT_EQ(3, pending_state_item()->GetCommand()); |
| 488 } |
| 489 |
448 } // namespace views | 490 } // namespace views |
OLD | NEW |