Skip to content

Commit

Permalink
[components] For mozilla-mobile/android-components#191 - Adds API to …
Browse files Browse the repository at this point in the history
…build a suggestion URL

UltraBlame original commit: 55c91ab2d3346de36b693ac22cfdee4e9f0c0106
  • Loading branch information
marco-c committed May 31, 2024
1 parent 6ba8794 commit 03088b2
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,79 @@ 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
=
Uri
.
decode
(
searchUri
uri
.
toString
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ junit
.
Assert
.
assertEquals
import
org
.
junit
.
Assert
.
assertNotNull
*
import
org
.
Expand Down Expand Up @@ -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
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03088b2

Please sign in to comment.