OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/string_util.h" | |
6 #include "base/sys_string_conversions.h" | |
7 #include "chrome/browser/browser_window.h" | |
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
9 #import "chrome/browser/ui/cocoa/find_bar_cocoa_controller.h" | |
10 #import "chrome/browser/ui/cocoa/find_pasteboard.h" | |
11 #import "chrome/browser/ui/cocoa/find_bar_text_field.h" | |
12 #include "chrome/browser/ui/find_bar/find_notification_details.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "testing/platform_test.h" | |
15 | |
16 // Expose private variables to make testing easier. | |
17 @interface FindBarCocoaController(Testing) | |
18 - (NSView*)findBarView; | |
19 - (NSString*)findText; | |
20 - (FindBarTextField*)findTextField; | |
21 @end | |
22 | |
23 @implementation FindBarCocoaController(Testing) | |
24 - (NSView*)findBarView { | |
25 return findBarView_; | |
26 } | |
27 | |
28 - (NSString*)findText { | |
29 return [findText_ stringValue]; | |
30 } | |
31 | |
32 - (FindBarTextField*)findTextField { | |
33 return findText_; | |
34 } | |
35 | |
36 - (NSButton*)nextButton { | |
37 return nextButton_; | |
38 } | |
39 | |
40 - (NSButton*)previousButton { | |
41 return previousButton_; | |
42 } | |
43 @end | |
44 | |
45 namespace { | |
46 | |
47 class FindBarCocoaControllerTest : public CocoaTest { | |
48 public: | |
49 virtual void SetUp() { | |
50 CocoaTest::SetUp(); | |
51 controller_.reset([[FindBarCocoaController alloc] init]); | |
52 [[test_window() contentView] addSubview:[controller_ view]]; | |
53 } | |
54 | |
55 protected: | |
56 scoped_nsobject<FindBarCocoaController> controller_; | |
57 }; | |
58 | |
59 TEST_VIEW(FindBarCocoaControllerTest, [controller_ view]) | |
60 | |
61 TEST_F(FindBarCocoaControllerTest, ImagesLoadedProperly) { | |
62 EXPECT_TRUE([[[controller_ nextButton] image] isValid]); | |
63 EXPECT_TRUE([[[controller_ previousButton] image] isValid]); | |
64 } | |
65 | |
66 TEST_F(FindBarCocoaControllerTest, ShowAndHide) { | |
67 NSView* findBarView = [controller_ findBarView]; | |
68 | |
69 ASSERT_GT([findBarView frame].origin.y, 0); | |
70 ASSERT_FALSE([controller_ isFindBarVisible]); | |
71 | |
72 [controller_ showFindBar:NO]; | |
73 EXPECT_EQ([findBarView frame].origin.y, 0); | |
74 EXPECT_TRUE([controller_ isFindBarVisible]); | |
75 | |
76 [controller_ hideFindBar:NO]; | |
77 EXPECT_GT([findBarView frame].origin.y, 0); | |
78 EXPECT_FALSE([controller_ isFindBarVisible]); | |
79 } | |
80 | |
81 TEST_F(FindBarCocoaControllerTest, SetFindText) { | |
82 NSTextField* findTextField = [controller_ findTextField]; | |
83 | |
84 // Start by making the find bar visible. | |
85 [controller_ showFindBar:NO]; | |
86 EXPECT_TRUE([controller_ isFindBarVisible]); | |
87 | |
88 // Set the find text. | |
89 NSString* const kFindText = @"Google"; | |
90 [controller_ setFindText:kFindText]; | |
91 EXPECT_EQ( | |
92 NSOrderedSame, | |
93 [[findTextField stringValue] compare:kFindText]); | |
94 | |
95 // Call clearResults, which doesn't actually clear the find text but | |
96 // simply sets it back to what it was before. This is silly, but | |
97 // matches the behavior on other platforms. |details| isn't used by | |
98 // our implementation of clearResults, so it's ok to pass in an | |
99 // empty |details|. | |
100 FindNotificationDetails details; | |
101 [controller_ clearResults:details]; | |
102 EXPECT_EQ( | |
103 NSOrderedSame, | |
104 [[findTextField stringValue] compare:kFindText]); | |
105 } | |
106 | |
107 TEST_F(FindBarCocoaControllerTest, ResultLabelUpdatesCorrectly) { | |
108 // TODO(rohitrao): Test this. It may involve creating some dummy | |
109 // FindNotificationDetails objects. | |
110 } | |
111 | |
112 TEST_F(FindBarCocoaControllerTest, FindTextIsGlobal) { | |
113 scoped_nsobject<FindBarCocoaController> otherController( | |
114 [[FindBarCocoaController alloc] init]); | |
115 [[test_window() contentView] addSubview:[otherController view]]; | |
116 | |
117 // Setting the text in one controller should update the other controller's | |
118 // text as well. | |
119 NSString* const kFindText = @"Respect to the man in the ice cream van"; | |
120 [controller_ setFindText:kFindText]; | |
121 EXPECT_EQ( | |
122 NSOrderedSame, | |
123 [[controller_ findText] compare:kFindText]); | |
124 EXPECT_EQ( | |
125 NSOrderedSame, | |
126 [[otherController.get() findText] compare:kFindText]); | |
127 } | |
128 | |
129 TEST_F(FindBarCocoaControllerTest, SettingFindTextUpdatesFindPboard) { | |
130 NSString* const kFindText = | |
131 @"It's not a bird, it's not a plane, it must be Dave who's on the train"; | |
132 [controller_ setFindText:kFindText]; | |
133 EXPECT_EQ( | |
134 NSOrderedSame, | |
135 [[[FindPasteboard sharedInstance] findText] compare:kFindText]); | |
136 } | |
137 | |
138 } // namespace | |
OLD | NEW |