chromium/third_party/blink/web_tests/http/tests/workers/use-counter-third-party-shared-worker-not-recorded-for-same-etld-plus-one.html

<!DOCTYPE html>
<!-- Tests that the UseCounter for "shared worker usage in third party context"
  is not recorded if the two different origins has the same eTLD+1. This
  cannot be upstreamed to WPT because it tests Chrome's UseCounter mechanism.
-->
<meta charset="utf-8">
<title>
Tests that the UseCounter for "shared worker usage in third party context is not
recorded if the two different origins has the same eTLD+1.</title>
<body></body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/get-host-info.js"></script>
<script>

function with_iframe(url) {
  return new Promise(function(resolve) {
      var frame = document.createElement('iframe');
      frame.src = url;
      frame.onload = function() { resolve(frame); };
      document.body.appendChild(frame);
    });
}

function child_frame_has_verified_use_counter() {
  return new Promise(function(resolve, reject) {
      window.onmessage = (msg) => {
        if (msg.data == 'verified_has_use_counter')
          reject("The use counter gets recorded unexpectedly.");
        else
          reject(msg.data);
      };
    });
}

promise_test(async t => {
  const remote_origin_same_etld_plus_one_url = get_host_info().HTTPS_ORIGIN +
        '/workers/resources/create-shared-worker-verify-third-party-use-counter.html';
  const frame1 = await with_iframe(remote_origin_same_etld_plus_one_url);
  t.step_timeout(function() { t.done(); }, 1000);
  await child_frame_has_verified_use_counter();
}, "Tests that the UseCounter for shared worker usage in third party context is not recorded if the two different origins has the same eTLD+1.");
</script>