1 /* 2 * Copyright (C) 2023 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 17 package com.android.systemui.qs.tiles.base.analytics 18 19 import android.platform.test.annotations.EnabledOnRavenwood 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.filters.SmallTest 22 import com.android.internal.logging.InstanceId 23 import com.android.internal.logging.UiEventLogger 24 import com.android.systemui.SysuiTestCase 25 import com.android.systemui.qs.QSEvent 26 import com.android.systemui.qs.tiles.viewmodel.QSTileConfigTestBuilder 27 import com.android.systemui.qs.tiles.viewmodel.QSTileUserAction 28 import org.junit.Before 29 import org.junit.Test 30 import org.junit.runner.RunWith 31 import org.mockito.Mock 32 import org.mockito.Mockito.eq 33 import org.mockito.Mockito.verify 34 import org.mockito.MockitoAnnotations 35 36 @SmallTest 37 @EnabledOnRavenwood 38 @RunWith(AndroidJUnit4::class) 39 class QSTileAnalyticsTest : SysuiTestCase() { 40 41 @Mock private lateinit var uiEventLogger: UiEventLogger 42 43 private lateinit var underTest: QSTileAnalytics 44 45 @Before setupnull46 fun setup() { 47 MockitoAnnotations.initMocks(this) 48 underTest = QSTileAnalytics(uiEventLogger) 49 } 50 51 @Test testClickIsLoggednull52 fun testClickIsLogged() { 53 underTest.trackUserAction(config, QSTileUserAction.Click(null)) 54 55 verify(uiEventLogger) 56 .logWithInstanceId( 57 eq(QSEvent.QS_ACTION_CLICK), 58 eq(0), 59 eq("test_spec"), 60 eq(InstanceId.fakeInstanceId(0)) 61 ) 62 } 63 64 @Test testLongClickIsLoggednull65 fun testLongClickIsLogged() { 66 underTest.trackUserAction(config, QSTileUserAction.LongClick(null)) 67 68 verify(uiEventLogger) 69 .logWithInstanceId( 70 eq(QSEvent.QS_ACTION_LONG_PRESS), 71 eq(0), 72 eq("test_spec"), 73 eq(InstanceId.fakeInstanceId(0)) 74 ) 75 } 76 77 private companion object { 78 79 val config = QSTileConfigTestBuilder.build() 80 } 81 } 82