tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PresentationConnection_onconnect-manual.https.html (2694B)


      1 <!DOCTYPE html>
      2 
      3 <meta charset="utf-8">
      4 <title>Establishing a presentation connection</title>
      5 <link rel="author" title="Intel" href="http://www.intel.com">
      6 <link rel="author" title="He Yue" href="mailto:yue.he@intel.com">
      7 <link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs/">
      8 <link rel="help" href="https://w3c.github.io/presentation-api/#establishing-a-presentation-connection">
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 <script src="common.js"></script>
     12 <h2>Description</h2>
     13 <p>
     14  This test validates that after connection starts,<br/>
     15  the onconnect EventHandler is triggered and connection state is connected.
     16 </p>
     17 <br/>
     18 <p>Click the button below to start the test.</p>
     19 <button id="presentBtn">Start Presentation Test</button>
     20 
     21 <script>
     22  setup({explicit_timeout: true});
     23 
     24  const presentBtn = document.getElementById('presentBtn');
     25 
     26  promise_test(t => {
     27    const clickWatcher = new EventWatcher(t, presentBtn, 'click');
     28    const request = new PresentationRequest(presentationUrls);
     29    let connection;
     30 
     31    t.add_cleanup(() => {
     32      if (connection) {
     33        connection.onconnect = () => { connection.terminate(); };
     34        if (connection.state === 'closed')
     35          request.reconnect(connection.id);
     36        else
     37          connection.terminate();
     38      }
     39    });
     40 
     41    const watchEvent = (obj, watcher, type) => {
     42      const watchHandler = new Promise(resolve => {
     43        obj['on' + type] = evt => { resolve(evt); };
     44      });
     45      return Promise.all([ watchHandler, watcher.wait_for(type) ]).then(results => {
     46        assert_equals(results[0], results[1], 'Both on' + type + ' and addEventListener pass the same event object.');
     47        return results[0];
     48      });
     49    };
     50 
     51    return clickWatcher.wait_for('click').then(() => {
     52      presentBtn.disabled = true;
     53 
     54      return request.start();
     55    }).then(c => {
     56      // Enable timeout again, cause no user action is needed from here.
     57      t.step_timeout(() => {
     58          t.force_timeout();
     59          t.done();
     60      }, 5000);
     61 
     62      connection = c;
     63      const eventWatcher = new EventWatcher(t, connection, 'connect');
     64      return watchEvent(connection, eventWatcher, 'connect');
     65    }).then(evt => {
     66      assert_true(evt.isTrusted && !evt.bubbles && !evt.cancelable && evt instanceof Event, 'A simple event is fired.');
     67      assert_equals(evt.type, 'connect', 'The event name is "connect".');
     68      assert_equals(evt.target, connection, 'event.target is the presentation connection.');
     69      assert_equals(connection.state, 'connected', 'The presentation connection state is set to "connected".');
     70    });
     71  });
     72 </script>