diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 15:35:38 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 15:35:38 +0000 |
commit | 3d4560f45d650a9421eff15cd63f3e4b796f01f5 (patch) | |
tree | 1bed2441c7e4b1071adb3d22146f0726f80510cd /chrome/browser/cocoa/find_bar_view_unittest.mm | |
parent | d49e4a51428d0234d0dcbb11343315e4f2aa8fd6 (diff) | |
download | chromium_src-3d4560f45d650a9421eff15cd63f3e4b796f01f5.zip chromium_src-3d4560f45d650a9421eff15cd63f3e4b796f01f5.tar.gz chromium_src-3d4560f45d650a9421eff15cd63f3e4b796f01f5.tar.bz2 |
[Mac] Eat mouse clicks in the findbar to prevent them from falling through to views below.
BUG=http://crbug.com/22854
TEST=See test case in bug.
Review URL: http://codereview.chromium.org/273041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/find_bar_view_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/find_bar_view_unittest.mm | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/find_bar_view_unittest.mm b/chrome/browser/cocoa/find_bar_view_unittest.mm index 734dcd9..c1fc902 100644 --- a/chrome/browser/cocoa/find_bar_view_unittest.mm +++ b/chrome/browser/cocoa/find_bar_view_unittest.mm @@ -5,11 +5,26 @@ #import <Cocoa/Cocoa.h> #include "base/scoped_nsobject.h" -#import "chrome/browser/cocoa/find_bar_view.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" +#import "chrome/browser/cocoa/find_bar_view.h" +#include "chrome/browser/cocoa/test_event_utils.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +@interface MouseDownViewPong : NSView { + BOOL pong_; +} +@property(assign) BOOL pong; +@end + +@implementation MouseDownViewPong +@synthesize pong = pong_; +- (void)mouseDown:(NSEvent*)event { + pong_ = YES; +} +@end + + namespace { class FindBarViewTest : public PlatformTest { @@ -37,4 +52,49 @@ TEST_F(FindBarViewTest, Display) { [view_ display]; } +TEST_F(FindBarViewTest, FindBarEatsMouseClicksInBackgroundArea) { + MouseDownViewPong* pongView = + [[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]; + + // Remove all of the subviews of the findbar, to make sure we don't + // accidentally hit a subview when trying to simulate a click in the + // background area. + [view_ setSubviews:[NSArray array]]; + [view_ setFrame:NSMakeRect(0, 0, 200, 200)]; + + // Add the pong view as a sibling of the findbar. + [cocoa_helper_.contentView() addSubview:pongView + positioned:NSWindowBelow + relativeTo:view_.get()]; + + // Synthesize a mousedown event and send it to the window. The event is + // placed in the center of the find bar. + NSPoint pointInCenterOfFindBar = NSMakePoint(100, 100); + [pongView setPong:NO]; + [cocoa_helper_.window() + sendEvent:test_event_utils::LeftMouseDownAtPoint(pointInCenterOfFindBar)]; + // Click gets eaten by findbar, not passed through to underlying view. + EXPECT_FALSE([pongView pong]); +} + +TEST_F(FindBarViewTest, FindBarPassesThroughClicksInTransparentArea) { + MouseDownViewPong* pongView = + [[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]; + [view_ setFrame:NSMakeRect(0, 0, 200, 200)]; + + // Add the pong view as a sibling of the findbar. + [cocoa_helper_.contentView() addSubview:pongView + positioned:NSWindowBelow + relativeTo:view_.get()]; + + // Synthesize a mousedown event and send it to the window. The event is inset + // a few pixels from the lower left corner of the window, which places it in + // the transparent area surrounding the findbar. + NSPoint pointInTransparentArea = NSMakePoint(2, 2); + [pongView setPong:NO]; + [cocoa_helper_.window() + sendEvent:test_event_utils::LeftMouseDownAtPoint(pointInTransparentArea)]; + // Click is ignored by findbar, passed through to underlying view. + EXPECT_TRUE([pongView pong]); +} } // namespace |