diff --git a/third_party/accessibility/ax/platform/ax_unique_id.cc b/third_party/accessibility/ax/platform/ax_unique_id.cc index 75e318419d70c..ed6de01d1e82b 100644 --- a/third_party/accessibility/ax/platform/ax_unique_id.cc +++ b/third_party/accessibility/ax/platform/ax_unique_id.cc @@ -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 { diff --git a/third_party/accessibility/ax/platform/ax_unique_id_unittest.cc b/third_party/accessibility/ax/platform/ax_unique_id_unittest.cc index 72f7d9d2823e9..5f62ad3d115f7 100644 --- a/third_party/accessibility/ax/platform/ax_unique_id_unittest.cc +++ b/third_party/accessibility/ax/platform/ax_unique_id_unittest.cc @@ -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 @@ -47,8 +43,7 @@ TEST(AXPlatformUniqueIdTest, UnassignedIdsAreReused) { } static int kIdToReplace = 10; - std::unique_ptr& 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; @@ -58,4 +53,22 @@ TEST(AXPlatformUniqueIdTest, UnassignedIdsAreReused) { EXPECT_EQ(ids[kIdToReplace]->Get(), expected_id); } +TEST(AXPlatformUniqueIdTest, DoesCreateCorrectId) { + int kLargerThanMaxId = kMaxId * 2; + std::unique_ptr ids[kLargerThanMaxId]; + // Creates and releases to fill up the internal static counter. + for (int i = 0; i < kLargerThanMaxId; i++) { + ids[i] = std::make_unique(); + } + 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 unique_id = + std::make_unique(); + + EXPECT_LE(unique_id->Get(), kMaxId); +} + } // namespace ui