Skip to content

[tests] Cover WebView JavaScript annotations - #12608

Open
simonrozsival wants to merge 6 commits into
mainfrom
simonrozsival-nativeaot-webview-annotation
Open

[tests] Cover WebView JavaScript annotations#12608
simonrozsival wants to merge 6 commits into
mainfrom
simonrozsival-nativeaot-webview-annotation

Conversation

@simonrozsival

@simonrozsival simonrozsival 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>
Copilot AI lite review requested due to automatic review settings September 1, 2026 01:10

Copilot AI 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)
Severity Finding
Medium severity tests/​MSBuildDeviceIntegration/​Tests/​WebViewJavascriptInterfaceTests.cs — 💡 suggestion — The bridge method increments an invocation counter, but the test’s “invoke once”…
Low severity 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 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.
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.

Comment thread src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Utilities/DexUtils.cs Outdated
simonrozsival and 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
Member Author

/review

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12608

@github-actions github-actions Bot 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 thread tests/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
Member Author

/review

@github-actions

github-actions Bot 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-actions github-actions Bot 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
Member Author

/review

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12608

@github-actions github-actions Bot 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

const string SuccessMarker = "# JAVASCRIPT_INTERFACE_RESULT ";
const string FailureMarker = "# JAVASCRIPT_INTERFACE_FAILURE ";

[Test]

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.

🤖 💡 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants