[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / confirm_quit_panel_controller_unittest.mm
blobf191e0f0d3a3553fcf452d6d0224c58379d27e83
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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h"
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
8 #include "chrome/browser/ui/cocoa/confirm_quit.h"
9 #include "testing/gtest_mac.h"
10 #include "ui/base/accelerators/platform_accelerator_cocoa.h"
12 namespace {
14 class ConfirmQuitPanelControllerTest : public CocoaTest {
15  public:
16   NSString* TestString(NSString* str) {
17     str = [str stringByReplacingOccurrencesOfString:@"{Cmd}"
18                                          withString:@"\u2318"];
19     str = [str stringByReplacingOccurrencesOfString:@"{Ctrl}"
20                                          withString:@"\u2303"];
21     str = [str stringByReplacingOccurrencesOfString:@"{Opt}"
22                                          withString:@"\u2325"];
23     str = [str stringByReplacingOccurrencesOfString:@"{Shift}"
24                                          withString:@"\u21E7"];
25     return str;
26   }
30 TEST_F(ConfirmQuitPanelControllerTest, ShowAndDismiss) {
31   ConfirmQuitPanelController* controller =
32       [ConfirmQuitPanelController sharedController];
33   // Test singleton.
34   EXPECT_EQ(controller, [ConfirmQuitPanelController sharedController]);
35   [controller showWindow:nil];
36   [controller dismissPanel];  // Releases self.
37   // The controller should still be the singleton instance until after the
38   // animation runs and the window closes. That will happen after this test body
39   // finishes executing.
40   EXPECT_EQ(controller, [ConfirmQuitPanelController sharedController]);
43 TEST_F(ConfirmQuitPanelControllerTest, KeyCombinationForAccelerator) {
44   Class controller = [ConfirmQuitPanelController class];
46   ui::PlatformAcceleratorCocoa item(@"q", NSCommandKeyMask);
47   EXPECT_NSEQ(TestString(@"{Cmd}Q"),
48               [controller keyCombinationForAccelerator:item]);
50   ui::PlatformAcceleratorCocoa item2(@"c", NSCommandKeyMask | NSShiftKeyMask);
51   EXPECT_NSEQ(TestString(@"{Cmd}{Shift}C"),
52               [controller keyCombinationForAccelerator:item2]);
54   ui::PlatformAcceleratorCocoa item3(@"h",
55       NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask);
56   EXPECT_NSEQ(TestString(@"{Cmd}{Opt}{Shift}H"),
57               [controller keyCombinationForAccelerator:item3]);
59   ui::PlatformAcceleratorCocoa item4(@"r",
60       NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask |
61       NSControlKeyMask);
62   EXPECT_NSEQ(TestString(@"{Cmd}{Ctrl}{Opt}{Shift}R"),
63               [controller keyCombinationForAccelerator:item4]);
65   ui::PlatformAcceleratorCocoa item5(@"o", NSControlKeyMask);
66   EXPECT_NSEQ(TestString(@"{Ctrl}O"),
67               [controller keyCombinationForAccelerator:item5]);
69   ui::PlatformAcceleratorCocoa item6(@"m", NSShiftKeyMask | NSControlKeyMask);
70   EXPECT_NSEQ(TestString(@"{Ctrl}{Shift}M"),
71               [controller keyCombinationForAccelerator:item6]);
73   ui::PlatformAcceleratorCocoa item7(
74       @"e", NSCommandKeyMask | NSAlternateKeyMask);
75   EXPECT_NSEQ(TestString(@"{Cmd}{Opt}E"),
76               [controller keyCombinationForAccelerator:item7]);
79 }  // namespace