<!DOCTYPE html>
<meta charset="utf-8">
<title>
The subresource load should not be blocked by skipping the fetch handler.
</title>
<!-- This cannot be upstreamed to WPT because it test uses Chrome's UseCounter
mechanism. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<script>
function isUseCounted(win, feature) {
return win.internals.isUseCounted(win.document, feature);
}
function observeUseCounter(win, feature) {
return win.internals.observeUseCounter(win.document, feature);
}
function addStyleSheet(win, href) {
const link = win.document.createElement('link');
link.rel = 'stylesheet';
link.href = href;
win.document.head.appendChild(link);
}
const scope = 'resources/simple.html';
// |kServiceWorkerNotHandledSubresourceLoad| in web_feature.mojom.
const kFeature = 4363;
promise_test(async t => {
const registration = await service_worker_unregister_and_register(
t, 'resources/empty-fetch-handler.js', scope);
t.add_cleanup(() => { registration.unregister(); });
await wait_for_state(t, registration.installing, 'activated');
// Set up the iframe in the scope.
const frame = await with_iframe('resources/simple.html');
t.add_cleanup(() => { frame.remove(); });
const win = frame.contentWindow;
// Ensure that the window is controlled by the service worker.
assert_not_equals(win.navigator.serviceWorker.controller, null);
// The stylesheet loaded at the page controlled by the service worker.
addStyleSheet(win, 'font-face.css');
// Ensure the service worker has been skipped.
await observeUseCounter(win, kFeature);
assert_true(isUseCounted(win, kFeature));
}, 'An empty service worker handler should be skipped for loading subresource');
</script>