summaryrefslogtreecommitdiff
path: root/InCallUI
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2015-03-06 11:40:15 -0800
committerYorke Lee <yorkelee@google.com>2015-03-06 11:40:15 -0800
commitf2c5fe2368b93576fc186c7dd311c4e4d2c6b743 (patch)
treec802fe144a9ba3c0644fa5e81c997d62f1dc0d8d /InCallUI
parent46d62c03a8066d43a709f52ddf8aa0f57e1ddb2c (diff)
Flesh out more InCall tests
Change-Id: If77e0767e9dbc65a9235dc1841f4d7298e4d39d5
Diffstat (limited to 'InCallUI')
-rw-r--r--InCallUI/src/com/android/incallui/Call.java28
-rw-r--r--InCallUI/src/com/android/incallui/InCallPresenter.java2
-rw-r--r--InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java58
3 files changed, 67 insertions, 21 deletions
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java
index 16e4a2c76..2060944cd 100644
--- a/InCallUI/src/com/android/incallui/Call.java
+++ b/InCallUI/src/com/android/incallui/Call.java
@@ -21,6 +21,7 @@ import com.android.contacts.common.testing.NeededForTesting;
import android.content.Context;
import android.net.Uri;
+import android.os.Bundle;
import android.telecom.CallProperties;
import android.telecom.DisconnectCause;
import android.telecom.GatewayInfo;
@@ -35,7 +36,7 @@ import java.util.Locale;
/**
* Describes a single call and its state.
*/
-public final class Call {
+class Call {
/* Defines different states of this call */
public static class State {
public static final int INVALID = 0;
@@ -179,7 +180,7 @@ public final class Call {
}
};
- private final android.telecom.Call mTelecommCall;
+ private android.telecom.Call mTelecommCall;
private final String mId;
private int mState = State.INVALID;
private DisconnectCause mDisconnectCause;
@@ -269,6 +270,9 @@ public final class Call {
}
public String getNumber() {
+ if (mTelecommCall == null) {
+ return null;
+ }
if (mTelecommCall.getDetails().getGatewayInfo() != null) {
return mTelecommCall.getDetails().getGatewayInfo()
.getOriginalAddress().getSchemeSpecificPart();
@@ -277,7 +281,7 @@ public final class Call {
}
public Uri getHandle() {
- return mTelecommCall.getDetails().getHandle();
+ return mTelecommCall == null ? null : mTelecommCall.getDetails().getHandle();
}
public int getState() {
@@ -293,15 +297,21 @@ public final class Call {
}
public int getNumberPresentation() {
- return getTelecommCall().getDetails().getHandlePresentation();
+ return mTelecommCall == null ? null : mTelecommCall.getDetails().getHandlePresentation();
}
public int getCnapNamePresentation() {
- return getTelecommCall().getDetails().getCallerDisplayNamePresentation();
+ return mTelecommCall == null ? null
+ : mTelecommCall.getDetails().getCallerDisplayNamePresentation();
}
public String getCnapName() {
- return getTelecommCall().getDetails().getCallerDisplayName();
+ return mTelecommCall == null ? null
+ : getTelecommCall().getDetails().getCallerDisplayName();
+ }
+
+ public Bundle getExtras() {
+ return mTelecommCall == null ? null : mTelecommCall.getDetails().getExtras();
}
/** Returns call disconnect cause, defined by {@link DisconnectCause}. */
@@ -354,15 +364,15 @@ public final class Call {
}
public GatewayInfo getGatewayInfo() {
- return mTelecommCall.getDetails().getGatewayInfo();
+ return mTelecommCall == null ? null : mTelecommCall.getDetails().getGatewayInfo();
}
public PhoneAccountHandle getAccountHandle() {
- return mTelecommCall.getDetails().getAccountHandle();
+ return mTelecommCall == null ? null : mTelecommCall.getDetails().getAccountHandle();
}
public VideoCall getVideoCall() {
- return mTelecommCall.getVideoCall();
+ return mTelecommCall == null ? null : mTelecommCall.getVideoCall();
}
public List<String> getChildCallIds() {
diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java
index e90dc99a5..1ff196444 100644
--- a/InCallUI/src/com/android/incallui/InCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/InCallPresenter.java
@@ -1013,7 +1013,7 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener,
*/
public static boolean isCallWithNoValidAccounts(Call call) {
if (call != null && !isEmergencyCall(call)) {
- Bundle extras = call.getTelecommCall().getDetails().getExtras();
+ Bundle extras = call.getExtras();
if (extras == null) {
extras = EMPTY_EXTRAS;
diff --git a/InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java b/InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java
index 6d6087615..55ab1e1dd 100644
--- a/InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java
+++ b/InCallUI/tests/src/com/android/incallui/InCallPresenterTest.java
@@ -22,6 +22,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
+import android.telecom.PhoneAccountHandle;
import android.test.InstrumentationTestCase;
import com.android.incallui.InCallPresenter.InCallState;
@@ -31,10 +32,11 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
public class InCallPresenterTest extends InstrumentationTestCase {
- private static final Call TEST_INCOMING_CALL = new Call(Call.State.INCOMING);
- private static final Call TEST_ACTIVE_CALL = new Call(Call.State.ACTIVE);
- private static final Call TEST_PENDING_CALL = new Call(Call.State.CONNECTING);
- private static final Call TEST_WAITING_FOR_ACCOUNT_CALL = new Call(Call.State.PRE_DIAL_WAIT);
+ private Call mIncomingCall;
+ private Call mActiveCall;
+ private Call mConnectingCall;
+ private Call mWaitingForAccountsCall;
+ private Call mDisconnectedCall;
@Mock private InCallActivity mInCallActivity;
@Mock private AudioModeProvider mAudioModeProvider;
@@ -52,6 +54,13 @@ public class InCallPresenterTest extends InstrumentationTestCase {
System.setProperty("dexmaker.dexcache",
getInstrumentation().getTargetContext().getCacheDir().getPath());
MockitoAnnotations.initMocks(this);
+
+ mIncomingCall = getMockCall(Call.State.INCOMING);
+ mActiveCall = getMockCall(Call.State.ACTIVE);
+ mConnectingCall = getMockCall(Call.State.CONNECTING);
+ mWaitingForAccountsCall = getMockCall(Call.State.PRE_DIAL_WAIT, false);
+ mDisconnectedCall = getMockCall(Call.State.DISCONNECTED);
+
mInCallPresenter = InCallPresenter.getInstance();
mInCallPresenter.setUp(mContext, mCallList, mAudioModeProvider, mStatusBarNotifier,
mContactInfoCache, mProximitySensor);
@@ -78,7 +87,7 @@ public class InCallPresenterTest extends InstrumentationTestCase {
}
public void testOnCallListChange_sendsNotificationWhenInCall() {
- when(mCallList.getIncomingCall()).thenReturn(TEST_INCOMING_CALL);
+ when(mCallList.getIncomingCall()).thenReturn(mIncomingCall);
mInCallPresenter.onCallListChange(mCallList);
@@ -91,7 +100,7 @@ public class InCallPresenterTest extends InstrumentationTestCase {
* activity.
*/
public void testOnCallListChange_handlesCallWaitingWhenScreenOffShouldRestartActivity() {
- when(mCallList.getActiveCall()).thenReturn(TEST_ACTIVE_CALL);
+ when(mCallList.getActiveCall()).thenReturn(mActiveCall);
mInCallPresenter.onCallListChange(mCallList);
mInCallPresenter.setActivity(mInCallActivity);
@@ -100,7 +109,7 @@ public class InCallPresenterTest extends InstrumentationTestCase {
when(mInCallActivity.isDestroyed()).thenReturn(false);
when(mInCallActivity.isFinishing()).thenReturn(false);
when(mProximitySensor.isScreenReallyOff()).thenReturn(true);
- when(mCallList.getIncomingCall()).thenReturn(TEST_INCOMING_CALL);
+ when(mCallList.getIncomingCall()).thenReturn(mIncomingCall);
mInCallPresenter.onCallListChange(mCallList);
verify(mInCallActivity).finish();
@@ -111,12 +120,12 @@ public class InCallPresenterTest extends InstrumentationTestCase {
* that it can display an error dialog.
*/
public void testOnCallListChange_pendingOutgoingToInCallTransitionShowsUiForErrorDialog() {
- when(mCallList.getPendingOutgoingCall()).thenReturn(TEST_PENDING_CALL);
+ when(mCallList.getPendingOutgoingCall()).thenReturn(mConnectingCall);
mInCallPresenter.onCallListChange(mCallList);
when(mCallList.getPendingOutgoingCall()).thenReturn(null);
- when(mCallList.getActiveCall()).thenReturn(TEST_ACTIVE_CALL);
+ when(mCallList.getActiveCall()).thenReturn(mActiveCall);
mInCallPresenter.onCallListChange(mCallList);
@@ -129,7 +138,7 @@ public class InCallPresenterTest extends InstrumentationTestCase {
* to display the account picker.
*/
public void testOnCallListChange_noAccountProvidedForCallShowsUiForAccountPicker() {
- when(mCallList.getWaitingForAccountCall()).thenReturn(TEST_WAITING_FOR_ACCOUNT_CALL);
+ when(mCallList.getWaitingForAccountCall()).thenReturn(mWaitingForAccountsCall);
mInCallPresenter.onCallListChange(mCallList);
verify(mContext).startActivity(InCallPresenter.getInstance().getInCallIntent(false, false));
@@ -141,13 +150,27 @@ public class InCallPresenterTest extends InstrumentationTestCase {
* InCallActivity is not displayed.
*/
public void testOnCallListChange_noCallsToPendingOutgoingDoesNotShowUi() {
- when(mCallList.getPendingOutgoingCall()).thenReturn(TEST_PENDING_CALL);
+ when(mCallList.getPendingOutgoingCall()).thenReturn(mConnectingCall);
mInCallPresenter.onCallListChange(mCallList);
verifyInCallActivityNotStarted();
verifyIncomingCallNotificationNotSent();
}
+ public void testOnCallListChange_LastCallDisconnectedNoCallsLeftFinishesUi() {
+ when(mCallList.getDisconnectedCall()).thenReturn(mDisconnectedCall);
+ mInCallPresenter.onCallListChange(mCallList);
+
+ mInCallPresenter.setActivity(mInCallActivity);
+
+ verify(mInCallActivity, never()).finish();
+
+ // Last remaining disconnected call is removed from CallList, activity should shut down.
+ when(mCallList.getDisconnectedCall()).thenReturn(null);
+ mInCallPresenter.onCallListChange(mCallList);
+ verify(mInCallActivity).finish();
+ }
+
//TODO
public void testCircularReveal_startsCircularRevealForOutgoingCalls() {
@@ -174,4 +197,17 @@ public class InCallPresenterTest extends InstrumentationTestCase {
verify(mStatusBarNotifier, never()).updateNotification(Mockito.any(InCallState.class),
Mockito.any(CallList.class));
}
+
+ private static Call getMockCall(int state) {
+ return getMockCall(state, true);
+ }
+
+ private static Call getMockCall(int state, boolean hasAccountHandle) {
+ final Call call = Mockito.mock(Call.class);
+ when(call.getState()).thenReturn(Integer.valueOf(state));
+ if (hasAccountHandle) {
+ when(call.getAccountHandle()).thenReturn(new PhoneAccountHandle(null, null));
+ }
+ return call;
+ }
}