Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -61,7 +61,6 @@ public class BluetoothOppBtEnableActivityTest { mIntent = new Intent(); mIntent.setClass(mTargetContext, BluetoothOppBtEnableActivity.class); Intents.init(); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); TestUtils.setUpUiTest(); } Loading @@ -69,7 +68,6 @@ public class BluetoothOppBtEnableActivityTest { public void tearDown() throws Exception { TestUtils.tearDownUiTest(); Intents.release(); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Test Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -80,7 +80,6 @@ public class BluetoothOppBtEnablingActivityTest { mIntent.setClass(mTargetContext, BluetoothOppBtEnablingActivity.class); mRealTimeoutValue = BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs; BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); TestUtils.setUpUiTest(); } Loading @@ -89,7 +88,6 @@ public class BluetoothOppBtEnablingActivityTest { TestUtils.tearDownUiTest(); BluetoothMethodProxy.setInstanceForTesting(null); BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs = mRealTimeoutValue; BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Ignore("b/277594572") Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ public class BluetoothOppLauncherActivityTest { mIntent = new Intent(); mIntent.setClass(mTargetContext, BluetoothOppLauncherActivity.class); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); TestUtils.setUpUiTest(); BluetoothOppManager.setInstance(mBluetoothOppManager); Loading @@ -100,7 +99,6 @@ public class BluetoothOppLauncherActivityTest { BluetoothMethodProxy.setInstanceForTesting(null); BluetoothOppManager.setInstance(null); Intents.release(); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Test Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java +62 −31 Original line number Diff line number Diff line Loading @@ -90,8 +90,6 @@ public class BluetoothOppReceiverTest { mReceiver = new BluetoothOppReceiver(); Intents.init(); BluetoothOppTestUtils.enableOppActivities(true, mContext); TestUtils.setUpUiTest(); } Loading @@ -114,24 +112,41 @@ public class BluetoothOppReceiverTest { Intent intent = new Intent(); intent.setAction(BluetoothDevicePicker.ACTION_DEVICE_SELECTED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); ActivityScenario<BluetoothOppBtEnableActivity> activityScenario = ActivityScenario.launch(BluetoothOppBtEnableActivity.class); activityScenario.onActivity(activity -> { try { BluetoothOppTestUtils.enableActivity( BluetoothOppBtEnableActivity.class, true, mContext); ActivityScenario<BluetoothOppBtEnableActivity> activityScenario = ActivityScenario.launch(BluetoothOppBtEnableActivity.class); activityScenario.onActivity( activity -> { mReceiver.onReceive(mContext, intent); }); doNothing().when(bluetoothOppManager).startTransfer(eq(device)); verify(bluetoothOppManager).startTransfer(eq(device)); BluetoothOppManager.setInstance(null); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppBtEnableActivity.class, false, mContext); } } @Test public void onReceive_withActionIncomingFileConfirm_startsIncomingFileConfirmActivity() { mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION); try { BluetoothOppTestUtils.enableActivity( BluetoothOppIncomingFileConfirmActivity.class, true, mContext); Intent intent = new Intent(); intent.setAction(Constants.ACTION_INCOMING_FILE_CONFIRM); intent.setData(Uri.parse("content:///not/important")); mReceiver.onReceive(mContext, intent); intended(hasComponent(BluetoothOppIncomingFileConfirmActivity.class.getName())); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppIncomingFileConfirmActivity.class, false, mContext); } } @Test Loading Loading @@ -161,28 +176,44 @@ public class BluetoothOppReceiverTest { @Test public void onReceive_withActionOutboundTransfer_startsTransferHistoryActivity() { mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION); try { BluetoothOppTestUtils.enableActivity(BluetoothOppTransferHistory.class, true, mContext); Intent intent = new Intent(); intent.setAction(Constants.ACTION_OPEN_OUTBOUND_TRANSFER); intent.setData(Uri.parse("content:///not/important")); intending(anyIntent()).respondWith( intending(anyIntent()) .respondWith( new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent())); mReceiver.onReceive(mContext, intent); intended(hasComponent(BluetoothOppTransferHistory.class.getName())); intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND)); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppTransferHistory.class, false, mContext); } } @Test public void onReceive_withActionInboundTransfer_startsTransferHistoryActivity() { mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION); try { BluetoothOppTestUtils.enableActivity(BluetoothOppTransferHistory.class, true, mContext); Intent intent = new Intent(); intent.setAction(Constants.ACTION_OPEN_INBOUND_TRANSFER); intent.setData(Uri.parse("content:///not/important")); intending(anyIntent()).respondWith( intending(anyIntent()) .respondWith( new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent())); mReceiver.onReceive(mContext, intent); intended(hasComponent(BluetoothOppTransferHistory.class.getName())); intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND)); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppTransferHistory.class, false, mContext); } } @Test Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTestUtils.java +15 −26 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.database.Cursor; import org.mockito.internal.util.MockUtil; import java.util.Arrays; import java.util.List; import java.util.Objects; Loading Loading @@ -115,35 +114,25 @@ public class BluetoothOppTestUtils { } /** * Enable/Disable all activities in Opp for testing * Enable/Disable an activity for testing * * @param activityClass the activity class to enable/disable * @param enable true to enable, false to disable * @param mTargetContext target context */ public static void enableOppActivities(boolean enable, Context mTargetContext) { int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DEFAULT; public static void enableActivity(Class activityClass, boolean enable, Context mTargetContext) { int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DEFAULT; mTargetContext.getPackageManager().setApplicationEnabledSetting( mTargetContext .getPackageManager() .setApplicationEnabledSetting( mTargetContext.getPackageName(), enabledState, DONT_KILL_APP); // All activities to be test Class[] activities = { BluetoothOppTransferActivity.class, BluetoothOppBtEnableActivity.class, BluetoothOppBtEnablingActivity.class, BluetoothOppBtErrorActivity.class, BluetoothOppIncomingFileConfirmActivity.class, BluetoothOppTransferHistory.class, BluetoothOppLauncherActivity.class, }; Arrays.stream(activities).forEach(activityClass -> { ComponentName activityName = new ComponentName(mTargetContext, activityClass); mTargetContext.getPackageManager().setComponentEnabledSetting( activityName, enabledState, DONT_KILL_APP); }); mTargetContext .getPackageManager() .setComponentEnabledSetting(activityName, enabledState, DONT_KILL_APP); } } Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivityTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -61,7 +61,6 @@ public class BluetoothOppBtEnableActivityTest { mIntent = new Intent(); mIntent.setClass(mTargetContext, BluetoothOppBtEnableActivity.class); Intents.init(); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); TestUtils.setUpUiTest(); } Loading @@ -69,7 +68,6 @@ public class BluetoothOppBtEnableActivityTest { public void tearDown() throws Exception { TestUtils.tearDownUiTest(); Intents.release(); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Test Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -80,7 +80,6 @@ public class BluetoothOppBtEnablingActivityTest { mIntent.setClass(mTargetContext, BluetoothOppBtEnablingActivity.class); mRealTimeoutValue = BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs; BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); TestUtils.setUpUiTest(); } Loading @@ -89,7 +88,6 @@ public class BluetoothOppBtEnablingActivityTest { TestUtils.tearDownUiTest(); BluetoothMethodProxy.setInstanceForTesting(null); BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs = mRealTimeoutValue; BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Ignore("b/277594572") Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ public class BluetoothOppLauncherActivityTest { mIntent = new Intent(); mIntent.setClass(mTargetContext, BluetoothOppLauncherActivity.class); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); TestUtils.setUpUiTest(); BluetoothOppManager.setInstance(mBluetoothOppManager); Loading @@ -100,7 +99,6 @@ public class BluetoothOppLauncherActivityTest { BluetoothMethodProxy.setInstanceForTesting(null); BluetoothOppManager.setInstance(null); Intents.release(); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } @Test Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java +62 −31 Original line number Diff line number Diff line Loading @@ -90,8 +90,6 @@ public class BluetoothOppReceiverTest { mReceiver = new BluetoothOppReceiver(); Intents.init(); BluetoothOppTestUtils.enableOppActivities(true, mContext); TestUtils.setUpUiTest(); } Loading @@ -114,24 +112,41 @@ public class BluetoothOppReceiverTest { Intent intent = new Intent(); intent.setAction(BluetoothDevicePicker.ACTION_DEVICE_SELECTED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); ActivityScenario<BluetoothOppBtEnableActivity> activityScenario = ActivityScenario.launch(BluetoothOppBtEnableActivity.class); activityScenario.onActivity(activity -> { try { BluetoothOppTestUtils.enableActivity( BluetoothOppBtEnableActivity.class, true, mContext); ActivityScenario<BluetoothOppBtEnableActivity> activityScenario = ActivityScenario.launch(BluetoothOppBtEnableActivity.class); activityScenario.onActivity( activity -> { mReceiver.onReceive(mContext, intent); }); doNothing().when(bluetoothOppManager).startTransfer(eq(device)); verify(bluetoothOppManager).startTransfer(eq(device)); BluetoothOppManager.setInstance(null); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppBtEnableActivity.class, false, mContext); } } @Test public void onReceive_withActionIncomingFileConfirm_startsIncomingFileConfirmActivity() { mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION); try { BluetoothOppTestUtils.enableActivity( BluetoothOppIncomingFileConfirmActivity.class, true, mContext); Intent intent = new Intent(); intent.setAction(Constants.ACTION_INCOMING_FILE_CONFIRM); intent.setData(Uri.parse("content:///not/important")); mReceiver.onReceive(mContext, intent); intended(hasComponent(BluetoothOppIncomingFileConfirmActivity.class.getName())); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppIncomingFileConfirmActivity.class, false, mContext); } } @Test Loading Loading @@ -161,28 +176,44 @@ public class BluetoothOppReceiverTest { @Test public void onReceive_withActionOutboundTransfer_startsTransferHistoryActivity() { mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION); try { BluetoothOppTestUtils.enableActivity(BluetoothOppTransferHistory.class, true, mContext); Intent intent = new Intent(); intent.setAction(Constants.ACTION_OPEN_OUTBOUND_TRANSFER); intent.setData(Uri.parse("content:///not/important")); intending(anyIntent()).respondWith( intending(anyIntent()) .respondWith( new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent())); mReceiver.onReceive(mContext, intent); intended(hasComponent(BluetoothOppTransferHistory.class.getName())); intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND)); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppTransferHistory.class, false, mContext); } } @Test public void onReceive_withActionInboundTransfer_startsTransferHistoryActivity() { mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION); try { BluetoothOppTestUtils.enableActivity(BluetoothOppTransferHistory.class, true, mContext); Intent intent = new Intent(); intent.setAction(Constants.ACTION_OPEN_INBOUND_TRANSFER); intent.setData(Uri.parse("content:///not/important")); intending(anyIntent()).respondWith( intending(anyIntent()) .respondWith( new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent())); mReceiver.onReceive(mContext, intent); intended(hasComponent(BluetoothOppTransferHistory.class.getName())); intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND)); } finally { BluetoothOppTestUtils.enableActivity( BluetoothOppTransferHistory.class, false, mContext); } } @Test Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTestUtils.java +15 −26 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import android.database.Cursor; import org.mockito.internal.util.MockUtil; import java.util.Arrays; import java.util.List; import java.util.Objects; Loading Loading @@ -115,35 +114,25 @@ public class BluetoothOppTestUtils { } /** * Enable/Disable all activities in Opp for testing * Enable/Disable an activity for testing * * @param activityClass the activity class to enable/disable * @param enable true to enable, false to disable * @param mTargetContext target context */ public static void enableOppActivities(boolean enable, Context mTargetContext) { int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DEFAULT; public static void enableActivity(Class activityClass, boolean enable, Context mTargetContext) { int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DEFAULT; mTargetContext.getPackageManager().setApplicationEnabledSetting( mTargetContext .getPackageManager() .setApplicationEnabledSetting( mTargetContext.getPackageName(), enabledState, DONT_KILL_APP); // All activities to be test Class[] activities = { BluetoothOppTransferActivity.class, BluetoothOppBtEnableActivity.class, BluetoothOppBtEnablingActivity.class, BluetoothOppBtErrorActivity.class, BluetoothOppIncomingFileConfirmActivity.class, BluetoothOppTransferHistory.class, BluetoothOppLauncherActivity.class, }; Arrays.stream(activities).forEach(activityClass -> { ComponentName activityName = new ComponentName(mTargetContext, activityClass); mTargetContext.getPackageManager().setComponentEnabledSetting( activityName, enabledState, DONT_KILL_APP); }); mTargetContext .getPackageManager() .setComponentEnabledSetting(activityName, enabledState, DONT_KILL_APP); } }