diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/service-workers/service-worker/resources/update-worker.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/service-workers/service-worker/resources/update-worker.py')
-rw-r--r-- | testing/web-platform/tests/service-workers/service-worker/resources/update-worker.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/update-worker.py b/testing/web-platform/tests/service-workers/service-worker/resources/update-worker.py new file mode 100644 index 0000000000..5638a8849c --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/resources/update-worker.py @@ -0,0 +1,62 @@ +from urllib.parse import unquote + +from wptserve.utils import isomorphic_decode, isomorphic_encode + +def redirect_response(request, response, visited_count): + # |visited_count| is used as a unique id to differentiate responses + # every time. + location = b'empty.js' + if b'Redirect' in request.GET: + location = isomorphic_encode(unquote(isomorphic_decode(request.GET[b'Redirect']))) + return (301, + [ + (b'Cache-Control', b'no-cache, must-revalidate'), + (b'Pragma', b'no-cache'), + (b'Content-Type', b'application/javascript'), + (b'Location', location), + ], + u'/* %s */' % str(visited_count)) + +def not_found_response(): + return 404, [(b'Content-Type', b'text/plain')], u"Page not found" + +def ok_response(request, response, visited_count, + extra_body=u'', mime_type=b'application/javascript'): + # |visited_count| is used as a unique id to differentiate responses + # every time. + return ( + [ + (b'Cache-Control', b'no-cache, must-revalidate'), + (b'Pragma', b'no-cache'), + (b'Content-Type', mime_type) + ], + u'/* %s */ %s' % (str(visited_count), extra_body)) + +def main(request, response): + key = request.GET[b"Key"] + mode = request.GET[b"Mode"] + + visited_count = request.server.stash.take(key) + if visited_count is None: + visited_count = 0 + + # Keep how many times the test requested this resource. + visited_count += 1 + request.server.stash.put(key, visited_count) + + # Return a response based on |mode| only when it's the second time (== update). + if visited_count == 2: + if mode == b'normal': + return ok_response(request, response, visited_count) + if mode == b'bad_mime_type': + return ok_response(request, response, visited_count, mime_type=b'text/html') + if mode == b'not_found': + return not_found_response() + if mode == b'redirect': + return redirect_response(request, response, visited_count) + if mode == b'syntax_error': + return ok_response(request, response, visited_count, extra_body=u'badsyntax(isbad;') + if mode == b'throw_install': + return ok_response(request, response, visited_count, extra_body=u"addEventListener('install', function(e) { throw new Error('boom'); });") + + return ok_response(request, response, visited_count) |