Commit 0ebc17fb authored by zhaoyangli's avatar zhaoyangli Committed by Commit Bot

Change FakeChromeIdentity to EDO pass-by-value class

This change will make EG2 tests work when FakeChromeIdentity is
passed between test and app processes.
- Overrode (BOOL)edo_isEDOValueType to let EDO framework pass it by
value.
- Made the class confirm to NSSecureCoding protocol as its required
by EDO pass-by-value.
- Overrode -isEqual and -hash methods to compare by values so that
comparing between copied objects will work.

Bug: 1015907, 922813

Change-Id: Iefadf89b401dabcee53e44ff1c6ce903cc979de4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1922336Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Zhaoyang Li <zhaoyangli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716467}
parent ffb30cf5
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#import "ios/public/provider/chrome/browser/signin/chrome_identity.h" #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
// A fake ChromeIdentity used for testing. // A fake ChromeIdentity used for testing.
@interface FakeChromeIdentity : ChromeIdentity @interface FakeChromeIdentity : ChromeIdentity <NSSecureCoding>
// Returns a ChromeIdentity based on |email|, |gaiaID| and |name|. // Returns a ChromeIdentity based on |email|, |gaiaID| and |name|.
// The |hashedGaiaID| property will be derived from |name|. // The |hashedGaiaID| property will be derived from |name|.
......
...@@ -4,10 +4,19 @@ ...@@ -4,10 +4,19 @@
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#include "base/mac/foundation_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace {
NSString* const kCoderUserEmailKey = @"UserEmail";
NSString* const kCoderGaiaIDKey = @"GaiaID";
NSString* const kCoderUserFullNameKey = @"UserFullName";
NSString* const kCoderHashedGaiaIDKey = @"HashedGaiaID";
} // namespace
@implementation FakeChromeIdentity { @implementation FakeChromeIdentity {
NSString* _userEmail; NSString* _userEmail;
NSString* _gaiaID; NSString* _gaiaID;
...@@ -52,4 +61,58 @@ ...@@ -52,4 +61,58 @@
return _hashedGaiaID; return _hashedGaiaID;
} }
// Overrides the method to return YES so that the object will be passed by value
// in EDO. This requires the object confirm to NSSecureCoding protocol.
- (BOOL)edo_isEDOValueType {
return YES;
}
// Overrides |isEqual| and |hash| methods to compare objects by values. This is
// useful when the object is passed by value between processes in EG2.
- (BOOL)isEqual:(id)object {
if (self == object) {
return YES;
}
if ([object isKindOfClass:self.class]) {
FakeChromeIdentity* other =
base::mac::ObjCCastStrict<FakeChromeIdentity>(object);
return [_userEmail isEqualToString:other.userEmail] &&
[_gaiaID isEqualToString:other.gaiaID] &&
[_userFullName isEqualToString:other.userFullName] &&
[_hashedGaiaID isEqualToString:other.hashedGaiaID];
}
return NO;
}
- (NSUInteger)hash {
return _gaiaID.hash;
}
#pragma mark - NSSecureCoding
- (void)encodeWithCoder:(NSCoder*)coder {
[coder encodeObject:_userEmail forKey:kCoderUserEmailKey];
[coder encodeObject:_gaiaID forKey:kCoderGaiaIDKey];
[coder encodeObject:_userFullName forKey:kCoderUserFullNameKey];
[coder encodeObject:_hashedGaiaID forKey:kCoderHashedGaiaIDKey];
}
- (id)initWithCoder:(NSCoder*)coder {
if ((self = [super init])) {
_userEmail = [coder decodeObjectOfClass:[NSString class]
forKey:kCoderUserEmailKey];
_gaiaID = [coder decodeObjectOfClass:[NSString class]
forKey:kCoderGaiaIDKey];
_userFullName = [coder decodeObjectOfClass:[NSString class]
forKey:kCoderUserFullNameKey];
_hashedGaiaID = [coder decodeObjectOfClass:[NSString class]
forKey:kCoderHashedGaiaIDKey];
}
return self;
}
+ (BOOL)supportsSecureCoding {
return YES;
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment