Commit 4ed48b0a authored by Chun-Heng Tai's avatar Chun-Heng Tai Committed by Chromium LUCI CQ

fix ax unique id may return id bigger than the max value

Change-Id: I0a04d7537c9e313e2c5e5157f836b4b28de44216
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616901Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842753}
parent 8283eeb2
......@@ -46,7 +46,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 {
......
......@@ -53,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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment