Ash: Refactor notifications and harden test utilities [chromium/src : main]

0 views
Skip to first unread message

Di Wu (Gerrit)

unread,
Oct 8, 2025, 4:21:04 AM (4 days ago) Oct 8
to Hidehiko Abe, Enterprise Policy Reviews, Nikhil Nayunigari, Peter Beverloo, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, feature-me...@chromium.org, cros-essential...@chromium.org, rrsilva+wat...@google.com, jackshira+w...@google.com, ejcaruso+wa...@chromium.org, jonmann+wa...@chromium.org, jiajunz+wa...@google.com, net-r...@chromium.org, stevenjb+wa...@chromium.org, chadduffin+w...@chromium.org, hsuregan+wa...@chromium.org, khorimoto+w...@chromium.org
Attention needed from Hidehiko Abe

Di Wu added 1 comment

File ui/message_center/test/message_center_waiter.cc
Line 62, Patchset 11: notification_added_ = true;
Hidehiko Abe . unresolved

why added? Shouldn't this be covered by OnNotificationAdded?

Di Wu

Good question! I renamed the variable to make it less confusing. I also added a comment to explain why `OnNotificationUpdated` was added this time, in addition to the existing `OnNotificationAdded` callback. Please take a look.

Hidehiko Abe

I'm wondering if this is what we want.
Are we testing the behavior that a notification is newly added?
If it was, then we cannot confirm if some of the testing scenario actually triggered the notification intentionally, or something that is leaked from some prev set up?

Di Wu

Great point, per our discussion, please take a look at the latest design of the waiter that hopefully does a better job differentiating between different scenarios. Thanks!

Open in Gerrit

Related details

Attention is currently required from:
  • Hidehiko Abe
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ica51268140326f62abd074f47e982315f4d02937
Gerrit-Change-Number: 6982106
Gerrit-PatchSet: 14
Gerrit-Owner: Di Wu <di...@google.com>
Gerrit-Reviewer: Di Wu <di...@google.com>
Gerrit-Reviewer: Hidehiko Abe <hide...@chromium.org>
Gerrit-CC: Enterprise Policy Reviews <enterprise-p...@google.com>
Gerrit-CC: Nikhil Nayunigari <nikh...@google.com>
Gerrit-CC: Peter Beverloo <pe...@chromium.org>
Gerrit-Attention: Hidehiko Abe <hide...@chromium.org>
Gerrit-Comment-Date: Wed, 08 Oct 2025 08:19:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Di Wu <di...@google.com>
Comment-In-Reply-To: Hidehiko Abe <hide...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Hidehiko Abe (Gerrit)

unread,
Oct 9, 2025, 6:39:22 AM (3 days ago) Oct 9
to Di Wu, Enterprise Policy Reviews, Nikhil Nayunigari, Peter Beverloo, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, feature-me...@chromium.org, cros-essential...@chromium.org, rrsilva+wat...@google.com, jackshira+w...@google.com, ejcaruso+wa...@chromium.org, jonmann+wa...@chromium.org, jiajunz+wa...@google.com, net-r...@chromium.org, stevenjb+wa...@chromium.org, chadduffin+w...@chromium.org, hsuregan+wa...@chromium.org, khorimoto+w...@chromium.org
Attention needed from Di Wu

Hidehiko Abe added 3 comments

Patchset-level comments
File-level comment, Patchset 14 (Latest):
Hidehiko Abe . resolved

Looking good!

File chrome/browser/ash/policy/handlers/minimum_version_policy_handler_browsertest.cc
Line 504, Patchset 14 (Latest): waiter.WaitUntilRemoved();
Hidehiko Abe . unresolved

I do not recommend to reuse the waiter.
The removal event may happen before the timing we're looking at, which would be unexpected behavior.

Ditto for everywhere else.

File ui/message_center/test/message_center_waiter.h
Line 29, Patchset 14 (Latest):// (`TaskEnvironment::TimeSource::MOCK_TIME`). In contrast, a manual `RunLoop`
// can sometimes cause unexpected side effects, such as prematurely flushing
// delayed tasks, leading to tests that pass for the wrong reasons (false
// positives).
Hidehiko Abe . unresolved

doesn't this mean the production code or test code would be wrong...?

Open in Gerrit

Related details

Attention is currently required from:
  • Di Wu
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ica51268140326f62abd074f47e982315f4d02937
Gerrit-Change-Number: 6982106
Gerrit-PatchSet: 14
Gerrit-Owner: Di Wu <di...@google.com>
Gerrit-Reviewer: Di Wu <di...@google.com>
Gerrit-Reviewer: Hidehiko Abe <hide...@chromium.org>
Gerrit-CC: Enterprise Policy Reviews <enterprise-p...@google.com>
Gerrit-CC: Nikhil Nayunigari <nikh...@google.com>
Gerrit-CC: Peter Beverloo <pe...@chromium.org>
Gerrit-Attention: Di Wu <di...@google.com>
Gerrit-Comment-Date: Thu, 09 Oct 2025 10:37:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Di Wu (Gerrit)

