1 /* 2 * Copyright (C) 2016 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.imsphone; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.fail; 22 import static org.mockito.Mockito.doReturn; 23 import static org.mockito.Mockito.eq; 24 import static org.mockito.Mockito.times; 25 import static org.mockito.Mockito.verify; 26 27 import android.support.test.filters.FlakyTest; 28 import android.test.suitebuilder.annotation.SmallTest; 29 30 import com.android.ims.ImsStreamMediaProfile; 31 import com.android.internal.telephony.Call; 32 import com.android.internal.telephony.TelephonyTest; 33 34 import org.junit.After; 35 import org.junit.Before; 36 import org.junit.Ignore; 37 import org.junit.Test; 38 import org.mockito.Mock; 39 40 public class ImsPhoneCallTest extends TelephonyTest { 41 @Mock 42 ImsPhoneConnection mConnection1; 43 @Mock 44 ImsPhoneConnection mConnection2; 45 @Mock 46 ImsStreamMediaProfile mMediaProfile; 47 48 private ImsPhoneCall mImsCallUT; 49 50 @Before 51 public void setUp() throws Exception { 52 super.setUp(getClass().getSimpleName()); 53 replaceInstance(ImsPhoneCallTracker.class, "mPhone", mImsCT, mImsPhone); 54 55 mImsCallUT = new ImsPhoneCall(mImsCT, ImsPhoneCall.CONTEXT_FOREGROUND); 56 } 57 58 @After 59 public void tearDown() throws Exception { 60 mImsCallUT = null; 61 super.tearDown(); 62 } 63 64 @FlakyTest 65 @Ignore 66 @Test 67 @SmallTest 68 public void testAttachDetach() { 69 //verify mConnections has 0 connections and is in IDLE state 70 assertEquals(0, mImsCallUT.mConnections.size()); 71 assertEquals(Call.State.IDLE, mImsCallUT.getState()); 72 73 //attach 74 mImsCallUT.attach(mConnection1, Call.State.ACTIVE); 75 76 //verify mConnections has 1 connection and is not in idle 77 assertEquals(1, mImsCallUT.mConnections.size()); 78 assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); 79 80 //detach 81 mImsCallUT.detach(mConnection1); 82 83 //verify mConnections has 0 connections and is in IDLE state 84 assertEquals(0, mImsCallUT.mConnections.size()); 85 assertEquals(Call.State.IDLE, mImsCallUT.getState()); 86 } 87 88 @FlakyTest 89 @Ignore 90 @Test 91 @SmallTest 92 public void testConnectionDisconnected() { 93 mImsCallUT.attach(mConnection1, Call.State.ACTIVE); 94 mImsCallUT.attach(mConnection2, Call.State.ACTIVE); 95 //both connections are active, state not change 96 mImsCallUT.connectionDisconnected(null); 97 assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); 98 // only one attached connection get disconnected, state not changed 99 doReturn(Call.State.DISCONNECTED).when(mConnection1).getState(); 100 mImsCallUT.connectionDisconnected(null); 101 assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); 102 doReturn(Call.State.DISCONNECTED).when(mConnection2).getState(); 103 mImsCallUT.connectionDisconnected(null); 104 assertEquals(Call.State.DISCONNECTED, mImsCallUT.getState()); 105 } 106 107 @FlakyTest 108 @Ignore 109 @Test 110 @SmallTest 111 public void testHangup() { 112 try { 113 mImsCallUT.hangup(); 114 verify(mImsCT).hangup(eq(mImsCallUT)); 115 } catch (Exception e) { 116 fail("Exception " + e + " not expected"); 117 } 118 } 119 120 @FlakyTest 121 @Ignore 122 @Test 123 @SmallTest 124 public void testUpdateRingBackTone() { 125 //Mock local tone 126 mMediaProfile.mAudioDirection = ImsStreamMediaProfile.DIRECTION_INACTIVE; 127 mImsCallProfile.mMediaProfile = mMediaProfile; 128 129 mImsCallUT.update(null, mImsCall, Call.State.ALERTING); 130 verify(mImsPhone, times(1)).startRingbackTone(); 131 assertEquals(Call.State.ALERTING, mImsCallUT.getState()); 132 mImsCallUT.update(null, mImsCall, Call.State.ACTIVE); 133 verify(mImsPhone, times(1)).stopRingbackTone(); 134 assertEquals(Call.State.ACTIVE, mImsCallUT.getState()); 135 } 136 137 @Test 138 @SmallTest 139 public void testSwitchWith() { 140 // this call in active state with connection 1 attached 141 mImsCallUT.attach(mConnection1, Call.State.ACTIVE); 142 // that call in idle state with connection 2 attached 143 ImsPhoneCall mImsCallThat = new ImsPhoneCall(mImsCT, ImsPhoneCall.CONTEXT_FOREGROUND); 144 mImsCallThat.attach(mConnection2, Call.State.IDLE); 145 146 mImsCallUT.switchWith(mImsCallThat); 147 assertEquals(Call.State.ACTIVE, mImsCallThat.getState()); 148 assertEquals(Call.State.IDLE, mImsCallUT.getState()); 149 assertEquals(mConnection1, mImsCallThat.getConnections().get(0)); 150 assertEquals(mConnection2, mImsCallUT.getConnections().get(0)); 151 } 152 153 @FlakyTest 154 @Ignore 155 @Test 156 @SmallTest 157 public void testMultiParty() { 158 doReturn(mImsCall).when(mConnection1).getImsCall(); 159 assertFalse(mImsCallUT.isMultiparty()); 160 verify(mImsCall, times(0)).isMultiparty(); 161 162 //get the ImsCall from the first Connection 163 mImsCallUT.attach(mConnection1, Call.State.ACTIVE); 164 mImsCallUT.isMultiparty(); 165 verify(mImsCall, times(1)).isMultiparty(); 166 } 167 } 168