summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2014-04-16 11:17:03 +0100
committerBen Murdoch <benm@google.com>2014-04-16 11:17:03 +0100
commita02191e04bc25c4935f804f2c080ae28663d096d (patch)
tree3cf38961650b5734763e473336009287244306ac /ios
parent8bad47e0f7d0c250a0443923cceb52f4a4abcd40 (diff)
downloadchromium_org-a02191e04bc25c4935f804f2c080ae28663d096d.tar.gz
Merge from Chromium at DEPS revision 263965
This commit was generated by merge_to_master.py. Change-Id: Ia1121eddd985123f160afde6372525c3d25975bf
Diffstat (limited to 'ios')
-rw-r--r--ios/ios_tests.gyp24
-rw-r--r--ios/provider/ios_components.gyp20
-rw-r--r--ios/public/DEPS12
-rw-r--r--ios/public/provider/components/signin/browser/profile_oauth2_token_service_ios_provider.h78
-rw-r--r--ios/public/test/fake_profile_oauth2_token_service_ios_provider.h63
-rw-r--r--ios/public/test/fake_profile_oauth2_token_service_ios_provider.mm91
6 files changed, 276 insertions, 12 deletions
diff --git a/ios/ios_tests.gyp b/ios/ios_tests.gyp
new file mode 100644
index 0000000000..563fe49569
--- /dev/null
+++ b/ios/ios_tests.gyp
@@ -0,0 +1,24 @@
+# Copyright 2014 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.
+{
+ 'variables': {
+ 'chromium_code': 1,
+ },
+ 'targets': [
+ {
+ 'target_name': 'test_support_ios',
+ 'type': 'static_library',
+ 'sources': [
+ 'public/test/fake_profile_oauth2_token_service_ios_provider.h',
+ 'public/test/fake_profile_oauth2_token_service_ios_provider.mm',
+ ],
+ 'dependencies': [
+ '<(DEPTH)/testing/gtest.gyp:gtest',
+ ],
+ 'include_dirs': [
+ '<(DEPTH)',
+ ],
+ },
+ ],
+}
diff --git a/ios/provider/ios_components.gyp b/ios/provider/ios_components.gyp
new file mode 100644
index 0000000000..002c43aef2
--- /dev/null
+++ b/ios/provider/ios_components.gyp
@@ -0,0 +1,20 @@
+# Copyright 2014 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.
+{
+ 'variables': {
+ 'chromium_code': 1,
+ },
+ 'targets': [
+ {
+ 'target_name': 'ios_components',
+ 'type': 'none',
+ 'include_dirs': [
+ '../..',
+ ],
+ 'sources': [
+ '../public/provider/components/signin/browser/profile_oauth2_token_service_ios_provider.h',
+ ]
+ },
+ ],
+}
diff --git a/ios/public/DEPS b/ios/public/DEPS
deleted file mode 100644
index c04c1d5dea..0000000000
--- a/ios/public/DEPS
+++ /dev/null
@@ -1,12 +0,0 @@
-include_rules = [
- # The public interfaces cannot reference Chromium code, so all allowances
- # that the top-level DEPS file introduces are removed here. This list should
- # be kept in sync with src/DEPS.
- "-base",
- "-build",
- "-library_loaders",
- "-testing",
- "-third_party/icu/source/common/unicode",
- "-third_party/icu/source/i18n/unicode",
- "-url",
-]
diff --git a/ios/public/provider/components/signin/browser/profile_oauth2_token_service_ios_provider.h b/ios/public/provider/components/signin/browser/profile_oauth2_token_service_ios_provider.h
new file mode 100644
index 0000000000..d6f5238c3b
--- /dev/null
+++ b/ios/public/provider/components/signin/browser/profile_oauth2_token_service_ios_provider.h
@@ -0,0 +1,78 @@
+// Copyright 2014 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.
+
+#ifndef IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
+#define IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
+
+#if defined(__OBJC__)
+@class NSDate;
+@class NSError;
+@class NSString;
+#else
+class NSDate;
+class NSError;
+class NSString;
+#endif // defined(__OBJC__)
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/callback.h"
+
+namespace ios {
+
+enum AuthenticationErrorCategory {
+ // Unknown errors.
+ kAuthenticationErrorCategoryUnknownErrors,
+ // Authorization errors.
+ kAuthenticationErrorCategoryAuthorizationErrors,
+ // Authorization errors with HTTP_FORBIDDEN (403) error code.
+ kAuthenticationErrorCategoryAuthorizationForbiddenErrors,
+ // Network server errors includes parsing error and should be treated as
+ // transient/offline errors.
+ kAuthenticationErrorCategoryNetworkServerErrors,
+ // User cancellation errors should be handled by treating them as a no-op.
+ kAuthenticationErrorCategoryUserCancellationErrors,
+ // User identity not found errors.
+ kAuthenticationErrorCategoryUnknownIdentityErrors,
+};
+
+// Interface that provides support for ProfileOAuth2TokenServiceIOS.
+class ProfileOAuth2TokenServiceIOSProvider {
+ public:
+ typedef base::Callback<void(NSString* token,
+ NSDate* expiration,
+ NSError* error)> AccessTokenCallback;
+
+ ProfileOAuth2TokenServiceIOSProvider() {};
+ virtual ~ProfileOAuth2TokenServiceIOSProvider() {};
+
+ // Returns whether authentication is using the shared authentication library.
+ virtual bool IsUsingSharedAuthentication() const = 0;
+
+ // Initializes the shared authentication library. This method should be called
+ // when loading credentials if the user is signed in to Chrome via the shared
+ // authentication library.
+ virtual void InitializeSharedAuthentication() = 0;
+
+ // Returns the ids of all accounts.
+ virtual std::vector<std::string> GetAllAccountIds() = 0;
+
+ // Starts fetching an access token for the account with id |account_id| with
+ // the given |scopes|. Once the token is obtained, |callback| is called.
+ virtual void GetAccessToken(const std::string& account_id,
+ const std::string& client_id,
+ const std::string& client_secret,
+ const std::set<std::string>& scopes,
+ const AccessTokenCallback& callback) = 0;
+
+ // Returns the authentication error category of |error|.
+ virtual AuthenticationErrorCategory GetAuthenticationErrorCategory(
+ NSError* error) const = 0;
+};
+
+} // namespace ios
+
+#endif // IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
diff --git a/ios/public/test/fake_profile_oauth2_token_service_ios_provider.h b/ios/public/test/fake_profile_oauth2_token_service_ios_provider.h
new file mode 100644
index 0000000000..2ca953ab7a
--- /dev/null
+++ b/ios/public/test/fake_profile_oauth2_token_service_ios_provider.h
@@ -0,0 +1,63 @@
+// Copyright 2014 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.
+
+#ifndef IOS_TEST_MOCK_PROFILE_OAUTH2_TOKEN_SERVICE_PROVIDER_IOS_H_
+#define IOS_TEST_MOCK_PROFILE_OAUTH2_TOKEN_SERVICE_PROVIDER_IOS_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "ios/public/provider/components/signin/browser/profile_oauth2_token_service_ios_provider.h"
+
+namespace ios {
+
+// Mock class of ProfileOAuth2TokenServiceIOSProvider for testing.
+class FakeProfileOAuth2TokenServiceIOSProvider
+ : public ProfileOAuth2TokenServiceIOSProvider {
+ public:
+ FakeProfileOAuth2TokenServiceIOSProvider();
+ virtual ~FakeProfileOAuth2TokenServiceIOSProvider();
+
+ // ProfileOAuth2TokenServiceIOSProvider
+ virtual bool IsUsingSharedAuthentication() const OVERRIDE;
+ virtual void InitializeSharedAuthentication() OVERRIDE;
+
+ virtual void GetAccessToken(const std::string& account_id,
+ const std::string& client_id,
+ const std::string& client_secret,
+ const std::set<std::string>& scopes,
+ const AccessTokenCallback& callback) OVERRIDE;
+
+ virtual std::vector<std::string> GetAllAccountIds() OVERRIDE;
+
+ virtual AuthenticationErrorCategory GetAuthenticationErrorCategory(
+ NSError* error) const OVERRIDE;
+
+ // Methods to configure this fake provider.
+ void AddAccount(const std::string& account_id);
+ void SetAccounts(const std::vector<std::string>& accounts);
+ void ClearAccounts();
+ void set_using_shared_authentication(bool is_using_shared_authentication) {
+ is_using_shared_authentication_ = is_using_shared_authentication;
+ }
+
+ // Issues access token responses.
+ void IssueAccessTokenForAllRequests();
+ void IssueAccessTokenErrorForAllRequests();
+
+ private:
+ typedef std::pair<std::string, AccessTokenCallback> AccessTokenRequest;
+
+ std::vector<std::string> accounts_;
+ bool is_using_shared_authentication_;
+ std::vector<AccessTokenRequest> requests_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenServiceIOSProvider);
+};
+
+} // namespace ios
+
+#endif // IOS_TEST_PROVIDER_CHROME_BROWSER_SIGNIN_MOCK_PROFILE_OAUTH2_TOKEN_SERVICE_PROVIDER_IOS_H_
diff --git a/ios/public/test/fake_profile_oauth2_token_service_ios_provider.mm b/ios/public/test/fake_profile_oauth2_token_service_ios_provider.mm
new file mode 100644
index 0000000000..e6ff73d085
--- /dev/null
+++ b/ios/public/test/fake_profile_oauth2_token_service_ios_provider.mm
@@ -0,0 +1,91 @@
+// Copyright 2014 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.
+
+#include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h"
+
+#include <Foundation/Foundation.h>
+
+#include "base/logging.h"
+#include "base/strings/sys_string_conversions.h"
+
+namespace ios {
+
+FakeProfileOAuth2TokenServiceIOSProvider::
+ FakeProfileOAuth2TokenServiceIOSProvider()
+ : is_using_shared_authentication_(true) {}
+
+FakeProfileOAuth2TokenServiceIOSProvider::
+ ~FakeProfileOAuth2TokenServiceIOSProvider() {}
+
+void FakeProfileOAuth2TokenServiceIOSProvider::GetAccessToken(
+ const std::string& account_id,
+ const std::string& client_id,
+ const std::string& client_secret,
+ const std::set<std::string>& scopes,
+ const AccessTokenCallback& callback) {
+ DCHECK(is_using_shared_authentication_);
+ requests_.push_back(AccessTokenRequest(account_id, callback));
+}
+
+std::vector<std::string>
+FakeProfileOAuth2TokenServiceIOSProvider::GetAllAccountIds() {
+ return accounts_;
+}
+
+void FakeProfileOAuth2TokenServiceIOSProvider::AddAccount(
+ const std::string& account_id) {
+ accounts_.push_back(account_id);
+}
+
+void FakeProfileOAuth2TokenServiceIOSProvider::SetAccounts(
+ const std::vector<std::string>& accounts) {
+ accounts_ = accounts;
+}
+
+void FakeProfileOAuth2TokenServiceIOSProvider::ClearAccounts() {
+ accounts_.clear();
+}
+
+void
+FakeProfileOAuth2TokenServiceIOSProvider::IssueAccessTokenForAllRequests() {
+ for (auto i = requests_.begin(); i != requests_.end(); ++i) {
+ std::string account_id = i->first;
+ AccessTokenCallback callback = i->second;
+ NSString* access_token = [NSString
+ stringWithFormat:@"fake_access_token [account=%s]", account_id.c_str()];
+ NSDate* one_hour_from_now = [NSDate dateWithTimeIntervalSinceNow:3600];
+ callback.Run(access_token, one_hour_from_now, nil);
+ }
+ requests_.clear();
+}
+
+void FakeProfileOAuth2TokenServiceIOSProvider::
+ IssueAccessTokenErrorForAllRequests() {
+ for (auto i = requests_.begin(); i != requests_.end(); ++i) {
+ std::string account_id = i->first;
+ AccessTokenCallback callback = i->second;
+ NSError* error = [[[NSError alloc] initWithDomain:@"fake_access_token_error"
+ code:-1
+ userInfo:nil] autorelease];
+ callback.Run(nil, nil, error);
+ }
+ requests_.clear();
+}
+
+bool FakeProfileOAuth2TokenServiceIOSProvider::IsUsingSharedAuthentication()
+ const {
+ return is_using_shared_authentication_;
+}
+
+void
+FakeProfileOAuth2TokenServiceIOSProvider::InitializeSharedAuthentication() {}
+
+AuthenticationErrorCategory
+FakeProfileOAuth2TokenServiceIOSProvider::GetAuthenticationErrorCategory(
+ NSError* error) const {
+ DCHECK(error);
+ return ios::kAuthenticationErrorCategoryAuthorizationErrors;
+}
+
+} // namespace ios