-
Notifications
You must be signed in to change notification settings - Fork 171
android: Add unit tests for CobaltService #7824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
/generate-commit-message |
🤖 Gemini Suggested Commit Message |
c343015 to
7ea4a3e
Compare
|
Remove Locale.US in CobaltService.java, the test will fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| @@ -0,0 +1,167 @@ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Remove empty line?
| String jsCodeTemplate = | ||
| "((w) => {\n" | ||
| + " let targetWindow = w;\n" | ||
| + " const appIframe = document.getElementById('anchor');\n" | ||
| + " if (appIframe?.contentWindow) {\n" | ||
| + " targetWindow = appIframe.contentWindow;\n" | ||
| + " }\n" | ||
| + " targetWindow.H5vccPlatformService.callbackFromAndroid(%d, '%s');\n" | ||
| + "})(window)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually one question - does it matter this content, as long as it's
valid JS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good point. This block has to exactly match the Java Bridge script. Any changes to the original script would result in this test failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good step forward
|
|
||
| } finally { | ||
| // Restore the original default locale to avoid affecting other tests. | ||
| Locale.setDefault(originalLocale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you would want to fail the test if any exception is thrown and the assertEquals doesn't get executed, right?
This change introduces unit tests for the CobaltService.sendToClient method
on Android. The tests verify that JavaScript code is consistently formatted
using Locale.US, preventing issues with locale-dependent number formatting.
Additionally, it ensures that the method handles a null CobaltActivity
gracefully without causing crashes.
Test log: https://paste.googleplex.com/6270902119563264
Bug: 455895170
Change-Id: I8811cad1da6d8d9016b3bf70e3ab09a7bd7a9899