blob: c023b572493fa0a2fdac97d3c8f020f86daf1abb [file] [log] [blame]
Chris Wren26ca65d2016-11-29 10:43:28 -05001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.internal.logging.legacy;
17
18import static org.mockito.Matchers.anyObject;
19import static org.mockito.Mockito.times;
20import static org.mockito.Mockito.verify;
21
Chris Wrenb6237142017-01-23 16:42:58 -050022import android.metrics.LogMaker;
Chris Wren26ca65d2016-11-29 10:43:28 -050023import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
24
25public class LockscreenGestureParserTest extends ParserTest {
26
27 public LockscreenGestureParserTest() {
28 mParser = new LockscreenGestureParser();
29 }
30
31 public void testSwipeUpUnlock() throws Throwable {
32 validate(MetricsEvent.ACTION_LS_UNLOCK, 1, 359, 6382);
33 }
34
35 public void testSwipeToShade() throws Throwable {
36 validate(MetricsEvent.ACTION_LS_SHADE, 2, 324, 0);
37 }
38
39 public void testTapLockHint() throws Throwable {
40 validate(MetricsEvent.ACTION_LS_HINT, 3, 0, 0);
41 }
42
43 public void testCamera() throws Throwable {
44 validate(MetricsEvent.ACTION_LS_CAMERA, 4, 223, 1756);
45 }
46
47 public void testDialer() throws Throwable {
48 validate(MetricsEvent.ACTION_LS_DIALER, 5, 163, 861);
49 }
50
51 public void testTapToLock() throws Throwable {
52 validate(MetricsEvent.ACTION_LS_LOCK, 6, 0, 0);
53 }
54
55 public void testTapOnNotification() throws Throwable {
56 validate(MetricsEvent.ACTION_LS_NOTE, 7, 0, 0);
57 }
58
59 public void testLockscreenQuickSettings() throws Throwable {
60 validate(MetricsEvent.ACTION_LS_QS, 8, 284, 3824);
61 }
62
63 public void testShadePullQuickSettings() throws Throwable {
64 validate(MetricsEvent.ACTION_SHADE_QS_PULL, 9, 175, 3444);
65 }
66
67 public void testShadeTapQuickSettings() throws Throwable {
68 validate(MetricsEvent.ACTION_SHADE_QS_TAP, 10, 0, 0);
69 }
70
71 private void validate(int view, int type, int len, int vel) {
72 int t = 1000;
73 Object[] objects = new Object[3];
74 objects[0] = type;
75 objects[1] = len;
76 objects[2] = vel;
77
78 mParser.parseEvent(mLogger, t, objects);
79
80 verify(mLogger, times(1)).addEvent(mProtoCaptor.capture());
81
Chris Wrenb6237142017-01-23 16:42:58 -050082 LogMaker proto = mProtoCaptor.getValue();
Chris Wren26ca65d2016-11-29 10:43:28 -050083 assertEquals(t, proto.getTimestamp());
84 assertEquals(view, proto.getCategory());
85 assertEquals(MetricsEvent.TYPE_ACTION, proto.getType());
86 }
87
88 public void testIgnoreUnexpectedData() throws Throwable {
89 int t = 1000;
90 Object[] objects = new Object[4];
91 objects[0] = 1;
92 objects[1] = 0;
93 objects[2] = 0;
94 objects[3] = "foo";
95
96 mParser.parseEvent(mLogger, t, objects);
97
Chris Wrenb6237142017-01-23 16:42:58 -050098 verify(mLogger, times(1)).addEvent((LogMaker) anyObject());
Chris Wren26ca65d2016-11-29 10:43:28 -050099 }
100}