Unverified Commit fc6a5827 authored by Jonathan Almeida's avatar Jonathan Almeida
Browse files

Close #7352: Always set scaleFactor on TabThumbnailView

parent 9e12caf0
......@@ -17,13 +17,17 @@ class TabThumbnailView(context: Context, attrs: AttributeSet) : AppCompatImageVi
@VisibleForTesting
public override fun setFrame(l: Int, t: Int, r: Int, b: Int): Boolean {
val changed = super.setFrame(l, t, r, b)
if (changed) {
val matrix = imageMatrix
val scaleFactor = width / drawable.intrinsicWidth.toFloat()
matrix.setScale(scaleFactor, scaleFactor, 0f, 0f)
imageMatrix = matrix
val result = super.setFrame(l, t, r, b)
val matrix = imageMatrix
val scaleFactor = if (drawable != null) {
width / drawable.intrinsicWidth.toFloat()
} else {
1F
}
return changed
matrix.setScale(scaleFactor, scaleFactor, 0f, 0f)
imageMatrix = matrix
return result
}
}
......@@ -4,6 +4,7 @@
package mozilla.components.browser.tabstray.thumbnail
import android.graphics.Matrix
import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.test.ext.junit.runners.AndroidJUnit4
......@@ -14,6 +15,8 @@ import org.junit.Assert.assertNotEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.`when`
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify
import org.robolectric.Robolectric.buildAttributeSet
@RunWith(AndroidJUnit4::class)
......@@ -61,6 +64,18 @@ class TabThumbnailViewTest {
assertEquals(matrix, matrix2)
}
@Test
fun `view scaleFactor does not change if there is no drawable`() {
val view = spy(TabThumbnailView(testContext, emptyAttributeSet()))
val matrix: Matrix = spy(Matrix())
`when`(view.imageMatrix).thenReturn(matrix)
view.setFrame(5, 5, 5, 5)
verify(matrix).setScale(1f, 1f, 0f, 0f)
}
}
private fun emptyAttributeSet() = buildAttributeSet().build()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment