OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/app/chrome_command_ids.h" // IDC_* | 10 #include "chrome/app/chrome_command_ids.h" // IDC_* |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 // Test that -copy: is correctly delegated to the observer. | 196 // Test that -copy: is correctly delegated to the observer. |
197 TEST_F(AutocompleteTextFieldEditorObserverTest, Copy) { | 197 TEST_F(AutocompleteTextFieldEditorObserverTest, Copy) { |
198 EXPECT_CALL(field_observer_, CanCopy()) | 198 EXPECT_CALL(field_observer_, CanCopy()) |
199 .WillOnce(Return(true)); | 199 .WillOnce(Return(true)); |
200 EXPECT_CALL(field_observer_, CopyToPasteboard(A<NSPasteboard*>())) | 200 EXPECT_CALL(field_observer_, CopyToPasteboard(A<NSPasteboard*>())) |
201 .Times(1); | 201 .Times(1); |
202 [editor_ copy:nil]; | 202 [editor_ copy:nil]; |
203 } | 203 } |
204 | 204 |
| 205 // Test that -copyURL: is correctly delegated to the observer. |
| 206 TEST_F(AutocompleteTextFieldEditorObserverTest, CopyURL) { |
| 207 EXPECT_CALL(field_observer_, CanCopy()).WillOnce(Return(true)); |
| 208 EXPECT_CALL(field_observer_, |
| 209 CopyURLToPasteboard(A<NSPasteboard*>())).Times(1); |
| 210 [editor_ copyURL:nil]; |
| 211 } |
| 212 |
205 // Test that -cut: is correctly delegated to the observer and clears | 213 // Test that -cut: is correctly delegated to the observer and clears |
206 // the text field. | 214 // the text field. |
207 TEST_F(AutocompleteTextFieldEditorObserverTest, Cut) { | 215 TEST_F(AutocompleteTextFieldEditorObserverTest, Cut) { |
208 // Sets a string in the field. | 216 // Sets a string in the field. |
209 NSString* test_string = @"astring"; | 217 NSString* test_string = @"astring"; |
210 EXPECT_CALL(field_observer_, OnDidBeginEditing()); | 218 EXPECT_CALL(field_observer_, OnDidBeginEditing()); |
211 EXPECT_CALL(field_observer_, OnBeforeChange()); | 219 EXPECT_CALL(field_observer_, OnBeforeChange()); |
212 EXPECT_CALL(field_observer_, OnDidChange()); | 220 EXPECT_CALL(field_observer_, OnDidChange()); |
213 EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(A<NSRange>())) | 221 EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(A<NSRange>())) |
214 .WillRepeatedly(ReturnArg<0>()); | 222 .WillRepeatedly(ReturnArg<0>()); |
(...skipping 12 matching lines...) Expand all Loading... |
227 } | 235 } |
228 | 236 |
229 // Test that -pasteAndGo: is correctly delegated to the observer. | 237 // Test that -pasteAndGo: is correctly delegated to the observer. |
230 TEST_F(AutocompleteTextFieldEditorObserverTest, PasteAndGo) { | 238 TEST_F(AutocompleteTextFieldEditorObserverTest, PasteAndGo) { |
231 EXPECT_CALL(field_observer_, OnPasteAndGo()); | 239 EXPECT_CALL(field_observer_, OnPasteAndGo()); |
232 [editor_ pasteAndGo:nil]; | 240 [editor_ pasteAndGo:nil]; |
233 } | 241 } |
234 | 242 |
235 // Test that the menu is constructed correctly when CanPasteAndGo(). | 243 // Test that the menu is constructed correctly when CanPasteAndGo(). |
236 TEST_F(AutocompleteTextFieldEditorObserverTest, CanPasteAndGoMenu) { | 244 TEST_F(AutocompleteTextFieldEditorObserverTest, CanPasteAndGoMenu) { |
237 EXPECT_CALL(field_observer_, CanPasteAndGo()) | 245 EXPECT_CALL(field_observer_, ShouldAddCopyURL()).WillOnce(Return(false)); |
238 .WillOnce(Return(true)); | 246 EXPECT_CALL(field_observer_, CanPasteAndGo()).WillOnce(Return(true)); |
239 EXPECT_CALL(field_observer_, GetPasteActionStringId()) | 247 EXPECT_CALL(field_observer_, GetPasteActionStringId()) |
240 .WillOnce(Return(IDS_PASTE_AND_GO)); | 248 .WillOnce(Return(IDS_PASTE_AND_GO)); |
241 | 249 |
242 NSMenu* menu = [editor_ menuForEvent:nil]; | 250 NSMenu* menu = [editor_ menuForEvent:nil]; |
243 NSArray* items = [menu itemArray]; | 251 NSArray* items = [menu itemArray]; |
244 ASSERT_EQ([items count], 6U); | 252 ASSERT_EQ([items count], 6U); |
245 // TODO(shess): Check the titles, too? | 253 // TODO(shess): Check the titles, too? |
246 NSUInteger i = 0; // Use an index to make future changes easier. | 254 NSUInteger i = 0; // Use an index to make future changes easier. |
247 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); | 255 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); |
248 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); | 256 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); |
249 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); | 257 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); |
250 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(pasteAndGo:)); | 258 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(pasteAndGo:)); |
251 EXPECT_TRUE([[items objectAtIndex:i++] isSeparatorItem]); | 259 EXPECT_TRUE([[items objectAtIndex:i++] isSeparatorItem]); |
252 | 260 |
253 EXPECT_EQ([[items objectAtIndex:i] action], @selector(commandDispatch:)); | 261 EXPECT_EQ([[items objectAtIndex:i] action], @selector(commandDispatch:)); |
254 EXPECT_EQ([[items objectAtIndex:i] tag], IDC_EDIT_SEARCH_ENGINES); | 262 EXPECT_EQ([[items objectAtIndex:i] tag], IDC_EDIT_SEARCH_ENGINES); |
255 i++; | 263 i++; |
256 } | 264 } |
257 | 265 |
258 // Test that the menu is constructed correctly when !CanPasteAndGo(). | 266 // Test that the menu is constructed correctly when !CanPasteAndGo(). |
259 TEST_F(AutocompleteTextFieldEditorObserverTest, CannotPasteAndGoMenu) { | 267 TEST_F(AutocompleteTextFieldEditorObserverTest, CannotPasteAndGoMenu) { |
260 EXPECT_CALL(field_observer_, CanPasteAndGo()) | 268 EXPECT_CALL(field_observer_, ShouldAddCopyURL()).WillOnce(Return(false)); |
261 .WillOnce(Return(false)); | 269 EXPECT_CALL(field_observer_, CanPasteAndGo()).WillOnce(Return(false)); |
262 | 270 |
263 NSMenu* menu = [editor_ menuForEvent:nil]; | 271 NSMenu* menu = [editor_ menuForEvent:nil]; |
264 NSArray* items = [menu itemArray]; | 272 NSArray* items = [menu itemArray]; |
265 ASSERT_EQ([items count], 5U); | 273 ASSERT_EQ([items count], 5U); |
266 // TODO(shess): Check the titles, too? | 274 // TODO(shess): Check the titles, too? |
267 NSUInteger i = 0; // Use an index to make future changes easier. | 275 NSUInteger i = 0; // Use an index to make future changes easier. |
268 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); | 276 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); |
269 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); | 277 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); |
270 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); | 278 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); |
271 EXPECT_TRUE([[items objectAtIndex:i++] isSeparatorItem]); | 279 EXPECT_TRUE([[items objectAtIndex:i++] isSeparatorItem]); |
(...skipping 18 matching lines...) Expand all Loading... |
290 NSMenu* menu = [editor_ menuForEvent:nil]; | 298 NSMenu* menu = [editor_ menuForEvent:nil]; |
291 NSArray* items = [menu itemArray]; | 299 NSArray* items = [menu itemArray]; |
292 ASSERT_EQ([items count], 3U); | 300 ASSERT_EQ([items count], 3U); |
293 // TODO(shess): Check the titles, too? | 301 // TODO(shess): Check the titles, too? |
294 NSUInteger i = 0; // Use an index to make future changes easier. | 302 NSUInteger i = 0; // Use an index to make future changes easier. |
295 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); | 303 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); |
296 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); | 304 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); |
297 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); | 305 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); |
298 } | 306 } |
299 | 307 |
| 308 // Test that the menu is constructed correctly when ShouldAddCopyURL() returns |
| 309 // true. |
| 310 TEST_F(AutocompleteTextFieldEditorObserverTest, ShouldAllowCopyURLMenu) { |
| 311 EXPECT_CALL(field_observer_, ShouldAddCopyURL()).WillOnce(Return(true)); |
| 312 EXPECT_CALL(field_observer_, CanPasteAndGo()).WillOnce(Return(false)); |
| 313 |
| 314 NSMenu* menu = [editor_ menuForEvent:nil]; |
| 315 NSArray* items = [menu itemArray]; |
| 316 ASSERT_EQ([items count], 6U); |
| 317 // TODO(shess): Check the titles, too? |
| 318 NSUInteger i = 0; // Use an index to make future changes easier. |
| 319 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(cut:)); |
| 320 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copy:)); |
| 321 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(copyURL:)); |
| 322 EXPECT_EQ([[items objectAtIndex:i++] action], @selector(paste:)); |
| 323 EXPECT_TRUE([[items objectAtIndex:i++] isSeparatorItem]); |
| 324 |
| 325 EXPECT_EQ([[items objectAtIndex:i] action], @selector(commandDispatch:)); |
| 326 EXPECT_EQ([[items objectAtIndex:i] tag], IDC_EDIT_SEARCH_ENGINES); |
| 327 } |
| 328 |
| 329 |
300 } // namespace | 330 } // namespace |
OLD | NEW |