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..cd3b3e8deb3a0ab6b4692e73ec4bbd79c1b5a7ae 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,52 @@ 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 point_outside_subviews = |
+ NSMakePoint(NSMinX([view_ bounds]), NSMaxY([view_ bounds]) - 1); |
+ NSPoint point_inside_text_view = NSZeroPoint; |
+ |
+ // hitTests on all inputs should be false, except for the inputField. |
+ for (id field_view in [view_ subviews]) { |
+ // Ensure |point_outside_subviews| really is outside subviews. |
+ ASSERT_FALSE([field_view hitTest:point_outside_subviews]); |
+ |
+ // Compute center of |field_view| in |view_|'s parent coordinate system. |
+ NSPoint point = |
+ [view_ convertPoint:NSMakePoint(NSMidX([field_view frame]), |
+ NSMidY([field_view frame])) |
+ toView:[view_ superview]]; |
+ if (field_view == [container_ inputField]) { |
+ point_inside_text_view = 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:point_outside_subviews |
+ toView:[view_ superview]]]); |
+ |
+ // Mouse events on the text view's editor should propagate. |
+ // Asserts ensure the path covering children of |inputField| is taken. |
+ [[view_ window] makeFirstResponder:[container_ inputField]]; |
+ NSView* editorView = [view_ hitTest:point_inside_text_view]; |
+ ASSERT_NE(editorView, [container_ inputField]); |
+ ASSERT_TRUE([editorView isDescendantOf:[container_ inputField]]); |
+ EXPECT_TRUE(editorView); |
+} |