Add unit tests for ImsVideoCallProviderWrapper.
Tyler Gunn [Thu, 11 May 2017 00:47:13 +0000 (17:47 -0700)]
Specifically adding tests to ensure that the issue described in the bug
is handled correctly.

Test: Manual/unit
Bug: 35304446
Change-Id: I40fb4b7df15c55114bda506442e5efa0aefbd809

src/java/com/android/internal/telephony/imsphone/ImsPhoneCallTracker.java
tests/telephonytests/src/com/android/internal/telephony/ims/ImsVideoProviderWrapperTest.java [new file with mode: 0644]

index 828f4eb..1fb8cfa 100644 (file)
@@ -2906,8 +2906,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);
diff --git a/tests/telephonytests/src/com/android/internal/telephony/ims/ImsVideoProviderWrapperTest.java b/tests/telephonytests/src/com/android/internal/telephony/ims/ImsVideoProviderWrapperTest.java
new file mode 100644 (file)
index 0000000..338e8a4
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * 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());
+    }
+}
+