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 #import "base/ios/crb_protocol_observers.h" | 5 #import "base/ios/crb_protocol_observers.h" |
6 #include "base/ios/weak_nsobject.h" | 6 #include "base/ios/weak_nsobject.h" |
| 7 #include "base/logging.h" |
7 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
8 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/gtest_mac.h" | 11 #include "testing/gtest_mac.h" |
11 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
12 | 13 |
13 @protocol TestObserver | 14 @protocol TestObserver |
14 | 15 |
15 @required | 16 @required |
16 - (void)requiredMethod; | 17 - (void)requiredMethod; |
(...skipping 12 matching lines...) Expand all Loading... |
29 @interface TestPartialObserver : NSObject<TestObserver> | 30 @interface TestPartialObserver : NSObject<TestObserver> |
30 @property(nonatomic, readonly) BOOL requiredMethodInvoked; | 31 @property(nonatomic, readonly) BOOL requiredMethodInvoked; |
31 @end | 32 @end |
32 | 33 |
33 // Implements all the methods in the TestObserver protocol. | 34 // Implements all the methods in the TestObserver protocol. |
34 @interface TestCompleteObserver : TestPartialObserver<TestObserver> | 35 @interface TestCompleteObserver : TestPartialObserver<TestObserver> |
35 @property(nonatomic, readonly) BOOL optionalMethodInvoked; | 36 @property(nonatomic, readonly) BOOL optionalMethodInvoked; |
36 @end | 37 @end |
37 | 38 |
38 @interface TestMutateObserver : TestCompleteObserver | 39 @interface TestMutateObserver : TestCompleteObserver |
39 | |
40 - (instancetype)initWithObserver:(CRBProtocolObservers*)observer | 40 - (instancetype)initWithObserver:(CRBProtocolObservers*)observer |
41 NS_DESIGNATED_INITIALIZER; | 41 NS_DESIGNATED_INITIALIZER; |
42 | 42 - (instancetype)init NS_UNAVAILABLE; |
43 @end | 43 @end |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 class CRBProtocolObserversTest : public PlatformTest { | 47 class CRBProtocolObserversTest : public PlatformTest { |
48 public: | 48 public: |
49 CRBProtocolObserversTest() {} | 49 CRBProtocolObserversTest() {} |
50 | 50 |
51 protected: | 51 protected: |
52 void SetUp() override { | 52 void SetUp() override { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 259 } |
260 | 260 |
261 - (instancetype)initWithObserver:(CRBProtocolObservers*)observers { | 261 - (instancetype)initWithObserver:(CRBProtocolObservers*)observers { |
262 self = [super init]; | 262 self = [super init]; |
263 if (self) { | 263 if (self) { |
264 _observers = observers; | 264 _observers = observers; |
265 } | 265 } |
266 return self; | 266 return self; |
267 } | 267 } |
268 | 268 |
| 269 - (instancetype)init { |
| 270 NOTREACHED(); |
| 271 return nil; |
| 272 } |
| 273 |
269 - (void)mutateByAddingObserver:(id<TestObserver>)observer { | 274 - (void)mutateByAddingObserver:(id<TestObserver>)observer { |
270 [_observers addObserver:observer]; | 275 [_observers addObserver:observer]; |
271 } | 276 } |
272 | 277 |
273 - (void)mutateByRemovingObserver:(id<TestObserver>)observer { | 278 - (void)mutateByRemovingObserver:(id<TestObserver>)observer { |
274 [_observers removeObserver:observer]; | 279 [_observers removeObserver:observer]; |
275 } | 280 } |
276 | 281 |
277 - (void)nestedMutateByAddingObserver:(id<TestObserver>)observer { | 282 - (void)nestedMutateByAddingObserver:(id<TestObserver>)observer { |
278 [_observers mutateByAddingObserver:observer]; | 283 [_observers mutateByAddingObserver:observer]; |
279 } | 284 } |
280 | 285 |
281 - (void)nestedMutateByRemovingObserver:(id<TestObserver>)observer { | 286 - (void)nestedMutateByRemovingObserver:(id<TestObserver>)observer { |
282 [_observers mutateByRemovingObserver:observer]; | 287 [_observers mutateByRemovingObserver:observer]; |
283 } | 288 } |
284 | 289 |
285 @end | 290 @end |
OLD | NEW |