Commit 24bc3bf5 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Add tests for throttling and service worker interception.

This adds tests that won't pass yet for a smaller CL. Split off of
https://chromium-review.googlesource.com/c/chromium/src/+/1174204

Tests that:
- FetchEventForNavigationHasThrottledRequest:
    The service worker fetch event observes headers modified by a
    throttle during navigation.  This is valid in both NetworkService
    and S13nServiceWorker.
- RedirectOccursBeforeFetchEvent:
    The service worker only sees the post-redirect request when a
    throttle redirects. This is valid in both NetworkService and
    S13nServiceWorker.
- NavigationHasThrottledRequestHeadersAfterNetworkFallback:
    After a service worker falls back to network, the request
    contains the headers modified by throttles during navigation.
    This is only valid for NetworkService. Headers are not
    propagated to the network request in the S13nServiceWorker
    case.
- NavigationPreloadHasThrottledRequestHeaders:
    When navigation preload is enabled, the navigation preload
    request contains the headers modified by throttles
    during navigation. This is valid for both NetworkService
    and S13nServiceWorker.

Bug: 873575
Change-Id: Id7d74a9cf7f0a4f15eebe06882039a108e176263
Reviewed-on: https://chromium-review.googlesource.com/1180832Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584394}
parent adfed495
<script>
const params = new URLSearchParams(location.search);
async function run() {
const reg = await navigator.serviceWorker.register(
params.get('worker_url'));
let options = {};
if (params.get('scope'))
options.scope = params.get('scope');
await navigator.serviceWorker.register(
params.get('worker_url'), options);
await navigator.serviceWorker.ready;
document.title = 'DONE';
}
self.onload = run;
async function setup() {
try {
await run();
} catch (error) {
console.error('ERROR: ' + error);
document.title = 'ERROR';
}
}
setup();
</script>
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
self.addEventListener('fetch', event => {
const url = new URL(event.request.url);
if (url.search != '?dump_headers')
return;
event.respondWith((async () => {
const result = {headers: []};
event.request.headers.forEach((value, name) => {
result.headers.push([name, value]);
});
return new Response(
JSON.stringify(result), {headers: [['content-type', 'text/html']]});
})());
});
......@@ -2,4 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
this.onfetch = function(event) { };
var saw_requests = [];
self.addEventListener('fetch', event => {
saw_requests.push(event.request.url);
});
self.addEventListener('message', event => {
event.source.postMessage(saw_requests);
});
HTTP/1.1 200 OK
Content-Type: text/javascript
Service-Worker-Allowed: /
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
self.addEventListener('activate', event => {
event.waitUntil(self.registration.navigationPreload.enable());
});
self.addEventListener('fetch', event => {
if (event.request.mode == 'navigate')
event.respondWith(event.preloadResponse);
});
HTTP/1.1 200 OK
Content-Type: text/javascript
Service-Worker-Allowed: /
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment