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.Mockito.times; |
| 19 | import static org.mockito.Mockito.verify; |
| 20 | |
| 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 StatusBarStateParserTest extends ParserTest { |
| 26 | |
| 27 | public StatusBarStateParserTest() { |
| 28 | mParser = new StatusBarStateParser(); |
| 29 | } |
| 30 | |
| 31 | public void testLockScreen() throws Throwable { |
| 32 | validate(MetricsEvent.LOCKSCREEN, MetricsEvent.TYPE_OPEN, 1, "1,1,0,0,1,0"); |
| 33 | } |
| 34 | |
| 35 | public void testBounce() throws Throwable { |
| 36 | validate(MetricsEvent.BOUNCER, MetricsEvent.TYPE_OPEN, 1, "1,1,0,1,1,0"); |
| 37 | } |
| 38 | |
| 39 | public void testUnlock() throws Throwable { |
| 40 | validate(MetricsEvent.LOCKSCREEN, MetricsEvent.TYPE_CLOSE, 1, "0,0,0,0,1,0"); |
| 41 | } |
| 42 | |
| 43 | public void testSecure() throws Throwable { |
| 44 | validate(MetricsEvent.BOUNCER, MetricsEvent.TYPE_OPEN, 1, "2,1,0,1,1,0"); |
| 45 | } |
| 46 | |
| 47 | public void testInsecure() throws Throwable { |
| 48 | validate(MetricsEvent.LOCKSCREEN, MetricsEvent.TYPE_OPEN, 0, "1,1,0,0,0,0"); |
| 49 | } |
| 50 | |
| 51 | public void testIgnoreUnexpectedData() throws Throwable { |
| 52 | validate(MetricsEvent.LOCKSCREEN, MetricsEvent.TYPE_OPEN, 0, "1,1,0,0,0,0,5"); |
| 53 | } |
| 54 | |
| 55 | private void validate(int view, int type, int subType, String log) { |
| 56 | String[] parts = log.split(","); |
| 57 | int t = 1000; |
| 58 | Object[] objects = new Object[parts.length]; |
| 59 | for (int i = 0; i < parts.length; i++) { |
| 60 | objects[i] = Integer.valueOf(parts[i]); |
| 61 | } |
| 62 | |
| 63 | mParser.parseEvent(mLogger, t, objects); |
| 64 | |
| 65 | verify(mLogger, times(1)).addEvent(mProtoCaptor.capture()); |
| 66 | |
Chris Wren | b623714 | 2017-01-23 16:42:58 -0500 | [diff] [blame] | 67 | LogMaker proto = mProtoCaptor.getValue(); |
Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 68 | assertEquals(t, proto.getTimestamp()); |
| 69 | assertEquals(view, proto.getCategory()); |
| 70 | assertEquals(type, proto.getType()); |
| 71 | assertEquals(subType, proto.getSubtype()); |
| 72 | } |
| 73 | } |