[tbb-commits] [Git][tpo/applications/android-components][android-components-102.0.14-12.0-1] Improve search term performance on the toolbar
Richard Pospesel (@richard)
git at gitlab.torproject.org
Tue Aug 30 21:22:19 UTC 2022
Richard Pospesel pushed to branch android-components-102.0.14-12.0-1 at The Tor Project / Applications / android-components
Commits:
18a85e4a by sarah541 at 2022-08-30T20:29:32+00:00
Improve search term performance on the toolbar
- - - - -
2 changed files:
- components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt
- components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt
Changes:
=====================================
components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt
=====================================
@@ -75,7 +75,8 @@ class BrowserToolbar @JvmOverloads constructor(
defStyleAttr: Int = 0
) : ViewGroup(context, attrs, defStyleAttr), Toolbar {
private var state: State = State.DISPLAY
- private var searchTerms: String = ""
+ @VisibleForTesting
+ internal var searchTerms: String = ""
private var urlCommitListener: ((String) -> Boolean)? = null
/**
@@ -219,11 +220,11 @@ class BrowserToolbar @JvmOverloads constructor(
}
override fun setSearchTerms(searchTerms: String) {
+ this.searchTerms = searchTerms.take(MAX_URI_LENGTH)
+
if (state == State.EDIT) {
- edit.editSuggestion(searchTerms)
+ edit.editSuggestion(this.searchTerms)
}
-
- this.searchTerms = searchTerms
}
override fun displayProgress(progress: Int) {
=====================================
components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt
=====================================
@@ -152,6 +152,38 @@ class BrowserToolbarTest {
assertEquals("c".repeat(MAX_URI_LENGTH - 1), capturedValues[2])
}
+ @Test
+ fun `searchTerms is truncated in case it is greater than MAX_URI_LENGTH`() {
+ val toolbar = BrowserToolbar(testContext)
+ toolbar.edit = spy(toolbar.edit)
+ toolbar.editMode()
+
+ toolbar.setSearchTerms("a".repeat(MAX_URI_LENGTH + 1))
+
+ // Value was too long and should've been truncated
+ assertEquals(toolbar.searchTerms.length, MAX_URI_LENGTH)
+ verify(toolbar.edit).editSuggestion("a".repeat(MAX_URI_LENGTH))
+ }
+
+ @Test
+ fun `searchTerms is not truncated in case it is equal or less than MAX_URI_LENGTH`() {
+ val toolbar = BrowserToolbar(testContext)
+ toolbar.edit = spy(toolbar.edit)
+ toolbar.editMode()
+
+ toolbar.setSearchTerms("b".repeat(MAX_URI_LENGTH))
+
+ // Value should be the same as before
+ assertEquals(toolbar.searchTerms.length, MAX_URI_LENGTH)
+ verify(toolbar.edit).editSuggestion("b".repeat(MAX_URI_LENGTH))
+
+ toolbar.setSearchTerms("c".repeat(MAX_URI_LENGTH - 1))
+
+ // Value should be the same as before
+ assertEquals(toolbar.searchTerms.length, MAX_URI_LENGTH - 1)
+ verify(toolbar.edit).editSuggestion("c".repeat(MAX_URI_LENGTH - 1))
+ }
+
@Test
fun `last URL will be forwarded to edit toolbar when switching mode`() {
val toolbar = BrowserToolbar(testContext)
View it on GitLab: https://gitlab.torproject.org/tpo/applications/android-components/-/commit/18a85e4ad39b9ff26a65b3c0afd5c0b8859877d8
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/android-components/-/commit/18a85e4ad39b9ff26a65b3c0afd5c0b8859877d8
You're receiving this email because of your account on gitlab.torproject.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20220830/abd6d5d1/attachment-0001.htm>
More information about the tbb-commits
mailing list