Commit 41cfa934 authored by Joshua Bell's avatar Joshua Bell Committed by Commit Bot

Web Locks API: query() needs callback even if origin is empty

Issue reported by canary dogfooder: the promise returned by
navigator.locks.query() would never resolve if no locks were held. In
debug builds, this would DCHECK. The code would early-exit without
running the callback in this case - a no-no.

Added fix (return empty arrays) and test case.

Bug: 807070
Change-Id: Ib4abd5d861c5ab259f7ea00355aebd006438508e
Reviewed-on: https://chromium-review.googlesource.com/891584
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533184}
parent 43debccc
......@@ -232,10 +232,13 @@ void LockManager::QueryState(QueryStateCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const url::Origin& origin = bindings_.dispatch_context().origin;
if (!base::ContainsKey(origins_, origin))
if (!base::ContainsKey(origins_, origin)) {
std::move(callback).Run(std::vector<blink::mojom::LockInfoPtr>(),
std::vector<blink::mojom::LockInfoPtr>());
return;
OriginState& state = origins_[origin];
}
OriginState& state = origins_[origin];
std::move(callback).Run(state.SnapshotRequested(), state.SnapshotHeld());
}
......
<!DOCTYPE html>
<meta charset=utf-8>
<title>Web Locks API: navigator.locks.query method - no locks held</title>
<link rel=help href="https://github.com/inexorabletash/web-locks">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>
<script>
'use strict';
promise_test(async t => {
const state = await navigator.locks.query();
assert_own_property(state, 'pending', 'State has `pending` property');
assert_true(Array.isArray(state.pending),
'State `pending` property is an array');
assert_array_equals(state.pending, [], 'Pending array is empty');
assert_own_property(state, 'held', 'State has `held` property');
assert_true(Array.isArray(state.held), 'State `held` property is an array');
assert_array_equals(state.held, [], 'Held array is empty');
}, 'query() returns dictionary with empty arrays when no locks are held');
</script>
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