• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2011 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.
4
5#include "base/memory/scoped_nsobject.h"
6#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
7#include "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h"
8#include "testing/gtest_mac.h"
9#include "ui/base/models/accelerator_cocoa.h"
10
11namespace {
12
13class ConfirmQuitPanelControllerTest : public CocoaTest {
14 public:
15  NSString* TestString(NSString* str) {
16    str = [str stringByReplacingOccurrencesOfString:@"{Cmd}"
17                                         withString:@"\u2318"];
18    str = [str stringByReplacingOccurrencesOfString:@"{Ctrl}"
19                                         withString:@"\u2303"];
20    str = [str stringByReplacingOccurrencesOfString:@"{Opt}"
21                                         withString:@"\u2325"];
22    str = [str stringByReplacingOccurrencesOfString:@"{Shift}"
23                                         withString:@"\u21E7"];
24    return str;
25  }
26};
27
28
29TEST_F(ConfirmQuitPanelControllerTest, ShowAndDismiss) {
30  ConfirmQuitPanelController* controller =
31      [ConfirmQuitPanelController sharedController];
32  // Test singleton.
33  EXPECT_EQ(controller, [ConfirmQuitPanelController sharedController]);
34  [controller showWindow:nil];
35  [controller dismissPanel];  // Releases self.
36  // The controller should still be the singleton instance until after the
37  // animation runs and the window closes. That will happen after this test body
38  // finishes executing.
39  EXPECT_EQ(controller, [ConfirmQuitPanelController sharedController]);
40}
41
42TEST_F(ConfirmQuitPanelControllerTest, KeyCombinationForAccelerator) {
43  Class controller = [ConfirmQuitPanelController class];
44
45  ui::AcceleratorCocoa item = ui::AcceleratorCocoa(@"q", NSCommandKeyMask);
46  EXPECT_NSEQ(TestString(@"{Cmd}Q"),
47              [controller keyCombinationForAccelerator:item]);
48
49  item = ui::AcceleratorCocoa(@"c", NSCommandKeyMask | NSShiftKeyMask);
50  EXPECT_NSEQ(TestString(@"{Cmd}{Shift}C"),
51              [controller keyCombinationForAccelerator:item]);
52
53  item = ui::AcceleratorCocoa(@"h",
54      NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask);
55  EXPECT_NSEQ(TestString(@"{Cmd}{Opt}{Shift}H"),
56              [controller keyCombinationForAccelerator:item]);
57
58  item = ui::AcceleratorCocoa(@"r",
59      NSCommandKeyMask | NSShiftKeyMask | NSAlternateKeyMask |
60      NSControlKeyMask);
61  EXPECT_NSEQ(TestString(@"{Cmd}{Ctrl}{Opt}{Shift}R"),
62              [controller keyCombinationForAccelerator:item]);
63
64  item = ui::AcceleratorCocoa(@"o", NSControlKeyMask);
65  EXPECT_NSEQ(TestString(@"{Ctrl}O"),
66              [controller keyCombinationForAccelerator:item]);
67
68  item = ui::AcceleratorCocoa(@"m", NSShiftKeyMask | NSControlKeyMask);
69  EXPECT_NSEQ(TestString(@"{Ctrl}{Shift}M"),
70              [controller keyCombinationForAccelerator:item]);
71
72  item = ui::AcceleratorCocoa(@"e", NSCommandKeyMask | NSAlternateKeyMask);
73  EXPECT_NSEQ(TestString(@"{Cmd}{Opt}E"),
74              [controller keyCombinationForAccelerator:item]);
75}
76
77}  // namespace
78