Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: sync/android/javatests/src/org/chromium/sync/notifier/InvalidationPreferencesTest.java

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.sync.notifier;
6
7 import android.accounts.Account;
8 import android.test.InstrumentationTestCase;
9 import android.test.suitebuilder.annotation.SmallTest;
10
11 import com.google.ipc.invalidation.external.client.types.ObjectId;
12
13 import org.chromium.base.CollectionUtil;
14 import org.chromium.base.test.util.Feature;
15
16 import java.util.Arrays;
17 import java.util.Set;
18
19 /**
20 * Tests for the {@link InvalidationPreferences}.
21 *
22 * @author dsmyers@google.com (Daniel Myers)
23 */
24 public class InvalidationPreferencesTest extends InstrumentationTestCase {
25 @SmallTest
26 @Feature({"Sync"})
27 public void testReadMissingData() {
28 /*
29 * Test plan: read saved state from empty preferences. Verify that null is returned.
30 */
31 InvalidationPreferences invPreferences = new InvalidationPreferences();
32 assertNull(invPreferences.getSavedSyncedAccount());
33 assertNull(invPreferences.getSavedSyncedTypes());
34 assertNull(invPreferences.getSavedObjectIds());
35 assertNull(invPreferences.getInternalNotificationClientState());
36 }
37
38 @SmallTest
39 @Feature({"Sync"})
40 public void testReadWriteAndReadData() {
41 /*
42 * Test plan: write and read back saved state. Verify that the returned state is what
43 * was written.
44 */
45 InvalidationPreferences invPreferences = new InvalidationPreferences();
46 InvalidationPreferences.EditContext editContext = invPreferences.edit();
47
48 // Write mix of valid and invalid types to disk to test that preferences are not
49 // interpreting the data. Invalid types should never be written to disk in practice.
50 Set<String> syncTypes = CollectionUtil.newHashSet("BOOKMARK", "INVALID") ;
51 Set<ObjectId> objectIds = CollectionUtil.newHashSet(
52 ObjectId.newInstance(1, "obj1".getBytes()),
53 ObjectId.newInstance(2, "obj2".getBytes()));
54 Account account = new Account("test@example.com", "bogus");
55 byte[] internalClientState = new byte[]{100, 101, 102};
56 invPreferences.setSyncTypes(editContext, syncTypes);
57 invPreferences.setObjectIds(editContext, objectIds);
58 invPreferences.setAccount(editContext, account);
59 invPreferences.setInternalNotificationClientState(editContext, internalC lientState);
60
61 // Nothing should yet have been written.
62 assertNull(invPreferences.getSavedSyncedAccount());
63 assertNull(invPreferences.getSavedSyncedTypes());
64 assertNull(invPreferences.getSavedObjectIds());
65
66 // Write the new data and verify that they are correctly read back.
67 invPreferences.commit(editContext);
68 assertEquals(account, invPreferences.getSavedSyncedAccount());
69 assertEquals(syncTypes, invPreferences.getSavedSyncedTypes());
70 assertEquals(objectIds, invPreferences.getSavedObjectIds());
71 assertTrue(Arrays.equals(
72 internalClientState, invPreferences.getInternalNotificationClien tState()));
73 }
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698