diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-02-06 16:03:39 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2020-02-06 16:03:39 -0500 |
commit | 5483f807c2663be8c63caf8d59ee151b3ef499d3 (patch) | |
tree | 13b912637e69511529d15676a905e7fe0ef2d169 /dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html | |
parent | e80e4595b9034fb06592c083c80feb7613ff9518 (diff) | |
download | UXP-5483f807c2663be8c63caf8d59ee151b3ef499d3.tar UXP-5483f807c2663be8c63caf8d59ee151b3ef499d3.tar.gz UXP-5483f807c2663be8c63caf8d59ee151b3ef499d3.tar.lz UXP-5483f807c2663be8c63caf8d59ee151b3ef499d3.tar.xz UXP-5483f807c2663be8c63caf8d59ee151b3ef499d3.zip |
Issue #1390 - Get rid of the Presentation API
Diffstat (limited to 'dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html')
-rw-r--r-- | dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html | 220 |
1 files changed, 0 insertions, 220 deletions
diff --git a/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html b/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html deleted file mode 100644 index cf02d2b2c..000000000 --- a/dom/presentation/tests/mochitest/file_presentation_1ua_receiver.html +++ /dev/null @@ -1,220 +0,0 @@ -<!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; -const DATA_ARRAY = [0, 255, 254, 0, 1, 2, 3, 0, 255, 255, 254, 0]; -const DATA_ARRAY_BUFFER = new ArrayBuffer(DATA_ARRAY.length); -const TYPED_DATA_ARRAY = new Uint8Array(DATA_ARRAY_BUFFER); -TYPED_DATA_ARRAY.set(DATA_ARRAY); - -function is_same_buffer(recv_data, expect_data) { - let recv_dataview = new Uint8Array(recv_data); - let expected_dataview = new Uint8Array(expect_data); - - if (recv_dataview.length !== expected_dataview.length) { - return false; - } - - for (let i = 0; i < recv_dataview.length; i++) { - if (recv_dataview[i] != expected_dataview[i]) { - info('discover byte differenct at ' + i); - return false; - } - } - return true; -} - -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."); - is(navigator.presentation.defaultRequest, null, "Receiver: navigator.presentation.defaultRequest should be null."); - - 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 testIncomingMessage() { - return new Promise(function(aResolve, aReject) { - info('Receiver: --- testIncomingMessage ---'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); - let msg = evt.data; - is(msg, 'msg-sender-to-receiver', 'Receiver: Receiver should receive message from sender.'); - command('forward-command', JSON.stringify({ name: 'message-from-sender-received' })); - aResolve(); - }); - command('forward-command', JSON.stringify({ name: 'trigger-message-from-sender' })); - }); -} - -function testSendMessage() { - return new Promise(function(aResolve, aReject) { - window.addEventListener('hashchange', function hashchangeHandler(evt) { - var message = JSON.parse(decodeURIComponent(window.location.hash.substring(1))); - if (message.type === 'trigger-message-from-receiver') { - info('Receiver: --- testSendMessage ---'); - connection.send('msg-receiver-to-sender'); - } - if (message.type === 'message-from-receiver-received') { - window.removeEventListener('hashchange', hashchangeHandler); - aResolve(); - } - }); - }); -} - -function testIncomingBlobMessage() { - return new Promise(function(aResolve, aReject) { - info('Receiver: --- testIncomingBlobMessage ---'); - connection.send('testIncomingBlobMessage'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); - let recvData= String.fromCharCode.apply(null, new Uint8Array(evt.data)); - is(recvData, "Hello World", 'expected same string data'); - aResolve(); - }); - }); -} - -function testConnectionClosed() { - return new Promise(function(aResolve, aReject) { - info('Receiver: --- testConnectionClosed ---'); - connection.onclose = function() { - connection.onclose = null; - is(connection.state, "closed", "Receiver: Connection should be closed."); - command('forward-command', JSON.stringify({ name: 'receiver-closed' })); - aResolve(); - }; - command('forward-command', JSON.stringify({ name: 'ready-to-close' })); - }); -} - -function testReconnectConnection() { - return new Promise(function(aResolve, aReject) { - info('Receiver: --- testReconnectConnection ---'); - window.addEventListener('hashchange', function hashchangeHandler(evt) { - var message = JSON.parse(decodeURIComponent(window.location.hash.substring(1))); - if (message.type === 'prepare-for-reconnect') { - command('forward-command', JSON.stringify({ name: 'ready-to-reconnect' })); - } - }); - connection.onconnect = function() { - connection.onconnect = null; - ok(true, "The connection is reconnected.") - aResolve(); - }; - }); -} - -function testIncomingArrayBuffer() { - return new Promise(function(aResolve, aReject) { - info('Receiver: --- testIncomingArrayBuffer ---'); - connection.binaryType = "blob"; - connection.send('testIncomingArrayBuffer'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); - var fileReader = new FileReader(); - fileReader.onload = function() { - ok(is_same_buffer(DATA_ARRAY_BUFFER, this.result), "expected same buffer data"); - aResolve(); - }; - fileReader.readAsArrayBuffer(evt.data); - }); - }); -} - -function testIncomingArrayBufferView() { - return new Promise(function(aResolve, aReject) { - info('Receiver: --- testIncomingArrayBufferView ---'); - connection.binaryType = "arraybuffer"; - connection.send('testIncomingArrayBufferView'); - connection.addEventListener('message', function messageHandler(evt) { - connection.removeEventListener('message', messageHandler); - ok(is_same_buffer(evt.data, TYPED_DATA_ARRAY), "expected same buffer data"); - aResolve(); - }); - }); -} - -function runTests() { - testConnectionAvailable() - .then(testConnectionReady) - .then(testIncomingMessage) - .then(testSendMessage) - .then(testIncomingBlobMessage) - .then(testConnectionClosed) - .then(testReconnectConnection) - .then(testIncomingArrayBuffer) - .then(testIncomingArrayBufferView) - .then(testConnectionClosed); -} - -runTests(); - -</script> - </body> -</html> |