diff options
author | Yiqun Wu <yiqunw@google.com> | 2021-05-25 03:17:09 -0700 |
---|---|---|
committer | Yiqun Wu <yiqunw@google.com> | 2021-06-01 19:30:36 -0700 |
commit | aa1dac43c8f9f6df053fd304b7c33f50f9f4a35a (patch) | |
tree | b52d2e063bbea8889a4e3ecec9387a9f1c3db438 | |
parent | 34eb7405f314fe033c7bf5bdce97392e896058b6 (diff) | |
download | Dialer-aa1dac43c8f9f6df053fd304b7c33f50f9f4a35a.tar.gz |
Test bluetooth error page
Delete robolectric tests for the NoHfpFragment.
Test 3 usecases:
1. Bluetooth is disabled
2. Bluetooth is enabled but there is no paired devices
3. Clicking on the connect bluetooth button navigates to bluetooth
settings
Bug: 187461550
Test: atest CarDialerInstruTests
Change-Id: If1f1ec475deef38d0681b53a2e85a46695cd3482
4 files changed, 111 insertions, 67 deletions
diff --git a/framework/fake/src/com/android/car/dialer/framework/FakeHfpManager.java b/framework/fake/src/com/android/car/dialer/framework/FakeHfpManager.java index 1e4c992f..22ec8701 100644 --- a/framework/fake/src/com/android/car/dialer/framework/FakeHfpManager.java +++ b/framework/fake/src/com/android/car/dialer/framework/FakeHfpManager.java @@ -18,7 +18,6 @@ package com.android.car.dialer.framework; import android.bluetooth.BluetoothDevice; -import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import com.android.car.dialer.framework.testdata.CallLogDataHandler; @@ -44,8 +43,8 @@ public class FakeHfpManager { private Map<String, SimulatedBluetoothDevice> mDeviceMap = new HashMap<>(); private List<BluetoothDevice> mDeviceList; - private LiveData<Integer> mBluetoothStateLiveData; - private LiveData<Set<BluetoothDevice>> mBluetoothPairListLiveData; + private MutableLiveData<Integer> mBluetoothStateLiveData; + private MutableLiveData<Set<BluetoothDevice>> mBluetoothPairListLiveData; private MutableLiveData<List<BluetoothDevice>> mHfpDeviceListLiveData; private final CallLogDataHandler mCallLogDataHandler; @@ -93,15 +92,15 @@ public class FakeHfpManager { return simulatedBluetoothDevice; } - public LiveData<Integer> getBluetoothStateLiveData() { + public MutableLiveData<Integer> getBluetoothStateLiveData() { return mBluetoothStateLiveData; } - public LiveData<Set<BluetoothDevice>> getBluetoothPairListLiveData() { + public MutableLiveData<Set<BluetoothDevice>> getBluetoothPairListLiveData() { return mBluetoothPairListLiveData; } - public LiveData<List<BluetoothDevice>> getHfpDeviceListLiveData() { + public MutableLiveData<List<BluetoothDevice>> getHfpDeviceListLiveData() { return mHfpDeviceListLiveData; } } diff --git a/tests/instrutests/Android.bp b/tests/instrutests/Android.bp index bc005ed2..8221e7d4 100644 --- a/tests/instrutests/Android.bp +++ b/tests/instrutests/Android.bp @@ -20,6 +20,7 @@ android_test { "androidx.test.rules", "androidx.test.espresso.core", "androidx.test.espresso.contrib", + "androidx.test.espresso.intents", "hilt_android_testing", "mockito-target-extended", ], diff --git a/tests/instrutests/src/com/android/car/dialer/integration/NoHfpFragmentTest.java b/tests/instrutests/src/com/android/car/dialer/integration/NoHfpFragmentTest.java new file mode 100644 index 00000000..435149a6 --- /dev/null +++ b/tests/instrutests/src/com/android/car/dialer/integration/NoHfpFragmentTest.java @@ -0,0 +1,105 @@ +/* + * 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.integration; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.swipeLeft; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.intent.Intents.intended; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasCategories; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +import static org.hamcrest.Matchers.allOf; + +import android.content.Context; +import android.content.Intent; + +import androidx.test.core.app.ActivityScenario; +import androidx.test.espresso.intent.Intents; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import com.android.car.dialer.R; +import com.android.car.dialer.bluetooth.BluetoothState; +import com.android.car.dialer.framework.FakeHfpManager; +import com.android.car.dialer.ui.TelecomActivity; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Collections; + +import javax.inject.Inject; + +import dagger.hilt.android.testing.HiltAndroidRule; +import dagger.hilt.android.testing.HiltAndroidTest; + +@RunWith(AndroidJUnit4.class) +@HiltAndroidTest +public class NoHfpFragmentTest { + + // Consistent with the constants defined in NoHfpFragment. + private static final String Bluetooth_Setting_ACTION = "android.settings.BLUETOOTH_SETTINGS"; + private static final String Bluetooth_Setting_CATEGORY = "android.intent.category.DEFAULT"; + + @Rule + public final HiltAndroidRule mHiltAndroidRule = new HiltAndroidRule(this); + + @Inject FakeHfpManager mFakeHfpManager; + + @Before + public void setup() { + mHiltAndroidRule.inject(); + + Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); + ActivityScenario.launch(new Intent(context, TelecomActivity.class)); + } + + @Test + public void bluetoothDisabled_displayErrorMsg() { + mFakeHfpManager.getBluetoothStateLiveData().postValue(BluetoothState.DISABLED); + + onView(withId(R.id.error_string)).check( + matches(allOf(isDisplayed(), withText(R.string.bluetooth_disabled)))); + } + + @Test + public void noPairedDevices_displayErrorMsg() { + mFakeHfpManager.getBluetoothStateLiveData().postValue(BluetoothState.ENABLED); + mFakeHfpManager.getBluetoothPairListLiveData().postValue(Collections.EMPTY_SET); + + onView(withId(R.id.error_string)).check( + matches(allOf(isDisplayed(), withText(R.string.bluetooth_unpaired)))); + } + + @Test + public void clickButton_navigateToBluetoothSettings() { + onView(withId(R.id.connect_bluetooth_button)).check(matches(isDisplayed())); + + Intents.init(); + // Use swipe action to perform the click action since the UI messes up and overlaps with + // each other. + onView(withId(R.id.connect_bluetooth_button)).perform(swipeLeft()); + intended(allOf(hasAction(Bluetooth_Setting_ACTION), + hasCategories(Collections.singleton(Bluetooth_Setting_CATEGORY)))); + Intents.release(); + } +} diff --git a/tests/robotests/src/com/android/car/dialer/ui/warning/NoHfpFragmentTest.java b/tests/robotests/src/com/android/car/dialer/ui/warning/NoHfpFragmentTest.java deleted file mode 100644 index 7e2657b0..00000000 --- a/tests/robotests/src/com/android/car/dialer/ui/warning/NoHfpFragmentTest.java +++ /dev/null @@ -1,61 +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.warning; - -import static com.google.common.truth.Truth.assertThat; - -import android.view.View; -import android.widget.TextView; - -import com.android.car.dialer.CarDialerRobolectricTestRunner; -import com.android.car.dialer.FragmentTestActivity; -import com.android.car.dialer.R; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.robolectric.Robolectric; - -@RunWith(CarDialerRobolectricTestRunner.class) -public class NoHfpFragmentTest { - - private NoHfpFragment mNoHfpFragment; - private FragmentTestActivity mFragmentTestActivity; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - - mNoHfpFragment = new NoHfpFragment(); - mFragmentTestActivity = Robolectric.buildActivity( - FragmentTestActivity.class).create().start().resume().get(); - mFragmentTestActivity.setFragment(mNoHfpFragment); - } - - @Test - public void createView_notNull() { - assertThat(mNoHfpFragment.getView()).isNotNull(); - } - - @Test - public void createView_displayErrorMsg() { - View rootView = mNoHfpFragment.getView(); - TextView errorMsgView = rootView.findViewById(R.id.error_string); - assertThat(errorMsgView.getText()).isEqualTo( - mNoHfpFragment.getString(R.string.bluetooth_disabled)); - } -} |