• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.launcher3.widget
18 
19 import android.content.Context
20 import android.os.Bundle
21 import androidx.test.ext.junit.runners.AndroidJUnit4
22 import androidx.test.filters.SmallTest
23 import androidx.test.platform.app.InstrumentationRegistry
24 import com.android.launcher3.Launcher
25 import com.android.launcher3.model.data.ItemInfo
26 import com.android.launcher3.model.data.LauncherAppWidgetInfo
27 import com.android.launcher3.util.ActivityContextWrapper
28 import com.google.common.truth.Truth
29 import org.junit.Test
30 import org.junit.runner.RunWith
31 import org.mockito.Mockito.any
32 import org.mockito.Mockito.verify
33 import org.mockito.kotlin.mock
34 import org.mockito.kotlin.whenever
35 
36 @SmallTest
37 @RunWith(AndroidJUnit4::class)
38 class WidgetAddFlowHandlerTest {
39 
40     private val context: Context
41         get() = ActivityContextWrapper(InstrumentationRegistry.getInstrumentation().targetContext)
42 
43     private val providerInfo =
<lambda>null44         LauncherAppWidgetProviderInfo().apply {
45             configure = InstrumentationRegistry.getInstrumentation().componentName
46         }
47     private val appWidgetHolder: LauncherWidgetHolder = mock<LauncherWidgetHolder>()
48     private val launcher: Launcher =
<lambda>null49         mock<Launcher>().also { whenever(it.appWidgetHolder).thenReturn(appWidgetHolder) }
<lambda>null50     private val appWidgetInfo = LauncherAppWidgetInfo().apply { appWidgetId = 123 }
51     private val requestCode = 123
52     private val flowHandler = WidgetAddFlowHandler(providerInfo)
53 
54     @Test
valuesShouldRemainTheSame_beforeAndAfter_parcelizationnull55     fun valuesShouldRemainTheSame_beforeAndAfter_parcelization() {
56         with(Bundle()) {
57             val testKey = "testKey"
58             putParcelable(testKey, flowHandler)
59             Truth.assertThat(getParcelable(testKey, WidgetAddFlowHandler::class.java))
60                 .isEqualTo(flowHandler)
61         }
62     }
63 
64     @Test
describeContents_shouldReturn_0null65     fun describeContents_shouldReturn_0() {
66         Truth.assertThat(flowHandler.describeContents()).isEqualTo(0)
67     }
68 
69     @Test
startBindFlow_shouldCorrectly_startLauncherFlowBindingnull70     fun startBindFlow_shouldCorrectly_startLauncherFlowBinding() {
71         flowHandler.startBindFlow(launcher, appWidgetInfo.appWidgetId, appWidgetInfo, requestCode)
72         verify(launcher).setWaitingForResult(any())
73         verify(appWidgetHolder)
74             .startBindFlow(launcher, appWidgetInfo.appWidgetId, providerInfo, requestCode)
75     }
76 
77     @Test
startConfigActivityWithCustomAppWidgetId_shouldAskLauncherToStartConfigActivitynull78     fun startConfigActivityWithCustomAppWidgetId_shouldAskLauncherToStartConfigActivity() {
79         flowHandler.startConfigActivity(
80             launcher,
81             appWidgetInfo.appWidgetId,
82             ItemInfo(),
83             requestCode
84         )
85         verify(launcher).setWaitingForResult(any())
86         verify(appWidgetHolder)
87             .startConfigActivity(launcher, appWidgetInfo.appWidgetId, requestCode)
88     }
89 
90     @Test
startConfigActivity_shouldAskLauncherToStartConfigActivitynull91     fun startConfigActivity_shouldAskLauncherToStartConfigActivity() {
92         flowHandler.startConfigActivity(launcher, appWidgetInfo, requestCode)
93         verify(launcher).setWaitingForResult(any())
94         verify(appWidgetHolder)
95             .startConfigActivity(launcher, appWidgetInfo.appWidgetId, requestCode)
96     }
97 
98     @Test
needsConfigure_returnsTrue_ifFlagsAndProviderInfoDetermineSonull99     fun needsConfigure_returnsTrue_ifFlagsAndProviderInfoDetermineSo() {
100         Truth.assertThat(flowHandler.needsConfigure()).isTrue()
101     }
102 
103     @Test
getProviderInfo_returnCorrectProviderInfonull104     fun getProviderInfo_returnCorrectProviderInfo() {
105         Truth.assertThat(flowHandler.getProviderInfo(context)).isSameInstanceAs(providerInfo)
106     }
107 }
108