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
Matthew Finkel
fenix
Commits
b0a1e088
Commit
b0a1e088
authored
Nov 11, 2020
by
Michael Comella
Committed by
Michael Comella
Nov 13, 2020
Browse files
For #16376: test view hierarchy depth in StartupExcessive*Test.
parent
88233ef4
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/androidTest/java/org/mozilla/fenix/ui/StartupExcessiveResourceUseTest.kt
View file @
b0a1e088
...
...
@@ -4,8 +4,13 @@
package
org.mozilla.fenix.ui
import
android.util.Log
import
android.view.View
import
android.view.ViewGroup
import
androidx.core.view.children
import
androidx.test.platform.app.InstrumentationRegistry
import
androidx.test.uiautomator.UiDevice
import
kotlinx.android.synthetic.main.activity_home.*
import
org.junit.Assert.assertEquals
import
org.junit.Rule
import
org.junit.Test
...
...
@@ -18,6 +23,7 @@ import org.mozilla.fenix.perf.ComponentInitCount
private
const
val
EXPECTED_SUPPRESSION_COUNT
=
11
private
const
val
EXPECTED_RUNBLOCKING_COUNT
=
2
private
const
val
EXPECTED_COMPONENT_INIT_COUNT
=
42
private
const
val
EXPECTED_VIEW_HIERARCHY_DEPTH
=
12
private
val
failureMsgStrictMode
=
getErrorMessage
(
shortName
=
"StrictMode suppression"
,
...
...
@@ -34,6 +40,12 @@ private val failureMsgComponentInit = getErrorMessage(
implications
=
"initializing new components on start up may be an indication that we're doing more work than necessary on start up?"
)
private
val
failureMsgViewHierarchyDepth
=
getErrorMessage
(
shortName
=
"view hierarchy depth"
,
implications
=
"having a deep view hierarchy can slow down measure/layout performance?"
)
+
"Please note that we're not sure if this is a useful metric to assert: with your feedback, "
+
"we'll find out over time if it is or is not."
/**
* A performance test to limit the number of StrictMode suppressions and number of runBlocking used
* on startup.
...
...
@@ -67,10 +79,25 @@ class StartupExcessiveResourceUseTest {
val
actualSuppresionCount
=
activityTestRule
.
activity
.
components
.
strictMode
.
suppressionCount
.
get
().
toInt
()
val
actualRunBlocking
=
RunBlockingCounter
.
count
.
get
()
val
actualComponentInitCount
=
ComponentInitCount
.
count
.
get
()
val
actualViewHierarchyDepth
=
countAndLogViewHierarchyDepth
(
activityTestRule
.
activity
.
rootContainer
,
1
)
assertEquals
(
failureMsgStrictMode
,
EXPECTED_SUPPRESSION_COUNT
,
actualSuppresionCount
)
assertEquals
(
failureMsgRunBlocking
,
EXPECTED_RUNBLOCKING_COUNT
,
actualRunBlocking
)
assertEquals
(
failureMsgComponentInit
,
EXPECTED_COMPONENT_INIT_COUNT
,
actualComponentInitCount
)
assertEquals
(
failureMsgViewHierarchyDepth
,
EXPECTED_VIEW_HIERARCHY_DEPTH
,
actualViewHierarchyDepth
)
}
}
private
fun
countAndLogViewHierarchyDepth
(
view
:
View
,
level
:
Int
):
Int
{
// Log for debugging purposes: not sure if this is actually helpful.
val
indent
=
"| "
.
repeat
(
level
-
1
)
Log
.
d
(
"Startup...Test"
,
"${indent}$view"
)
return
if
(
view
!
is
ViewGroup
)
{
level
}
else
{
val
maxDepth
=
view
.
children
.
map
{
countAndLogViewHierarchyDepth
(
it
,
level
+
1
)
}.
maxOrNull
()
maxDepth
?:
level
}
}
...
...
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