(preload_sri_success, subresource_sri_success, name,
number_of_requests, destination, resource_url,
link_attrs, subresource_attrs)
| 94 | // |number_of_requests| is used to ensure that preload requests are actually |
| 95 | // reused as expected. |
| 96 | const SRIPreloadTest = (preload_sri_success, subresource_sri_success, name, |
| 97 | number_of_requests, destination, resource_url, |
| 98 | link_attrs, subresource_attrs) => { |
| 99 | const test = async_test(name); |
| 100 | const link = document.createElement('link'); |
| 101 | |
| 102 | // Early-fail in UAs that do not support `preload` links. |
| 103 | test.step_func(() => { |
| 104 | assert_true(link.relList.supports('preload'), |
| 105 | "This test is automatically failing because the browser does not" + |
| 106 | "support `preload` links."); |
| 107 | })(); |
| 108 | |
| 109 | // Build up the link. |
| 110 | link.rel = 'preload'; |
| 111 | link.as = destination; |
| 112 | link.href = resource_url; |
| 113 | for (const [attr_name, attr_val] of Object.entries(link_attrs)) { |
| 114 | link[attr_name] = attr_val; // This may override `rel` to modulepreload. |
| 115 | } |
| 116 | |
| 117 | // Preload + subresource success and failure loading functions. |
| 118 | const valid_preload_failed = test.step_func(() => |
| 119 | { assert_unreached("Valid preload fired error handler.") }); |
| 120 | const invalid_preload_succeeded = test.step_func(() => |
| 121 | { assert_unreached("Invalid preload load succeeded.") }); |
| 122 | const valid_subresource_failed = test.step_func(() => |
| 123 | { assert_unreached("Valid subresource fired error handler.") }); |
| 124 | const invalid_subresource_succeeded = test.step_func(() => |
| 125 | { assert_unreached("Invalid subresource load succeeded.") }); |
| 126 | const subresource_pass = test.step_func(() => { |
| 127 | verifyNumberOfResourceTimingEntries(resource_url, number_of_requests); |
| 128 | test.done(); |
| 129 | }); |
| 130 | const preload_pass = test.step_func(() => { |
| 131 | const subresource_element = buildElementFromDestination( |
| 132 | resource_url, |
| 133 | destination, |
| 134 | subresource_attrs |
| 135 | ); |
| 136 | |
| 137 | if (subresource_sri_success) { |
| 138 | subresource_element.onload = subresource_pass; |
| 139 | subresource_element.onerror = valid_subresource_failed; |
| 140 | } else { |
| 141 | subresource_element.onload = invalid_subresource_succeeded; |
| 142 | subresource_element.onerror = subresource_pass; |
| 143 | } |
| 144 | |
| 145 | document.body.append(subresource_element); |
| 146 | }); |
| 147 | |
| 148 | if (preload_sri_success) { |
| 149 | link.onload = preload_pass; |
| 150 | link.onerror = valid_preload_failed; |
| 151 | } else { |
| 152 | link.onload = invalid_preload_succeeded; |
| 153 | link.onerror = preload_pass; |
nothing calls this directly
no test coverage detected