summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/navigation-redirect-to-http-worker.js
blob: 6f2a8ae1d749bb58e547bdb511b895b0e6bdee43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
importScripts('/resources/testharness.js');

self.addEventListener('fetch', function(event) {
    event.respondWith(new Promise(function(resolve) {
      Promise.resolve()
        .then(function() {
            assert_equals(
                event.request.redirect, 'manual',
                'The redirect mode of navigation request must be manual.');
            return fetch(event.request);
          })
        .then(function(response) {
            assert_equals(
                response.type, 'opaqueredirect',
                'The response type of 302 response must be opaqueredirect.');
            resolve(new Response('OK'));
          })
        .catch(function(error) {
            resolve(new Response('Failed in SW: ' + error));
          });
    }));
  });