blob: 2b343c21fc8f1e40ea1bfbe0765f7bcf12e610c1 [file] [log] [blame]
Tony Mak202f25d2019-01-07 14:40:39 +00001/**
2 * Copyright (C) 2018 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.systemui.statusbar.notification.logging;
17
Tony Mak202f25d2019-01-07 14:40:39 +000018import static org.mockito.ArgumentMatchers.anyBoolean;
Gustav Senntona8e38aa2019-01-22 14:55:39 +000019import static org.mockito.ArgumentMatchers.anyInt;
Tony Mak202f25d2019-01-07 14:40:39 +000020import static org.mockito.ArgumentMatchers.eq;
Tony Mak96b3f1b2019-01-23 20:57:08 +000021import static org.mockito.Mockito.times;
Tony Mak202f25d2019-01-07 14:40:39 +000022import static org.mockito.Mockito.verify;
23
24import android.os.RemoteException;
Tony Mak202f25d2019-01-07 14:40:39 +000025import android.testing.AndroidTestingRunner;
26import android.testing.TestableLooper;
27
Brett Chabot84151d92019-02-27 15:37:59 -080028import androidx.test.filters.SmallTest;
29
Tony Mak202f25d2019-01-07 14:40:39 +000030import com.android.internal.statusbar.IStatusBarService;
31import com.android.internal.statusbar.NotificationVisibility;
32import com.android.systemui.Dependency;
33import com.android.systemui.SysuiTestCase;
34import com.android.systemui.UiOffloadThread;
Tony Mak96b3f1b2019-01-23 20:57:08 +000035import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
Tony Mak202f25d2019-01-07 14:40:39 +000036
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40import org.mockito.Mock;
41import org.mockito.Mockito;
42import org.mockito.MockitoAnnotations;
43
44import java.util.Collections;
45
46@SmallTest
47@RunWith(AndroidTestingRunner.class)
48@TestableLooper.RunWithLooper
49public class ExpansionStateLoggerTest extends SysuiTestCase {
50 private static final String NOTIFICATION_KEY = "notin_key";
51
52 private NotificationLogger.ExpansionStateLogger mLogger;
53 @Mock
54 private IStatusBarService mBarService;
55
56 @Before
57 public void setUp() {
58 MockitoAnnotations.initMocks(this);
59 mLogger = new NotificationLogger.ExpansionStateLogger(
60 Dependency.get(UiOffloadThread.class));
61 mLogger.mBarService = mBarService;
62 }
63
64 @Test
65 public void testVisible() throws RemoteException {
66 mLogger.onVisibilityChanged(
67 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
68 Collections.emptyList());
69 waitForUiOffloadThread();
70
71 verify(mBarService, Mockito.never()).onNotificationExpansionChanged(
Gustav Senntona8e38aa2019-01-22 14:55:39 +000072 eq(NOTIFICATION_KEY), anyBoolean(), anyBoolean(), anyInt());
Tony Mak202f25d2019-01-07 14:40:39 +000073 }
74
75 @Test
76 public void testExpanded() throws RemoteException {
Gustav Senntonc7d0d322019-01-07 15:36:41 +000077 mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
78 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
Tony Mak202f25d2019-01-07 14:40:39 +000079 waitForUiOffloadThread();
80
81 verify(mBarService, Mockito.never()).onNotificationExpansionChanged(
Gustav Senntona8e38aa2019-01-22 14:55:39 +000082 eq(NOTIFICATION_KEY), anyBoolean(), anyBoolean(), anyInt());
Tony Mak202f25d2019-01-07 14:40:39 +000083 }
84
85 @Test
86 public void testVisibleAndNotExpanded() throws RemoteException {
Gustav Senntonc7d0d322019-01-07 15:36:41 +000087 mLogger.onExpansionChanged(NOTIFICATION_KEY, true, false,
88 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
Tony Mak202f25d2019-01-07 14:40:39 +000089 mLogger.onVisibilityChanged(
90 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
91 Collections.emptyList());
92 waitForUiOffloadThread();
93
94 verify(mBarService, Mockito.never()).onNotificationExpansionChanged(
Gustav Senntona8e38aa2019-01-22 14:55:39 +000095 eq(NOTIFICATION_KEY), anyBoolean(), anyBoolean(), anyInt());
Tony Mak202f25d2019-01-07 14:40:39 +000096 }
97
98 @Test
99 public void testVisibleAndExpanded() throws RemoteException {
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000100 mLogger.onExpansionChanged(NOTIFICATION_KEY, true, true,
101 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
Tony Mak202f25d2019-01-07 14:40:39 +0000102 mLogger.onVisibilityChanged(
103 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
104 Collections.emptyList());
105 waitForUiOffloadThread();
106
107 verify(mBarService).onNotificationExpansionChanged(
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000108 NOTIFICATION_KEY, true, true,
109 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN.toMetricsEventEnum());
Tony Mak202f25d2019-01-07 14:40:39 +0000110 }
111
112 @Test
113 public void testExpandedAndVisible_expandedBeforeVisible() throws RemoteException {
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000114 mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
115 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
Tony Mak202f25d2019-01-07 14:40:39 +0000116 mLogger.onVisibilityChanged(
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000117 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true,
118 NotificationVisibility.NotificationLocation.LOCATION_MAIN_AREA)),
Tony Mak202f25d2019-01-07 14:40:39 +0000119 Collections.emptyList());
120 waitForUiOffloadThread();
121
122 verify(mBarService).onNotificationExpansionChanged(
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000123 NOTIFICATION_KEY, false, true,
124 // The last location seen should be logged (the one passed to onVisibilityChanged).
125 NotificationVisibility.NotificationLocation.LOCATION_MAIN_AREA.toMetricsEventEnum()
126 );
Tony Mak202f25d2019-01-07 14:40:39 +0000127 }
128
129 @Test
130 public void testExpandedAndVisible_visibleBeforeExpanded() throws RemoteException {
131 mLogger.onVisibilityChanged(
132 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
133 Collections.emptyList());
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000134 mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
135 NotificationVisibility.NotificationLocation.LOCATION_FIRST_HEADS_UP);
Tony Mak202f25d2019-01-07 14:40:39 +0000136 waitForUiOffloadThread();
137
138 verify(mBarService).onNotificationExpansionChanged(
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000139 NOTIFICATION_KEY, false, true,
140 // The last location seen should be logged (the one passed to onExpansionChanged).
141 NotificationVisibility.NotificationLocation.LOCATION_FIRST_HEADS_UP.toMetricsEventEnum());
Tony Mak202f25d2019-01-07 14:40:39 +0000142 }
143
144 @Test
145 public void testExpandedAndVisible_logOnceOnly() throws RemoteException {
146 mLogger.onVisibilityChanged(
147 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
148 Collections.emptyList());
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000149 mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
150 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
151 mLogger.onExpansionChanged(NOTIFICATION_KEY, false, true,
152 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
Tony Mak202f25d2019-01-07 14:40:39 +0000153 waitForUiOffloadThread();
154
155 verify(mBarService).onNotificationExpansionChanged(
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000156 NOTIFICATION_KEY, false, true,
157 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN.toMetricsEventEnum());
Tony Mak202f25d2019-01-07 14:40:39 +0000158 }
159
Tony Mak96b3f1b2019-01-23 20:57:08 +0000160 @Test
161 public void testOnEntryReinflated() throws RemoteException {
162 mLogger.onExpansionChanged(NOTIFICATION_KEY, true, true,
163 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
164 mLogger.onVisibilityChanged(
165 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
166 Collections.emptyList());
167 waitForUiOffloadThread();
168 verify(mBarService).onNotificationExpansionChanged(
169 NOTIFICATION_KEY, true, true, ExpandableViewState.LOCATION_UNKNOWN);
170
171 mLogger.onEntryReinflated(NOTIFICATION_KEY);
172 mLogger.onVisibilityChanged(
173 Collections.singletonList(createNotificationVisibility(NOTIFICATION_KEY, true)),
174 Collections.emptyList());
175 waitForUiOffloadThread();
176 // onNotificationExpansionChanged is called the second time.
177 verify(mBarService, times(2)).onNotificationExpansionChanged(
178 NOTIFICATION_KEY, true, true, ExpandableViewState.LOCATION_UNKNOWN);
179 }
180
Tony Mak202f25d2019-01-07 14:40:39 +0000181 private NotificationVisibility createNotificationVisibility(String key, boolean visibility) {
Gustav Senntonc7d0d322019-01-07 15:36:41 +0000182 return createNotificationVisibility(key, visibility,
183 NotificationVisibility.NotificationLocation.LOCATION_UNKNOWN);
184 }
185
186 private NotificationVisibility createNotificationVisibility(String key, boolean visibility,
187 NotificationVisibility.NotificationLocation location) {
188 return NotificationVisibility.obtain(key, 0, 0, visibility, location);
Tony Mak202f25d2019-01-07 14:40:39 +0000189 }
190}