Skip to content

[tests] Cover WebView JavaScript annotations - #12608

Merged
simonrozsival merged 7 commits into
mainfrom
simonrozsival-nativeaot-webview-annotation
Sep 3, 2026
Merged

[tests] Cover WebView JavaScript annotations#12608
simonrozsival merged 7 commits into
mainfrom
simonrozsival-nativeaot-webview-annotation

Conversation

@simonrozsival

@simonrozsivalsimonrozsival commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

  • add a focused MSBuildDeviceIntegration app that loads deterministic local HTML in WebView and calls a managed bridge through addJavascriptInterface
  • exercise the runtime behavior with llvm-ir/CoreCLR, trimmable/CoreCLR, and trimmable/NativeAOT
  • assert the callback reaches the exact managed bridge instance once with the expected payload, with bounded timeout and device cleanup

Tracks 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

./dotnet-local.sh test bin/TestDebug/MSBuildDeviceIntegration/net10.0/MSBuildDeviceIntegration.dll \
--filter 'FullyQualifiedName~WebViewJavascriptInterfaceTests'
Passed: 3, Failed: 0, Skipped: 0

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
CopilotAI lite review requested due to automatic review settings September 1, 2026 01:10

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

Review tier: Lite
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
SeverityFinding
Medium severitytests/​MSBuildDeviceIntegration/​Tests/​WebViewJavascriptInterfaceTests.cs — 💡 suggestion — The bridge method increments an invocation counter, but the test’s “invoke once”…
Low severitysrc/​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 WebView and invokes a managed bridge via addJavascriptInterface.
  • Validates [JavascriptInterface] presence in all generated JCW .java copies and as a VISIBILITY_RUNTIME method annotation in classes.dex.
  • Extends DexUtils with a helper to detect runtime-visible method annotations via dexdump -a.
FileDescription
tests/​MSBuildDeviceIntegration/​Tests/​WebViewJavascriptInterfaceTests.csAdds 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.csAdds ContainsRuntimeMethodAnnotation helper and supports passing dexdump options.

simonrozsivaland others added 3 commits September 1, 2026 12:57
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>
@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/review

@github-actions

github-actionsBot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12608

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️Needs Changes — 0 errors, 0 warnings, 1 suggestion. The annotation parser is carefully scoped by class and method, and the regression coverage exercises all three intended runtime/type-map combinations. Please make device cleanup deterministic on failure paths. Azure DevOps build #1576521 is still in progress; all completed checks are passing.

Generated by Android PR Reviewer for #12608 · gpt56 · 96.4 AIC · ⌖ 19.3 AIC · ⊞ 25.7K
Comment /review to run again

Comment threadtests/MSBuildDeviceIntegration/Tests/WebViewJavascriptInterfaceTests.cs Outdated
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>
@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/review

@github-actions

github-actionsBot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12608

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>

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️Needs Changes — 0 errors, 1 warning, 0 suggestions. The parser state machine is well-scoped and its focused tests cover ordering, visibility, malformed input, and false-positive cases. The device regression also exercises the intended runtime/type-map combinations, but cleanup failure can currently be silently reported as a passing test. Azure DevOps build #1576616 is still in progress; the completed CLA and Android Tools Tests Mac checks are passing, with no failures reported yet.

Generated by Android PR Reviewer for #12608 · gpt56 · 127.1 AIC · ⌖ 9.03 AIC · ⊞ 25.7K
Comment /review to run again

@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/review

@github-actions

github-actionsBot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12608

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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

Comment threadtests/MSBuildDeviceIntegration/Tests/WebViewJavascriptInterfaceTests.cs Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsivalsimonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 3, 2026
@simonrozsival
simonrozsival merged commit b67366c into mainSep 3, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-nativeaot-webview-annotation branch September 3, 2026 13:14
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-reviewThis PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@simonrozsival@rolfbjarne@jonathanpeppers