Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Side by Side Diff: ios/web_view/test/boolean_observer.mm

Issue 2892193002: Add unittest to test CWVWebView. (Closed)
Patch Set: Respond to comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #import "ios/web_view/test/boolean_observer.h"
6
7 #if !defined(__has_feature) || !__has_feature(objc_arc)
8 #error "This file requires ARC support."
9 #endif
10
11 @implementation BooleanObserver
12
13 @synthesize keyPath = _keyPath;
14 @synthesize lastValue = _lastValue;
15 @synthesize object = _object;
16
17 - (void)setObservedObject:(NSObject*)object keyPath:(NSString*)keyPath {
18 if (_object) {
Eugene But (OOO till 7-30) 2017/05/23 19:49:33 No need for this check, it's perfectly fine to cal
michaeldo 2017/05/24 15:02:34 Done.
19 [_object removeObserver:self forKeyPath:_keyPath];
20 }
21
22 _lastValue = NO;
23 _keyPath = [keyPath copy];
24 _object = object;
25 if (keyPath) {
Eugene But (OOO till 7-30) 2017/05/23 19:49:33 Is is there a value in passing nil keyPath? Should
michaeldo 2017/05/24 15:02:34 It's the only current way to stop this object from
Eugene But (OOO till 7-30) 2017/05/24 15:32:14 I think if we need API for stopping the observing,
26 [_object addObserver:self
27 forKeyPath:_keyPath
28 options:NSKeyValueObservingOptionNew
29 context:nil];
30 }
31 }
32
33 - (void)observeValueForKeyPath:(NSString*)keyPath
34 ofObject:(id)object
35 change:(NSDictionary<NSKeyValueChangeKey, id>*)change
36 context:(void*)context {
37 if (object != _object || keyPath != _keyPath) {
38 // Ignore extraneous call from previous |_object| or |_keyPath|.
39 return;
40 }
41 _lastValue = [change[NSKeyValueChangeNewKey] boolValue];
42 }
43
44 - (void)dealloc {
45 [_object removeObserver:self forKeyPath:_keyPath];
46 }
47
48 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698