| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_runner.h" | 5 #include "ui/views/controls/menu/menu_runner.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 101 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 102 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); | 102 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); |
| 103 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | 103 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Tests that when a menu is run asynchronously, key events are handled properly | 106 // Tests that when a menu is run asynchronously, key events are handled properly |
| 107 // by testing that Escape key closes the menu. | 107 // by testing that Escape key closes the menu. |
| 108 TEST_F(MenuRunnerTest, AsynchronousKeyEventHandling) { | 108 TEST_F(MenuRunnerTest, AsynchronousKeyEventHandling) { |
| 109 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 109 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
| 110 // http://crbug.com/663809. | 110 // http://crbug.com/663809. |
| 111 if (IsAuraMusClient()) | 111 if (IsMus()) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 InitMenuRunner(MenuRunner::ASYNC); | 114 InitMenuRunner(MenuRunner::ASYNC); |
| 115 MenuRunner* runner = menu_runner(); | 115 MenuRunner* runner = menu_runner(); |
| 116 MenuRunner::RunResult result = runner->RunMenuAt( | 116 MenuRunner::RunResult result = runner->RunMenuAt( |
| 117 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 117 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); |
| 118 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | 118 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); |
| 119 EXPECT_TRUE(runner->IsRunning()); | 119 EXPECT_TRUE(runner->IsRunning()); |
| 120 | 120 |
| 121 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); | 121 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); |
| 122 generator.PressKey(ui::VKEY_ESCAPE, 0); | 122 generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 123 EXPECT_FALSE(runner->IsRunning()); | 123 EXPECT_FALSE(runner->IsRunning()); |
| 124 TestMenuDelegate* delegate = menu_delegate(); | 124 TestMenuDelegate* delegate = menu_delegate(); |
| 125 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 125 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 126 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); | 126 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); |
| 127 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | 127 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Tests that a key press on a US keyboard layout activates the correct menu | 130 // Tests that a key press on a US keyboard layout activates the correct menu |
| 131 // item. | 131 // item. |
| 132 TEST_F(MenuRunnerTest, LatinMnemonic) { | 132 TEST_F(MenuRunnerTest, LatinMnemonic) { |
| 133 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 133 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
| 134 // http://crbug.com/663809. | 134 // http://crbug.com/663809. |
| 135 if (IsAuraMusClient()) | 135 if (IsMus()) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 InitMenuRunner(MenuRunner::ASYNC); | 138 InitMenuRunner(MenuRunner::ASYNC); |
| 139 MenuRunner* runner = menu_runner(); | 139 MenuRunner* runner = menu_runner(); |
| 140 MenuRunner::RunResult result = runner->RunMenuAt( | 140 MenuRunner::RunResult result = runner->RunMenuAt( |
| 141 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 141 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); |
| 142 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | 142 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); |
| 143 EXPECT_TRUE(runner->IsRunning()); | 143 EXPECT_TRUE(runner->IsRunning()); |
| 144 | 144 |
| 145 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); | 145 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); |
| 146 generator.PressKey(ui::VKEY_O, 0); | 146 generator.PressKey(ui::VKEY_O, 0); |
| 147 EXPECT_FALSE(runner->IsRunning()); | 147 EXPECT_FALSE(runner->IsRunning()); |
| 148 TestMenuDelegate* delegate = menu_delegate(); | 148 TestMenuDelegate* delegate = menu_delegate(); |
| 149 EXPECT_EQ(1, delegate->execute_command_id()); | 149 EXPECT_EQ(1, delegate->execute_command_id()); |
| 150 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 150 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 151 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); | 151 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); |
| 152 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | 152 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Tests that a key press on a non-US keyboard layout activates the correct menu | 155 // Tests that a key press on a non-US keyboard layout activates the correct menu |
| 156 // item. | 156 // item. |
| 157 TEST_F(MenuRunnerTest, NonLatinMnemonic) { | 157 TEST_F(MenuRunnerTest, NonLatinMnemonic) { |
| 158 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 158 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
| 159 // http://crbug.com/663809. | 159 // http://crbug.com/663809. |
| 160 if (IsAuraMusClient()) | 160 if (IsMus()) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 InitMenuRunner(MenuRunner::ASYNC); | 163 InitMenuRunner(MenuRunner::ASYNC); |
| 164 MenuRunner* runner = menu_runner(); | 164 MenuRunner* runner = menu_runner(); |
| 165 MenuRunner::RunResult result = runner->RunMenuAt( | 165 MenuRunner::RunResult result = runner->RunMenuAt( |
| 166 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 166 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); |
| 167 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | 167 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); |
| 168 EXPECT_TRUE(runner->IsRunning()); | 168 EXPECT_TRUE(runner->IsRunning()); |
| 169 | 169 |
| 170 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); | 170 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 class MenuRunnerWidgetTest : public MenuRunnerTest { | 235 class MenuRunnerWidgetTest : public MenuRunnerTest { |
| 236 public: | 236 public: |
| 237 MenuRunnerWidgetTest() {} | 237 MenuRunnerWidgetTest() {} |
| 238 | 238 |
| 239 Widget* widget() { return widget_; } | 239 Widget* widget() { return widget_; } |
| 240 EventCountView* event_count_view() { return event_count_view_; } | 240 EventCountView* event_count_view() { return event_count_view_; } |
| 241 | 241 |
| 242 std::unique_ptr<ui::test::EventGenerator> EventGeneratorForWidget( | 242 std::unique_ptr<ui::test::EventGenerator> EventGeneratorForWidget( |
| 243 Widget* widget) { | 243 Widget* widget) { |
| 244 return base::MakeUnique<ui::test::EventGenerator>( | 244 return base::MakeUnique<ui::test::EventGenerator>( |
| 245 IsMus() || IsAuraMusClient() ? widget->GetNativeWindow() : GetContext(), | 245 IsMus() ? widget->GetNativeWindow() : GetContext(), |
| 246 widget->GetNativeWindow()); | 246 widget->GetNativeWindow()); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void AddMenuLauncherEventHandler(Widget* widget) { | 249 void AddMenuLauncherEventHandler(Widget* widget) { |
| 250 consumer_ = | 250 consumer_ = |
| 251 base::MakeUnique<MenuLauncherEventHandler>(menu_runner(), widget); | 251 base::MakeUnique<MenuLauncherEventHandler>(menu_runner(), widget); |
| 252 event_count_view_->AddPostTargetHandler(consumer_.get()); | 252 event_count_view_->AddPostTargetHandler(consumer_.get()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // ViewsTestBase: | 255 // ViewsTestBase: |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE, | 371 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE, |
| 372 nullptr, 0); | 372 nullptr, 0); |
| 373 | 373 |
| 374 // This should not access the destroyed MenuController | 374 // This should not access the destroyed MenuController |
| 375 menu_runner2->Release(); | 375 menu_runner2->Release(); |
| 376 menu_runner->Release(); | 376 menu_runner->Release(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace test | 379 } // namespace test |
| 380 } // namespace views | 380 } // namespace views |
| OLD | NEW |