Skip to content

Commit

Permalink
For mozilla-mobile#11670: Use explicit intent for setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed Mar 17, 2022
1 parent fcbb1dc commit d6d7e9a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.robolectric.Robolectric
class CrashHandlerServiceTest {
private var service: CrashHandlerService? = null
private var reporter: CrashReporter? = null
private var intent: Intent? = null
private val intent = Intent("org.mozilla.gecko.ACTION_CRASHED")

@get:Rule
val coroutinesTestRule = MainCoroutineRule()
Expand All @@ -41,7 +41,6 @@ class CrashHandlerServiceTest {
@Before
fun setUp() {
service = spy(Robolectric.setupService(CrashHandlerService::class.java))
service!!.startService(Intent())
reporter = spy(
CrashReporter(
context = testContext,
Expand All @@ -52,38 +51,39 @@ class CrashHandlerServiceTest {
)
).install(testContext)

intent = Intent("org.mozilla.gecko.ACTION_CRASHED")
intent!!.component = ComponentName(
intent.component = ComponentName(
"org.mozilla.samples.browser",
"mozilla.components.lib.crash.handler.CrashHandlerService"
)
intent!!.putExtra(
intent.putExtra(
"uuid",
"94f66ed7-50c7-41d1-96a7-299139a8c2af"
)
intent!!.putExtra(
intent.putExtra(
"minidumpPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.dmp"
)
intent!!.putExtra(
intent.putExtra(
"extrasPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.extra"
)
intent!!.putExtra("minidumpSuccess", true)
intent.putExtra("minidumpSuccess", true)

service!!.startService(intent)
}

@After
fun tearDown() {
service!!.stopService(Intent())
service!!.stopService(intent)
CrashReporter.reset()
}

@Test
fun `CrashHandlerService forwards main process native code crash to crash reporter`() = runBlocking {
doNothing().`when`(reporter)!!.sendCrashReport(any(), any())

intent!!.putExtra("processType", "MAIN")
service!!.handleCrashIntent(intent!!, scope)
intent.putExtra("processType", "MAIN")
service!!.handleCrashIntent(intent, scope)
verify(reporter)!!.onCrash(any(), any())
verify(reporter)!!.sendCrashReport(any(), any())
verify(reporter, never())!!.sendNonFatalCrashIntent(any(), any())
Expand All @@ -93,8 +93,8 @@ class CrashHandlerServiceTest {
fun `CrashHandlerService forwards foreground child process native code crash to crash reporter`() = runBlocking {
doNothing().`when`(reporter)!!.sendCrashReport(any(), any())

intent!!.putExtra("processType", "FOREGROUND_CHILD")
service!!.handleCrashIntent(intent!!, scope)
intent.putExtra("processType", "FOREGROUND_CHILD")
service!!.handleCrashIntent(intent, scope)
verify(reporter)!!.onCrash(any(), any())
verify(reporter)!!.sendNonFatalCrashIntent(any(), any())
verify(reporter, never())!!.sendCrashReport(any(), any())
Expand All @@ -104,8 +104,8 @@ class CrashHandlerServiceTest {
fun `CrashHandlerService forwards background child process native code crash to crash reporter`() = runBlocking {
doNothing().`when`(reporter)!!.sendCrashReport(any(), any())

intent!!.putExtra("processType", "BACKGROUND_CHILD")
service!!.handleCrashIntent(intent!!, scope)
intent.putExtra("processType", "BACKGROUND_CHILD")
service!!.handleCrashIntent(intent, scope)
verify(reporter)!!.onCrash(any(), any())
verify(reporter)!!.sendCrashReport(any(), any())
verify(reporter, never())!!.sendNonFatalCrashIntent(any(), any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,36 @@ import org.robolectric.Robolectric
@RunWith(AndroidJUnit4::class)
class SendCrashReportServiceTest {
private var service: SendCrashReportService? = null
private val intent = Intent("org.mozilla.gecko.ACTION_CRASHED")

@get:Rule
val coroutinesTestRule = MainCoroutineRule()
private val scope = TestCoroutineScope(coroutinesTestRule.testDispatcher)

@Before
fun setUp() {
intent.component = ComponentName(
"org.mozilla.samples.browser",
"mozilla.components.lib.crash.handler.CrashHandlerService"
)
intent.putExtra(
"minidumpPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.dmp"
)
intent.putExtra("fatal", false)
intent.putExtra(
"extrasPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.extra"
)
intent.putExtra("minidumpSuccess", true)
intent.putParcelableArrayListExtra("breadcrumbs", null)
service = spy(Robolectric.setupService(SendCrashReportService::class.java))
service?.startService(Intent())
service?.startService(intent)
}

@After
fun tearDown() {
service?.stopService(Intent())
service?.stopService(intent)
CrashReporter.reset()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,36 @@ import org.robolectric.Robolectric
@RunWith(AndroidJUnit4::class)
class SendCrashTelemetryServiceTest {
private var service: SendCrashTelemetryService? = null
private val intent = Intent("org.mozilla.gecko.ACTION_CRASHED")

@get:Rule
val coroutinesTestRule = MainCoroutineRule()
private val scope = TestCoroutineScope(coroutinesTestRule.testDispatcher)

@Before
fun setUp() {
intent.component = ComponentName(
"org.mozilla.samples.browser",
"mozilla.components.lib.crash.handler.CrashHandlerService"
)
intent.putExtra(
"minidumpPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.dmp"
)
intent.putExtra("fatal", false)
intent.putExtra(
"extrasPath",
"/data/data/org.mozilla.samples.browser/files/mozilla/Crash Reports/pending/3ba5f665-8422-dc8e-a88e-fc65c081d304.extra"
)
intent.putExtra("minidumpSuccess", true)
intent.putParcelableArrayListExtra("breadcrumbs", null)
service = spy(Robolectric.setupService(SendCrashTelemetryService::class.java))
service?.startService(Intent())
service?.startService(intent)
}

@After
fun tearDown() {
service?.stopService(Intent())
service?.stopService(intent)
CrashReporter.reset()
}

Expand Down

0 comments on commit d6d7e9a

Please sign in to comment.