replicant-packages_apps_Email/tests/src/com/android/email/activity/setup/AccountSetupAccountTypeTest...

137 lines
4.4 KiB
Java
Raw Normal View History

2009-04-30 19:16:42 +00:00
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.email.activity.setup;
import com.android.email.R;
2009-04-30 19:16:42 +00:00
import com.android.email.mail.Store;
import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility;
2009-04-30 19:16:42 +00:00
import android.content.ContentUris;
2009-04-30 19:16:42 +00:00
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
2009-04-30 19:16:42 +00:00
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.View;
2009-04-30 19:16:42 +00:00
import java.net.URISyntaxException;
2009-04-30 19:16:42 +00:00
import java.util.HashSet;
/**
* This is a series of unit tests for the AccountSetupAccountType class.
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
* You can run this entire test case with:
* runtest -c com.android.email.activity.setup.AccountSetupAccountTypeTests email
2009-04-30 19:16:42 +00:00
*/
@SmallTest
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
public class AccountSetupAccountTypeTests
2009-04-30 19:16:42 +00:00
extends ActivityUnitTestCase<AccountSetupAccountType> {
Context mContext;
private HashSet<Account> mAccounts = new HashSet<Account>();
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
public AccountSetupAccountTypeTests() {
2009-04-30 19:16:42 +00:00
super(AccountSetupAccountType.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
mContext = this.getInstrumentation().getTargetContext();
}
/**
* Delete any dummy accounts we set up for this test
*/
@Override
protected void tearDown() throws Exception {
for (Account account : mAccounts) {
Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, account.mId);
mContext.getContentResolver().delete(uri, null, null);
2009-04-30 19:16:42 +00:00
}
// must call last because it scrubs member variables
super.tearDown();
2009-04-30 19:16:42 +00:00
}
2009-04-30 19:16:42 +00:00
/**
* Test store type limit enforcement
*/
public void testStoreTypeLimits()
throws URISyntaxException {
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
createTestAccount("scheme1");
createTestAccount("scheme1");
createTestAccount("scheme2");
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
AccountSetupAccountType activity = startActivity(getTestIntent(), null, null);
2009-04-30 19:16:42 +00:00
// Test with no limit
Store.StoreInfo info = new Store.StoreInfo();
info.mAccountInstanceLimit = -1;
info.mScheme = "scheme1";
assertTrue("no limit", activity.checkAccountInstanceLimit(info));
2009-04-30 19:16:42 +00:00
// Test with limit, but not reached
info.mAccountInstanceLimit = 3;
assertTrue("limit, but not reached", activity.checkAccountInstanceLimit(info));
2009-04-30 19:16:42 +00:00
// Test with limit, reached
info.mAccountInstanceLimit = 2;
assertFalse("limit, reached", activity.checkAccountInstanceLimit(info));
}
/**
* Confirm that EAS is presented, when supported.
*/
public void testEasOffered()
throws URISyntaxException {
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
createTestAccount("scheme1");
AccountSetupAccountType activity = startActivity(getTestIntent(), null, null);
View exchangeButton = activity.findViewById(R.id.exchange);
int expected = View.GONE; // Default is hidden
//EXCHANGE-REMOVE-SECTION-START
expected = View.VISIBLE; // Will be visible if supported.
//EXCHANGE-REMOVE-SECTION-END
assertEquals(expected, exchangeButton.getVisibility());
}
2009-04-30 19:16:42 +00:00
/**
* Create a dummy account with minimal fields
*/
private Account createTestAccount(String scheme)
throws URISyntaxException {
Account account = new Account();
HostAuth auth = account.getOrCreateHostAuthRecv(mContext);
Utility.setHostAuthFromString(auth, scheme + "://user:pass@server.com:123");
account.save(mContext);
2009-04-30 19:16:42 +00:00
mAccounts.add(account);
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
SetupData.init(SetupData.FLOW_MODE_NORMAL, account);
2009-04-30 19:16:42 +00:00
return account;
}
2009-04-30 19:16:42 +00:00
/**
* Create an intent with the Account in it
*/
Use AccountManager for POP/IMAP; refactor setup classes There are two major, interrelated parts to this CL: 1) Clean up the activities to reduce the use of Intents to pass information between activities; instead, we use a common SetupData structure that automatically saved/restored as necessary during the setup flow. A fair amount of code and inconsistent use of Bundle extras has been eliminated in the process. * Create SetupData structure, setters/getters, and initialization methods to simplify the preservation of state during setup flow * Remove all state/flow extras from Intents; Intents now only specify the Activity to be started, which should greatly simplify the transition to Fragments. * Remove all state/flow fields from Activities * Modify existing setup activity unit tests and confirm tests pass 2) Create AccountManager accounts for POP/IMAP email accounts to provide consistency in user experience. Also, internal flows are now identical as between account types. * Move account reconciliation from SyncManager to MailService, so that reconciliation is consistent between email and exchange accounts; move unit tests as appropriate * Add a "Sync Email" setting for POP/IMAP/EAS * Change MailService to respect the "Sync Email" setting in Settings -> Accounts & sync * Create PopImapSyncAdapterService to handle manual POP/IMAP sync as requested by SyncManager; add EmailSyncAdapterService to perform the same function for EAS * Use new PopImapAuthenticatorService to add AccountManager accounts for POP/IMAP accounts; setup appropriate stanzas in AndroidManifest and add related xml files * Update AccountSettings to use SetupData Miscellaneous other changes: * Only allow valid port numbers in incoming/outgoing setup Bug: 1712475 Change-Id: Ibdac52fb2c5578b86bf3992ddb1acd10f162391a
2010-07-08 17:08:47 +00:00
private Intent getTestIntent() {
return new Intent(Intent.ACTION_MAIN);
2009-04-30 19:16:42 +00:00
}
}