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

Commit 82b15f4e authored by Johnson Lu's avatar Johnson Lu Committed by Android (Google) Code Review
Browse files

Merge "Use the UiDevice.setOrientation methods to simulate orienting the device"

parents e1763134 d1be14fe
Loading
Loading
Loading
Loading
+33 −10
Original line number Diff line number Diff line
@@ -18,13 +18,18 @@ package com.android.settings.wifi.dpp;

import static com.google.common.truth.Truth.assertThat;

import android.app.Instrumentation;
import android.content.Intent;
import android.content.pm.ActivityInfo;

import android.os.RemoteException;
import android.provider.Settings;
import android.support.test.uiautomator.UiDevice;

import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,6 +44,13 @@ public class WifiDppConfiguratorActivityTest {
    public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
            new ActivityTestRule<>(WifiDppConfiguratorActivity.class);

    private UiDevice mDevice;

    @Before
    public void setUp() {
        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    }

    @Test
    public void launchActivity_qrCodeScanner_shouldNotAutoFinish() {
        Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
@@ -124,12 +136,17 @@ public class WifiDppConfiguratorActivityTest {
        // setWifiDppQrCode and check if getWifiDppQrCode correctly after rotation
        mActivityRule.launchActivity(intent);
        mActivityRule.getActivity().setWifiDppQrCode(wifiQrCode);
        mActivityRule.getActivity().setRequestedOrientation(
                ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        mActivityRule.getActivity().setRequestedOrientation(
                ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        WifiQrCode restoredWifiDppQrCode = mActivityRule.getActivity().getWifiDppQrCode();

        try {
            mDevice.setOrientationLeft();
            mDevice.setOrientationNatural();
            mDevice.setOrientationRight();
            mDevice.setOrientationNatural();
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }

        WifiQrCode restoredWifiDppQrCode = mActivityRule.getActivity().getWifiDppQrCode();
        assertThat(restoredWifiDppQrCode).isNotNull();
        assertThat(restoredWifiDppQrCode.getQrCode()).isEqualTo(VALID_WIFI_DPP_QR_CODE);
    }
@@ -144,10 +161,16 @@ public class WifiDppConfiguratorActivityTest {
        // setWifiNetworkConfig and check if getWifiNetworkConfig correctly after rotation
        mActivityRule.launchActivity(intent);
        mActivityRule.getActivity().setWifiNetworkConfig(wifiNetworkConfig);
        mActivityRule.getActivity().setRequestedOrientation(
                ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        mActivityRule.getActivity().setRequestedOrientation(
                ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        try {
            mDevice.setOrientationLeft();
            mDevice.setOrientationNatural();
            mDevice.setOrientationRight();
            mDevice.setOrientationNatural();
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }

        WifiNetworkConfig restoredWifiNetworkConfig =
                mActivityRule.getActivity().getWifiNetworkConfig();