unread,
Oct 10, 2025, 3:02:19 AM (2 days ago) Oct 10
to Hidehiko Abe, Enterprise Policy Reviews, Nikhil Nayunigari, Peter Beverloo, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, feature-me...@chromium.org, cros-essential...@chromium.org, rrsilva+wat...@google.com, jackshira+w...@google.com, ejcaruso+wa...@chromium.org, jonmann+wa...@chromium.org, jiajunz+wa...@google.com, net-r...@chromium.org, stevenjb+wa...@chromium.org, chadduffin+w...@chromium.org, hsuregan+wa...@chromium.org, khorimoto+w...@chromium.org
Attention needed from Hidehiko Abe

Di Wu added 2 comments

File chrome/browser/ash/policy/handlers/minimum_version_policy_handler_browsertest.cc
Line 504, Patchset 14: waiter.WaitUntilRemoved();
Hidehiko Abe . resolved

I do not recommend to reuse the waiter.
The removal event may happen before the timing we're looking at, which would be unexpected behavior.

Ditto for everywhere else.

Di Wu

Good point. Updated, I found 5 places, all are in `chrome/browser/ash/policy/handlers/minimum_version_policy_handler_browsertest.cc`.

File ui/message_center/test/message_center_waiter.h
Line 29, Patchset 14:// (`TaskEnvironment::TimeSource::MOCK_TIME`). In contrast, a manual `RunLoop`

// can sometimes cause unexpected side effects, such as prematurely flushing
// delayed tasks, leading to tests that pass for the wrong reasons (false
// positives).
Hidehiko Abe . unresolved

doesn't this mean the production code or test code would be wrong...?

Di Wu

production code or test code would be wrong...

You have a sharp pair of eyes. I didn't find production code that was wrong. I did, however, find test code that was likely wrong, due to its false positive output.

See [here] for a timer that would fire a hats notification after a one-minute delay.

See [this original assertion] that would pass, without waiting out the whole one-minute delay, due to likely premature flushing of delayed tasks.

In a previous version of the waiter that I implemented, and that was never merged, I used RunLoop instead of RunUntil. I can confirm that the RunLoop version would always prematurely flush delayed tasks, at least in a mock time environment, just like its TestFuture counterpart. And the test would as a result pass with a false positive.

This is why RunUntil, which would not prematurely flush delayed tasks in a mock time environment, would need a companion `task_environment_.FastForwardBy(kDelayTriggerTimeout);` to go with it. Otherwise the test would time out and fail due to time would not automatically elapse in a mock time environment.

[here]:https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/webui/ash/cloud_upload/hats_office_trigger.cc;l=67
[this original assertion]:https://chromium-review.googlesource.com/c/chromium/src/+/6637692/30/chrome/browser/ui/webui/ash/cloud_upload/hats_office_trigger_unittest.cc#b308

Open in Gerrit

Related details

Attention is currently required from:
  • Hidehiko Abe
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ica51268140326f62abd074f47e982315f4d02937
Gerrit-Change-Number: 6982106
Gerrit-PatchSet: 15
Gerrit-Owner: Di Wu <di...@google.com>
Gerrit-Reviewer: Di Wu <di...@google.com>
Gerrit-Reviewer: Hidehiko Abe <hide...@chromium.org>
Gerrit-CC: Enterprise Policy Reviews <enterprise-p...@google.com>
Gerrit-CC: Nikhil Nayunigari <nikh...@google.com>
Gerrit-CC: Peter Beverloo <pe...@chromium.org>
Gerrit-Attention: Hidehiko Abe <hide...@chromium.org>
Gerrit-Comment-Date: Fri, 10 Oct 2025 07:00:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Hidehiko Abe <hide...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Hidehiko Abe (Gerrit)

unread,
Oct 10, 2025, 9:19:51 AM (2 days ago) Oct 10
to Di Wu, Enterprise Policy Reviews, Nikhil Nayunigari, Peter Beverloo, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, feature-me...@chromium.org, cros-essential...@chromium.org, rrsilva+wat...@google.com, jackshira+w...@google.com, ejcaruso+wa...@chromium.org, jonmann+wa...@chromium.org, jiajunz+wa...@google.com, net-r...@chromium.org, stevenjb+wa...@chromium.org, chadduffin+w...@chromium.org, hsuregan+wa...@chromium.org, khorimoto+w...@chromium.org
Attention needed from Di Wu

Hidehiko Abe voted and added 3 comments

Votes added by Hidehiko Abe

Code-Review+1

3 comments

Patchset-level comments
File-level comment, Patchset 15 (Latest):
Hidehiko Abe . resolved

LGTM!

