diff options
Diffstat (limited to 'chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm index bdb4962..c4ec346 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm @@ -9,9 +9,12 @@ #include "base/string_util.h" #import "chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +using ::testing::Return; + namespace { int NumTypesOnPasteboard(NSPasteboard* pb) { @@ -156,4 +159,43 @@ TEST_F(AutocompleteTextFieldEditorTest, Paste) { [editor_.get() paste:nil]; } +// Test that -pasteAndGo: is correctly delegated to the observer. +TEST_F(AutocompleteTextFieldEditorTest, PasteAndGo) { + EXPECT_CALL(field_observer_, OnPasteAndGo()); + [editor_.get() pasteAndGo:nil]; +} + +// Test that the menu is constructed correctly when CanPasteAndGo(). +TEST_F(AutocompleteTextFieldEditorTest, CanPasteAndGoMenu) { + EXPECT_CALL(field_observer_, CanPasteAndGo()) + .WillOnce(Return(true)); + EXPECT_CALL(field_observer_, GetPasteActionStringId()) + .WillOnce(Return(IDS_PASTE_AND_GO)); + + NSMenu* menu = [editor_.get() menuForEvent:nil]; + NSArray* items = [menu itemArray]; + ASSERT_EQ([items count], 4U); + // TODO(shess): Check the titles, too? + NSUInteger i = 0; // Use an index to make future changes easier. + EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); + EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); + EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); + EXPECT_EQ([[items objectAtIndex:i++] action], @selector(pasteAndGo:)); +} + +// Test that the menu is constructed correctly when !CanPasteAndGo(). +TEST_F(AutocompleteTextFieldEditorTest, CannotPasteAndGoMenu) { + EXPECT_CALL(field_observer_, CanPasteAndGo()) + .WillOnce(Return(false)); + + NSMenu* menu = [editor_.get() menuForEvent:nil]; + NSArray* items = [menu itemArray]; + ASSERT_EQ([items count], 3U); + // TODO(shess): Check the titles, too? + NSUInteger i = 0; // Use an index to make future changes easier. + EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); + EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); + EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); +} + } // namespace |