EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.sync.notifier]

COVERAGE SUMMARY FOR SOURCE FILE [InvalidationPreferencesTest.java]

nameclass, %method, %block, %line, %
InvalidationPreferencesTest.java100% (1/1)100% (6/6)100% (157/157)100% (32/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InvalidationPreferencesTest100% (1/1)100% (6/6)100% (157/157)100% (32/32)
InvalidationPreferencesTest (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (11/11)100% (3/3)
testReadMissingData (): void 100% (1/1)100% (16/16)100% (5/5)
testReadWriteAndReadData (): void 100% (1/1)100% (78/78)100% (15/15)
testTranslateAllSyncTypes (): void 100% (1/1)100% (16/16)100% (4/4)
testTranslateBasicSyncTypes (): void 100% (1/1)100% (33/33)100% (4/4)

1// Copyright (c) 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 
5package org.chromium.sync.notifier;
6 
7import android.accounts.Account;
8import android.content.Context;
9import android.test.InstrumentationTestCase;
10import android.test.suitebuilder.annotation.SmallTest;
11 
12import org.chromium.base.CollectionUtil;
13import org.chromium.base.test.util.AdvancedMockContext;
14import org.chromium.base.test.util.Feature;
15import org.chromium.sync.internal_api.pub.base.ModelType;
16 
17import java.util.Arrays;
18import java.util.EnumSet;
19import java.util.HashSet;
20import java.util.Set;
21 
22/**
23 * Tests for the {@link InvalidationPreferences}.
24 *
25 * @author dsmyers@google.com (Daniel Myers)
26 */
27public class InvalidationPreferencesTest extends InstrumentationTestCase {
28    private Context mContext;
29 
30    @Override
31    protected void setUp() throws Exception {
32        super.setUp();
33        mContext = new AdvancedMockContext(getInstrumentation().getContext());
34    }
35 
36    @SmallTest
37    @Feature({"Sync"})
38    public void testTranslateBasicSyncTypes() throws Exception {
39        /*
40         * Test plan: convert three strings to model types, one of which is invalid. Verify that
41         * the two valid strings are properly converted and that the invalid string is dropped.
42         */
43        HashSet<ModelType> expectedTypes = CollectionUtil.newHashSet(
44                ModelType.BOOKMARK,ModelType.SESSION);
45        Set<ModelType> actualTypes = ModelType.syncTypesToModelTypes(
46                CollectionUtil.newHashSet("BOOKMARK", "SESSION", "0!!!INVALID"));
47        assertEquals(expectedTypes, actualTypes);
48    }
49 
50    @SmallTest
51    @Feature({"Sync"})
52    public void testTranslateAllSyncTypes() {
53        /*
54         * Test plan: convert the special all-types type to model types. Verify that it is
55         * properly expanded.
56         */
57        Set<ModelType> expectedTypes = EnumSet.allOf(ModelType.class);
58        Set<ModelType> actualTypes = ModelType.syncTypesToModelTypes(
59                CollectionUtil.newHashSet(ModelType.ALL_TYPES_TYPE));
60        assertEquals(expectedTypes, actualTypes);
61    }
62 
63    @SmallTest
64    @Feature({"Sync"})
65    public void testReadMissingData() {
66        /*
67         * Test plan: read saved state from empty preferences. Verify that null is returned.
68         */
69        InvalidationPreferences invPreferences = new InvalidationPreferences(mContext);
70        assertNull(invPreferences.getSavedSyncedAccount());
71        assertNull(invPreferences.getSavedSyncedTypes());
72        assertNull(invPreferences.getInternalNotificationClientState());
73    }
74 
75    @SmallTest
76    @Feature({"Sync"})
77    public void testReadWriteAndReadData() {
78        /*
79         * Test plan: write and read back saved state. Verify that the returned state is what
80         * was written.
81         */
82        InvalidationPreferences invPreferences = new InvalidationPreferences(mContext);
83        InvalidationPreferences.EditContext editContext = invPreferences.edit();
84 
85        // We should never write both a real type and the all-types type in practice, but we test
86        // with them here to ensure that preferences are not interpreting the written data.
87        Set<String> syncTypes = CollectionUtil.newHashSet("BOOKMARK", ModelType.ALL_TYPES_TYPE);
88        Account account = new Account("test@example.com", "bogus");
89        byte[] internalClientState = new byte[]{100,101,102};
90        invPreferences.setSyncTypes(editContext, syncTypes);
91        invPreferences.setAccount(editContext, account);
92        invPreferences.setInternalNotificationClientState(editContext, internalClientState);
93 
94        // Nothing should yet have been written.
95        assertNull(invPreferences.getSavedSyncedAccount());
96        assertNull(invPreferences.getSavedSyncedTypes());
97 
98        // Write the new data and verify that they are correctly read back.
99        invPreferences.commit(editContext);
100        assertEquals(account, invPreferences.getSavedSyncedAccount());
101        assertEquals(syncTypes, invPreferences.getSavedSyncedTypes());
102        assertTrue(Arrays.equals(
103                internalClientState, invPreferences.getInternalNotificationClientState()));
104    }
105}

[all classes][org.chromium.sync.notifier]
EMMA 2.0.5312 (C) Vladimir Roubtsov