File: PresentationConnection_onconnect-manual.https.html

package info (click to toggle)
thunderbird 1%3A115.16.0esr-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,476,252 kB
  • sloc: cpp: 6,972,150; javascript: 5,209,211; ansic: 3,507,222; python: 1,137,609; asm: 432,531; xml: 205,149; java: 175,761; sh: 116,485; makefile: 22,152; perl: 13,971; objc: 12,561; yacc: 4,583; pascal: 2,840; lex: 1,720; ruby: 1,075; exp: 762; sql: 666; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (72 lines) | stat: -rw-r--r-- 2,694 bytes parent folder | download | duplicates (30)
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
<!DOCTYPE html>

<meta charset="utf-8">
<title>Establishing a presentation connection</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="author" title="He Yue" href="mailto:yue.he@intel.com">
<link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
<link rel="help" href="https://w3c.github.io/presentation-api/#establishing-a-presentation-connection">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
<h2>Description</h2>
<p>
  This test validates that after connection starts,<br/>
  the onconnect EventHandler is triggered and connection state is connected.
</p>
<br/>
<p>Click the button below to start the test.</p>
<button id="presentBtn">Start Presentation Test</button>

<script>
  setup({explicit_timeout: true});

  const presentBtn = document.getElementById('presentBtn');

  promise_test(t => {
    const clickWatcher = new EventWatcher(t, presentBtn, 'click');
    const request = new PresentationRequest(presentationUrls);
    let connection;

    t.add_cleanup(() => {
      if (connection) {
        connection.onconnect = () => { connection.terminate(); };
        if (connection.state === 'closed')
          request.reconnect(connection.id);
        else
          connection.terminate();
      }
    });

    const watchEvent = (obj, watcher, type) => {
      const watchHandler = new Promise(resolve => {
        obj['on' + type] = evt => { resolve(evt); };
      });
      return Promise.all([ watchHandler, watcher.wait_for(type) ]).then(results => {
        assert_equals(results[0], results[1], 'Both on' + type + ' and addEventListener pass the same event object.');
        return results[0];
      });
    };

    return clickWatcher.wait_for('click').then(() => {
      presentBtn.disabled = true;

      return request.start();
    }).then(c => {
      // Enable timeout again, cause no user action is needed from here.
      t.step_timeout(() => {
          t.force_timeout();
          t.done();
      }, 5000);

      connection = c;
      const eventWatcher = new EventWatcher(t, connection, 'connect');
      return watchEvent(connection, eventWatcher, 'connect');
    }).then(evt => {
      assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
      assert_equals(evt.type, 'connect', 'The event name is "connect".');
      assert_equals(evt.target, connection, 'event.target is the presentation connection.');
      assert_equals(connection.state, 'connected', 'The presentation connection state is set to "connected".');
    });
  });
</script>