diff --git a/mobile/android/android-components/components/browser/search/src/main/java/mozilla/components/browser/search/SearchEngine.kt b/mobile/android/android-components/components/browser/search/src/main/java/mozilla/components/browser/search/SearchEngine.kt index 006786656cb0..70ccba3f6dc9 100644 --- a/mobile/android/android-components/components/browser/search/src/main/java/mozilla/components/browser/search/SearchEngine.kt +++ b/mobile/android/android-components/components/browser/search/src/main/java/mozilla/components/browser/search/SearchEngine.kt @@ -222,6 +222,71 @@ resultsUris [ 0 ] +return +buildURL +( +searchUri +searchTerm +) +} +/ +* +* +* +Attempts +to +builds +a +Uri +to +get +suggestions +from +this +search +engine +* +/ +fun +buildSuggestionsURL +( +searchTerm +: +String +) +: +String +? +{ +val +suggestUri += +suggestUri +? +: +return +null +return +buildURL +( +suggestUri +searchTerm +) +} +private +fun +buildURL +( +uri +: +Uri +searchTerm +: +String +) +: +String +{ val template = @@ -229,7 +294,7 @@ Uri . decode ( -searchUri +uri . toString ( diff --git a/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineParserTest.kt b/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineParserTest.kt index 50c8b196a71a..af14a2a7b707 100644 --- a/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineParserTest.kt +++ b/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineParserTest.kt @@ -71,15 +71,7 @@ junit . Assert . -assertEquals -import -org -. -junit -. -Assert -. -assertNotNull +* import org . @@ -228,6 +220,98 @@ utf " url ) +val +suggestionURL += +searchEngine +. +buildSuggestionsURL +( +" +Mozilla +" +) +assertEquals +( +" +https +: +/ +/ +www +. +google +. +com +/ +complete +/ +search +? +client += +firefox +& +q += +Mozilla +" +suggestionURL +) +} +Test +fun +SearchEngine +without +SuggestUri +wont +build +suggestionURL +( +) +{ +val +searchEngine += +SearchEngineParser +( +) +. +load +( +RuntimeEnvironment +. +application +. +assets +" +amazon +" +" +searchplugins +/ +amazon +- +au +. +xml +" +) +val +suggestionURL += +searchEngine +. +buildSuggestionsURL +( +" +Mozilla +" +) +assertNull +( +suggestionURL +) } Test ( diff --git a/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineTest.kt b/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineTest.kt index 751f7e752e09..3a7f10289b46 100644 --- a/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineTest.kt +++ b/mobile/android/android-components/components/browser/search/src/test/java/mozilla/components/browser/search/SearchEngineTest.kt @@ -561,6 +561,124 @@ world ) ) } +Test +fun +Build +search +suggestion +URL +( +) +{ +val +searchUri += +Uri +. +parse +( +" +https +: +/ +/ +mozilla +. +org +/ +search +/ +? +q += +{ +searchTerms +} +" +) +val +suggestionsUri += +Uri +. +parse +( +" +https +: +/ +/ +mozilla +. +org +/ +search +/ +suggestions +? +q += +{ +searchTerms +} +" +) +val +searchEngine += +SearchEngine +( +" +mozsearch +" +" +Mozilla +Search +" +mock +( +Bitmap +: +: +class +. +java +) +listOf +( +searchUri +) +suggestionsUri +) +assertEquals +( +" +https +: +/ +/ +mozilla +. +org +/ +search +/ +suggestions +? +q += +Focus +" +searchEngine +. +buildSuggestionsURL +( +" +Focus +" +) +) +} private fun mockResultUriList