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

Commit cb791e7e authored by Hieu Dang's avatar Hieu Dang
Browse files

Fix a test in IncomingFileConfirmActivityTest

Bug: 277593460
Tag: #refactor
Test: BluetoothInstrumentationTests
Change-Id: Ibc204f121b719580d37ba49a3d783f37d774028c
parent cb1d20f4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.provider.Telephony;
import android.util.Log;
@@ -194,6 +195,14 @@ public class BluetoothMethodProxy {
        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}.
     */
+7 −4
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.widget.Toast;

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

/**
 * 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 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";

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

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

    private final Handler mTimeoutHandler = new Handler() {
+10 −11
Original line number 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.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 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.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;

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

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

    boolean mDestroyed;
    static final int TIMEOUT_MS = 3_000;

    @Before
    public void setUp() {
@@ -146,7 +149,7 @@ public class IncomingFileConfirmActivityTest {
        // To work around (possibly) ActivityScenario's bug.
        // The dialog button is clicked (no error throw) but onClick() is not triggered.
        // 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()))
                .inRoot(isDialog()).check(matches(isDisplayed())).perform(click());

@@ -167,7 +170,7 @@ public class IncomingFileConfirmActivityTest {
        // To work around (possibly) ActivityScenario's bug.
        // The dialog button is clicked (no error throw) but onClick() is not triggered.
        // 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()))
                .inRoot(isDialog()).check(matches(isDisplayed())).perform(click());

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

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

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

    @Test