157928453a0996396a7a899cd4637d3e8865b1f97John Reck/* 257928453a0996396a7a899cd4637d3e8865b1f97John Reck * Copyright (C) 2011 The Android Open Source Project 357928453a0996396a7a899cd4637d3e8865b1f97John Reck * 457928453a0996396a7a899cd4637d3e8865b1f97John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 557928453a0996396a7a899cd4637d3e8865b1f97John Reck * you may not use this file except in compliance with the License. 657928453a0996396a7a899cd4637d3e8865b1f97John Reck * You may obtain a copy of the License at 757928453a0996396a7a899cd4637d3e8865b1f97John Reck * 857928453a0996396a7a899cd4637d3e8865b1f97John Reck * http://www.apache.org/licenses/LICENSE-2.0 957928453a0996396a7a899cd4637d3e8865b1f97John Reck * 1057928453a0996396a7a899cd4637d3e8865b1f97John Reck * Unless required by applicable law or agreed to in writing, software 1157928453a0996396a7a899cd4637d3e8865b1f97John Reck * distributed under the License is distributed on an "AS IS" BASIS, 1257928453a0996396a7a899cd4637d3e8865b1f97John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1357928453a0996396a7a899cd4637d3e8865b1f97John Reck * See the License for the specific language governing permissions and 1457928453a0996396a7a899cd4637d3e8865b1f97John Reck * limitations under the License. 1557928453a0996396a7a899cd4637d3e8865b1f97John Reck */ 1657928453a0996396a7a899cd4637d3e8865b1f97John Reck 1757928453a0996396a7a899cd4637d3e8865b1f97John Reckpackage com.android.browser.tests; 1857928453a0996396a7a899cd4637d3e8865b1f97John Reck 1957928453a0996396a7a899cd4637d3e8865b1f97John Reckimport com.android.browser.Bookmarks; 2057928453a0996396a7a899cd4637d3e8865b1f97John Reckimport com.android.browser.tests.utils.BP2TestCaseHelper; 2157928453a0996396a7a899cd4637d3e8865b1f97John Reck 2257928453a0996396a7a899cd4637d3e8865b1f97John Reckimport android.content.ContentResolver; 2357928453a0996396a7a899cd4637d3e8865b1f97John Reckimport android.database.Cursor; 2457928453a0996396a7a899cd4637d3e8865b1f97John Reckimport android.test.suitebuilder.annotation.SmallTest; 2557928453a0996396a7a899cd4637d3e8865b1f97John Reck 2657928453a0996396a7a899cd4637d3e8865b1f97John Reck/** 2757928453a0996396a7a899cd4637d3e8865b1f97John Reck * Extends from BP2TestCaseHelper for the helper methods 2857928453a0996396a7a899cd4637d3e8865b1f97John Reck * and to get the mock database 2957928453a0996396a7a899cd4637d3e8865b1f97John Reck */ 3057928453a0996396a7a899cd4637d3e8865b1f97John Reck@SmallTest 3157928453a0996396a7a899cd4637d3e8865b1f97John Reckpublic class BookmarksTests extends BP2TestCaseHelper { 3257928453a0996396a7a899cd4637d3e8865b1f97John Reck 3357928453a0996396a7a899cd4637d3e8865b1f97John Reck public void testQueryCombinedForUrl() { 3457928453a0996396a7a899cd4637d3e8865b1f97John Reck // First, add some bookmarks 3557928453a0996396a7a899cd4637d3e8865b1f97John Reck assertNotNull(insertBookmark( 3657928453a0996396a7a899cd4637d3e8865b1f97John Reck "http://google.com/search?q=test", "Test search")); 3757928453a0996396a7a899cd4637d3e8865b1f97John Reck assertNotNull(insertBookmark( 3857928453a0996396a7a899cd4637d3e8865b1f97John Reck "http://google.com/search?q=mustang", "Mustang search")); 3957928453a0996396a7a899cd4637d3e8865b1f97John Reck assertNotNull(insertBookmark( 4057928453a0996396a7a899cd4637d3e8865b1f97John Reck "http://google.com/search?q=aliens", "Aliens search")); 4157928453a0996396a7a899cd4637d3e8865b1f97John Reck ContentResolver cr = getMockContentResolver(); 4257928453a0996396a7a899cd4637d3e8865b1f97John Reck 4357928453a0996396a7a899cd4637d3e8865b1f97John Reck Cursor c = null; 4457928453a0996396a7a899cd4637d3e8865b1f97John Reck try { 4557928453a0996396a7a899cd4637d3e8865b1f97John Reck // First, search for a match 4657928453a0996396a7a899cd4637d3e8865b1f97John Reck String url = "http://google.com/search?q=test"; 4757928453a0996396a7a899cd4637d3e8865b1f97John Reck c = Bookmarks.queryCombinedForUrl(cr, null, url); 4857928453a0996396a7a899cd4637d3e8865b1f97John Reck assertEquals(1, c.getCount()); 4957928453a0996396a7a899cd4637d3e8865b1f97John Reck assertTrue(c.moveToFirst()); 5057928453a0996396a7a899cd4637d3e8865b1f97John Reck assertEquals(url, c.getString(0)); 5157928453a0996396a7a899cd4637d3e8865b1f97John Reck c.close(); 5257928453a0996396a7a899cd4637d3e8865b1f97John Reck 5357928453a0996396a7a899cd4637d3e8865b1f97John Reck // Next, search for no match 5457928453a0996396a7a899cd4637d3e8865b1f97John Reck url = "http://google.com/search"; 5557928453a0996396a7a899cd4637d3e8865b1f97John Reck c = Bookmarks.queryCombinedForUrl(cr, null, url); 5657928453a0996396a7a899cd4637d3e8865b1f97John Reck assertEquals(0, c.getCount()); 5757928453a0996396a7a899cd4637d3e8865b1f97John Reck assertFalse(c.moveToFirst()); 5857928453a0996396a7a899cd4637d3e8865b1f97John Reck c.close(); 5957928453a0996396a7a899cd4637d3e8865b1f97John Reck } finally { 6057928453a0996396a7a899cd4637d3e8865b1f97John Reck if (c != null) c.close(); 6157928453a0996396a7a899cd4637d3e8865b1f97John Reck } 6257928453a0996396a7a899cd4637d3e8865b1f97John Reck } 6357928453a0996396a7a899cd4637d3e8865b1f97John Reck 6457928453a0996396a7a899cd4637d3e8865b1f97John Reck} 65