|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 package org.mozilla.gecko.background.sync; |
|
5 |
|
6 import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; |
|
7 import org.mozilla.gecko.sync.SyncConstants; |
|
8 import org.mozilla.gecko.sync.Utils; |
|
9 import org.mozilla.gecko.sync.setup.Constants; |
|
10 import org.mozilla.gecko.sync.setup.SyncAccounts; |
|
11 import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters; |
|
12 import org.mozilla.gecko.sync.setup.SyncAuthenticatorService; |
|
13 |
|
14 import android.accounts.Account; |
|
15 import android.accounts.AccountManager; |
|
16 import android.content.Context; |
|
17 import android.os.Bundle; |
|
18 |
|
19 public class TestSyncAuthenticatorService extends AndroidSyncTestCase { |
|
20 private static final String TEST_USERNAME = "testAccount@mozilla.com"; |
|
21 private static final String TEST_SYNCKEY = "testSyncKey"; |
|
22 private static final String TEST_PASSWORD = "testPassword"; |
|
23 private static final String TEST_SERVERURL = "test.server.url/"; |
|
24 |
|
25 private Account account; |
|
26 private Context context; |
|
27 private AccountManager accountManager; |
|
28 private SyncAccountParameters syncAccount; |
|
29 |
|
30 public void setUp() { |
|
31 account = null; |
|
32 context = getApplicationContext(); |
|
33 accountManager = AccountManager.get(context); |
|
34 syncAccount = new SyncAccountParameters(context, accountManager, |
|
35 TEST_USERNAME, TEST_SYNCKEY, TEST_PASSWORD, TEST_SERVERURL); |
|
36 } |
|
37 |
|
38 public void tearDown() { |
|
39 if (account == null) { |
|
40 return; |
|
41 } |
|
42 TestSyncAccounts.deleteAccount(this, accountManager, account); |
|
43 account = null; |
|
44 } |
|
45 |
|
46 public void testGetPlainAuthToken() throws Exception { |
|
47 account = SyncAccounts.createSyncAccount(syncAccount, false); |
|
48 assertNotNull(account); |
|
49 |
|
50 final Bundle bundle = SyncAuthenticatorService.getPlainAuthToken(context, account); |
|
51 |
|
52 assertEquals(TEST_USERNAME, bundle.getString(AccountManager.KEY_ACCOUNT_NAME)); |
|
53 assertEquals(SyncConstants.ACCOUNTTYPE_SYNC, bundle.getString(AccountManager.KEY_ACCOUNT_TYPE)); |
|
54 assertEquals(Utils.usernameFromAccount(TEST_USERNAME), bundle.getString(Constants.OPTION_USERNAME)); |
|
55 assertEquals(TEST_PASSWORD, bundle.getString(AccountManager.KEY_AUTHTOKEN)); |
|
56 assertEquals(TEST_SYNCKEY, bundle.getString(Constants.OPTION_SYNCKEY)); |
|
57 assertEquals(TEST_SERVERURL, bundle.getString(Constants.OPTION_SERVER)); |
|
58 } |
|
59 |
|
60 public void testGetBadTokenType() throws Exception { |
|
61 account = SyncAccounts.createSyncAccount(syncAccount, false); |
|
62 assertNotNull(account); |
|
63 |
|
64 assertNull(accountManager.blockingGetAuthToken(account, "BAD_TOKEN_TYPE", false)); |
|
65 } |
|
66 } |