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

Unified Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm

Issue 1011943002: Mac: Clicking an omnibox decoration should not highlight the omnibox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm
diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm
index 6d138011b2687a550b13f28c65cb701d7d1a5b86..0cc3afef6ab7c4b839078980c87c8d61d7b45835 100644
--- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest.mm
@@ -51,7 +51,6 @@ class MockButtonDecoration : public ButtonDecoration {
IMAGE_GRID(IDR_OMNIBOX_EV_BUBBLE),
IDR_OMNIBOX_EV_BUBBLE_CENTER,
3) {}
- void Hide() { SetVisible(false); }
MOCK_METHOD2(OnMousePressed, bool(NSRect frame, NSPoint location));
};
Scott Hess - ex-Googler 2015/05/08 19:38:28 Given the current code, this class seems like it i
erikchen 2015/05/08 20:02:20 Yup, removed.
@@ -170,6 +169,31 @@ class AutocompleteTextFieldObserverTest : public AutocompleteTextFieldTest {
AutocompleteTextFieldTest::TearDown();
}
+ // Returns the center point of the decoration.
+ NSPoint ClickLocationForDecoration(LocationBarDecoration* decoration) {
+ AutocompleteTextFieldCell* cell = [field_ cell];
+ NSRect decoration_rect =
+ [cell frameForDecoration:decoration inFrame:[field_ bounds]];
+ EXPECT_FALSE(NSIsEmptyRect(decoration_rect));
+ return NSMakePoint(NSMidX(decoration_rect), NSMidY(decoration_rect));
+ }
+
+ void SendMouseClickToDecoration(LocationBarDecoration* decoration) {
+ NSPoint point = ClickLocationForDecoration(decoration);
+ NSEvent* downEvent = Event(field_, point, NSLeftMouseDown);
+ NSEvent* upEvent = Event(field_, point, NSLeftMouseUp);
+
+ // Can't just use -sendEvent:, since that doesn't populate -currentEvent.
+ [NSApp postEvent:downEvent atStart:YES];
+ [NSApp postEvent:upEvent atStart:NO];
+
+ NSEvent* next_event = [NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:nil
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES];
+ [NSApp sendEvent:next_event];
+ }
+
StrictMock<MockAutocompleteTextFieldObserver> field_observer_;
};
@@ -594,8 +618,10 @@ TEST_F(AutocompleteTextFieldTest, LeftDecorationMouseDown) {
.WillOnce(Return(true));
[field_ mouseDown:downEvent];
+ // The text field should no longer be first responder.
// The selection should not have changed.
- EXPECT_TRUE(NSEqualRanges(allRange, [[field_ currentEditor] selectedRange]));
+ EXPECT_FALSE([base::mac::ObjCCast<NSView>([[field_ window] firstResponder])
+ isDescendantOf:field_]);
// TODO(shess): Test that mouse drags are initiated if the next
// event is a drag, or if the mouse-up takes too long to arrive.
@@ -789,61 +815,49 @@ TEST_F(AutocompleteTextFieldTest, HideFocusState) {
EXPECT_TRUE([FieldEditor() shouldDrawInsertionPoint]);
}
-// Verify that OnSetFocus for button decorations is only sent after the
-// decoration is picked as the target for the subsequent -mouseDown:. Otherwise
-// hiding a ButtonDecoration in OnSetFocus will prevent a call to
-// OnMousePressed, since it is already hidden at the time of mouseDown.
-TEST_F(AutocompleteTextFieldObserverTest, ButtonDecorationFocus) {
- // Add the mock button.
- MockButtonDecoration mock_button;
- mock_button.SetVisible(true);
+// Verify that clicking decorations defocuses the omnibox.
+TEST_F(AutocompleteTextFieldObserverTest, ClickingDecorationDefocusesOmnibox) {
AutocompleteTextFieldCell* cell = [field_ cell];
- [cell addLeftDecoration:&mock_button];
- // Ensure button is hidden when OnSetFocus() is called.
- EXPECT_CALL(field_observer_, OnSetFocus(false)).WillOnce(
- testing::InvokeWithoutArgs(&mock_button, &MockButtonDecoration::Hide));
+ // Set up a non-interactive decoration.
+ MockDecoration noninteractive_decoration;
+ noninteractive_decoration.SetVisible(true);
+ EXPECT_CALL(noninteractive_decoration, AcceptsMousePress())
+ .WillRepeatedly(testing::Return(false));
+ [cell addLeftDecoration:&noninteractive_decoration];
+
+ // Set up an interactive decoration.
+ MockButtonDecoration interactive_decoration;
+ interactive_decoration.SetVisible(true);
+ [cell addLeftDecoration:&interactive_decoration];
+ EXPECT_CALL(interactive_decoration, OnMousePressed(_, _))
+ .WillOnce(testing::Return(true));
- // Ignore incidental calls.
+ // Ignore incidental calls. The exact frequency of these calls doesn't
+ // matter, as they auxiliary to the behavior being tested.
Scott Hess - ex-Googler 2015/05/08 19:38:28 probably "they are auxiliary"
erikchen 2015/05/08 20:02:21 Done.
EXPECT_CALL(field_observer_, SelectionRangeForProposedRange(_))
.WillRepeatedly(testing::Return(NSMakeRange(0, 0)));
- EXPECT_CALL(field_observer_, OnMouseDown(_));
-
- // Still expect an OnMousePressed on the button.
- EXPECT_CALL(mock_button, OnMousePressed(_, _))
- .WillOnce(testing::Return(true));
-
- // Get click point for button decoration.
- NSRect button_rect =
- [cell frameForDecoration:&mock_button inFrame:[field_ bounds]];
- EXPECT_FALSE(NSIsEmptyRect(button_rect));
- NSPoint click_location =
- NSMakePoint(NSMidX(button_rect), NSMidY(button_rect));
+ EXPECT_CALL(field_observer_, OnMouseDown(_)).Times(testing::AnyNumber());
+ EXPECT_CALL(field_observer_, OnSetFocus(false)).Times(testing::AnyNumber());
+ EXPECT_CALL(field_observer_, OnKillFocus()).Times(testing::AnyNumber());
+ EXPECT_CALL(field_observer_, OnDidEndEditing()).Times(testing::AnyNumber());
// Ensure the field is currently not first responder.
[test_window() makePretendKeyWindowAndSetFirstResponder:nil];
- EXPECT_NSNE([[field_ window] firstResponder], field_);
-
- // Execute button click event sequence.
- NSEvent* downEvent = Event(field_, click_location, NSLeftMouseDown);
- NSEvent* upEvent = Event(field_, click_location, NSLeftMouseUp);
-
- // Can't just use -sendEvent:, since that doesn't populate -currentEvent.
- [NSApp postEvent:downEvent atStart:YES];
- [NSApp postEvent:upEvent atStart:NO];
- NSEvent* next_event = [NSApp nextEventMatchingMask:NSAnyEventMask
- untilDate:nil
- inMode:NSDefaultRunLoopMode
- dequeue:YES];
- [NSApp sendEvent:next_event];
-
- // Expectations check that both OnSetFocus and OnMouseDown were called.
- // Additionally, ensure button is hidden and field is firstResponder.
- EXPECT_FALSE(mock_button.IsVisible());
- EXPECT_TRUE(NSIsEmptyRect([cell frameForDecoration:&mock_left_decoration_
- inFrame:[field_ bounds]]));
- EXPECT_TRUE([base::mac::ObjCCastStrict<NSView>(
- [[field_ window] firstResponder]) isDescendantOf:field_]);
+ EXPECT_FALSE([base::mac::ObjCCast<NSView>([[field_ window] firstResponder])
+ isDescendantOf:field_]);
+
+ SendMouseClickToDecoration(&noninteractive_decoration);
+ EXPECT_TRUE([base::mac::ObjCCast<NSView>([[field_ window] firstResponder])
+ isDescendantOf:field_]);
+
+ SendMouseClickToDecoration(&interactive_decoration);
+ EXPECT_FALSE([base::mac::ObjCCast<NSView>([[field_ window] firstResponder])
+ isDescendantOf:field_]);
Scott Hess - ex-Googler 2015/05/08 19:38:28 This ties in with the comment in the implementatio
erikchen 2015/05/08 20:02:20 See my response to the earlier comment.
+
+ SendMouseClickToDecoration(&noninteractive_decoration);
+ EXPECT_TRUE([base::mac::ObjCCast<NSView>([[field_ window] firstResponder])
+ isDescendantOf:field_]);
}
TEST_F(AutocompleteTextFieldObserverTest, SendsEditingMessages) {

Powered by Google App Engine
This is Rietveld 408576698