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

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

Issue 2478673002: [Mac] Hover/Pressed background for the Omnibox decorations (Closed)
Patch Set: nit Created 4 years, 1 month 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) 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
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
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
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 = [field_ cell];
807
808 mock_left_decoration_.SetVisible(true);
809 mock_right_decoration_.SetVisible(true);
810
811 EXPECT_CALL(mock_left_decoration_, AcceptsMousePress())
812 .WillOnce(Return(true))
813 .WillRepeatedly(Return(true));
814 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress())
815 .WillOnce(Return(false))
816 .WillRepeatedly(Return(false));
817 [cell updateMouseTrackingAndToolTipsInRect:[field_ bounds] ofView:field_];
818
819 EXPECT_EQ([cell mouseTrackingDecorations].size(), 1.0);
820
821 [cell clearTrackingArea];
822 EXPECT_TRUE([cell mouseTrackingDecorations].empty());
823
824 EXPECT_CALL(mock_right_decoration_, AcceptsMousePress())
825 .WillOnce(Return(true))
826 .WillRepeatedly(Return(true));
827
828 [cell updateMouseTrackingAndToolTipsInRect:[field_ bounds] ofView:field_];
829 EXPECT_EQ([cell mouseTrackingDecorations].size(), 2.0);
830 }
831
800 // Verify that clicking a decoration that accepts mouse clicks does not focus 832 // Verify that clicking a decoration that accepts mouse clicks does not focus
801 // the Omnibox. 833 // the Omnibox.
802 TEST_F(AutocompleteTextFieldObserverTest, 834 TEST_F(AutocompleteTextFieldObserverTest,
803 ClickingDecorationDoesNotFocusOmnibox) { 835 ClickingDecorationDoesNotFocusOmnibox) {
804 AutocompleteTextFieldCell* cell = [field_ cell]; 836 AutocompleteTextFieldCell* cell = [field_ cell];
805 837
806 // Set up a non-interactive decoration. 838 // Set up a non-interactive decoration.
807 MockDecoration noninteractive_decoration; 839 MockDecoration noninteractive_decoration;
808 noninteractive_decoration.SetVisible(true); 840 noninteractive_decoration.SetVisible(true);
809 EXPECT_CALL(noninteractive_decoration, AcceptsMousePress()) 841 EXPECT_CALL(noninteractive_decoration, AcceptsMousePress())
810 .WillRepeatedly(testing::Return(false)); 842 .WillRepeatedly(testing::Return(false));
811 [cell addLeftDecoration:&noninteractive_decoration]; 843 [cell addLeftDecoration:&noninteractive_decoration];
812 844
813 // Set up an interactive decoration. 845 // Set up an interactive decoration.
814 MockDecoration interactive_decoration; 846 MockDecoration interactive_decoration;
815 EXPECT_CALL(interactive_decoration, AcceptsMousePress()) 847 EXPECT_CALL(interactive_decoration, AcceptsMousePress())
816 .WillRepeatedly(testing::Return(true)); 848 .WillRepeatedly(testing::Return(true));
817 interactive_decoration.SetVisible(true); 849 interactive_decoration.SetVisible(true);
818 [cell addLeftDecoration:&interactive_decoration]; 850 [cell addLeftDecoration:&interactive_decoration];
851 [cell updateMouseTrackingAndToolTipsInRect:[field_ frame] ofView:field_];
819 EXPECT_CALL(interactive_decoration, OnMousePressed(_, _)) 852 EXPECT_CALL(interactive_decoration, OnMousePressed(_, _))
820 .WillRepeatedly(testing::Return(true)); 853 .WillRepeatedly(testing::Return(true));
821 854
822 // Ignore incidental calls. The exact frequency of these calls doesn't matter 855 // Ignore incidental calls. The exact frequency of these calls doesn't matter
823 // as they are auxiliary. 856 // as they are auxiliary.
824 EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(_)) 857 EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(_))
825 .WillRepeatedly(testing::Return(NSMakeRange(0, 0))); 858 .WillRepeatedly(testing::Return(NSMakeRange(0, 0)));
826 EXPECT_CALL(field_observer_, OnMouseDown(_)).Times(testing::AnyNumber()); 859 EXPECT_CALL(field_observer_, OnMouseDown(_)).Times(testing::AnyNumber());
827 EXPECT_CALL(field_observer_, OnSetFocus(false)).Times(testing::AnyNumber()); 860 EXPECT_CALL(field_observer_, OnSetFocus(false)).Times(testing::AnyNumber());
828 EXPECT_CALL(field_observer_, OnKillFocus()).Times(testing::AnyNumber()); 861 EXPECT_CALL(field_observer_, OnKillFocus()).Times(testing::AnyNumber());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 base::scoped_nsobject<AutocompleteTextField> pin([field_ retain]); 932 base::scoped_nsobject<AutocompleteTextField> pin([field_ retain]);
900 [field_ removeFromSuperview]; 933 [field_ removeFromSuperview];
901 [test_window() resignKeyWindow]; 934 [test_window() resignKeyWindow];
902 935
903 [[test_window() contentView] addSubview:field_]; 936 [[test_window() contentView] addSubview:field_];
904 EXPECT_CALL(field_observer_, ClosePopup()); 937 EXPECT_CALL(field_observer_, ClosePopup());
905 [test_window() resignKeyWindow]; 938 [test_window() resignKeyWindow];
906 } 939 }
907 940
908 } // namespace 941 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698