[tests] Cover WebView JavaScript annotations - #12608
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Review tier: Lite
Findings: 1
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
tests/MSBuildDeviceIntegration/Tests/WebViewJavascriptInterfaceTests.cs — 💡 suggestion — The bridge method increments an invocation counter, but the test’s “invoke once”… |
|
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Utilities/DexUtils.cs — 💡 suggestion — ContainsRuntimeMethodAnnotation currently uses culture-implicit Contains checks… |
What changed in this PR
Adds an end-to-end MSBuildDeviceIntegration regression test to ensure [JavascriptInterface] is preserved through JCW Java source generation and retained as a runtime-visible DEX method annotation, covering the WebView JavaScript bridge scenario across llvm-ir/CoreCLR, trimmable/CoreCLR, and trimmable/NativeAOT.
Changes:
- Introduces a new device integration test app that loads local HTML in
WebViewand invokes a managed bridge viaaddJavascriptInterface. - Validates
[JavascriptInterface]presence in all generated JCW.javacopies and as aVISIBILITY_RUNTIMEmethod annotation inclasses.dex. - Extends
DexUtilswith a helper to detect runtime-visible method annotations viadexdump -a.
| File | Description |
|---|---|
| tests/MSBuildDeviceIntegration/Tests/WebViewJavascriptInterfaceTests.cs | Adds device integration coverage for WebView JS bridge + annotation retention checks (JCW Java + DEX + runtime logcat). |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Utilities/DexUtils.cs | Adds ContainsRuntimeMethodAnnotation helper and supports passing dexdump options. |
Use a JavaScript completion callback to observe the final report invocation count, and scope DEX annotation matching to the exact class and method with ordinal comparisons. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Associate each dexdump annotation block with the class descriptor emitted after it, tighten generated Java assertions to the annotated report method, and pass dexdump arguments without string quoting hazards. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Correlate dexdump annotations and descriptors by class index, keep stderr out of parser state, include diagnostics on process failures, and cover malformed and alternate output shapes with focused tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
Generated by Android PR Reviewer for #12608 · gpt56 · 96.4 AIC · ⌖ 19.3 AIC · ⊞ 25.7K
Comment /review to run again
Always attempt to uninstall a successfully installed test app, including assertion and startup failure paths, without masking the original failure if cleanup itself fails. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
Keep the end-to-end device tests and remove generated-source and DEX inspection infrastructure. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Generated by Android PR Reviewer for #12608 · gpt56 · 127.1 AIC · ⌖ 9.03 AIC · ⊞ 25.7K
Comment /review to run again
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ Needs Changes
Findings: 0 errors · 0 warnings · 1 suggestion
The end-to-end test is focused and verifies the callback payload, instance identity, dispatch count, timeout, and cleanup across the intended CoreCLR/NativeAOT type-map configurations. I left one inline suggestion to consolidate the duplicated NUnit wrappers.
CI is still in progress; at review time, two Azure DevOps jobs and the CLA check had passed, with no reported failures.
Generated by Android PR Reviewer for #12608 · gpt56 · 82.1 AIC · ⌖ 14.7 AIC · ⊞ 25.7K
Comment /review to run again
| const string SuccessMarker = "# JAVASCRIPT_INTERFACE_RESULT "; | ||
| const string FailureMarker = "# JAVASCRIPT_INTERFACE_FAILURE "; | ||
|
|
||
| [Test] |
There was a problem hiding this comment.
🤖 💡 Testing — Please consider expressing these three configurations as [TestCase (...)] cases on a single test method. That keeps the runtime/type-map matrix in NUnit metadata, removes the forwarding wrappers, and makes future matrix additions less likely to leave the method name and arguments out of sync.
Rule: Code consolidation


Summary
MSBuildDeviceIntegrationapp that loads deterministic local HTML inWebViewand calls a managed bridge throughaddJavascriptInterfacellvm-ir/CoreCLR, trimmable/CoreCLR, and trimmable/NativeAOTTracks the remaining annotation regression item in #12561 and adds end-to-end coverage for #12542 / #12549.
Regression evidence
With annotation emission disabled, the NativeAOT runtime case timed out. With production annotation emission restored, all three runtime cases passed.
Testing