| 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/mac/scoped_nsautorelease_pool.h" | 7 #include "base/mac/scoped_nsautorelease_pool.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/gtest_mac.h" | 10 #include "testing/gtest_mac.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 @interface TestPartialObserver : NSObject<TestObserver> | 29 @interface TestPartialObserver : NSObject<TestObserver> |
| 30 @property(nonatomic, readonly) BOOL requiredMethodInvoked; | 30 @property(nonatomic, readonly) BOOL requiredMethodInvoked; |
| 31 @end | 31 @end |
| 32 | 32 |
| 33 // Implements all the methods in the TestObserver protocol. | 33 // Implements all the methods in the TestObserver protocol. |
| 34 @interface TestCompleteObserver : TestPartialObserver<TestObserver> | 34 @interface TestCompleteObserver : TestPartialObserver<TestObserver> |
| 35 @property(nonatomic, readonly) BOOL optionalMethodInvoked; | 35 @property(nonatomic, readonly) BOOL optionalMethodInvoked; |
| 36 @end | 36 @end |
| 37 | 37 |
| 38 @interface TestMutateObserver : TestCompleteObserver | 38 @interface TestMutateObserver : TestCompleteObserver |
| 39 | 39 - (instancetype)init NS_UNAVAILABLE; |
| 40 - (instancetype)initWithObserver:(CRBProtocolObservers*)observer | 40 - (instancetype)initWithObserver:(CRBProtocolObservers*)observer |
| 41 NS_DESIGNATED_INITIALIZER; | 41 NS_DESIGNATED_INITIALIZER; |
| 42 | 42 |
| 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() {} |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 [super reset]; | 251 [super reset]; |
| 252 _optionalMethodInvoked = NO; | 252 _optionalMethodInvoked = NO; |
| 253 } | 253 } |
| 254 | 254 |
| 255 @end | 255 @end |
| 256 | 256 |
| 257 @implementation TestMutateObserver { | 257 @implementation TestMutateObserver { |
| 258 __weak id _observers; | 258 __weak id _observers; |
| 259 } | 259 } |
| 260 | 260 |
| 261 - (instancetype)init { |
| 262 NOTREACHED(); |
| 263 return nil; |
| 264 } |
| 265 |
| 261 - (instancetype)initWithObserver:(CRBProtocolObservers*)observers { | 266 - (instancetype)initWithObserver:(CRBProtocolObservers*)observers { |
| 262 self = [super init]; | 267 self = [super init]; |
| 263 if (self) { | 268 if (self) { |
| 264 _observers = observers; | 269 _observers = observers; |
| 265 } | 270 } |
| 266 return self; | 271 return self; |
| 267 } | 272 } |
| 268 | 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 |