| Index: chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
|
| ===================================================================
|
| --- chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm (revision 32421)
|
| +++ chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm (working copy)
|
| @@ -40,40 +40,36 @@
|
| // TODO(shess): Very similar to AutocompleteTextFieldTest. Maybe
|
| // those can be shared.
|
|
|
| -class AutocompleteTextFieldEditorTest : public PlatformTest {
|
| +class AutocompleteTextFieldEditorTest : public CocoaTest {
|
| public:
|
| AutocompleteTextFieldEditorTest()
|
| : pb_([NSPasteboard pasteboardWithUniqueName]) {
|
| + }
|
| +
|
| + virtual void SetUp() {
|
| + CocoaTest::SetUp();
|
| NSRect frame = NSMakeRect(0, 0, 50, 30);
|
| - field_.reset([[AutocompleteTextField alloc] initWithFrame:frame]);
|
| + scoped_nsobject<AutocompleteTextField> field(
|
| + [[AutocompleteTextField alloc] initWithFrame:frame]);
|
| + field_ = field.get();
|
| [field_ setStringValue:@"Testing"];
|
| [field_ setObserver:&field_observer_];
|
| - [cocoa_helper_.contentView() addSubview:field_.get()];
|
| + [[test_window() contentView] addSubview:field_];
|
|
|
| // Arrange for |field_| to get the right field editor.
|
| window_delegate_.reset(
|
| [[AutocompleteTextFieldWindowTestDelegate alloc] init]);
|
| - [cocoa_helper_.window() setDelegate:window_delegate_.get()];
|
| + [test_window() setDelegate:window_delegate_.get()];
|
|
|
| // Get the field editor setup.
|
| - cocoa_helper_.makeFirstResponder(field_);
|
| - id editor = [field_.get() currentEditor];
|
| - editor_.reset([static_cast<AutocompleteTextFieldEditor*>(editor) retain]);
|
| - }
|
| + [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
|
| + editor_ = static_cast<AutocompleteTextFieldEditor*>([field_ currentEditor]);
|
|
|
| - virtual void SetUp() {
|
| - EXPECT_TRUE(editor_.get() != nil);
|
| - EXPECT_TRUE(
|
| - [editor_.get() isKindOfClass:[AutocompleteTextFieldEditor class]]);
|
| + EXPECT_TRUE(editor_);
|
| + EXPECT_TRUE([editor_ isKindOfClass:[AutocompleteTextFieldEditor class]]);
|
| }
|
|
|
| - // The removeFromSuperview call is needed to prevent crashes in
|
| - // later tests.
|
| - // TODO(shess): -removeromSuperview should not be necessary. Fix
|
| - // it. Also in autocomplete_text_field_unittest.mm.
|
| virtual ~AutocompleteTextFieldEditorTest() {
|
| - [cocoa_helper_.window() setDelegate:nil];
|
| - [field_ removeFromSuperview];
|
| [pb_ releaseGlobally];
|
| }
|
|
|
| @@ -82,22 +78,23 @@
|
| return pb_;
|
| }
|
|
|
| - CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
|
| - scoped_nsobject<AutocompleteTextFieldEditor> editor_;
|
| - scoped_nsobject<AutocompleteTextField> field_;
|
| + AutocompleteTextFieldEditor* editor_;
|
| + AutocompleteTextField* field_;
|
| MockAutocompleteTextFieldObserver field_observer_;
|
| scoped_nsobject<AutocompleteTextFieldWindowTestDelegate> window_delegate_;
|
|
|
| private:
|
| - NSPasteboard *pb_;
|
| + NSPasteboard* pb_;
|
| };
|
|
|
| +TEST_VIEW(AutocompleteTextFieldEditorTest, field_);
|
| +
|
| // Test that the field editor is linked in correctly.
|
| TEST_F(AutocompleteTextFieldEditorTest, FirstResponder) {
|
| - EXPECT_EQ(editor_.get(), [field_ currentEditor]);
|
| - EXPECT_TRUE([editor_.get() isDescendantOf:field_.get()]);
|
| - EXPECT_EQ([editor_.get() delegate], field_.get());
|
| - EXPECT_EQ([editor_.get() observer], [field_.get() observer]);
|
| + EXPECT_EQ(editor_, [field_ currentEditor]);
|
| + EXPECT_TRUE([editor_ isDescendantOf:field_]);
|
| + EXPECT_EQ([editor_ delegate], field_);
|
| + EXPECT_EQ([editor_ observer], [field_ observer]);
|
| }
|
|
|
| TEST_F(AutocompleteTextFieldEditorTest, CutCopyTest) {
|
| @@ -107,47 +104,29 @@
|
| NSString* test_string_1 = @"astring";
|
| NSString* test_string_2 = @"another string";
|
|
|
| - [editor_.get() setRichText:YES];
|
| + [editor_ setRichText:YES];
|
|
|
| // Put some text on the clipboard.
|
| - [editor_.get() setString:test_string_1];
|
| - [editor_.get() selectAll:nil];
|
| - [editor_.get() alignRight:nil]; // Add a rich text attribute.
|
| + [editor_ setString:test_string_1];
|
| + [editor_ selectAll:nil];
|
| + [editor_ alignRight:nil]; // Add a rich text attribute.
|
| ASSERT_TRUE(NoRichTextOnClipboard(clipboard()));
|
|
|
| // Check that copying it works and we only get plain text.
|
| - [editor_.get() performCopy:clipboard()];
|
| + [editor_ performCopy:clipboard()];
|
| ASSERT_TRUE(NoRichTextOnClipboard(clipboard()));
|
| ASSERT_TRUE(ClipboardContainsText(clipboard(), test_string_1));
|
|
|
| // Check that cutting it works and we only get plain text.
|
| - [editor_.get() setString:test_string_2];
|
| - [editor_.get() selectAll:nil];
|
| - [editor_.get() alignLeft:nil]; // Add a rich text attribute.
|
| - [editor_.get() performCut:clipboard()];
|
| + [editor_ setString:test_string_2];
|
| + [editor_ selectAll:nil];
|
| + [editor_ alignLeft:nil]; // Add a rich text attribute.
|
| + [editor_ performCut:clipboard()];
|
| ASSERT_TRUE(NoRichTextOnClipboard(clipboard()));
|
| ASSERT_TRUE(ClipboardContainsText(clipboard(), test_string_2));
|
| - ASSERT_EQ([[editor_.get() textStorage] length], 0U);
|
| + ASSERT_EQ([[editor_ textStorage] length], 0U);
|
| }
|
|
|
| -// Test adding/removing from the view hierarchy, mostly to ensure nothing
|
| -// leaks or crashes.
|
| -TEST_F(AutocompleteTextFieldEditorTest, AddRemove) {
|
| - EXPECT_EQ(cocoa_helper_.contentView(), [field_ superview]);
|
| -
|
| - // TODO(shess): For some reason, -removeFromSuperview while |field_|
|
| - // is first-responder causes AutocompleteTextFieldWindowTestDelegate
|
| - // -windowWillReturnFieldEditor:toObject: to be passed an object of
|
| - // class AutocompleteTextFieldEditor. Which is weird. Changing
|
| - // first responder will remove the field editor.
|
| - cocoa_helper_.makeFirstResponder(nil);
|
| - EXPECT_FALSE([field_.get() currentEditor]);
|
| - EXPECT_FALSE([editor_.get() superview]);
|
| -
|
| - [field_.get() removeFromSuperview];
|
| - EXPECT_FALSE([field_.get() superview]);
|
| -}
|
| -
|
| // Test drawing, mostly to ensure nothing leaks or crashes.
|
| TEST_F(AutocompleteTextFieldEditorTest, Display) {
|
| [field_ display];
|
| @@ -157,13 +136,13 @@
|
| // Test that -paste: is correctly delegated to the observer.
|
| TEST_F(AutocompleteTextFieldEditorTest, Paste) {
|
| EXPECT_CALL(field_observer_, OnPaste());
|
| - [editor_.get() paste:nil];
|
| + [editor_ paste:nil];
|
| }
|
|
|
| // Test that -pasteAndGo: is correctly delegated to the observer.
|
| TEST_F(AutocompleteTextFieldEditorTest, PasteAndGo) {
|
| EXPECT_CALL(field_observer_, OnPasteAndGo());
|
| - [editor_.get() pasteAndGo:nil];
|
| + [editor_ pasteAndGo:nil];
|
| }
|
|
|
| // Test that the menu is constructed correctly when CanPasteAndGo().
|
| @@ -173,7 +152,7 @@
|
| EXPECT_CALL(field_observer_, GetPasteActionStringId())
|
| .WillOnce(Return(IDS_PASTE_AND_GO));
|
|
|
| - NSMenu* menu = [editor_.get() menuForEvent:nil];
|
| + NSMenu* menu = [editor_ menuForEvent:nil];
|
| NSArray* items = [menu itemArray];
|
| ASSERT_EQ([items count], 6U);
|
| // TODO(shess): Check the titles, too?
|
| @@ -194,7 +173,7 @@
|
| EXPECT_CALL(field_observer_, CanPasteAndGo())
|
| .WillOnce(Return(false));
|
|
|
| - NSMenu* menu = [editor_.get() menuForEvent:nil];
|
| + NSMenu* menu = [editor_ menuForEvent:nil];
|
| NSArray* items = [menu itemArray];
|
| ASSERT_EQ([items count], 5U);
|
| // TODO(shess): Check the titles, too?
|
| @@ -212,8 +191,8 @@
|
| // Test that the menu is constructed correctly when field isn't
|
| // editable.
|
| TEST_F(AutocompleteTextFieldEditorTest, CanPasteAndGoMenuNotEditable) {
|
| - [field_.get() setEditable:NO];
|
| - [editor_.get() setEditable:NO];
|
| + [field_ setEditable:NO];
|
| + [editor_ setEditable:NO];
|
|
|
| // Never call these when not editable.
|
| EXPECT_CALL(field_observer_, CanPasteAndGo())
|
| @@ -221,7 +200,7 @@
|
| EXPECT_CALL(field_observer_, GetPasteActionStringId())
|
| .Times(0);
|
|
|
| - NSMenu* menu = [editor_.get() menuForEvent:nil];
|
| + NSMenu* menu = [editor_ menuForEvent:nil];
|
| NSArray* items = [menu itemArray];
|
| ASSERT_EQ([items count], 3U);
|
| // TODO(shess): Check the titles, too?
|
|
|