<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>This test validates that the initiatorType information for various
Resource Timing entries is accurate for scripts.</title>
<link rel="help"
      href="https://www.w3.org/TR/resource-timing-2/#dom-performanceresourcetiming-initiatortype"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/entry-invariants.js"></script>
<!-- Tested resources -->
<script src="resources/empty_script.js?id=blocking"></script>
<script src="resources/empty_script.js?id=async" async></script>
<script src="resources/empty_script.js?id=async_false" async=false></script>
<script src="resources/empty_script.js?id=defer" defer></script>
<script>
document.write("<script src='resources/empty_script.js?id=doc_written'></scr"
               + "ipt>");

const head = document.getElementsByTagName("head")[0];
const s1 = document.createElement("script");
s1.src = "empty_script.js?id=appended";
head.appendChild(s1);

const s2 = document.createElement("script");
s2.src = "empty_script.js?id=appended_async";
s2.async = true;
head.appendChild(s2);

const s3 = document.createElement("script");
s3.src = "empty_script.js?id=appended_aync_false";
s3.async = false;
head.appendChild(s3);

const s4 = document.createElement("script");
s4.src = "empty_script.js?id=appended_defer";
s4.defer = true;
head.appendChild(s4);
</script>
</head>
<body>
<script>

const wait_for_onload = () => {
  return new Promise(resolve => {
    window.addEventListener("load", resolve);
})};

promise_test(
  async () => {
    await wait_for_onload();

    const entry_list = performance.getEntriesByType("resource");
    for (entry of entry_list) {
      if (entry.name.includes("empty_script.js")) {
        assert_equals(entry.initiatorType, "script",
                      "initiatorType should be 'script' for " + entry.name);
      }
    }
}, "Validate initiatorType for scripts is 'script'");
</script>
</body>
</html>

