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