PresentationConnection_terminate-manual.https.html (2722B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Terminating a presentation in a receiving browsing context</title> 4 <link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/"> 5 <link rel="help" href="https://w3c.github.io/presentation-api/#terminating-a-presentation-in-a-receiving-browsing-context"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="common.js"></script> 9 <script src="support/stash.js"></script> 10 <style> 11 iframe { display: none; } 12 </style> 13 14 <p>Click the button below and select the available presentation display, to start the manual test.</p> 15 <button id="presentBtn" disabled>Start Presentation Test</button> 16 <iframe id="childFrame" sandbox="allow-scripts allow-presentation" src="support/iframe.html"></iframe> 17 18 <script> 19 setup({explicit_timeout: true}); 20 21 let connection; 22 23 const presentBtn = document.getElementById('presentBtn'); 24 const child = document.getElementById('childFrame'); 25 26 child.onload = () => { presentBtn.disabled = false; }; 27 28 presentBtn.onclick = () => { 29 presentBtn.disabled = true; 30 const stash = new Stash(stashIds.toController, stashIds.toReceiver); 31 const request = new PresentationRequest('support/PresentationConnection_terminate_receiving-ua.html'); 32 33 promise_test(t => { 34 t.add_cleanup(() => { 35 connection.onconnect = () => { connection.terminate(); }; 36 if (connection.state === 'closed') 37 request.reconnect(connection.id); 38 else 39 connection.terminate(); 40 stash.stop(); 41 }); 42 43 return request.start().then(c => { 44 // enable timeout again, cause no user action is needed from here. 45 t.step_timeout(() => { 46 t.force_timeout(); 47 t.done(); 48 }, 5000); 49 50 connection = c; 51 const eventWatcher = new EventWatcher(t, connection, 'connect'); 52 return eventWatcher.wait_for('connect'); 53 }).then(() => { 54 return stash.init(); 55 }).then(() => { 56 child.contentWindow.postMessage({ type: 'connect', id: connection.id, url: connection.url }, '*'); 57 const eventWatcher1 = new EventWatcher(t, connection, 'terminate'); 58 const eventWatcher2 = new EventWatcher(t, window, 'message'); 59 return Promise.all([ eventWatcher1.wait_for('terminate'), eventWatcher2.wait_for('message') ]); 60 }).then(() => { 61 return Promise.race([ 62 stash.receive().then(data => { 63 if (data.type === 'error') 64 assert_unreached('The presentation is not terminated successfully.'); 65 }), 66 new Promise(resolve => { t.step_timeout(resolve, 2000); }) 67 ]); 68 }); 69 }); 70 }; 71 </script>