1/* 2 * Copyright (C) 2011 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 com.android.browser.tests; 18 19import com.android.browser.Bookmarks; 20import com.android.browser.tests.utils.BP2TestCaseHelper; 21 22import android.content.ContentResolver; 23import android.database.Cursor; 24import android.test.suitebuilder.annotation.SmallTest; 25 26/** 27 * Extends from BP2TestCaseHelper for the helper methods 28 * and to get the mock database 29 */ 30@SmallTest 31public class BookmarksTests extends BP2TestCaseHelper { 32 33 public void testQueryCombinedForUrl() { 34 // First, add some bookmarks 35 assertNotNull(insertBookmark( 36 "http://google.com/search?q=test", "Test search")); 37 assertNotNull(insertBookmark( 38 "http://google.com/search?q=mustang", "Mustang search")); 39 assertNotNull(insertBookmark( 40 "http://google.com/search?q=aliens", "Aliens search")); 41 ContentResolver cr = getMockContentResolver(); 42 43 Cursor c = null; 44 try { 45 // First, search for a match 46 String url = "http://google.com/search?q=test"; 47 c = Bookmarks.queryCombinedForUrl(cr, null, url); 48 assertEquals(1, c.getCount()); 49 assertTrue(c.moveToFirst()); 50 assertEquals(url, c.getString(0)); 51 c.close(); 52 53 // Next, search for no match 54 url = "http://google.com/search"; 55 c = Bookmarks.queryCombinedForUrl(cr, null, url); 56 assertEquals(0, c.getCount()); 57 assertFalse(c.moveToFirst()); 58 c.close(); 59 } finally { 60 if (c != null) c.close(); 61 } 62 } 63 64} 65