summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYiqun Wu <yiqunw@google.com>2021-06-10 00:54:08 -0700
committerYiqun Wu <yiqunw@google.com>2021-06-10 12:49:50 -0700
commit7299ef0315d45bd08c35e8ce935096e4641785f4 (patch)
tree07476aa8ef6b8f5160627dfe73ae279db753d3cf
parent9df71d549e82737308365b6222dbe984e873503f (diff)
downloadDialer-7299ef0315d45bd08c35e8ce935096e4641785f4.tar.gz
Migrate OnGoingControllerBarFragmentTest
Bug: 187461550 Test: atest CarDialerUnitTests Change-Id: I04204a0b41e607baa25d72548125c478f0988218
-rw-r--r--src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragment.java6
-rw-r--r--testing/Android.bp2
-rw-r--r--testing/src/com/android/car/dialer/testing/TestViewActions.java52
-rw-r--r--tests/robotests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java265
-rw-r--r--tests/unittests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java252
-rw-r--r--tests/unittests/src/com/android/car/dialer/ui/activecall/RingingCallControllerBarFragmentTest.java17
6 files changed, 318 insertions, 276 deletions
diff --git a/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragment.java b/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragment.java
index 0d69fc86..59a14a5a 100644
--- a/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragment.java
+++ b/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragment.java
@@ -131,8 +131,6 @@ public class OnGoingCallControllerBarFragment extends Hilt_OnGoingCallController
mInCallViewModel.getPrimaryCallState().observe(this, this::setCallState);
mPrimaryCallLiveData = mInCallViewModel.getPrimaryCall();
mPrimaryCallDetailLiveData = mInCallViewModel.getPrimaryCallDetail();
- mPrimaryCallDetailLiveData.observe(this,
- primaryCallDetail -> mAudioRouteButton.setEnabled(primaryCallDetail != null));
mOngoingCallPairLiveData = mInCallViewModel.getOngoingCallPair();
mOngoingCallListLiveData = mInCallViewModel.getOngoingCallList();
@@ -206,12 +204,16 @@ public class OnGoingCallControllerBarFragment extends Hilt_OnGoingCallController
mAudioRouteView = fragmentView.findViewById(R.id.voice_channel_view);
mAudioRouteButton = fragmentView.findViewById(R.id.voice_channel_button);
mAudioRouteText = fragmentView.findViewById(R.id.voice_channel_text);
+ mPrimaryCallDetailLiveData.observe(this,
+ primaryCallDetail -> mAudioRouteView.setEnabled(primaryCallDetail != null));
mAudioRoutes.observe(this, audioRoutes -> {
if (audioRoutes.size() > 1) {
mAudioRouteView.setOnClickListener((v) -> {
mAudioRouteView.setActivated(true);
mAudioRouteSelectionDialog.show();
});
+ } else {
+ mAudioRouteView.setClickable(false);
}
});
diff --git a/testing/Android.bp b/testing/Android.bp
index 19918933..2421239f 100644
--- a/testing/Android.bp
+++ b/testing/Android.bp
@@ -18,6 +18,8 @@ android_library {
static_libs: [
"androidx.lifecycle_lifecycle-extensions",
+ "androidx.test.espresso.core",
+ "androidx.test.espresso.contrib",
"hilt_android",
"mockito-target-extended-minus-junit4",
],
diff --git a/testing/src/com/android/car/dialer/testing/TestViewActions.java b/testing/src/com/android/car/dialer/testing/TestViewActions.java
new file mode 100644
index 00000000..3ce918af
--- /dev/null
+++ b/testing/src/com/android/car/dialer/testing/TestViewActions.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 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.car.dialer.testing;
+
+import static org.hamcrest.Matchers.allOf;
+
+import android.view.View;
+
+import androidx.test.espresso.UiController;
+import androidx.test.espresso.ViewAction;
+import androidx.test.espresso.matcher.ViewMatchers;
+
+import org.hamcrest.Matcher;
+
+/** Custom view actions as a workaround for clicking overlapping UI elements. */
+public final class TestViewActions {
+
+ /** A click action by calling the {@link View#performClick()} api. */
+ public static ViewAction selfClick() {
+ return new ViewAction() {
+
+ @Override
+ public Matcher<View> getConstraints() {
+ return allOf(ViewMatchers.isDisplayingAtLeast(90), ViewMatchers.isClickable());
+ }
+
+ @Override
+ public String getDescription() {
+ return "Calling View#performClick() api";
+ }
+
+ @Override
+ public void perform(UiController uiController, View view) {
+ view.performClick();
+ }
+ };
+ }
+}
diff --git a/tests/robotests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java b/tests/robotests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java
deleted file mode 100644
index 803acd27..00000000
--- a/tests/robotests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (C) 2019 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.car.dialer.ui.activecall;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.telecom.Call;
-import android.telecom.CallAudioState;
-import android.telecom.TelecomManager;
-import android.view.View;
-import android.widget.ImageView;
-
-import androidx.core.util.Pair;
-import androidx.lifecycle.MutableLiveData;
-
-import com.android.car.dialer.CarDialerRobolectricTestRunner;
-import com.android.car.dialer.FragmentTestActivity;
-import com.android.car.dialer.R;
-import com.android.car.dialer.TestDialerApplication;
-import com.android.car.dialer.telecom.InCallServiceImpl;
-import com.android.car.dialer.telecom.UiCallManager;
-import com.android.car.dialer.testutils.ShadowAndroidViewModelFactory;
-import com.android.car.telephony.common.CallDetail;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-import org.robolectric.shadow.api.Shadow;
-import org.robolectric.shadows.ShadowContextImpl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Config(shadows = {ShadowAndroidViewModelFactory.class})
-@RunWith(CarDialerRobolectricTestRunner.class)
-public class OnGoingCallControllerBarFragmentTest {
- private OnGoingCallControllerBarFragment mOnGoingCallControllerBarFragment;
- private List<Integer> mAudioRouteList = new ArrayList<>();
- private MutableLiveData<Call> mCallLiveData;
- private MutableLiveData<Integer> mCallStateLiveData;
- private MutableLiveData<CallDetail> mCallDetailLiveData;
- private MutableLiveData<Boolean> mDialpadStateLiveData;
- private MutableLiveData<List<Call>> mCallListLiveData;
- private MutableLiveData<CallAudioState> mCallAudioStateLiveData;
- private MutableLiveData<Pair<Call, Call>> mOngoingCallPairLiveData;
- private List<Call> mCallList;
- @Mock
- private Call mMockCall;
- @Mock
- private TelecomManager mMockTelecomManager;
- @Mock
- private CallAudioState mMockAudioState;
- @Mock
- private UiCallManager mMockUiCallManager;
- @Mock
- private InCallViewModel mMockInCallViewModel;
- @Mock
- private InCallServiceImpl mMockInCallService;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- mCallLiveData = new MutableLiveData<>();
- mCallLiveData.setValue(mMockCall);
- mCallStateLiveData = new MutableLiveData<>();
- mCallDetailLiveData = new MutableLiveData<>();
- mDialpadStateLiveData = new MutableLiveData<>();
- mCallListLiveData = new MutableLiveData<>();
- mCallAudioStateLiveData = new MutableLiveData<>();
- mOngoingCallPairLiveData = new MutableLiveData<>();
- mCallList = new ArrayList<>();
- mCallList.add(mMockCall);
- mCallListLiveData.setValue(mCallList);
-
- ((TestDialerApplication) RuntimeEnvironment.application).setupInCallServiceImpl(
- mMockInCallService);
- when(mMockInCallService.getCallAudioState()).thenReturn(mMockAudioState);
- ShadowContextImpl shadowContext = Shadow.extract(
- RuntimeEnvironment.application.getBaseContext());
- shadowContext.setSystemService(Context.TELECOM_SERVICE, mMockTelecomManager);
- }
-
- @Test
- public void testMuteButton() {
- addFragment(Call.STATE_ACTIVE);
-
- View muteButton = mOnGoingCallControllerBarFragment.getView().findViewById(
- R.id.mute_button);
- // Test initial state
- assertThat(muteButton.hasOnClickListeners()).isTrue();
- assertThat(muteButton.isActivated()).isFalse();
- // Mute
- muteButton.performClick();
- assertThat(muteButton.isActivated()).isTrue();
- verify(mMockUiCallManager).setMuted(true);
- // Unmute
- muteButton.performClick();
- assertThat(muteButton.isActivated()).isFalse();
- verify(mMockUiCallManager).setMuted(false);
- }
-
- @Test
- public void testDialpadButton() {
- addFragment(Call.STATE_ACTIVE);
- mDialpadStateLiveData.setValue(false);
-
- View dialpadButton = mOnGoingCallControllerBarFragment.getView().findViewById(
- R.id.toggle_dialpad_button);
-
- // Test initial state
- assertThat(dialpadButton.hasOnClickListeners()).isTrue();
- assertThat(dialpadButton.isActivated()).isFalse();
- assertThat(mDialpadStateLiveData.getValue()).isFalse();
- // On open dialpad
- dialpadButton.performClick();
- assertThat(dialpadButton.isActivated()).isTrue();
- assertThat(mDialpadStateLiveData.getValue()).isTrue();
- // On close dialpad
- dialpadButton.performClick();
- assertThat(dialpadButton.isActivated()).isFalse();
- assertThat(mDialpadStateLiveData.getValue()).isFalse();
- }
-
- @Test
- public void testEndCallButton() {
- addFragment(Call.STATE_ACTIVE);
-
- View endCallButton = mOnGoingCallControllerBarFragment.getView().findViewById(
- R.id.end_call_button);
- assertThat(endCallButton.hasOnClickListeners()).isTrue();
- // onEndCall
- endCallButton.performClick();
- verify(mMockCall).disconnect();
- }
-
- @Test
- public void testAudioRouteButton_withOneAudioRoute() {
- addFragment(Call.STATE_ACTIVE);
-
- View fragmentView = mOnGoingCallControllerBarFragment.getView();
- assertThat(fragmentView.findViewById(
- R.id.voice_channel_button).hasOnClickListeners()).isFalse();
- }
-
- @Test
- public void testAudioRouteButtonView_withMultipleAudioRoutes() {
- mAudioRouteList.add(CallAudioState.ROUTE_EARPIECE);
- mAudioRouteList.add(CallAudioState.ROUTE_BLUETOOTH);
- addFragment(Call.STATE_ACTIVE);
-
- View fragmentView = mOnGoingCallControllerBarFragment.getView();
- View audioRouteButton = fragmentView.findViewById(R.id.voice_channel_view);
- assertThat(audioRouteButton.hasOnClickListeners()).isTrue();
- }
-
- @Test
- public void testClickPauseButton_activeCall() {
- addFragment(Call.STATE_ACTIVE);
-
- ImageView pauseButton = mOnGoingCallControllerBarFragment.getView().findViewById(
- R.id.pause_button);
- assertThat(pauseButton.hasOnClickListeners()).isTrue();
- assertThat(pauseButton.isEnabled()).isTrue();
- assertThat(pauseButton.isActivated()).isFalse();
-
- // onHoldCall
- pauseButton.performClick();
- verify(mMockCall).hold();
- // onUnHoldCall
- mCallStateLiveData.setValue(Call.STATE_HOLDING);
- pauseButton.performClick();
- verify(mMockCall).unhold();
- }
-
- @Test
- public void testClickPauseButton_onholdCall() {
- addFragment(Call.STATE_HOLDING);
- ImageView pauseButton = mOnGoingCallControllerBarFragment.getView().findViewById(
- R.id.pause_button);
- assertThat(pauseButton.isEnabled()).isTrue();
- assertThat(pauseButton.isActivated()).isTrue();
-
- // onHoldCall
- pauseButton.performClick();
- verify(mMockCall).unhold();
- }
-
- @Test
- public void testClickPauseButton_connectingCall() {
- addFragment(Call.STATE_DIALING);
- ImageView pauseButton = mOnGoingCallControllerBarFragment.getView().findViewById(
- R.id.pause_button);
- assertThat(pauseButton.isEnabled()).isFalse();
-
- pauseButton.performClick();
- verify(mMockCall, never()).hold();
- verify(mMockCall, never()).unhold();
- }
-
- @Test
- public void testPauseButton_MultipleCall() {
- mCallList.add(mock(Call.class));
- addFragment(Call.STATE_DIALING);
- ImageView pauseButton = mOnGoingCallControllerBarFragment.getView().findViewById(
- R.id.pause_button);
- assertThat(pauseButton.isEnabled()).isFalse();
- }
-
- private void addFragment(int callState) {
- mAudioRouteList.add(CallAudioState.ROUTE_SPEAKER);
- when(mMockUiCallManager.getSupportedAudioRoute(any())).thenReturn(mAudioRouteList);
-
- mCallStateLiveData.setValue(callState);
- when(mMockInCallViewModel.getPrimaryCall()).thenReturn(mCallLiveData);
- when(mMockInCallViewModel.getPrimaryCallDetail()).thenReturn(mCallDetailLiveData);
- when(mMockInCallViewModel.getPrimaryCallState()).thenReturn(mCallStateLiveData);
- when(mMockInCallViewModel.getDialpadOpenState()).thenReturn(mDialpadStateLiveData);
- when(mMockInCallViewModel.getAllCallList()).thenReturn(mCallListLiveData);
- when(mMockInCallViewModel.getCallAudioState()).thenReturn(mCallAudioStateLiveData);
- when(mMockInCallViewModel.getOngoingCallPair()).thenReturn(mOngoingCallPairLiveData);
- when(mMockInCallViewModel.getOngoingCallList()).thenReturn(mCallListLiveData);
-
- MutableLiveData<Integer> audioRouteLiveData = new MutableLiveData<>();
- audioRouteLiveData.setValue(CallAudioState.ROUTE_BLUETOOTH);
- when(mMockInCallViewModel.getAudioRoute()).thenReturn(audioRouteLiveData);
-
- MutableLiveData<Pair<Integer, Long>> stateAndConnectTimeLiveData = new MutableLiveData<>();
- when(mMockInCallViewModel.getCallStateAndConnectTime())
- .thenReturn(stateAndConnectTimeLiveData);
-
- ShadowAndroidViewModelFactory.add(InCallViewModel.class, mMockInCallViewModel);
-
- FragmentTestActivity fragmentTestActivity = Robolectric.buildActivity(
- FragmentTestActivity.class).create().start().resume().get();
- mOnGoingCallControllerBarFragment = new OnGoingCallControllerBarFragment();
- mOnGoingCallControllerBarFragment.mUiCallManager = mMockUiCallManager;
- fragmentTestActivity.setFragment(mOnGoingCallControllerBarFragment);
- }
-}
diff --git a/tests/unittests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java b/tests/unittests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java
new file mode 100644
index 00000000..f40ef7db
--- /dev/null
+++ b/tests/unittests/src/com/android/car/dialer/ui/activecall/OnGoingCallControllerBarFragmentTest.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2021 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.car.dialer.ui.activecall;
+
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.isClickable;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
+import static androidx.test.espresso.matcher.ViewMatchers.isNotClickable;
+import static androidx.test.espresso.matcher.ViewMatchers.isNotEnabled;
+import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+
+import static com.android.car.dialer.testing.TestViewActions.selfClick;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.telecom.Call;
+import android.telecom.CallAudioState;
+import android.view.View;
+
+import androidx.core.util.Pair;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Transformations;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.test.core.app.ActivityScenario;
+import androidx.test.espresso.matcher.ViewMatchers;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.car.dialer.R;
+import com.android.car.dialer.testing.TestActivity;
+import com.android.car.telephony.common.CallDetail;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public class OnGoingCallControllerBarFragmentTest {
+ private List<Integer> mAudioRouteList = new ArrayList<>();
+ private MutableLiveData<Call> mPrimaryCallLiveData;
+ private MutableLiveData<Integer> mCallStateLiveData;
+ private MutableLiveData<CallDetail> mCallDetailLiveData;
+ private MutableLiveData<Boolean> mDialpadStateLiveData;
+ private MutableLiveData<List<Call>> mCallListLiveData;
+ private MutableLiveData<CallAudioState> mCallAudioStateLiveData;
+ private LiveData<Pair<Call, Call>> mOngoingCallPairLiveData;
+ private List<Call> mCallList;
+ @Mock
+ private Call mMockCall;
+ @Mock
+ private Call.Details mMockDetails;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+
+ when(mMockCall.getDetails()).thenReturn(mMockDetails);
+ mPrimaryCallLiveData = new MutableLiveData<>(mMockCall);
+ mCallList = new ArrayList<>();
+ mCallList.add(mMockCall);
+ mCallListLiveData = new MutableLiveData<>(mCallList);
+ mOngoingCallPairLiveData = Transformations.map(mCallListLiveData,
+ calls -> calls.size() > 1 ? new Pair<>(mMockCall, calls.get(1))
+ : new Pair<>(mMockCall, null));
+
+ mCallStateLiveData = new MutableLiveData<>();
+ mCallDetailLiveData = new MutableLiveData<>();
+ mDialpadStateLiveData = new MutableLiveData<>(false);
+ mCallAudioStateLiveData = new MutableLiveData<>();
+ }
+
+ @Test
+ public void testMuteButton() {
+ addFragment(Call.STATE_ACTIVE);
+
+ // Test initial state
+ onView(withId(R.id.mute_button)).check(matches(isClickable())).check(
+ matches(isActivated(false)));
+
+ // Mute
+ onView(withId(R.id.mute_button)).perform(selfClick()).check(matches(isActivated(true)));
+ // Unmute
+ onView(withId(R.id.mute_button)).perform(selfClick()).check(matches(isActivated(false)));
+ }
+
+ @Test
+ public void testDialpadButton() {
+ addFragment(Call.STATE_ACTIVE);
+
+ // Test initial state
+ onView(withId(R.id.toggle_dialpad_button)).check(matches(isClickable())).check(
+ matches(isActivated(false)));
+ assertThat(mDialpadStateLiveData.getValue()).isFalse();
+ // On open dialpad
+ onView(withId(R.id.toggle_dialpad_button)).perform(selfClick()).check(
+ matches(isActivated(true)));
+ assertThat(mDialpadStateLiveData.getValue()).isTrue();
+ // On close dialpad
+ onView(withId(R.id.toggle_dialpad_button)).perform(selfClick()).check(
+ matches(isActivated(false)));
+ assertThat(mDialpadStateLiveData.getValue()).isFalse();
+ }
+
+ @Test
+ public void testEndCallButton() {
+ addFragment(Call.STATE_ACTIVE);
+
+ onView(withId(R.id.end_call_button)).check(matches(isClickable()));
+ // onEndCall
+ onView(withId(R.id.end_call_button)).perform(selfClick());
+ verify(mMockCall).disconnect();
+ }
+
+ @Test
+ public void testAudioRouteButton_withOneAudioRoute() {
+ addFragment(Call.STATE_ACTIVE);
+
+ onView(withId(R.id.voice_channel_view)).check(matches(isNotClickable()));
+ }
+
+ @Test
+ public void testAudioRouteButtonView_withMultipleAudioRoutes() {
+ mAudioRouteList.add(CallAudioState.ROUTE_EARPIECE);
+ addFragment(Call.STATE_ACTIVE);
+
+ onView(withId(R.id.voice_channel_view)).check(matches(isClickable()));
+ }
+
+ @Test
+ public void testClickPauseButton_activeCall() {
+ addFragment(Call.STATE_ACTIVE);
+
+ onView(withId(R.id.pause_button)).check(matches(isClickable())).check(
+ matches(isEnabled())).check(matches(isActivated(false)));
+
+ // onHoldCall
+ onView(withId(R.id.pause_button)).perform(selfClick());
+ verify(mMockCall).hold();
+ }
+
+ @Test
+ public void testClickPauseButton_onholdCall() {
+ addFragment(Call.STATE_HOLDING);
+
+ onView(withId(R.id.pause_button)).check(matches(isClickable())).check(
+ matches(isEnabled())).check(matches(isActivated(true)));
+
+ // onUnholdCall
+ onView(withId(R.id.pause_button)).perform(selfClick());
+ verify(mMockCall).unhold();
+ }
+
+ @Test
+ public void testClickPauseButton_connectingCall() {
+ addFragment(Call.STATE_DIALING);
+ onView(withId(R.id.pause_button)).check(matches(isNotEnabled()));
+
+ onView(withId(R.id.pause_button)).perform(selfClick());
+ verify(mMockCall, never()).hold();
+ verify(mMockCall, never()).unhold();
+ }
+
+ @Test
+ public void testPauseButton_MultipleCall() {
+ Call secondCall = mock(Call.class);
+ mCallList.add(secondCall);
+ addFragment(Call.STATE_ACTIVE);
+
+ onView(withId(R.id.pause_button)).check(matches(withEffectiveVisibility(
+ ViewMatchers.Visibility.GONE)));
+ onView(withId(R.id.merge_button)).check(matches(isDisplayed()));
+ }
+
+ private void addFragment(int callState) {
+ ActivityScenario<TestActivity> activityScenario = ActivityScenario.launch(
+ TestActivity.class);
+ activityScenario.onActivity(activity -> {
+ InCallViewModel mockInCallViewModel = new ViewModelProvider(activity).get(
+ InCallViewModel.class);
+
+ mCallStateLiveData.setValue(callState);
+ when(mockInCallViewModel.getPrimaryCall()).thenReturn(mPrimaryCallLiveData);
+ when(mockInCallViewModel.getPrimaryCallDetail()).thenReturn(mCallDetailLiveData);
+ when(mockInCallViewModel.getPrimaryCallState()).thenReturn(mCallStateLiveData);
+ when(mockInCallViewModel.getDialpadOpenState()).thenReturn(mDialpadStateLiveData);
+ when(mockInCallViewModel.getAllCallList()).thenReturn(mCallListLiveData);
+ when(mockInCallViewModel.getCallAudioState()).thenReturn(mCallAudioStateLiveData);
+ when(mockInCallViewModel.getOngoingCallPair()).thenReturn(mOngoingCallPairLiveData);
+ when(mockInCallViewModel.getOngoingCallList()).thenReturn(mCallListLiveData);
+
+ mAudioRouteList.add(CallAudioState.ROUTE_BLUETOOTH);
+ when(mockInCallViewModel.getSupportedAudioRoutes()).thenReturn(
+ new MutableLiveData<>(mAudioRouteList));
+ MutableLiveData<Integer> audioRouteLiveData = new MutableLiveData<>(
+ CallAudioState.ROUTE_BLUETOOTH);
+ when(mockInCallViewModel.getAudioRoute()).thenReturn(audioRouteLiveData);
+
+ MutableLiveData<Pair<Integer, Long>> stateAndConnectTimeLiveData =
+ new MutableLiveData<>();
+ when(mockInCallViewModel.getCallStateAndConnectTime())
+ .thenReturn(stateAndConnectTimeLiveData);
+
+ activity.getSupportFragmentManager().beginTransaction().add(
+ R.id.test_fragment_container,
+ new OnGoingCallControllerBarFragment()).commit();
+ });
+ }
+
+ private static Matcher<View> isActivated(boolean isActivated) {
+ return new TypeSafeMatcher<View>() {
+ @Override
+ protected boolean matchesSafely(View item) {
+ return item.isActivated() == isActivated;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("View is " + (isActivated ? "activated" : "not activated"));
+ }
+ };
+ }
+}
diff --git a/tests/unittests/src/com/android/car/dialer/ui/activecall/RingingCallControllerBarFragmentTest.java b/tests/unittests/src/com/android/car/dialer/ui/activecall/RingingCallControllerBarFragmentTest.java
index a1376b75..5d85b257 100644
--- a/tests/unittests/src/com/android/car/dialer/ui/activecall/RingingCallControllerBarFragmentTest.java
+++ b/tests/unittests/src/com/android/car/dialer/ui/activecall/RingingCallControllerBarFragmentTest.java
@@ -17,12 +17,13 @@
package com.android.car.dialer.ui.activecall;
import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isClickable;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static com.android.car.dialer.testing.TestViewActions.selfClick;
+
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.verify;
@@ -71,25 +72,23 @@ public class RingingCallControllerBarFragmentTest {
@Test
public void testAnswerCallButton() {
onView(withId(R.id.answer_call_button)).check(matches(isDisplayed())).check(
- matches(isClickable())).perform(click());
+ matches(isClickable())).perform(selfClick());
- // TODO: UI overlapping blocks the verification
- // verify(mMockCall).answer(eq(0));
+ verify(mMockCall).answer(eq(0));
}
@Test
public void testAnswerCallText() {
onView(withId(R.id.answer_call_text)).check(matches(isDisplayed())).check(
- matches(isClickable())).perform(click());
+ matches(isClickable())).perform(selfClick());
- // TODO: UI overlapping blocks the verification
- // verify(mMockCall).answer(eq(0));
+ verify(mMockCall).answer(eq(0));
}
@Test
public void testEndCallButton() {
onView(withId(R.id.end_call_button)).check(matches(isDisplayed())).check(
- matches(isClickable())).perform(click());
+ matches(isClickable())).perform(selfClick());
verify(mMockCall).reject(eq(false), isNull());
}
@@ -97,7 +96,7 @@ public class RingingCallControllerBarFragmentTest {
@Test
public void testEndCallText() {
onView(withId(R.id.end_call_text)).check(matches(isDisplayed())).check(
- matches(isClickable())).perform(click());
+ matches(isClickable())).perform(selfClick());
verify(mMockCall).reject(eq(false), isNull());
}