| 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; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 /** | 27 /** |
| 28 * Unit tests for BackgroundScheduler. | 28 * Unit tests for BackgroundScheduler. |
| 29 */ | 29 */ |
| 30 @RunWith(OfflinePageTestRunner.class) | 30 @RunWith(OfflinePageTestRunner.class) |
| 31 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, | 31 @Config(manifest = Config.NONE, application = BaseChromiumApplication.class, |
| 32 shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.cl
ass}) | 32 shadows = {ShadowGcmNetworkManager.class, ShadowGoogleApiAvailability.cl
ass}) |
| 33 public class BackgroundSchedulerTest { | 33 public class BackgroundSchedulerTest { |
| 34 private Context mContext; | 34 private Context mContext; |
| 35 private TriggerConditions mConditions1 = new TriggerConditions( | 35 private TriggerConditions mConditions1 = new TriggerConditions( |
| 36 true /* power */, 10 /* battery percentage */, false /* unmetered */
); | 36 true /* power */, 10 /* battery percentage */, false /* unmetered */
); |
| 37 private TriggerConditions mConditions2 = new TriggerConditions( |
| 38 false /* power */, 0 /* battery percentage */, false /* unmetered */
); |
| 37 private ShadowGcmNetworkManager mGcmNetworkManager; | 39 private ShadowGcmNetworkManager mGcmNetworkManager; |
| 38 | 40 |
| 39 @Before | 41 @Before |
| 40 public void setUp() throws Exception { | 42 public void setUp() throws Exception { |
| 41 mContext = RuntimeEnvironment.application; | 43 mContext = RuntimeEnvironment.application; |
| 42 mGcmNetworkManager = (ShadowGcmNetworkManager) ShadowExtractor.extract( | 44 mGcmNetworkManager = (ShadowGcmNetworkManager) ShadowExtractor.extract( |
| 43 GcmNetworkManager.getInstance(mContext)); | 45 GcmNetworkManager.getInstance(mContext)); |
| 44 mGcmNetworkManager.clear(); | 46 mGcmNetworkManager.clear(); |
| 45 } | 47 } |
| 46 | 48 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 65 @Feature({"OfflinePages"}) | 67 @Feature({"OfflinePages"}) |
| 66 public void testCancel() { | 68 public void testCancel() { |
| 67 assertNull(mGcmNetworkManager.getScheduledTask()); | 69 assertNull(mGcmNetworkManager.getScheduledTask()); |
| 68 BackgroundScheduler.getInstance(mContext).schedule(mConditions1); | 70 BackgroundScheduler.getInstance(mContext).schedule(mConditions1); |
| 69 assertNotNull(mGcmNetworkManager.getScheduledTask()); | 71 assertNotNull(mGcmNetworkManager.getScheduledTask()); |
| 70 | 72 |
| 71 assertNull(mGcmNetworkManager.getCanceledTask()); | 73 assertNull(mGcmNetworkManager.getCanceledTask()); |
| 72 BackgroundScheduler.getInstance(mContext).cancel(); | 74 BackgroundScheduler.getInstance(mContext).cancel(); |
| 73 assertNotNull(mGcmNetworkManager.getCanceledTask()); | 75 assertNotNull(mGcmNetworkManager.getCanceledTask()); |
| 74 } | 76 } |
| 77 |
| 78 @Test |
| 79 @Feature({"OfflinePages"}) |
| 80 public void testReschedulOnUpgrade() { |
| 81 assertNull(mGcmNetworkManager.getScheduledTask()); |
| 82 BackgroundScheduler.getInstance(mContext).rescheduleOfflinePagesTasksOnU
pgrade(); |
| 83 // Check with gcmNetworkManagerShadow that schedule got called. |
| 84 assertNotNull(mGcmNetworkManager.getScheduledTask()); |
| 85 |
| 86 // Verify details of the scheduled task. |
| 87 Task task = mGcmNetworkManager.getScheduledTask(); |
| 88 assertEquals(OfflinePageUtils.TASK_TAG, task.getTag()); |
| 89 long scheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(task.ge
tExtras()); |
| 90 assertTrue(scheduledTimeMillis > 0L); |
| 91 assertEquals( |
| 92 mConditions2, TaskExtrasPacker.unpackTriggerConditionsFromBundle
(task.getExtras())); |
| 93 } |
| 75 } | 94 } |
| OLD | NEW |