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