1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
<!DOCTYPE html>
<meta charset="utf-8">
<title>Reconnecting presentations on two distinct displays</title>
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
<link rel="help" href="http://w3c.github.io/presentation-api/#dom-presentationrequest-reconnect">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
<style>
#second-step {
display: none;
}
</style>
<p id="first-step">Click the button below and select the available presentation display, to start the manual test.</p>
<p id="second-step">Click the button below and select the other available presentation display, to continue the manual test.</p>
<p>This test asks you to click the button twice, unless the test fails.<br>
<em>This test requires two or more available displays.<em></p>
<button id="presentBtn">Start Presentation Test</button>
<script>
promise_test(async t => {
const presentBtn = document.getElementById("presentBtn");
const request1 = new PresentationRequest(presentationUrls);
const request2 = new PresentationRequest(presentationUrls);
const clickWatcher = new EventWatcher(t, presentBtn, 'click');
let connection1, connection2, eventWatcher1, eventWatcher2, timer;
t.add_cleanup(() => {
[
{ connection: connection1, request: request1 },
{ connection: connection2, request: request2 }
].forEach(p => {
if (p.connection) {
p.connection.onconnect = () => { p.connection.terminate(); };
if (p.connection.state == 'closed')
p.request.reconnect(p.connection.id);
else
p.connection.terminate();
}
});
});
const disableTimeout = () => {
setup({explicit_timeout: true});
if (timer) {
clearTimeout(timer);
timer = null;
}
};
const enableTimeout = () => {
timer = t.step_timeout(() => {
t.force_timeout();
t.done();
}, 5000);
}
disableTimeout();
await clickWatcher.wait_for('click');
presentBtn.disabled = true;
connection1 = await request1.start();
presentBtn.disabled = false;
document.getElementById('first-step').style.display = 'none';
document.getElementById('second-step').style.display = 'block';
presentBtn.innerText = 'Continue Presentation Test';
eventWatcher1 = new EventWatcher(t, connection1, ['connect', 'close', 'terminate']);
await Promise.all([
eventWatcher1.wait_for('connect'),
(async () => {
await clickWatcher.wait_for('click');
presentBtn.disabled = true;
connection2 = await request2.start();
enableTimeout();
eventWatcher2 = new EventWatcher(t, connection2, ['connect', 'close', 'terminate']);
await eventWatcher2.wait_for('connect');
})()
]);
connection1.close();
assert_equals(connection2.state, 'connected',
'Closing one presentation connection does not affect the state of the other.');
await eventWatcher1.wait_for('close');
assert_equals(connection1.state, 'closed', 'The presentation connection is successfully closed.');
connection2.close();
await eventWatcher2.wait_for('close');
assert_equals(connection2.state, 'closed', 'The presentation connection is successfully closed.');
const c11 = await request1.reconnect(connection1.id);
assert_equals(c11, connection1, 'The promise is resolved with the existing presentation connection.');
const c22 = await request2.reconnect(connection2.id);
assert_equals(c22, connection2, 'The promise is resolved with the existing presentation connection.');
await Promise.all([
eventWatcher1.wait_for('connect'),
eventWatcher2.wait_for('connect')
]);
assert_equals(connection1.state, 'connected', 'The presentation connection is successfully reconnected.');
assert_equals(connection2.state, 'connected', 'The presentation connection is successfully reconnected.');
// Reconnecting a presentation via a different presentation request with the same presentation
// URLs will succeed
connection2.close();
await eventWatcher2.wait_for('close');
const c12 = await request1.reconnect(connection2.id);
assert_equals(c12, connection2, 'The promise is resolved with the existing presentation connection.');
connection1.close();
await eventWatcher1.wait_for('close');
const c21 = await request2.reconnect(connection1.id);
assert_equals(c21, connection1, 'The promise is resolved with the existing presentation connection.');
await Promise.all([
eventWatcher1.wait_for('connect'),
eventWatcher2.wait_for('connect')
]);
assert_equals(connection1.state, 'connected', 'The presentation connection is successfully reconnected.');
assert_equals(connection2.state, 'connected', 'The presentation connection is successfully reconnected.');
connection1.terminate();
connection2.terminate();
await Promise.all([
eventWatcher1.wait_for('terminate'),
eventWatcher2.wait_for('terminate')
]);
});
</script>
|