OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/mac/scoped_nsobject.h" | |
7 #import "ios/chrome/browser/ui/open_in_toolbar.h" | 6 #import "ios/chrome/browser/ui/open_in_toolbar.h" |
8 #include "testing/platform_test.h" | 7 #include "testing/platform_test.h" |
9 #import "third_party/ocmock/OCMock/OCMock.h" | 8 #import "third_party/ocmock/OCMock/OCMock.h" |
10 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." |
| 12 #endif |
| 13 |
11 // A class that counts the number of times the |dummyMethod:| method is called. | 14 // A class that counts the number of times the |dummyMethod:| method is called. |
12 @interface DummyObserver : NSObject | 15 @interface DummyObserver : NSObject |
13 | 16 |
14 // The number of times |dummyMethod:| is invoked. | 17 // The number of times |dummyMethod:| is invoked. |
15 @property(nonatomic, readonly) int dummyMethodCallCount; | 18 @property(nonatomic, readonly) int dummyMethodCallCount; |
16 | 19 |
17 // The method whose invocation increases |dummyMethodCallCount| by one. | 20 // The method whose invocation increases |dummyMethodCallCount| by one. |
18 - (void)dummyMethod:(id)parameter; | 21 - (void)dummyMethod:(id)parameter; |
19 | 22 |
20 @end | 23 @end |
(...skipping 18 matching lines...) Expand all Loading... |
39 for (UIView* subview in subviews) { | 42 for (UIView* subview in subviews) { |
40 if ([subview isKindOfClass:[UIButton class]]) { | 43 if ([subview isKindOfClass:[UIButton class]]) { |
41 return (UIButton*)subview; | 44 return (UIButton*)subview; |
42 } | 45 } |
43 } | 46 } |
44 return nil; | 47 return nil; |
45 } | 48 } |
46 }; | 49 }; |
47 | 50 |
48 TEST_F(OpenInToolbarTest, TestButtonActionAndSelector) { | 51 TEST_F(OpenInToolbarTest, TestButtonActionAndSelector) { |
49 base::scoped_nsobject<DummyObserver> dummyObserver( | 52 DummyObserver* dummyObserver = [[DummyObserver alloc] init]; |
50 [[DummyObserver alloc] init]); | 53 OpenInToolbar* openInToolbar = |
51 base::scoped_nsobject<OpenInToolbar> openInToolbar([[OpenInToolbar alloc] | 54 [[OpenInToolbar alloc] initWithTarget:dummyObserver |
52 initWithTarget:dummyObserver | 55 action:@selector(dummyMethod:)]; |
53 action:@selector(dummyMethod:)]); | |
54 UIButton* button = GetOpenInButtonInToolBar(openInToolbar); | 56 UIButton* button = GetOpenInButtonInToolBar(openInToolbar); |
55 ASSERT_TRUE(button); | 57 ASSERT_TRUE(button); |
56 EXPECT_EQ([dummyObserver dummyMethodCallCount], 0); | 58 EXPECT_EQ([dummyObserver dummyMethodCallCount], 0); |
57 [button sendActionsForControlEvents:UIControlEventTouchUpInside]; | 59 [button sendActionsForControlEvents:UIControlEventTouchUpInside]; |
58 EXPECT_EQ([dummyObserver dummyMethodCallCount], 1); | 60 EXPECT_EQ([dummyObserver dummyMethodCallCount], 1); |
59 } | 61 } |
60 | 62 |
61 } // namespace | 63 } // namespace |
OLD | NEW |