File chrome/browser/ash/notifications/gnubby_notification.h
Line 39, Patchset 7 (Parent): void CreateNotification();
Di Wu . resolved

`CreateNotification()` is absorbed in `ShowNotification()` to save an extra instance variable `notification_prompt_`.

Hidehiko Abe

Acknowledged

File ui/message_center/test/message_center_waiter.h
Line 29, Patchset 14:// (`TaskEnvironment::TimeSource::MOCK_TIME`). In contrast, a manual `RunLoop`
// can sometimes cause unexpected side effects, such as prematurely flushing
// delayed tasks, leading to tests that pass for the wrong reasons (false
// positives).
Hidehiko Abe . resolved

doesn't this mean the production code or test code would be wrong...?

Di Wu

production code or test code would be wrong...

You have a sharp pair of eyes. I didn't find production code that was wrong. I did, however, find test code that was likely wrong, due to its false positive output.

See [here] for a timer that would fire a hats notification after a one-minute delay.

See [this original assertion] that would pass, without waiting out the whole one-minute delay, due to likely premature flushing of delayed tasks.

In a previous version of the waiter that I implemented, and that was never merged, I used RunLoop instead of RunUntil. I can confirm that the RunLoop version would always prematurely flush delayed tasks, at least in a mock time environment, just like its TestFuture counterpart. And the test would as a result pass with a false positive.

This is why RunUntil, which would not prematurely flush delayed tasks in a mock time environment, would need a companion `task_environment_.FastForwardBy(kDelayTriggerTimeout);` to go with it. Otherwise the test would time out and fail due to time would not automatically elapse in a mock time environment.

[here]:https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/webui/ash/cloud_upload/hats_office_trigger.cc;l=67
[this original assertion]:https://chromium-review.googlesource.com/c/chromium/src/+/6637692/30/chrome/browser/ui/webui/ash/cloud_upload/hats_office_trigger_unittest.cc#b308

Hidehiko Abe

Acknowledged

Open in Gerrit

Related details

Attention is currently required from:
  • Di Wu
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ica51268140326f62abd074f47e982315f4d02937
    Gerrit-Change-Number: 6982106
    Gerrit-PatchSet: 15
    Gerrit-Owner: Di Wu <di...@google.com>
    Gerrit-Reviewer: Di Wu <di...@google.com>
    Gerrit-Reviewer: Hidehiko Abe <hide...@chromium.org>
    Gerrit-CC: Enterprise Policy Reviews <enterprise-p...@google.com>
    Gerrit-CC: Nikhil Nayunigari <nikh...@google.com>
    Gerrit-CC: Peter Beverloo <pe...@chromium.org>
    Gerrit-Attention: Di Wu <di...@google.com>
    Gerrit-Comment-Date: Fri, 10 Oct 2025 13:17:36 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Di Wu (Gerrit)

    unread,
    Oct 10, 2025, 8:47:26 PM (2 days ago) Oct 10
    to Mitsuru Oshima, Hidehiko Abe, Enterprise Policy Reviews, Nikhil Nayunigari, Peter Beverloo, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, feature-me...@chromium.org, cros-essential...@chromium.org, rrsilva+wat...@google.com, jackshira+w...@google.com, ejcaruso+wa...@chromium.org, jonmann+wa...@chromium.org, jiajunz+wa...@google.com, net-r...@chromium.org, stevenjb+wa...@chromium.org, chadduffin+w...@chromium.org, hsuregan+wa...@chromium.org, khorimoto+w...@chromium.org
    Attention needed from Mitsuru Oshima

    Di Wu added 1 comment

    Patchset-level comments
    Di Wu . unresolved

    Hi @osh...@chromium.org san, this is a follow-up in my code refactoring series of severing the ties between Cros code and the numerous tester/helper/utilities of DisplayService.

    Especially, please help review the changes in `ui/message_center/test/message_center_waiter.h` and `ui/message_center/test/message_center_waiter.cc` as I further improved them to be even more specific and targeted when used in tests.

    Let me know if you have any questions. Thanks!

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Mitsuru Oshima
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ica51268140326f62abd074f47e982315f4d02937
    Gerrit-Change-Number: 6982106
    Gerrit-PatchSet: 15
    Gerrit-Owner: Di Wu <di...@google.com>
    Gerrit-Reviewer: Di Wu <di...@google.com>
    Gerrit-Reviewer: Hidehiko Abe <hide...@chromium.org>
    Gerrit-Reviewer: Mitsuru Oshima <osh...@chromium.org>
    Gerrit-CC: Enterprise Policy Reviews <enterprise-p...@google.com>
    Gerrit-CC: Nikhil Nayunigari <nikh...@google.com>
    Gerrit-CC: Peter Beverloo <pe...@chromium.org>
    Gerrit-Attention: Mitsuru Oshima <osh...@chromium.org>
    Gerrit-Comment-Date: Sat, 11 Oct 2025 00:45:07 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages