summaryrefslogtreecommitdiffstats
path: root/dom/presentation/tests/mochitest/file_presentation_receiver_establish_connection_error.html
blob: 6b1f2152fb3538819cc21356379764528c5e40de (plain)
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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for connection establishing errors of B2G Presentation API 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');
}

function testConnectionAvailable() {
  return new Promise(function(aResolve, aReject) {
    ok(navigator.presentation, "navigator.presentation should be available.");
    ok(navigator.presentation.receiver, "navigator.presentation.receiver should be available.");
    aResolve();
  });
}

function testUnexpectedControlChannelClose() {
  // Trigger the control channel to be closed with error code.
  command({ name: 'trigger-control-channel-close', data: 0x80004004 /* NS_ERROR_ABORT */ });

  return new Promise(function(aResolve, aReject) {
    return Promise.race([
      navigator.presentation.receiver.connectionList.then(
        (aList) => {
          ok(false, "Should not get a connection list.")
          aReject();
        },
        (aError) => {
          ok(false, "Error occurred when getting the connection list: " + aError);
          aReject();
        }
      ),
      new Promise(
        () => {
          setTimeout(() => {
            ok(true, "Not getting a conenction list.");
            aResolve();
          }, 3000);
        }
      ),
    ]);
  });
}

testConnectionAvailable().
then(testUnexpectedControlChannelClose).
then(finish);

</script>
</body>
</html>