Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: chrome/browser/cocoa/location_bar/autocomplete_text_field_unittest.mm

Issue 2854051: [Mac] Convert omnibox keyword hint to decoration. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #import "base/cocoa_protocols_mac.h" 8 #import "base/cocoa_protocols_mac.h"
9 #include "base/scoped_nsobject.h" 9 #include "base/scoped_nsobject.h"
10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" 10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h"
(...skipping 10 matching lines...) Expand all
21 using ::testing::InSequence; 21 using ::testing::InSequence;
22 using ::testing::Return; 22 using ::testing::Return;
23 using ::testing::StrictMock; 23 using ::testing::StrictMock;
24 using ::testing::_; 24 using ::testing::_;
25 25
26 namespace { 26 namespace {
27 27
28 class MockDecoration : public LocationBarDecoration { 28 class MockDecoration : public LocationBarDecoration {
29 public: 29 public:
30 virtual CGFloat GetWidthForSpace(CGFloat width) { return 20.0; } 30 virtual CGFloat GetWidthForSpace(CGFloat width) { return 20.0; }
31 virtual bool IsVisible() const { return visible_; }
32 void SetVisible(bool visible) { visible_ = visible; }
33 31
34 virtual void DrawInFrame(NSRect frame, NSView* control_view) { ; } 32 virtual void DrawInFrame(NSRect frame, NSView* control_view) { ; }
35 virtual bool AcceptsMousePress() { return true; } 33 MOCK_METHOD0(AcceptsMousePress, bool());
36 MOCK_METHOD1(OnMousePressed, bool(NSRect frame)); 34 MOCK_METHOD1(OnMousePressed, bool(NSRect frame));
37 MOCK_METHOD0(GetMenu, NSMenu*()); 35 MOCK_METHOD0(GetMenu, NSMenu*());
38
39 bool visible_;
40 }; 36 };
41 37
42 // Mock up an incrementing event number. 38 // Mock up an incrementing event number.
43 NSUInteger eventNumber = 0; 39 NSUInteger eventNumber = 0;
44 40
45 // Create an event of the indicated |type| at |point| within |view|. 41 // Create an event of the indicated |type| at |point| within |view|.
46 // TODO(shess): Would be nice to have a MockApplication which provided 42 // TODO(shess): Would be nice to have a MockApplication which provided
47 // nifty accessors to create these things and inject them. It could 43 // nifty accessors to create these things and inject them. It could
48 // even provide functions for "Click and drag mouse from point A to 44 // even provide functions for "Click and drag mouse from point A to
49 // point B". 45 // point B".
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 200 }
205 201
206 // Test drawing, mostly to ensure nothing leaks or crashes. 202 // Test drawing, mostly to ensure nothing leaks or crashes.
207 TEST_F(AutocompleteTextFieldTest, Display) { 203 TEST_F(AutocompleteTextFieldTest, Display) {
208 [field_ display]; 204 [field_ display];
209 205
210 // Test focussed drawing. 206 // Test focussed drawing.
211 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; 207 [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
212 [field_ display]; 208 [field_ display];
213 [test_window() clearPretendKeyWindowAndFirstResponder]; 209 [test_window() clearPretendKeyWindowAndFirstResponder];
214
215 // Test display of various cell configurations.
216 AutocompleteTextFieldCell* cell = [field_ cell];
217
218 [cell setSearchHintString:@"Type to search" availableWidth:kWidth];
219 [field_ display];
220
221 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
222 [cell setKeywordHintPrefix:@"prefix" image:image suffix:@"suffix"
223 availableWidth:kWidth];
224 [field_ display];
225
226 [cell clearHint];
227
228 [field_ display];
229 } 210 }
230 211
231 TEST_F(AutocompleteTextFieldObserverTest, FlagsChanged) { 212 TEST_F(AutocompleteTextFieldObserverTest, FlagsChanged) {
232 InSequence dummy; // Call mock in exactly the order specified. 213 InSequence dummy; // Call mock in exactly the order specified.
233 214
234 // Test without Control key down, but some other modifier down. 215 // Test without Control key down, but some other modifier down.
235 EXPECT_CALL(field_observer_, OnControlKeyChanged(false)); 216 EXPECT_CALL(field_observer_, OnControlKeyChanged(false));
236 [field_ flagsChanged:KeyDownEventWithFlags(NSShiftKeyMask)]; 217 [field_ flagsChanged:KeyDownEventWithFlags(NSShiftKeyMask)];
237 218
238 // Test with Control key down. 219 // Test with Control key down.
(...skipping 25 matching lines...) Expand all
264 EXPECT_CALL(field_observer_, OnFrameChanged()); 245 EXPECT_CALL(field_observer_, OnFrameChanged());
265 NSRect frame = [field_ frame]; 246 NSRect frame = [field_ frame];
266 frame.size.width += 10.0; 247 frame.size.width += 10.0;
267 [field_ setFrame:frame]; 248 [field_ setFrame:frame];
268 } 249 }
269 250
270 // Test that the field editor gets the same bounds when focus is 251 // Test that the field editor gets the same bounds when focus is
271 // delivered by the standard focusing machinery, or by 252 // delivered by the standard focusing machinery, or by
272 // -resetFieldEditorFrameIfNeeded. 253 // -resetFieldEditorFrameIfNeeded.
273 TEST_F(AutocompleteTextFieldTest, ResetFieldEditorBase) { 254 TEST_F(AutocompleteTextFieldTest, ResetFieldEditorBase) {
274 AutocompleteTextFieldCell* cell = [field_ cell];
275
276 // Capture the editor frame resulting from the standard focus 255 // Capture the editor frame resulting from the standard focus
277 // machinery. 256 // machinery.
278 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; 257 [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
279 const NSRect baseEditorFrame(EditorFrame()); 258 const NSRect baseEditorFrame = EditorFrame();
280 259
281 // Setting a hint should result in a strictly smaller editor frame. 260 // A decoration should result in a strictly smaller editor frame.
282 EXPECT_FALSE([cell hintString]); 261 mock_left_decoration_.SetVisible(true);
283 [cell setSearchHintString:@"search hint" availableWidth:kWidth];
284 EXPECT_TRUE([cell hintString]);
285 [field_ resetFieldEditorFrameIfNeeded]; 262 [field_ resetFieldEditorFrameIfNeeded];
286 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame())); 263 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame()));
287 EXPECT_TRUE(NSContainsRect(baseEditorFrame, EditorFrame())); 264 EXPECT_TRUE(NSContainsRect(baseEditorFrame, EditorFrame()));
288 265
289 // Clearing hint string and using -resetFieldEditorFrameIfNeeded 266 // Removing the decoration and using -resetFieldEditorFrameIfNeeded
290 // should result in the same frame as the standard focus machinery. 267 // should result in the same frame as the standard focus machinery.
291 [cell clearHint]; 268 mock_left_decoration_.SetVisible(false);
292 EXPECT_FALSE([cell hintString]);
293 [field_ resetFieldEditorFrameIfNeeded]; 269 [field_ resetFieldEditorFrameIfNeeded];
294 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame())); 270 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame()));
295 } 271 }
296 272
297 // Test that the field editor gets the same bounds when focus is 273 // Test that the field editor gets the same bounds when focus is
298 // delivered by the standard focusing machinery, or by 274 // delivered by the standard focusing machinery, or by
299 // -resetFieldEditorFrameIfNeeded. 275 // -resetFieldEditorFrameIfNeeded, this time with a decoration
300 TEST_F(AutocompleteTextFieldTest, ResetFieldEditorSearchHint) { 276 // pre-loaded.
301 AutocompleteTextFieldCell* cell = [field_ cell]; 277 TEST_F(AutocompleteTextFieldTest, ResetFieldEditorWithDecoration) {
302
303 NSString* const kHintString = @"Type to search";
304
305 // Capture the editor frame resulting from the standard focus
306 // machinery.
307 [cell setSearchHintString:kHintString availableWidth:kWidth];
308 EXPECT_TRUE([cell hintString]);
309 [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
310 const NSRect baseEditorFrame(EditorFrame());
311
312 // Clearing the hint should result in a strictly larger editor
313 // frame.
314 [cell clearHint];
315 EXPECT_FALSE([cell hintString]);
316 [field_ resetFieldEditorFrameIfNeeded];
317 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame()));
318 EXPECT_TRUE(NSContainsRect(EditorFrame(), baseEditorFrame));
319
320 // Setting the same hint string and using
321 // -resetFieldEditorFrameIfNeeded should result in the same frame as
322 // the standard focus machinery.
323 [cell setSearchHintString:kHintString availableWidth:kWidth];
324 EXPECT_TRUE([cell hintString]);
325 [field_ resetFieldEditorFrameIfNeeded];
326 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame()));
327 }
328
329 // Test that the field editor gets the same bounds when focus is
330 // delivered by the standard focusing machinery, or by
331 // -resetFieldEditorFrameIfNeeded.
332 TEST_F(AutocompleteTextFieldTest, ResetFieldEditorKeywordHint) {
333 AutocompleteTextFieldCell* cell = [field_ cell]; 278 AutocompleteTextFieldCell* cell = [field_ cell];
334 279
335 // Make sure decoration isn't already visible, then make it visible. 280 // Make sure decoration isn't already visible, then make it visible.
336 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ 281 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_
337 inFrame:[field_ bounds]])); 282 inFrame:[field_ bounds]]));
338 mock_left_decoration_.SetVisible(true); 283 mock_left_decoration_.SetVisible(true);
339 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ 284 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_
340 inFrame:[field_ bounds]])); 285 inFrame:[field_ bounds]]));
341 286
342 // Capture the editor frame resulting from the standard focus 287 // Capture the editor frame resulting from the standard focus
343 // machinery. 288 // machinery.
344 289
345 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; 290 [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
346 const NSRect baseEditorFrame(EditorFrame()); 291 const NSRect baseEditorFrame = EditorFrame();
347 292
348 // When the decoration is not visible the frame should be strictly larger. 293 // When the decoration is not visible the frame should be strictly larger.
349 mock_left_decoration_.SetVisible(false); 294 mock_left_decoration_.SetVisible(false);
350 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ 295 EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_
351 inFrame:[field_ bounds]])); 296 inFrame:[field_ bounds]]));
352 [field_ resetFieldEditorFrameIfNeeded]; 297 [field_ resetFieldEditorFrameIfNeeded];
353 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame())); 298 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame()));
354 EXPECT_TRUE(NSContainsRect(EditorFrame(), baseEditorFrame)); 299 EXPECT_TRUE(NSContainsRect(EditorFrame(), baseEditorFrame));
355 300
356 // When the decoration is visible, -resetFieldEditorFrameIfNeeded 301 // When the decoration is visible, -resetFieldEditorFrameIfNeeded
357 // should result in the same frame as the standard focus machinery. 302 // should result in the same frame as the standard focus machinery.
358 mock_left_decoration_.SetVisible(true); 303 mock_left_decoration_.SetVisible(true);
359 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_ 304 EXPECT_FALSE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_
360 inFrame:[field_ bounds]])); 305 inFrame:[field_ bounds]]));
361 306
362 [field_ resetFieldEditorFrameIfNeeded]; 307 [field_ resetFieldEditorFrameIfNeeded];
363 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame())); 308 EXPECT_TRUE(NSEqualRects(baseEditorFrame, EditorFrame()));
364 } 309 }
365 310
366 // Test that resetting the field editor bounds does not cause untoward 311 // Test that resetting the field editor bounds does not cause untoward
367 // messages to the field's observer. 312 // messages to the field's observer.
368 TEST_F(AutocompleteTextFieldObserverTest, ResetFieldEditorContinuesEditing) { 313 TEST_F(AutocompleteTextFieldObserverTest, ResetFieldEditorContinuesEditing) {
369 EXPECT_CALL(field_observer_, OnSetFocus(false)); 314 EXPECT_CALL(field_observer_, OnSetFocus(false));
370 // Becoming first responder doesn't begin editing. 315 // Becoming first responder doesn't begin editing.
371 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; 316 [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
317 const NSRect baseEditorFrame = EditorFrame();
372 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); 318 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]);
373 EXPECT_TRUE(nil != editor); 319 EXPECT_TRUE(nil != editor);
374 320
375 // This should begin editing and indicate a change. 321 // This should begin editing and indicate a change.
376 EXPECT_CALL(field_observer_, OnDidBeginEditing()); 322 EXPECT_CALL(field_observer_, OnDidBeginEditing());
377 EXPECT_CALL(field_observer_, OnDidChange()); 323 EXPECT_CALL(field_observer_, OnDidChange());
378 [editor shouldChangeTextInRange:NSMakeRange(0, 0) replacementString:@""]; 324 [editor shouldChangeTextInRange:NSMakeRange(0, 0) replacementString:@""];
379 [editor didChangeText]; 325 [editor didChangeText];
380 326
381 // No messages to |field_observer_| when resetting the frame. 327 // No messages to |field_observer_| when the frame actually changes.
382 AutocompleteTextFieldCell* cell = [field_ cell]; 328 mock_left_decoration_.SetVisible(true);
383 [cell setSearchHintString:@"Type to search" availableWidth:kWidth];
384 [field_ resetFieldEditorFrameIfNeeded]; 329 [field_ resetFieldEditorFrameIfNeeded];
330 EXPECT_FALSE(NSEqualRects(baseEditorFrame, EditorFrame()));
385 } 331 }
386 332
387 // Clicking in the search hint should put the caret in the rightmost 333 // Clicking in a right-hand decoration which does not handle the mouse
388 // position. 334 // puts the caret rightmost.
389 TEST_F(AutocompleteTextFieldTest, ClickSearchHintPutsCaretRightmost) { 335 TEST_F(AutocompleteTextFieldTest, ClickRightDecorationPutsCaretRightmost) {
336 // Decoration does not handle the mouse event, so the cell should
337 // process it. Called at least once.
338 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress())
339 .WillOnce(Return(false))
340 .WillRepeatedly(Return(false));
341
390 // Set the decoration before becoming responder. 342 // Set the decoration before becoming responder.
391 EXPECT_FALSE([field_ currentEditor]); 343 EXPECT_FALSE([field_ currentEditor]);
392 AutocompleteTextFieldCell* cell = [field_ cell]; 344 mock_right_decoration_.SetVisible(true);
393 [cell setSearchHintString:@"Type to search" availableWidth:kWidth];
394 345
395 // Can't rely on the window machinery to make us first responder, 346 // Make first responder should select all.
396 // here.
397 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; 347 [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
398 EXPECT_TRUE([field_ currentEditor]); 348 EXPECT_TRUE([field_ currentEditor]);
349 const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]);
350 EXPECT_TRUE(NSEqualRanges(allRange, [[field_ currentEditor] selectedRange]));
399 351
400 const NSPoint point(NSMakePoint(300.0 - 20.0, 5.0)); 352 // Generate a click on the decoration.
401 NSEvent* downEvent(Event(field_, point, NSLeftMouseDown)); 353 AutocompleteTextFieldCell* cell = [field_ cell];
402 NSEvent* upEvent(Event(field_, point, NSLeftMouseUp)); 354 const NSRect bounds = [field_ bounds];
355 const NSRect iconFrame =
356 [cell frameForDecoration:&mock_right_decoration_ inFrame:bounds];
357 const NSPoint point = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
358 NSEvent* downEvent = Event(field_, point, NSLeftMouseDown);
359 NSEvent* upEvent = Event(field_, point, NSLeftMouseUp);
403 [NSApp postEvent:upEvent atStart:YES]; 360 [NSApp postEvent:upEvent atStart:YES];
404 [field_ mouseDown:downEvent]; 361 [field_ mouseDown:downEvent];
405 const NSRange selectedRange([[field_ currentEditor] selectedRange]); 362
406 EXPECT_EQ(selectedRange.location, [[field_ stringValue] length]); 363 // Selection should be a right-hand-side caret.
407 EXPECT_EQ(selectedRange.length, 0U); 364 EXPECT_TRUE(NSEqualRanges(NSMakeRange([[field_ stringValue] length], 0),
365 [[field_ currentEditor] selectedRange]));
408 } 366 }
409 367
410 // Clicking in a left-side decoration which doesn't handle the event 368 // Clicking in a left-side decoration which doesn't handle the event
411 // puts the selection in the leftmost position. 369 // puts the selection in the leftmost position.
412 TEST_F(AutocompleteTextFieldTest, ClickLeftDecorationPutsCaretLeftmost) { 370 TEST_F(AutocompleteTextFieldTest, ClickLeftDecorationPutsCaretLeftmost) {
413 // Decoration does not handle the mouse event, so the cell should 371 // Decoration does not handle the mouse event, so the cell should
414 // process it. 372 // process it. Called at least once.
415 EXPECT_CALL(mock_left_decoration_, OnMousePressed(_)) 373 EXPECT_CALL(mock_left_decoration_, AcceptsMousePress())
374 .WillOnce(Return(false))
416 .WillRepeatedly(Return(false)); 375 .WillRepeatedly(Return(false));
417 376
418 // Set the decoration before becoming responder. 377 // Set the decoration before becoming responder.
419 EXPECT_FALSE([field_ currentEditor]); 378 EXPECT_FALSE([field_ currentEditor]);
420 mock_left_decoration_.SetVisible(true); 379 mock_left_decoration_.SetVisible(true);
421 380
422 // Make first responder should select all. 381 // Make first responder should select all.
423 [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; 382 [test_window() makePretendKeyWindowAndSetFirstResponder:field_];
424 EXPECT_TRUE([field_ currentEditor]); 383 EXPECT_TRUE([field_ currentEditor]);
425 const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]); 384 const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]);
426 EXPECT_TRUE(NSEqualRanges(allRange, [[field_ currentEditor] selectedRange])); 385 EXPECT_TRUE(NSEqualRanges(allRange, [[field_ currentEditor] selectedRange]));
427 386
428 // Generate a click on the decoration. 387 // Generate a click on the decoration.
429 AutocompleteTextFieldCell* cell = [field_ cell]; 388 AutocompleteTextFieldCell* cell = [field_ cell];
389 const NSRect bounds = [field_ bounds];
430 const NSRect iconFrame = 390 const NSRect iconFrame =
431 [cell frameForDecoration:&mock_left_decoration_ inFrame:[field_ bounds]]; 391 [cell frameForDecoration:&mock_left_decoration_ inFrame:bounds];
432 const NSPoint point = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); 392 const NSPoint point = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
433 NSEvent* downEvent(Event(field_, point, NSLeftMouseDown)); 393 NSEvent* downEvent = Event(field_, point, NSLeftMouseDown);
434 NSEvent* upEvent(Event(field_, point, NSLeftMouseUp)); 394 NSEvent* upEvent = Event(field_, point, NSLeftMouseUp);
435 [NSApp postEvent:upEvent atStart:YES]; 395 [NSApp postEvent:upEvent atStart:YES];
436 [field_ mouseDown:downEvent]; 396 [field_ mouseDown:downEvent];
437 397
438 // Selection should be a left-hand-side caret. 398 // Selection should be a left-hand-side caret.
439 EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, 0), 399 EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, 0),
440 [[field_ currentEditor] selectedRange])); 400 [[field_ currentEditor] selectedRange]));
441 } 401 }
442 402
443 // Clicks not in the text area or the cell's decorations fall through 403 // Clicks not in the text area or the cell's decorations fall through
444 // to the editor. 404 // to the editor.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 EXPECT_EQ(selectedRange.location, 0U); 511 EXPECT_EQ(selectedRange.location, 0U);
552 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]); 512 EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]);
553 } 513 }
554 514
555 // Clicking a decoration should call decoration's OnMousePressed. 515 // Clicking a decoration should call decoration's OnMousePressed.
556 TEST_F(AutocompleteTextFieldTest, LeftDecorationMouseDown) { 516 TEST_F(AutocompleteTextFieldTest, LeftDecorationMouseDown) {
557 // At this point, not focussed. 517 // At this point, not focussed.
558 EXPECT_FALSE([field_ currentEditor]); 518 EXPECT_FALSE([field_ currentEditor]);
559 519
560 mock_left_decoration_.SetVisible(true); 520 mock_left_decoration_.SetVisible(true);
521 EXPECT_CALL(mock_left_decoration_, AcceptsMousePress())
522 .WillRepeatedly(Return(true));
561 523
562 AutocompleteTextFieldCell* cell = [field_ cell]; 524 AutocompleteTextFieldCell* cell = [field_ cell];
563 const NSRect iconFrame = 525 const NSRect iconFrame =
564 [cell frameForDecoration:&mock_left_decoration_ inFrame:[field_ bounds]]; 526 [cell frameForDecoration:&mock_left_decoration_ inFrame:[field_ bounds]];
565 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); 527 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
566 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1); 528 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1);
567 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1); 529 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1);
568 530
569 // Since decorations can be dragged, the mouse-press is sent on 531 // Since decorations can be dragged, the mouse-press is sent on
570 // mouse-up. 532 // mouse-up.
(...skipping 25 matching lines...) Expand all
596 // IDEA: mock decoration to return a pasteboard which a mock 558 // IDEA: mock decoration to return a pasteboard which a mock
597 // AutocompleteTextField notes in -dragImage:*. 559 // AutocompleteTextField notes in -dragImage:*.
598 } 560 }
599 561
600 // Clicking a decoration should call decoration's OnMousePressed. 562 // Clicking a decoration should call decoration's OnMousePressed.
601 TEST_F(AutocompleteTextFieldTest, RightDecorationMouseDown) { 563 TEST_F(AutocompleteTextFieldTest, RightDecorationMouseDown) {
602 // At this point, not focussed. 564 // At this point, not focussed.
603 EXPECT_FALSE([field_ currentEditor]); 565 EXPECT_FALSE([field_ currentEditor]);
604 566
605 mock_right_decoration_.SetVisible(true); 567 mock_right_decoration_.SetVisible(true);
568 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress())
569 .WillRepeatedly(Return(true));
606 570
607 AutocompleteTextFieldCell* cell = [field_ cell]; 571 AutocompleteTextFieldCell* cell = [field_ cell];
572 const NSRect bounds = [field_ bounds];
608 const NSRect iconFrame = 573 const NSRect iconFrame =
609 [cell frameForDecoration:&mock_right_decoration_ inFrame:[field_ bounds]]; 574 [cell frameForDecoration:&mock_right_decoration_ inFrame:bounds];
610 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); 575 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
611 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1); 576 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1);
612 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1); 577 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1);
613 578
614 // Since decorations can be dragged, the mouse-press is sent on 579 // Since decorations can be dragged, the mouse-press is sent on
615 // mouse-up. 580 // mouse-up.
616 [NSApp postEvent:upEvent atStart:YES]; 581 [NSApp postEvent:upEvent atStart:YES];
617 582
618 EXPECT_CALL(mock_right_decoration_, OnMousePressed(_)) 583 EXPECT_CALL(mock_right_decoration_, OnMousePressed(_))
619 .WillOnce(Return(true)); 584 .WillOnce(Return(true));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 scoped_nsobject<AutocompleteTextField> pin([field_ retain]); 768 scoped_nsobject<AutocompleteTextField> pin([field_ retain]);
804 [field_ removeFromSuperview]; 769 [field_ removeFromSuperview];
805 [test_window() resignKeyWindow]; 770 [test_window() resignKeyWindow];
806 771
807 [[test_window() contentView] addSubview:field_]; 772 [[test_window() contentView] addSubview:field_];
808 EXPECT_CALL(field_observer_, ClosePopup()); 773 EXPECT_CALL(field_observer_, ClosePopup());
809 [test_window() resignKeyWindow]; 774 [test_window() resignKeyWindow];
810 } 775 }
811 776
812 } // namespace 777 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698