Commit f7e42d6f authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

wake lock: Account for lost Mojo connection in MockWakeLock::WaitForCancelation()

WakeLockTest.LossOfDocumentActivity has been flaky since
r803272 ("[HeapMojo] Make HeapMojoWrapperMode::kWithContextObserver
default"), but that CL simply uncovered a bug in MockWakeLock: when the
ExecutionContext is destroyed, MockWakeLock::OnConnectionError() may be
called before we call MockWakeLock::WaitForCancelation(), in which case the
latter will loop forever.

Bail out early if |receiver_| is not bound, which indicates that there has
been a Mojo connection error and MockWakeLock::CancelWakeLock() has already
been called.

Bug: 1123879
Change-Id: Ia2f29fe560a3d7ca49b083dfec01fdcd6c48a504
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2390065
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarMinoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803852}
parent 0c895d91
......@@ -43,10 +43,8 @@ class MODULES_EXPORT WakeLockManager final
// An actual platform WakeLock. If bound, it means there is an active wake
// lock for a given type.
// TODO(crbug.com/1123879): Resolve the flaky test and make this
// kWithoutContextObserver.
HeapMojoRemote<device::mojom::blink::WakeLock,
HeapMojoWrapperMode::kForceWithoutContextObserver>
HeapMojoWrapperMode::kWithoutContextObserver>
wake_lock_;
WakeLockType wake_lock_type_;
......
......@@ -77,7 +77,6 @@ TEST(WakeLockTest, RequestWakeLockDenied) {
EXPECT_EQ("NotAllowedError", dom_exception->name());
}
// Test is flaky : http://crbug.com/1123879
// https://w3c.github.io/wake-lock/#handling-document-loss-of-full-activity
TEST(WakeLockTest, LossOfDocumentActivity) {
MockWakeLockService wake_lock_service;
......
......@@ -100,6 +100,12 @@ void MockWakeLock::WaitForRequest() {
void MockWakeLock::WaitForCancelation() {
DCHECK(!cancel_wake_lock_callback_);
if (!receiver_.is_bound()) {
// If OnConnectionError() has been called, bail out early to avoid waiting
// forever.
DCHECK(!is_acquired_);
return;
}
base::RunLoop run_loop;
cancel_wake_lock_callback_ = run_loop.QuitClosure();
RunWithStack(&run_loop);
......
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