-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add strictmode scenarios, handle disk write violation crash when pena…
…ltydeath is set
- Loading branch information
1 parent
c28a4ae
commit 5aa7bee
Showing
8 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Feature: Android support | ||
|
||
Scenario: Test handled Android Exception | ||
When I run "StrictModeDiscScenario" with the defaults | ||
Then I should receive a request | ||
And the request is a valid for the error reporting API | ||
And the exception "errorClass" equals "android.os.StrictMode$StrictModeViolation" | ||
And the exception "message" equals "policy=262145 violation=1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Feature: Android support | ||
|
||
Scenario: Test handled Android Exception | ||
When I run "StrictModeNetworkScenario" with the defaults | ||
Then I should receive a request | ||
And the request is a valid for the error reporting API | ||
And the exception "errorClass" equals "android.os.StrictMode$StrictModeViolation" | ||
And the exception "message" equals "policy=262145 violation=1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
mazerunner/src/main/java/com/bugsnag/android/mazerunner/TestCaseFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package com.bugsnag.android.mazerunner | ||
|
||
import android.content.Context | ||
import com.bugsnag.android.mazerunner.scenarios.Scenario | ||
|
||
internal class TestCaseFactory { | ||
|
||
fun testCaseForName(eventType: String?): Scenario { | ||
fun testCaseForName(eventType: String?, context: Context?): Scenario { | ||
val clz = Class.forName("com.bugsnag.android.mazerunner.scenarios.$eventType") | ||
return clz.newInstance() as Scenario | ||
val scenario = clz.newInstance() as Scenario | ||
scenario.context = context | ||
return scenario | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/Scenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/StrictModeDiscScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bugsnag.android.mazerunner.scenarios | ||
|
||
import android.os.StrictMode | ||
import java.io.File | ||
|
||
/** | ||
* Generates a strictmode exception caused by writing to disc on main thread | ||
*/ | ||
internal class StrictModeDiscScenario : Scenario() { | ||
|
||
override fun run() { | ||
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder() | ||
.detectDiskWrites() | ||
.penaltyDeath() | ||
.build()) | ||
val file = File(context?.cacheDir, "fake") | ||
file.writeBytes("test".toByteArray()) | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...unner/src/main/java/com/bugsnag/android/mazerunner/scenarios/StrictModeNetworkScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.bugsnag.android.mazerunner.scenarios | ||
|
||
import android.os.StrictMode | ||
import java.io.File | ||
|
||
/** | ||
* Generates a strictmode exception caused by writing to disc on main thread | ||
*/ | ||
internal class StrictModeNetworkScenario : Scenario() { | ||
|
||
override fun run() { | ||
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder() | ||
.detectDiskWrites() | ||
.penaltyDeath() | ||
.build()) | ||
val file = File(context?.cacheDir, "fake") | ||
file.writeBytes("test".toByteArray()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters