| 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 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
| 17 | 17 |
| 18 // Expose private variables to make testing easier. | 18 // Expose private variables to make testing easier. |
| 19 @interface FindBarCocoaController(Testing) | 19 @interface FindBarCocoaController(Testing) |
| 20 - (NSView*)findBarView; |
| 20 - (NSTextField*)findText; | 21 - (NSTextField*)findText; |
| 21 - (NSTextField*)resultsLabel; | 22 - (NSTextField*)resultsLabel; |
| 22 @end | 23 @end |
| 23 | 24 |
| 24 @implementation FindBarCocoaController(Testing) | 25 @implementation FindBarCocoaController(Testing) |
| 26 - (NSView*)findBarView { |
| 27 return findBarView_; |
| 28 } |
| 29 |
| 25 - (NSTextField*)findText { | 30 - (NSTextField*)findText { |
| 26 return findText_; | 31 return findText_; |
| 27 } | 32 } |
| 28 | 33 |
| 29 - (NSTextField*)resultsLabel { | 34 - (NSTextField*)resultsLabel { |
| 30 return resultsLabel_; | 35 return resultsLabel_; |
| 31 } | 36 } |
| 32 @end | 37 @end |
| 33 | 38 |
| 34 namespace { | 39 namespace { |
| 35 | 40 |
| 36 class FindBarCocoaControllerTest : public PlatformTest { | 41 class FindBarCocoaControllerTest : public PlatformTest { |
| 37 public: | 42 public: |
| 38 virtual void SetUp() { | 43 virtual void SetUp() { |
| 39 PlatformTest::SetUp(); | 44 PlatformTest::SetUp(); |
| 40 | 45 |
| 41 // TODO(rohitrao): We don't really need to do this once per test. | 46 // TODO(rohitrao): We don't really need to do this once per test. |
| 42 // Consider moving it to SetUpTestCase(). | 47 // Consider moving it to SetUpTestCase(). |
| 43 controller_.reset([[FindBarCocoaController alloc] init]); | 48 controller_.reset([[FindBarCocoaController alloc] init]); |
| 44 [helper_.contentView() addSubview:[controller_ view]]; | 49 [helper_.contentView() addSubview:[controller_ view]]; |
| 45 } | 50 } |
| 46 | 51 |
| 47 protected: | 52 protected: |
| 48 CocoaTestHelper helper_; | 53 CocoaTestHelper helper_; |
| 49 scoped_nsobject<FindBarCocoaController> controller_; | 54 scoped_nsobject<FindBarCocoaController> controller_; |
| 50 }; | 55 }; |
| 51 | 56 |
| 52 TEST_F(FindBarCocoaControllerTest, ShowAndHide) { | 57 TEST_F(FindBarCocoaControllerTest, ShowAndHide) { |
| 53 NSView* findBarView = [controller_ view]; | 58 NSView* findBarView = [controller_ findBarView]; |
| 54 | 59 |
| 55 ASSERT_TRUE([findBarView isHidden]); | 60 ASSERT_GT([findBarView frame].origin.y, 0); |
| 56 ASSERT_FALSE([controller_ isFindBarVisible]); | 61 ASSERT_FALSE([controller_ isFindBarVisible]); |
| 57 | 62 |
| 58 [controller_ showFindBar]; | 63 [controller_ showFindBar:NO]; |
| 59 EXPECT_FALSE([findBarView isHidden]); | 64 EXPECT_EQ([findBarView frame].origin.y, 0); |
| 60 EXPECT_TRUE([controller_ isFindBarVisible]); | 65 EXPECT_TRUE([controller_ isFindBarVisible]); |
| 61 | 66 |
| 62 [controller_ hideFindBar]; | 67 [controller_ hideFindBar:NO]; |
| 63 EXPECT_TRUE([findBarView isHidden]); | 68 EXPECT_GT([findBarView frame].origin.y, 0); |
| 64 EXPECT_FALSE([controller_ isFindBarVisible]); | 69 EXPECT_FALSE([controller_ isFindBarVisible]); |
| 65 } | 70 } |
| 66 | 71 |
| 67 TEST_F(FindBarCocoaControllerTest, SetFindText) { | 72 TEST_F(FindBarCocoaControllerTest, SetFindText) { |
| 68 NSView* findBarView = [controller_ view]; | |
| 69 NSTextField* findText = [controller_ findText]; | 73 NSTextField* findText = [controller_ findText]; |
| 70 | 74 |
| 71 // Start by making the find bar visible. | 75 // Start by making the find bar visible. |
| 72 [controller_ showFindBar]; | 76 [controller_ showFindBar:NO]; |
| 73 EXPECT_FALSE([findBarView isHidden]); | 77 EXPECT_TRUE([controller_ isFindBarVisible]); |
| 74 | 78 |
| 75 // Set the find text. | 79 // Set the find text. |
| 76 const std::string kFindText = "Google"; | 80 const std::string kFindText = "Google"; |
| 77 [controller_ setFindText:ASCIIToUTF16(kFindText)]; | 81 [controller_ setFindText:ASCIIToUTF16(kFindText)]; |
| 78 EXPECT_EQ( | 82 EXPECT_EQ( |
| 79 NSOrderedSame, | 83 NSOrderedSame, |
| 80 [[findText stringValue] compare:base::SysUTF8ToNSString(kFindText)]); | 84 [[findText stringValue] compare:base::SysUTF8ToNSString(kFindText)]); |
| 81 | 85 |
| 82 // Call clearResults, which doesn't actually clear the find text but | 86 // Call clearResults, which doesn't actually clear the find text but |
| 83 // simply sets it back to what it was before. This is silly, but | 87 // simply sets it back to what it was before. This is silly, but |
| 84 // matches the behavior on other platforms. |details| isn't used by | 88 // matches the behavior on other platforms. |details| isn't used by |
| 85 // our implementation of clearResults, so it's ok to pass in an | 89 // our implementation of clearResults, so it's ok to pass in an |
| 86 // empty |details|. | 90 // empty |details|. |
| 87 FindNotificationDetails details; | 91 FindNotificationDetails details; |
| 88 [controller_ clearResults:details]; | 92 [controller_ clearResults:details]; |
| 89 EXPECT_EQ( | 93 EXPECT_EQ( |
| 90 NSOrderedSame, | 94 NSOrderedSame, |
| 91 [[findText stringValue] compare:base::SysUTF8ToNSString(kFindText)]); | 95 [[findText stringValue] compare:base::SysUTF8ToNSString(kFindText)]); |
| 92 } | 96 } |
| 93 | 97 |
| 94 TEST_F(FindBarCocoaControllerTest, ResultLabelUpdatesCorrectly) { | 98 TEST_F(FindBarCocoaControllerTest, ResultLabelUpdatesCorrectly) { |
| 95 // TODO(rohitrao): Test this. It may involve creating some dummy | 99 // TODO(rohitrao): Test this. It may involve creating some dummy |
| 96 // FindNotificationDetails objects. | 100 // FindNotificationDetails objects. |
| 97 } | 101 } |
| 98 | 102 |
| 99 } // namespace | 103 } // namespace |
| OLD | NEW |