diff options
author | Marcus Hagerott <mhagerott@google.com> | 2016-09-22 21:28:24 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-09-22 21:28:25 +0000 |
commit | 0493a6dfc6f0329b13a3bdd0f8eb7b1bb6728faf (patch) | |
tree | cbf056e0fa39bc7726d3d47b3798f8726970903c /tests | |
parent | 8debbac602d98b63602a27c29e9d78d2468c3d45 (diff) | |
parent | 949d4e88400761dac02992978f6b79997b5f0055 (diff) | |
download | packages_apps_Contacts-0493a6dfc6f0329b13a3bdd0f8eb7b1bb6728faf.tar.gz packages_apps_Contacts-0493a6dfc6f0329b13a3bdd0f8eb7b1bb6728faf.tar.bz2 packages_apps_Contacts-0493a6dfc6f0329b13a3bdd0f8eb7b1bb6728faf.zip |
Merge "Prevent device default account from sticking." into ub-contactsdialer-g-dev
Diffstat (limited to 'tests')
4 files changed, 62 insertions, 64 deletions
diff --git a/tests/src/com/android/contacts/common/model/AccountWithDataSetTest.java b/tests/src/com/android/contacts/common/model/AccountWithDataSetTest.java index 7bfb92216..933906340 100644 --- a/tests/src/com/android/contacts/common/model/AccountWithDataSetTest.java +++ b/tests/src/com/android/contacts/common/model/AccountWithDataSetTest.java @@ -59,11 +59,11 @@ public class AccountWithDataSetTest extends AndroidTestCase { } public void testStringifyAndUnstringifyLocalAccount() { - final String stringified = AccountWithDataSet.getLocalAccount().stringify(); + final String stringified = AccountWithDataSet.getNullAccount().stringify(); final AccountWithDataSet restored = AccountWithDataSet.unstringify(stringified); - assertEquals(AccountWithDataSet.getLocalAccount(), restored); + assertEquals(AccountWithDataSet.getNullAccount(), restored); } public void testStringifyListAndUnstringify() { diff --git a/tests/src/com/android/contacts/common/preference/ContactsPreferencesTest.java b/tests/src/com/android/contacts/common/preference/ContactsPreferencesTest.java index a84190250..8400737cb 100644 --- a/tests/src/com/android/contacts/common/preference/ContactsPreferencesTest.java +++ b/tests/src/com/android/contacts/common/preference/ContactsPreferencesTest.java @@ -31,6 +31,8 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import java.util.Arrays; + @SmallTest public class ContactsPreferencesTest extends InstrumentationTestCase { @@ -139,9 +141,8 @@ public class ContactsPreferencesTest extends InstrumentationTestCase { } public void testRefreshDefaultAccount() throws InterruptedException { - Mockito.when(mResources.getBoolean(Mockito.anyInt())).thenReturn( - true // R.bool.config_default_account_user_changeable - ); + mContactsPreferences = new ContactsPreferences(mContext, + /* isDefaultAccountUserChangeable */ true); Mockito.when(mSharedPreferences.getString(Mockito.eq(ACCOUNT_KEY), Mockito.anyString())) .thenReturn(new AccountWithDataSet("name1", "type1", "dataset1").stringify(), @@ -154,4 +155,46 @@ public class ContactsPreferencesTest extends InstrumentationTestCase { Assert.assertEquals(new AccountWithDataSet("name2", "type2", "dataset2"), mContactsPreferences.getDefaultAccount()); } + + public void testShouldShowAccountChangedNotificationIfAccountNotSaved() { + mContactsPreferences = new ContactsPreferences(mContext, + /* isDefaultAccountUserChangeable */ true); + Mockito.when(mSharedPreferences.getString(Mockito.eq(ACCOUNT_KEY), Mockito.anyString())) + .thenReturn(null); + + assertTrue("Should prompt to change default if no default is saved", + mContactsPreferences.shouldShowAccountChangedNotification(Arrays.asList( + new AccountWithDataSet("name1", "type1", "dataset1"), + new AccountWithDataSet("name2", "type2", "dataset2")))); + } + + public void testShouldShowAccountChangedNotification() { + mContactsPreferences = new ContactsPreferences(mContext, + /* isDefaultAccountUserChangeable */ true); + Mockito.when(mSharedPreferences.getString(Mockito.eq(ACCOUNT_KEY), Mockito.anyString())) + .thenReturn(new AccountWithDataSet("name", "type", "dataset").stringify()); + + assertFalse("Should not prompt to change default if current default exists", + mContactsPreferences.shouldShowAccountChangedNotification(Arrays.asList( + new AccountWithDataSet("name", "type", "dataset"), + new AccountWithDataSet("name1", "type1", "dataset1")))); + + assertTrue("Should prompt to change default if current default does not exist", + mContactsPreferences.shouldShowAccountChangedNotification(Arrays.asList( + new AccountWithDataSet("name1", "type1", "dataset1"), + new AccountWithDataSet("name2", "type2", "dataset2")))); + } + + public void testShouldShowAccountChangedNotificationWhenThereIsOneAccount() { + mContactsPreferences = new ContactsPreferences(mContext, + /* isDefaultAccountUserChangeable */ true); + Mockito.when(mSharedPreferences.getString(Mockito.eq(ACCOUNT_KEY), Mockito.anyString())) + .thenReturn(null); + + // Normally we would prompt because there is no default set but if there is just one + // account we should just use it. + assertFalse("Should not prompt to change default if there is only one account available", + mContactsPreferences.shouldShowAccountChangedNotification(Arrays.asList( + new AccountWithDataSet("name", "type", "dataset")))); + } } diff --git a/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java b/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java index b5df8c915..525a85c15 100644 --- a/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java +++ b/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java @@ -111,63 +111,18 @@ public class ContactEditorUtilsTest extends AndroidTestCase { /** * Test for - * - {@link ContactEditorUtils#saveDefaultAndAllAccounts} - * - {@link ContactEditorUtils#getDefaultAccount} - * - {@link ContactEditorUtils#getSavedAccounts()} + * - {@link ContactEditorUtils#saveDefaultAccount} + * - {@link ContactEditorUtils#getOnlyOrDefaultAccount} */ - public void testSaveDefaultAndAllAccounts() { + public void testSaveDefaultAccount() { // Use these account types here. setAccountTypes(TYPE1, TYPE2); - // If none has been saved, it should return an empty list. - assertEquals(0, mTarget.getSavedAccounts().size()); + mTarget.saveDefaultAccount(null); + assertNull(mTarget.getOnlyOrDefaultAccount()); - // Save 0 accounts. - mAccountTypes.mAccounts = new AccountWithDataSet[]{}; - mTarget.saveDefaultAndAllAccounts(null); - assertNull(mTarget.getDefaultAccount()); - MoreAsserts.assertEquals( - Sets.newHashSet(mAccountTypes.mAccounts), - toSet(mTarget.getSavedAccounts())); - - // 1 account - mAccountTypes.mAccounts = new AccountWithDataSet[]{ACCOUNT_1_A}; - mTarget.saveDefaultAndAllAccounts(ACCOUNT_1_A); - assertEquals(ACCOUNT_1_A, mTarget.getDefaultAccount()); - MoreAsserts.assertEquals( - Sets.newHashSet(mAccountTypes.mAccounts), - toSet(mTarget.getSavedAccounts())); - - // 2 accounts - mAccountTypes.mAccounts = new AccountWithDataSet[]{ACCOUNT_1_A, ACCOUNT_1_B}; - mTarget.saveDefaultAndAllAccounts(ACCOUNT_1_B); - assertEquals(ACCOUNT_1_B, mTarget.getDefaultAccount()); - MoreAsserts.assertEquals( - Sets.newHashSet(mAccountTypes.mAccounts), - toSet(mTarget.getSavedAccounts())); - - // 2 accounts, and save null as the default. Even though there are accounts, the saved - // account list should be empty in this case. - mTarget.saveDefaultAndAllAccounts(null); - assertNull(mTarget.getDefaultAccount()); - assertEquals(0, mTarget.getSavedAccounts().size()); - } - - public void testIsAccountValid() { - // Use these account types here. - setAccountTypes(TYPE1, TYPE2); - - // 0 accounts - mAccountTypes.mAccounts = new AccountWithDataSet[]{}; - assertFalse(mTarget.isValidAccount(ACCOUNT_1_A)); - assertTrue(mTarget.isValidAccount(null)); // null is always valid - - // 2 accounts - mAccountTypes.mAccounts = new AccountWithDataSet[]{ACCOUNT_1_A, ACCOUNT_2_A}; - assertTrue(mTarget.isValidAccount(ACCOUNT_1_A)); - assertTrue(mTarget.isValidAccount(ACCOUNT_2_A)); - assertFalse(mTarget.isValidAccount(ACCOUNT_2EX_A)); - assertTrue(mTarget.isValidAccount(null)); // null is always valid + mTarget.saveDefaultAccount(ACCOUNT_1_A); + assertEquals(ACCOUNT_1_A, mTarget.getOnlyOrDefaultAccount()); } /** @@ -186,7 +141,7 @@ public class ContactEditorUtilsTest extends AndroidTestCase { // Now we open the contact editor with the new account. // When closing the editor, we save the default account. - mTarget.saveDefaultAndAllAccounts(ACCOUNT_1_A); + mTarget.saveDefaultAccount(ACCOUNT_1_A); // Next time the user creates a contact, we don't show the notification. assertFalse(mTarget.shouldShowAccountChangedNotification()); @@ -198,7 +153,7 @@ public class ContactEditorUtilsTest extends AndroidTestCase { assertFalse(mTarget.shouldShowAccountChangedNotification()); // User saved a new contact. We update the account list and the default account. - mTarget.saveDefaultAndAllAccounts(ACCOUNT_1_B); + mTarget.saveDefaultAccount(ACCOUNT_1_B); // User created another contact. Now we don't show the notification. assertFalse(mTarget.shouldShowAccountChangedNotification()); @@ -214,7 +169,7 @@ public class ContactEditorUtilsTest extends AndroidTestCase { assertFalse(mTarget.shouldShowAccountChangedNotification()); // User saves a new contact, with a different default account. - mTarget.saveDefaultAndAllAccounts(ACCOUNT_2_A); + mTarget.saveDefaultAccount(ACCOUNT_2_A); // Next time user creates a contact, no notification. assertFalse(mTarget.shouldShowAccountChangedNotification()); @@ -253,7 +208,7 @@ public class ContactEditorUtilsTest extends AndroidTestCase { assertFalse(mTarget.shouldShowAccountChangedNotification()); // User saves a new contact. - mTarget.saveDefaultAndAllAccounts(ACCOUNT_1_A); + mTarget.saveDefaultAccount(ACCOUNT_1_A); // Next time, no notification. assertFalse(mTarget.shouldShowAccountChangedNotification()); @@ -272,7 +227,7 @@ public class ContactEditorUtilsTest extends AndroidTestCase { assertTrue(mTarget.shouldShowAccountChangedNotification()); // We show the notification here, and user clicked "keep local" and saved an contact. - mTarget.saveDefaultAndAllAccounts(AccountWithDataSet.getLocalAccount()); + mTarget.saveDefaultAccount(AccountWithDataSet.getNullAccount()); // Now there are no accounts, and default account is null. @@ -285,7 +240,7 @@ public class ContactEditorUtilsTest extends AndroidTestCase { setAccountTypes(TYPE1); setAccounts(ACCOUNT_1_A); - mTarget.saveDefaultAndAllAccounts(ACCOUNT_1_A); + mTarget.saveDefaultAccount(ACCOUNT_1_A); // Right after a save, the dialog shouldn't show up. assertFalse(mTarget.shouldShowAccountChangedNotification()); diff --git a/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java b/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java index e68511f25..aa3f725ab 100644 --- a/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java +++ b/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java @@ -122,7 +122,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_AccountType_DeviceAccount() { - final AccountWithDataSet deviceAccount = AccountWithDataSet.getLocalAccount(); + final AccountWithDataSet deviceAccount = AccountWithDataSet.getNullAccount(); final AccountDisplayInfo account = new AccountDisplayInfo(deviceAccount, "Device", "Device", /*icon*/ null, /*isDeviceAccount*/ true); |