Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferActivityTest.java +181 −193 Original line number Diff line number Diff line Loading @@ -17,10 +17,6 @@ package com.android.bluetooth.opp; import static android.content.pm.PackageManager.DONT_KILL_APP; import static android.service.pm.PackageProto.UserInfoProto.COMPONENT_ENABLED_STATE_DEFAULT; import static android.service.pm.PackageProto.UserInfoProto.COMPONENT_ENABLED_STATE_ENABLED; import static com.android.bluetooth.opp.BluetoothOppTestUtils.CursorMockData; import static com.android.bluetooth.opp.BluetoothOppTransferActivity.DIALOG_RECEIVE_COMPLETE_FAIL; import static com.android.bluetooth.opp.BluetoothOppTransferActivity.DIALOG_RECEIVE_COMPLETE_SUCCESS; Loading @@ -35,19 +31,16 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.test.ActivityInstrumentationTestCase2; import androidx.test.core.app.ActivityScenario; import androidx.test.filters.MediumTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import com.android.bluetooth.pbap.BluetoothPbapActivity; import org.junit.After; import org.junit.Before; Loading @@ -61,9 +54,9 @@ import org.mockito.Spy; import java.util.ArrayList; import java.util.List; @MediumTest @RunWith(AndroidJUnit4.class) public class BluetoothOppTransferActivityTest { public class BluetoothOppTransferActivityTest extends ActivityInstrumentationTestCase2<BluetoothOppTransferActivity> { @Mock Cursor mCursor; @Spy Loading @@ -74,6 +67,10 @@ public class BluetoothOppTransferActivityTest { Intent mIntent; Context mTargetContext; public BluetoothOppTransferActivityTest() { super(BluetoothOppTransferActivity.class); } @Before public void setUp() { MockitoAnnotations.initMocks(this); Loading @@ -81,7 +78,7 @@ public class BluetoothOppTransferActivityTest { BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy); Uri dataUrl = Uri.parse("content://com.android.bluetooth.opp.test/random"); injectInstrumentation(InstrumentationRegistry.getInstrumentation()); mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); mIntent = new Intent(); Loading Loading @@ -111,14 +108,13 @@ public class BluetoothOppTransferActivityTest { new CursorMockData(BluetoothShare.USER_CONFIRMATION, 11, BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED) )); enableActivity(true); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); } @After public void tearDown() { BluetoothMethodProxy.setInstanceForTesting(null); enableActivity(false); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Test Loading @@ -132,12 +128,11 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 0)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); activityScenario.onActivity(activity -> { InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_ONGOING); }); } @Test Loading @@ -153,12 +148,12 @@ public class BluetoothOppTransferActivityTest { new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 100)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); activityScenario.onActivity(activity -> { assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_COMPLETE_SUCCESS); }); } @Test Loading @@ -172,11 +167,12 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 42)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); activityScenario.onActivity( activity -> assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_COMPLETE_FAIL)); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_COMPLETE_FAIL); } @Test Loading @@ -190,11 +186,12 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 0)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); activityScenario.onActivity( activity -> assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_ONGOING)); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_ONGOING); } @Test Loading @@ -210,11 +207,13 @@ public class BluetoothOppTransferActivityTest { ); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); activityScenario.onActivity(activity -> assertThat(activity.mWhichDialog).isEqualTo( DIALOG_RECEIVE_COMPLETE_SUCCESS)); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_COMPLETE_SUCCESS); } @Test Loading @@ -228,23 +227,12 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 42)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); activityScenario.onActivity(activity -> assertThat(activity.mWhichDialog).isEqualTo( DIALOG_RECEIVE_COMPLETE_FAIL)); } private void enableActivity(boolean enable) { int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DEFAULT; setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); mTargetContext.getPackageManager().setApplicationEnabledSetting( mTargetContext.getPackageName(), enabledState, DONT_KILL_APP); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); ComponentName activityName = new ComponentName(mTargetContext, BluetoothOppTransferActivity.class); mTargetContext.getPackageManager().setComponentEnabledSetting( activityName, enabledState, DONT_KILL_APP); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_COMPLETE_FAIL); } } Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferActivityTest.java +181 −193 Original line number Diff line number Diff line Loading @@ -17,10 +17,6 @@ package com.android.bluetooth.opp; import static android.content.pm.PackageManager.DONT_KILL_APP; import static android.service.pm.PackageProto.UserInfoProto.COMPONENT_ENABLED_STATE_DEFAULT; import static android.service.pm.PackageProto.UserInfoProto.COMPONENT_ENABLED_STATE_ENABLED; import static com.android.bluetooth.opp.BluetoothOppTestUtils.CursorMockData; import static com.android.bluetooth.opp.BluetoothOppTransferActivity.DIALOG_RECEIVE_COMPLETE_FAIL; import static com.android.bluetooth.opp.BluetoothOppTransferActivity.DIALOG_RECEIVE_COMPLETE_SUCCESS; Loading @@ -35,19 +31,16 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.test.ActivityInstrumentationTestCase2; import androidx.test.core.app.ActivityScenario; import androidx.test.filters.MediumTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import com.android.bluetooth.pbap.BluetoothPbapActivity; import org.junit.After; import org.junit.Before; Loading @@ -61,9 +54,9 @@ import org.mockito.Spy; import java.util.ArrayList; import java.util.List; @MediumTest @RunWith(AndroidJUnit4.class) public class BluetoothOppTransferActivityTest { public class BluetoothOppTransferActivityTest extends ActivityInstrumentationTestCase2<BluetoothOppTransferActivity> { @Mock Cursor mCursor; @Spy Loading @@ -74,6 +67,10 @@ public class BluetoothOppTransferActivityTest { Intent mIntent; Context mTargetContext; public BluetoothOppTransferActivityTest() { super(BluetoothOppTransferActivity.class); } @Before public void setUp() { MockitoAnnotations.initMocks(this); Loading @@ -81,7 +78,7 @@ public class BluetoothOppTransferActivityTest { BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy); Uri dataUrl = Uri.parse("content://com.android.bluetooth.opp.test/random"); injectInstrumentation(InstrumentationRegistry.getInstrumentation()); mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); mIntent = new Intent(); Loading Loading @@ -111,14 +108,13 @@ public class BluetoothOppTransferActivityTest { new CursorMockData(BluetoothShare.USER_CONFIRMATION, 11, BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED) )); enableActivity(true); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); } @After public void tearDown() { BluetoothMethodProxy.setInstanceForTesting(null); enableActivity(false); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Test Loading @@ -132,12 +128,11 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 0)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); activityScenario.onActivity(activity -> { InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_ONGOING); }); } @Test Loading @@ -153,12 +148,12 @@ public class BluetoothOppTransferActivityTest { new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 100)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); activityScenario.onActivity(activity -> { assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_COMPLETE_SUCCESS); }); } @Test Loading @@ -172,11 +167,12 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 42)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); activityScenario.onActivity( activity -> assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_COMPLETE_FAIL)); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_SEND_COMPLETE_FAIL); } @Test Loading @@ -190,11 +186,12 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 0)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); activityScenario.onActivity( activity -> assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_ONGOING)); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_ONGOING); } @Test Loading @@ -210,11 +207,13 @@ public class BluetoothOppTransferActivityTest { ); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); activityScenario.onActivity(activity -> assertThat(activity.mWhichDialog).isEqualTo( DIALOG_RECEIVE_COMPLETE_SUCCESS)); setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_COMPLETE_SUCCESS); } @Test Loading @@ -228,23 +227,12 @@ public class BluetoothOppTransferActivityTest { mCursorMockDataList.add(new CursorMockData(BluetoothShare.CURRENT_BYTES, 4, 42)); BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList); ActivityScenario<BluetoothOppTransferActivity> activityScenario = ActivityScenario.launch( mIntent); activityScenario.onActivity(activity -> assertThat(activity.mWhichDialog).isEqualTo( DIALOG_RECEIVE_COMPLETE_FAIL)); } private void enableActivity(boolean enable) { int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DEFAULT; setActivityIntent(mIntent); BluetoothOppTransferActivity activity = getActivity(); mTargetContext.getPackageManager().setApplicationEnabledSetting( mTargetContext.getPackageName(), enabledState, DONT_KILL_APP); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); ComponentName activityName = new ComponentName(mTargetContext, BluetoothOppTransferActivity.class); mTargetContext.getPackageManager().setComponentEnabledSetting( activityName, enabledState, DONT_KILL_APP); assertThat(activity.mWhichDialog).isEqualTo(DIALOG_RECEIVE_COMPLETE_FAIL); } }