|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.android.testing.espresso.EspressoDeviceSample |
| 18 | + |
| 19 | +import androidx.test.espresso.device.DeviceInteraction.Companion.setDisplaySize |
| 20 | +import androidx.test.espresso.device.EspressoDevice.Companion.onDevice |
| 21 | +import androidx.test.espresso.device.filter.RequiresDisplay |
| 22 | +import androidx.test.espresso.device.rules.DisplaySizeRule |
| 23 | +import androidx.test.espresso.device.sizeclass.HeightSizeClass |
| 24 | +import androidx.test.espresso.device.sizeclass.WidthSizeClass |
| 25 | +import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum |
| 26 | +import androidx.test.espresso.device.sizeclass.HeightSizeClass.Companion.HeightSizeClassEnum |
| 27 | +import androidx.test.ext.junit.rules.activityScenarioRule |
| 28 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 29 | +import org.junit.Rule |
| 30 | +import org.junit.Test |
| 31 | +import org.junit.runner.RunWith |
| 32 | +import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum.EXPANDED as EXPANDED1 |
| 33 | + |
| 34 | +/* |
| 35 | + * Illustrates usage of [onDevice] API to change the display size. |
| 36 | + */ |
| 37 | +@RunWith(AndroidJUnit4::class) |
| 38 | +class ResizeDisplayTest { |
| 39 | + |
| 40 | + @get:Rule(order = 1) var activityScenarioRule = activityScenarioRule<MainActivity>() |
| 41 | + |
| 42 | + // Test rule for restoring device to its starting display size when a test case finishes |
| 43 | + @get:Rule(order = 2) var displaySizeRule: DisplaySizeRule = DisplaySizeRule() |
| 44 | + |
| 45 | + @Test |
| 46 | + fun resizeWindow_compact() { |
| 47 | + onDevice().setDisplaySize( |
| 48 | + widthSizeClass = WidthSizeClass.COMPACT, |
| 49 | + heightSizeClass = HeightSizeClass.COMPACT |
| 50 | + ) |
| 51 | + // Verify visual attributes or state restoration |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Setting the display size to EXPANDED would fail in small devices, so the [RequiresDisplay] |
| 56 | + * annotation prevents this test from being run on devices outside the EXPANDED buckets. |
| 57 | + */ |
| 58 | + @RequiresDisplay( |
| 59 | + widthSizeClass = WidthSizeClassEnum.EXPANDED, |
| 60 | + heightSizeClass = HeightSizeClassEnum.EXPANDED |
| 61 | + ) |
| 62 | + @Test |
| 63 | + fun resizeWindow_expanded() { |
| 64 | + onDevice().setDisplaySize( |
| 65 | + widthSizeClass = WidthSizeClass.EXPANDED, |
| 66 | + heightSizeClass = HeightSizeClass.EXPANDED |
| 67 | + ) |
| 68 | + // Verify visual attributes or state restoration |
| 69 | + } |
| 70 | +} |
0 commit comments