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

Commit 2f950fd8 authored by Brad Ebinger's avatar Brad Ebinger Committed by android-build-merger
Browse files

Fix Telecom Unit Tests 1) Add/Fix VideoProviderTests 2) Update tests to...

Fix Telecom Unit Tests 1) Add/Fix VideoProviderTests 2) Update tests to accommodate ContentProvider changes
am: d7a57f03

Change-Id: I03f15f45085d05f7c49207c5df5602530e8ecb06
parents 509f24eb d7a57f03
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.LinkedList;

import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyChar;
@@ -190,7 +191,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        Call mockCall = createForegroundCall();
        PhoneAccount fakePhoneAccount = makeQuickAccount("id0", TEST_ACCOUNT_INDEX);
        when(mMockPhoneAccountRegistrar.getPhoneAccountOfCurrentUser(
                any(PhoneAccountHandle.class))).thenReturn(fakePhoneAccount);
                nullable(PhoneAccountHandle.class))).thenReturn(fakePhoneAccount);

        String networkOperator = mBluetoothPhoneService.mBinder.getNetworkOperator();

@@ -211,7 +212,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        Call mockCall = createForegroundCall();
        PhoneAccount fakePhoneAccount = makeQuickAccount("id0", TEST_ACCOUNT_INDEX);
        when(mMockPhoneAccountRegistrar.getPhoneAccountOfCurrentUser(
                any(PhoneAccountHandle.class))).thenReturn(fakePhoneAccount);
                nullable(PhoneAccountHandle.class))).thenReturn(fakePhoneAccount);

        String subscriberNumber = mBluetoothPhoneService.mBinder.getSubscriberNumber();

@@ -223,9 +224,9 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        Call mockCall = createForegroundCall();
        String fakeNumber = "8675309";
        when(mMockPhoneAccountRegistrar.getPhoneAccountOfCurrentUser(
                any(PhoneAccountHandle.class))).thenReturn(null);
                nullable(PhoneAccountHandle.class))).thenReturn(null);
        when(mMockPhoneAccountRegistrar.getPhoneAccountUnchecked(
                any(PhoneAccountHandle.class))).thenReturn(null);
                nullable(PhoneAccountHandle.class))).thenReturn(null);
        when(TelephonyManager.from(mContext).getLine1Number()).thenReturn(fakeNumber);

        String subscriberNumber = mBluetoothPhoneService.mBinder.getSubscriberNumber();
@@ -297,7 +298,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        mBluetoothPhoneService.mCallsManagerListener.onIsConferencedChanged(parentCall);
        // Make sure the call has only occurred collectively 2 times (not on the third)
        verify(mMockBluetoothHeadset, times(2)).phoneStateChanged(any(int.class),
                any(int.class), any(int.class), any(String.class), any(int.class));
                any(int.class), any(int.class), nullable(String.class), any(int.class));
    }

    @MediumTest
@@ -401,7 +402,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(2)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
                anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyInt());
    }

    @MediumTest
@@ -416,7 +417,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
        mBluetoothPhoneService.mBinder.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(1)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
                anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyInt());
    }

    @MediumTest
@@ -436,7 +437,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(2)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
                anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyInt());
    }

    @MediumTest
@@ -490,7 +491,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
                "5550000", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(2)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
                anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyInt());
    }

    @MediumTest
@@ -519,7 +520,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {
                "5550001", PhoneNumberUtils.TOA_Unknown);
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
        verify(mMockBluetoothHeadset, times(3)).clccResponse(anyInt(),
                anyInt(), anyInt(), anyInt(), anyBoolean(), anyString(), anyInt());
                anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyInt());
    }

    @MediumTest
@@ -607,7 +608,7 @@ public class BluetoothPhoneServiceTest extends TelecomTestCase {

        boolean didProcess = mBluetoothPhoneService.mBinder.processChld(CHLD_TYPE_RELEASEHELD);

        verify(mMockCallsManager).rejectCall(eq(ringingCall), eq(false), any(String.class));
        verify(mMockCallsManager).rejectCall(eq(ringingCall), eq(false), nullable(String.class));
        assertEquals(didProcess, true);
    }

+6 −7
Original line number Diff line number Diff line
@@ -39,9 +39,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -228,7 +227,7 @@ public class BluetoothRouteManagerTest extends StateMachineTestBase<BluetoothRou
                BluetoothRouteManager.AUDIO_OFF_STATE_NAME, null);
        setupConnectedDevices(new BluetoothDevice[]{device1}, null);
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
                any(ContentResolver.class))).thenReturn(0L);
                nullable(ContentResolver.class))).thenReturn(0L);
        when(mHeadsetProxy.connectAudio()).thenReturn(false);
        executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, null);
        // Wait 3 times: for the first connection attempt, the retry attempt, and once more to
@@ -249,7 +248,7 @@ public class BluetoothRouteManagerTest extends StateMachineTestBase<BluetoothRou
                BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX, device1);
        setupConnectedDevices(new BluetoothDevice[]{device1, device2}, null);
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
                any(ContentResolver.class))).thenReturn(0L);
                nullable(ContentResolver.class))).thenReturn(0L);
        when(mHeadsetProxy.connectAudio()).thenReturn(false);
        executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, device2.getAddress());
        // Wait 3 times: the first connection attempt is accounted for in executeRoutingAction,
