summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 17:18:53 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 17:18:53 +0000
commit62feb0592aa9a25a44a117db487586e6e538593f (patch)
tree4f2b779fb326f5536683c6553452b224570e0f4a /chrome/browser
parent73814b59b4365a36546f63758c95d83adee8c93a (diff)
downloadchromium_src-62feb0592aa9a25a44a117db487586e6e538593f.zip
chromium_src-62feb0592aa9a25a44a117db487586e6e538593f.tar.gz
chromium_src-62feb0592aa9a25a44a117db487586e6e538593f.tar.bz2
[Mac] Remove paste-and-go from omnibox context menu in popup windows.
The field is not editable, and this is an editing item. http://crbug.com/20246 TEST=www.popuptest.com, test #2, right-click in the popup's omnibox. Should not have paste-and-go/paste-and-search menu item. Review URL: http://codereview.chromium.org/219018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor.mm30
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm22
2 files changed, 39 insertions, 13 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.mm b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
index 9cefff9..8bb2e8a 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
@@ -88,19 +88,23 @@
action:@selector(paste:)
keyEquivalent:@""];
- // Paste and go/search.
- AutocompleteTextFieldObserver* observer = [self observer];
- DCHECK(observer);
- if (observer && observer->CanPasteAndGo()) {
- const int string_id = observer->GetPasteActionStringId();
- NSString* label = l10n_util::GetNSStringWithFixup(string_id);
-
- // TODO(rohitrao): If the clipboard is empty, should we show a
- // greyed-out "Paste and Go" or nothing at all?
- if (label) {
- [menu addItemWithTitle:label
- action:@selector(pasteAndGo:)
- keyEquivalent:@""];
+ // TODO(shess): If the control is not editable, should we show a
+ // greyed-out "Paste and Go"?
+ if ([self isEditable]) {
+ // Paste and go/search.
+ AutocompleteTextFieldObserver* observer = [self observer];
+ DCHECK(observer);
+ if (observer && observer->CanPasteAndGo()) {
+ const int string_id = observer->GetPasteActionStringId();
+ NSString* label = l10n_util::GetNSStringWithFixup(string_id);
+
+ // TODO(rohitrao): If the clipboard is empty, should we show a
+ // greyed-out "Paste and Go" or nothing at all?
+ if (label) {
+ [menu addItemWithTitle:label
+ action:@selector(pasteAndGo:)
+ keyEquivalent:@""];
+ }
}
}
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
index c4ec346..e45fdd2 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
@@ -198,4 +198,26 @@ TEST_F(AutocompleteTextFieldEditorTest, CannotPasteAndGoMenu) {
EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:));
}
+// Test that the menu is constructed correctly when field isn't
+// editable.
+TEST_F(AutocompleteTextFieldEditorTest, CanPasteAndGoMenuNotEditable) {
+ [field_.get() setEditable:NO];
+ [editor_.get() setEditable:NO];
+
+ // Never call these when not editable.
+ EXPECT_CALL(field_observer_, CanPasteAndGo())
+ .Times(0);
+ EXPECT_CALL(field_observer_, GetPasteActionStringId())
+ .Times(0);
+
+ 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