| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.sync.notifier; | 5 package org.chromium.components.sync.notifier; |
| 6 | 6 |
| 7 import android.accounts.Account; | 7 import android.accounts.Account; |
| 8 import android.test.InstrumentationTestCase; | 8 import android.test.InstrumentationTestCase; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 | 10 |
| 11 import com.google.ipc.invalidation.external.client.types.ObjectId; | 11 import com.google.ipc.invalidation.external.client.types.ObjectId; |
| 12 | 12 |
| 13 import org.chromium.base.CollectionUtil; | 13 import org.chromium.base.CollectionUtil; |
| 14 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
| 15 | 15 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 41 /* | 41 /* |
| 42 * Test plan: write and read back saved state. Verify that the returned
state is what | 42 * Test plan: write and read back saved state. Verify that the returned
state is what |
| 43 * was written. | 43 * was written. |
| 44 */ | 44 */ |
| 45 InvalidationPreferences invPreferences = new InvalidationPreferences(); | 45 InvalidationPreferences invPreferences = new InvalidationPreferences(); |
| 46 InvalidationPreferences.EditContext editContext = invPreferences.edit(); | 46 InvalidationPreferences.EditContext editContext = invPreferences.edit(); |
| 47 | 47 |
| 48 // Write mix of valid and invalid types to disk to test that preferences
are not | 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. | 49 // interpreting the data. Invalid types should never be written to disk
in practice. |
| 50 Set<String> syncTypes = CollectionUtil.newHashSet("BOOKMARK", "INVALID")
; | 50 Set<String> syncTypes = CollectionUtil.newHashSet("BOOKMARK", "INVALID")
; |
| 51 Set<ObjectId> objectIds = CollectionUtil.newHashSet( | 51 Set<ObjectId> objectIds = |
| 52 ObjectId.newInstance(1, "obj1".getBytes()), | 52 CollectionUtil.newHashSet(ObjectId.newInstance(1, "obj1".getByte
s()), |
| 53 ObjectId.newInstance(2, "obj2".getBytes())); | 53 ObjectId.newInstance(2, "obj2".getBytes())); |
| 54 Account account = new Account("test@example.com", "bogus"); | 54 Account account = new Account("test@example.com", "bogus"); |
| 55 byte[] internalClientState = new byte[]{100, 101, 102}; | 55 byte[] internalClientState = new byte[] {100, 101, 102}; |
| 56 invPreferences.setSyncTypes(editContext, syncTypes); | 56 invPreferences.setSyncTypes(editContext, syncTypes); |
| 57 invPreferences.setObjectIds(editContext, objectIds); | 57 invPreferences.setObjectIds(editContext, objectIds); |
| 58 invPreferences.setAccount(editContext, account); | 58 invPreferences.setAccount(editContext, account); |
| 59 invPreferences.setInternalNotificationClientState(editContext, internalC
lientState); | 59 invPreferences.setInternalNotificationClientState(editContext, internalC
lientState); |
| 60 | 60 |
| 61 // Nothing should yet have been written. | 61 // Nothing should yet have been written. |
| 62 assertNull(invPreferences.getSavedSyncedAccount()); | 62 assertNull(invPreferences.getSavedSyncedAccount()); |
| 63 assertNull(invPreferences.getSavedSyncedTypes()); | 63 assertNull(invPreferences.getSavedSyncedTypes()); |
| 64 assertNull(invPreferences.getSavedObjectIds()); | 64 assertNull(invPreferences.getSavedObjectIds()); |
| 65 | 65 |
| 66 // Write the new data and verify that they are correctly read back. | 66 // Write the new data and verify that they are correctly read back. |
| 67 invPreferences.commit(editContext); | 67 invPreferences.commit(editContext); |
| 68 assertEquals(account, invPreferences.getSavedSyncedAccount()); | 68 assertEquals(account, invPreferences.getSavedSyncedAccount()); |
| 69 assertEquals(syncTypes, invPreferences.getSavedSyncedTypes()); | 69 assertEquals(syncTypes, invPreferences.getSavedSyncedTypes()); |
| 70 assertEquals(objectIds, invPreferences.getSavedObjectIds()); | 70 assertEquals(objectIds, invPreferences.getSavedObjectIds()); |
| 71 assertTrue(Arrays.equals( | 71 assertTrue(Arrays.equals( |
| 72 internalClientState, invPreferences.getInternalNotificationClien
tState())); | 72 internalClientState, invPreferences.getInternalNotificationClien
tState())); |
| 73 } | 73 } |
| 74 } | 74 } |
| OLD | NEW |