Update V8 to version 4.7.45.
[chromium-blink-merge.git] / ui / base / cocoa / tracking_area_unittest.mm
blobcb2c82925bc0abb159d32de36da6e82d4e9d5d9d
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/mac/scoped_nsobject.h"
6 #import "ui/base/cocoa/tracking_area.h"
7 #import "ui/gfx/test/ui_cocoa_test_helper.h"
9 // A test object that counts the number of times a message is sent to it.
10 @interface TestTrackingAreaOwner : NSObject {
11  @private
12   NSUInteger messageCount_;
14 @property(nonatomic, assign) NSUInteger messageCount;
15 - (void)performMessage;
16 @end
18 @implementation TestTrackingAreaOwner
19 @synthesize messageCount = messageCount_;
20 - (void)performMessage {
21   ++messageCount_;
23 @end
25 namespace ui {
27 class CrTrackingAreaTest : public CocoaTest {
28  public:
29   CrTrackingAreaTest()
30       : owner_([[TestTrackingAreaOwner alloc] init]),
31         trackingArea_([[CrTrackingArea alloc]
32             initWithRect:NSMakeRect(0, 0, 100, 100)
33                  options:NSTrackingMouseMoved | NSTrackingActiveInKeyWindow
34                    owner:owner_.get()
35                 userInfo:nil]) {
36   }
38   base::scoped_nsobject<TestTrackingAreaOwner> owner_;
39   base::scoped_nsobject<CrTrackingArea> trackingArea_;
42 TEST_F(CrTrackingAreaTest, OwnerForwards) {
43   [[trackingArea_ owner] performMessage];
44   EXPECT_EQ(1U, [owner_ messageCount]);
46   [[trackingArea_ owner] performMessage];
47   EXPECT_EQ(2U, [owner_ messageCount]);
50 TEST_F(CrTrackingAreaTest, OwnerStopsForwarding) {
51   [[trackingArea_ owner] performMessage];
52   EXPECT_EQ(1U, [owner_ messageCount]);
54   [trackingArea_ clearOwner];
56   [[trackingArea_ owner] performMessage];
57   EXPECT_EQ(1U, [owner_ messageCount]);
60 TEST_F(CrTrackingAreaTest, OwnerAutomaticallyStopsForwardingOnClose) {
61   [test_window() orderFront:nil];
62   [trackingArea_ clearOwnerWhenWindowWillClose:test_window()];
64   [[trackingArea_ owner] performMessage];
65   EXPECT_EQ(1U, [owner_ messageCount]);
67   [test_window() close];
69   [[trackingArea_ owner] performMessage];
70   EXPECT_EQ(1U, [owner_ messageCount]);
73 TEST_F(CrTrackingAreaTest, ScoperInit) {
74   {
75     ScopedCrTrackingArea scoper([trackingArea_ retain]);
76     [[scoper.get() owner] performMessage];
77     EXPECT_EQ(1U, [owner_ messageCount]);
78   }
80   [[trackingArea_ owner] performMessage];
81   EXPECT_EQ(1U, [owner_ messageCount]);
84 TEST_F(CrTrackingAreaTest, ScoperReset) {
85   {
86     ScopedCrTrackingArea scoper;
87     EXPECT_FALSE(scoper.get());
89     scoper.reset([trackingArea_ retain]);
90     [[scoper.get() owner] performMessage];
91     EXPECT_EQ(1U, [owner_ messageCount]);
93     [[scoper.get() owner] performMessage];
94     EXPECT_EQ(2U, [owner_ messageCount]);
95   }
97   [[trackingArea_ owner] performMessage];
98   EXPECT_EQ(2U, [owner_ messageCount]);
101 }  // namespace ui