Closed Bug 2037911 Opened 6 months ago Closed 6 months ago

Refactor tests and code to prevent using Robolectric ReflectionHelpers

Categories

(Firefox for Android :: Tooling, task)

All
Android
task

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: mcarare, Assigned: mcarare)

References

Details

(Whiteboard: [fxdroid][group6] )

Attachments

(1 external file)

https://developer.android.com/about/versions/17/behavior-changes-17#static-final-fields

Apps running on Android 17 or higher that target Android 17 (API level 37) or higher cannot change static final fields. If an app attempts to change a static final field by using reflection, it will cause an IllegalAccessException. Attempting to modify one of these fields through JNI APIs (such as SetStaticLongField()) will cause the app to crash.

Multiple tests (e.g., WindowTest.kt, AdaptiveIconProcessorTest.kt) use Robolectric's ReflectionHelpers.setStaticField to mock Build.VERSION.SDK_INT. These tests will likely fail when executed against an Android 17 runtime environment.

  • Removed manual reflection-based overrides of Build.VERSION.SDK_INT and associated setup/teardown methods.
  • Adjusted WindowTest to properly initialize STATUS_BAR_COLOR and mock WindowInsetsController for API 29 compatibility.
  • Updated exception handling assertions in MediaSessionServiceDelegateTest to reflect realistic behaviors for different SDK levels.
Pushed by mcarare@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/4f5b9474d688 https://hg.mozilla.org/integration/autoland/rev/a0cd53d60e84 Refactor unit tests to use Robolectric's `@Config(sdk = ...)` annotation instead of manually mocking `Build.VERSION.SDK_INT`. r=android-reviewers,giorga
Status: ASSIGNED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch
Depends on: 2038949
No longer depends on: 2038949
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: