Commit 3cdeae87 authored by Joshua Bell's avatar Joshua Bell Committed by Commit Bot

Web Locks API: Run tests in additional globals

Use the "META: global=" annotation to run the web-locks/ tests in
shared and service workers, as appropriate.

Change-Id: I1d6acd9b4e2932bf3a60b1e41285cbe74e3cb8ff
Reviewed-on: https://chromium-review.googlesource.com/1208447
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590265}
parent 8bc03e93
// META: title=Web Locks API: navigator.locks.request method // META: title=Web Locks API: navigator.locks.request method
// META: script=resources/helpers.js // META: script=resources/helpers.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: Lock held until callback result resolves // META: title=Web Locks API: Lock held until callback result resolves
// META: script=resources/helpers.js // META: script=resources/helpers.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict';
promise_test(async t => {
const srcs = ['./web-locks.idl', '/interfaces/html.idl'];
const [weblocks, html] = await Promise.all(
srcs.map(i => fetch(i).then(r => r.text())));
const idl_array = new IdlArray();
idl_array.add_idls(weblocks);
idl_array.add_dependency_idls(html);
try {
await navigator.locks.request('name', l => { self.lock = l; });
} catch (e) {
// Surfaced in idlharness.js's test_object below.
}
idl_array.add_objects({
LockManager: ['navigator.locks'],
Lock: ['lock'],
});
if (self.Window) {
idl_array.add_objects({ Navigator: ['navigator'] });
} else {
idl_array.add_objects({ WorkerNavigator: ['navigator'] });
}
idl_array.test();
});
// META: title=Web Locks API: ifAvailable option // META: title=Web Locks API: ifAvailable option
// META: script=resources/helpers.js // META: script=resources/helpers.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
<!DOCTYPE html>
<meta charset=utf-8>
<title>Web Locks API: WebIDL tests in service worker</title>
<link rel=help href="https://wicg.github.io/web-locks/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
(async () => {
const scope = 'resources/does/not/exist';
let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
'resources/interfaces-serviceworker.js', {scope});
fetch_tests_from_worker(registration.installing);
})();
</script>
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js
'use strict';
promise_test(async t => {
const response = await fetch('interfaces.idl');
const idls = await response.text();
const idl_array = new IdlArray();
idl_array.add_untested_idls('[Exposed=Window] interface Navigator {};');
idl_array.add_untested_idls('[Exposed=Worker] interface WorkerNavigator {};');
idl_array.add_idls(idls);
let lock;
await navigator.locks.request('name', l => { lock = l; });
idl_array.add_objects({
LockManager: [navigator.locks],
Lock: [lock],
});
idl_array.test();
});
// META: title=Web Locks API: Lock Attributes // META: title=Web Locks API: Lock Attributes
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: Exclusive Mode // META: title=Web Locks API: Exclusive Mode
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: Mixed Modes // META: title=Web Locks API: Mixed Modes
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: Shared Mode // META: title=Web Locks API: Shared Mode
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META title=Web Locks API: API not available in non-secure context // META: title=Web Locks API: API not available in non-secure context
// META: global=window,dedicatedworker,sharedworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: navigator.locks.query method - no locks held // META: title=Web Locks API: navigator.locks.query method - no locks held
// META: script=resources/helpers.js // META: script=resources/helpers.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: navigator.locks.query ordering // META: title=Web Locks API: navigator.locks.query ordering
// META: script=resources/helpers.js // META: script=resources/helpers.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: Resources DOMString edge cases // META: title=Web Locks API: Resources DOMString edge cases
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
'use strict';
importScripts('/resources/testharness.js',
'/resources/WebIDLParser.js',
'/resources/idlharness.js');
promise_test(async t => {
const response = await fetch('../interfaces.idl');
const idls = await response.text();
const idl_array = new IdlArray();
idl_array.add_untested_idls('[Exposed=Window] interface Navigator {};');
idl_array.add_untested_idls('[Exposed=Worker] interface WorkerNavigator {};');
idl_array.add_idls(idls);
let lock;
await navigator.locks.request('name', l => { lock = l; });
idl_array.add_objects({
LockManager: [navigator.locks],
Lock: [lock],
});
idl_array.test();
}, 'Interface test');
done();
// META: title=Web Locks API: API requires secure context // META: title=Web Locks API: API requires secure context
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: AbortSignal integration // META: title=Web Locks API: AbortSignal integration
// META: script=resources/helpers.js // META: script=resources/helpers.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
// META: title=Web Locks API: steal option // META: title=Web Locks API: steal option
// META: script=resources/helpers.js // META: script=resources/helpers.js
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict'; 'use strict';
......
[SecureContext]
enum LockMode { "shared", "exclusive" }; interface mixin NavigatorLocks {
readonly attribute LockManager locks;
dictionary LockOptions {
LockMode mode = "exclusive";
boolean ifAvailable = false;
};
callback LockGrantedCallback = any (Lock lock);
[Exposed=Window]
partial interface Navigator {
[SecureContext] readonly attribute LockManager locks;
};
[Exposed=Worker]
partial interface WorkerNavigator {
[SecureContext] readonly attribute LockManager locks;
}; };
Navigator includes NavigatorLocks;
WorkerNavigator includes NavigatorLocks;
[Exposed=(Window,Worker), SecureContext] [SecureContext, Exposed=(Window,Worker)]
interface LockManager { interface LockManager {
Promise<any> request(DOMString name, Promise<any> request(DOMString name,
LockGrantedCallback callback); LockGrantedCallback callback);
...@@ -29,18 +16,30 @@ interface LockManager { ...@@ -29,18 +16,30 @@ interface LockManager {
Promise<LockManagerSnapshot> query(); Promise<LockManagerSnapshot> query();
}; };
[Exposed=(Window,Worker), SecureContext] callback LockGrantedCallback = Promise<any> (Lock lock);
interface Lock {
readonly attribute DOMString name; enum LockMode { "shared", "exclusive" };
readonly attribute LockMode mode;
dictionary LockOptions {
LockMode mode = "exclusive";
boolean ifAvailable = false;
boolean steal = false;
AbortSignal signal;
}; };
dictionary LockManagerSnapshot { dictionary LockManagerSnapshot {
sequence<LockInfo> pending;
sequence<LockInfo> held; sequence<LockInfo> held;
sequence<LockInfo> pending;
}; };
dictionary LockInfo { dictionary LockInfo {
DOMString name; DOMString name;
LockMode mode; LockMode mode;
DOMString clientId;
};
[SecureContext, Exposed=(Window,Worker)]
interface Lock {
readonly attribute DOMString name;
readonly attribute LockMode mode;
}; };
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