Refactors platform_view_android_delegate test (#162696)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

Reduce magic number

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
chunhtai 2025-02-04 16:08:24 -08:00 committed by GitHub
parent dea13f8baf
commit b0d95460e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 10 deletions

View File

@ -44,12 +44,6 @@ PlatformViewAndroidDelegate::PlatformViewAndroidDelegate(
void PlatformViewAndroidDelegate::UpdateSemantics(
const flutter::SemanticsNodeUpdates& update,
const flutter::CustomAccessibilityActionUpdates& actions) {
constexpr size_t kBytesPerNode = 49 * sizeof(int32_t);
constexpr size_t kBytesPerChild = sizeof(int32_t);
constexpr size_t kBytesPerCustomAction = sizeof(int32_t);
constexpr size_t kBytesPerAction = 4 * sizeof(int32_t);
constexpr size_t kBytesPerStringAttribute = 4 * sizeof(int32_t);
{
size_t num_bytes = 0;
for (const auto& value : update) {

View File

@ -16,6 +16,11 @@ namespace flutter {
class PlatformViewAndroidDelegate {
public:
static constexpr size_t kBytesPerNode = 49 * sizeof(int32_t);
static constexpr size_t kBytesPerChild = sizeof(int32_t);
static constexpr size_t kBytesPerCustomAction = sizeof(int32_t);
static constexpr size_t kBytesPerAction = 4 * sizeof(int32_t);
static constexpr size_t kBytesPerStringAttribute = 4 * sizeof(int32_t);
explicit PlatformViewAndroidDelegate(
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
void UpdateSemantics(

View File

@ -23,7 +23,8 @@ TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) {
node0.tooltip = "tooltip";
update.insert(std::make_pair(0, node0));
std::vector<uint8_t> expected_buffer(196);
std::vector<uint8_t> expected_buffer(
PlatformViewAndroidDelegate::kBytesPerNode);
std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
size_t position = 0;
int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
@ -87,7 +88,8 @@ TEST(PlatformViewShell, UpdateSemanticsDoesUpdatelinkUrl) {
node0.linkUrl = "url";
update.insert(std::make_pair(0, node0));
std::vector<uint8_t> expected_buffer(196);
std::vector<uint8_t> expected_buffer(
PlatformViewAndroidDelegate::kBytesPerNode);
std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
size_t position = 0;
int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
@ -165,7 +167,10 @@ TEST(PlatformViewShell,
node0.hintAttributes.push_back(locale_attribute);
update.insert(std::make_pair(0, node0));
std::vector<uint8_t> expected_buffer(228);
std::vector<uint8_t> expected_buffer(
PlatformViewAndroidDelegate::kBytesPerNode +
// 1 label attribute + 1 hint attribute.
2 * PlatformViewAndroidDelegate::kBytesPerStringAttribute);
std::vector<std::vector<uint8_t>> expected_string_attribute_args;
size_t position = 0;
int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
@ -241,7 +246,8 @@ TEST(PlatformViewShell,
action0.hint = "hint";
actions.insert(std::make_pair(0, action0));
std::vector<uint8_t> expected_actions_buffer(16);
std::vector<uint8_t> expected_actions_buffer(
PlatformViewAndroidDelegate::kBytesPerAction);
int32_t* actions_buffer_int32 =
reinterpret_cast<int32_t*>(&expected_actions_buffer[0]);
std::vector<std::string> expected_action_strings;