Chromium Code Reviews| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView())); | 247 internal::NativeWidgetPrivate::GetGlobalCapture(widget->GetNativeView())); |
| 248 | 248 |
| 249 // The menu should still be open. | 249 // The menu should still be open. |
| 250 TestMenuDelegate* delegate = menu_delegate(); | 250 TestMenuDelegate* delegate = menu_delegate(); |
| 251 EXPECT_TRUE(runner->IsRunning()); | 251 EXPECT_TRUE(runner->IsRunning()); |
| 252 EXPECT_EQ(0, delegate->on_menu_closed_called()); | 252 EXPECT_EQ(0, delegate->on_menu_closed_called()); |
| 253 | 253 |
| 254 widget->CloseNow(); | 254 widget->CloseNow(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Tests that after showing a menu on mouse press, that the subsequent mouse | |
| 258 // will be delivered to the correct view, and not to the one that shown the | |
|
tapted
2016/10/27 23:19:24
nit: shown -> showed (or `has shown` - English gra
themblsha
2016/10/29 13:47:19
Done.
| |
| 259 // menu. | |
| 260 // | |
| 261 // The original bug is reproducible only when showing the menu on mouse press, | |
| 262 // as RootView::OnMouseReleased() doesn't have the same behavior. | |
| 263 TEST_F(MenuRunnerTest, ClearsMouseHandlerOnRun) { | |
| 264 Widget* widget = new Widget; | |
| 265 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 266 widget->Init(params); | |
| 267 widget->Show(); | |
| 268 widget->SetSize(gfx::Size(200, 100)); | |
| 269 | |
| 270 // Create a view that will show a menu on press. | |
| 271 EventCountView* event_count_view = new EventCountView(); | |
| 272 event_count_view->SetBounds(0, 0, 100, 100); | |
| 273 widget->GetRootView()->AddChildView(event_count_view); | |
| 274 | |
| 275 InitMenuRunner(MenuRunner::ASYNC); | |
|
tapted
2016/10/27 23:19:24
I think this will make a MenuRunnerImpl on Mac, so
themblsha
2016/10/29 13:47:19
Yeah, it's non-Cocoa but tests a common code path
| |
| 276 MenuRunner* runner = menu_runner(); | |
| 277 | |
| 278 MenuLauncherEventHandler consumer(runner, widget); | |
| 279 event_count_view->AddPostTargetHandler(&consumer); | |
|
tapted
2016/10/27 23:19:24
everything above is copy-paste from WidgetDoesntTa
themblsha
2016/10/29 13:47:19
Thanks for the name :-)
| |
| 280 | |
| 281 // Create a second view that's supposed to get the second mouse press. | |
| 282 EventCountView* second_event_count_view = new EventCountView(); | |
| 283 second_event_count_view->SetBounds(100, 0, 100, 100); | |
| 284 widget->GetRootView()->AddChildView(second_event_count_view); | |
| 285 | |
| 286 // Click on the first view to show the menu. | |
| 287 std::unique_ptr<ui::test::EventGenerator> generator( | |
| 288 new ui::test::EventGenerator( | |
| 289 IsMus() ? widget->GetNativeWindow() : GetContext(), | |
| 290 widget->GetNativeWindow())); | |
| 291 generator->MoveMouseTo(gfx::Point(50, 50)); | |
| 292 generator->PressLeftButton(); | |
| 293 | |
| 294 // Pretend we dismissed the menu using normal means, as it doesn't matter. | |
| 295 EXPECT_TRUE(runner->IsRunning()); | |
| 296 runner->Cancel(); | |
| 297 | |
|
tapted
2016/10/27 23:19:24
EXPECT_FALSE(runner->IsRunning());
themblsha
2016/10/29 13:47:19
Done.
| |
| 298 // EventGenerator won't allow us to re-send the left button press without | |
| 299 // releasing it first. We can't send the release event using the same | |
| 300 // generator as it would be handled by the RootView in the main Widget. | |
| 301 // In actual application the RootView doesn't see the release event. | |
| 302 generator.reset(); | |
| 303 generator.reset(new ui::test::EventGenerator( | |
| 304 IsMus() ? widget->GetNativeWindow() : GetContext(), | |
| 305 widget->GetNativeWindow())); | |
| 306 | |
| 307 generator->MoveMouseTo(gfx::Point(150, 50)); | |
| 308 generator->PressLeftButton(); | |
| 309 EXPECT_EQ(1, second_event_count_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | |
| 310 | |
| 311 widget->CloseNow(); | |
| 312 } | |
| 313 | |
| 257 typedef MenuRunnerTest MenuRunnerImplTest; | 314 typedef MenuRunnerTest MenuRunnerImplTest; |
| 258 | 315 |
| 259 // Tests that when nested menu runners are destroyed out of order, that | 316 // Tests that when nested menu runners are destroyed out of order, that |
| 260 // MenuController is not accessed after it has been destroyed. This should not | 317 // MenuController is not accessed after it has been destroyed. This should not |
| 261 // crash on ASAN bots. | 318 // crash on ASAN bots. |
| 262 TEST_F(MenuRunnerImplTest, NestedMenuRunnersDestroyedOutOfOrder) { | 319 TEST_F(MenuRunnerImplTest, NestedMenuRunnersDestroyedOutOfOrder) { |
| 263 internal::MenuRunnerImpl* menu_runner = | 320 internal::MenuRunnerImpl* menu_runner = |
| 264 new internal::MenuRunnerImpl(menu_item_view()); | 321 new internal::MenuRunnerImpl(menu_item_view()); |
| 265 EXPECT_EQ(MenuRunner::NORMAL_EXIT, | 322 EXPECT_EQ(MenuRunner::NORMAL_EXIT, |
| 266 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), | 323 menu_runner->RunMenuAt(owner(), nullptr, gfx::Rect(), |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 285 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE, | 342 menu_runner->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE, |
| 286 nullptr, 0); | 343 nullptr, 0); |
| 287 | 344 |
| 288 // This should not access the destroyed MenuController | 345 // This should not access the destroyed MenuController |
| 289 menu_runner2->Release(); | 346 menu_runner2->Release(); |
| 290 menu_runner->Release(); | 347 menu_runner->Release(); |
| 291 } | 348 } |
| 292 | 349 |
| 293 } // namespace test | 350 } // namespace test |
| 294 } // namespace views | 351 } // namespace views |
| OLD | NEW |