3b307455a0
35b6d322ab
Change-Id: I3ed574a517dbe350b6dfe5b1d3ed198203d22f44
80 lines
2.7 KiB
Kotlin
80 lines
2.7 KiB
Kotlin
/*
|
|
* Copyright (C) 2024 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.android.launcher3.dagger
|
|
|
|
import android.content.Context
|
|
import android.content.ContextWrapper
|
|
import android.view.ContextThemeWrapper
|
|
import androidx.test.core.app.ApplicationProvider
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
import com.android.launcher3.R
|
|
import com.android.launcher3.util.LauncherModelHelper.TEST_PACKAGE
|
|
import com.android.launcher3.util.SandboxApplication
|
|
import org.junit.Assert.assertNotNull
|
|
import org.junit.Assert.assertNotSame
|
|
import org.junit.Assert.assertSame
|
|
import org.junit.Test
|
|
import org.junit.runner.RunWith
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
class LauncherComponentProviderTest {
|
|
|
|
val app: Context = ApplicationProvider.getApplicationContext()
|
|
|
|
@Test
|
|
fun `returns same component as Launcher application`() {
|
|
val c = SandboxApplication()
|
|
c.init()
|
|
try {
|
|
assertSame(c.appComponent, LauncherComponentProvider.get(c))
|
|
assertNotSame(LauncherComponentProvider.get(c), LauncherComponentProvider.get(app))
|
|
} finally {
|
|
c.onDestroy()
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun `returns same component for isolated context`() {
|
|
val c = IsolatedContext()
|
|
|
|
// Same component is returned for multiple calls, irrespective of the wrappers
|
|
assertNotNull(LauncherComponentProvider.get(c))
|
|
assertSame(
|
|
LauncherComponentProvider.get(c),
|
|
LauncherComponentProvider.get(ContextThemeWrapper(c, R.style.LauncherTheme)),
|
|
)
|
|
|
|
// Different than main application
|
|
assertNotSame(LauncherComponentProvider.get(c), LauncherComponentProvider.get(app))
|
|
}
|
|
|
|
@Test
|
|
fun `different components for different isolated context`() {
|
|
val c1 = IsolatedContext()
|
|
val c2 = IsolatedContext()
|
|
|
|
assertNotNull(LauncherComponentProvider.get(c1))
|
|
assertNotNull(LauncherComponentProvider.get(c2))
|
|
assertNotSame(LauncherComponentProvider.get(c1), LauncherComponentProvider.get(c2))
|
|
}
|
|
|
|
inner class IsolatedContext : ContextWrapper(app.createPackageContext(TEST_PACKAGE, 0)) {
|
|
|
|
override fun getApplicationContext(): Context = this
|
|
}
|
|
}
|