blob: 27f1b8be63f2f367e6cca4d99c7f80828f4da368 [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;
Fred Quintanad9d2f112009-04-23 13:36:27 -070024import android.accounts.Account;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26public class SyncStorageEngineTest extends AndroidTestCase {
27
28 /**
29 * Test that we handle the case of a history row being old enough to purge before the
30 * correcponding sync is finished. This can happen if the clock changes while we are syncing.
31 */
32 public void testPurgeActiveSync() throws Exception {
Fred Quintanad9d2f112009-04-23 13:36:27 -070033 final Account account = new Account("a@example.com", "example.type");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 final String authority = "testprovider";
35
36 MockContentResolver mockResolver = new MockContentResolver();
37
38 SyncStorageEngine engine = SyncStorageEngine.newTestInstance(
39 new TestContext(mockResolver, getContext()));
40
41 long time0 = 1000;
42 long historyId = engine.insertStartSyncEvent(
43 account, authority, time0, Sync.History.SOURCE_LOCAL);
44 long time1 = time0 + SyncStorageEngine.MILLIS_IN_4WEEKS * 2;
45 engine.stopSyncEvent(historyId, time1 - time0, "yay", 0, 0);
46 }
47}
48
49class TestContext extends ContextWrapper {
50
51 ContentResolver mResolver;
52
53 public TestContext(ContentResolver resolver, Context realContext) {
54 super(new RenamingDelegatingContext(new MockContext(), realContext, "test."));
55 mResolver = resolver;
56 }
57
58 @Override
59 public void enforceCallingOrSelfPermission(String permission, String message) {
60 }
61
62
63 @Override
64 public ContentResolver getContentResolver() {
65 return mResolver;
66 }
67}