servo/tests/wpt/web-platform-tests/presentation-api/controlling-ua/PresentationRequest_onconnectionavailable-manual.https.html

61 lines
3 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8">
<title>PresentationRequest.onconnectionavailable (manual test)</title>
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
<link rel="help" href="https://w3c.github.io/presentation-api/#starting-a-presentation">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
<p>Click the button below and select the available presentation display, to start the manual test.</p>
<button id="presentBtn">Start Presentation Test</button>
<script>
// disable the timeout function for the tests
setup({explicit_timeout: true});
// ----------
// DOM Object
// ----------
var presentBtn = document.getElementById("presentBtn");
// --------------------------------------------------------------------------
// Start New PresentationRequest.onconnectionavailable Test (success) - begin
// --------------------------------------------------------------------------
var startPresentation = function () {
presentBtn.disabled = true;
promise_test(function (t) {
var connection;
t.add_cleanup(function() {
if(connection)
connection.terminate();
});
// Note: During starting a presentation, the connectionavailable event is fired (step 20)
// after the promise P is resolved (step 19).
return new Promise(function(resolve, reject) {
var request = new PresentationRequest(presentationUrls);
request.onconnectionavailable = function (evt) {
resolve(evt.connection);
};
// This test fails if request.onconnectionavailable is not invoked although the presentation is started successfully
// or the presentation fails to be started
request.start().then(function(c) {
connection = c;
t.step_timeout(function() { assert_unreached('The connectionavailable event was not fired.'); }, 5000);
}, reject);
}).then(function(c) {
connection = c;
assert_equals(connection.state, 'connecting', 'The initial state of the presentation connection is "connecting".');
assert_true(!!connection.id, 'The connection ID is set.');
assert_true(typeof connection.id === 'string', 'The connection ID is a string.');
assert_true(connection instanceof PresentationConnection, 'The connection is an instance of PresentationConnection.');
});
}, 'The connectionavailable event was fired successfully.');
}
presentBtn.onclick = startPresentation;
// ------------------------------------------------------------------------
// Start New PresentationRequest.onconnectionavailable Test (success) - end
// ------------------------------------------------------------------------
</script>