forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#1824: Prevent extremely long URLs from locking up …
…HomeFragment
- Loading branch information
Showing
4 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/test/java/org/mozilla/fenix/home/TabViewHolderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.home | ||
|
||
import android.view.LayoutInflater | ||
import io.mockk.mockk | ||
import kotlinx.android.synthetic.main.tab_list_row.view.* | ||
import mozilla.components.browser.state.state.MediaState | ||
import mozilla.components.browser.toolbar.MAX_URI_LENGTH | ||
import mozilla.components.support.test.robolectric.testContext | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
import org.mozilla.fenix.home.sessioncontrol.TabSessionInteractor | ||
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabViewHolder | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
class TabViewHolderTest { | ||
|
||
@Test | ||
fun `extremely long URLs are truncated to prevent slowing down the UI`() { | ||
val view = LayoutInflater.from(testContext).inflate( | ||
R.layout.tab_list_row, null, false) | ||
|
||
val interactor: TabSessionInteractor = mockk() | ||
val tabViewHolder = TabViewHolder(view, interactor) | ||
|
||
val extremelyLongUrl = "m".repeat(MAX_URI_LENGTH + 1) | ||
val tab = Tab( | ||
sessionId = "123", | ||
url = extremelyLongUrl, | ||
hostname = extremelyLongUrl, | ||
title = "test", | ||
mediaState = MediaState.State.NONE) | ||
tabViewHolder.bindSession(tab) | ||
|
||
assertEquals("m".repeat(MAX_URI_LENGTH), view.hostname.text) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/test/java/org/mozilla/fenix/tabtray/TabTrayViewHolderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.tabtray | ||
|
||
import android.view.LayoutInflater | ||
import androidx.test.core.app.ApplicationProvider | ||
import io.mockk.mockk | ||
import mozilla.components.browser.toolbar.MAX_URI_LENGTH | ||
import mozilla.components.concept.tabstray.Tab | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.doNothing | ||
import org.mockito.Mockito.spy | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
class TabTrayViewHolderTest { | ||
|
||
@Test | ||
fun `extremely long URLs are truncated to prevent slowing down the UI`() { | ||
val view = LayoutInflater.from(ApplicationProvider.getApplicationContext()).inflate( | ||
R.layout.tab_tray_item, null, false) | ||
|
||
val tabViewHolder = spy(TabTrayViewHolder(view)) | ||
doNothing().`when`(tabViewHolder).updateBackgroundColor(false) | ||
|
||
val extremelyLongUrl = "m".repeat(MAX_URI_LENGTH + 1) | ||
val tab = Tab( | ||
id = "123", | ||
url = extremelyLongUrl) | ||
tabViewHolder.bind(tab, false, mockk()) | ||
|
||
assertEquals("m".repeat(MAX_URI_LENGTH), tabViewHolder.urlView?.text) | ||
} | ||
} |