Revision ed8099ac2129f3f7a0f9f3a5e30e3b581d54cdee authored by Philipp Hancke on 23 July 2018, 08:58:44 UTC, committed by Philipp Hancke on 25 July 2018, 15:46:40 UTC
makes most new transceiver tests pass by avoiding addTrack(track) which does not work in Firefox yet.
1 parent 6c8ab50
steal.tentative.https.html
<!DOCTYPE html>
<meta charset=utf-8>
<title>Web Locks API: steal option</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';
const never_settled = new Promise(resolve => { /* never */ });
promise_test(async t => {
const res = uniqueName(t);
let callback_called = false;
await navigator.locks.request(res, {steal: true}, lock => {
callback_called = true;
assert_not_equals(lock, null, 'Lock should be granted');
});
assert_true(callback_called, 'Callback should be called');
}, 'Lock available');
promise_test(async t => {
const res = uniqueName(t);
let callback_called = false;
// Grab and hold the lock.
navigator.locks.request(res, lock => never_settled).catch(_ => {});
// Steal it.
await navigator.locks.request(res, {steal: true}, lock => {
callback_called = true;
assert_not_equals(lock, null, 'Lock should be granted');
});
assert_true(callback_called, 'Callback should be called');
}, 'Lock not available');
promise_test(async t => {
const res = uniqueName(t);
// Grab and hold the lock.
const promise = navigator.locks.request(res, lock => never_settled);
const assertion = promise_rejects(
t, 'AbortError', promise, `Initial request's promise should reject`);
// Steal it.
await navigator.locks.request(res, {steal: true}, lock => {});
await assertion;
}, `Broken lock's release promise rejects`);
promise_test(async t => {
const res = uniqueName(t);
// Grab and hold the lock.
navigator.locks.request(res, lock => never_settled).catch(_ => {});
// Make a request for it.
let request_granted = false;
const promise = navigator.locks.request(res, lock => {
request_granted = true;
});
// Steal it.
await navigator.locks.request(res, {steal: true}, lock => {
assert_false(request_granted, 'Steal should override request');
});
await promise;
assert_true(request_granted, 'Request should eventually be granted');
}, `Requested lock's release promise is deferred`);
promise_test(async t => {
const res = uniqueName(t);
// Grab and hold the lock.
navigator.locks.request(res, lock => never_settled).catch(_ => {});
// Steal it.
let saw_abort = false;
const first_steal = navigator.locks.request(
res, {steal: true}, lock => never_settled).catch(error => {
saw_abort = true;
});
// Steal it again.
await navigator.locks.request(res, {steal: true}, lock => {});
await first_steal;
assert_true(saw_abort, 'First steal should have aborted');
}, 'Last caller wins');
</script>
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...