Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: ash/accelerators/accelerator_controller_unittest.cc

Issue 1177773002: Deprecating high-conflict accelerators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moving IsDeprecated() to c/b/ui/ash Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ash/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 6
7 #include "ash/accelerators/accelerator_table.h" 7 #include "ash/accelerators/accelerator_table.h"
8 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
(...skipping 19 matching lines...) Expand all
30 #include "ash/wm/wm_event.h" 30 #include "ash/wm/wm_event.h"
31 #include "base/command_line.h" 31 #include "base/command_line.h"
32 #include "ui/aura/client/aura_constants.h" 32 #include "ui/aura/client/aura_constants.h"
33 #include "ui/aura/test/test_window_delegate.h" 33 #include "ui/aura/test/test_window_delegate.h"
34 #include "ui/aura/test/test_windows.h" 34 #include "ui/aura/test/test_windows.h"
35 #include "ui/aura/window.h" 35 #include "ui/aura/window.h"
36 #include "ui/events/event.h" 36 #include "ui/events/event.h"
37 #include "ui/events/event_processor.h" 37 #include "ui/events/event_processor.h"
38 #include "ui/events/test/event_generator.h" 38 #include "ui/events/test/event_generator.h"
39 #include "ui/gfx/screen.h" 39 #include "ui/gfx/screen.h"
40 #include "ui/message_center/message_center.h"
40 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
41 42
42 #if defined(USE_X11) 43 #if defined(USE_X11)
43 #include <X11/Xlib.h> 44 #include <X11/Xlib.h>
44 #include "ui/events/test/events_test_utils_x11.h" 45 #include "ui/events/test/events_test_utils_x11.h"
45 #endif 46 #endif
46 47
47 namespace ash { 48 namespace ash {
48 49
49 namespace { 50 namespace {
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 1402 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
1402 wm::ActivateWindow(window.get()); 1403 wm::ActivateWindow(window.get());
1403 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); 1404 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE);
1404 delegate->TriggerAccessibilityAlert(ui::A11Y_ALERT_NONE); 1405 delegate->TriggerAccessibilityAlert(ui::A11Y_ALERT_NONE);
1405 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]); 1406 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]);
1406 EXPECT_NE(delegate->GetLastAccessibilityAlert(), 1407 EXPECT_NE(delegate->GetLastAccessibilityAlert(),
1407 ui::A11Y_ALERT_WINDOW_NEEDED); 1408 ui::A11Y_ALERT_WINDOW_NEEDED);
1408 } 1409 }
1409 } 1410 }
1410 1411
1412 namespace {
1413
1414 // defines a class to test the behavior of deprecated accelerators.
1415 class DeprecatedAcceleratorTester : public AcceleratorControllerTest {
1416 public:
1417 DeprecatedAcceleratorTester() {}
1418 ~DeprecatedAcceleratorTester() override {}
1419
1420 ui::Accelerator CreateAccelerator(const AcceleratorData& data) const {
1421 ui::Accelerator result(data.keycode, data.modifiers);
1422 result.set_type(data.trigger_on_press ? ui::ET_KEY_PRESSED
1423 : ui::ET_KEY_RELEASED);
1424 return result;
1425 }
1426
1427 void ResetStateIfNeeded() {
1428 Shell* shell = Shell::GetInstance();
1429 if (shell->session_state_delegate()->IsScreenLocked() ||
1430 shell->session_state_delegate()->IsUserSessionBlocked()) {
1431 UnblockUserSession();
1432 }
1433 }
1434
1435 bool ContainsDeprecatedAcceleratorNotification() const {
1436 return nullptr !=
1437 message_center()->FindVisibleNotificationById(
1438 kDeprecatedAcceleratorNotificationId);
1439 }
1440
1441 bool IsMessageCenterEmpty() const {
1442 return message_center()->GetVisibleNotifications().empty();
1443 }
1444
1445 void RemoveAllNotifications() const {
1446 message_center()->RemoveAllNotifications(false);
1447 }
1448
1449 message_center::MessageCenter* message_center() const {
1450 return message_center::MessageCenter::Get();
1451 }
1452
1453 private:
1454 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester);
1455 };
1456
1457 } // namespace
1458
1459 TEST_F(DeprecatedAcceleratorTester, TestDeprecatedAcceleratorsBehavior) {
1460 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) {
1461 const DeprecatedAcceleratorData& data = kDeprecatedAccelerators[i];
1462
1463 EXPECT_TRUE(IsMessageCenterEmpty());
1464
1465 ui::Accelerator deprecated_accelerator =
1466 CreateAccelerator(data.deprecated_accelerator);
1467 if (data.deprecated_enabled)
1468 EXPECT_TRUE(ProcessInController(deprecated_accelerator));
1469 else
1470 EXPECT_FALSE(ProcessInController(deprecated_accelerator));
1471
1472 // We expect to see a notification in the message center.
1473 EXPECT_TRUE(ContainsDeprecatedAcceleratorNotification());
1474 RemoveAllNotifications();
1475
1476 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1477 // screen before we proceed testing the rest of accelerators.
1478 ResetStateIfNeeded();
1479 }
1480 }
1481
1482 TEST_F(DeprecatedAcceleratorTester, TestNewAccelerators) {
1483 // Add below the new accelerators that replaced the deprecated ones (if any).
1484 const AcceleratorData kNewAccelerators[] = {
1485 #if defined(OS_CHROMEOS)
1486 { true, ui::VKEY_L, ui::EF_COMMAND_DOWN, LOCK_SCREEN },
1487 { true, ui::VKEY_ESCAPE, ui::EF_COMMAND_DOWN, SHOW_TASK_MANAGER },
1488 #endif // defined(OS_CHROMEOS)
1489 };
1490
1491 EXPECT_TRUE(IsMessageCenterEmpty());
1492
1493 for (auto data : kNewAccelerators) {
1494 EXPECT_TRUE(ProcessInController(CreateAccelerator(data)));
1495
1496 // Expect no notifications from the new accelerators.
1497 EXPECT_TRUE(IsMessageCenterEmpty());
1498
1499 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1500 // screen before we proceed testing the rest of accelerators.
1501 ResetStateIfNeeded();
1502 }
1503 }
1504
1411 } // namespace ash 1505 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698