| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 owner_->Init(params); | 110 owner_->Init(params); |
| 111 owner_->Show(); | 111 owner_->Show(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void MenuRunnerTest::TearDown() { | 114 void MenuRunnerTest::TearDown() { |
| 115 owner_->CloseNow(); | 115 owner_->CloseNow(); |
| 116 ViewsTestBase::TearDown(); | 116 ViewsTestBase::TearDown(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Tests that MenuRunner is still running after the call to RunMenuAt when | 119 // Tests that MenuRunner is still running after the call to RunMenuAt when |
| 120 // initialized with MenuRunner::ASYNC, and that MenuDelegate is notified upon | 120 // initialized with , and that MenuDelegate is notified upon |
| 121 // the closing of the menu. | 121 // the closing of the menu. |
| 122 TEST_F(MenuRunnerTest, AsynchronousRun) { | 122 TEST_F(MenuRunnerTest, AsynchronousRun) { |
| 123 InitMenuRunner(MenuRunner::ASYNC); | 123 InitMenuRunner(0); |
| 124 MenuRunner* runner = menu_runner(); | 124 MenuRunner* runner = menu_runner(); |
| 125 MenuRunner::RunResult result = runner->RunMenuAt( | 125 runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 126 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 126 ui::MENU_SOURCE_NONE); |
| 127 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | |
| 128 EXPECT_TRUE(runner->IsRunning()); | 127 EXPECT_TRUE(runner->IsRunning()); |
| 129 | 128 |
| 130 runner->Cancel(); | 129 runner->Cancel(); |
| 131 EXPECT_FALSE(runner->IsRunning()); | 130 EXPECT_FALSE(runner->IsRunning()); |
| 132 TestMenuDelegate* delegate = menu_delegate(); | 131 TestMenuDelegate* delegate = menu_delegate(); |
| 133 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 132 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 134 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); | 133 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); |
| 135 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | |
| 136 } | 134 } |
| 137 | 135 |
| 138 // Tests that when a menu is run asynchronously, key events are handled properly | 136 // Tests that when a menu is run asynchronously, key events are handled properly |
| 139 // by testing that Escape key closes the menu. | 137 // by testing that Escape key closes the menu. |
| 140 TEST_F(MenuRunnerTest, AsynchronousKeyEventHandling) { | 138 TEST_F(MenuRunnerTest, AsynchronousKeyEventHandling) { |
| 141 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 139 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
| 142 // http://crbug.com/663809. | 140 // http://crbug.com/663809. |
| 143 if (IsMus()) | 141 if (IsMus()) |
| 144 return; | 142 return; |
| 145 | 143 |
| 146 InitMenuRunner(MenuRunner::ASYNC); | 144 InitMenuRunner(0); |
| 147 MenuRunner* runner = menu_runner(); | 145 MenuRunner* runner = menu_runner(); |
| 148 MenuRunner::RunResult result = runner->RunMenuAt( | 146 runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 149 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 147 ui::MENU_SOURCE_NONE); |
| 150 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | |
| 151 EXPECT_TRUE(runner->IsRunning()); | 148 EXPECT_TRUE(runner->IsRunning()); |
| 152 | 149 |
| 153 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); | 150 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); |
| 154 generator.PressKey(ui::VKEY_ESCAPE, 0); | 151 generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 155 EXPECT_FALSE(runner->IsRunning()); | 152 EXPECT_FALSE(runner->IsRunning()); |
| 156 TestMenuDelegate* delegate = menu_delegate(); | 153 TestMenuDelegate* delegate = menu_delegate(); |
| 157 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 154 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 158 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); | 155 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); |
| 159 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | |
| 160 } | 156 } |
| 161 | 157 |
| 162 // Tests that a key press on a US keyboard layout activates the correct menu | 158 // Tests that a key press on a US keyboard layout activates the correct menu |
| 163 // item. | 159 // item. |
| 164 TEST_F(MenuRunnerTest, LatinMnemonic) { | 160 TEST_F(MenuRunnerTest, LatinMnemonic) { |
| 165 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 161 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
| 166 // http://crbug.com/663809. | 162 // http://crbug.com/663809. |
| 167 if (IsMus()) | 163 if (IsMus()) |
| 168 return; | 164 return; |
| 169 | 165 |
| 170 InitMenuRunner(MenuRunner::ASYNC); | 166 InitMenuRunner(0); |
| 171 MenuRunner* runner = menu_runner(); | 167 MenuRunner* runner = menu_runner(); |
| 172 MenuRunner::RunResult result = runner->RunMenuAt( | 168 runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 173 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 169 ui::MENU_SOURCE_NONE); |
| 174 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | |
| 175 EXPECT_TRUE(runner->IsRunning()); | 170 EXPECT_TRUE(runner->IsRunning()); |
| 176 | 171 |
| 177 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); | 172 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); |
| 178 generator.PressKey(ui::VKEY_O, 0); | 173 generator.PressKey(ui::VKEY_O, 0); |
| 179 EXPECT_FALSE(runner->IsRunning()); | 174 EXPECT_FALSE(runner->IsRunning()); |
| 180 TestMenuDelegate* delegate = menu_delegate(); | 175 TestMenuDelegate* delegate = menu_delegate(); |
| 181 EXPECT_EQ(1, delegate->execute_command_id()); | 176 EXPECT_EQ(1, delegate->execute_command_id()); |
| 182 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 177 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 183 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); | 178 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); |
| 184 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | |
| 185 } | 179 } |
| 186 | 180 |
| 187 // Tests that a key press on a non-US keyboard layout activates the correct menu | 181 // Tests that a key press on a non-US keyboard layout activates the correct menu |
| 188 // item. | 182 // item. |
| 189 TEST_F(MenuRunnerTest, NonLatinMnemonic) { | 183 TEST_F(MenuRunnerTest, NonLatinMnemonic) { |
| 190 // TODO: test uses GetContext(), which is not applicable to aura-mus. | 184 // TODO: test uses GetContext(), which is not applicable to aura-mus. |
| 191 // http://crbug.com/663809. | 185 // http://crbug.com/663809. |
| 192 if (IsMus()) | 186 if (IsMus()) |
| 193 return; | 187 return; |
| 194 | 188 |
| 195 InitMenuRunner(MenuRunner::ASYNC); | 189 InitMenuRunner(0); |
| 196 MenuRunner* runner = menu_runner(); | 190 MenuRunner* runner = menu_runner(); |
| 197 MenuRunner::RunResult result = runner->RunMenuAt( | 191 runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 198 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 192 ui::MENU_SOURCE_NONE); |
| 199 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | |
| 200 EXPECT_TRUE(runner->IsRunning()); | 193 EXPECT_TRUE(runner->IsRunning()); |
| 201 | 194 |
| 202 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); | 195 ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow()); |
| 203 ui::KeyEvent key_press(0x062f, ui::VKEY_N, 0); | 196 ui::KeyEvent key_press(0x062f, ui::VKEY_N, 0); |
| 204 generator.Dispatch(&key_press); | 197 generator.Dispatch(&key_press); |
| 205 EXPECT_FALSE(runner->IsRunning()); | 198 EXPECT_FALSE(runner->IsRunning()); |
| 206 TestMenuDelegate* delegate = menu_delegate(); | 199 TestMenuDelegate* delegate = menu_delegate(); |
| 207 EXPECT_EQ(2, delegate->execute_command_id()); | 200 EXPECT_EQ(2, delegate->execute_command_id()); |
| 208 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 201 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 209 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); | 202 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); |
| 210 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | |
| 211 } | 203 } |
| 212 | 204 |
| 213 // Tests that attempting to nest a menu within a drag-and-drop menu does not | 205 // Tests that attempting to nest a menu within a drag-and-drop menu does not |
| 214 // cause a crash. Instead the drag and drop action should be canceled, and the | 206 // cause a crash. Instead the drag and drop action should be canceled, and the |
| 215 // new menu should be openned. | 207 // new menu should be openned. |
| 216 TEST_F(MenuRunnerTest, NestingDuringDrag) { | 208 TEST_F(MenuRunnerTest, NestingDuringDrag) { |
| 217 InitMenuRunner(MenuRunner::FOR_DROP); | 209 InitMenuRunner(MenuRunner::FOR_DROP); |
| 218 MenuRunner* runner = menu_runner(); | 210 MenuRunner* runner = menu_runner(); |
| 219 MenuRunner::RunResult result = runner->RunMenuAt( | 211 runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 220 owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 212 ui::MENU_SOURCE_NONE); |
| 221 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | |
| 222 EXPECT_TRUE(runner->IsRunning()); | 213 EXPECT_TRUE(runner->IsRunning()); |
| 223 | 214 |
| 224 std::unique_ptr<TestMenuDelegate> nested_delegate(new TestMenuDelegate); | 215 std::unique_ptr<TestMenuDelegate> nested_delegate(new TestMenuDelegate); |
| 225 MenuItemView* nested_menu = new MenuItemView(nested_delegate.get()); | 216 MenuItemView* nested_menu = new MenuItemView(nested_delegate.get()); |
| 226 std::unique_ptr<MenuRunner> nested_runner( | 217 std::unique_ptr<MenuRunner> nested_runner( |
| 227 new MenuRunner(nested_menu, MenuRunner::IS_NESTED | MenuRunner::ASYNC)); | 218 new MenuRunner(nested_menu, MenuRunner::IS_NESTED)); |
| 228 result = nested_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), | 219 nested_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 229 MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); | 220 ui::MENU_SOURCE_NONE); |
| 230 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | |
| 231 EXPECT_TRUE(nested_runner->IsRunning()); | 221 EXPECT_TRUE(nested_runner->IsRunning()); |
| 232 EXPECT_FALSE(runner->IsRunning()); | 222 EXPECT_FALSE(runner->IsRunning()); |
| 233 TestMenuDelegate* delegate = menu_delegate(); | 223 TestMenuDelegate* delegate = menu_delegate(); |
| 234 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 224 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
| 235 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); | 225 EXPECT_NE(nullptr, delegate->on_menu_closed_menu()); |
| 236 EXPECT_EQ(MenuRunner::NORMAL_EXIT, delegate->on_menu_closed_run_result()); | |
| 237 } | 226 } |
| 238 | 227 |
| 239 namespace { | 228 namespace { |
| 240 | 229 |
| 241 // An EventHandler that launches a menu in response to a mouse press. | 230 // An EventHandler that launches a menu in response to a mouse press. |
| 242 class MenuLauncherEventHandler : public ui::EventHandler { | 231 class MenuLauncherEventHandler : public ui::EventHandler { |
| 243 public: | 232 public: |
| 244 MenuLauncherEventHandler(MenuRunner* runner, Widget* owner) | 233 MenuLauncherEventHandler(MenuRunner* runner, Widget* owner) |
| 245 : runner_(runner), owner_(owner) {} | 234 : runner_(runner), owner_(owner) {} |
| 246 ~MenuLauncherEventHandler() override {} | 235 ~MenuLauncherEventHandler() override {} |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 widget_ = new Widget; | 279 widget_ = new Widget; |
| 291 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 280 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 292 widget_->Init(params); | 281 widget_->Init(params); |
| 293 widget_->Show(); | 282 widget_->Show(); |
| 294 widget_->SetSize(gfx::Size(300, 300)); | 283 widget_->SetSize(gfx::Size(300, 300)); |
| 295 | 284 |
| 296 event_count_view_ = new EventCountView(); | 285 event_count_view_ = new EventCountView(); |
| 297 event_count_view_->SetBounds(0, 0, 300, 300); | 286 event_count_view_->SetBounds(0, 0, 300, 300); |
| 298 widget_->GetRootView()->AddChildView(event_count_view_); | 287 widget_->GetRootView()->AddChildView(event_count_view_); |
| 299 | 288 |
| 300 InitMenuRunner(MenuRunner::ASYNC); | 289 InitMenuRunner(0); |
| 301 } | 290 } |
| 302 | 291 |
| 303 void TearDown() override { | 292 void TearDown() override { |
| 304 widget_->CloseNow(); | 293 widget_->CloseNow(); |
| 305 MenuRunnerTest::TearDown(); | 294 MenuRunnerTest::TearDown(); |
| 306 } | 295 } |
| 307 | 296 |
| 308 private: | 297 private: |
| 309 Widget* widget_ = nullptr; | 298 Widget* widget_ = nullptr; |
| 310 EventCountView* event_count_view_ = nullptr; | 299 EventCountView* event_count_view_ = nullptr; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 362 } |
| 374 | 363 |
| 375 typedef MenuRunnerTest MenuRunnerImplTest; | 364 typedef MenuRunnerTest MenuRunnerImplTest; |
| 376 | 365 |
| 377 // Tests that when nested menu runners are destroyed out of order, that | 366 // Tests that when nested menu runners are destroyed out of order, that |
| 378 // MenuController is not accessed after it has been destroyed. This should not | 367 // MenuController is not accessed after it has been destroyed. This should not |
| 379 // crash on ASAN bots. | 368 // crash on ASAN bots. |
| 380 TEST_F(MenuRunnerImplTest, NestedMenuRunnersDestroyedOutOfOrder) { | 369 TEST_F(MenuRunnerImplTest, NestedMenuRunnersDestroyedOutOfOrder) { |
| 381 internal::MenuRunnerImpl* menu_runner = | 370 internal::MenuRunnerImpl* menu_runner = |
| 382 new internal::MenuRunnerImpl(menu_item_view()); | 371 new internal::MenuRunnerImpl(menu_item_view()); |
| 383 EXPECT_EQ(MenuRunner::NORMAL_EXIT, | 372 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, 0); |
| 384 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), | |
| 385 MENU_ANCHOR_TOPLEFT, MenuRunner::ASYNC)); | |
| 386 | 373 |
| 387 std::unique_ptr<TestMenuDelegate> menu_delegate2(new TestMenuDelegate); | 374 std::unique_ptr<TestMenuDelegate> menu_delegate2(new TestMenuDelegate); |
| 388 MenuItemView* menu_item_view2 = new MenuItemView(menu_delegate2.get()); | 375 MenuItemView* menu_item_view2 = new MenuItemView(menu_delegate2.get()); |
| 389 menu_item_view2->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One")); | 376 menu_item_view2->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One")); |
| 390 | 377 |
| 391 internal::MenuRunnerImpl* menu_runner2 = | 378 internal::MenuRunnerImpl* menu_runner2 = |
| 392 new internal::MenuRunnerImpl(menu_item_view2); | 379 new internal::MenuRunnerImpl(menu_item_view2); |
| 393 EXPECT_EQ(MenuRunner::NORMAL_EXIT, | 380 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 394 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(), | 381 MenuRunner::IS_NESTED); |
| 395 MENU_ANCHOR_TOPLEFT, | |
| 396 MenuRunner::ASYNC | MenuRunner::IS_NESTED)); | |
| 397 | 382 |
| 398 // Hide the controller so we can test out of order destruction. | 383 // Hide the controller so we can test out of order destruction. |
| 399 MenuControllerTestApi menu_controller; | 384 MenuControllerTestApi menu_controller; |
| 400 menu_controller.SetShowing(false); | 385 menu_controller.SetShowing(false); |
| 401 | 386 |
| 402 // This destroyed MenuController | 387 // This destroyed MenuController |
| 403 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE, | 388 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE, |
| 404 nullptr, 0); | 389 nullptr, 0); |
| 405 | 390 |
| 406 // This should not access the destroyed MenuController | 391 // This should not access the destroyed MenuController |
| 407 menu_runner2->Release(); | 392 menu_runner2->Release(); |
| 408 menu_runner->Release(); | 393 menu_runner->Release(); |
| 409 } | 394 } |
| 410 | 395 |
| 411 // Tests that when there are two separate MenuControllers, and the active one is | 396 // Tests that when there are two separate MenuControllers, and the active one is |
| 412 // deleted first, that shutting down the MenuRunner of the original | 397 // deleted first, that shutting down the MenuRunner of the original |
| 413 // MenuController properly closes its controller. This should not crash on ASAN | 398 // MenuController properly closes its controller. This should not crash on ASAN |
| 414 // bots. | 399 // bots. |
| 415 TEST_F(MenuRunnerImplTest, MenuRunnerDestroyedWithNoActiveController) { | 400 TEST_F(MenuRunnerImplTest, MenuRunnerDestroyedWithNoActiveController) { |
| 416 internal::MenuRunnerImpl* menu_runner = | 401 internal::MenuRunnerImpl* menu_runner = |
| 417 new internal::MenuRunnerImpl(menu_item_view()); | 402 new internal::MenuRunnerImpl(menu_item_view()); |
| 418 EXPECT_EQ(MenuRunner::NORMAL_EXIT, | 403 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, 0); |
| 419 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), | |
| 420 MENU_ANCHOR_TOPLEFT, MenuRunner::ASYNC)); | |
| 421 | 404 |
| 422 // Hide the menu, and clear its item selection state. | 405 // Hide the menu, and clear its item selection state. |
| 423 MenuControllerTestApi menu_controller; | 406 MenuControllerTestApi menu_controller; |
| 424 menu_controller.SetShowing(false); | 407 menu_controller.SetShowing(false); |
| 425 menu_controller.ClearState(); | 408 menu_controller.ClearState(); |
| 426 | 409 |
| 427 std::unique_ptr<TestMenuDelegate> menu_delegate2(new TestMenuDelegate); | 410 std::unique_ptr<TestMenuDelegate> menu_delegate2(new TestMenuDelegate); |
| 428 MenuItemView* menu_item_view2 = new MenuItemView(menu_delegate2.get()); | 411 MenuItemView* menu_item_view2 = new MenuItemView(menu_delegate2.get()); |
| 429 menu_item_view2->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One")); | 412 menu_item_view2->AppendMenuItemWithLabel(1, base::ASCIIToUTF16("One")); |
| 430 | 413 |
| 431 internal::MenuRunnerImpl* menu_runner2 = | 414 internal::MenuRunnerImpl* menu_runner2 = |
| 432 new internal::MenuRunnerImpl(menu_item_view2); | 415 new internal::MenuRunnerImpl(menu_item_view2); |
| 433 EXPECT_EQ(MenuRunner::NORMAL_EXIT, | 416 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 434 menu_runner2->RunMenuAt(owner(), nullptr, gfx::Rect(), | 417 MenuRunner::FOR_DROP); |
| 435 MENU_ANCHOR_TOPLEFT, | |
| 436 MenuRunner::ASYNC | MenuRunner::FOR_DROP)); | |
| 437 | 418 |
| 438 EXPECT_NE(menu_controller.controller(), MenuController::GetActiveInstance()); | 419 EXPECT_NE(menu_controller.controller(), MenuController::GetActiveInstance()); |
| 439 menu_controller.SetShowing(true); | 420 menu_controller.SetShowing(true); |
| 440 | 421 |
| 441 // Close the runner with the active menu first. | 422 // Close the runner with the active menu first. |
| 442 menu_runner2->Release(); | 423 menu_runner2->Release(); |
| 443 // Even though there is no active menu, this should still cleanup the | 424 // Even though there is no active menu, this should still cleanup the |
| 444 // controller that it created. | 425 // controller that it created. |
| 445 menu_runner->Release(); | 426 menu_runner->Release(); |
| 446 | 427 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 views_delegate_ = views_delegate.get(); | 466 views_delegate_ = views_delegate.get(); |
| 486 set_views_delegate(std::move(views_delegate)); | 467 set_views_delegate(std::move(views_delegate)); |
| 487 MenuRunnerTest::SetUp(); | 468 MenuRunnerTest::SetUp(); |
| 488 } | 469 } |
| 489 | 470 |
| 490 // Tests that when ViewsDelegate is released that a nested Cancel of the | 471 // Tests that when ViewsDelegate is released that a nested Cancel of the |
| 491 // MenuRunner does not occur. | 472 // MenuRunner does not occur. |
| 492 TEST_F(MenuRunnerDestructionTest, MenuRunnerDestroyedDuringReleaseRef) { | 473 TEST_F(MenuRunnerDestructionTest, MenuRunnerDestroyedDuringReleaseRef) { |
| 493 internal::MenuRunnerImpl* menu_runner = | 474 internal::MenuRunnerImpl* menu_runner = |
| 494 new internal::MenuRunnerImpl(menu_item_view()); | 475 new internal::MenuRunnerImpl(menu_item_view()); |
| 495 EXPECT_EQ(MenuRunner::NORMAL_EXIT, | 476 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MENU_ANCHOR_TOPLEFT, 0); |
| 496 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), | |
| 497 MENU_ANCHOR_TOPLEFT, MenuRunner::ASYNC)); | |
| 498 | 477 |
| 499 views_delegate()->set_menu_runner(menu_runner); | 478 views_delegate()->set_menu_runner(menu_runner); |
| 500 | 479 |
| 501 base::WeakPtr<internal::MenuRunnerImpl> ref(MenuRunnerAsWeakPtr(menu_runner)); | 480 base::WeakPtr<internal::MenuRunnerImpl> ref(MenuRunnerAsWeakPtr(menu_runner)); |
| 502 MenuControllerTestApi menu_controller; | 481 MenuControllerTestApi menu_controller; |
| 503 // This will release the ref on ViewsDelegate. The test version will release | 482 // This will release the ref on ViewsDelegate. The test version will release |
| 504 // |menu_runner| simulating device shutdown. | 483 // |menu_runner| simulating device shutdown. |
| 505 menu_controller.controller()->CancelAll(); | 484 menu_controller.controller()->CancelAll(); |
| 506 // Both the |menu_runner| and |menu_controller| should have been deleted. | 485 // Both the |menu_runner| and |menu_controller| should have been deleted. |
| 507 EXPECT_EQ(nullptr, ref); | 486 EXPECT_EQ(nullptr, ref); |
| 508 EXPECT_EQ(nullptr, menu_controller.controller()); | 487 EXPECT_EQ(nullptr, menu_controller.controller()); |
| 509 } | 488 } |
| 510 | 489 |
| 511 } // namespace test | 490 } // namespace test |
| 512 } // namespace views | 491 } // namespace views |
| OLD | NEW |