diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/presentation/tests/mochitest/file_presentation_terminate.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/presentation/tests/mochitest/file_presentation_terminate.html')
-rw-r--r-- | dom/presentation/tests/mochitest/file_presentation_terminate.html | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/dom/presentation/tests/mochitest/file_presentation_terminate.html b/dom/presentation/tests/mochitest/file_presentation_terminate.html new file mode 100644 index 000000000..a26a44b90 --- /dev/null +++ b/dom/presentation/tests/mochitest/file_presentation_terminate.html @@ -0,0 +1,104 @@ +<!DOCTYPE HTML> +<!-- vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: --> +<html> + <head> + <meta charset='utf-8'> + <title>Test for B2G PresentationReceiver at receiver side</title> + </head> + <body> + <div id='content'></div> +<script type='application/javascript;version=1.7'> + +'use strict'; + +function is(a, b, msg) { + if (a === b) { + alert('OK ' + msg); + } else { + alert('KO ' + msg + ' | reason: ' + a + ' != ' + b); + } +} + +function ok(a, msg) { + alert((a ? 'OK ' : 'KO ') + msg); +} + +function info(msg) { + alert('INFO ' + msg); +} + +function command(name, data) { + alert('COMMAND ' + JSON.stringify({name: name, data: data})); +} + +function finish() { + alert('DONE'); +} + +var connection; + +function testConnectionAvailable() { + return new Promise(function(aResolve, aReject) { + info('Receiver: --- testConnectionAvailable ---'); + ok(navigator.presentation, 'Receiver: navigator.presentation should be available.'); + ok(navigator.presentation.receiver, 'Receiver: navigator.presentation.receiver should be available.'); + + navigator.presentation.receiver.connectionList + .then((aList) => { + is(aList.connections.length, 1, 'Should get one conncetion.'); + connection = aList.connections[0]; + ok(connection.id, 'Connection ID should be set: ' + connection.id); + is(connection.state, 'connected', 'Connection state at receiver side should be connected.'); + aResolve(); + }) + .catch((aError) => { + ok(false, 'Receiver: Error occurred when getting the connection: ' + aError); + finish(); + aReject(); + }); + }); +} + +function testConnectionReady() { + return new Promise(function(aResolve, aReject) { + info('Receiver: --- testConnectionReady ---'); + connection.onconnect = function() { + connection.onconnect = null; + ok(false, 'Should not get |onconnect| event.') + aReject(); + }; + if (connection.state === 'connected') { + connection.onconnect = null; + is(connection.state, 'connected', 'Receiver: Connection state should become connected.'); + aResolve(); + } + }); +} + +function testConnectionTerminate() { + return new Promise(function(aResolve, aReject) { + info('Receiver: --- testConnectionTerminate ---'); + connection.onterminate = function() { + connection.onterminate = null; + // Using window.alert at this stage will cause window.close() fail. + // Only trigger it if verdict fail. + if (connection.state !== 'terminated') { + is(connection.state, 'terminated', 'Receiver: Connection should be terminated.'); + } + aResolve(); + }; + command('forward-command', JSON.stringify({ name: 'ready-to-terminate' })); + }); +} + +function runTests() { + testConnectionAvailable() + .then(testConnectionReady) + .then(testConnectionTerminate) +} + +runTests(); + +</script> + </body> +</html> |