Skip to content

Commit

Permalink
Close mozilla-mobile#7352: Always set scaleFactor on TabThumbnailView
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalmeida committed Jun 12, 2020
1 parent 4df1ee8 commit eecfd92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit eecfd92

Please sign in to comment.