summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/focus_tracker_unittest.mm
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-19 21:52:16 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-19 21:52:16 +0000
commitd4e186524ef4db7f227c57dd61ef727c5eaac623 (patch)
tree7bf4bc7a25f60c3de9f03f917907fdb151735a81 /chrome/browser/cocoa/focus_tracker_unittest.mm
parent2d9c6094d497fac4714ff79205de870c3b6ccaa1 (diff)
downloadchromium_src-d4e186524ef4db7f227c57dd61ef727c5eaac623.zip
chromium_src-d4e186524ef4db7f227c57dd61ef727c5eaac623.tar.gz
chromium_src-d4e186524ef4db7f227c57dd61ef727c5eaac623.tar.bz2
Moved a whole pile of unittests over to CocoaTest.
AboutIPC.xib - Connected up controller to its window and the window delegate to the controller. BUG=26484, 26484 TEST=See repro steps in bugs. Review URL: http://codereview.chromium.org/402066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32551 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/focus_tracker_unittest.mm')
-rw-r--r--chrome/browser/cocoa/focus_tracker_unittest.mm76
1 files changed, 37 insertions, 39 deletions
diff --git a/chrome/browser/cocoa/focus_tracker_unittest.mm b/chrome/browser/cocoa/focus_tracker_unittest.mm
index 65ab91e..f2fb64f 100644
--- a/chrome/browser/cocoa/focus_tracker_unittest.mm
+++ b/chrome/browser/cocoa/focus_tracker_unittest.mm
@@ -12,79 +12,77 @@
namespace {
-class FocusTrackerTest : public PlatformTest {
+class FocusTrackerTest : public CocoaTest {
public:
virtual void SetUp() {
- PlatformTest::SetUp();
-
- viewA_.reset([[NSView alloc] initWithFrame:NSZeroRect]);
- viewB_.reset([[NSView alloc] initWithFrame:NSZeroRect]);
- [helper_.contentView() addSubview:viewA_.get()];
- [helper_.contentView() addSubview:viewB_.get()];
+ CocoaTest::SetUp();
+ scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
+ viewA_ = view.get();
+ [[test_window() contentView] addSubview:viewA_];
+
+ view.reset([[NSView alloc] initWithFrame:NSZeroRect]);
+ viewB_ = view.get();
+ [[test_window() contentView] addSubview:viewB_];
}
protected:
- CocoaTestHelper helper_;
- scoped_nsobject<NSView> viewA_;
- scoped_nsobject<NSView> viewB_;
+ NSView* viewA_;
+ NSView* viewB_;
};
TEST_F(FocusTrackerTest, SaveRestore) {
- NSWindow* window = helper_.window();
- ASSERT_TRUE([window makeFirstResponder:viewA_.get()]);
- FocusTracker* tracker =
- [[[FocusTracker alloc] initWithWindow:window] autorelease];
-
+ NSWindow* window = test_window();
+ ASSERT_TRUE([window makeFirstResponder:viewA_]);
+ scoped_nsobject<FocusTracker> tracker(
+ [[FocusTracker alloc] initWithWindow:window]);
// Give focus to |viewB_|, then try and restore it to view1.
- ASSERT_TRUE([window makeFirstResponder:viewB_.get()]);
+ ASSERT_TRUE([window makeFirstResponder:viewB_]);
EXPECT_TRUE([tracker restoreFocusInWindow:window]);
- EXPECT_EQ(viewA_.get(), [window firstResponder]);
+ EXPECT_EQ(viewA_, [window firstResponder]);
}
TEST_F(FocusTrackerTest, SaveRestoreWithTextView) {
// Valgrind will complain if the text field has zero size.
NSRect frame = NSMakeRect(0, 0, 100, 20);
- NSWindow* window = helper_.window();
- NSTextField* text =
- [[[NSTextField alloc] initWithFrame:frame] autorelease];
- [helper_.contentView() addSubview:text];
+ NSWindow* window = test_window();
+ scoped_nsobject<NSTextField> text([[NSTextField alloc] initWithFrame:frame]);
+ [[window contentView] addSubview:text];
ASSERT_TRUE([window makeFirstResponder:text]);
- FocusTracker* tracker =
- [[[FocusTracker alloc] initWithWindow:window] autorelease];
-
+ scoped_nsobject<FocusTracker> tracker([[FocusTracker alloc]
+ initWithWindow:window]);
// Give focus to |viewB_|, then try and restore it to the text field.
- ASSERT_TRUE([window makeFirstResponder:viewB_.get()]);
+ ASSERT_TRUE([window makeFirstResponder:viewB_]);
EXPECT_TRUE([tracker restoreFocusInWindow:window]);
EXPECT_TRUE([[window firstResponder] isKindOfClass:[NSTextView class]]);
}
TEST_F(FocusTrackerTest, DontRestoreToViewNotInWindow) {
- NSWindow* window = helper_.window();
- NSView* view3 = [[[NSView alloc] initWithFrame:NSZeroRect] autorelease];
- [helper_.contentView() addSubview:view3];
+ NSWindow* window = test_window();
+ scoped_nsobject<NSView> viewC([[NSView alloc] initWithFrame:NSZeroRect]);
+ [[window contentView] addSubview:viewC];
- ASSERT_TRUE([window makeFirstResponder:view3]);
- FocusTracker* tracker =
- [[[FocusTracker alloc] initWithWindow:window] autorelease];
+ ASSERT_TRUE([window makeFirstResponder:viewC]);
+ scoped_nsobject<FocusTracker> tracker(
+ [[FocusTracker alloc] initWithWindow:window]);
- // Give focus to |viewB_|, then remove view3 from the hierarchy and try
+ // Give focus to |viewB_|, then remove viewC from the hierarchy and try
// to restore focus. The restore should fail.
- ASSERT_TRUE([window makeFirstResponder:viewB_.get()]);
- [view3 removeFromSuperview];
+ ASSERT_TRUE([window makeFirstResponder:viewB_]);
+ [viewC removeFromSuperview];
EXPECT_FALSE([tracker restoreFocusInWindow:window]);
}
TEST_F(FocusTrackerTest, DontRestoreFocusToViewInDifferentWindow) {
- NSWindow* window = helper_.window();
- ASSERT_TRUE([window makeFirstResponder:viewA_.get()]);
- FocusTracker* tracker =
- [[[FocusTracker alloc] initWithWindow:window] autorelease];
+ NSWindow* window = test_window();
+ ASSERT_TRUE([window makeFirstResponder:viewA_]);
+ scoped_nsobject<FocusTracker> tracker(
+ [[FocusTracker alloc] initWithWindow:window]);
// Give focus to |viewB_|, then try and restore focus in a different
// window. It is ok to pass a nil NSWindow here because we only use
// it for direct comparison.
- ASSERT_TRUE([window makeFirstResponder:viewB_.get()]);
+ ASSERT_TRUE([window makeFirstResponder:viewB_]);
EXPECT_FALSE([tracker restoreFocusInWindow:nil]);
}