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

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

Issue 2892193002: Add unittest to test CWVWebView. (Closed)
Patch Set: 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 #include "base/logging.h"
8
9 #if !defined(__has_feature) || !__has_feature(objc_arc)
10 #error "This file requires ARC support."
11 #endif
12
13 @implementation BooleanObserver
14
15 @synthesize keyPath = _keyPath;
16 @synthesize lastValue = _lastValue;
17 @synthesize object = _object;
18
19 - (void)setObservedObject:(NSObject*)object keyPath:(NSString*)keyPath {
20 if (_object) {
21 [_object removeObserver:self forKeyPath:_keyPath];
22 }
23
24 _lastValue = NO;
25 _keyPath = [keyPath copy];
26 _object = object;
27 [_object addObserver:self
28 forKeyPath:_keyPath
29 options:NSKeyValueObservingOptionNew
30 context:nil];
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
42 SEL selector = NSSelectorFromString(keyPath);
43 DCHECK([_object respondsToSelector:selector]);
44 #pragma clang diagnostic push
45 #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
46 _lastValue = [object performSelector:selector];
Eugene But (OOO till 7-30) 2017/05/19 18:39:48 Is this something you can get from |change| dictio
michaeldo 2017/05/23 16:20:51 Yes, it is cleaner to get out of |change|. Done.
47 #pragma clang diagnostic pop
48 }
49
50 - (void)dealloc {
51 [_object removeObserver:self forKeyPath:_keyPath];
52 }
53
54 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698