summaryrefslogtreecommitdiffstats
path: root/sync/android/javatests
diff options
context:
space:
mode:
authordsmyers@chromium.org <dsmyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-19 04:36:54 +0000
committerdsmyers@chromium.org <dsmyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-19 04:36:54 +0000
commit4385014499032789eb4db19a4ce3d34403dca62e (patch)
treefb2549a9cddbf3cbfe53c8730a46f34a6d1068b4 /sync/android/javatests
parentb040f9da1e83507fcff6588bacdcb7e298734940 (diff)
downloadchromium_src-4385014499032789eb4db19a4ce3d34403dca62e.zip
chromium_src-4385014499032789eb4db19a4ce3d34403dca62e.tar.gz
chromium_src-4385014499032789eb4db19a4ce3d34403dca62e.tar.bz2
Add an invalidation preferences wrapper.
Adds an InvalidationPreferences class that manages the preferences used by the sync code to store data, such as the sync types on which notifications should be received. BUG=159221 Review URL: https://chromiumcodereview.appspot.com/11969049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177835 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/android/javatests')
-rw-r--r--sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java9
-rw-r--r--sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java99
2 files changed, 107 insertions, 1 deletions
diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
index eee2bdf..0a84273 100644
--- a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
+++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationControllerTest.java
@@ -101,7 +101,7 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
assertEquals(account, intentAccount);
// Validate registered types.
- Set<String> expectedTypes = Sets.newHashSet(IntentProtocol.ALL_TYPES_TYPE);
+ Set<String> expectedTypes = Sets.newHashSet(ModelType.ALL_TYPES_TYPE);
Set<String> actualTypes = Sets.newHashSet();
actualTypes.addAll(intent.getStringArrayListExtra(IntentProtocol.EXTRA_REGISTERED_TYPES));
assertEquals(expectedTypes, actualTypes);
@@ -113,6 +113,13 @@ public class InvalidationControllerTest extends InstrumentationTestCase {
assertEquals(mContext.getPackageName(), mController.getContractAuthority());
}
+ @SmallTest
+ @Feature({"Sync"})
+ public void testGetIntentDestination() {
+ assertEquals("org.chromium.sync.notifier.TEST_VALUE",
+ InvalidationController.getDestinationClassName(mContext));
+ }
+
/**
* Asserts that {@code intent} is destined for the correct component.
*/
diff --git a/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java
new file mode 100644
index 0000000..ddaca6c
--- /dev/null
+++ b/sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java
@@ -0,0 +1,99 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.sync.notifier;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.google.common.collect.Sets;
+
+import org.chromium.base.test.util.AdvancedMockContext;
+import org.chromium.base.test.util.Feature;
+import org.chromium.sync.internal_api.pub.base.ModelType;
+import org.chromium.sync.notifier.InvalidationPreferences;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Tests for the {@link InvalidationPreferences}.
+ *
+ * @author dsmyers@google.com (Daniel Myers)
+ */
+public class InvalidationPreferencesTest extends InstrumentationTestCase {
+ private Context mContext;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContext = new AdvancedMockContext(getInstrumentation().getContext());
+ }
+
+ @SmallTest
+ @Feature({"Sync"})
+ public void testTranslateBasicSyncTypes() throws Exception {
+ /*
+ * Test plan: convert three strings to model types, one of which is invalid. Verify that
+ * the two valid strings are properly converted and that the invalid string is dropped.
+ */
+ HashSet<ModelType> expectedTypes = Sets.newHashSet(ModelType.BOOKMARK, ModelType.SESSION);
+ Set<ModelType> actualTypes = ModelType.syncTypesToModelTypes(
+ Sets.newHashSet("BOOKMARK", "SESSION", "0!!!INVALID"));
+ assertEquals(expectedTypes, actualTypes);
+ }
+
+ @SmallTest
+ @Feature({"Sync"})
+ public void testTranslateAllSyncTypes() {
+ /*
+ * Test plan: convert the special all-types type to model types. Verify that it is
+ * properly expanded.
+ */
+ HashSet<ModelType> expectedTypes = Sets.newHashSet(ModelType.values());
+ Set<ModelType> actualTypes = ModelType.syncTypesToModelTypes(
+ Sets.newHashSet(ModelType.ALL_TYPES_TYPE));
+ assertEquals(expectedTypes, actualTypes);
+ }
+
+ @SmallTest
+ @Feature({"Sync"})
+ public void testReadMissingData() {
+ /*
+ * Test plan: read saved state from empty preferences. Verify that null is returned.
+ */
+ InvalidationPreferences invPreferences = new InvalidationPreferences(mContext);
+ assertNull(invPreferences.getSavedSyncedAccount());
+ assertNull(invPreferences.getSavedSyncedTypes());
+ }
+
+ @SmallTest
+ @Feature({"Sync"})
+ public void testReadWriteAndReadData() {
+ /*
+ * Test plan: write and read back saved state. Verify that the returned state is what
+ * was written.
+ */
+ InvalidationPreferences invPreferences = new InvalidationPreferences(mContext);
+ InvalidationPreferences.EditContext editContext = invPreferences.edit();
+
+ // We should never write both a real type and the all-types type in practice, but we test
+ // with them here to ensure that preferences are not interpreting the written data.
+ Set<String> syncTypes = Sets.newHashSet("BOOKMARK", ModelType.ALL_TYPES_TYPE);
+ Account account = new Account("test@example.com", "bogus");
+ invPreferences.setSyncTypes(editContext, syncTypes);
+ invPreferences.setAccount(editContext, account);
+
+ // Nothing should yet have been written.
+ assertNull(invPreferences.getSavedSyncedAccount());
+ assertNull(invPreferences.getSavedSyncedTypes());
+
+ // Write the new data and verify that they are correctly read back.
+ invPreferences.commit(editContext);
+ assertEquals(account, invPreferences.getSavedSyncedAccount());
+ assertEquals(syncTypes, invPreferences.getSavedSyncedTypes());
+ }
+}