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