mobile/android/tests/background/junit3/src/sync/TestSyncAuthenticatorService.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/tests/background/junit3/src/sync/TestSyncAuthenticatorService.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +package org.mozilla.gecko.background.sync;
     1.8 +
     1.9 +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
    1.10 +import org.mozilla.gecko.sync.SyncConstants;
    1.11 +import org.mozilla.gecko.sync.Utils;
    1.12 +import org.mozilla.gecko.sync.setup.Constants;
    1.13 +import org.mozilla.gecko.sync.setup.SyncAccounts;
    1.14 +import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters;
    1.15 +import org.mozilla.gecko.sync.setup.SyncAuthenticatorService;
    1.16 +
    1.17 +import android.accounts.Account;
    1.18 +import android.accounts.AccountManager;
    1.19 +import android.content.Context;
    1.20 +import android.os.Bundle;
    1.21 +
    1.22 +public class TestSyncAuthenticatorService extends AndroidSyncTestCase {
    1.23 +  private static final String TEST_USERNAME   = "testAccount@mozilla.com";
    1.24 +  private static final String TEST_SYNCKEY    = "testSyncKey";
    1.25 +  private static final String TEST_PASSWORD   = "testPassword";
    1.26 +  private static final String TEST_SERVERURL  = "test.server.url/";
    1.27 +
    1.28 +  private Account account;
    1.29 +  private Context context;
    1.30 +  private AccountManager accountManager;
    1.31 +  private SyncAccountParameters syncAccount;
    1.32 +
    1.33 +  public void setUp() {
    1.34 +    account = null;
    1.35 +    context = getApplicationContext();
    1.36 +    accountManager = AccountManager.get(context);
    1.37 +    syncAccount = new SyncAccountParameters(context, accountManager,
    1.38 +        TEST_USERNAME, TEST_SYNCKEY, TEST_PASSWORD, TEST_SERVERURL);
    1.39 +  }
    1.40 +
    1.41 +  public void tearDown() {
    1.42 +    if (account == null) {
    1.43 +      return;
    1.44 +    }
    1.45 +    TestSyncAccounts.deleteAccount(this, accountManager, account);
    1.46 +    account = null;
    1.47 +  }
    1.48 +
    1.49 +  public void testGetPlainAuthToken() throws Exception {
    1.50 +    account = SyncAccounts.createSyncAccount(syncAccount, false);
    1.51 +    assertNotNull(account);
    1.52 +
    1.53 +    final Bundle bundle = SyncAuthenticatorService.getPlainAuthToken(context, account);
    1.54 +
    1.55 +    assertEquals(TEST_USERNAME, bundle.getString(AccountManager.KEY_ACCOUNT_NAME));
    1.56 +    assertEquals(SyncConstants.ACCOUNTTYPE_SYNC, bundle.getString(AccountManager.KEY_ACCOUNT_TYPE));
    1.57 +    assertEquals(Utils.usernameFromAccount(TEST_USERNAME), bundle.getString(Constants.OPTION_USERNAME));
    1.58 +    assertEquals(TEST_PASSWORD, bundle.getString(AccountManager.KEY_AUTHTOKEN));
    1.59 +    assertEquals(TEST_SYNCKEY, bundle.getString(Constants.OPTION_SYNCKEY));
    1.60 +    assertEquals(TEST_SERVERURL, bundle.getString(Constants.OPTION_SERVER));
    1.61 +  }
    1.62 +
    1.63 +  public void testGetBadTokenType() throws Exception {
    1.64 +    account = SyncAccounts.createSyncAccount(syncAccount, false);
    1.65 +    assertNotNull(account);
    1.66 +
    1.67 +    assertNull(accountManager.blockingGetAuthToken(account, "BAD_TOKEN_TYPE", false));
    1.68 +  }
    1.69 +}

mercurial