Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion third_party/accessibility/ax/platform/ax_unique_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int32_t AXUniqueId::GetNextAXUniqueId(const int32_t max_id) {

const int32_t prev_id = current_id;
do {
if (current_id == max_id) {
if (current_id >= max_id) {
current_id = 1;
has_wrapped = true;
} else {
Expand Down
25 changes: 19 additions & 6 deletions third_party/accessibility/ax/platform/ax_unique_id_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ AXTestSmallBankUniqueId::AXTestSmallBankUniqueId() : AXUniqueId(kMaxId) {}
AXTestSmallBankUniqueId::~AXTestSmallBankUniqueId() = default;

TEST(AXPlatformUniqueIdTest, UnassignedIdsAreReused) {
// TODO(chunhtai): enable this test once the flake has been
// resolved.
// https://github.com/flutter/flutter/issues/73512
GTEST_SKIP() << "Flaky Test: https://github.com/flutter/flutter/issues/73512";
// Create a bank of ids that uses up all available ids.
// Then remove an id and replace with a new one. Since it's the only
// slot available, the id will end up having the same value, rather than
Expand All @@ -47,8 +43,7 @@ TEST(AXPlatformUniqueIdTest, UnassignedIdsAreReused) {
}

static int kIdToReplace = 10;
std::unique_ptr<AXTestSmallBankUniqueId>& unique = ids[kIdToReplace];
int32_t expected_id = unique->Get();
int32_t expected_id = ids[kIdToReplace]->Get();

// Delete one of the ids and replace with a new one.
ids[kIdToReplace] = nullptr;
Expand All @@ -58,4 +53,22 @@ TEST(AXPlatformUniqueIdTest, UnassignedIdsAreReused) {
EXPECT_EQ(ids[kIdToReplace]->Get(), expected_id);
}

TEST(AXPlatformUniqueIdTest, DoesCreateCorrectId) {
int kLargerThanMaxId = kMaxId * 2;
std::unique_ptr<AXUniqueId> ids[kLargerThanMaxId];
// Creates and releases to fill up the internal static counter.
for (int i = 0; i < kLargerThanMaxId; i++) {
ids[i] = std::make_unique<AXUniqueId>();
}
for (int i = 0; i < kLargerThanMaxId; i++) {
ids[i].reset(nullptr);
}
// Creates an unique id whose max value is less than the internal
// static counter.
std::unique_ptr<AXTestSmallBankUniqueId> unique_id =
std::make_unique<AXTestSmallBankUniqueId>();

EXPECT_LE(unique_id->Get(), kMaxId);
}

} // namespace ui