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
Raw File
acquire.tentative.https.html
<!DOCTYPE html>
<meta charset=utf-8>
<title>Web Locks API: navigator.locks.request method</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 res = uniqueName(t);
  await promise_rejects(t, new TypeError(), navigator.locks.request());
  await promise_rejects(t, new TypeError(), navigator.locks.request(res));
}, 'navigator.locks.request requires a name and a callback');

promise_test(async t => {
  const res = uniqueName(t);
  await promise_rejects(
    t, new TypeError(),
    navigator.locks.request(res, {mode: 'foo'}, lock => {}));
  await promise_rejects(
    t, new TypeError(),
    navigator.locks.request(res, {mode: null }, lock => {}));
  assert_equals(await navigator.locks.request(
    res, {mode: 'exclusive'}, lock => lock.mode), 'exclusive',
                'mode is exclusive');
  assert_equals(await navigator.locks.request(
    res, {mode: 'shared'}, lock => lock.mode), 'shared',
                'mode is shared');
}, 'mode must be "shared" or "exclusive"');

promise_test(async t => {
  const res = uniqueName(t);
  await promise_rejects(
    t, 'NotSupportedError',
    navigator.locks.request(
      res, {steal: true, ifAvailable: true}, lock => {}),
    "A NotSupportedError should be thrown if both " +
    "'steal' and 'ifAvailable' are specified.");
}, "The 'steal' and 'ifAvailable' options are mutually exclusive");

promise_test(async t => {
  const res = uniqueName(t);
  await promise_rejects(
    t, 'NotSupportedError',
    navigator.locks.request(res, {mode: 'shared', steal: true}, lock => {}),
    'Request with mode=shared and steal=true should fail');
}, "The 'steal' option must be used with exclusive locks");

promise_test(async t => {
  const res = uniqueName(t);
  const controller = new AbortController();
  await promise_rejects(
    t, 'NotSupportedError',
    navigator.locks.request(
      res, {signal: controller.signal, steal: true}, lock => {}),
    'Request with signal and steal=true should fail');
}, "The 'signal' and 'steal' options are mutually exclusive");

promise_test(async t => {
  const res = uniqueName(t);
  const controller = new AbortController();
  await promise_rejects(
    t, 'NotSupportedError',
    navigator.locks.request(
      res, {signal: controller.signal, ifAvailable: true}, lock => {}),
    'Request with signal and ifAvailable=true should fail');
}, "The 'signal' and 'ifAvailable' options are mutually exclusive");

promise_test(async t => {
  const res = uniqueName(t);
  await promise_rejects(
    t, new TypeError(), navigator.locks.request(res, undefined));
  await promise_rejects(
    t, new TypeError(), navigator.locks.request(res, null));
  await promise_rejects(
    t, new TypeError(), navigator.locks.request(res, 123));
  await promise_rejects(
    t, new TypeError(), navigator.locks.request(res, 'abc'));
  await promise_rejects(
    t, new TypeError(), navigator.locks.request(res, []));
  await promise_rejects(
    t, new TypeError(), navigator.locks.request(res, {}));
  await promise_rejects(
    t, new TypeError(), navigator.locks.request(res, new Promise(r => {})));
}, 'callback must be a function');

promise_test(async t => {
  const res = uniqueName(t);
  let release;
  const promise = new Promise(r => { release = r; });

  let returned = navigator.locks.request(res, lock => { return promise; });

  const order = [];

  returned.then(() => { order.push('returned'); });
  promise.then(() => { order.push('holding'); });

  release();

  await Promise.all([returned, promise]);

  assert_array_equals(order, ['holding', 'returned']);

}, 'navigator.locks.request\'s returned promise resolves after' +
   ' lock is released');

promise_test(async t => {
  const res = uniqueName(t);
  const test_error = {name: 'test'};
  const p = navigator.locks.request(res, lock => {
    throw test_error;
  });
  assert_equals(Promise.resolve(p), p, 'request() result is a Promise');
  await promise_rejects(t, test_error, p, 'result should reject');
}, 'Returned Promise rejects if callback throws synchronously');

promise_test(async t => {
  const res = uniqueName(t);
  const test_error = {name: 'test'};
  const p = navigator.locks.request(res, async lock => {
    throw test_error;
  });
  assert_equals(Promise.resolve(p), p, 'request() result is a Promise');
  await promise_rejects(t, test_error, p, 'result should reject');
}, 'Returned Promise rejects if callback throws asynchronously');

</script>
back to top