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

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

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

Powered by Google App Engine
This is Rietveld 408576698