blob: c8c27d44e8c0adea59094cce425566a9042e7c16 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.base.jank_tracker;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.view.FrameMetrics;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner;
/**
* Tests for FrameMetricsListener.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class FrameMetricsListenerTest {
@Test
public void testMetricRecording_OffByDefault() {
FrameMetricsStore store = new FrameMetricsStore();
FrameMetricsListener metricsListener = new FrameMetricsListener(store);
FrameMetrics frameMetrics = mock(FrameMetrics.class);
store.startTrackingScenario(JankScenario.PERIODIC_REPORTING);
when(frameMetrics.getMetric(FrameMetrics.TOTAL_DURATION)).thenReturn(10_000_000L);
metricsListener.onFrameMetricsAvailable(null, frameMetrics, 0);
// By default metrics shouldn't be logged.
Assert.assertEquals(
0, store.stopTrackingScenario(JankScenario.PERIODIC_REPORTING).durationsNs.length);
verifyNoMoreInteractions(frameMetrics);
}
@Test
public void testMetricRecording_EnableRecording() {
FrameMetricsStore store = new FrameMetricsStore();
FrameMetricsListener metricsListener = new FrameMetricsListener(store);
FrameMetrics frameMetrics = mock(FrameMetrics.class);
store.startTrackingScenario(JankScenario.PERIODIC_REPORTING);
when(frameMetrics.getMetric(FrameMetrics.TOTAL_DURATION)).thenReturn(10_000_000L);
metricsListener.setIsListenerRecording(true);
metricsListener.onFrameMetricsAvailable(null, frameMetrics, 0);
Assert.assertArrayEquals(new Long[] {10_000_000L},
store.stopTrackingScenario(JankScenario.PERIODIC_REPORTING).durationsNs);
}
}
|