• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.shadows;
2 
3 import static com.google.common.truth.Truth.assertThat;
4 import static org.mockito.Matchers.anyLong;
5 import static org.mockito.Mockito.mock;
6 import static org.mockito.Mockito.never;
7 import static org.mockito.Mockito.verify;
8 
9 import android.view.Choreographer;
10 import androidx.test.ext.junit.runners.AndroidJUnit4;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.robolectric.util.TimeUtils;
14 
15 @RunWith(AndroidJUnit4.class)
16 public class ShadowChoreographerTest {
17 
18   @Test
setFrameInterval_shouldUpdateFrameInterval()19   public void setFrameInterval_shouldUpdateFrameInterval() {
20     final long frameInterval = 10 * TimeUtils.NANOS_PER_MS;
21     ShadowChoreographer.setFrameInterval(frameInterval);
22 
23     final Choreographer instance = ShadowChoreographer.getInstance();
24     long time1 = instance.getFrameTimeNanos();
25     long time2 = instance.getFrameTimeNanos();
26 
27     assertThat(time2 - time1).isEqualTo(frameInterval);
28   }
29 
30   @Test
removeFrameCallback_shouldRemoveCallback()31   public void removeFrameCallback_shouldRemoveCallback() {
32     Choreographer instance = ShadowChoreographer.getInstance();
33     Choreographer.FrameCallback callback = mock(Choreographer.FrameCallback.class);
34     instance.postFrameCallbackDelayed(callback, 1000);
35     instance.removeFrameCallback(callback);
36     ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
37     verify(callback, never()).doFrame(anyLong());
38   }
39 
40   @Test
reset_shouldResetFrameInterval()41   public void reset_shouldResetFrameInterval() {
42     ShadowChoreographer.setFrameInterval(1);
43     assertThat(ShadowChoreographer.getFrameInterval()).isEqualTo(1);
44 
45     ShadowChoreographer.reset();
46     assertThat(ShadowChoreographer.getFrameInterval()).isEqualTo(10 * TimeUtils.NANOS_PER_MS);
47   }
48 }
49