non-fully-active.https.html (3332B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Web Locks API: Non-fully-active documents</title> 4 <link rel=help href="https://w3c.github.io/web-locks/"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="resources/helpers.js"></script> 8 9 <div></div> 10 11 <script> 12 function createNonFullyActiveIframe(src) { 13 const iframe = document.createElement("iframe"); 14 document.body.appendChild(iframe); 15 const { navigator, DOMException, postMessage } = iframe.contentWindow; 16 iframe.remove(); 17 return { iframe, navigator, DOMException, postMessage }; 18 } 19 20 promise_test(async t => { 21 const { navigator, DOMException } = createNonFullyActiveIframe(); 22 const p = navigator.locks.request("foo", t.unreached_func()); 23 await promise_rejects_dom(t, "InvalidStateError", DOMException, p, "Request should explicitly fail"); 24 }, "request() on non-fully-active document must fail"); 25 26 promise_test(async t => { 27 const { navigator, DOMException } = createNonFullyActiveIframe(); 28 const p = navigator.locks.query(); 29 await promise_rejects_dom(t, "InvalidStateError", DOMException, p, "Query should explicitly fail"); 30 }, "query() on a non-fully-active document must fail"); 31 32 promise_test(async t => { 33 const { navigator, DOMException, postMessage } = createNonFullyActiveIframe(); 34 35 const p = navigator.locks.request("-", t.unreached_func()); 36 await promise_rejects_dom(t, "InvalidStateError", DOMException, p, "Request should explicitly fail"); 37 }, "request()'s fully-active check happens earlier than name validation"); 38 39 promise_test(async t => { 40 const { iframe, navigator, DOMException } = createNonFullyActiveIframe(); 41 document.body.append(iframe); 42 t.add_cleanup(() => iframe.remove()); 43 44 // Appending should create a new browsing context with a new Navigator object 45 // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:insert-an-element-into-a-document 46 // https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object:associated-navigator 47 assert_not_equals(navigator, iframe.contentWindow.navigator, "Navigator object changes"); 48 assert_not_equals(navigator.locks, iframe.contentWindow.navigator.locks, "LockManager object changes"); 49 50 const p = navigator.locks.request("foo", t.unreached_func()); 51 await promise_rejects_dom(t, "InvalidStateError", DOMException, p, "Request on the previous LockManager still must fail"); 52 }, "Reactivated iframe must not reuse the previous LockManager"); 53 54 promise_test(async t => { 55 const iframe = document.createElement("iframe"); 56 document.body.appendChild(iframe); 57 const worker = new iframe.contentWindow.Worker("resources/worker.js"); 58 59 const name = uniqueName(t); 60 await postToWorkerAndWait(worker, { op: 'request', name }); 61 62 let query = await navigator.locks.query(); 63 assert_equals(query.held.length, 1, "One lock is present"); 64 65 iframe.remove(); 66 67 const lock = await navigator.locks.request(name, lock => lock); 68 assert_equals(lock.name, name, "The following lock should be processed"); 69 70 query = await navigator.locks.query(); 71 assert_equals(query.held.length, 0, "No lock is present"); 72 }, "Workers owned by an unloaded iframe must release their locks"); 73 </script>