Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.server.telecom.tests;
     18 
     19 import org.junit.After;
     20 import org.junit.Before;
     21 import org.junit.Test;
     22 import org.junit.runner.RunWith;
     23 import org.junit.runners.JUnit4;
     24 import org.mockito.ArgumentCaptor;
     25 import org.mockito.Mock;
     26 import org.mockito.invocation.InvocationOnMock;
     27 import org.mockito.stubbing.Answer;
     28 
     29 import android.app.AppOpsManager;
     30 import android.content.Context;
     31 import android.graphics.SurfaceTexture;
     32 import android.net.Uri;
     33 import android.os.Build;
     34 import android.os.Handler;
     35 import android.os.Looper;
     36 import android.os.UserHandle;
     37 import android.telecom.Connection.VideoProvider;
     38 import android.telecom.InCallService;
     39 import android.telecom.InCallService.VideoCall;
     40 import android.telecom.VideoCallImpl;
     41 import android.telecom.VideoProfile;
     42 import android.telecom.VideoProfile.CameraCapabilities;
     43 import android.test.suitebuilder.annotation.MediumTest;
     44 import android.view.Surface;
     45 
     46 import com.google.common.base.Predicate;
     47 
     48 import java.util.List;
     49 import java.util.concurrent.CountDownLatch;
     50 import java.util.concurrent.TimeUnit;
     51 
     52 import static org.junit.Assert.assertEquals;
     53 import static org.mockito.Matchers.any;
     54 import static org.mockito.Matchers.anyInt;
     55 import static org.mockito.Matchers.anyLong;
     56 import static org.mockito.Matchers.anyString;
     57 import static org.mockito.Matchers.eq;
     58 import static org.mockito.Mockito.doAnswer;
     59 import static org.mockito.Mockito.doNothing;
     60 import static org.mockito.Mockito.doReturn;
     61 import static org.mockito.Mockito.doThrow;
     62 import static org.mockito.Mockito.timeout;
     63 import static org.mockito.Mockito.mock;
     64 import static org.mockito.Mockito.verify;
     65 
     66 /**
     67  * Performs tests of the {@link VideoProvider} and {@link VideoCall} APIs.  Ensures that requests
     68  * sent from an InCallService are routed through Telecom to a VideoProvider, and that callbacks are
     69  * correctly routed.
     70  */
     71 @RunWith(JUnit4.class)
     72 public class VideoProviderTest extends TelecomSystemTest {
     73     private static final int ORIENTATION_0 = 0;
     74     private static final int ORIENTATION_90 = 90;
     75     private static final float ZOOM_LEVEL = 3.0f;
     76 
     77     @Mock private VideoCall.Callback mVideoCallCallback;
     78     private IdPair mCallIds;
     79     private InCallService.VideoCall mVideoCall;
     80     private VideoCallImpl mVideoCallImpl;
     81     private ConnectionServiceFixture.ConnectionInfo mConnectionInfo;
     82     private CountDownLatch mVerificationLock;
     83     private AppOpsManager mAppOpsManager;
     84 
     85     private Answer mVerification = new Answer() {
     86         @Override
     87         public Object answer(InvocationOnMock i) {
     88             mVerificationLock.countDown();
     89             return null;
     90         }
     91     };
     92 
     93     @Override
     94     @Before
     95     public void setUp() throws Exception {
     96         super.setUp();
     97         mContext = mComponentContextFixture.getTestDouble().getApplicationContext();
     98         mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
     99 
    100         mCallIds = startAndMakeActiveOutgoingCall(
    101                 "650-555-1212",
    102                 mPhoneAccountA0.getAccountHandle(),
    103                 mConnectionServiceFixtureA);
    104 
    105         // Set the video provider on the connection.
    106         mConnectionServiceFixtureA.sendSetVideoProvider(
    107                 mConnectionServiceFixtureA.mLatestConnectionId);
    108 
    109         // Provide a mocked VideoCall.Callback to receive callbacks via.
    110         mVideoCallCallback = mock(InCallService.VideoCall.Callback.class);
    111 
    112         mVideoCall = mInCallServiceFixtureX.getCall(mCallIds.mCallId).getVideoCallImpl(
    113                 mInCallServiceComponentNameX.getPackageName(), Build.VERSION.SDK_INT);
    114         mVideoCallImpl = (VideoCallImpl) mVideoCall;
    115         mVideoCall.registerCallback(mVideoCallCallback);
    116 
    117         mConnectionInfo = mConnectionServiceFixtureA.mConnectionById.get(mCallIds.mConnectionId);
    118         mVerificationLock = new CountDownLatch(1);
    119         waitForHandlerAction(new Handler(Looper.getMainLooper()), TEST_TIMEOUT);
    120 
    121         doNothing().when(mContext).enforcePermission(anyString(), anyInt(), anyInt(), anyString());
    122         doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager).noteOp(anyInt(), anyInt(),
    123                 anyString());
    124     }
    125 
    126     @Override
    127     @After
    128     public void tearDown() throws Exception {
    129         super.tearDown();
    130     }
    131 
    132     /**
    133      * Tests the {@link VideoCall#setCamera(String)}, {@link VideoProvider#onSetCamera(String)},
    134      * and {@link VideoCall.Callback#onCameraCapabilitiesChanged(CameraCapabilities)}
    135      * APIS.
    136      */
    137     @MediumTest
    138     @Test
    139     public void testCameraChange() throws Exception {
    140         // Wait until the callback has been received before performing verification.
    141         doAnswer(mVerification).when(mVideoCallCallback)
    142                 .onCameraCapabilitiesChanged(any(CameraCapabilities.class));
    143 
    144         // Make 2 setCamera requests.
    145         mVideoCall.setCamera(MockVideoProvider.CAMERA_FRONT);
    146         mVideoCall.setCamera(MockVideoProvider.CAMERA_BACK);
    147 
    148         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    149 
    150         // Capture the video profile reported via the callback.
    151         ArgumentCaptor<CameraCapabilities> cameraCapabilitiesCaptor =
    152                 ArgumentCaptor.forClass(CameraCapabilities.class);
    153 
    154         // Verify that the callback was called twice and capture the callback arguments.
    155         verify(mVideoCallCallback, timeout(TEST_TIMEOUT).times(2))
    156                 .onCameraCapabilitiesChanged(cameraCapabilitiesCaptor.capture());
    157 
    158         assertEquals(2, cameraCapabilitiesCaptor.getAllValues().size());
    159 
    160         List<CameraCapabilities> cameraCapabilities = cameraCapabilitiesCaptor.getAllValues();
    161         // Ensure dimensions are as expected.
    162         assertEquals(MockVideoProvider.CAMERA_FRONT_DIMENSIONS,
    163                 cameraCapabilities.get(0).getHeight());
    164         assertEquals(MockVideoProvider.CAMERA_BACK_DIMENSIONS,
    165                 cameraCapabilities.get(1).getHeight());
    166     }
    167 
    168     /**
    169      * Tests the caller permission check in {@link VideoCall#setCamera(String)} to ensure a camera
    170      * change from a non-permitted caller is ignored.
    171      */
    172     @MediumTest
    173     @Test
    174     public void testCameraChangePermissionFail() throws Exception {
    175         // Wait until the callback has been received before performing verification.
    176         doAnswer(mVerification).when(mVideoCallCallback).onCallSessionEvent(anyInt());
    177 
    178         // ensure permission check fails.
    179         doThrow(new SecurityException()).when(mContext)
    180                 .enforcePermission(anyString(), anyInt(), anyInt(), anyString());
    181 
    182         // Set the target SDK version to to > N-MR1.
    183         mVideoCallImpl.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT);
    184         // Make a request to change the camera
    185         mVideoCall.setCamera(MockVideoProvider.CAMERA_FRONT);
    186         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    187 
    188         // Capture the session event reported via the callback.
    189         ArgumentCaptor<Integer> sessionEventCaptor = ArgumentCaptor.forClass(Integer.class);
    190         verify(mVideoCallCallback, timeout(TEST_TIMEOUT)).onCallSessionEvent(
    191                 sessionEventCaptor.capture());
    192 
    193         assertEquals(VideoProvider.SESSION_EVENT_CAMERA_PERMISSION_ERROR,
    194                 sessionEventCaptor.getValue().intValue());
    195     }
    196 
    197     /**
    198      * Tests the caller app ops check in {@link VideoCall#setCamera(String)} to ensure a camera
    199      * change from a non-permitted caller is ignored.
    200      */
    201     @MediumTest
    202     @Test
    203     public void testCameraChangeAppOpsFail() throws Exception {
    204         // Wait until the callback has been received before performing verification.
    205         doAnswer(mVerification).when(mVideoCallCallback).onCallSessionEvent(anyInt());
    206 
    207         // ensure app ops check fails.
    208         doReturn(AppOpsManager.MODE_ERRORED).when(mAppOpsManager).noteOp(anyInt(), anyInt(),
    209                 anyString());
    210 
    211         // Set the target SDK version to > N-MR1.
    212         mVideoCallImpl.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT);
    213         // Make a request to change the camera
    214         mVideoCall.setCamera(MockVideoProvider.CAMERA_FRONT);
    215         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    216 
    217         // Capture the session event reported via the callback.
    218         ArgumentCaptor<Integer> sessionEventCaptor = ArgumentCaptor.forClass(Integer.class);
    219         verify(mVideoCallCallback, timeout(TEST_TIMEOUT)).onCallSessionEvent(
    220                 sessionEventCaptor.capture());
    221 
    222         assertEquals(VideoProvider.SESSION_EVENT_CAMERA_PERMISSION_ERROR,
    223                 sessionEventCaptor.getValue().intValue());
    224     }
    225 
    226     /**
    227      * Tests the caller app ops check in {@link VideoCall#setCamera(String)} to ensure a camera
    228      * change from a non-permitted caller is ignored. For < N-MR1, throw a CAMERA_FAILURE instead
    229      * of a CAMERA_PERMISSION_ERROR.
    230      */
    231     @MediumTest
    232     @Test
    233     public void testCameraChangeAppOpsBelowNMR1Fail() throws Exception {
    234         // Wait until the callback has been received before performing verification.
    235         doAnswer(mVerification).when(mVideoCallCallback).onCallSessionEvent(anyInt());
    236 
    237         // ensure app ops check fails.
    238         doReturn(AppOpsManager.MODE_ERRORED).when(mAppOpsManager).noteOp(anyInt(), anyInt(),
    239                 anyString());
    240 
    241         // Set the target SDK version to below N-MR1
    242         mVideoCallImpl.setTargetSdkVersion(Build.VERSION_CODES.N);
    243 
    244         // Make a request to change the camera
    245         mVideoCall.setCamera(MockVideoProvider.CAMERA_FRONT);
    246         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    247 
    248         // Capture the session event reported via the callback.
    249         ArgumentCaptor<Integer> sessionEventCaptor = ArgumentCaptor.forClass(Integer.class);
    250         verify(mVideoCallCallback, timeout(TEST_TIMEOUT)).onCallSessionEvent(
    251                 sessionEventCaptor.capture());
    252 
    253         assertEquals(VideoProvider.SESSION_EVENT_CAMERA_FAILURE,
    254                 sessionEventCaptor.getValue().intValue());
    255     }
    256 
    257     /**
    258      * Tests the caller user handle check in {@link VideoCall#setCamera(String)} to ensure a camera
    259      * change from a background user is not permitted.
    260      */
    261     @MediumTest
    262     @Test
    263     public void testCameraChangeUserFail() throws Exception {
    264         // Wait until the callback has been received before performing verification.
    265         doAnswer(mVerification).when(mVideoCallCallback).onCallSessionEvent(anyInt());
    266 
    267         // Set a fake user to be the current foreground user.
    268         mTelecomSystem.getCallsManager().onUserSwitch(new UserHandle(1000));
    269 
    270         // Set the target SDK version to > N-MR1
    271         mVideoCallImpl.setTargetSdkVersion(Build.VERSION_CODES.CUR_DEVELOPMENT);
    272         // Make a request to change the camera
    273         mVideoCall.setCamera(MockVideoProvider.CAMERA_FRONT);
    274         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    275 
    276         // Capture the session event reported via the callback.
    277         ArgumentCaptor<Integer> sessionEventCaptor = ArgumentCaptor.forClass(Integer.class);
    278         verify(mVideoCallCallback, timeout(TEST_TIMEOUT)).onCallSessionEvent(
    279                 sessionEventCaptor.capture());
    280 
    281         assertEquals(VideoProvider.SESSION_EVENT_CAMERA_PERMISSION_ERROR,
    282                 sessionEventCaptor.getValue().intValue());
    283     }
    284 
    285     /**
    286      * Tests the caller permission check in {@link VideoCall#setCamera(String)} to ensure the
    287      * caller can null out the camera, even if they do not have camera permission.
    288      */
    289     @MediumTest
    290     @Test
    291     public void testCameraChangeNullNoPermission() throws Exception {
    292         // Wait until the callback has been received before performing verification.
    293         doAnswer(mVerification).when(mVideoCallCallback).onCallSessionEvent(anyInt());
    294 
    295         // ensure permission check fails.
    296         doThrow(new SecurityException()).when(mContext)
    297                 .enforcePermission(anyString(), anyInt(), anyInt(), anyString());
    298 
    299         // Make a request to null the camera; we expect the permission check won't happen.
    300         mVideoCall.setCamera(null);
    301         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    302 
    303         // Capture the session event reported via the callback.
    304         ArgumentCaptor<Integer> sessionEventCaptor = ArgumentCaptor.forClass(Integer.class);
    305         verify(mVideoCallCallback, timeout(TEST_TIMEOUT)).onCallSessionEvent(
    306                 sessionEventCaptor.capture());
    307 
    308         // See the MockVideoProvider class; for convenience when the camera is nulled we just send
    309         // back a "camera ready" event.
    310         assertEquals(VideoProvider.SESSION_EVENT_CAMERA_READY,
    311                 sessionEventCaptor.getValue().intValue());
    312     }
    313 
    314     /**
    315      * Tests the {@link VideoCall#setPreviewSurface(Surface)} and
    316      * {@link VideoProvider#onSetPreviewSurface(Surface)} APIs.
    317      */
    318     @MediumTest
    319     @Test
    320     public void testSetPreviewSurface() throws Exception {
    321         final Surface surface = new Surface(new SurfaceTexture(1));
    322         mVideoCall.setPreviewSurface(surface);
    323 
    324         assertTrueWithTimeout(new Predicate<Void>() {
    325             @Override
    326             public boolean apply(Void v) {
    327                 return mConnectionInfo.mockVideoProvider.getPreviewSurface() == surface;
    328             }
    329         });
    330 
    331         mVideoCall.setPreviewSurface(null);
    332 
    333         assertTrueWithTimeout(new Predicate<Void>() {
    334             @Override
    335             public boolean apply(Void v) {
    336                 return mConnectionInfo.mockVideoProvider.getPreviewSurface() == null;
    337             }
    338         });
    339     }
    340 
    341     /**
    342      * Tests the {@link VideoCall#setDisplaySurface(Surface)} and
    343      * {@link VideoProvider#onSetDisplaySurface(Surface)} APIs.
    344      */
    345     @MediumTest
    346     @Test
    347     public void testSetDisplaySurface() throws Exception {
    348         final Surface surface = new Surface(new SurfaceTexture(1));
    349         mVideoCall.setDisplaySurface(surface);
    350 
    351         assertTrueWithTimeout(new Predicate<Void>() {
    352             @Override
    353             public boolean apply(Void v) {
    354                 return mConnectionInfo.mockVideoProvider.getDisplaySurface() == surface;
    355             }
    356         });
    357 
    358         mVideoCall.setDisplaySurface(null);
    359 
    360         assertTrueWithTimeout(new Predicate<Void>() {
    361             @Override
    362             public boolean apply(Void v) {
    363                 return mConnectionInfo.mockVideoProvider.getDisplaySurface() == null;
    364             }
    365         });
    366     }
    367 
    368     /**
    369      * Tests the {@link VideoCall#setDeviceOrientation(int)} and
    370      * {@link VideoProvider#onSetDeviceOrientation(int)} APIs.
    371      */
    372     @MediumTest
    373     @Test
    374     public void testSetDeviceOrientation() throws Exception {
    375         mVideoCall.setDeviceOrientation(ORIENTATION_0);
    376 
    377         assertTrueWithTimeout(new Predicate<Void>() {
    378             @Override
    379             public boolean apply(Void v) {
    380                 return mConnectionInfo.mockVideoProvider.getDeviceOrientation() == ORIENTATION_0;
    381             }
    382         });
    383 
    384         mVideoCall.setDeviceOrientation(ORIENTATION_90);
    385 
    386         assertTrueWithTimeout(new Predicate<Void>() {
    387             @Override
    388             public boolean apply(Void v) {
    389                 return mConnectionInfo.mockVideoProvider.getDeviceOrientation() == ORIENTATION_90;
    390             }
    391         });
    392     }
    393 
    394     /**
    395      * Tests the {@link VideoCall#setZoom(float)} and {@link VideoProvider#onSetZoom(float)} APIs.
    396      */
    397     @MediumTest
    398     @Test
    399     public void testSetZoom() throws Exception {
    400         mVideoCall.setZoom(ZOOM_LEVEL);
    401 
    402         assertTrueWithTimeout(new Predicate<Void>() {
    403             @Override
    404             public boolean apply(Void v) {
    405                 return mConnectionInfo.mockVideoProvider.getZoom() == ZOOM_LEVEL;
    406             }
    407         });
    408     }
    409 
    410     /**
    411      * Tests the {@link VideoCall#sendSessionModifyRequest(VideoProfile)},
    412      * {@link VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)},
    413      * {@link VideoProvider#receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}, and
    414      * {@link VideoCall.Callback#onSessionModifyResponseReceived(int, VideoProfile, VideoProfile)}
    415      * APIs.
    416      *
    417      * Emulates a scenario where an InCallService sends a request to upgrade to video, which the
    418      * peer accepts as-is.
    419      */
    420     @MediumTest
    421     @Test
    422     public void testSessionModifyRequest() throws Exception {
    423         VideoProfile requestProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL);
    424 
    425         // Set the starting video state on the video call impl; normally this would be set based on
    426         // the original android.telecom.Call instance.
    427         mVideoCallImpl.setVideoState(VideoProfile.STATE_RX_ENABLED);
    428 
    429         doAnswer(mVerification).when(mVideoCallCallback)
    430                 .onSessionModifyResponseReceived(anyInt(), any(VideoProfile.class),
    431                         any(VideoProfile.class));
    432 
    433         // Send the request.
    434         mVideoCall.sendSessionModifyRequest(requestProfile);
    435 
    436         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    437 
    438         // Capture the video profiles from the callback.
    439         ArgumentCaptor<VideoProfile> fromVideoProfileCaptor =
    440                 ArgumentCaptor.forClass(VideoProfile.class);
    441         ArgumentCaptor<VideoProfile> toVideoProfileCaptor =
    442                 ArgumentCaptor.forClass(VideoProfile.class);
    443 
    444         // Verify we got a response and capture the profiles.
    445         verify(mVideoCallCallback, timeout(TEST_TIMEOUT))
    446                 .onSessionModifyResponseReceived(eq(VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS),
    447                         fromVideoProfileCaptor.capture(), toVideoProfileCaptor.capture());
    448 
    449         assertEquals(VideoProfile.STATE_RX_ENABLED,
    450                 fromVideoProfileCaptor.getValue().getVideoState());
    451         assertEquals(VideoProfile.STATE_BIDIRECTIONAL,
    452                 toVideoProfileCaptor.getValue().getVideoState());
    453     }
    454 
    455     /**
    456      * Tests the {@link VideoCall#sendSessionModifyResponse(VideoProfile)},
    457      * and {@link VideoProvider#onSendSessionModifyResponse(VideoProfile)} APIs.
    458      */
    459     @MediumTest
    460     @Test
    461     public void testSessionModifyResponse() throws Exception {
    462         VideoProfile sessionModifyResponse = new VideoProfile(VideoProfile.STATE_TX_ENABLED);
    463 
    464         mVideoCall.sendSessionModifyResponse(sessionModifyResponse);
    465 
    466         assertTrueWithTimeout(new Predicate<Void>() {
    467             @Override
    468             public boolean apply(Void v) {
    469                 VideoProfile response = mConnectionInfo.mockVideoProvider
    470                         .getSessionModifyResponse();
    471                 return response != null && response.getVideoState() == VideoProfile.STATE_TX_ENABLED;
    472             }
    473         });
    474     }
    475 
    476     /**
    477      * Tests the {@link VideoCall#requestCameraCapabilities()} ()},
    478      * {@link VideoProvider#onRequestCameraCapabilities()} ()}, and
    479      * {@link VideoCall.Callback#onCameraCapabilitiesChanged(CameraCapabilities)} APIs.
    480      */
    481     @MediumTest
    482     @Test
    483     public void testRequestCameraCapabilities() throws Exception {
    484         // Wait until the callback has been received before performing verification.
    485         doAnswer(mVerification).when(mVideoCallCallback)
    486                 .onCameraCapabilitiesChanged(any(CameraCapabilities.class));
    487 
    488         mVideoCall.requestCameraCapabilities();
    489 
    490         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    491 
    492         verify(mVideoCallCallback, timeout(TEST_TIMEOUT))
    493                 .onCameraCapabilitiesChanged(any(CameraCapabilities.class));
    494     }
    495 
    496     /**
    497      * Tests the {@link VideoCall#setPauseImage(Uri)}, and
    498      * {@link VideoProvider#onSetPauseImage(Uri)} APIs.
    499      */
    500     @MediumTest
    501     @Test
    502     public void testSetPauseImage() throws Exception {
    503         final Uri testUri = Uri.fromParts("file", "test.jpg", null);
    504         mVideoCall.setPauseImage(testUri);
    505 
    506         assertTrueWithTimeout(new Predicate<Void>() {
    507             @Override
    508             public boolean apply(Void v) {
    509                 Uri pauseImage = mConnectionInfo.mockVideoProvider.getPauseImage();
    510                 return pauseImage != null && pauseImage.equals(testUri);
    511             }
    512         });
    513     }
    514 
    515     /**
    516      * Tests the {@link VideoCall#requestCallDataUsage()},
    517      * {@link VideoProvider#onRequestConnectionDataUsage()}, and
    518      * {@link VideoCall.Callback#onCallDataUsageChanged(long)} APIs.
    519      */
    520     @MediumTest
    521     @Test
    522     public void testRequestDataUsage() throws Exception {
    523         // Wait until the callback has been received before performing verification.
    524         doAnswer(mVerification).when(mVideoCallCallback)
    525                 .onCallDataUsageChanged(anyLong());
    526 
    527         mVideoCall.requestCallDataUsage();
    528 
    529         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    530 
    531         verify(mVideoCallCallback, timeout(TEST_TIMEOUT))
    532                 .onCallDataUsageChanged(eq(MockVideoProvider.DATA_USAGE));
    533     }
    534 
    535     /**
    536      * Tests the {@link VideoProvider#receiveSessionModifyRequest(VideoProfile)},
    537      * {@link VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)} APIs.
    538      */
    539     @MediumTest
    540     @Test
    541     public void testReceiveSessionModifyRequest() throws Exception {
    542         // Wait until the callback has been received before performing verification.
    543         doAnswer(mVerification).when(mVideoCallCallback)
    544                 .onSessionModifyRequestReceived(any(VideoProfile.class));
    545 
    546         mConnectionInfo.mockVideoProvider.sendMockSessionModifyRequest();
    547 
    548         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    549 
    550         ArgumentCaptor<VideoProfile> requestProfileCaptor =
    551                 ArgumentCaptor.forClass(VideoProfile.class);
    552         verify(mVideoCallCallback, timeout(TEST_TIMEOUT))
    553                 .onSessionModifyRequestReceived(requestProfileCaptor.capture());
    554         assertEquals(VideoProfile.STATE_BIDIRECTIONAL,
    555                 requestProfileCaptor.getValue().getVideoState());
    556     }
    557 
    558 
    559     /**
    560      * Tests the {@link VideoProvider#handleCallSessionEvent(int)}, and
    561      * {@link VideoCall.Callback#onCallSessionEvent(int)} APIs.
    562      */
    563     @MediumTest
    564     @Test
    565     public void testSessionEvent() throws Exception {
    566         // Wait until the callback has been received before performing verification.
    567         doAnswer(mVerification).when(mVideoCallCallback)
    568                 .onCallSessionEvent(anyInt());
    569 
    570         mConnectionInfo.mockVideoProvider.sendMockSessionEvent(
    571                 VideoProvider.SESSION_EVENT_CAMERA_READY);
    572 
    573         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    574 
    575         verify(mVideoCallCallback, timeout(TEST_TIMEOUT))
    576                 .onCallSessionEvent(eq(VideoProvider.SESSION_EVENT_CAMERA_READY));
    577     }
    578 
    579     /**
    580      * Tests the {@link VideoProvider#changePeerDimensions(int, int)} and
    581      * {@link VideoCall.Callback#onPeerDimensionsChanged(int, int)} APIs.
    582      */
    583     @MediumTest
    584     @Test
    585     public void testPeerDimensionChange() throws Exception {
    586         // Wait until the callback has been received before performing verification.
    587         doAnswer(mVerification).when(mVideoCallCallback)
    588                 .onPeerDimensionsChanged(anyInt(), anyInt());
    589 
    590         mConnectionInfo.mockVideoProvider.sendMockPeerDimensions(MockVideoProvider.PEER_DIMENSIONS,
    591                 MockVideoProvider.PEER_DIMENSIONS);
    592 
    593         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    594 
    595         verify(mVideoCallCallback, timeout(TEST_TIMEOUT))
    596                 .onPeerDimensionsChanged(eq(MockVideoProvider.PEER_DIMENSIONS),
    597                         eq(MockVideoProvider.PEER_DIMENSIONS));
    598     }
    599 
    600     /**
    601      * Tests the {@link VideoProvider#changeVideoQuality(int)} and
    602      * {@link VideoCall.Callback#onVideoQualityChanged(int)} APIs.
    603      */
    604     @MediumTest
    605     @Test
    606     public void testVideoQualityChange() throws Exception {
    607         // Wait until the callback has been received before performing verification.
    608         doAnswer(mVerification).when(mVideoCallCallback)
    609                 .onVideoQualityChanged(anyInt());
    610 
    611         mConnectionInfo.mockVideoProvider.sendMockVideoQuality(VideoProfile.QUALITY_HIGH);
    612 
    613         mVerificationLock.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    614 
    615         verify(mVideoCallCallback, timeout(TEST_TIMEOUT))
    616                 .onVideoQualityChanged(eq(VideoProfile.QUALITY_HIGH));
    617     }
    618 }
    619