Add benchmark tests for NavigationSuiteScaffold.
Test: benchmark tests
Change-Id: I3cf9cb1b0f2170dc3c2b358ea3fb2b1a6772a5a5
diff --git a/compose/material3/benchmark/build.gradle b/compose/material3/benchmark/build.gradle
index df3e144..490c06c 100644
--- a/compose/material3/benchmark/build.gradle
+++ b/compose/material3/benchmark/build.gradle
@@ -26,6 +26,8 @@
androidTestImplementation(project(":compose:material:material-icons-core"))
androidTestImplementation(project(":compose:material3:material3"))
+ androidTestImplementation(project(":compose:material3:material3-adaptive"))
+ androidTestImplementation(project(":compose:material3:material3-window-size-class"))
androidTestImplementation(project(":benchmark:benchmark-junit4"))
androidTestImplementation(project(":compose:runtime:runtime"))
androidTestImplementation(project(":compose:benchmark-utils"))
diff --git a/compose/material3/benchmark/src/androidTest/java/androidx/compose/material3/benchmark/NavigationSuiteScaffoldBenchmarkTest.kt b/compose/material3/benchmark/src/androidTest/java/androidx/compose/material3/benchmark/NavigationSuiteScaffoldBenchmarkTest.kt
new file mode 100644
index 0000000..2eb3cec
--- /dev/null
+++ b/compose/material3/benchmark/src/androidTest/java/androidx/compose/material3/benchmark/NavigationSuiteScaffoldBenchmarkTest.kt
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.material3.benchmark
+
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.size
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
+import androidx.compose.material3.adaptive.NavigationSuiteScaffold
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableIntState
+import androidx.compose.runtime.mutableIntStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.testutils.LayeredComposeTestCase
+import androidx.compose.testutils.ToggleableTestCase
+import androidx.compose.testutils.benchmark.ComposeBenchmarkRule
+import androidx.compose.testutils.benchmark.benchmarkFirstCompose
+import androidx.compose.testutils.benchmark.toggleStateBenchmarkComposeMeasureLayout
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import org.junit.Rule
+import org.junit.Test
+
+class NavigationSuiteScaffoldBenchmarkTest {
+ @get:Rule
+ val benchmarkRule = ComposeBenchmarkRule()
+
+ private val testCaseFactory = { NavigationSuiteScaffoldTestCase() }
+ @Test
+ fun firstPixel() {
+ benchmarkRule.benchmarkFirstRenderUntilStable(testCaseFactory)
+ }
+
+ @Test
+ fun firstCompose() {
+ benchmarkRule.benchmarkFirstCompose(testCaseFactory)
+ }
+
+ @Test
+ fun changeSelection() {
+ benchmarkRule.toggleStateBenchmarkComposeMeasureLayout(
+ testCaseFactory,
+ assertOneRecomposition = false,
+ )
+ }
+}
+
+@OptIn(ExperimentalMaterial3AdaptiveApi::class)
+internal class NavigationSuiteScaffoldTestCase : LayeredComposeTestCase(), ToggleableTestCase {
+ private lateinit var selectedIndexState: MutableIntState
+
+ @Composable
+ override fun MeasuredContent() {
+ selectedIndexState = remember { mutableIntStateOf(0) }
+
+ NavigationSuiteScaffold(
+ navigationSuiteItems = {
+ item(
+ selected = selectedIndexState.value == 0,
+ onClick = {},
+ icon = { Spacer(Modifier.size(24.dp)) }
+ )
+ item(
+ selected = selectedIndexState.value == 1,
+ onClick = {},
+ icon = { Spacer(Modifier.size(24.dp)) }
+ )
+ }
+ )
+ }
+
+ @Composable
+ override fun ContentWrappers(content: @Composable () -> Unit) {
+ MaterialTheme {
+ content()
+ }
+ }
+
+ override fun toggleState() {
+ selectedIndexState.value = if (selectedIndexState.value == 0) 1 else 0
+ }
+}