1 /* 2 * Copyright (C) 2010 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 com.android.quicksearchbox; 17 18 import android.test.AndroidTestCase; 19 import android.test.suitebuilder.annotation.SmallTest; 20 21 /** 22 * Tests for {@link SuggestionUtils}. 23 */ 24 @SmallTest 25 public class SuggestionUtilsTest extends AndroidTestCase { 26 testUrlsWithAndWithoutSchemeEquivalent()27 public void testUrlsWithAndWithoutSchemeEquivalent() { 28 assertsUrlsEquivalent("http://www.google.com", "www.google.com"); 29 } 30 testUrlsWithAndWithoutPathEquivalent()31 public void testUrlsWithAndWithoutPathEquivalent() { 32 assertsUrlsEquivalent("http://www.google.com/", "www.google.com"); 33 assertsUrlsEquivalent("www.google.com/", "http://www.google.com"); 34 assertsUrlsNotEquivalent("www.google.com/search/", "http://www.google.com/search"); 35 } 36 testHttpAndHttpsUrlsNotEquivalent()37 public void testHttpAndHttpsUrlsNotEquivalent() { 38 assertsUrlsNotEquivalent("https://www.google.com/", "http://www.google.com/"); 39 assertsUrlsNotEquivalent("https://www.google.com", "www.google.com"); 40 } 41 testNonHttpUrlsEquivalent()42 public void testNonHttpUrlsEquivalent() { 43 assertsUrlsEquivalent("gopher://www.google.com/", "gopher://www.google.com"); 44 } 45 testNonHttpUrlsAndNoSchemeNotEquivalent()46 public void testNonHttpUrlsAndNoSchemeNotEquivalent() { 47 assertsUrlsNotEquivalent("gopher://www.google.com", "www.google.com"); 48 } 49 testUrlsWithDifferentPathsNotEquivalent()50 public void testUrlsWithDifferentPathsNotEquivalent() { 51 assertsUrlsNotEquivalent("www.google.com/search", "www.google.com"); 52 assertsUrlsNotEquivalent("http://www.google.com/search", "www.google.com"); 53 assertsUrlsNotEquivalent("www.google.com/search", "http://www.google.com"); 54 } 55 assertsUrlsEquivalent(String url1, String url2)56 private void assertsUrlsEquivalent(String url1, String url2) { 57 assertTrue("Urls " + url1 + " and " + url2 + " not equal", 58 SuggestionUtils.normalizeUrl(url1).equals(SuggestionUtils.normalizeUrl(url2))); 59 } 60 assertsUrlsNotEquivalent(String url1, String url2)61 private void assertsUrlsNotEquivalent(String url1, String url2) { 62 assertFalse("Urls " + url1 + " and " + url2 + " equal", 63 SuggestionUtils.normalizeUrl(url1).equals(SuggestionUtils.normalizeUrl(url2))); 64 } 65 } 66