aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSandeep Siddhartha <sansid@google.com>2014-10-09 16:41:25 -0700
committerSandeep Siddhartha <sansid@google.com>2014-10-10 16:03:54 -0700
commitd9015233f50724294bb408f1c56715a581dc4bed (patch)
treee9609fa9518fb442a48996e134d845a90cb69aba /tests
parent1e10d29bc8975ea45ca5e3bdf1936aa418161bcb (diff)
downloadlatinime-d9015233f50724294bb408f1c56715a581dc4bed.tar.gz
latinime-d9015233f50724294bb408f1c56715a581dc4bed.tar.xz
latinime-d9015233f50724294bb408f1c56715a581dc4bed.zip
Set up a sync preference and policy for syncing [2]
- Adds a preference for enabling sync, which controls the sync behavior - Make the ProductionFlags depend on appropriate flags to guarantee that we don't mess things when flipping some flags - Preferences now control the "syncable" property of the provider thereby controlling the policy and when this entry shows up in system settings. Bug: 17464069 Change-Id: I1d58351188518c1ae9f1f9e147b5ea15d32a3427
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java
index 2ef8b548f..a0b2c2296 100644
--- a/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java
+++ b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java
@@ -16,14 +16,20 @@
package com.android.inputmethod.latin.settings;
+import static com.android.inputmethod.latin.settings.AccountsSettingsFragment.AUTHORITY;
+
+import android.accounts.Account;
import android.app.AlertDialog;
import android.app.Dialog;
+import android.content.ContentResolver;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.View;
import android.widget.ListView;
+import com.android.inputmethod.latin.define.ProductionFlags;
+
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -32,6 +38,7 @@ public class AccountsSettingsFragmentTests
extends ActivityInstrumentationTestCase2<TestFragmentActivity> {
private static final String FRAG_NAME = AccountsSettingsFragment.class.getName();
private static final long TEST_TIMEOUT_MILLIS = 5000;
+ private static final Account TEST_ACCOUNT = new Account("account-for-test", "account-type");
private AlertDialog mDialog;
@@ -47,6 +54,13 @@ public class AccountsSettingsFragmentTests
setActivityIntent(intent);
}
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ // reset the syncable state to unknown
+ ContentResolver.setIsSyncable(TEST_ACCOUNT, AUTHORITY, -1);
+ }
+
public void testEmptyAccounts() {
final AccountsSettingsFragment fragment =
(AccountsSettingsFragment) getActivity().mFragment;
@@ -129,4 +143,57 @@ public class AccountsSettingsFragmentTests
assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_NEGATIVE).getVisibility());
assertEquals(View.VISIBLE, mDialog.getButton(Dialog.BUTTON_POSITIVE).getVisibility());
}
+
+ public void testUpdateSyncPolicy_enable() {
+ // This test is a no-op when ENABLE_PERSONAL_DICTIONARY_SYNC is not enabled
+ if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+ return;
+ }
+ // Should be unknown by default.
+ assertTrue(ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY) < 0);
+
+ final AccountsSettingsFragment fragment =
+ (AccountsSettingsFragment) getActivity().mFragment;
+ fragment.updateSyncPolicy(true, TEST_ACCOUNT);
+
+ // Should be syncable now.
+ assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+ }
+
+ public void testUpdateSyncPolicy_disable() {
+ // This test is a no-op when ENABLE_PERSONAL_DICTIONARY_SYNC is not enabled
+ if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+ return;
+ }
+ // Should be unknown by default.
+ assertTrue(ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY) < 0);
+
+ final AccountsSettingsFragment fragment =
+ (AccountsSettingsFragment) getActivity().mFragment;
+ fragment.updateSyncPolicy(false, TEST_ACCOUNT);
+
+ // Should not be syncable now.
+ assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+ }
+
+ public void testUpdateSyncPolicy_enableDisable() {
+ // This test is a no-op when ENABLE_PERSONAL_DICTIONARY_SYNC is not enabled
+ if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
+ return;
+ }
+ // Should be unknown by default.
+ assertTrue(ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY) < 0);
+
+ final AccountsSettingsFragment fragment =
+ (AccountsSettingsFragment) getActivity().mFragment;
+ fragment.updateSyncPolicy(true, TEST_ACCOUNT);
+
+ // Should be syncable now.
+ assertEquals(1, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+
+ fragment.updateSyncPolicy(false, TEST_ACCOUNT);
+
+ // Should not be syncable now.
+ assertEquals(0, ContentResolver.getIsSyncable(TEST_ACCOUNT, AUTHORITY));
+ }
}