From 13e76a4adc63fd799a534f1f53a1d22c70247fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Alc=C3=A9rreca?= Date: Fri, 2 Feb 2024 10:57:54 +0000 Subject: [PATCH 1/2] Adds new ResizeDisplayTest --- .../EspressoDeviceSample/app/build.gradle | 8 ++- .../EspressoDeviceSample/ResizeDisplayTest.kt | 54 +++++++++++++++++++ .../app/src/main/AndroidManifest.xml | 1 + ui/espresso/EspressoDeviceSample/build.gradle | 2 +- .../EspressoDeviceSample/gradle.properties | 1 + 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt diff --git a/ui/espresso/EspressoDeviceSample/app/build.gradle b/ui/espresso/EspressoDeviceSample/app/build.gradle index 806ea4543..3bb580bbb 100644 --- a/ui/espresso/EspressoDeviceSample/app/build.gradle +++ b/ui/espresso/EspressoDeviceSample/app/build.gradle @@ -6,7 +6,7 @@ android { compileSdk 33 defaultConfig { applicationId "com.example.android.testing.espresso.EspressoDeviceSample" - minSdkVersion 14 + minSdkVersion 19 targetSdkVersion 33 versionCode 1 versionName "1.0" @@ -16,12 +16,16 @@ android { productFlavors { } testOptions { + + emulatorControl { + enable = true + } unitTests { includeAndroidResources = true } managedDevices { devices { - // run with ../gradlew nexusOneApi30DebugAndroidTest + // run with ./gradlew nexusOneApi30DebugAndroidTest nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) { // A lower resolution device is used here for better emulator performance device = "Nexus One" diff --git a/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt new file mode 100644 index 000000000..0e2e7189e --- /dev/null +++ b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt @@ -0,0 +1,54 @@ +package com.example.android.testing.espresso.EspressoDeviceSample + +import androidx.test.espresso.device.DeviceInteraction.Companion.setDisplaySize +import androidx.test.espresso.device.EspressoDevice.Companion.onDevice +import androidx.test.espresso.device.filter.RequiresDisplay +import androidx.test.espresso.device.rules.DisplaySizeRule +import androidx.test.espresso.device.sizeclass.HeightSizeClass +import androidx.test.espresso.device.sizeclass.WidthSizeClass +import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum +import androidx.test.espresso.device.sizeclass.HeightSizeClass.Companion.HeightSizeClassEnum +import androidx.test.ext.junit.rules.activityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum.EXPANDED as EXPANDED1 + +/* + * Illustrates usage of [onDevice] API to change the display size. + */ +@RunWith(AndroidJUnit4::class) +class ResizeDisplayTest { + + @get:Rule(order = 1) var activityScenarioRule = activityScenarioRule() + + // Test rule for restoring device to its starting display size when a test case finishes + @get:Rule(order = 2) var displaySizeRule: DisplaySizeRule = DisplaySizeRule() + + @Test + fun resizeWindow_compact() { + onDevice().setDisplaySize( + widthSizeClass = WidthSizeClass.COMPACT, + heightSizeClass = HeightSizeClass.COMPACT + ) + // Verify visual attributes or state restoration + } + + /** + * Setting the display size to EXPANDED would fail in small devices, so the [RequiresDisplay] + * annotation prevents this test from being run on devices outside the EXPANDED buckets. + */ + @RequiresDisplay( + widthSizeClass = WidthSizeClassEnum.EXPANDED, + heightSizeClass = HeightSizeClassEnum.EXPANDED + ) + @Test + fun resizeWindow_expanded() { + onDevice().setDisplaySize( + widthSizeClass = WidthSizeClass.EXPANDED, + heightSizeClass = HeightSizeClass.EXPANDED + ) + // Verify visual attributes or state restoration + } +} diff --git a/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml b/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml index 6b29b606b..ba5c2f784 100644 --- a/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml +++ b/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml @@ -16,6 +16,7 @@ --> + Date: Fri, 2 Feb 2024 11:05:24 +0000 Subject: [PATCH 2/2] Adds copyright to test file --- .../EspressoDeviceSample/ResizeDisplayTest.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt index 0e2e7189e..216a6418b 100644 --- a/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt +++ b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/ResizeDisplayTest.kt @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2022 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 com.example.android.testing.espresso.EspressoDeviceSample import androidx.test.espresso.device.DeviceInteraction.Companion.setDisplaySize