Skip to content

Commit

Permalink
[Background Fetch] Move CORS preflight check to the controller.
Browse files Browse the repository at this point in the history
Bug: 889888
Change-Id: I2429361627ffea2e1b8d5a11eb0e34b0cbfa1abb
  • Loading branch information
Mugdha Lakhani authored and wpt-autoroller committed Oct 3, 2018
1 parent efa4c0d commit a82753a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions background-fetch/fetch.https.window.js
Expand Up @@ -82,6 +82,41 @@ backgroundFetchTest(async (test, backgroundFetch) => {

}, 'Empty URL is OK.');

backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = uniqueId();
const registration =
await backgroundFetch.fetch(registrationId,
new Request('https://example/com', {
method: 'PUT',
}));

assert_equals(registration.id, registrationId);

const {type, eventRegistration, results} = await getMessageFromServiceWorker();

assert_equals(type, 'backgroundfetchsuccess');
assert_equals(eventRegistration.result, 'success');
assert_equals(eventRegistration.failureReason, '');
}, 'Requests with PUT method require CORS Preflight and succeed.');

backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = uniqueId();
const registration =
await backgroundFetch.fetch(registrationId,
new Request('https://example/com', {
method: 'POST',
headers: {'Content-Type': 'text/json'}
}));

assert_equals(registration.id, registrationId);

const {type, eventRegistration, results} = await getMessageFromServiceWorker();

assert_equals(type, 'backgroundfetchsuccess');
assert_equals(eventRegistration.result, 'success');
assert_equals(eventRegistration.failureReason, '');
}, 'Requests with text/json content type require CORS Preflight and succeed.');

backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = uniqueId();
const registration =
Expand Down

0 comments on commit a82753a

Please sign in to comment.