| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.offlinepages; | 5 package org.chromium.chrome.browser.offlinepages; |
| 6 | 6 |
| 7 import static org.junit.Assert.assertEquals; | 7 import static org.junit.Assert.assertEquals; |
| 8 import static org.junit.Assert.assertNotNull; | 8 import static org.junit.Assert.assertNotNull; |
| 9 import static org.junit.Assert.assertNull; | 9 import static org.junit.Assert.assertNull; |
| 10 import static org.junit.Assert.assertTrue; | 10 import static org.junit.Assert.assertTrue; |
| 11 | 11 |
| 12 import android.content.Context; | 12 import android.content.Context; |
| 13 | 13 |
| 14 import com.google.android.gms.common.ConnectionResult; |
| 15 import com.google.android.gms.common.GoogleApiAvailability; |
| 14 import com.google.android.gms.gcm.GcmNetworkManager; | 16 import com.google.android.gms.gcm.GcmNetworkManager; |
| 15 import com.google.android.gms.gcm.Task; | 17 import com.google.android.gms.gcm.Task; |
| 16 | 18 |
| 17 import org.junit.Before; | 19 import org.junit.Before; |
| 18 import org.junit.Test; | 20 import org.junit.Test; |
| 19 import org.junit.runner.RunWith; | 21 import org.junit.runner.RunWith; |
| 20 import org.robolectric.RuntimeEnvironment; | 22 import org.robolectric.RuntimeEnvironment; |
| 21 import org.robolectric.annotation.Config; | 23 import org.robolectric.annotation.Config; |
| 22 import org.robolectric.internal.ShadowExtractor; | 24 import org.robolectric.internal.ShadowExtractor; |
| 25 import org.robolectric.shadows.gms.Shadows; |
| 26 import org.robolectric.shadows.gms.common.ShadowGoogleApiAvailability; |
| 23 | 27 |
| 24 import org.chromium.base.BaseChromiumApplication; | 28 import org.chromium.base.BaseChromiumApplication; |
| 25 import org.chromium.base.test.util.Feature; | 29 import org.chromium.base.test.util.Feature; |
| 26 import org.chromium.testing.local.LocalRobolectricTestRunner; | 30 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 27 | 31 |
| 28 /** | 32 /** |
| 29 * Unit tests for BackgroundScheduler. | 33 * Unit tests for BackgroundScheduler. |
| 30 */ | 34 */ |
| 31 @RunWith(LocalRobolectricTestRunner.class) | 35 @RunWith(LocalRobolectricTestRunner.class) |
| 32 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, sdk
= 21, | 36 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, sdk
= 21, |
| 33 shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.cl
ass}) | 37 shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.cl
ass}) |
| 34 public class BackgroundSchedulerTest { | 38 public class BackgroundSchedulerTest { |
| 35 private Context mContext; | 39 private Context mContext; |
| 36 private TriggerConditions mConditions1 = new TriggerConditions( | 40 private TriggerConditions mConditions1 = new TriggerConditions( |
| 37 true /* power */, 10 /* battery percentage */, false /* unmetered */
); | 41 true /* power */, 10 /* battery percentage */, false /* unmetered */
); |
| 38 private ShadowGcmNetworkManager mGcmNetworkManager; | 42 private ShadowGcmNetworkManager mGcmNetworkManager; |
| 39 | 43 |
| 40 @Before | 44 @Before |
| 41 public void setUp() throws Exception { | 45 public void setUp() throws Exception { |
| 46 Shadows.shadowOf(GoogleApiAvailability.getInstance()) |
| 47 .setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS); |
| 48 |
| 42 mContext = RuntimeEnvironment.application; | 49 mContext = RuntimeEnvironment.application; |
| 43 mGcmNetworkManager = (ShadowGcmNetworkManager) ShadowExtractor.extract( | 50 mGcmNetworkManager = (ShadowGcmNetworkManager) ShadowExtractor.extract( |
| 44 GcmNetworkManager.getInstance(mContext)); | 51 GcmNetworkManager.getInstance(mContext)); |
| 45 mGcmNetworkManager.clear(); | 52 mGcmNetworkManager.clear(); |
| 46 } | 53 } |
| 47 | 54 |
| 48 @Test | 55 @Test |
| 49 @Feature({"OfflinePages"}) | 56 @Feature({"OfflinePages"}) |
| 50 public void testSchedule() { | 57 public void testSchedule() { |
| 51 assertNull(mGcmNetworkManager.getScheduledTask()); | 58 assertNull(mGcmNetworkManager.getScheduledTask()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 67 public void testCancel() { | 74 public void testCancel() { |
| 68 assertNull(mGcmNetworkManager.getScheduledTask()); | 75 assertNull(mGcmNetworkManager.getScheduledTask()); |
| 69 BackgroundScheduler.getInstance(mContext).schedule(mConditions1); | 76 BackgroundScheduler.getInstance(mContext).schedule(mConditions1); |
| 70 assertNotNull(mGcmNetworkManager.getScheduledTask()); | 77 assertNotNull(mGcmNetworkManager.getScheduledTask()); |
| 71 | 78 |
| 72 assertNull(mGcmNetworkManager.getCanceledTask()); | 79 assertNull(mGcmNetworkManager.getCanceledTask()); |
| 73 BackgroundScheduler.getInstance(mContext).cancel(); | 80 BackgroundScheduler.getInstance(mContext).cancel(); |
| 74 assertNotNull(mGcmNetworkManager.getCanceledTask()); | 81 assertNotNull(mGcmNetworkManager.getCanceledTask()); |
| 75 } | 82 } |
| 76 } | 83 } |
| OLD | NEW |