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
6#include "base/mac/scoped_nsobject.h"
7#import "chrome/browser/ui/cocoa/bubble_view.h"
8#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9#import "testing/gtest_mac.h"
10
11class BubbleViewTest : public CocoaTest {
12 public:
13  BubbleViewTest() {
14    NSRect frame = NSMakeRect(0, 0, 50, 50);
15    base::scoped_nsobject<BubbleView> view(
16        [[BubbleView alloc] initWithFrame:frame themeProvider:test_window()]);
17    view_ = view.get();
18    [[test_window() contentView] addSubview:view_];
19    [view_ setContent:@"Hi there, I'm a bubble view"];
20  }
21
22  BubbleView* view_;
23};
24
25TEST_VIEW(BubbleViewTest, view_);
26
27// Test a nil themeProvider in init.
28TEST_F(BubbleViewTest, NilThemeProvider) {
29  NSRect frame = NSMakeRect(0, 0, 50, 50);
30  base::scoped_nsobject<BubbleView> view(
31      [[BubbleView alloc] initWithFrame:frame themeProvider:nil]);
32  [[test_window() contentView] addSubview:view.get()];
33  [view display];
34}
35
36// Make sure things don't go haywire when given invalid or long strings.
37TEST_F(BubbleViewTest, SetContent) {
38  [view_ setContent:nil];
39  EXPECT_TRUE([view_ content] == nil);
40  [view_ setContent:@""];
41  EXPECT_NSEQ(@"", [view_ content]);
42  NSString* str = @"This is a really really long string that's just too long";
43  [view_ setContent:str];
44  EXPECT_NSEQ(str, [view_ content]);
45}
46
47TEST_F(BubbleViewTest, CornerFlags) {
48  // Set some random flags just to check.
49  [view_ setCornerFlags:kRoundedTopRightCorner | kRoundedTopLeftCorner];
50  EXPECT_EQ([view_ cornerFlags],
51            (unsigned long)kRoundedTopRightCorner | kRoundedTopLeftCorner);
52  // Set no flags (all 4 draw corners are square).
53  [view_ setCornerFlags:0];
54  EXPECT_EQ([view_ cornerFlags], 0UL);
55  // Set all bits. Meaningless past the first 4, but harmless to set too many.
56  [view_ setCornerFlags:0xFFFFFFFF];
57  EXPECT_EQ([view_ cornerFlags], 0xFFFFFFFF);
58}
59