gecko-dev/testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html
Joshua Bell 3cb7b1360c Bug 1472022 [wpt PR 11713] - Web Locks API: Upstream tests to web-platform-tests (as .tentative), a=testonly
Automatic update from web-platform-testsWeb Locks API: Upstream tests to web-platform-tests (as .tentative)

* Move tests from http/tests/locks to external/wpt/web-locks
* Name with '.tentative' infix since this is still just a proposal
* Name most tests with '.https' infix since feature is [SecureContext]
   (and remove redirect-to-secure-host logic in tests)
* Consolidate window/worker interfaces test with '.any.js' variant
* Update paths to service worker helpers

Bug: 857265
Change-Id: Iaf254c5d53ff5b6bb65de4516df85307ad3a6519
Reviewed-on: https://chromium-review.googlesource.com/1118764
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573991}

--

wpt-commits: 89ccb892ad85159b093dab6956ca9caea7bb4edc
wpt-pr: 11713
2018-07-24 21:46:13 +00:00

35 lines
1.1 KiB
HTML

<!DOCTYPE html>
<meta charset=utf-8>
<title>iframe used in clientId test</title>
<script>
self.onmessage = async event => {
try {
if (event.data === 'get_sw_client_id') {
// Use the controlling service worker to determine
// this client's id according to the Service Worker.
const response = await fetch('/clientId');
const data = await response.json();
window.parent.postMessage(data.clientId, '*');
return;
}
if (event.data === 'get_lock_client_id') {
// Grab a lock, then query the lock manager for state to
// determine this client's id according to the lock manager.
await navigator.locks.request('lock-name', async lock => {
const lock_state = await navigator.locks.query();
const held_lock = lock_state.held.filter(l => l.name === lock.name)[0];
window.parent.postMessage(held_lock.clientId, '*');
});
return;
}
window.parent.postMessage(`unknown request: ${event.data}`, '*');
} catch (ex) {
// In case of test failure, don't leave parent window hanging.
window.parent.postMessage(`${ex.name}: ${ex.message}`, '*');
}
};
</script>