Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
fc6a5827
Unverified
Commit
fc6a5827
authored
Jun 12, 2020
by
Jonathan Almeida
Browse files
Close #7352: Always set scaleFactor on TabThumbnailView
parent
9e12caf0
Changes
2
Hide whitespace changes
Inline
Side-by-side
components/browser/tabstray/src/main/java/mozilla/components/browser/tabstray/thumbnail/TabThumbnailView.kt
View file @
fc6a5827
...
...
@@ -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
}
}
components/browser/tabstray/src/test/java/mozilla/components/browser/tabstray/thumbnail/TabThumbnailViewTest.kt
View file @
fc6a5827
...
...
@@ -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
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment