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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
8 #import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field_cell.h" | 9 #import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field_cell.h" |
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 | 12 |
13 @interface FindBarTextFieldCell (ExposedForTesting) | 13 @interface FindBarTextFieldCell (ExposedForTesting) |
14 - (NSAttributedString*)resultsAttributedString; | 14 - (NSAttributedString*)resultsAttributedString; |
15 @end | 15 @end |
16 | 16 |
17 @implementation FindBarTextFieldCell (ExposedForTesting) | 17 @implementation FindBarTextFieldCell (ExposedForTesting) |
18 - (NSAttributedString*)resultsAttributedString { | 18 - (NSAttributedString*)resultsAttributedString { |
19 return resultsString_.get(); | 19 return resultsString_.get(); |
20 } | 20 } |
21 @end | 21 @end |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Width of the field so that we don't have to ask |field_| for it all | 25 // Width of the field so that we don't have to ask |field_| for it all |
26 // the time. | 26 // the time. |
27 const CGFloat kWidth(300.0); | 27 const CGFloat kWidth(300.0); |
28 | 28 |
29 // A narrow width for tests which test things that don't fit. | 29 // A narrow width for tests which test things that don't fit. |
30 const CGFloat kNarrowWidth(5.0); | 30 const CGFloat kNarrowWidth(5.0); |
31 | 31 |
32 class FindBarTextFieldCellTest : public CocoaTest { | 32 class FindBarTextFieldCellTest : public CocoaTest { |
33 public: | 33 public: |
34 FindBarTextFieldCellTest() { | 34 FindBarTextFieldCellTest() { |
35 // Make sure this is wide enough to play games with the cell | 35 // Make sure this is wide enough to play games with the cell |
36 // decorations. | 36 // decorations. |
37 const NSRect frame = NSMakeRect(0, 0, kWidth, 30); | 37 const NSRect frame = NSMakeRect(0, 0, kWidth, 30); |
38 | 38 |
39 scoped_nsobject<FindBarTextFieldCell> cell( | 39 base::scoped_nsobject<FindBarTextFieldCell> cell( |
40 [[FindBarTextFieldCell alloc] initTextCell:@"Testing"]); | 40 [[FindBarTextFieldCell alloc] initTextCell:@"Testing"]); |
41 cell_ = cell; | 41 cell_ = cell; |
42 [cell_ setEditable:YES]; | 42 [cell_ setEditable:YES]; |
43 [cell_ setBordered:YES]; | 43 [cell_ setBordered:YES]; |
44 | 44 |
45 scoped_nsobject<NSTextField> view( | 45 base::scoped_nsobject<NSTextField> view( |
46 [[NSTextField alloc] initWithFrame:frame]); | 46 [[NSTextField alloc] initWithFrame:frame]); |
47 view_ = view; | 47 view_ = view; |
48 [view_ setCell:cell_]; | 48 [view_ setCell:cell_]; |
49 | 49 |
50 [[test_window() contentView] addSubview:view_]; | 50 [[test_window() contentView] addSubview:view_]; |
51 } | 51 } |
52 | 52 |
53 NSTextField* view_; | 53 NSTextField* view_; |
54 FindBarTextFieldCell* cell_; | 54 FindBarTextFieldCell* cell_; |
55 }; | 55 }; |
(...skipping 18 matching lines...) Expand all Loading... |
74 [view_ display]; | 74 [view_ display]; |
75 | 75 |
76 [cell_ clearResults]; | 76 [cell_ clearResults]; |
77 [view_ display]; | 77 [view_ display]; |
78 } | 78 } |
79 | 79 |
80 // Verify that setting and clearing the find results changes the results string | 80 // Verify that setting and clearing the find results changes the results string |
81 // appropriately. | 81 // appropriately. |
82 TEST_F(FindBarTextFieldCellTest, SetAndClearFindResults) { | 82 TEST_F(FindBarTextFieldCellTest, SetAndClearFindResults) { |
83 [cell_ setActiveMatch:10 of:30]; | 83 [cell_ setActiveMatch:10 of:30]; |
84 scoped_nsobject<NSAttributedString> tenString( | 84 base::scoped_nsobject<NSAttributedString> tenString( |
85 [[cell_ resultsAttributedString] copy]); | 85 [[cell_ resultsAttributedString] copy]); |
86 EXPECT_GT([tenString length], 0U); | 86 EXPECT_GT([tenString length], 0U); |
87 | 87 |
88 [cell_ setActiveMatch:0 of:0]; | 88 [cell_ setActiveMatch:0 of:0]; |
89 scoped_nsobject<NSAttributedString> zeroString( | 89 base::scoped_nsobject<NSAttributedString> zeroString( |
90 [[cell_ resultsAttributedString] copy]); | 90 [[cell_ resultsAttributedString] copy]); |
91 EXPECT_GT([zeroString length], 0U); | 91 EXPECT_GT([zeroString length], 0U); |
92 EXPECT_FALSE([tenString isEqualToAttributedString:zeroString]); | 92 EXPECT_FALSE([tenString isEqualToAttributedString:zeroString]); |
93 | 93 |
94 [cell_ clearResults]; | 94 [cell_ clearResults]; |
95 EXPECT_EQ(0U, [[cell_ resultsAttributedString] length]); | 95 EXPECT_EQ(0U, [[cell_ resultsAttributedString] length]); |
96 } | 96 } |
97 | 97 |
98 TEST_F(FindBarTextFieldCellTest, TextFrame) { | 98 TEST_F(FindBarTextFieldCellTest, TextFrame) { |
99 const NSRect bounds = [view_ bounds]; | 99 const NSRect bounds = [view_ bounds]; |
(...skipping 28 matching lines...) Expand all Loading... |
128 EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1))); | 128 EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1))); |
129 | 129 |
130 [cell_ setActiveMatch:4 of:5]; | 130 [cell_ setActiveMatch:4 of:5]; |
131 textFrame = [cell_ textFrameForFrame:bounds]; | 131 textFrame = [cell_ textFrameForFrame:bounds]; |
132 drawingRect = [cell_ drawingRectForBounds:bounds]; | 132 drawingRect = [cell_ drawingRectForBounds:bounds]; |
133 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); | 133 EXPECT_FALSE(NSIsEmptyRect(drawingRect)); |
134 EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1))); | 134 EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1))); |
135 } | 135 } |
136 | 136 |
137 } // namespace | 137 } // namespace |
OLD | NEW |