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

Commit 9b878a8b authored by Hieu Dang's avatar Hieu Dang Committed by Gerrit Code Review
Browse files

Merge "Fix a test in IncomingFileConfirmActivityTest"

parents 44289166 cb791e7e
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.provider.Telephony;
import android.provider.Telephony;
import android.util.Log;
import android.util.Log;
@@ -194,6 +195,14 @@ public class BluetoothMethodProxy {
        return handler.sendEmptyMessage(what);
        return handler.sendEmptyMessage(what);
    }
    }


    /**
     * Proxies {@link Handler#sendMessageDelayed(Message, long)}.
     */
    public boolean handlerSendMessageDelayed(Handler handler, final int what,
            final long delayMillis) {
        return handler.sendMessageDelayed(handler.obtainMessage(what), delayMillis);
    }

    /**
    /**
     * Proxies {@link HeaderSet#getHeader}.
     * Proxies {@link HeaderSet#getHeader}.
     */
     */
+7 −4
Original line number Original line Diff line number Diff line
@@ -54,6 +54,7 @@ import android.widget.Toast;


import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.bluetooth.R;
import com.android.internal.annotations.VisibleForTesting;


/**
/**
 * This class is designed to ask user to confirm if accept incoming file;
 * This class is designed to ask user to confirm if accept incoming file;
@@ -63,9 +64,11 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
    private static final boolean D = Constants.DEBUG;
    private static final boolean D = Constants.DEBUG;
    private static final boolean V = Constants.VERBOSE;
    private static final boolean V = Constants.VERBOSE;


    private static final int DISMISS_TIMEOUT_DIALOG = 0;
    @VisibleForTesting
    static final int DISMISS_TIMEOUT_DIALOG = 0;


    private static final int DISMISS_TIMEOUT_DIALOG_VALUE = 2000;
    @VisibleForTesting
    static final int DISMISS_TIMEOUT_DIALOG_VALUE = 2000;


    private static final String PREFERENCE_USER_TIMEOUT = "user_timeout";
    private static final String PREFERENCE_USER_TIMEOUT = "user_timeout";


@@ -224,8 +227,8 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
                DialogInterface.BUTTON_POSITIVE,
                DialogInterface.BUTTON_POSITIVE,
                getString(R.string.incoming_file_confirm_timeout_ok));
                getString(R.string.incoming_file_confirm_timeout_ok));


        mTimeoutHandler.sendMessageDelayed(mTimeoutHandler.obtainMessage(DISMISS_TIMEOUT_DIALOG),
        BluetoothMethodProxy.getInstance().handlerSendMessageDelayed(mTimeoutHandler,
                DISMISS_TIMEOUT_DIALOG_VALUE);
                DISMISS_TIMEOUT_DIALOG, DISMISS_TIMEOUT_DIALOG_VALUE);
    }
    }


    private final Handler mTimeoutHandler = new Handler() {
    private final Handler mTimeoutHandler = new Handler() {
+10 −11
Original line number Original line Diff line number Diff line
@@ -23,6 +23,9 @@ import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static androidx.test.espresso.matcher.ViewMatchers.withText;


import static com.android.bluetooth.opp.BluetoothOppIncomingFileConfirmActivity.DISMISS_TIMEOUT_DIALOG;
import static com.android.bluetooth.opp.BluetoothOppIncomingFileConfirmActivity.DISMISS_TIMEOUT_DIALOG_VALUE;

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


import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
@@ -30,6 +33,7 @@ import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;


import android.content.Context;
import android.content.Context;
@@ -50,7 +54,6 @@ import com.google.common.base.Objects;


import org.junit.After;
import org.junit.After;
import org.junit.Before;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mock;
@@ -76,7 +79,7 @@ public class IncomingFileConfirmActivityTest {
    Intent mIntent;
    Intent mIntent;
    Context mTargetContext;
    Context mTargetContext;


    boolean mDestroyed;
    static final int TIMEOUT_MS = 3_000;


    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
@@ -148,7 +151,7 @@ public class IncomingFileConfirmActivityTest {
        // To work around (possibly) ActivityScenario's bug.
        // To work around (possibly) ActivityScenario's bug.
        // The dialog button is clicked (no error throw) but onClick() is not triggered.
        // The dialog button is clicked (no error throw) but onClick() is not triggered.
        // It works normally if sleep for a few seconds
        // It works normally if sleep for a few seconds
        Thread.sleep(3_000);
        Thread.sleep(TIMEOUT_MS);
        onView(withText(mTargetContext.getText(R.string.incoming_file_confirm_cancel).toString()))
        onView(withText(mTargetContext.getText(R.string.incoming_file_confirm_cancel).toString()))
                .inRoot(isDialog()).check(matches(isDisplayed())).perform(click());
                .inRoot(isDialog()).check(matches(isDisplayed())).perform(click());


@@ -169,7 +172,7 @@ public class IncomingFileConfirmActivityTest {
        // To work around (possibly) ActivityScenario's bug.
        // To work around (possibly) ActivityScenario's bug.
        // The dialog button is clicked (no error throw) but onClick() is not triggered.
        // The dialog button is clicked (no error throw) but onClick() is not triggered.
        // It works normally if sleep for a few seconds
        // It works normally if sleep for a few seconds
        Thread.sleep(3_000);
        Thread.sleep(TIMEOUT_MS);
        onView(withText(mTargetContext.getText(R.string.incoming_file_confirm_ok).toString()))
        onView(withText(mTargetContext.getText(R.string.incoming_file_confirm_ok).toString()))
                .inRoot(isDialog()).check(matches(isDisplayed())).perform(click());
                .inRoot(isDialog()).check(matches(isDisplayed())).perform(click());


@@ -180,9 +183,8 @@ public class IncomingFileConfirmActivityTest {
        ), nullable(String.class), nullable(String[].class));
        ), nullable(String.class), nullable(String[].class));
    }
    }


    @Ignore("b/277593460")
    @Test
    @Test
    public void onTimeout_sendIntentWithUSER_CONFIRMATION_TIMEOUT_ACTION_finish() throws Exception {
    public void onTimeout_broadcastUserConfirmationTimeoutAction_sendDismissTimeoutDialogMessage() {
        BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList);
        BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList);
        ActivityScenario<BluetoothOppIncomingFileConfirmActivity> scenario =
        ActivityScenario<BluetoothOppIncomingFileConfirmActivity> scenario =
                ActivityScenario.launch(mIntent);
                ActivityScenario.launch(mIntent);
@@ -191,11 +193,8 @@ public class IncomingFileConfirmActivityTest {
        Intent in = new Intent(BluetoothShare.USER_CONFIRMATION_TIMEOUT_ACTION);
        Intent in = new Intent(BluetoothShare.USER_CONFIRMATION_TIMEOUT_ACTION);
        mTargetContext.sendBroadcast(in);
        mTargetContext.sendBroadcast(in);


        // To work around (possibly) ActivityScenario's bug.
        verify(mBluetoothMethodProxy, timeout(TIMEOUT_MS)).handlerSendMessageDelayed(any(),
        // The dialog button is clicked (no error throw) but onClick() is not triggered.
                eq(DISMISS_TIMEOUT_DIALOG), eq((long) DISMISS_TIMEOUT_DIALOG_VALUE));
        // It works normally if sleep for a few seconds
        Thread.sleep(3_000);
        assertThat(scenario.getState()).isEqualTo(Lifecycle.State.DESTROYED);
    }
    }


    @Test
    @Test