Backed out changeset 9976b7730dbd (bug 1893120) for causing lint failures CLOSED TREE

This commit is contained in:
acseh
2024-05-14 12:57:36 +03:00
parent 23c464a0e2
commit 3f4b08c594
90 changed files with 100 additions and 521 deletions

View File

@@ -19,7 +19,6 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mockito.`when`
import org.robolectric.annotation.Config
import java.io.IOException
import java.io.OutputStream
@@ -58,36 +57,6 @@ class IconDiskCacheTest {
assertEquals(resources, restoredResources)
}
@Test
@Config(sdk = [28])
fun `Writing and reading bitmap bytes on SDK 28`() {
val cache = IconDiskCache()
val resource = IconRequest.Resource(
url = "https://www.mozilla.org/icon64.png",
sizes = listOf(Size(64, 64)),
mimeType = "image/png",
type = IconRequest.Resource.Type.FAVICON,
)
val bitmap: Bitmap = mock()
`when`(bitmap.compress(any(), anyInt(), any())).thenAnswer {
@Suppress("DEPRECATION")
assertEquals(Bitmap.CompressFormat.WEBP, it.arguments[0] as Bitmap.CompressFormat)
assertEquals(90, it.arguments[1] as Int) // Quality
val stream = it.arguments[2] as OutputStream
stream.write("Hello World".toByteArray())
true
}
cache.putIconBitmap(testContext, resource, bitmap)
val data = cache.getIconData(testContext, resource)
assertNotNull(data!!)
assertEquals("Hello World", String(data))
}
@Test
fun `Writing and reading bitmap bytes`() {
val cache = IconDiskCache()
@@ -101,7 +70,9 @@ class IconDiskCacheTest {
val bitmap: Bitmap = mock()
`when`(bitmap.compress(any(), anyInt(), any())).thenAnswer {
assertEquals(Bitmap.CompressFormat.WEBP_LOSSY, it.arguments[0] as Bitmap.CompressFormat)
@Suppress("DEPRECATION")
// Deprecation will be handled in https://github.com/mozilla-mobile/android-components/issues/9555
assertEquals(Bitmap.CompressFormat.WEBP, it.arguments[0] as Bitmap.CompressFormat)
assertEquals(90, it.arguments[1] as Int) // Quality
val stream = it.arguments[2] as OutputStream

View File

@@ -60,7 +60,6 @@ import org.mockito.Mockito.spy
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
class CustomTabsToolbarFeatureTest {
@@ -127,46 +126,6 @@ class CustomTabsToolbarFeatureTest {
assertFalse(toolbar.display.onUrlClicked.invoke())
}
@Test
@Config(sdk = [28])
fun `initialize updates toolbar, window and text color on SDK 28`() {
val tab = createCustomTab(
"https://www.mozilla.org",
id = "mozilla",
config = CustomTabConfig(
colorSchemes = ColorSchemes(
defaultColorSchemeParams = ColorSchemeParams(
toolbarColor = Color.RED,
navigationBarColor = Color.BLUE,
),
),
),
)
val store = BrowserStore(
BrowserState(
customTabs = listOf(tab),
),
)
val toolbar = spy(BrowserToolbar(testContext))
val useCases = CustomTabsUseCases(
store = store,
loadUrlUseCase = SessionUseCases(store).loadUrl,
)
val window: Window = mock()
`when`(window.decorView).thenReturn(mock())
val feature = CustomTabsToolbarFeature(store, toolbar, sessionId = "mozilla", useCases = useCases, window = window) {}
feature.init(tab.config)
verify(toolbar).setBackgroundColor(Color.RED)
verify(window).statusBarColor = Color.RED
verify(window).navigationBarColor = Color.BLUE
assertEquals(Color.WHITE, toolbar.display.colors.title)
assertEquals(Color.WHITE, toolbar.display.colors.text)
}
@Test
fun `initialize updates toolbar, window and text color`() {
val tab = createCustomTab(
@@ -194,8 +153,6 @@ class CustomTabsToolbarFeatureTest {
)
val window: Window = mock()
`when`(window.decorView).thenReturn(mock())
`when`(window.insetsController).thenReturn(mock())
val feature = CustomTabsToolbarFeature(store, toolbar, sessionId = "mozilla", useCases = useCases, window = window) {}
feature.init(tab.config)
@@ -232,7 +189,6 @@ class CustomTabsToolbarFeatureTest {
)
val window: Window = mock()
`when`(window.decorView).thenReturn(mock())
`when`(window.insetsController).thenReturn(mock())
run {
val feature = CustomTabsToolbarFeature(

View File

@@ -1374,8 +1374,7 @@ class AbstractFetchDownloadServiceTest {
}
@Test
@Config(sdk = [28])
fun `onDestroy cancels all running jobs when using legacy file stream`() = runBlocking {
fun `onDestroy cancels all running jobs`() = runBlocking {
val download = DownloadState("https://example.com/file.txt", "file.txt")
val response = Response(
"https://example.com/file.txt",
@@ -1575,7 +1574,6 @@ class AbstractFetchDownloadServiceTest {
}
@Test
@Config(sdk = [28])
fun `WHEN a download is completed and the scoped storage is not used it MUST be added manually to the download system database`() = runTest(testsDispatcher) {
val download = DownloadState(
url = "http://www.mozilla.org",
@@ -1608,39 +1606,6 @@ class AbstractFetchDownloadServiceTest {
)
}
@Test
fun `WHEN a download is completed and the scoped storage is NOT not used it MUST NOT be added manually to the download system database`() = runTest(testsDispatcher) {
val download = DownloadState(
url = "http://www.mozilla.org",
fileName = "example.apk",
destinationDirectory = folder.root.path,
status = DownloadState.Status.COMPLETED,
)
val service = spy(
object : AbstractFetchDownloadService() {
override val httpClient = client
override val store = browserStore
override val notificationsDelegate = this@AbstractFetchDownloadServiceTest.notificationsDelegate
},
)
val downloadJobState = DownloadJobState(state = download, status = DownloadState.Status.COMPLETED)
doReturn(testContext).`when`(service).context
service.updateDownloadNotification(DownloadState.Status.COMPLETED, downloadJobState, this)
verify(service, never()).addCompletedDownload(
title = any(),
description = any(),
isMediaScannerScannable = anyBoolean(),
mimeType = any(),
path = any(),
length = anyLong(),
showNotification = anyBoolean(),
download = any(),
)
}
@Test
fun `WHEN a download is completed and the scoped storage is used addToDownloadSystemDatabaseCompat MUST NOT be called`() = runTest(testsDispatcher) {
val download = DownloadState(
@@ -1730,8 +1695,7 @@ class AbstractFetchDownloadServiceTest {
@Test
@Suppress("Deprecation")
@Config(sdk = [28])
fun `WHEN scoped storage is used do not pass non-http(s) url to addCompletedDownload`() = runTest(testsDispatcher) {
fun `do not pass non-http(s) url to addCompletedDownload`() = runTest(testsDispatcher) {
val download = DownloadState(
url = "blob:moz-extension://d5ea9baa-64c9-4c3d-bb38-49308c47997c/",
fileName = "example.apk",
@@ -1795,8 +1759,7 @@ class AbstractFetchDownloadServiceTest {
@Test
@Suppress("Deprecation")
@Config(sdk = [28])
fun `WHEN scoped storage is used pass http(s) url to addCompletedDownload`() = runTest(testsDispatcher) {
fun `pass http(s) url to addCompletedDownload`() = runTest(testsDispatcher) {
val download = DownloadState(
url = "https://mozilla.com",
fileName = "example.apk",
@@ -1818,23 +1781,12 @@ class AbstractFetchDownloadServiceTest {
doReturn(downloadManager).`when`(spyContext).getSystemService<DownloadManager>()
service.addToDownloadSystemDatabaseCompat(download, this)
verify(downloadManager).addCompletedDownload(
eq("example.apk"),
eq("example.apk"),
eq(true),
eq("*/*"),
anyString(),
eq(0L),
eq(false),
eq("https://mozilla.com".toUri()),
eq(null),
)
verify(downloadManager).addCompletedDownload(anyString(), anyString(), anyBoolean(), anyString(), anyString(), anyLong(), anyBoolean(), any(), any())
}
@Test
@Suppress("Deprecation")
@Config(sdk = [28])
fun `WHEN scoped storage is used ALWAYS call addCompletedDownload with a not empty or null mimeType`() = runTest(testsDispatcher) {
fun `always call addCompletedDownload with a not empty or null mimeType`() = runTest(testsDispatcher) {
val service = spy(
object : AbstractFetchDownloadService() {
override val httpClient = client
@@ -1870,44 +1822,6 @@ class AbstractFetchDownloadServiceTest {
)
}
@Test
@Suppress("Deprecation")
fun `WHEN scoped storage is NOT used NEVER call addCompletedDownload with a not empty or null mimeType`() = runTest(testsDispatcher) {
val service = spy(
object : AbstractFetchDownloadService() {
override val httpClient = client
override val store = browserStore
override val notificationsDelegate = this@AbstractFetchDownloadServiceTest.notificationsDelegate
},
)
val spyContext = spy(testContext)
var downloadManager: DownloadManager = mock()
doReturn(spyContext).`when`(service).context
doReturn(downloadManager).`when`(spyContext).getSystemService<DownloadManager>()
val downloadWithNullMimeType = DownloadState(
url = "blob:moz-extension://d5ea9baa-64c9-4c3d-bb38-49308c47997c/",
fileName = "example.apk",
destinationDirectory = folder.root.path,
contentType = null,
)
val downloadWithEmptyMimeType = downloadWithNullMimeType.copy(contentType = "")
val defaultMimeType = "*/*"
service.addToDownloadSystemDatabaseCompat(downloadWithNullMimeType, this)
verify(downloadManager, never()).addCompletedDownload(
anyString(), anyString(), anyBoolean(), eq(defaultMimeType),
anyString(), anyLong(), anyBoolean(), isNull(), any(),
)
downloadManager = mock()
doReturn(downloadManager).`when`(spyContext).getSystemService<DownloadManager>()
service.addToDownloadSystemDatabaseCompat(downloadWithEmptyMimeType, this)
verify(downloadManager, never()).addCompletedDownload(
anyString(), anyString(), anyBoolean(), eq(defaultMimeType),
anyString(), anyLong(), anyBoolean(), isNull(), any(),
)
}
@Test
fun `cancelled download does not prevent other notifications`() = runBlocking {
val cancelledDownload = DownloadState("https://example.com/file.txt", "file.txt")

View File

@@ -46,7 +46,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mockito.doNothing
@@ -56,7 +55,6 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.robolectric.annotation.Config
import org.robolectric.shadows.ShadowToast
@RunWith(AndroidJUnit4::class)
@@ -739,8 +737,7 @@ class DownloadsFeatureTest {
}
@Test
@Config(sdk = [32])
fun `when url is data url return only our app as downloader app on SDK 32 or less`() {
fun `when url is data url return only our app as downloader app`() {
val context = mock<Context>()
val download = DownloadState(url = "data:", sessionId = "test-tab")
val app = mock<ResolveInfo>()
@@ -790,62 +787,6 @@ class DownloadsFeatureTest {
assertEquals(ourApp, appList[0])
}
@Test
fun `when url is data url return only our app as downloader app`() {
val context = mock<Context>()
val download = DownloadState(url = "data:", sessionId = "test-tab")
val app = mock<ResolveInfo>()
val activityInfo = mock<ActivityInfo>()
app.activityInfo = activityInfo
val nonLocalizedLabel = "nonLocalizedLabel"
val packageName = "packageName"
val appName = "Fenix"
activityInfo.packageName = packageName
activityInfo.name = appName
activityInfo.exported = true
val packageManager = mock<PackageManager>()
whenever(context.packageManager).thenReturn(packageManager)
whenever(context.packageName).thenReturn(packageName)
whenever(app.loadLabel(packageManager)).thenReturn(nonLocalizedLabel)
val ourApp = DownloaderApp(
nonLocalizedLabel,
app,
packageName,
appName,
download.url,
download.contentType,
)
val mockList = listOf(app)
whenever(
packageManager.queryIntentActivities(
any(),
ArgumentMatchers.any(PackageManager.ResolveInfoFlags::class.java),
),
).thenReturn(mockList)
val downloadManager: DownloadManager = mock()
val feature = DownloadsFeature(
context,
store,
DownloadsUseCases(store),
downloadManager = downloadManager,
shouldForwardToThirdParties = { true },
)
val appList = feature.getDownloaderApps(context, download)
assertTrue(download.url.startsWith("data:"))
assertEquals(1, appList.size)
assertEquals(ourApp, appList[0])
}
@Test
fun `showAppDownloaderDialog MUST setup and show the dialog`() {
val tab = createTab("https://www.mozilla.org", id = "test-tab")

View File

@@ -45,7 +45,6 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoInteractions
import org.robolectric.annotation.Config
import java.io.File
@RunWith(AndroidJUnit4::class)
@@ -130,27 +129,6 @@ class FilePickerTest {
verify(fragment, never()).startActivityForResult(Intent(), 1)
}
@Test
@Config(sdk = [28])
fun `handleFilePickerRequest with the required permission will call startActivityForResult on SDK 28`() {
var onRequestPermissionWasCalled = false
filePicker = FilePicker(
fragment,
store,
fileUploadsDirCleaner = mock(),
) {
onRequestPermissionWasCalled = true
}
grantPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
filePicker.handleFileRequest(request)
assertFalse(onRequestPermissionWasCalled)
verify(fragment).startActivityForResult(any(), anyInt())
}
@Test
fun `handleFilePickerRequest with the required permission will call startActivityForResult`() {
var onRequestPermissionWasCalled = false
@@ -163,11 +141,7 @@ class FilePickerTest {
onRequestPermissionWasCalled = true
}
grantPermission(
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_VIDEO,
)
grantPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
filePicker.handleFileRequest(request)
@@ -347,38 +321,21 @@ class FilePickerTest {
fun `handleFilePickerIntentResult called with null Intent will make captureUri null`() {
stubContext()
captureUri = "randomSaveLocationOnDisk".toUri()
val onSingleFileSelection: (Context, Uri) -> Unit = { _, _ -> Unit }
val promptRequest = mock<PromptRequest.File>()
doReturn(noopSingle).`when`(promptRequest).onSingleFileSelected
doReturn(onSingleFileSelection).`when`(promptRequest).onSingleFileSelected
filePicker.handleFilePickerIntentResult(null, promptRequest)
assertNull(captureUri)
}
@Test
@Config(sdk = [29])
fun `handleFilePickerIntentResult called with valid Intent will make captureUri null also if request is dismissed on SDK 29 and below`() {
stubContext()
captureUri = "randomSaveLocationOnDisk".toUri()
val promptRequest = mock<PromptRequest.File>()
doReturn({ }).`when`(promptRequest).onDismiss
// A private file cannot be picked so the request will be dismissed.
val intent = Intent().apply {
data = ("file://" + File(testContext.applicationInfo.dataDir, "randomFile").canonicalPath).toUri()
}
filePicker.handleFilePickerIntentResult(intent, promptRequest)
assertNull(captureUri)
}
@Test
fun `handleFilePickerIntentResult called with valid Intent will make captureUri null also if request is dismissed`() {
stubContext()
captureUri = "randomSaveLocationOnDisk".toUri()
val promptRequest = mock<PromptRequest.File>()
doReturn({ }).`when`(promptRequest).onDismiss
doReturn(noopSingle).`when`(promptRequest).onSingleFileSelected
// A private file cannot be picked so the request will be dismissed.
val intent = Intent().apply {
data = ("file://" + File(testContext.applicationInfo.dataDir, "randomFile").canonicalPath).toUri()
@@ -393,8 +350,9 @@ class FilePickerTest {
fun `handleFilePickerIntentResult for multiple files selection will make captureUri null`() {
stubContext()
captureUri = "randomSaveLocationOnDisk".toUri()
val onMultipleFilesSelected: (Context, Array<Uri>) -> Unit = { _, _ -> Unit }
val promptRequest = mock<PromptRequest.File>()
doReturn(noopMulti).`when`(promptRequest).onMultipleFilesSelected
doReturn(onMultipleFilesSelected).`when`(promptRequest).onMultipleFilesSelected
doReturn(true).`when`(promptRequest).isMultipleFilesSelection
val intent = Intent().apply {
clipData = (ClipData.newRawUri("Test", "https://www.mozilla.org".toUri()))
@@ -406,29 +364,6 @@ class FilePickerTest {
assertNull(captureUri)
}
@Test
@Config(sdk = [29])
fun `handleFilePickerIntentResult for multiple files selection will make captureUri null also if request is dismissed on SDK 29 and below`() {
stubContext()
captureUri = "randomSaveLocationOnDisk".toUri()
val promptRequest = mock<PromptRequest.File>()
doReturn({ }).`when`(promptRequest).onDismiss
doReturn(true).`when`(promptRequest).isMultipleFilesSelection
// A private file cannot be picked so the request will be dismissed.
val intent = Intent().apply {
clipData = (
ClipData.newRawUri(
"Test",
("file://" + File(testContext.applicationInfo.dataDir, "randomFile").canonicalPath).toUri(),
)
)
}
filePicker.handleFilePickerIntentResult(intent, promptRequest)
assertNull(captureUri)
}
@Test
fun `handleFilePickerIntentResult for multiple files selection will make captureUri null also if request is dismissed`() {
stubContext()
@@ -436,8 +371,6 @@ class FilePickerTest {
val promptRequest = mock<PromptRequest.File>()
doReturn({ }).`when`(promptRequest).onDismiss
doReturn(true).`when`(promptRequest).isMultipleFilesSelection
doReturn(noopMulti).`when`(promptRequest).onMultipleFilesSelected
// A private file cannot be picked so the request will be dismissed.
val intent = Intent().apply {
clipData = (

View File

@@ -9,7 +9,6 @@ import android.content.pm.ActivityInfo
import android.os.Looper.getMainLooper
import android.view.View
import android.view.Window
import android.view.WindowInsetsController
import android.view.WindowManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.CompletableDeferred
@@ -26,7 +25,6 @@ import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations.openMocks
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
class WebAppActivityFeatureTest {
@@ -37,8 +35,6 @@ class WebAppActivityFeatureTest {
@Mock private lateinit var decorView: View
@Mock private lateinit var insetsController: WindowInsetsController
@Mock private lateinit var layoutParams: WindowManager.LayoutParams
@Mock private lateinit var icons: BrowserIcons
@@ -50,30 +46,11 @@ class WebAppActivityFeatureTest {
`when`(activity.window).thenReturn(window)
`when`(window.decorView).thenReturn(decorView)
`when`(window.attributes).thenReturn(layoutParams)
`when`(icons.loadIcon(any())).thenReturn(CompletableDeferred(mock<Icon>()))
}
@Test
@Config(sdk = [28])
fun `enters immersive mode only when display mode is fullscreen on SDK 28`() {
val basicManifest = WebAppManifest(
name = "Demo",
startUrl = "https://mozilla.com",
display = WebAppManifest.DisplayMode.STANDALONE,
)
WebAppActivityFeature(activity, icons, basicManifest).onResume(mock())
val fullscreenManifest = basicManifest.copy(
display = WebAppManifest.DisplayMode.FULLSCREEN,
)
WebAppActivityFeature(activity, icons, fullscreenManifest).onResume(mock())
}
@Test
fun `enters immersive mode only when display mode is fullscreen`() {
`when`(window.insetsController).thenReturn(insetsController)
val basicManifest = WebAppManifest(
name = "Demo",
startUrl = "https://mozilla.com",
@@ -100,6 +77,7 @@ class WebAppActivityFeatureTest {
verify(activity).requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
}
@Suppress("Deprecation")
@Test
fun `sets task description`() {
val manifest = WebAppManifest(

View File

@@ -7,9 +7,6 @@ package mozilla.components.feature.qr
import android.Manifest.permission
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.Insets
import android.graphics.Point
import android.graphics.Rect
import android.hardware.camera2.CameraAccessException
import android.hardware.camera2.CameraCaptureSession
import android.hardware.camera2.CameraDevice
@@ -24,11 +21,8 @@ import android.util.Size
import android.view.Display
import android.view.Surface
import android.view.View
import android.view.WindowInsets
import android.view.WindowManager
import android.view.WindowMetrics
import android.widget.TextView
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.FragmentActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.zxing.BarcodeFormat
@@ -655,7 +649,6 @@ class QrFragmentTest {
@Test
@Suppress("DEPRECATION")
@Config(sdk = [29])
fun `GIVEN a device rotation of 90 deg WHEN getting the device rotation on a device below SDK 30 THEN the rotation should be 90 deg`() {
val mockActivity: FragmentActivity = mock()
val mockManager: WindowManager = mock()
@@ -677,25 +670,7 @@ class QrFragmentTest {
}
@Test
fun `GIVEN a device rotation of 90 deg WHEN getting the device rotation on a device above SDK 30 THEN the rotation should be 90 deg`() {
val mockActivity: FragmentActivity = mock()
val mockDisplay: Display = mock()
val testRotation = Surface.ROTATION_90
val listener = mock<QrFragment.OnScanCompleteListener>()
val qrFragment = spy(QrFragment.newInstance(listener))
whenever(qrFragment.context).thenReturn(mockActivity)
whenever(mockActivity.display).thenReturn(mockDisplay)
whenever(mockDisplay.rotation).thenReturn(testRotation)
val rotation = qrFragment.getScreenRotation()
assertEquals(testRotation, rotation)
}
@Test
@Suppress("DEPRECATION")
fun `configureTransform uses getScreenRotation method to get rotation`() {
val listener = mock<QrFragment.OnScanCompleteListener>()
val qrFragment = spy(QrFragment.newInstance(listener))
@@ -710,6 +685,7 @@ class QrFragmentTest {
}
@Test
@Suppress("DEPRECATION")
fun `setUpCameraOutputs uses getScreenRotation method to get rotation`() {
val listener = mock<QrFragment.OnScanCompleteListener>()
val qrFragment = spy(QrFragment.newInstance(listener))
@@ -721,7 +697,6 @@ class QrFragmentTest {
@Test
@Suppress("DEPRECATION")
@Config(sdk = [29])
fun `getDisplaySize calls defaultDisplay getSize for SDK below 30`() {
val mockActivity: FragmentActivity = mock()
val mockManager: WindowManager = mock()
@@ -736,31 +711,6 @@ class QrFragmentTest {
verify(mockDisplay, times(1)).getSize(any())
}
@Test
fun `test getDisplaySize for SDK 30 and up`() {
val mockManager: WindowManager = mock()
val mockWindowMetrics: WindowMetrics = mock()
val bounds = Rect(0, 0, 170, 270)
val insets = Insets.of(10, 10, 10, 10)
val expectedSize = Point(150, 250)
val mockWindowInsets: WindowInsets = mock()
whenever(
mockWindowInsets.getInsetsIgnoringVisibility(
WindowInsetsCompat.Type.navigationBars() or WindowInsetsCompat.Type.displayCutout(),
),
).thenReturn(insets)
whenever(mockManager.currentWindowMetrics).thenReturn(mockWindowMetrics)
whenever(mockWindowMetrics.windowInsets).thenReturn(mockWindowInsets)
whenever(mockWindowMetrics.bounds).thenReturn(bounds)
val result = mockManager.getDisplaySize()
assertEquals(expectedSize, result)
}
@Test
fun `maybeStartBackgroundThread does nothing if the thread already exists`() {
val qrFragment = QrFragment()

View File

@@ -12,7 +12,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.lib.crash.Crash
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.support.base.android.NotificationsDelegate
import mozilla.components.support.test.any
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.whenever
import org.junit.Assert.assertEquals
@@ -20,11 +19,8 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.anyBoolean
import org.mockito.Mockito.doNothing
import org.mockito.Mockito.spy
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
class CrashNotificationTest {
@@ -145,8 +141,7 @@ class CrashNotificationTest {
}
@Test
@Config(sdk = [32])
fun `not showing notification when permission is denied on SDK 32 and below`() {
fun `not showing notification when permission is denied`() {
val notificationManager = testContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val shadowNotificationManager = shadowOf(notificationManager)
@@ -158,43 +153,6 @@ class CrashNotificationTest {
val notificationsDelegate = spy(NotificationsDelegate(notificationManagerCompat))
whenever(notificationManagerCompat.areNotificationsEnabled()).thenReturn(false)
doNothing().`when`(notificationsDelegate)
.requestNotificationPermission(any(), any(), anyBoolean())
val crashNotification = CrashNotification(
testContext,
crash,
CrashReporter.PromptConfiguration(
appName = "TestApp",
),
notificationsDelegate = notificationsDelegate,
)
crashNotification.show()
assertEquals(1, shadowNotificationManager.notificationChannels.size)
assertEquals(
"Crashes",
(shadowNotificationManager.notificationChannels[0] as NotificationChannel).name,
)
assertEquals(0, shadowNotificationManager.size())
}
@Test
fun `not showing notification when permission is needed and denied`() {
val notificationManager = testContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val shadowNotificationManager = shadowOf(notificationManager)
assertEquals(0, shadowNotificationManager.notificationChannels.size)
assertEquals(0, shadowNotificationManager.size())
val crash = Crash.UncaughtExceptionCrash(0, RuntimeException("Boom"), arrayListOf())
val notificationManagerCompat = spy(NotificationManagerCompat.from(testContext))
val notificationsDelegate = spy(NotificationsDelegate(notificationManagerCompat))
whenever(notificationManagerCompat.areNotificationsEnabled()).thenReturn(false)
doNothing().`when`(notificationsDelegate)
.requestNotificationPermission(any(), any(), anyBoolean())
val crashNotification = CrashNotification(
testContext,

View File

@@ -16,7 +16,6 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mock
@@ -49,8 +48,7 @@ class AndroidAssetFinderTest {
}
@Test
@Config(sdk = [28])
fun `test getAndroidAppAsset returns empty list if name not found on SDK 28 or less`() {
fun `test getAndroidAppAsset returns empty list if name not found`() {
@Suppress("DEPRECATION")
`when`(packageManager.getPackageInfo(anyString(), anyInt()))
.thenThrow(PackageManager.NameNotFoundException::class.java)
@@ -61,22 +59,6 @@ class AndroidAssetFinderTest {
)
}
@Test
fun `test getAndroidAppAsset returns empty list if name not found`() {
`when`(
packageManager.getPackageInfo(
anyString(),
ArgumentMatchers.any(PackageManager.PackageInfoFlags::class.java),
),
)
.thenThrow(PackageManager.NameNotFoundException::class.java)
assertEquals(
emptyList<AssetDescriptor.Android>(),
assetFinder.getAndroidAppAsset("com.test.app", packageManager).toList(),
)
}
@Config(sdk = [Build.VERSION_CODES.P])
@Test
fun `test getAndroidAppAsset on P SDK`() {

View File

@@ -83,7 +83,6 @@ class ActivityTest {
}
@Test
@Config(sdk = [28])
fun `GIVEN enterImmersiveMode was called WHEN window insets are changed THEN insetsController hides system bars and sets bars behaviour again`() {
val insetListenerCaptor = argumentCaptor<View.OnApplyWindowInsetsListener>()
doReturn(30).`when`(windowInsets).systemWindowInsetTop

View File

@@ -15,7 +15,6 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
class BundleTest {
@@ -63,8 +62,7 @@ class BundleTest {
}
@Test
@Config(sdk = [32])
fun `getParcelableArrayCompat with unexpected type returns empty array and does not throw exception on SDK 32 and below`() {
fun `getParcelableArrayCompat with unexpected type returns empty array and does not throw exception`() {
val bundle = Bundle()
val testArray = Array(4) { Unexpected() }
@@ -77,8 +75,7 @@ class BundleTest {
}
@Test
@Config(sdk = [32])
fun `getParcelableArrayCompat with both expected unexpected type returns array with only expected on SDK 32 and below`() {
fun `getParcelableArrayCompat with both expected unexpected type returns array with only expected`() {
val bundle = Bundle()
val testArray = Array<Parcelable>(4) { Expected() }