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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web_view/test/boolean_observer.h ('k') | ios/web_view/test/chrome_web_view_kvo_inttest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web_view/test/boolean_observer.mm
diff --git a/ios/web_view/test/boolean_observer.mm b/ios/web_view/test/boolean_observer.mm
new file mode 100644
index 0000000000000000000000000000000000000000..fc2b5f2dcd3cb873f01b2634f65db7f7e3e88db2
--- /dev/null
+++ b/ios/web_view/test/boolean_observer.mm
@@ -0,0 +1,46 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/web_view/test/boolean_observer.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@implementation BooleanObserver
+
+@synthesize keyPath = _keyPath;
+@synthesize lastValue = _lastValue;
+@synthesize object = _object;
+
+- (void)setObservedObject:(NSObject*)object keyPath:(NSString*)keyPath {
+ [_object removeObserver:self forKeyPath:_keyPath];
+
+ _lastValue = nil;
+ _keyPath = [keyPath copy];
+ _object = object;
+ if (keyPath) {
+ [_object addObserver:self
+ forKeyPath:_keyPath
+ options:NSKeyValueObservingOptionNew
+ context:nil];
+ }
+}
+
+- (void)observeValueForKeyPath:(NSString*)keyPath
+ ofObject:(id)object
+ change:(NSDictionary<NSKeyValueChangeKey, id>*)change
+ context:(void*)context {
+ if (![object isEqual:_object] || ![keyPath isEqualToString:_keyPath]) {
+ // Ignore extraneous call from previous |_object| or |_keyPath|.
+ return;
+ }
+ _lastValue = change[NSKeyValueChangeNewKey];
+}
+
+- (void)dealloc {
+ [_object removeObserver:self forKeyPath:_keyPath];
+}
+
+@end
« no previous file with comments | « ios/web_view/test/boolean_observer.h ('k') | ios/web_view/test/chrome_web_view_kvo_inttest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698