blob: 36805b15e864c852c3702ff11bc7deddc921a9b6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
19import android.test.AndroidTestCase;
20import android.test.RenamingDelegatingContext;
21import android.test.mock.MockContext;
22import android.test.mock.MockContentResolver;
23import android.provider.Sync;
24
25public class SyncStorageEngineTest extends AndroidTestCase {
26
27 /**
28 * Test that we handle the case of a history row being old enough to purge before the
29 * correcponding sync is finished. This can happen if the clock changes while we are syncing.
30 */
31 public void testPurgeActiveSync() throws Exception {
32 final String account = "a@example.com";
33 final String authority = "testprovider";
34
35 MockContentResolver mockResolver = new MockContentResolver();
36
37 SyncStorageEngine engine = SyncStorageEngine.newTestInstance(
38 new TestContext(mockResolver, getContext()));
39
40 long time0 = 1000;
41 long historyId = engine.insertStartSyncEvent(
42 account, authority, time0, Sync.History.SOURCE_LOCAL);
43 long time1 = time0 + SyncStorageEngine.MILLIS_IN_4WEEKS * 2;
44 engine.stopSyncEvent(historyId, time1 - time0, "yay", 0, 0);
45 }
46}
47
48class TestContext extends ContextWrapper {
49
50 ContentResolver mResolver;
51
52 public TestContext(ContentResolver resolver, Context realContext) {
53 super(new RenamingDelegatingContext(new MockContext(), realContext, "test."));
54 mResolver = resolver;
55 }
56
57 @Override
58 public void enforceCallingOrSelfPermission(String permission, String message) {
59 }
60
61
62 @Override
63 public ContentResolver getContentResolver() {
64 return mResolver;
65 }
66}