diff options
author | Peter Li <pyli@google.com> | 2021-06-24 22:46:03 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-06-24 22:46:03 +0000 |
commit | ce18a414932f626c709f6a65eb6213f7ad7ab61a (patch) | |
tree | 5751b5c7b008dc1b4f6c9490830be5bc1536adab | |
parent | 5e617fa797e6d93183b9929bca893c348438cde1 (diff) | |
parent | 83553eea43aa6b2974efb2bed0fdb2189f96eb92 (diff) | |
download | Dialer-ce18a414932f626c709f6a65eb6213f7ad7ab61a.tar.gz |
Migrate OngoingCallFragment tests am: 83553eea43
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Car/Dialer/+/15020465
Change-Id: I3e52ce321de8d9fa62e436a580fe708231bc4c23
5 files changed, 163 insertions, 97 deletions
diff --git a/res/drawable/on_hold_background.xml b/res/drawable/on_hold_background.xml new file mode 100644 index 00000000..6a7bf1ab --- /dev/null +++ b/res/drawable/on_hold_background.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ 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. + --> +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + <corners android:radius="@dimen/onhold_profile_corner_radius"/> + <solid android:color="@color/onhold_call_background"/> +</shape> diff --git a/res/layout/onhold_user_profile.xml b/res/layout/onhold_user_profile.xml index 15b2af88..7773a557 100644 --- a/res/layout/onhold_user_profile.xml +++ b/res/layout/onhold_user_profile.xml @@ -16,12 +16,11 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - <androidx.cardview.widget.CardView + <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:elevation="@dimen/dialer_card_elevation" - app:cardBackgroundColor="@color/onhold_call_background" - app:cardCornerRadius="@dimen/onhold_profile_corner_radius"> + android:background="@drawable/on_hold_background"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" @@ -125,6 +124,6 @@ app:layout_constraintEnd_toEndOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> - </androidx.cardview.widget.CardView> + </FrameLayout> </com.android.car.ui.FocusArea> diff --git a/res/values/overlayable.xml b/res/values/overlayable.xml index fcf30bb3..f04baa7f 100644 --- a/res/values/overlayable.xml +++ b/res/values/overlayable.xml @@ -209,6 +209,7 @@ REGENERATE USING packages/apps/Car/tests/tools/rro/generate-overlayable.py <item type="drawable" name="ic_speaker_phone_activatable"/> <item type="drawable" name="icon_call_button"/> <item type="drawable" name="list_divider"/> + <item type="drawable" name="on_hold_background"/> <item type="drawable" name="restricted_dialing_mode_label_background"/> <item type="id" name="address_button"/> <item type="id" name="answer_call_button"/> diff --git a/tests/robotests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java b/tests/robotests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java deleted file mode 100644 index 4c6c0289..00000000 --- a/tests/robotests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2018 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 android.content.Context; -import android.view.View; - -import androidx.fragment.app.Fragment; - -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.telephony.common.InMemoryPhoneBook; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.robolectric.Robolectric; -import org.robolectric.RuntimeEnvironment; - -@RunWith(CarDialerRobolectricTestRunner.class) -public class OngoingCallFragmentTest { - - private OngoingCallFragment mOngoingCallFragment; - private FragmentTestActivity mFragmentTestActivity; - private View mUserProfileContainerView; - private Fragment mInCallDialpadFragment; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - - Context context = RuntimeEnvironment.application; - ((TestDialerApplication) context).setupInCallServiceImpl(); - InMemoryPhoneBook.init(context); - - mOngoingCallFragment = new OngoingCallFragment(); - mFragmentTestActivity = Robolectric.buildActivity( - FragmentTestActivity.class).create().start().resume().get(); - mFragmentTestActivity.setFragment(mOngoingCallFragment); - - mUserProfileContainerView = mOngoingCallFragment.getView().findViewById( - R.id.user_profile_container); - mInCallDialpadFragment = mOngoingCallFragment.getChildFragmentManager().findFragmentById( - R.id.incall_dialpad_fragment); - } - - @After - public void tearDown() { - InMemoryPhoneBook.tearDown(); - } - - @Test - public void testOnCreateView() { - assertThat(mInCallDialpadFragment.isHidden()).isTrue(); - assertThat(mUserProfileContainerView.getVisibility()).isEqualTo(View.VISIBLE); - } - - @Test - public void testOnOpenDialpad() { - mOngoingCallFragment.onOpenDialpad(); - - assertThat(mInCallDialpadFragment.isHidden()).isFalse(); - assertThat(mUserProfileContainerView.getVisibility()).isEqualTo(View.GONE); - } - - @Test - public void testOnCloseDialpad() { - mOngoingCallFragment.onCloseDialpad(); - - assertThat(mInCallDialpadFragment.isHidden()).isTrue(); - assertThat(mUserProfileContainerView.getVisibility()).isEqualTo(View.VISIBLE); - } -} diff --git a/tests/unittests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java b/tests/unittests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java new file mode 100644 index 00000000..947c5b22 --- /dev/null +++ b/tests/unittests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java @@ -0,0 +1,139 @@ +/* + * 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.withEffectiveVisibility; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +import static org.mockito.Mockito.when; + +import android.telecom.Call; +import android.telecom.CallAudioState; + +import androidx.core.util.Pair; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +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.livedata.CallDetailLiveData; +import com.android.car.dialer.testing.TestActivity; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.Collections; + +@RunWith(AndroidJUnit4.class) +public class OngoingCallFragmentTest { + + private OngoingCallFragment mOngoingCallFragment; + private Call mMockCall; + @Mock + private CallAudioState mMockCallAudioState; + private CallDetailLiveData mMockCallDetailLiveData; + private LiveData<Pair<Integer, Long>> mCallStateAndConnectTimeLiveData; + private LiveData<Boolean> mShouldShowOnHoldCall; + + private ActivityScenario<TestActivity> mActivityScenario; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + startFragment(); + } + + @Test + public void testOnCreateView() { + onView(withId(R.id.incall_dialpad_fragment)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); + onView(withId(R.id.user_profile_container)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); + } + + @Test + public void testOnOpenDialpad() { + mActivityScenario.onActivity(activity -> { + mOngoingCallFragment.onOpenDialpad(); + }); + + onView(withId(R.id.incall_dialpad_fragment)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); + onView(withId(R.id.user_profile_container)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); + } + + @Test + public void testOnCloseDialpad() { + mActivityScenario.onActivity(activity -> { + mOngoingCallFragment.onCloseDialpad(); + }); + + onView(withId(R.id.incall_dialpad_fragment)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); + onView(withId(R.id.user_profile_container)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); + } + + private void startFragment() { + mActivityScenario = ActivityScenario.launch(TestActivity.class); + mActivityScenario.onActivity(activity -> { + InCallViewModel mockInCallViewModel = new ViewModelProvider(activity).get( + InCallViewModel.class); + mMockCallDetailLiveData = new CallDetailLiveData(); + mMockCallDetailLiveData.setTelecomCall(mMockCall); + mShouldShowOnHoldCall = new MutableLiveData<>(false); + mCallStateAndConnectTimeLiveData = + new MutableLiveData<>(new Pair<>(Call.STATE_ACTIVE, 1000L)); + when(mockInCallViewModel.getPrimaryCallState()) + .thenReturn(new MutableLiveData<>(Call.STATE_ACTIVE)); + when(mockInCallViewModel.getPrimaryCallDetail()).thenReturn(mMockCallDetailLiveData); + when(mockInCallViewModel.getCallStateAndConnectTime()) + .thenReturn(mCallStateAndConnectTimeLiveData); + when(mockInCallViewModel.shouldShowOnholdCall()).thenReturn(mShouldShowOnHoldCall); + when(mockInCallViewModel.getCallAudioState()) + .thenReturn(new MutableLiveData<>(mMockCallAudioState)); + when(mockInCallViewModel.getAudioRoute()).thenReturn(new MutableLiveData<>(1)); + when(mockInCallViewModel.getSupportedAudioRoutes()) + .thenReturn(new MutableLiveData<>(Collections.EMPTY_LIST)); + when(mockInCallViewModel.getSecondaryCallDetail()).thenReturn(mMockCallDetailLiveData); + when(mockInCallViewModel.getPrimaryCall()).thenReturn(new MutableLiveData<>(mMockCall)); + when(mockInCallViewModel.getSecondaryCallConnectTime()) + .thenReturn(new MutableLiveData<>(1000L)); + when(mockInCallViewModel.getAllCallList()) + .thenReturn(new MutableLiveData<>(Collections.EMPTY_LIST)); + when(mockInCallViewModel.getOngoingCallPair()) + .thenReturn(new MutableLiveData<>(new Pair<>(mMockCall, mMockCall))); + when(mockInCallViewModel.getOngoingCallList()) + .thenReturn(new MutableLiveData<>(Collections.EMPTY_LIST)); + when(mockInCallViewModel.getDialpadOpenState()) + .thenReturn(new MutableLiveData<>(false)); + + mOngoingCallFragment = new OngoingCallFragment(); + activity.getSupportFragmentManager().beginTransaction().add( + R.id.test_fragment_container, mOngoingCallFragment).commit(); + }); + } +} |