startMultiplePresentations_success-manual.https.html (3530B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Starting presentations on two distinct displays</title> 4 <link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs"> 5 <link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="common.js"></script> 9 <style> 10 #second-step { 11 display: none; 12 } 13 </style> 14 15 <p id="first-step">Click the button below and select the available presentation display, to start the manual test.</p> 16 <p id="second-step">Click the button below and select the other available presentation display, to continue the manual test.</p> 17 <p>This test asks you to click the button twice, unless the test fails.<br> 18 <em>This test requires two or more available displays.<em></p> 19 <button id="presentBtn">Start Presentation Test</button> 20 21 22 <script> 23 promise_test(async t => { 24 const presentBtn = document.getElementById("presentBtn"); 25 26 const request = new PresentationRequest(presentationUrls); 27 const clickWatcher = new EventWatcher(t, presentBtn, 'click'); 28 let connection1, connection2, eventWatcher1, eventWatcher2, timer; 29 30 t.add_cleanup(() => { 31 [connection1, connection2].forEach(connection => { 32 if (connection) { 33 connection.onconnect = () => { connection.terminate(); }; 34 if (connection.state == 'closed') 35 request.reconnect(connection.id); 36 else 37 connection.terminate(); 38 } 39 }); 40 }); 41 42 const disableTimeout = () => { 43 setup({explicit_timeout: true}); 44 if (timer) { 45 clearTimeout(timer); 46 timer = null; 47 } 48 }; 49 50 const enableTimeout = () => { 51 timer = t.step_timeout(() => { 52 t.force_timeout(); 53 t.done(); 54 }, 5000); 55 } 56 57 disableTimeout(); 58 59 await clickWatcher.wait_for('click'); 60 presentBtn.disabled = true; 61 connection1 = await request.start(); 62 63 presentBtn.disabled = false; 64 document.getElementById('first-step').style.display = 'none'; 65 document.getElementById('second-step').style.display = 'block'; 66 presentBtn.innerText = 'Continue Presentation Test'; 67 eventWatcher1 = new EventWatcher(t, connection1, ['connect', 'close', 'terminate']); 68 69 await Promise.all([ 70 eventWatcher1.wait_for('connect'), 71 (async () => { 72 await clickWatcher.wait_for('click'); 73 presentBtn.disabled = true; 74 75 connection2 = await request.start(); 76 enableTimeout(); 77 eventWatcher2 = new EventWatcher(t, connection2, ['connect', 'terminate']); 78 await eventWatcher2.wait_for('connect'); 79 })() 80 ]); 81 82 assert_not_equals(connection1.id, connection2.id, 83 'Presentation connections on distinct presentations must have different presentation IDs.'); 84 85 assert_equals(connection1.state, 'connected', 'The presentation connection is successfully reconnected.'); 86 connection1.terminate(); 87 assert_equals(connection2.state, 'connected', 88 'Terminating one presentation connection does not affect the state of the other.'); 89 connection2.terminate(); 90 91 await Promise.all([ 92 eventWatcher1.wait_for('terminate'), 93 eventWatcher2.wait_for('terminate') 94 ]); 95 96 assert_equals(connection1.state, 'terminated', 'One presentation connection is successfully terminated.'); 97 assert_equals(connection2.state, 'terminated', 'Both presentation connections are successfully terminated.'); 98 }); 99 </script>