observer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #ifndef IOS_WEB_VIEW_TEST_OBSERVER_H_
  5. #define IOS_WEB_VIEW_TEST_OBSERVER_H_
  6. #import <Foundation/Foundation.h>
  7. NS_ASSUME_NONNULL_BEGIN
  8. // Observes a KVO compliant property. To use this Observer, create an instance
  9. // and call |setObservedObject:keyPath:|. Then test expected values against
  10. // |lastValue|.
  11. @interface Observer : NSObject
  12. // The last value of performing |keyPath| on |object| after being notified of a
  13. // KVO value change or null if a change has not been observed.
  14. @property(nonatomic, nullable, readonly) id lastValue;
  15. // The previous value of |lastValue| or null if at least two changes have not
  16. // been observed.
  17. @property(nonatomic, nullable, readonly) id previousValue;
  18. // The |keyPath| of |object| being observed.
  19. @property(nonatomic, nullable, readonly) NSString* keyPath;
  20. // The current |object| being observed.
  21. @property(nonatomic, nullable, readonly, weak) NSObject* object;
  22. // Sets the |object| and |keyPath| to observe. The |keyPath| property of
  23. // |object| must exist and be KVO compliant.
  24. - (void)setObservedObject:(NSObject*)object keyPath:(NSString*)keyPath;
  25. @end
  26. NS_ASSUME_NONNULL_END
  27. #endif // IOS_WEB_VIEW_TEST_OBSERVER_H_