| 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.gcm.GcmNetworkManager; | 14 import com.google.android.gms.gcm.GcmNetworkManager; |
| 15 import com.google.android.gms.gcm.Task; | 15 import com.google.android.gms.gcm.Task; |
| 16 | 16 |
| 17 import org.junit.Before; | 17 import org.junit.Before; |
| 18 import org.junit.Test; | 18 import org.junit.Test; |
| 19 import org.junit.runner.RunWith; | 19 import org.junit.runner.RunWith; |
| 20 import org.robolectric.RuntimeEnvironment; | 20 import org.robolectric.RuntimeEnvironment; |
| 21 import org.robolectric.annotation.Config; | 21 import org.robolectric.annotation.Config; |
| 22 import org.robolectric.internal.ShadowExtractor; | 22 import org.robolectric.internal.ShadowExtractor; |
| 23 | 23 |
| 24 import org.chromium.base.BaseChromiumApplication; | 24 import org.chromium.base.BaseChromiumApplication; |
| 25 import org.chromium.base.test.util.Feature; | 25 import org.chromium.base.test.util.Feature; |
| 26 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Unit tests for BackgroundScheduler. | 29 * Unit tests for BackgroundScheduler. |
| 29 */ | 30 */ |
| 30 @RunWith(OfflinePageTestRunner.class) | 31 @RunWith(LocalRobolectricTestRunner.class) |
| 31 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, | 32 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, sdk
= 21, |
| 32 shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.cl
ass}) | 33 shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.cl
ass}) |
| 33 public class BackgroundSchedulerTest { | 34 public class BackgroundSchedulerTest { |
| 34 private Context mContext; | 35 private Context mContext; |
| 35 private TriggerConditions mConditions1 = new TriggerConditions( | 36 private TriggerConditions mConditions1 = new TriggerConditions( |
| 36 true /* power */, 10 /* battery percentage */, false /* unmetered */
); | 37 true /* power */, 10 /* battery percentage */, false /* unmetered */
); |
| 37 private ShadowGcmNetworkManager mGcmNetworkManager; | 38 private ShadowGcmNetworkManager mGcmNetworkManager; |
| 38 | 39 |
| 39 @Before | 40 @Before |
| 40 public void setUp() throws Exception { | 41 public void setUp() throws Exception { |
| 41 mContext = RuntimeEnvironment.application; | 42 mContext = RuntimeEnvironment.application; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 66 public void testCancel() { | 67 public void testCancel() { |
| 67 assertNull(mGcmNetworkManager.getScheduledTask()); | 68 assertNull(mGcmNetworkManager.getScheduledTask()); |
| 68 BackgroundScheduler.getInstance(mContext).schedule(mConditions1); | 69 BackgroundScheduler.getInstance(mContext).schedule(mConditions1); |
| 69 assertNotNull(mGcmNetworkManager.getScheduledTask()); | 70 assertNotNull(mGcmNetworkManager.getScheduledTask()); |
| 70 | 71 |
| 71 assertNull(mGcmNetworkManager.getCanceledTask()); | 72 assertNull(mGcmNetworkManager.getCanceledTask()); |
| 72 BackgroundScheduler.getInstance(mContext).cancel(); | 73 BackgroundScheduler.getInstance(mContext).cancel(); |
| 73 assertNotNull(mGcmNetworkManager.getCanceledTask()); | 74 assertNotNull(mGcmNetworkManager.getCanceledTask()); |
| 74 } | 75 } |
| 75 } | 76 } |
| OLD | NEW |