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

Side by Side Diff: chrome/browser/cocoa/find_bar_view_unittest.mm

Issue 402066: Moved a whole pile of unittests over to CocoaTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #import "chrome/browser/cocoa/cocoa_test_helper.h" 8 #import "chrome/browser/cocoa/cocoa_test_helper.h"
9 #import "chrome/browser/cocoa/find_bar_view.h" 9 #import "chrome/browser/cocoa/find_bar_view.h"
10 #include "chrome/browser/cocoa/test_event_utils.h" 10 #include "chrome/browser/cocoa/test_event_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
13 13
14 @interface MouseDownViewPong : NSView { 14 @interface MouseDownViewPong : NSView {
15 BOOL pong_; 15 BOOL pong_;
16 } 16 }
17 @property(assign) BOOL pong; 17 @property(assign) BOOL pong;
18 @end 18 @end
19 19
20 @implementation MouseDownViewPong 20 @implementation MouseDownViewPong
21 @synthesize pong = pong_; 21 @synthesize pong = pong_;
22 - (void)mouseDown:(NSEvent*)event { 22 - (void)mouseDown:(NSEvent*)event {
23 pong_ = YES; 23 pong_ = YES;
24 } 24 }
25 @end 25 @end
26 26
27 27
28 namespace { 28 namespace {
29 29
30 class FindBarViewTest : public PlatformTest { 30 class FindBarViewTest : public CocoaTest {
31 public: 31 public:
32 FindBarViewTest() { 32 FindBarViewTest() {
33 NSRect frame = NSMakeRect(0, 0, 100, 30); 33 NSRect frame = NSMakeRect(0, 0, 100, 30);
34 view_.reset([[FindBarView alloc] initWithFrame:frame]); 34 scoped_nsobject<FindBarView> view(
35 [cocoa_helper_.contentView() addSubview:view_.get()]; 35 [[FindBarView alloc] initWithFrame:frame]);
36 view_ = view.get();
37 [[test_window() contentView] addSubview:view_];
36 } 38 }
37 39
38 scoped_nsobject<FindBarView> view_; 40 FindBarView* view_;
39 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
40 }; 41 };
41 42
42 // Test adding/removing from the view hierarchy, mostly to ensure nothing 43 TEST_VIEW(FindBarViewTest, view_)
43 // leaks or crashes.
44 TEST_F(FindBarViewTest, AddRemove) {
45 EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]);
46 [view_.get() removeFromSuperview];
47 EXPECT_FALSE([view_ superview]);
48 }
49
50 // Test drawing, mostly to ensure nothing leaks or crashes.
51 TEST_F(FindBarViewTest, Display) {
52 [view_ display];
53 }
54 44
55 TEST_F(FindBarViewTest, FindBarEatsMouseClicksInBackgroundArea) { 45 TEST_F(FindBarViewTest, FindBarEatsMouseClicksInBackgroundArea) {
56 MouseDownViewPong* pongView = 46 MouseDownViewPong* pongView =
57 [[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]; 47 [[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)];
58 48
59 // Remove all of the subviews of the findbar, to make sure we don't 49 // Remove all of the subviews of the findbar, to make sure we don't
60 // accidentally hit a subview when trying to simulate a click in the 50 // accidentally hit a subview when trying to simulate a click in the
61 // background area. 51 // background area.
62 [view_ setSubviews:[NSArray array]]; 52 [view_ setSubviews:[NSArray array]];
63 [view_ setFrame:NSMakeRect(0, 0, 200, 200)]; 53 [view_ setFrame:NSMakeRect(0, 0, 200, 200)];
64 54
65 // Add the pong view as a sibling of the findbar. 55 // Add the pong view as a sibling of the findbar.
66 [cocoa_helper_.contentView() addSubview:pongView 56 [[test_window() contentView] addSubview:pongView
67 positioned:NSWindowBelow 57 positioned:NSWindowBelow
68 relativeTo:view_.get()]; 58 relativeTo:view_];
69 59
70 // Synthesize a mousedown event and send it to the window. The event is 60 // Synthesize a mousedown event and send it to the window. The event is
71 // placed in the center of the find bar. 61 // placed in the center of the find bar.
72 NSPoint pointInCenterOfFindBar = NSMakePoint(100, 100); 62 NSPoint pointInCenterOfFindBar = NSMakePoint(100, 100);
73 [pongView setPong:NO]; 63 [pongView setPong:NO];
74 [cocoa_helper_.window() 64 [test_window()
75 sendEvent:test_event_utils::LeftMouseDownAtPoint(pointInCenterOfFindBar)]; 65 sendEvent:test_event_utils::LeftMouseDownAtPoint(pointInCenterOfFindBar)];
76 // Click gets eaten by findbar, not passed through to underlying view. 66 // Click gets eaten by findbar, not passed through to underlying view.
77 EXPECT_FALSE([pongView pong]); 67 EXPECT_FALSE([pongView pong]);
78 } 68 }
79 69
80 TEST_F(FindBarViewTest, FindBarPassesThroughClicksInTransparentArea) { 70 TEST_F(FindBarViewTest, FindBarPassesThroughClicksInTransparentArea) {
81 MouseDownViewPong* pongView = 71 MouseDownViewPong* pongView =
82 [[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]; 72 [[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)];
83 [view_ setFrame:NSMakeRect(0, 0, 200, 200)]; 73 [view_ setFrame:NSMakeRect(0, 0, 200, 200)];
84 74
85 // Add the pong view as a sibling of the findbar. 75 // Add the pong view as a sibling of the findbar.
86 [cocoa_helper_.contentView() addSubview:pongView 76 [[test_window() contentView] addSubview:pongView
87 positioned:NSWindowBelow 77 positioned:NSWindowBelow
88 relativeTo:view_.get()]; 78 relativeTo:view_];
89 79
90 // Synthesize a mousedown event and send it to the window. The event is inset 80 // Synthesize a mousedown event and send it to the window. The event is inset
91 // a few pixels from the lower left corner of the window, which places it in 81 // a few pixels from the lower left corner of the window, which places it in
92 // the transparent area surrounding the findbar. 82 // the transparent area surrounding the findbar.
93 NSPoint pointInTransparentArea = NSMakePoint(2, 2); 83 NSPoint pointInTransparentArea = NSMakePoint(2, 2);
94 [pongView setPong:NO]; 84 [pongView setPong:NO];
95 [cocoa_helper_.window() 85 [test_window()
96 sendEvent:test_event_utils::LeftMouseDownAtPoint(pointInTransparentArea)]; 86 sendEvent:test_event_utils::LeftMouseDownAtPoint(pointInTransparentArea)];
97 // Click is ignored by findbar, passed through to underlying view. 87 // Click is ignored by findbar, passed through to underlying view.
98 EXPECT_TRUE([pongView pong]); 88 EXPECT_TRUE([pongView pong]);
99 } 89 }
100 } // namespace 90 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/find_bar_cocoa_controller_unittest.mm ('k') | chrome/browser/cocoa/find_pasteboard_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698