For #27635 - New telemetry for Save to PDF failures

This commit is contained in:
DreVla 2022-11-02 11:52:38 -04:00 committed by mergify[bot]
parent 063f00ca95
commit 27c34cecbf
3 changed files with 63 additions and 6 deletions

View File

@ -468,6 +468,23 @@ events:
metadata:
tags:
- Sharing
save_to_pdf_failure:
type: event
description: |
A user tapped the save pdf but an error ocurred
and the process failed.
bugs:
- https://github.com/mozilla-mobile/fenix/issues/27635
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/27661#issuecomment-1300505370
data_sensitivity:
- technical
notification_emails:
- android-probes@mozilla.com
expires: 122
metadata:
tags:
- Sharing
onboarding:
syn_cfr_shown:

View File

@ -7,17 +7,16 @@ package org.mozilla.fenix.share
import android.content.Context
import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import mozilla.components.browser.state.action.BrowserAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.Middleware
import mozilla.components.lib.state.MiddlewareContext
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.R
import org.mozilla.gecko.util.ThreadUtils
/**
* [BrowserAction] middleware reacting in response to Save to PDF related [Action]s.
@ -27,7 +26,6 @@ class SaveToPDFMiddleware(
private val context: Context,
) : Middleware<BrowserState, BrowserAction> {
@OptIn(DelicateCoroutinesApi::class)
override fun invoke(
ctx: MiddlewareContext<BrowserState, BrowserAction>,
next: (BrowserAction) -> Unit,
@ -36,9 +34,10 @@ class SaveToPDFMiddleware(
if (action is EngineAction.SaveToPdfExceptionAction) {
// See https://github.com/mozilla-mobile/fenix/issues/27649 for more details,
// why a Toast is used here.
GlobalScope.launch(Dispatchers.Main) {
ThreadUtils.runOnUiThread {
Toast.makeText(context, R.string.unable_to_save_to_pdf_error, LENGTH_LONG).show()
}
Events.saveToPdfFailure.record(NoExtras())
} else {
next(action)
}

View File

@ -0,0 +1,41 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.share
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.service.glean.testing.GleanTestRule
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule
import mozilla.components.support.test.rule.runTestOnMain
import org.junit.Assert.assertNotNull
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class SaveToPDFMiddlewareTest {
@get:Rule
val gleanTestRule = GleanTestRule(testContext)
@get:Rule
val mainCoroutineTestRule = MainCoroutineRule()
@Test
fun `GIVEN a save to pdf request WHEN it fails THEN telemetry is sent`() = runTestOnMain {
val middleware = SaveToPDFMiddleware(testContext)
val browserStore = BrowserStore(middleware = listOf(middleware))
browserStore.dispatch(EngineAction.SaveToPdfExceptionAction("14", RuntimeException("reader save to pdf failed")))
browserStore.waitUntilIdle()
testScheduler.advanceUntilIdle()
assertNotNull(Events.saveToPdfFailure.testGetValue())
}
}