@@ -426,7 +425,7 @@ public class BluetoothRouteManagerTest extends StateMachineTestBase<BluetoothRou
            BluetoothDevice first = getFirstExcluding(devices,
                    (String) invocation.getArguments()[0]);
            return first == null ? null : first.getAddress();
        }).when(mDeviceManager).getMostRecentlyConnectedDevice(anyString());
        }).when(mDeviceManager).getMostRecentlyConnectedDevice(nullable(String.class));
    }

    private void executeRoutingAction(BluetoothRouteManager brm, int message, String device) {
@@ -457,9 +456,9 @@ public class BluetoothRouteManagerTest extends StateMachineTestBase<BluetoothRou
        when(mDeviceManager.getHeadsetService()).thenReturn(mHeadsetProxy);
        when(mHeadsetProxy.connectAudio()).thenReturn(true);
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
                any(ContentResolver.class))).thenReturn(100000L);
                nullable(ContentResolver.class))).thenReturn(100000L);
        when(mTimeoutsAdapter.getBluetoothPendingTimeoutMillis(
                any(ContentResolver.class))).thenReturn(100000L);
                nullable(ContentResolver.class))).thenReturn(100000L);
    }

    private static BluetoothDevice getFirstExcluding(
+7 −6
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import org.mockito.Mock;

import java.util.Collections;

import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
@@ -110,11 +111,11 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {

        when(mDefaultDialerCache.getDefaultDialerApplication(eq(UserHandle.USER_CURRENT)))
                .thenReturn(PKG_NAME);
        when(mPackageManager.queryIntentServicesAsUser(any(Intent.class), anyInt(), anyInt()))
        when(mPackageManager.queryIntentServicesAsUser(nullable(Intent.class), anyInt(), anyInt()))
                .thenReturn(Collections.singletonList(mResolveInfo));
        when(mParcelableCallUtilsConverter.toParcelableCall(
                eq(mCall), anyBoolean(), eq(mPhoneAccountRegistrar))).thenReturn(null);
        when(mContext.bindServiceAsUser(any(Intent.class), any(ServiceConnection.class),
        when(mContext.bindServiceAsUser(nullable(Intent.class), nullable(ServiceConnection.class),
                anyInt(), eq(UserHandle.CURRENT))).thenReturn(true);
    }

@@ -128,7 +129,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {

    @SmallTest
    public void testNoResolveEntries() {
        when(mPackageManager.queryIntentServicesAsUser(any(Intent.class), anyInt(), anyInt()))
        when(mPackageManager.queryIntentServicesAsUser(nullable(Intent.class), anyInt(), anyInt()))
                .thenReturn(Collections.emptyList());
        mFilter.startFilterLookup(mCall, mCallback);
        verify(mCallback).onCallFilteringComplete(eq(mCall), eq(PASS_RESULT));
@@ -150,7 +151,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {

    @SmallTest
    public void testContextFailToBind() {
        when(mContext.bindServiceAsUser(any(Intent.class), any(ServiceConnection.class),
        when(mContext.bindServiceAsUser(nullable(Intent.class), nullable(ServiceConnection.class),
                anyInt(), eq(UserHandle.CURRENT))).thenReturn(false);
        mFilter.startFilterLookup(mCall, mCallback);
        verify(mCallback).onCallFilteringComplete(eq(mCall), eq(PASS_RESULT));
@@ -159,7 +160,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
    @SmallTest
    public void testExceptionInScreeningService() throws Exception {
        doThrow(new RemoteException()).when(mCallScreeningService).screenCall(
                any(ICallScreeningAdapter.class), any(ParcelableCall.class));
                nullable(ICallScreeningAdapter.class), nullable(ParcelableCall.class));
        mFilter.startFilterLookup(mCall, mCallback);
        ServiceConnection serviceConnection = verifyBindingIntent();
        serviceConnection.onServiceConnected(COMPONENT_NAME, mBinder);
@@ -214,7 +215,7 @@ public class CallScreeningServiceFilterTest extends TelecomTestCase {
    private ICallScreeningAdapter getCallScreeningAdapter() throws Exception {
        ArgumentCaptor<ICallScreeningAdapter> captor =
                ArgumentCaptor.forClass(ICallScreeningAdapter.class);
        verify(mCallScreeningService).screenCall(captor.capture(), any(ParcelableCall.class));
        verify(mCallScreeningService).screenCall(captor.capture(), nullable(ParcelableCall.class));
        return captor.getValue();
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.content.IContentProvider;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
@@ -208,6 +209,11 @@ public class ComponentContextFixture implements TestFixture<Context> {
            return "com.android.server.telecom.tests";
        }

        @Override
        public ApplicationInfo getApplicationInfo() {
            return mTestApplicationInfo;
        }

        @Override
        public ContentResolver getContentResolver() {
            return new ContentResolver(mApplicationContextSpy) {
@@ -423,6 +429,7 @@ public class ComponentContextFixture implements TestFixture<Context> {
    private final CountryDetector mCountryDetector = mock(CountryDetector.class);
    private final Map<String, IContentProvider> mIContentProviderByUri = new HashMap<>();
    private final Configuration mResourceConfiguration = new Configuration();
    private final ApplicationInfo mTestApplicationInfo = new ApplicationInfo();

    private TelecomManager mTelecomManager = null;

+2 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import org.mockito.MockitoAnnotations;

import java.util.ArrayList;

import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
@@ -242,7 +243,7 @@ public class CreateConnectionProcessorTest extends TelecomTestCase {
        // Put in a regular phone account to be sure it doesn't call that
        PhoneAccountHandle pAHandle = getNewTargetPhoneAccountHandle("tel_acct");
        when(mMockAccountRegistrar.getOutgoingPhoneAccountForSchemeOfCurrentUser(
                any(String.class))).thenReturn(pAHandle);
                nullable(String.class))).thenReturn(pAHandle);
        // Include a normal Connection Manager to be sure it doesn't call that
        PhoneAccount callManagerPA = getNewConnectionManagerPhoneAccount("cm_acct", 0);
        // Include a connection Manager for the user with the capability to make calls
Loading