Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.internal.logging.legacy; |
| 17 | |
| 18 | import static org.mockito.Matchers.anyObject; |
| 19 | import static org.mockito.Mockito.times; |
| 20 | import static org.mockito.Mockito.verify; |
| 21 | |
Chris Wren | b623714 | 2017-01-23 16:42:58 -0500 | [diff] [blame] | 22 | import android.metrics.LogMaker; |
Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 23 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 24 | |
| 25 | public 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 Wren | b623714 | 2017-01-23 16:42:58 -0500 | [diff] [blame] | 82 | LogMaker proto = mProtoCaptor.getValue(); |
Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 83 | 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 Wren | b623714 | 2017-01-23 16:42:58 -0500 | [diff] [blame] | 98 | verify(mLogger, times(1)).addEvent((LogMaker) anyObject()); |
Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 99 | } |
| 100 | } |