Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S13nServiceWorker: Support network fallback with blob request body. #9130

Merged
merged 1 commit into from Jan 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 75 additions & 0 deletions service-workers/service-worker/fetch-event.https.html
Expand Up @@ -456,6 +456,43 @@
});
}, 'FetchEvent#body is a string');

// Test that the request body is sent to network upon network fallback,
// for a string body.
promise_test(t => {
// Set scope to "?ignore" so the service worker falls back to network
// for the main resource request, and add a suffix to avoid colliding
// with other tests.
const scope = 'resources/?ignore-for-request-body-fallback-string';
let frame;

return service_worker_unregister_and_register(t, worker, scope)
.then(reg => {
add_completion_callback(() => { reg.unregister(); });
return wait_for_state(t, reg.installing, 'activated');
})
.then(() => {
return with_iframe(scope); })
.then(f => {
frame = f;
// Add "?ignore" so the service worker falls back to echo-content.py.
const echo_url = '/fetch/api/resources/echo-content.py?ignore';
return frame.contentWindow.fetch(echo_url, {
method: 'POST',
body: 'i am the request body'
});
})
.then(response => {
return response.text();
})
.then(response_text => {
frame.remove();
assert_equals(
response_text,
'i am the request body',
'the network fallback request should include the request body');
});
}, 'FetchEvent#body is a string and is passed to network fallback');

// Test that the service worker can read FetchEvent#body when it is a blob.
// It responds with request body it read.
promise_test(t => {
Expand Down Expand Up @@ -489,6 +526,44 @@
});
}, 'FetchEvent#body is a blob');

// Test that the request body is sent to network upon network fallback,
// for a blob body.
promise_test(t => {
// Set scope to "?ignore" so the service worker falls back to network
// for the main resource request, and add a suffix to avoid colliding
// with other tests.
const scope = 'resources/simple.html?ignore-for-request-body-fallback-blob';
let frame;

return service_worker_unregister_and_register(t, worker, scope)
.then(reg => {
add_completion_callback(() => { reg.unregister(); });
return wait_for_state(t, reg.installing, 'activated');
})
.then(() => {
return with_iframe(scope); })
.then(f => {
frame = f;
const blob = new Blob(['it\'s me the blob', ' ', 'and more blob!']);
// Add "?ignore" so the service worker falls back to echo-content.py.
const echo_url = '/fetch/api/resources/echo-content.py?ignore';
return frame.contentWindow.fetch(echo_url, {
method: 'POST',
body: blob
});
})
.then(response => {
return response.text();
})
.then(response_text => {
frame.remove();
assert_equals(
response_text,
'it\'s me the blob and more blob!',
'the network fallback request should include the request body');
});
}, 'FetchEvent#body is a blob and is passed to network fallback');

promise_test(async (t) => {
const scope = 'resources/simple.html?keepalive';

Expand Down