Home | History | Annotate | Download | only in ims
      1 /*
      2  * Copyright (C) 2017 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.internal.telephony.ims;
     18 
     19 import static org.mockito.ArgumentMatchers.anyInt;
     20 import static org.mockito.Mockito.when;
     21 
     22 import android.support.test.filters.SmallTest;
     23 import android.support.test.runner.AndroidJUnit4;
     24 import android.telecom.VideoProfile;
     25 
     26 import com.android.ims.internal.ImsVideoCallProviderWrapper;
     27 import com.android.ims.internal.VideoPauseTracker;
     28 
     29 import junit.framework.TestCase;
     30 
     31 import org.junit.Before;
     32 import org.junit.Test;
     33 import org.junit.runner.RunWith;
     34 import org.mockito.Mock;
     35 import org.mockito.MockitoAnnotations;
     36 
     37 /**
     38  * Tests for the {@link com.android.ims.internal.VideoPauseTracker} class.
     39  */
     40 @RunWith(AndroidJUnit4.class)
     41 public class ImsVideoProviderWrapperTest extends TestCase {
     42     private ImsVideoCallProviderWrapper mImsVideoCallProviderWrapper;
     43     @Mock
     44     VideoPauseTracker mVideoPauseTracker;
     45 
     46     @Before
     47     @Override
     48     public void setUp() throws Exception {
     49         super.setUp();
     50         MockitoAnnotations.initMocks(this);
     51         mImsVideoCallProviderWrapper = new ImsVideoCallProviderWrapper(null, mVideoPauseTracker);
     52         when(mVideoPauseTracker.shouldPauseVideoFor(anyInt())).thenReturn(true);
     53         when(mVideoPauseTracker.shouldResumeVideoFor(anyInt())).thenReturn(true);
     54     }
     55 
     56     @SmallTest
     57     @Test
     58     public void testIsPause() {
     59         assertTrue(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_BIDIRECTIONAL,
     60                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
     61         assertTrue(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_BIDIRECTIONAL,
     62                 VideoProfile.STATE_PAUSED));
     63         assertFalse(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_PAUSED,
     64                 VideoProfile.STATE_PAUSED));
     65         assertFalse(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_AUDIO_ONLY,
     66                 VideoProfile.STATE_AUDIO_ONLY));
     67     }
     68 
     69     @SmallTest
     70     @Test
     71     public void testIsResume() {
     72         assertTrue(ImsVideoCallProviderWrapper.isResumeRequest(
     73                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
     74                 VideoProfile.STATE_BIDIRECTIONAL));
     75         assertTrue(ImsVideoCallProviderWrapper.isResumeRequest(VideoProfile.STATE_PAUSED,
     76                 VideoProfile.STATE_AUDIO_ONLY));
     77         assertFalse(ImsVideoCallProviderWrapper.isResumeRequest(
     78                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
     79                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
     80         assertFalse(ImsVideoCallProviderWrapper.isResumeRequest(VideoProfile.STATE_PAUSED,
     81                 VideoProfile.STATE_AUDIO_ONLY | VideoProfile.STATE_PAUSED));
     82     }
     83 
     84     @SmallTest
     85     @Test
     86     public void testIsTurnOffCameraRequest() {
     87         assertTrue(ImsVideoCallProviderWrapper.isTurnOffCameraRequest(
     88                 VideoProfile.STATE_BIDIRECTIONAL, VideoProfile.STATE_RX_ENABLED));
     89         assertTrue(ImsVideoCallProviderWrapper.isTurnOffCameraRequest(
     90                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
     91                 VideoProfile.STATE_RX_ENABLED));
     92         assertFalse(ImsVideoCallProviderWrapper.isTurnOffCameraRequest(
     93                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
     94                 VideoProfile.STATE_BIDIRECTIONAL));
     95     }
     96 
     97     @SmallTest
     98     @Test
     99     public void testIsTurnOnCameraRequest() {
    100         assertTrue(ImsVideoCallProviderWrapper.isTurnOnCameraRequest(
    101                 VideoProfile.STATE_RX_ENABLED, VideoProfile.STATE_BIDIRECTIONAL));
    102         assertTrue(ImsVideoCallProviderWrapper.isTurnOnCameraRequest(
    103                 VideoProfile.STATE_RX_ENABLED,
    104                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
    105         assertFalse(ImsVideoCallProviderWrapper.isTurnOnCameraRequest(
    106                 VideoProfile.STATE_BIDIRECTIONAL,
    107                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
    108     }
    109 
    110     /**
    111      * Verifies that the to profile is not changed when a request to turn off the camera is sent
    112      * using the broken vendor-format request.
    113      */
    114     @SmallTest
    115     @Test
    116     public void testNoFilterWhenDisablingCamera() {
    117         mImsVideoCallProviderWrapper.setUseVideoPauseWorkaround(true);
    118         VideoProfile fromProfile = new VideoProfile(
    119                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED);
    120         VideoProfile toProfile = new VideoProfile(VideoProfile.STATE_RX_ENABLED);
    121 
    122         VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
    123                 toProfile, VideoPauseTracker.SOURCE_INCALL);
    124         assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    125     }
    126 
    127     /**
    128      * Verifies that the to profile is not changed when a request to turn on the camera is sent
    129      * using the broken vendor-format request.
    130      */
    131     @SmallTest
    132     @Test
    133     public void testNoFilterWhenEnablingCamera() {
    134         mImsVideoCallProviderWrapper.setUseVideoPauseWorkaround(true);
    135         VideoProfile fromProfile = new VideoProfile(
    136                 VideoProfile.STATE_RX_ENABLED | VideoProfile.STATE_PAUSED);
    137         VideoProfile toProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL);
    138 
    139         VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
    140                 toProfile, VideoPauseTracker.SOURCE_INCALL);
    141         assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    142     }
    143 
    144     /**
    145      * Verifies normal operation of filtering of pause request.
    146      */
    147     @SmallTest
    148     @Test
    149     public void testNoFilteringOnPause() {
    150         VideoProfile fromProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL);
    151         VideoProfile toProfile = new VideoProfile(
    152                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED);
    153 
    154         VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
    155                 toProfile, VideoPauseTracker.SOURCE_INCALL);
    156         assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    157     }
    158 
    159     /**
    160      * Verifies normal operation of filtering of pause request.
    161      */
    162     @SmallTest
    163     @Test
    164     public void testNoFilteringOnResume() {
    165         VideoProfile fromProfile = new VideoProfile(
    166                 VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED);
    167         VideoProfile toProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL);
    168 
    169         VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
    170                 toProfile, VideoPauseTracker.SOURCE_INCALL);
    171         assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    172     }
    173 }
    174 
    175