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

Commit aad0a1ad authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add unit tests for ImsVideoCallProviderWrapper."

parents 375768dd 4dd930cb
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -3015,8 +3015,15 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        IImsVideoCallProvider imsVideoCallProvider =
                imsCall.getCallSession().getVideoCallProvider();
        if (imsVideoCallProvider != null) {
            // TODO: Remove this when we can better formalize the format of session modify requests.
            boolean useVideoPauseWorkaround = mPhone.getContext().getResources().getBoolean(
                    com.android.internal.R.bool.config_useVideoPauseWorkaround);

            ImsVideoCallProviderWrapper imsVideoCallProviderWrapper =
                    new ImsVideoCallProviderWrapper(imsVideoCallProvider);
            if (useVideoPauseWorkaround) {
                imsVideoCallProviderWrapper.setUseVideoPauseWorkaround(useVideoPauseWorkaround);
            }
            conn.setVideoProvider(imsVideoCallProviderWrapper);
            imsVideoCallProviderWrapper.registerForDataUsageUpdate
                    (this, EVENT_VT_DATA_USAGE_UPDATE, imsCall);
+174 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.ims;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.telecom.VideoProfile;

import com.android.ims.internal.ImsVideoCallProviderWrapper;
import com.android.ims.internal.VideoPauseTracker;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

/**
 * Tests for the {@link com.android.ims.internal.VideoPauseTracker} class.
 */
@RunWith(AndroidJUnit4.class)
public class ImsVideoProviderWrapperTest extends TestCase {
    private ImsVideoCallProviderWrapper mImsVideoCallProviderWrapper;
    @Mock
    VideoPauseTracker mVideoPauseTracker;

    @Before
    @Override
    public void setUp() throws Exception {
        super.setUp();
        MockitoAnnotations.initMocks(this);
        mImsVideoCallProviderWrapper = new ImsVideoCallProviderWrapper(null, mVideoPauseTracker);
        when(mVideoPauseTracker.shouldPauseVideoFor(anyInt())).thenReturn(true);
        when(mVideoPauseTracker.shouldResumeVideoFor(anyInt())).thenReturn(true);
    }

    @SmallTest
    @Test
    public void testIsPause() {
        assertTrue(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_BIDIRECTIONAL,
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
        assertTrue(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_BIDIRECTIONAL,
                VideoProfile.STATE_PAUSED));
        assertFalse(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_PAUSED,
                VideoProfile.STATE_PAUSED));
        assertFalse(ImsVideoCallProviderWrapper.isPauseRequest(VideoProfile.STATE_AUDIO_ONLY,
                VideoProfile.STATE_AUDIO_ONLY));
    }

    @SmallTest
    @Test
    public void testIsResume() {
        assertTrue(ImsVideoCallProviderWrapper.isResumeRequest(
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
                VideoProfile.STATE_BIDIRECTIONAL));
        assertTrue(ImsVideoCallProviderWrapper.isResumeRequest(VideoProfile.STATE_PAUSED,
                VideoProfile.STATE_AUDIO_ONLY));
        assertFalse(ImsVideoCallProviderWrapper.isResumeRequest(
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
        assertFalse(ImsVideoCallProviderWrapper.isResumeRequest(VideoProfile.STATE_PAUSED,
                VideoProfile.STATE_AUDIO_ONLY | VideoProfile.STATE_PAUSED));
    }

    @SmallTest
    @Test
    public void testIsTurnOffCameraRequest() {
        assertTrue(ImsVideoCallProviderWrapper.isTurnOffCameraRequest(
                VideoProfile.STATE_BIDIRECTIONAL, VideoProfile.STATE_RX_ENABLED));
        assertTrue(ImsVideoCallProviderWrapper.isTurnOffCameraRequest(
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
                VideoProfile.STATE_RX_ENABLED));
        assertFalse(ImsVideoCallProviderWrapper.isTurnOffCameraRequest(
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED,
                VideoProfile.STATE_BIDIRECTIONAL));
    }

    @SmallTest
    @Test
    public void testIsTurnOnCameraRequest() {
        assertTrue(ImsVideoCallProviderWrapper.isTurnOnCameraRequest(
                VideoProfile.STATE_RX_ENABLED, VideoProfile.STATE_BIDIRECTIONAL));
        assertTrue(ImsVideoCallProviderWrapper.isTurnOnCameraRequest(
                VideoProfile.STATE_RX_ENABLED,
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
        assertFalse(ImsVideoCallProviderWrapper.isTurnOnCameraRequest(
                VideoProfile.STATE_BIDIRECTIONAL,
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED));
    }

    /**
     * Verifies that the to profile is not changed when a request to turn off the camera is sent
     * using the broken vendor-format request.
     */
    @SmallTest
    @Test
    public void testNoFilterWhenDisablingCamera() {
        mImsVideoCallProviderWrapper.setUseVideoPauseWorkaround(true);
        VideoProfile fromProfile = new VideoProfile(
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED);
        VideoProfile toProfile = new VideoProfile(VideoProfile.STATE_RX_ENABLED);

        VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
                toProfile, VideoPauseTracker.SOURCE_INCALL);
        assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    }

    /**
     * Verifies that the to profile is not changed when a request to turn on the camera is sent
     * using the broken vendor-format request.
     */
    @SmallTest
    @Test
    public void testNoFilterWhenEnablingCamera() {
        mImsVideoCallProviderWrapper.setUseVideoPauseWorkaround(true);
        VideoProfile fromProfile = new VideoProfile(
                VideoProfile.STATE_RX_ENABLED | VideoProfile.STATE_PAUSED);
        VideoProfile toProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL);

        VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
                toProfile, VideoPauseTracker.SOURCE_INCALL);
        assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    }

    /**
     * Verifies normal operation of filtering of pause request.
     */
    @SmallTest
    @Test
    public void testNoFilteringOnPause() {
        VideoProfile fromProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL);
        VideoProfile toProfile = new VideoProfile(
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED);

        VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
                toProfile, VideoPauseTracker.SOURCE_INCALL);
        assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    }

    /**
     * Verifies normal operation of filtering of pause request.
     */
    @SmallTest
    @Test
    public void testNoFilteringOnResume() {
        VideoProfile fromProfile = new VideoProfile(
                VideoProfile.STATE_BIDIRECTIONAL | VideoProfile.STATE_PAUSED);
        VideoProfile toProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL);

        VideoProfile filteredTo = mImsVideoCallProviderWrapper.maybeFilterPauseResume(fromProfile,
                toProfile, VideoPauseTracker.SOURCE_INCALL);
        assertEquals(filteredTo.getVideoState(), toProfile.getVideoState());
    }
}