use of com.onesignal.SyncJobService in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method ensureNoConcurrentUpdateCallsWithSameData.
@Test
@Config(sdk = 26)
public void ensureNoConcurrentUpdateCallsWithSameData() throws Exception {
sendTagsAndImmediatelyBackgroundApp();
// Simulate a hung network connection when SyncJobService starts.
ShadowOneSignalRestClient.freezeResponses = true;
SyncJobService syncJobService = Robolectric.buildService(SyncJobService.class).create().get();
syncJobService.onStartJob(null);
// Kicks off the Job service's background thread.
threadAndTaskWait();
// App is resumed, the SyncJobService is still waiting on a network response at this point.
blankActivityController.resume();
threadAndTaskWait();
// Should only be 3 requests if there are no duplicates
assertEquals(3, ShadowOneSignalRestClient.requests.size());
}
use of com.onesignal.SyncJobService in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method ensureFailureOnPauseIsSentFromSyncService_forPendingActiveTime.
@Test
@Config(sdk = 26)
public void ensureFailureOnPauseIsSentFromSyncService_forPendingActiveTime() throws Exception {
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// 1. Start app
time.advanceSystemAndElapsedTimeBy(0);
OneSignalInit();
threadAndTaskWait();
// 2. Wait 2 minutes
time.advanceSystemAndElapsedTimeBy(2 * 60);
// 3. Put app in background, simulating network issue.
ShadowOneSignalRestClient.failAll = true;
pauseActivity(blankActivityController);
assertAndRunSyncService();
assertEquals(3, ShadowOneSignalRestClient.requests.size());
// Simulate a hung network connection when SyncJobService starts.
ShadowOneSignalRestClient.failAll = false;
SyncJobService syncJobService = Robolectric.buildService(SyncJobService.class).create().get();
syncJobService.onStartJob(null);
// Kicks off the Job service's background thread.
threadAndTaskWait();
assertRestCalls(4);
assertOnFocusAtIndex(3, 120);
// // FIXME: Cleanup for upcoming unit test
// // This is a one off scenario where a unit test fails after this one is run
// blankActivityController.resume();
// threadAndTaskWait();
}
use of com.onesignal.SyncJobService in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method ensureNoConcurrentUpdateCallsWithSameData_forPendingActiveTime.
@Test
@Config(sdk = 26)
public void ensureNoConcurrentUpdateCallsWithSameData_forPendingActiveTime() throws Exception {
// useAppFor2minThenBackground();
time.advanceSystemAndElapsedTimeBy(0);
// 1. Start app
OneSignalInit();
threadAndTaskWait();
// 2. Wait 2 minutes
time.advanceSystemAndElapsedTimeBy(2 * 60);
// 3. Put app in background
ShadowOneSignalRestClient.freezeResponses = true;
pauseActivity(blankActivityController);
// 4. Simulate a hung network connection when SyncJobService starts.
SyncJobService syncJobService = Robolectric.buildService(SyncJobService.class).create().get();
syncJobService.onStartJob(null);
// Kicks off the Job service's background thread.
threadAndTaskWait();
// 5. App is resumed, the SyncJobService is still waiting on a network response at this point.
blankActivityController.resume();
threadAndTaskWait();
// 6. Network connection now responding
ShadowOneSignalRestClient.unFreezeResponses();
threadAndTaskWait();
assertEquals(3, ShadowOneSignalRestClient.requests.size());
}
use of com.onesignal.SyncJobService in project OneSignal-Android-SDK by OneSignal.
the class LocationIntegrationTests method shouldCallOnSessionEvenIfSyncJobStarted_Huawei.
@Test
@Config(shadows = { ShadowHMSFusedLocationProviderClient.class, ShadowHuaweiTask.class })
public void shouldCallOnSessionEvenIfSyncJobStarted_Huawei() throws Exception {
ShadowOSUtils.supportsHMS(true);
ShadowHMSFusedLocationProviderClient.shadowTask = true;
ShadowHuaweiTask.result = ShadowHMSFusedLocationProviderClient.getLocation();
shadowOf(RuntimeEnvironment.application).grantPermissions("android.permission.ACCESS_COARSE_LOCATION");
OneSignalInit();
threadAndTaskWait();
restartAppAndElapseTimeToNextSession(time);
ShadowHMSFusedLocationProviderClient.skipOnGetLocation = true;
OneSignalInit();
SyncJobService syncJobService = Robolectric.buildService(SyncJobService.class).create().get();
syncJobService.onStartJob(null);
TestHelpers.getThreadByName("OS_SYNCSRV_BG_SYNC").join();
OneSignalPackagePrivateHelper.runAllNetworkRunnables();
ShadowHuaweiTask.callSuccessListener(ShadowHMSFusedLocationProviderClient.getLocation());
threadAndTaskWait();
ShadowOneSignalRestClient.Request request = ShadowOneSignalRestClient.requests.get(3);
assertEquals(ShadowOneSignalRestClient.REST_METHOD.POST, request.method);
assertEquals("players/a2f7f967-e8cc-11e4-bed1-118f05be4511/on_session", request.url);
}
use of com.onesignal.SyncJobService in project OneSignal-Android-SDK by OneSignal.
the class LocationIntegrationTests method shouldCallOnSessionEvenIfSyncJobStarted.
@Test
@Config(shadows = { ShadowGoogleApiClientBuilder.class, ShadowGoogleApiClientCompatProxy.class, ShadowFusedLocationApiWrapper.class })
public void shouldCallOnSessionEvenIfSyncJobStarted() throws Exception {
shadowOf(RuntimeEnvironment.application).grantPermissions("android.permission.ACCESS_COARSE_LOCATION");
OneSignalInit();
threadAndTaskWait();
restartAppAndElapseTimeToNextSession(time);
ShadowGoogleApiClientCompatProxy.skipOnConnected = true;
OneSignalInit();
SyncJobService syncJobService = Robolectric.buildService(SyncJobService.class).create().get();
syncJobService.onStartJob(null);
TestHelpers.getThreadByName("OS_SYNCSRV_BG_SYNC").join();
OneSignalPackagePrivateHelper.runAllNetworkRunnables();
ShadowGoogleApiClientBuilder.connectionCallback.onConnected(null);
threadAndTaskWait();
ShadowOneSignalRestClient.Request request = ShadowOneSignalRestClient.requests.get(3);
assertEquals(ShadowOneSignalRestClient.REST_METHOD.POST, request.method);
assertEquals("players/a2f7f967-e8cc-11e4-bed1-118f05be4511/on_session", request.url);
}
Aggregations