OLD | NEW |
(Empty) | |
| 1 import time |
| 2 |
| 3 def main(request, response): |
| 4 # Set mode to 'init' for initial fetch. |
| 5 mode = 'init' |
| 6 if 'mode' in request.cookies: |
| 7 mode = request.cookies['mode'].value |
| 8 |
| 9 # no-cache itself to ensure the user agent finds a new version for each upda
te. |
| 10 headers = [('Cache-Control', 'no-cache, must-revalidate'), |
| 11 ('Pragma', 'no-cache')] |
| 12 |
| 13 content_type = '' |
| 14 extra_body = '' |
| 15 |
| 16 if mode == 'init': |
| 17 # Set a normal mimetype. |
| 18 # Set cookie value to 'normal' so the next fetch will work in 'normal' m
ode. |
| 19 content_type = 'application/javascript' |
| 20 response.set_cookie('mode', 'normal') |
| 21 elif mode == 'normal': |
| 22 # Set a normal mimetype. |
| 23 # Set cookie value to 'error' so the next fetch will work in 'error' mod
e. |
| 24 content_type = 'application/javascript' |
| 25 response.set_cookie('mode', 'error'); |
| 26 elif mode == 'error': |
| 27 # Set a disallowed mimetype. |
| 28 # Set cookie value to 'syntax-error' so the next fetch will work in 'syn
tax-error' mode. |
| 29 content_type = 'text/html' |
| 30 response.set_cookie('mode', 'syntax-error'); |
| 31 elif mode == 'syntax-error': |
| 32 # Set cookie value to 'throw-install' so the next fetch will work in 'th
row-install' mode. |
| 33 content_type = 'application/javascript' |
| 34 response.set_cookie('mode', 'throw-install'); |
| 35 extra_body = 'badsyntax(isbad;' |
| 36 elif mode == 'throw-install': |
| 37 # Unset and delete cookie to clean up the test setting. |
| 38 content_type = 'application/javascript' |
| 39 response.delete_cookie('mode') |
| 40 extra_body = "addEventListener('install', function(e) { throw new Error(
'boom'); });" |
| 41 |
| 42 headers.append(('Content-Type', content_type)) |
| 43 # Return a different script for each access. Use .time() and .clock() for |
| 44 # best time resolution across different platforms. |
| 45 return headers, '/* %s %s */ %s' % (time.time(), time.clock(), extra_body) |
| 46 |
OLD | NEW |