summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller_unittest.mm
blob: 9061b9ed9bda121dd8ff3f0b3d653a43c352beca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h"

#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#include "testing/gtest_mac.h"
#include "ui/base/models/accelerator_cocoa.h"

@interface FullscreenExitBubbleController(JustForTesting)
// Already defined.
+ (NSString*)keyCommandString;
+ (NSString*)keyCombinationForAccelerator:(const ui::AcceleratorCocoa&)item;
@end

@interface FullscreenExitBubbleController(ExposedForTesting)
- (NSTextField*)exitLabelPlaceholder;
- (NSTextView*)exitLabel;
@end

@implementation FullscreenExitBubbleController(ExposedForTesting)
- (NSTextField*)exitLabelPlaceholder {
  return exitLabelPlaceholder_;
}

- (NSTextView*)exitLabel {
  return exitLabel_;
}
@end

class FullscreenExitBubbleControllerTest : public CocoaTest {
 public:
  virtual void SetUp() {
    CocoaTest::SetUp();

    controller_.reset(
        [[FullscreenExitBubbleController alloc] initWithOwner:nil browser:nil]);
    EXPECT_TRUE([controller_ view]);

    [[test_window() contentView] addSubview:[controller_ view]];
  }

  scoped_nsobject<FullscreenExitBubbleController> controller_;
};

TEST_VIEW(FullscreenExitBubbleControllerTest, [controller_ view])

TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) {
  EXPECT_FALSE([controller_ exitLabelPlaceholder]);
  EXPECT_TRUE([controller_ exitLabel]);
}

TEST_F(FullscreenExitBubbleControllerTest, LabelContainsShortcut) {
  NSString* shortcut = [FullscreenExitBubbleController keyCommandString];
  EXPECT_GT([shortcut length], 0U);

  NSString* message = [[[controller_ exitLabel] textStorage] string];

  NSRange range = [message rangeOfString:shortcut];
  EXPECT_NE(NSNotFound, range.location);
}

TEST_F(FullscreenExitBubbleControllerTest, ShortcutText) {
  ui::AcceleratorCocoa cmd_F(@"F", NSCommandKeyMask);
  ui::AcceleratorCocoa cmd_shift_f(@"f", NSCommandKeyMask|NSShiftKeyMask);
  NSString* cmd_F_text = [FullscreenExitBubbleController
      keyCombinationForAccelerator:cmd_F];
  NSString* cmd_shift_f_text = [FullscreenExitBubbleController
      keyCombinationForAccelerator:cmd_shift_f];
  EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text);
  EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text);
}