The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.content; |
| 18 | |
| 19 | import android.test.AndroidTestCase; |
| 20 | import android.test.RenamingDelegatingContext; |
| 21 | import android.test.mock.MockContext; |
| 22 | import android.test.mock.MockContentResolver; |
| 23 | import android.provider.Sync; |
Fred Quintana | d9d2f11 | 2009-04-23 13:36:27 -0700 | [diff] [blame] | 24 | import android.accounts.Account; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | public 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 Quintana | d9d2f11 | 2009-04-23 13:36:27 -0700 | [diff] [blame] | 33 | final Account account = new Account("a@example.com", "example.type"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | 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 | |
| 49 | class 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 | } |