Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <ApplicationServices/ApplicationServices.h> | 5 #import <ApplicationServices/ApplicationServices.h> |
| 6 #import <Cocoa/Cocoa.h> | 6 #import <Cocoa/Cocoa.h> |
| 7 | 7 |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 // Clicking a decoration should call decoration's OnMousePressed. | 567 // Clicking a decoration should call decoration's OnMousePressed. |
| 568 TEST_F(AutocompleteTextFieldTest, LeftDecorationMouseDown) { | 568 TEST_F(AutocompleteTextFieldTest, LeftDecorationMouseDown) { |
| 569 // At this point, not focussed. | 569 // At this point, not focussed. |
| 570 EXPECT_FALSE([field_ currentEditor]); | 570 EXPECT_FALSE([field_ currentEditor]); |
| 571 | 571 |
| 572 mock_left_decoration_.SetVisible(true); | 572 mock_left_decoration_.SetVisible(true); |
| 573 EXPECT_CALL(mock_left_decoration_, AcceptsMousePress()) | 573 EXPECT_CALL(mock_left_decoration_, AcceptsMousePress()) |
| 574 .WillRepeatedly(Return(true)); | 574 .WillRepeatedly(Return(true)); |
| 575 | 575 |
| 576 AutocompleteTextFieldCell* cell = [field_ cell]; | 576 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 577 [cell updateMouseTrackingAndToolTipsInRect:[field_ frame] ofView:field_]; | |
| 578 | |
| 577 const NSRect iconFrame = | 579 const NSRect iconFrame = |
| 578 [cell frameForDecoration:&mock_left_decoration_ inFrame:[field_ bounds]]; | 580 [cell frameForDecoration:&mock_left_decoration_ inFrame:[field_ bounds]]; |
| 579 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); | 581 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); |
| 580 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1); | 582 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1); |
| 581 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1); | 583 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1); |
| 582 | 584 |
| 583 // Since decorations can be dragged, the mouse-press is sent on | 585 // Since decorations can be dragged, the mouse-press is sent on |
| 584 // mouse-up. | 586 // mouse-up. |
| 585 [NSApp postEvent:upEvent atStart:YES]; | 587 [NSApp postEvent:upEvent atStart:YES]; |
| 586 | 588 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 614 // Clicking a decoration should call decoration's OnMousePressed. | 616 // Clicking a decoration should call decoration's OnMousePressed. |
| 615 TEST_F(AutocompleteTextFieldTest, RightDecorationMouseDown) { | 617 TEST_F(AutocompleteTextFieldTest, RightDecorationMouseDown) { |
| 616 // At this point, not focussed. | 618 // At this point, not focussed. |
| 617 EXPECT_FALSE([field_ currentEditor]); | 619 EXPECT_FALSE([field_ currentEditor]); |
| 618 | 620 |
| 619 mock_right_decoration_.SetVisible(true); | 621 mock_right_decoration_.SetVisible(true); |
| 620 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress()) | 622 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress()) |
| 621 .WillRepeatedly(Return(true)); | 623 .WillRepeatedly(Return(true)); |
| 622 | 624 |
| 623 AutocompleteTextFieldCell* cell = [field_ cell]; | 625 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 626 [cell updateMouseTrackingAndToolTipsInRect:[field_ frame] ofView:field_]; | |
| 627 | |
| 624 const NSRect bounds = [field_ bounds]; | 628 const NSRect bounds = [field_ bounds]; |
| 625 const NSRect iconFrame = | 629 const NSRect iconFrame = |
| 626 [cell frameForDecoration:&mock_right_decoration_ inFrame:bounds]; | 630 [cell frameForDecoration:&mock_right_decoration_ inFrame:bounds]; |
| 627 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); | 631 const NSPoint location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)); |
| 628 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1); | 632 NSEvent* downEvent = Event(field_, location, NSLeftMouseDown, 1); |
| 629 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1); | 633 NSEvent* upEvent = Event(field_, location, NSLeftMouseUp, 1); |
| 630 | 634 |
| 631 // Since decorations can be dragged, the mouse-press is sent on | 635 // Since decorations can be dragged, the mouse-press is sent on |
| 632 // mouse-up. | 636 // mouse-up. |
| 633 [NSApp postEvent:upEvent atStart:YES]; | 637 [NSApp postEvent:upEvent atStart:YES]; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 ofView:field_]; | 794 ofView:field_]; |
| 791 EXPECT_FALSE([[field_ cell] showsFirstResponder]); | 795 EXPECT_FALSE([[field_ cell] showsFirstResponder]); |
| 792 EXPECT_FALSE([FieldEditor() shouldDrawInsertionPoint]); | 796 EXPECT_FALSE([FieldEditor() shouldDrawInsertionPoint]); |
| 793 | 797 |
| 794 [[field_ cell] setHideFocusState:NO | 798 [[field_ cell] setHideFocusState:NO |
| 795 ofView:field_]; | 799 ofView:field_]; |
| 796 EXPECT_TRUE([[field_ cell] showsFirstResponder]); | 800 EXPECT_TRUE([[field_ cell] showsFirstResponder]); |
| 797 EXPECT_TRUE([FieldEditor() shouldDrawInsertionPoint]); | 801 EXPECT_TRUE([FieldEditor() shouldDrawInsertionPoint]); |
| 798 } | 802 } |
| 799 | 803 |
| 804 // Verify that the tracking areas are added properly. | |
| 805 TEST_F(AutocompleteTextFieldTest, UpdateTrackingAreas) { | |
| 806 AutocompleteTextFieldCell* cell = | |
| 807 static_cast<AutocompleteTextFieldCell*>([field_ cell]); | |
|
Robert Sesek
2016/11/11 19:35:07
Is this cast needed? Line 837 doesn't do it.
spqchan
2016/11/12 00:36:20
Done.
| |
| 808 | |
| 809 mock_left_decoration_.SetVisible(true); | |
| 810 mock_right_decoration_.SetVisible(true); | |
| 811 | |
| 812 EXPECT_CALL(mock_left_decoration_, AcceptsMousePress()) | |
| 813 .WillOnce(Return(true)) | |
| 814 .WillRepeatedly(Return(true)); | |
| 815 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress()) | |
| 816 .WillOnce(Return(false)) | |
| 817 .WillRepeatedly(Return(false)); | |
| 818 [cell updateMouseTrackingAndToolTipsInRect:[field_ bounds] ofView:field_]; | |
| 819 | |
| 820 EXPECT_EQ([cell mouseTrackingDecorations].size(), 1.0); | |
| 821 | |
| 822 [cell clearTrackingArea]; | |
| 823 EXPECT_TRUE([cell mouseTrackingDecorations].empty()); | |
| 824 | |
| 825 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress()) | |
| 826 .WillOnce(Return(true)) | |
| 827 .WillRepeatedly(Return(true)); | |
| 828 | |
| 829 [cell updateMouseTrackingAndToolTipsInRect:[field_ bounds] ofView:field_]; | |
| 830 EXPECT_EQ([cell mouseTrackingDecorations].size(), 2.0); | |
| 831 } | |
| 832 | |
| 800 // Verify that clicking a decoration that accepts mouse clicks does not focus | 833 // Verify that clicking a decoration that accepts mouse clicks does not focus |
| 801 // the Omnibox. | 834 // the Omnibox. |
| 802 TEST_F(AutocompleteTextFieldObserverTest, | 835 TEST_F(AutocompleteTextFieldObserverTest, |
| 803 ClickingDecorationDoesNotFocusOmnibox) { | 836 ClickingDecorationDoesNotFocusOmnibox) { |
| 804 AutocompleteTextFieldCell* cell = [field_ cell]; | 837 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 805 | 838 |
| 806 // Set up a non-interactive decoration. | 839 // Set up a non-interactive decoration. |
| 807 MockDecoration noninteractive_decoration; | 840 MockDecoration noninteractive_decoration; |
| 808 noninteractive_decoration.SetVisible(true); | 841 noninteractive_decoration.SetVisible(true); |
| 809 EXPECT_CALL(noninteractive_decoration, AcceptsMousePress()) | 842 EXPECT_CALL(noninteractive_decoration, AcceptsMousePress()) |
| 810 .WillRepeatedly(testing::Return(false)); | 843 .WillRepeatedly(testing::Return(false)); |
| 811 [cell addLeftDecoration:&noninteractive_decoration]; | 844 [cell addLeftDecoration:&noninteractive_decoration]; |
| 812 | 845 |
| 813 // Set up an interactive decoration. | 846 // Set up an interactive decoration. |
| 814 MockDecoration interactive_decoration; | 847 MockDecoration interactive_decoration; |
| 815 EXPECT_CALL(interactive_decoration, AcceptsMousePress()) | 848 EXPECT_CALL(interactive_decoration, AcceptsMousePress()) |
| 816 .WillRepeatedly(testing::Return(true)); | 849 .WillRepeatedly(testing::Return(true)); |
| 817 interactive_decoration.SetVisible(true); | 850 interactive_decoration.SetVisible(true); |
| 818 [cell addLeftDecoration:&interactive_decoration]; | 851 [cell addLeftDecoration:&interactive_decoration]; |
| 852 [cell updateMouseTrackingAndToolTipsInRect:[field_ frame] ofView:field_]; | |
| 819 EXPECT_CALL(interactive_decoration, OnMousePressed(_, _)) | 853 EXPECT_CALL(interactive_decoration, OnMousePressed(_, _)) |
| 820 .WillRepeatedly(testing::Return(true)); | 854 .WillRepeatedly(testing::Return(true)); |
| 821 | 855 |
| 822 // Ignore incidental calls. The exact frequency of these calls doesn't matter | 856 // Ignore incidental calls. The exact frequency of these calls doesn't matter |
| 823 // as they are auxiliary. | 857 // as they are auxiliary. |
| 824 EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(_)) | 858 EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(_)) |
| 825 .WillRepeatedly(testing::Return(NSMakeRange(0, 0))); | 859 .WillRepeatedly(testing::Return(NSMakeRange(0, 0))); |
| 826 EXPECT_CALL(field_observer_, OnMouseDown(_)).Times(testing::AnyNumber()); | 860 EXPECT_CALL(field_observer_, OnMouseDown(_)).Times(testing::AnyNumber()); |
| 827 EXPECT_CALL(field_observer_, OnSetFocus(false)).Times(testing::AnyNumber()); | 861 EXPECT_CALL(field_observer_, OnSetFocus(false)).Times(testing::AnyNumber()); |
| 828 EXPECT_CALL(field_observer_, OnKillFocus()).Times(testing::AnyNumber()); | 862 EXPECT_CALL(field_observer_, OnKillFocus()).Times(testing::AnyNumber()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 base::scoped_nsobject<AutocompleteTextField> pin([field_ retain]); | 933 base::scoped_nsobject<AutocompleteTextField> pin([field_ retain]); |
| 900 [field_ removeFromSuperview]; | 934 [field_ removeFromSuperview]; |
| 901 [test_window() resignKeyWindow]; | 935 [test_window() resignKeyWindow]; |
| 902 | 936 |
| 903 [[test_window() contentView] addSubview:field_]; | 937 [[test_window() contentView] addSubview:field_]; |
| 904 EXPECT_CALL(field_observer_, ClosePopup()); | 938 EXPECT_CALL(field_observer_, ClosePopup()); |
| 905 [test_window() resignKeyWindow]; | 939 [test_window() resignKeyWindow]; |
| 906 } | 940 } |
| 907 | 941 |
| 908 } // namespace | 942 } // namespace |
| OLD | NEW |