tor-browser

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

client-id.https.html (2162B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: Client.id</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="resources/test-helpers.sub.js"></script>
      6 <script>
      7 var scope = 'resources/blank.html?client-id';
      8 var frame1, frame2;
      9 
     10 promise_test(function(t) {
     11    return service_worker_unregister_and_register(
     12        t, 'resources/client-id-worker.js', scope)
     13      .then(function(registration) {
     14          t.add_cleanup(function() {
     15              return service_worker_unregister(t, scope);
     16            });
     17 
     18          return wait_for_state(t, registration.installing, 'activated');
     19        })
     20      .then(function() { return with_iframe(scope + '#1'); })
     21      .then(function(f) {
     22          frame1 = f;
     23          // To be sure Clients.matchAll() iterates in the same order.
     24          f.focus();
     25          return with_iframe(scope + '#2');
     26        })
     27      .then(function(f) {
     28          frame2 = f;
     29          var channel = new MessageChannel();
     30 
     31          return new Promise(function(resolve, reject) {
     32              channel.port1.onmessage = resolve;
     33              channel.port1.onmessageerror = reject;
     34              f.contentWindow.navigator.serviceWorker.controller.postMessage(
     35                  {port:channel.port2}, [channel.port2]);
     36            });
     37        })
     38      .then(on_message);
     39  }, 'Client.id returns the client\'s ID.');
     40 
     41 function on_message(e) {
     42  // The result of two sequential clients.matchAll() calls in the SW.
     43  // 1st matchAll() results in e.data[0], e.data[1].
     44  // 2nd matchAll() results in e.data[2], e.data[3].
     45  assert_equals(e.data.length, 4);
     46  // All should be string values.
     47  assert_equals(typeof e.data[0], 'string');
     48  assert_equals(typeof e.data[1], 'string');
     49  assert_equals(typeof e.data[2], 'string');
     50  assert_equals(typeof e.data[3], 'string');
     51  // Different clients should have different ids.
     52  assert_not_equals(e.data[0], e.data[1]);
     53  assert_not_equals(e.data[2], e.data[3]);
     54  // Same clients should have an identical id.
     55  assert_equals(e.data[0], e.data[2]);
     56  assert_equals(e.data[1], e.data[3]);
     57  frame1.remove();
     58  frame2.remove();
     59 }
     60 </script>