| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/focus/focus_manager.h" | 5 #include "ui/views/focus/focus_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); | 462 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 463 EXPECT_EQ(target.accelerator_count(), 1); | 463 EXPECT_EQ(target.accelerator_count(), 1); |
| 464 EXPECT_EQ(NULL, | 464 EXPECT_EQ(NULL, |
| 465 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); | 465 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); |
| 466 | 466 |
| 467 // Hitting the return key again; nothing should happen. | 467 // Hitting the return key again; nothing should happen. |
| 468 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | 468 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 469 EXPECT_EQ(target.accelerator_count(), 1); | 469 EXPECT_EQ(target.accelerator_count(), 1); |
| 470 } | 470 } |
| 471 | 471 |
| 472 static bool SuspendAcceleratorsCallback(bool input) { |
| 473 return input; |
| 474 } |
| 475 |
| 476 TEST_F(FocusManagerTest, SuspendAccelerators) { |
| 477 const ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); |
| 478 ui::Accelerator accelerator(event.key_code(), event.flags()); |
| 479 TestAcceleratorTarget target(true); |
| 480 FocusManager* focus_manager = GetFocusManager(); |
| 481 focus_manager->RegisterAccelerator(accelerator, |
| 482 ui::AcceleratorManager::kNormalPriority, |
| 483 &target); |
| 484 |
| 485 // Callback returns true, should not process accelerators. |
| 486 base::Callback<bool()> callback = |
| 487 base::Bind(&SuspendAcceleratorsCallback, true); |
| 488 focus_manager->set_shortcut_handling_suspended_callback(&callback); |
| 489 EXPECT_TRUE(focus_manager->OnKeyEvent(event)); |
| 490 EXPECT_EQ(0, target.accelerator_count()); |
| 491 |
| 492 // Callback returns false, should process accelerators. |
| 493 callback = base::Bind(&SuspendAcceleratorsCallback, false); |
| 494 focus_manager->set_shortcut_handling_suspended_callback(&callback); |
| 495 EXPECT_FALSE(focus_manager->OnKeyEvent(event)); |
| 496 EXPECT_EQ(1, target.accelerator_count()); |
| 497 |
| 498 // Uninstall callback, should process accelerators. |
| 499 focus_manager->set_shortcut_handling_suspended_callback(nullptr); |
| 500 EXPECT_FALSE(focus_manager->OnKeyEvent(event)); |
| 501 EXPECT_EQ(2, target.accelerator_count()); |
| 502 } |
| 503 |
| 472 class FocusManagerDtorTest : public FocusManagerTest { | 504 class FocusManagerDtorTest : public FocusManagerTest { |
| 473 protected: | 505 protected: |
| 474 typedef std::vector<std::string> DtorTrackVector; | 506 typedef std::vector<std::string> DtorTrackVector; |
| 475 | 507 |
| 476 class FocusManagerDtorTracked : public FocusManager { | 508 class FocusManagerDtorTracked : public FocusManager { |
| 477 public: | 509 public: |
| 478 FocusManagerDtorTracked(Widget* widget, DtorTrackVector* dtor_tracker) | 510 FocusManagerDtorTracked(Widget* widget, DtorTrackVector* dtor_tracker) |
| 479 : FocusManager(widget, NULL /* delegate */), | 511 : FocusManager(widget, NULL /* delegate */), |
| 480 dtor_tracker_(dtor_tracker) { | 512 dtor_tracker_(dtor_tracker) { |
| 481 } | 513 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 941 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 910 | 942 |
| 911 // Allow focus to go to the parent, and focus backwards which should now move | 943 // Allow focus to go to the parent, and focus backwards which should now move |
| 912 // up |widget_view| (in the parent). | 944 // up |widget_view| (in the parent). |
| 913 delegate->set_should_advance_focus_to_parent(true); | 945 delegate->set_should_advance_focus_to_parent(true); |
| 914 GetFocusManager()->AdvanceFocus(true); | 946 GetFocusManager()->AdvanceFocus(true); |
| 915 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 947 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
| 916 } | 948 } |
| 917 | 949 |
| 918 } // namespace views | 950 } // namespace views |
| OLD | NEW |