Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Side by Side Diff: chrome/browser/cocoa/bubble_view_unittest.mm

Issue 333017: Fixes up bookmark bubbles and the browser window so that they shut down corre... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h>
6 5
7 #include "base/scoped_nsobject.h" 6 #include "base/scoped_nsobject.h"
8 #import "chrome/browser/cocoa/bubble_view.h" 7 #import "chrome/browser/cocoa/bubble_view.h"
9 #include "chrome/browser/cocoa/cocoa_test_helper.h" 8 #include "chrome/browser/cocoa/cocoa_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
12 9
13 class BubbleViewTest : public PlatformTest { 10 class BubbleViewTest : public CocoaTest {
14 public: 11 public:
15 BubbleViewTest() { 12 BubbleViewTest() {
16 NSRect frame = NSMakeRect(0, 0, 50, 50); 13 NSRect frame = NSMakeRect(0, 0, 50, 50);
17 view_.reset([[BubbleView alloc] initWithFrame:frame 14 scoped_nsobject<BubbleView> view(
18 themeProvider:cocoa_helper_.window()]); 15 [[BubbleView alloc] initWithFrame:frame themeProvider:test_window()]);
19 [cocoa_helper_.contentView() addSubview:view_.get()]; 16 view_ = view.get();
17 [[test_window() contentView] addSubview:view_];
20 [view_ setContent:@"Hi there, I'm a bubble view"]; 18 [view_ setContent:@"Hi there, I'm a bubble view"];
21 } 19 }
22 20
23 CocoaTestHelper cocoa_helper_; 21 BubbleView* view_;
24 scoped_nsobject<BubbleView> view_;
25 }; 22 };
26 23
27 // Test adding/removing from the view hierarchy, mostly to ensure nothing 24 TEST_VIEW(BubbleViewTest, view_);
28 // leaks or crashes.
29 TEST_F(BubbleViewTest, AddRemove) {
30 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]);
31 [view_.get() removeFromSuperview];
32 EXPECT_FALSE([view_ superview]);
33 }
34
35 // Test drawing, mostly to ensure nothing leaks or crashes.
36 TEST_F(BubbleViewTest, Display) {
37 [view_ display];
38 }
39 25
40 // Test a nil themeProvider in init. 26 // Test a nil themeProvider in init.
41 TEST_F(BubbleViewTest, NilThemeProvider) { 27 TEST_F(BubbleViewTest, NilThemeProvider) {
42 NSRect frame = NSMakeRect(0, 0, 50, 50); 28 NSRect frame = NSMakeRect(0, 0, 50, 50);
43 view_.reset([[BubbleView alloc] initWithFrame:frame 29 scoped_nsobject<BubbleView> view(
44 themeProvider:nil]); 30 [[BubbleView alloc] initWithFrame:frame themeProvider:nil]);
45 [cocoa_helper_.contentView() addSubview:view_.get()]; 31 [[test_window() contentView] addSubview:view.get()];
46 [view_ display]; 32 [view display];
47 } 33 }
48 34
49 // Make sure things don't go haywire when given invalid or long strings. 35 // Make sure things don't go haywire when given invalid or long strings.
50 TEST_F(BubbleViewTest, SetContent) { 36 TEST_F(BubbleViewTest, SetContent) {
51 [view_ setContent:nil]; 37 [view_ setContent:nil];
52 EXPECT_TRUE([view_ content] == nil); 38 EXPECT_TRUE([view_ content] == nil);
53 [view_ setContent:@""]; 39 [view_ setContent:@""];
54 EXPECT_TRUE([[view_ content] isEqualToString:@""]); 40 EXPECT_TRUE([[view_ content] isEqualToString:@""]);
55 NSString* str = @"This is a really really long string that's just too long"; 41 NSString* str = @"This is a really really long string that's just too long";
56 [view_ setContent:str]; 42 [view_ setContent:str];
57 EXPECT_TRUE([[view_ content] isEqualToString:str]); 43 EXPECT_TRUE([[view_ content] isEqualToString:str]);
58 } 44 }
59 45
60 TEST_F(BubbleViewTest, CornerFlags) { 46 TEST_F(BubbleViewTest, CornerFlags) {
61 // Set some random flags just to check. 47 // Set some random flags just to check.
62 [view_ setCornerFlags:kRoundedTopRightCorner | kRoundedTopLeftCorner]; 48 [view_ setCornerFlags:kRoundedTopRightCorner | kRoundedTopLeftCorner];
63 EXPECT_EQ([view_ cornerFlags], 49 EXPECT_EQ([view_ cornerFlags],
64 (unsigned long)kRoundedTopRightCorner | kRoundedTopLeftCorner); 50 (unsigned long)kRoundedTopRightCorner | kRoundedTopLeftCorner);
65 // Set no flags (all 4 draw corners are square). 51 // Set no flags (all 4 draw corners are square).
66 [view_ setCornerFlags:0]; 52 [view_ setCornerFlags:0];
67 EXPECT_EQ([view_ cornerFlags], 0UL); 53 EXPECT_EQ([view_ cornerFlags], 0UL);
68 // Set all bits. Meaningless past the first 4, but harmless to set too many. 54 // Set all bits. Meaningless past the first 4, but harmless to set too many.
69 [view_ setCornerFlags:0xFFFFFFFF]; 55 [view_ setCornerFlags:0xFFFFFFFF];
70 EXPECT_EQ([view_ cornerFlags], 0xFFFFFFFF); 56 EXPECT_EQ([view_ cornerFlags], 0xFFFFFFFF);
71 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698