summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-24 15:22:31 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-24 15:22:31 +0000
commitcd6c75b82de639cf5b11a85ffeb47ea9206e5375 (patch)
tree5f361c9d11eef2289de42c99af80d7e007780273 /chrome/browser/cocoa
parente96833357a87a977afb7f171729e0d7c615e5043 (diff)
downloadchromium_src-cd6c75b82de639cf5b11a85ffeb47ea9206e5375.zip
chromium_src-cd6c75b82de639cf5b11a85ffeb47ea9206e5375.tar.gz
chromium_src-cd6c75b82de639cf5b11a85ffeb47ea9206e5375.tar.bz2
Unittest for FindBarCocoaController.
TEST=The new unittest passes. BUG=10802 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/find_bar_bridge.h9
-rw-r--r--chrome/browser/cocoa/find_bar_bridge.mm5
-rw-r--r--chrome/browser/cocoa/find_bar_cocoa_controller.h4
-rw-r--r--chrome/browser/cocoa/find_bar_cocoa_controller.mm3
-rw-r--r--chrome/browser/cocoa/find_bar_cocoa_controller_unittest.mm94
5 files changed, 105 insertions, 10 deletions
diff --git a/chrome/browser/cocoa/find_bar_bridge.h b/chrome/browser/cocoa/find_bar_bridge.h
index b01b849..2388733 100644
--- a/chrome/browser/cocoa/find_bar_bridge.h
+++ b/chrome/browser/cocoa/find_bar_bridge.h
@@ -22,7 +22,7 @@ class FindBarController;
// created by a static method in BrowserWindow. The FindBarBridge
// constructor creates a FindBarCocoaController, which in turn loads a
// FindBarView from a nib file. All of this is happening outside of
-// the main view hierarchy, so FindBarCocoaController calls
+// the main view hierarchy, so the static method also calls
// BrowserWindowCocoa::AddFindBar() in order to add its FindBarView to
// the cocoa views hierarchy.
//
@@ -32,10 +32,13 @@ class FindBarController;
class FindBarBridge : public FindBar {
public:
- // Constructs a new bridge object and adds its cocoa controller to |window|.
- FindBarBridge(BrowserWindowCocoa* window);
+ FindBarBridge();
virtual ~FindBarBridge();
+ FindBarCocoaController* find_bar_cocoa_controller() {
+ return cocoa_controller_.get();
+ }
+
virtual void SetFindBarController(FindBarController* find_bar_controller) {
find_bar_controller_ = find_bar_controller;
}
diff --git a/chrome/browser/cocoa/find_bar_bridge.mm b/chrome/browser/cocoa/find_bar_bridge.mm
index 415273b..d8eb802 100644
--- a/chrome/browser/cocoa/find_bar_bridge.mm
+++ b/chrome/browser/cocoa/find_bar_bridge.mm
@@ -5,9 +5,8 @@
#import "chrome/browser/cocoa/find_bar_bridge.h"
#import "chrome/browser/cocoa/find_bar_cocoa_controller.h"
-FindBarBridge::FindBarBridge(BrowserWindowCocoa* window) {
- cocoa_controller_.reset(
- [[FindBarCocoaController alloc] initWithBrowserWindow:window]);
+FindBarBridge::FindBarBridge() {
+ cocoa_controller_.reset([[FindBarCocoaController alloc] init]);
[cocoa_controller_ setFindBarBridge:this];
}
diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.h b/chrome/browser/cocoa/find_bar_cocoa_controller.h
index eb3e5a8..933f88e 100644
--- a/chrome/browser/cocoa/find_bar_cocoa_controller.h
+++ b/chrome/browser/cocoa/find_bar_cocoa_controller.h
@@ -29,8 +29,8 @@ class FindNotificationDetails;
FindBarBridge* findBarBridge_; // weak
};
-// Initializes a new FindBarCocoaController and add itself to |window|.
-- (id)initWithBrowserWindow:(BrowserWindowCocoa*)window;
+// Initializes a new FindBarCocoaController.
+- (id)init;
- (void)setFindBarBridge:(FindBarBridge*)findBar;
diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.mm b/chrome/browser/cocoa/find_bar_cocoa_controller.mm
index dbd66fb..a4229fc 100644
--- a/chrome/browser/cocoa/find_bar_cocoa_controller.mm
+++ b/chrome/browser/cocoa/find_bar_cocoa_controller.mm
@@ -17,10 +17,9 @@
@implementation FindBarCocoaController
-- (id)initWithBrowserWindow:(BrowserWindowCocoa*)window {
+- (id)init {
if ((self = [super initWithNibName:@"FindBar"
bundle:mac_util::MainAppBundle()])) {
- window->AddFindBar(self);
}
return self;
}
diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller_unittest.mm b/chrome/browser/cocoa/find_bar_cocoa_controller_unittest.mm
new file mode 100644
index 0000000..48912bd
--- /dev/null
+++ b/chrome/browser/cocoa/find_bar_cocoa_controller_unittest.mm
@@ -0,0 +1,94 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/scoped_ptr.h"
+#include "base/scoped_nsobject.h"
+#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/find_notification_details.h"
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+#import "chrome/browser/cocoa/find_bar_cocoa_controller.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+// Expose private variables to make testing easier.
+@interface FindBarCocoaController(Testing)
+- (NSTextField*)findText;
+- (NSTextField*)resultsLabel;
+@end
+
+@implementation FindBarCocoaController(Testing)
+- (NSTextField*)findText {
+ return findText_;
+}
+
+- (NSTextField*)resultsLabel {
+ return resultsLabel_;
+}
+@end
+
+namespace {
+
+class FindBarCocoaControllerTest : public PlatformTest {
+ public:
+ virtual void SetUp() {
+ PlatformTest::SetUp();
+
+ // TODO(rohitrao): We don't really need to do this once per test.
+ // Consider moving it to SetUpTestCase().
+ controller_.reset([[FindBarCocoaController alloc] init]);
+ [helper_.contentView() addSubview:[controller_ view]];
+ }
+
+ protected:
+ CocoaTestHelper helper_;
+ scoped_nsobject<FindBarCocoaController> controller_;
+};
+
+TEST_F(FindBarCocoaControllerTest, ShowAndHide) {
+ NSView* findBarView = [controller_ view];
+
+ ASSERT_TRUE([findBarView isHidden]);
+ ASSERT_FALSE([controller_ isFindBarVisible]);
+
+ [controller_ showFindBar];
+ EXPECT_FALSE([findBarView isHidden]);
+ EXPECT_TRUE([controller_ isFindBarVisible]);
+
+ [controller_ hideFindBar];
+ EXPECT_TRUE([findBarView isHidden]);
+ EXPECT_FALSE([controller_ isFindBarVisible]);
+}
+
+TEST_F(FindBarCocoaControllerTest, SetFindText) {
+ NSView* findBarView = [controller_ view];
+ NSTextField* findText = [controller_ findText];
+
+ // Start by making the find bar visible.
+ [controller_ showFindBar];
+ EXPECT_FALSE([findBarView isHidden]);
+
+ // Set the find text.
+ const std::string kFindText = "Google";
+ [controller_ setFindText:ASCIIToUTF16(kFindText)];
+ EXPECT_EQ(
+ NSOrderedSame,
+ [[findText stringValue] compare:base::SysUTF8ToNSString(kFindText)]);
+
+ // Clear the find text. |details| isn't used by our implementation
+ // of clearResults, so it's ok to pass in an empty |details|.
+ FindNotificationDetails details;
+ [controller_ clearResults:details];
+ EXPECT_EQ(0U, [[findText stringValue] length]);
+}
+
+TEST_F(FindBarCocoaControllerTest, ResultLabelUpdatesCorrectly) {
+ // TODO(rohitrao): Test this. It may involve creating some dummy
+ // FindNotificationDetails objects.
+}
+
+} // namespace