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

Commit a4a4dbab authored by Joonhun Shin's avatar Joonhun Shin Committed by Automerger Merge Worker
Browse files

Merge "Add test function to verify abnormal case." into main am: 7e9ac17a

parents 320268b3 7e9ac17a
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.imsphone;

import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -237,4 +238,40 @@ public class ImsCallTest extends TelephonyTest {
        assertFalse(mTestImsCall.isWifiCall());
        assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }

    @Test
    @SmallTest
    public void testListenerCalledAfterCallClosed() throws Exception {
        ImsCallSession mockSession = mock(ImsCallSession.class);
        ImsCall testImsCall = new ImsCall(mContext, mTestCallProfile);
        ImsCallProfile profile = new ImsCallProfile();
        when(mockSession.getCallProfile()).thenReturn(profile);
        testImsCall.attachSession(mockSession);

        ArgumentCaptor<ImsCallSession.Listener> listenerCaptor =
                ArgumentCaptor.forClass(ImsCallSession.Listener.class);
        verify(mockSession).setListener(listenerCaptor.capture(), any());
        ImsCallSession.Listener listener = listenerCaptor.getValue();
        assertNotNull(listener);

        // Call closed
        testImsCall.close();
        // Set CallProfile value to null because ImsCallSession was closed
        when(mockSession.getCallProfile()).thenReturn(null);

        // Set new profile with direction of none
        ImsStreamMediaProfile newProfile = new ImsStreamMediaProfile(
                ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB,
                ImsStreamMediaProfile.DIRECTION_INACTIVE,
                ImsStreamMediaProfile.VIDEO_QUALITY_NONE,
                ImsStreamMediaProfile.DIRECTION_INACTIVE,
                ImsStreamMediaProfile.RTT_MODE_DISABLED);
        try {
            listener.callSessionProgressing(mockSession, newProfile);
        } catch (Exception e) {
            throw new AssertionError("not expected exception", e);
        }

        assertNull(testImsCall.getCallProfile());
    }
}