Chromium Code Reviews

Side by Side Diff: views/focus/focus_manager_unittest.cc

Issue 3046041: [Linux Views] Refactor accelerator handler related code. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Prevent ctrl+alt. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "app/combobox_model.h" 7 #include "app/combobox_model.h"
8 #include "base/keyboard_codes.h" 8 #include "base/keyboard_codes.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 1467 matching lines...)
1478 } 1478 }
1479 1479
1480 private: 1480 private:
1481 bool accelerator_pressed_; 1481 bool accelerator_pressed_;
1482 std::vector<base::KeyboardCode> keys_pressed_; 1482 std::vector<base::KeyboardCode> keys_pressed_;
1483 std::vector<base::KeyboardCode> keys_released_; 1483 std::vector<base::KeyboardCode> keys_released_;
1484 1484
1485 DISALLOW_COPY_AND_ASSIGN(MessageTrackingView); 1485 DISALLOW_COPY_AND_ASSIGN(MessageTrackingView);
1486 }; 1486 };
1487 1487
1488 #if defined(OS_WIN)
1489 // This test is now Windows only. Linux Views port does not handle accelerator
1490 // keys in AcceleratorHandler anymore. The logic has been moved into
1491 // WidgetGtk::OnKeyEvent().
1488 // Tests that the keyup messages are eaten for accelerators. 1492 // Tests that the keyup messages are eaten for accelerators.
1489 TEST_F(FocusManagerTest, IgnoreKeyupForAccelerators) { 1493 TEST_F(FocusManagerTest, IgnoreKeyupForAccelerators) {
1490 FocusManager* focus_manager = GetFocusManager(); 1494 FocusManager* focus_manager = GetFocusManager();
1491 MessageTrackingView* mtv = new MessageTrackingView(); 1495 MessageTrackingView* mtv = new MessageTrackingView();
1492 mtv->AddAccelerator(Accelerator(base::VKEY_0, false, false, false)); 1496 mtv->AddAccelerator(Accelerator(base::VKEY_0, false, false, false));
1493 mtv->AddAccelerator(Accelerator(base::VKEY_1, false, false, false)); 1497 mtv->AddAccelerator(Accelerator(base::VKEY_1, false, false, false));
1494 content_view_->AddChildView(mtv); 1498 content_view_->AddChildView(mtv);
1495 focus_manager->SetFocusedView(mtv); 1499 focus_manager->SetFocusedView(mtv);
1496 1500
1497 // First send a non-accelerator key sequence. 1501 // First send a non-accelerator key sequence.
(...skipping 48 matching lines...)
1546 // Same thing with repeat and more than one key at once. 1550 // Same thing with repeat and more than one key at once.
1547 PostKeyDown(base::VKEY_0); 1551 PostKeyDown(base::VKEY_0);
1548 PostKeyDown(base::VKEY_1); 1552 PostKeyDown(base::VKEY_1);
1549 PostKeyDown(base::VKEY_1); 1553 PostKeyDown(base::VKEY_1);
1550 PostKeyDown(base::VKEY_0); 1554 PostKeyDown(base::VKEY_0);
1551 PostKeyDown(base::VKEY_0); 1555 PostKeyDown(base::VKEY_0);
1552 PostKeyUp(base::VKEY_1); 1556 PostKeyUp(base::VKEY_1);
1553 PostKeyUp(base::VKEY_0); 1557 PostKeyUp(base::VKEY_0);
1554 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 1558 MessageLoopForUI::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
1555 MessageLoopForUI::current()->Run(&accelerator_handler); 1559 MessageLoopForUI::current()->Run(&accelerator_handler);
1556 #if defined(OS_WIN)
1557 // Linux eats only last accelerator's release event.
1558 // See http://crbug.com/23383 for details.
1559 EXPECT_TRUE(mtv->keys_pressed().empty()); 1560 EXPECT_TRUE(mtv->keys_pressed().empty());
1560 EXPECT_TRUE(mtv->keys_released().empty()); 1561 EXPECT_TRUE(mtv->keys_released().empty());
1561 #endif
1562 EXPECT_TRUE(mtv->accelerator_pressed()); 1562 EXPECT_TRUE(mtv->accelerator_pressed());
1563 mtv->Reset(); 1563 mtv->Reset();
1564 } 1564 }
1565 #endif
1565 1566
1566 #if defined(OS_WIN) 1567 #if defined(OS_WIN)
1567 // Test that the focus manager is created successfully for the first view 1568 // Test that the focus manager is created successfully for the first view
1568 // window parented to a native dialog. 1569 // window parented to a native dialog.
1569 TEST_F(FocusManagerTest, CreationForNativeRoot) { 1570 TEST_F(FocusManagerTest, CreationForNativeRoot) {
1570 // Create a window class. 1571 // Create a window class.
1571 WNDCLASSEX class_ex; 1572 WNDCLASSEX class_ex;
1572 memset(&class_ex, 0, sizeof(class_ex)); 1573 memset(&class_ex, 0, sizeof(class_ex));
1573 class_ex.cbSize = sizeof(WNDCLASSEX); 1574 class_ex.cbSize = sizeof(WNDCLASSEX);
1574 class_ex.lpfnWndProc = &DefWindowProc; 1575 class_ex.lpfnWndProc = &DefWindowProc;
(...skipping 142 matching lines...)
1717 // Focus manager should be the last one to destruct. 1718 // Focus manager should be the last one to destruct.
1718 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); 1719 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str());
1719 1720
1720 // Clear window_ so that we don't try to close it again. 1721 // Clear window_ so that we don't try to close it again.
1721 window_ = NULL; 1722 window_ = NULL;
1722 } 1723 }
1723 1724
1724 #endif // defined(OS_CHROMEOS) 1725 #endif // defined(OS_CHROMEOS)
1725 1726
1726 } // namespace views 1727 } // namespace views
OLDNEW

Powered by Google App Engine