Skip to content

Commit c067ae4

Browse files
committed
Test reproducing delay on a network request
We mock fail the network request to reproduce the issue where the app does not get foregrounded.
1 parent 1c3e69e commit c067ae4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

OneSignalSDK/unittest/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,25 @@ public void testOpeningLauncherActivity() throws Exception {
10771077
assertNull(shadowOf(blankActivity).getNextStartedActivity());
10781078
}
10791079

1080+
@Test
1081+
public void testOpeningLauncherActivityWhenOffline() throws Exception {
1082+
ShadowOneSignalRestClient.failGetParams = true;
1083+
AddLauncherIntentFilter();
1084+
1085+
OneSignalInit();
1086+
// This removes Activity from the unit test's state
1087+
assertNotNull(shadowOf(blankActivity).getNextStartedActivity());
1088+
1089+
// Background the app
1090+
blankActivityController.pause();
1091+
1092+
// Open a notification
1093+
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\" } }]"), ONESIGNAL_NOTIFICATION_ID);
1094+
1095+
// Ensure the app is foregrounded
1096+
assertNotNull(shadowOf(blankActivity).getNextStartedActivity());
1097+
}
1098+
10801099
@Test
10811100
public void testOpeningLaunchUrl() throws Exception {
10821101
// First init run for appId to be saved

0 commit comments

Comments
 (0)