Loading android/app/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java +2 −1 Original line number Diff line number Diff line Loading @@ -139,7 +139,8 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity { } }; private final BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() { @VisibleForTesting final BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Loading android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +2 −1 Original line number Diff line number Diff line Loading @@ -413,7 +413,8 @@ public class BluetoothOppLauncherActivity extends Activity { return text; } private void sendFileInfo(String mimeType, String uriString, boolean isHandover, @VisibleForTesting void sendFileInfo(String mimeType, String uriString, boolean isHandover, boolean fromExternal) { BluetoothOppManager manager = BluetoothOppManager.getInstance(getApplicationContext()); try { Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +14 −7 Original line number Diff line number Diff line Loading @@ -22,20 +22,15 @@ import static android.content.pm.PackageManager.DONT_KILL_APP; import static androidx.lifecycle.Lifecycle.State.DESTROYED; import static com.android.bluetooth.opp.BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import android.bluetooth.BluetoothAdapter; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Looper; import android.view.KeyEvent; import androidx.lifecycle.Lifecycle; Loading @@ -44,7 +39,6 @@ import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import com.android.bluetooth.TestUtils; import org.junit.After; import org.junit.Before; Loading Loading @@ -129,6 +123,19 @@ public class BluetoothOppBtEnablingActivityTest { assertActivityState(activityScenario, DESTROYED); } @Test public void broadcastReceiver_onReceive_finishImmediately() throws Exception { doReturn(false).when(mBluetoothMethodProxy).bluetoothAdapterIsEnabled(any()); ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( mIntent); activityScenario.onActivity(activity -> { Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON); activity.mBluetoothReceiver.onReceive(mTargetContext, intent); }); assertActivityState(activityScenario, DESTROYED); } private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) throws Exception { // TODO: Change this into an event driven systems Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java +23 −2 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; Loading @@ -59,6 +60,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.File; Loading @@ -71,6 +73,8 @@ public class BluetoothOppLauncherActivityTest { Intent mIntent; BluetoothMethodProxy mMethodProxy; @Mock BluetoothOppManager mBluetoothOppManager; @Before public void setUp() { Loading @@ -84,12 +88,14 @@ public class BluetoothOppLauncherActivityTest { mIntent.setClass(mTargetContext, BluetoothOppLauncherActivity.class); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); BluetoothOppManager.setInstance(mBluetoothOppManager); Intents.init(); } @After public void tearDown() { BluetoothMethodProxy.setInstanceForTesting(null); BluetoothOppManager.setInstance(null); Intents.release(); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } Loading Loading @@ -166,8 +172,8 @@ public class BluetoothOppLauncherActivityTest { final Uri[] fileUri = new Uri[1]; final String shareContent = "a string to trigger pattern match with url: www.google.com, phone number: " + "+821023456798, and email: abc@test.com"; "\na < b & c > a string to trigger pattern match with url: \r" + "www.google.com, phone number: +821023456798, and email: abc@test.com"; scenario.onActivity(activity -> { fileUri[0] = activity.createFileForSharedContent(activity, shareContent); Loading @@ -179,6 +185,21 @@ public class BluetoothOppLauncherActivityTest { assertThat(file.length()).isGreaterThan(shareContent.length()); } @Test public void sendFileInfo_finishImmediately() throws Exception { doReturn(true).when(mMethodProxy).bluetoothAdapterIsEnabled(any()); // Unsupported action, the activity will stay without being finished right the way mIntent.setAction("unsupported-action"); ActivityScenario<BluetoothOppLauncherActivity> scenario = ActivityScenario.launch(mIntent); doThrow(new IllegalArgumentException()).when(mBluetoothOppManager).saveSendingFileInfo( any(), any(String.class), any(), any()); scenario.onActivity(activity -> { activity.sendFileInfo("text/plain", "content:///abc.txt", false, false); }); assertActivityState(scenario, Lifecycle.State.DESTROYED); } private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) throws Exception { Thread.sleep(2_000); Loading Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java +2 −1 Original line number Diff line number Diff line Loading @@ -139,7 +139,8 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity { } }; private final BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() { @VisibleForTesting final BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +2 −1 Original line number Diff line number Diff line Loading @@ -413,7 +413,8 @@ public class BluetoothOppLauncherActivity extends Activity { return text; } private void sendFileInfo(String mimeType, String uriString, boolean isHandover, @VisibleForTesting void sendFileInfo(String mimeType, String uriString, boolean isHandover, boolean fromExternal) { BluetoothOppManager manager = BluetoothOppManager.getInstance(getApplicationContext()); try { Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivityTest.java +14 −7 Original line number Diff line number Diff line Loading @@ -22,20 +22,15 @@ import static android.content.pm.PackageManager.DONT_KILL_APP; import static androidx.lifecycle.Lifecycle.State.DESTROYED; import static com.android.bluetooth.opp.BluetoothOppBtEnablingActivity.sBtEnablingTimeoutMs; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import android.bluetooth.BluetoothAdapter; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Looper; import android.view.KeyEvent; import androidx.lifecycle.Lifecycle; Loading @@ -44,7 +39,6 @@ import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import com.android.bluetooth.TestUtils; import org.junit.After; import org.junit.Before; Loading Loading @@ -129,6 +123,19 @@ public class BluetoothOppBtEnablingActivityTest { assertActivityState(activityScenario, DESTROYED); } @Test public void broadcastReceiver_onReceive_finishImmediately() throws Exception { doReturn(false).when(mBluetoothMethodProxy).bluetoothAdapterIsEnabled(any()); ActivityScenario<BluetoothOppBtEnablingActivity> activityScenario = ActivityScenario.launch( mIntent); activityScenario.onActivity(activity -> { Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED); intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_ON); activity.mBluetoothReceiver.onReceive(mTargetContext, intent); }); assertActivityState(activityScenario, DESTROYED); } private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) throws Exception { // TODO: Change this into an event driven systems Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppLauncherActivityTest.java +23 −2 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; Loading @@ -59,6 +60,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.File; Loading @@ -71,6 +73,8 @@ public class BluetoothOppLauncherActivityTest { Intent mIntent; BluetoothMethodProxy mMethodProxy; @Mock BluetoothOppManager mBluetoothOppManager; @Before public void setUp() { Loading @@ -84,12 +88,14 @@ public class BluetoothOppLauncherActivityTest { mIntent.setClass(mTargetContext, BluetoothOppLauncherActivity.class); BluetoothOppTestUtils.enableOppActivities(true, mTargetContext); BluetoothOppManager.setInstance(mBluetoothOppManager); Intents.init(); } @After public void tearDown() { BluetoothMethodProxy.setInstanceForTesting(null); BluetoothOppManager.setInstance(null); Intents.release(); BluetoothOppTestUtils.enableOppActivities(false, mTargetContext); } Loading Loading @@ -166,8 +172,8 @@ public class BluetoothOppLauncherActivityTest { final Uri[] fileUri = new Uri[1]; final String shareContent = "a string to trigger pattern match with url: www.google.com, phone number: " + "+821023456798, and email: abc@test.com"; "\na < b & c > a string to trigger pattern match with url: \r" + "www.google.com, phone number: +821023456798, and email: abc@test.com"; scenario.onActivity(activity -> { fileUri[0] = activity.createFileForSharedContent(activity, shareContent); Loading @@ -179,6 +185,21 @@ public class BluetoothOppLauncherActivityTest { assertThat(file.length()).isGreaterThan(shareContent.length()); } @Test public void sendFileInfo_finishImmediately() throws Exception { doReturn(true).when(mMethodProxy).bluetoothAdapterIsEnabled(any()); // Unsupported action, the activity will stay without being finished right the way mIntent.setAction("unsupported-action"); ActivityScenario<BluetoothOppLauncherActivity> scenario = ActivityScenario.launch(mIntent); doThrow(new IllegalArgumentException()).when(mBluetoothOppManager).saveSendingFileInfo( any(), any(String.class), any(), any()); scenario.onActivity(activity -> { activity.sendFileInfo("text/plain", "content:///abc.txt", false, false); }); assertActivityState(scenario, Lifecycle.State.DESTROYED); } private void assertActivityState(ActivityScenario activityScenario, Lifecycle.State state) throws Exception { Thread.sleep(2_000); Loading