| 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 TEST_F(FocusManagerTest, SuspendAccelerators) { |
| 473 const ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); |
| 474 ui::Accelerator accelerator(event.key_code(), event.flags()); |
| 475 TestAcceleratorTarget target(true); |
| 476 FocusManager* focus_manager = GetFocusManager(); |
| 477 focus_manager->RegisterAccelerator(accelerator, |
| 478 ui::AcceleratorManager::kNormalPriority, |
| 479 &target); |
| 480 |
| 481 focus_manager->set_shortcut_handling_suspended(true); |
| 482 EXPECT_TRUE(focus_manager->OnKeyEvent(event)); |
| 483 EXPECT_EQ(0, target.accelerator_count()); |
| 484 |
| 485 focus_manager->set_shortcut_handling_suspended(false); |
| 486 EXPECT_FALSE(focus_manager->OnKeyEvent(event)); |
| 487 EXPECT_EQ(1, target.accelerator_count()); |
| 488 } |
| 489 |
| 472 class FocusManagerDtorTest : public FocusManagerTest { | 490 class FocusManagerDtorTest : public FocusManagerTest { |
| 473 protected: | 491 protected: |
| 474 typedef std::vector<std::string> DtorTrackVector; | 492 typedef std::vector<std::string> DtorTrackVector; |
| 475 | 493 |
| 476 class FocusManagerDtorTracked : public FocusManager { | 494 class FocusManagerDtorTracked : public FocusManager { |
| 477 public: | 495 public: |
| 478 FocusManagerDtorTracked(Widget* widget, DtorTrackVector* dtor_tracker) | 496 FocusManagerDtorTracked(Widget* widget, DtorTrackVector* dtor_tracker) |
| 479 : FocusManager(widget, NULL /* delegate */), | 497 : FocusManager(widget, NULL /* delegate */), |
| 480 dtor_tracker_(dtor_tracker) { | 498 dtor_tracker_(dtor_tracker) { |
| 481 } | 499 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 927 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 910 | 928 |
| 911 // Allow focus to go to the parent, and focus backwards which should now move | 929 // Allow focus to go to the parent, and focus backwards which should now move |
| 912 // up |widget_view| (in the parent). | 930 // up |widget_view| (in the parent). |
| 913 delegate->set_should_advance_focus_to_parent(true); | 931 delegate->set_should_advance_focus_to_parent(true); |
| 914 GetFocusManager()->AdvanceFocus(true); | 932 GetFocusManager()->AdvanceFocus(true); |
| 915 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 933 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
| 916 } | 934 } |
| 917 | 935 |
| 918 } // namespace views | 936 } // namespace views |
| OLD | NEW |