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

Unified Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/services/accountauthenticator/AccountAuthenticatorService.java

Issue 1258563005: Added Signin Utilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
Index: chrome/test/android/javatests/src/org/chromium/chrome/test/services/accountauthenticator/AccountAuthenticatorService.java
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/services/accountauthenticator/AccountAuthenticatorService.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/services/accountauthenticator/AccountAuthenticatorService.java
new file mode 100644
index 0000000000000000000000000000000000000000..09074e5c2f33be9b944a74954f0397cfc4ce5ecb
--- /dev/null
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/services/accountauthenticator/AccountAuthenticatorService.java
@@ -0,0 +1,115 @@
+// Copyright 2015 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.
+
+package org.chromium.chrome.test.services.accountauthenticator;
+
+import android.accounts.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.AccountManager;
+import android.app.Service;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.IBinder;
+
+/**
+ * Authenticators {@link Service} for test accounts. Allows adding fake accounts without password
+ * validation.
+ */
+public class AccountAuthenticatorService extends Service {
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return new AccountAuthenticator(this).getIBinder();
+ }
+
+ /**
+ * Account authenticator implementation for test accounts.
+ */
+ private final class AccountAuthenticator extends AbstractAccountAuthenticator {
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
+
+ public AccountAuthenticator(Context mContext) {
+ super(mContext);
+ this.mContext = mContext;
+ this.mContentResolver = mContext.getContentResolver();
+ }
+
+ @Override
+ public Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
+ String authTokenType, String[] requiredFeatures, Bundle options) {
+ Intent intent = new Intent(mContext, null /* AddAccountActivity.class */);
+ intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
+
+ Bundle result = new Bundle();
+ result.putParcelable(AccountManager.KEY_INTENT, intent);
+ return result;
+ }
+
+ @Override
+ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account,
+ Bundle options) {
+ Bundle result = new Bundle();
+ result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
+ return result;
+ }
+
+ @Override
+ public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
+ // Properties aren't supported
+ return Bundle.EMPTY;
+ }
+
+ @Override
+ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
+ String authTokenType, Bundle options) {
+ String authToken = null;
+ AccountManager accountManager = AccountManager.get(mContext);
+ Bundle result = new Bundle();
+
+ authToken = accountManager.getUserData(account, AccountManager.KEY_AUTHTOKEN);
+ if (authToken == null) {
+ authToken = "myToken";
+ }
+
+ accountManager.setUserData(account, AccountManager.KEY_AUTHTOKEN, authToken);
+ result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
+ result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
+ result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
+ return result;
+ }
+
+ @Override
+ public String getAuthTokenLabel(String authTokenType) {
+ return authTokenType;
+ }
+
+ @Override
+ public Bundle hasFeatures(
+ AccountAuthenticatorResponse response, Account account, String[] features) {
+ Bundle result = new Bundle();
+ result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
+ return result;
+ }
+
+ @Override
+ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account,
+ String authTokenType, Bundle options) {
+ Bundle result = new Bundle();
+ if (!shouldFailAuth(account)) {
+ result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
+ result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
+ }
+ return result;
+ }
+
+ private boolean shouldFailAuth(Account account) {
+ AccountManager accountManager = AccountManager.get(mContext);
+ return "AUTH_FAILS".equals(accountManager.getPassword(account));
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698