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

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: oshima's comments Created 5 years, 3 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"
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 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 1404 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
1404 wm::ActivateWindow(window.get()); 1405 wm::ActivateWindow(window.get());
1405 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); 1406 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE);
1406 delegate->TriggerAccessibilityAlert(ui::A11Y_ALERT_NONE); 1407 delegate->TriggerAccessibilityAlert(ui::A11Y_ALERT_NONE);
1407 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]); 1408 GetController()->PerformActionIfEnabled(kActionsNeedingWindow[i]);
1408 EXPECT_NE(delegate->GetLastAccessibilityAlert(), 1409 EXPECT_NE(delegate->GetLastAccessibilityAlert(),
1409 ui::A11Y_ALERT_WINDOW_NEEDED); 1410 ui::A11Y_ALERT_WINDOW_NEEDED);
1410 } 1411 }
1411 } 1412 }
1412 1413
1414 #if defined(OS_CHROMEOS)
1415 namespace {
1416
1417 // defines a class to test the behavior of deprecated accelerators.
1418 class DeprecatedAcceleratorTester : public AcceleratorControllerTest {
1419 public:
1420 DeprecatedAcceleratorTester() {}
1421 ~DeprecatedAcceleratorTester() override {}
1422
1423 ui::Accelerator CreateAccelerator(const AcceleratorData& data) const {
1424 ui::Accelerator result(data.keycode, data.modifiers);
1425 result.set_type(data.trigger_on_press ? ui::ET_KEY_PRESSED
1426 : ui::ET_KEY_RELEASED);
1427 return result;
1428 }
1429
1430 void ResetStateIfNeeded() {
1431 Shell* shell = Shell::GetInstance();
1432 if (shell->session_state_delegate()->IsScreenLocked() ||
1433 shell->session_state_delegate()->IsUserSessionBlocked()) {
1434 UnblockUserSession();
1435 }
1436 }
1437
1438 bool ContainsDeprecatedAcceleratorNotification(const char* const id) const {
1439 return nullptr != message_center()->FindVisibleNotificationById(id);
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(
1475 ContainsDeprecatedAcceleratorNotification(data.uma_histogram_name));
1476 RemoveAllNotifications();
1477
1478 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1479 // screen before we proceed testing the rest of accelerators.
1480 ResetStateIfNeeded();
1481 }
1482 }
1483
1484 TEST_F(DeprecatedAcceleratorTester, TestNewAccelerators) {
1485 // Add below the new accelerators that replaced the deprecated ones (if any).
1486 const AcceleratorData kNewAccelerators[] = {
1487 {true, ui::VKEY_L, ui::EF_COMMAND_DOWN, LOCK_SCREEN},
1488 {true, ui::VKEY_ESCAPE, ui::EF_COMMAND_DOWN, SHOW_TASK_MANAGER},
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 #endif // defined(OS_CHROMEOS)
1505
1413 } // namespace ash 1506 } // 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