1 /* 2 * Copyright (C) 2009 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 package android.content.cts; 17 18 import android.app.SearchManager; 19 import android.content.ContentValues; 20 import android.content.SearchRecentSuggestionsProvider; 21 import android.database.Cursor; 22 import android.net.Uri; 23 import android.test.AndroidTestCase; 24 import android.test.IsolatedContext; 25 import android.test.RenamingDelegatingContext; 26 import android.test.mock.MockContentResolver; 27 import android.test.mock.MockContext; 28 29 public class SearchRecentSuggestionsProviderTest extends AndroidTestCase { 30 private final static String AUTHORITY_HEAD = "content://" + MockSRSProvider.AUTHORITY; 31 private final static Uri TEST_URI = Uri.parse(AUTHORITY_HEAD + "/suggestions"); 32 33 private IsolatedContext mProviderContext; 34 35 @Override 36 public void setUp() throws Exception { 37 super.setUp(); 38 39 final String filenamePrefix = "test."; 40 final RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext( 41 new MockContext(), getContext(), filenamePrefix); 42 mProviderContext = new IsolatedContext(new MockContentResolver(), targetContextWrapper); 43 } 44 45 public void testSearchRecentSuggestionsProvider() { 46 final MockSRSProvider s = new MockSRSProvider(); 47 assertTrue(MockSRSProvider.setupSuggestCalled); 48 49 assertFalse(s.isOnCreateCalled()); 50 s.attachInfo(mProviderContext, null); 51 assertTrue(s.isOnCreateCalled()); 52 53 assertNotNull(s.getType(TEST_URI)); 54 55 final String uriStr = AUTHORITY_HEAD + '/' + SearchManager.SUGGEST_URI_PATH_QUERY; 56 final Uri contentUri = Uri.parse(uriStr); 57 String[] selArgs = new String[] { null }; 58 59 Cursor c = s.query(contentUri, null, null, selArgs, null); 60 assertEquals(0, c.getCount()); 61 62 s.insert(TEST_URI, new ContentValues()); 63 c = s.query(contentUri, null, null, selArgs, null); 64 assertEquals(1, c.getCount()); 65 66 s.insert(TEST_URI, new ContentValues()); 67 c = s.query(contentUri, null, null, selArgs, null); 68 assertEquals(2, c.getCount()); 69 70 s.delete(TEST_URI, null, null); 71 c = s.query(contentUri, null, null, selArgs, null); 72 assertEquals(0, c.getCount()); 73 74 try { 75 s.update(TEST_URI, null, null, null); 76 fail("testUpdate failed"); 77 } catch (UnsupportedOperationException e) { 78 // expected 79 } 80 } 81 } 82