Commit 5ec3f4c0 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Sync] Fix bug in disable logic

and add a unit test to verify the same for when Google Play Services is
up to date on the device, vs. when it's not.

Change-Id: I36e7df61e4549af57b3fc275356878ed826dd7c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819245
Auto-Submit: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699275}
parent 04d40a3e
......@@ -18,6 +18,7 @@ chrome_junit_test_java_sources = [
"junit/src/org/chromium/chrome/browser/autofill/AutofillUiUtilsTest.java",
"junit/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTaskSchedulerTest.java",
"junit/src/org/chromium/chrome/browser/background_sync/BackgroundSyncBackgroundTaskTest.java",
"junit/src/org/chromium/chrome/browser/background_sync/BackgroundSyncGooglePlayServicesCheckerTest.java",
"junit/src/org/chromium/chrome/browser/background_sync/PeriodicBackgroundSyncChromeWakeUpTaskTest.java",
"junit/src/org/chromium/chrome/browser/background_task_scheduler/NativeBackgroundTaskTest.java",
"junit/src/org/chromium/chrome/browser/browserservices/ClearDataDialogResultRecorderTest.java",
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.background_sync;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
......@@ -15,7 +16,6 @@ import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
*/
final class GooglePlayServicesChecker {
private static final String TAG = "PlayServicesChecker";
private GooglePlayServicesChecker() {}
/**
......@@ -25,14 +25,16 @@ final class GooglePlayServicesChecker {
* wait until Play Services is updated before attempting them.
*/
@CalledByNative
private static boolean shouldDisableBackgroundSync() {
@VisibleForTesting
protected static boolean shouldDisableBackgroundSync() {
boolean isAvailable = true;
if (!ExternalAuthUtils.canUseGooglePlayServices()) {
Log.i(TAG, "Disabling Background Sync because Play Services is not up to date.");
isAvailable = false;
}
RecordHistogram.recordBooleanHistogram(
"BackgroundSync.LaunchTask.PlayServicesAvailable", isAvailable);
return isAvailable;
return !isAvailable;
}
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.background_sync;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.gms.Shadows;
import org.robolectric.shadows.gms.common.ShadowGoogleApiAvailability;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.test.support.DisableHistogramsRule;
/** Unit tests for GooglePlayServicesChecker. */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE, shadows = {ShadowGoogleApiAvailability.class})
public class BackgroundSyncGooglePlayServicesCheckerTest {
@Rule
public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsRule();
@Test
@Feature("BackgroundSync")
public void testDisableLogicWhenGooglePlayServicesReturnsSuccess() {
Shadows.shadowOf(GoogleApiAvailability.getInstance())
.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);
assertFalse(GooglePlayServicesChecker.shouldDisableBackgroundSync());
}
@Test
@Feature("BackgroundSync")
public void testDisableLogicWhenGooglePlayServicesReturnsError() {
Shadows.shadowOf(GoogleApiAvailability.getInstance())
.setIsGooglePlayServicesAvailable(ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED);
assertTrue(GooglePlayServicesChecker.shouldDisableBackgroundSync());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment