Chromium Code Reviews| Index: chrome/browser/ui/cocoa/autofill/autofill_suggestion_container_unittest.mm |
| diff --git a/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container_unittest.mm b/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container_unittest.mm |
| index 9ab03180ff4d881a83d047d9891b373287e6cdeb..fef2fdceef416c910388839f06d2e1ebd244596b 100644 |
| --- a/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container_unittest.mm |
| +++ b/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container_unittest.mm |
| @@ -16,10 +16,12 @@ class AutofillSuggestionContainerTest : public ui::CocoaTest { |
| CocoaTest::SetUp(); |
| container_.reset([[AutofillSuggestionContainer alloc] init]); |
| [[test_window() contentView] addSubview:[container_ view]]; |
| + view_ = [container_ view]; |
| } |
| protected: |
| base::scoped_nsobject<AutofillSuggestionContainer> container_; |
| + NSView* view_; |
| }; |
| } // namespace |
| @@ -44,3 +46,51 @@ TEST_F(AutofillSuggestionContainerTest, HasSubviews) { |
| EXPECT_TRUE(has_text_view); |
| EXPECT_TRUE(has_edit_field); |
| } |
| + |
| +// Test that mouse events outside the input field are ignored. |
| +TEST_F(AutofillSuggestionContainerTest, HitTestInputField) { |
| + base::scoped_nsobject<NSImage> icon( |
| + [[NSImage alloc] initWithSize:NSMakeSize(16, 16)]); |
| + [container_ setSuggestionWithVerticallyCompactText:@"suggest" |
| + horizontallyCompactText:@"suggest" |
| + icon:nil |
| + maxWidth:200]; |
| + [container_ showInputField:@"input" withIcon:icon]; |
| + [view_ setFrameSize:[container_ preferredSize]]; |
| + [container_ performLayout]; |
| + |
| + // Point not touching any subviews, in |view_|'s coordinate system. |
| + NSPoint pointOutsideSubviews = |
|
Robert Sesek
2014/01/08 14:50:19
naming: under_scores (also update the comments)
groby-ooo-7-16
2014/01/08 19:20:58
Done.
|
| + NSMakePoint(NSMinX([view_ bounds]), NSMaxY([view_ bounds]) - 1); |
| + NSPoint pointInsideTextView = NSZeroPoint; |
| + |
| + // hitTests on all inputs should be false, except for the inputField. |
| + for (id fieldView in [view_ subviews]) { |
|
Robert Sesek
2014/01/08 14:50:19
naming: field_view
groby-ooo-7-16
2014/01/08 19:20:58
Done.
|
| + // Ensure |pointOutsideSubviews| really is outside subviews. |
| + ASSERT_FALSE([fieldView hitTest:pointOutsideSubviews]); |
| + |
| + // Compute center of |fieldView| in |view_|'s parent coordinate system. |
| + NSPoint point = |
| + [view_ convertPoint:NSMakePoint(NSMidX([fieldView frame]), |
| + NSMidY([fieldView frame])) |
| + toView:[view_ superview]]; |
| + if (fieldView == [container_ inputField]) { |
| + pointInsideTextView = point; |
| + EXPECT_TRUE([view_ hitTest:point]); |
| + } else { |
| + EXPECT_FALSE([view_ hitTest:point]); |
| + } |
| + } |
| + |
| + // Mouse events directly on the main view should be ignored. |
| + EXPECT_FALSE([view_ hitTest: |
| + [view_ convertPoint:pointOutsideSubviews |
| + toView:[view_ superview]]]); |
| + |
| + // Mouse events on the text view's editor should propagate. |
| + [[view_ window] makeFirstResponder:[container_ inputField]]; |
| + NSView* editorView = [view_ hitTest:pointInsideTextView]; |
| + ASSERT_NE(editorView, [container_ inputField]); |
|
Robert Sesek
2014/01/08 14:50:19
Generally stick with EXPECT_ unless you need to st
groby-ooo-7-16
2014/01/08 19:20:58
This was intentional - it confirms a precondition
|
| + ASSERT_TRUE([editorView isDescendantOf:[container_ inputField]]); |
| + EXPECT_TRUE(editorView); |
| +} |