OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "base/mac/scoped_sending_event.h" | 5 #import "base/mac/scoped_sending_event.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | |
8 | |
9 #include "base/mac/scoped_nsobject.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
8 | 11 |
Mark Mentovai
2014/10/17 19:44:58
:)
| |
12 @interface ScopedSendingEventTestCrApp : NSObject <CrAppControlProtocol> { | |
13 @private | |
14 BOOL handlingSendEvent_; | |
15 } | |
16 @property(nonatomic, assign, getter=isHandlingSendEvent) BOOL handlingSendEvent; | |
17 @end | |
18 | |
19 @implementation ScopedSendingEventTestCrApp | |
20 @synthesize handlingSendEvent = handlingSendEvent_; | |
21 @end | |
22 | |
9 namespace { | 23 namespace { |
10 | 24 |
25 class ScopedSendingEventTest : public testing::Test { | |
26 public: | |
27 ScopedSendingEventTest() : app_([[ScopedSendingEventTestCrApp alloc] init]) { | |
28 NSApp = app_.get(); | |
29 } | |
30 virtual ~ScopedSendingEventTest() { | |
31 NSApp = nil; | |
32 } | |
33 | |
34 private: | |
35 base::scoped_nsobject<ScopedSendingEventTestCrApp> app_; | |
36 }; | |
37 | |
11 // Sets the flag within scope, resets when leaving scope. | 38 // Sets the flag within scope, resets when leaving scope. |
12 TEST(ScopedSendingEventTest, SetHandlingSendEvent) { | 39 TEST_F(ScopedSendingEventTest, SetHandlingSendEvent) { |
13 id<CrAppProtocol> app = NSApp; | 40 id<CrAppProtocol> app = NSApp; |
14 EXPECT_FALSE([app isHandlingSendEvent]); | 41 EXPECT_FALSE([app isHandlingSendEvent]); |
15 { | 42 { |
16 base::mac::ScopedSendingEvent is_handling_send_event; | 43 base::mac::ScopedSendingEvent is_handling_send_event; |
17 EXPECT_TRUE([app isHandlingSendEvent]); | 44 EXPECT_TRUE([app isHandlingSendEvent]); |
18 } | 45 } |
19 EXPECT_FALSE([app isHandlingSendEvent]); | 46 EXPECT_FALSE([app isHandlingSendEvent]); |
20 } | 47 } |
21 | 48 |
22 // Nested call restores previous value rather than resetting flag. | 49 // Nested call restores previous value rather than resetting flag. |
23 TEST(ScopedSendingEventTest, NestedSetHandlingSendEvent) { | 50 TEST_F(ScopedSendingEventTest, NestedSetHandlingSendEvent) { |
24 id<CrAppProtocol> app = NSApp; | 51 id<CrAppProtocol> app = NSApp; |
25 EXPECT_FALSE([app isHandlingSendEvent]); | 52 EXPECT_FALSE([app isHandlingSendEvent]); |
26 { | 53 { |
27 base::mac::ScopedSendingEvent is_handling_send_event; | 54 base::mac::ScopedSendingEvent is_handling_send_event; |
28 EXPECT_TRUE([app isHandlingSendEvent]); | 55 EXPECT_TRUE([app isHandlingSendEvent]); |
29 { | 56 { |
30 base::mac::ScopedSendingEvent nested_is_handling_send_event; | 57 base::mac::ScopedSendingEvent nested_is_handling_send_event; |
31 EXPECT_TRUE([app isHandlingSendEvent]); | 58 EXPECT_TRUE([app isHandlingSendEvent]); |
32 } | 59 } |
33 EXPECT_TRUE([app isHandlingSendEvent]); | 60 EXPECT_TRUE([app isHandlingSendEvent]); |
34 } | 61 } |
35 EXPECT_FALSE([app isHandlingSendEvent]); | 62 EXPECT_FALSE([app isHandlingSendEvent]); |
36 } | 63 } |
37 | 64 |
38 } // namespace | 65 } // namespace |
OLD | NEW |