Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 committed Apr 16, 2020
1 parent a5cdf61 commit 05f8313
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ internal class SupportedAddonsWorker(
}

withContext(Dispatchers.Main) {
newSupportedAddons.map {
addonManager.enableAddon(it, source = EnableSource.APP_SUPPORT)
newSupportedAddons.forEach {
addonManager.enableAddon(it, source = EnableSource.APP_SUPPORT, onError = { error ->
GlobalAddonDependencyProvider.onCrash?.invoke(error)
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@ import mozilla.components.feature.addons.ui.translatedName
import mozilla.components.support.base.ids.SharedIdsHelper
import mozilla.components.support.ktx.android.content.appName
import mozilla.components.support.test.mock
import mozilla.components.support.test.eq
import mozilla.components.support.test.any
import mozilla.components.support.test.argumentCaptor
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule
import mozilla.components.support.test.whenever
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.verify
import java.io.IOException
import java.lang.Exception

@RunWith(AndroidJUnit4::class)
class SupportedAddonsWorkerTest {
Expand All @@ -58,15 +63,19 @@ class SupportedAddonsWorkerTest {
fun `doWork - will return Result_success and create a notification when a new supported add-on is found`() {
val addonManager = mock<AddonManager>()
val worker = TestListenableWorkerBuilder<SupportedAddonsWorker>(testContext).build()

var throwable: Throwable? = null
val onCrash = { caught: Throwable ->
throwable = caught
}
val unsupportedAddon = mock<Addon> {
whenever(translatableName).thenReturn(mapOf(Addon.DEFAULT_LOCALE to "one"))
whenever(isSupported()).thenReturn(true)
whenever(isDisabledAsUnsupported()).thenReturn(true)
whenever(defaultLocale).thenReturn(Addon.DEFAULT_LOCALE)
}

GlobalAddonDependencyProvider.initialize(addonManager, mock())
GlobalAddonDependencyProvider.initialize(addonManager, mock(), onCrash)
val onErrorCaptor = argumentCaptor<((Throwable) -> Unit)>()

runBlocking {
whenever(addonManager.getAddons()).thenReturn(listOf(unsupportedAddon))
Expand All @@ -76,7 +85,10 @@ class SupportedAddonsWorkerTest {

val notificationId = SharedIdsHelper.getIdForTag(testContext, NOTIFICATION_TAG)
assertTrue(isNotificationVisible(notificationId))
verify(addonManager).enableAddon(unsupportedAddon, source = EnableSource.APP_SUPPORT)
verify(addonManager).enableAddon(eq(unsupportedAddon), source = eq(EnableSource.APP_SUPPORT), onSuccess = any(), onError = onErrorCaptor.capture())

onErrorCaptor.value.invoke(Exception())
assertNotNull(throwable!!)
}
}

Expand Down

0 comments on commit 05f8313

Please sign in to comment.