diff options
| author | 2020-10-20 17:50:13 +0900 | |
|---|---|---|
| committer | 2020-10-20 18:04:54 +0900 | |
| commit | c7340fbddb56eb00d40f97c9aadcc068a0836a87 (patch) | |
| tree | 9ce06d2c9a2a5cb10adc1b59deb66d4b24d0fd76 | |
| parent | 72ea549909fbdd11a8c7b9606e3e38e8a51d9a47 (diff) | |
Dismiss ScreenRecordDialog when test finishes
The GlobalActionsDialogTest#testShoudLogScreenshotsLongPress test
opens ScreenRecordDialog while testing but remains it opened when test
finishes.
Bug: 171271162
Test: atest SystemUITest:GlobalActionsDialogTest
Change-Id: Ic84fed37d6eef818489ebb4a6e2052a4215014b2
3 files changed, 23 insertions, 1 deletions
diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp index a9a5671d5b03..80a6257fd7a9 100644 --- a/packages/SystemUI/Android.bp +++ b/packages/SystemUI/Android.bp @@ -139,7 +139,9 @@ android_library { "SystemUI-tags", "SystemUI-proto", "metrics-helper-lib", - "androidx.test.rules", "hamcrest-library", + "hamcrest-library", + "androidx.test.rules", + "androidx.test.uiautomator", "mockito-target-extended-minus-junit4", "testables", "truth-prebuilt", diff --git a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java index 86b1e61d76b1..197c000f16bc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java +++ b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java @@ -30,6 +30,7 @@ import android.testing.TestableLooper; import android.util.Log; import androidx.test.InstrumentationRegistry; +import androidx.test.uiautomator.UiDevice; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.settingslib.bluetooth.LocalBluetoothManager; @@ -149,6 +150,10 @@ public abstract class SysuiTestCase { return mContext; } + protected UiDevice getUiDevice() { + return UiDevice.getInstance(mRealInstrumentation); + } + protected void runShellCommand(String command) throws IOException { ParcelFileDescriptor pfd = mRealInstrumentation.getUiAutomation() .executeShellCommand(command); diff --git a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java index b4af786c5579..78ee5936fe0b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogTest.java @@ -53,6 +53,9 @@ import android.view.WindowManagerPolicyConstants; import android.widget.FrameLayout; import androidx.test.filters.SmallTest; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiObject2; +import androidx.test.uiautomator.Until; import com.android.internal.colorextraction.ColorExtractor; import com.android.internal.logging.MetricsLogger; @@ -86,11 +89,16 @@ import org.mockito.MockitoAnnotations; import java.util.List; import java.util.concurrent.Executor; +import java.util.regex.Pattern; @SmallTest @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper(setAsMainLooper = true) public class GlobalActionsDialogTest extends SysuiTestCase { + private static final long UI_TIMEOUT_MILLIS = 5000; // 5 sec + private static final Pattern CANCEL_BUTTON = + Pattern.compile("cancel", Pattern.CASE_INSENSITIVE); + private GlobalActionsDialog mGlobalActionsDialog; @Mock private GlobalActions.GlobalActionsManager mWindowManagerFuncs; @@ -240,6 +248,13 @@ public class GlobalActionsDialogTest extends SysuiTestCase { mGlobalActionsDialog.makeScreenshotActionForTesting(); screenshotAction.onLongPress(); verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS); + + // Dismiss ScreenRecordDialog opened by the long press above. + final UiObject2 cancelButton = getUiDevice().wait( + Until.findObject(By.text(CANCEL_BUTTON)), UI_TIMEOUT_MILLIS); + if (cancelButton != null) { + cancelButton.click(); + } } @Test |