| 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.assertNotNull; |
| 8 import static org.junit.Assert.assertNull; |
| 7 import static org.junit.Assert.assertSame; | 9 import static org.junit.Assert.assertSame; |
| 8 import static org.junit.Assert.assertTrue; | 10 import static org.junit.Assert.assertTrue; |
| 9 | 11 |
| 10 import android.os.Bundle; | 12 import android.os.Bundle; |
| 11 | 13 |
| 12 import org.chromium.base.BaseChromiumApplication; | 14 import org.chromium.base.BaseChromiumApplication; |
| 13 import org.chromium.base.test.util.Feature; | 15 import org.chromium.base.test.util.Feature; |
| 14 import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter; | 16 import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter; |
| 15 import org.chromium.net.ConnectionType; | 17 import org.chromium.net.ConnectionType; |
| 16 import org.chromium.testing.local.LocalRobolectricTestRunner; | 18 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 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; |
| 22 import org.robolectric.Robolectric; |
| 20 import org.robolectric.annotation.Config; | 23 import org.robolectric.annotation.Config; |
| 21 | 24 |
| 22 /** | 25 /** |
| 23 * Unit tests for BackgroundOfflinerTask. | 26 * Unit tests for BackgroundOfflinerTask. |
| 24 */ | 27 */ |
| 25 @RunWith(LocalRobolectricTestRunner.class) | 28 @RunWith(LocalRobolectricTestRunner.class) |
| 26 @Config(manifest = Config.NONE, | 29 @Config(manifest = Config.NONE, |
| 27 application = BaseChromiumApplication.class) | 30 application = BaseChromiumApplication.class, |
| 31 shadows = { ShadowGcmNetworkManager.class }) |
| 28 public class BackgroundOfflinerTaskTest { | 32 public class BackgroundOfflinerTaskTest { |
| 29 private Bundle mTaskExtras; | 33 private Bundle mTaskExtras; |
| 30 private long mTestTime; | 34 private long mTestTime; |
| 31 private StubBackgroundSchedulerProcessor mStubBackgroundSchedulerProcessor; | 35 private StubBackgroundSchedulerProcessor mStubBackgroundSchedulerProcessor; |
| 32 | 36 |
| 33 @Before | 37 @Before |
| 34 public void setUp() throws Exception { | 38 public void setUp() throws Exception { |
| 35 // Build a bundle | 39 // Build a bundle |
| 36 mTaskExtras = new Bundle(); | 40 mTaskExtras = new Bundle(); |
| 37 TaskExtrasPacker.packTimeInBundle(mTaskExtras); | 41 TaskExtrasPacker.packTimeInBundle(mTaskExtras); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 | 54 |
| 51 // Check with ShadowBackgroundBackgroundSchedulerProcessor that startPro
cessing got called. | 55 // Check with ShadowBackgroundBackgroundSchedulerProcessor that startPro
cessing got called. |
| 52 assertTrue(mStubBackgroundSchedulerProcessor.getStartProcessingCalled())
; | 56 assertTrue(mStubBackgroundSchedulerProcessor.getStartProcessingCalled())
; |
| 53 assertSame(deviceConditions, mStubBackgroundSchedulerProcessor.getDevice
Conditions()); | 57 assertSame(deviceConditions, mStubBackgroundSchedulerProcessor.getDevice
Conditions()); |
| 54 | 58 |
| 55 // TODO(dougarnett): Call processor callback and verify waiter signaled. | 59 // TODO(dougarnett): Call processor callback and verify waiter signaled. |
| 56 } | 60 } |
| 57 | 61 |
| 58 @Test | 62 @Test |
| 59 @Feature({"OfflinePages"}) | 63 @Feature({"OfflinePages"}) |
| 64 public void testStartBackgroundRequests() { |
| 65 BackgroundOfflinerTask task = new BackgroundOfflinerTask(mStubBackground
SchedulerProcessor); |
| 66 ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter
(1); |
| 67 assertNull("Nothing scheduled", ShadowGcmNetworkManager.getScheduledTask
()); |
| 68 assertTrue(task.startBackgroundRequests(Robolectric.application, mTaskEx
tras, waiter)); |
| 69 |
| 70 // Check that the backup task was scheduled. |
| 71 assertNotNull("Backup task scheduled", ShadowGcmNetworkManager.getSchedu
ledTask()); |
| 72 |
| 73 // Check with ShadowBackgroundBackgroundSchedulerProcessor that startPro
cessing got called. |
| 74 assertTrue(mStubBackgroundSchedulerProcessor.getStartProcessingCalled())
; |
| 75 } |
| 76 |
| 77 @Test |
| 78 @Feature({"OfflinePages"}) |
| 60 public void testCallback() { | 79 public void testCallback() { |
| 61 // TODO(petewil): Implement the test | 80 // TODO(petewil): Implement the test |
| 62 } | 81 } |
| 63 } | 82 } |
| OLD | NEW |