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

Unified Diff: ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm

Issue 2287383002: Add setup for integration tests in FakeChromeIdentityService. (Closed)
Patch Set: Created 4 years, 4 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/public/provider/chrome/browser/signin/fake_chrome_identity_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm
diff --git a/ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm b/ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm
index c8bcb9469f3e2ba06948e8acc2552cde6408fed6..8e01d9d5c7f2afcb3c0fe8b6fedc998a75f3e36e 100644
--- a/ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm
+++ b/ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.mm
@@ -7,8 +7,61 @@
#import <Foundation/Foundation.h>
#include "base/strings/sys_string_conversions.h"
+#include "google_apis/gaia/gaia_auth_util.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
+#include "ios/public/provider/chrome/browser/signin/signin_resources_provider.h"
+
+using ::testing::_;
+using ::testing::Invoke;
+
+namespace {
+
+void FakeGetAccessToken(ChromeIdentity*,
+ const std::string&,
+ const std::string&,
+ const std::set<std::string>&,
+ const ios::AccessTokenCallback& callback) {
+ // Token and expiration date. It should be larger than typical test
msarda 2016/08/30 12:23:08 These local variables are only used inside the blo
bzanotti 2016/08/30 12:36:34 Done.
+ // execution because tests usually setup mock to expect one token request
+ // and then rely on access token being served from cache.
+ NSTimeInterval expiration = 60.0;
+ NSDate* expiresDate = [NSDate dateWithTimeIntervalSinceNow:expiration];
+ NSString* token = [expiresDate description];
+
+ // GetAccessToken is normally an asynchronous operation (that requires some
msarda 2016/08/30 12:23:08 Nit: Here and for the comments below: s/GetAccessT
bzanotti 2016/08/30 12:36:34 Done.
+ // network calls), this is replicated here by dispatching it.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ callback(token, expiresDate, nil);
+ });
+}
+
+UIImage* FakeGetCachedAvatarForIdentity(ChromeIdentity*) {
+ ios::SigninResourcesProvider* provider =
+ ios::GetChromeBrowserProvider()->GetSigninResourcesProvider();
+ return provider ? provider->GetDefaultAvatar() : nil;
+}
+
+void FakeGetAvatarForIdentity(ChromeIdentity* identity,
+ ios::GetAvatarCallback callback) {
+ // GetAvatarForIdentity is normally an asynchronous operation, this is
+ // replicated here by dispatching it.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ callback(FakeGetCachedAvatarForIdentity(identity));
+ });
+}
+
+void FakeGetHostedDomainForIdentity(ChromeIdentity* identity,
+ ios::GetHostedDomainCallback callback) {
+ NSString* domain = base::SysUTF8ToNSString(gaia::ExtractDomainName(
+ gaia::CanonicalizeEmail(base::SysNSStringToUTF8(identity.userEmail))));
msarda 2016/08/30 12:23:08 Nit: Add blank line as otherwise reading this on t
bzanotti 2016/08/30 12:36:34 Done.
+ // GetHostedDomainForIdentity is normally an asynchronous operation , this is
+ // replicated here by dispatching it.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ callback(domain, nil);
+ });
+}
+}
namespace ios {
@@ -72,6 +125,20 @@ void FakeChromeIdentityService::ForgetIdentity(
}
}
+void FakeChromeIdentityService::SetUpForIntegrationTests() {
+ ON_CALL(*this, GetAccessToken(_, _, _, _, _))
+ .WillByDefault(Invoke(FakeGetAccessToken));
+
+ ON_CALL(*this, GetAvatarForIdentity(_, _))
+ .WillByDefault(Invoke(FakeGetAvatarForIdentity));
+
+ ON_CALL(*this, GetCachedAvatarForIdentity(_))
+ .WillByDefault(Invoke(FakeGetCachedAvatarForIdentity));
+
+ ON_CALL(*this, GetHostedDomainForIdentity(_, _))
+ .WillByDefault(Invoke(FakeGetHostedDomainForIdentity));
+}
+
void FakeChromeIdentityService::AddIdentities(NSArray* identitiesNames) {
for (NSString* name in identitiesNames) {
NSString* email = [NSString stringWithFormat:kIdentityEmailFormat, name];
« no previous file with comments | « ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698