Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: components/background_task_scheduler/android/junit/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerTest.java

Issue 2814653003: [Android] BackgroundTaskScheduler reschedule implementation (Closed)
Patch Set: Exposing BackgroundTaskGcmTaskService in AndroidManifest.xml Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.components.background_task_scheduler;
6
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertTrue;
10 import static org.mockito.Mockito.doNothing;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.eq;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.robolectric.RuntimeEnvironment;
22 import org.robolectric.annotation.Config;
23
24 import org.chromium.base.ContextUtils;
25 import org.chromium.base.test.util.Feature;
26 import org.chromium.testing.local.LocalRobolectricTestRunner;
27
28 import java.util.concurrent.TimeUnit;
29
30 /** Unit tests for {@link BackgroundTaskScheduler}. */
31 @RunWith(LocalRobolectricTestRunner.class)
32 @Config(manifest = Config.NONE)
33 public class BackgroundTaskSchedulerTest {
34 private static final TaskInfo TASK =
35 TaskInfo.createOneOffTask(
36 TaskIds.TEST, TestBackgroundTask.class, TimeUnit.DAY S.toMillis(1))
37 .build();
38
39 @Mock
40 private BackgroundTaskSchedulerDelegate mDelegate;
41
42 @Before
43 public void setUp() {
44 MockitoAnnotations.initMocks(this);
45 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati on);
46 BackgroundTaskSchedulerFactory.setSchedulerForTesting(
47 new BackgroundTaskScheduler(mDelegate));
48 TestBackgroundTask.reset();
49 }
50
51 @Test
52 @Feature({"BackgroundTaskScheduler"})
53 public void testScheduleTask() {
54 doReturn(true).when(mDelegate).schedule(eq(RuntimeEnvironment.applicatio n), eq(TASK));
55 BackgroundTaskSchedulerFactory.getScheduler().schedule(
56 RuntimeEnvironment.application, TASK);
57 assertFalse(BackgroundTaskSchedulerPrefs.getScheduledTasks().contains(
nyquist 2017/04/18 22:33:03 It's unclear to me why this should be false. Don't
fgorski 2017/04/20 19:09:58 Good catch. This was a test bug. I was thinking w
58 TASK.getBackgroundTaskClass()));
59 verify(mDelegate, times(1)).schedule(eq(RuntimeEnvironment.application), eq(TASK));
60 }
61
62 @Test
63 @Feature({"BackgroundTaskScheduler"})
64 public void testCancel() {
65 BackgroundTaskSchedulerPrefs.addScheduledTask(TASK);
66
67 doNothing().when(mDelegate).cancel(eq(RuntimeEnvironment.application), e q(TaskIds.TEST));
68 BackgroundTaskSchedulerFactory.getScheduler().cancel(
69 RuntimeEnvironment.application, TaskIds.TEST);
70 assertFalse(BackgroundTaskSchedulerPrefs.getScheduledTasks().contains(
71 TASK.getBackgroundTaskClass()));
72 verify(mDelegate, times(1)).cancel(eq(RuntimeEnvironment.application), e q(TaskIds.TEST));
73 }
74
75 @Test
76 @Feature({"BackgroundTaskScheduler"})
77 public void testRescheduleTasks() {
78 BackgroundTaskSchedulerPrefs.addScheduledTask(TASK);
79
80 assertEquals(0, TestBackgroundTask.getRescheduleCalls());
81 assertFalse(BackgroundTaskSchedulerPrefs.getScheduledTasks().isEmpty());
82 BackgroundTaskSchedulerFactory.getScheduler().reschedule(RuntimeEnvironm ent.application);
83
84 assertEquals(1, TestBackgroundTask.getRescheduleCalls());
85 assertTrue(BackgroundTaskSchedulerPrefs.getScheduledTasks().isEmpty());
86 }
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698