Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7340fbd authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

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
parent 72ea5499
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -139,7 +139,9 @@ android_library {
        "SystemUI-tags",
        "SystemUI-tags",
        "SystemUI-proto",
        "SystemUI-proto",
        "metrics-helper-lib",
        "metrics-helper-lib",
        "androidx.test.rules", "hamcrest-library",
        "hamcrest-library",
        "androidx.test.rules",
        "androidx.test.uiautomator",
        "mockito-target-extended-minus-junit4",
        "mockito-target-extended-minus-junit4",
        "testables",
        "testables",
        "truth-prebuilt",
        "truth-prebuilt",
+5 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ import android.testing.TestableLooper;
import android.util.Log;
import android.util.Log;


import androidx.test.InstrumentationRegistry;
import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;


import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -149,6 +150,10 @@ public abstract class SysuiTestCase {
        return mContext;
        return mContext;
    }
    }


    protected UiDevice getUiDevice() {
        return UiDevice.getInstance(mRealInstrumentation);
    }

    protected void runShellCommand(String command) throws IOException {
    protected void runShellCommand(String command) throws IOException {
        ParcelFileDescriptor pfd = mRealInstrumentation.getUiAutomation()
        ParcelFileDescriptor pfd = mRealInstrumentation.getUiAutomation()
                .executeShellCommand(command);
                .executeShellCommand(command);
+15 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,9 @@ import android.view.WindowManagerPolicyConstants;
import android.widget.FrameLayout;
import android.widget.FrameLayout;


import androidx.test.filters.SmallTest;
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.colorextraction.ColorExtractor;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsLogger;
@@ -86,11 +89,16 @@ import org.mockito.MockitoAnnotations;


import java.util.List;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;


@SmallTest
@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
public class GlobalActionsDialogTest extends SysuiTestCase {
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;
    private GlobalActionsDialog mGlobalActionsDialog;


    @Mock private GlobalActions.GlobalActionsManager mWindowManagerFuncs;
    @Mock private GlobalActions.GlobalActionsManager mWindowManagerFuncs;
@@ -240,6 +248,13 @@ public class GlobalActionsDialogTest extends SysuiTestCase {
                mGlobalActionsDialog.makeScreenshotActionForTesting();
                mGlobalActionsDialog.makeScreenshotActionForTesting();
        screenshotAction.onLongPress();
        screenshotAction.onLongPress();
        verifyLogPosted(GlobalActionsDialog.GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS);
        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
    @Test