Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Service Worker: Check script error sanitization</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="../resources/get-host-info.js"></script> | |
| 6 <script src="resources/test-helpers.js?pipe=sub"></script> | |
| 7 <script> | |
| 8 var messageCallback; | |
| 9 var host_info = get_host_info(); | |
| 10 | |
| 11 window.addEventListener('message', function(evt) { | |
| 12 messageCallback(evt.data); | |
| 13 }); | |
| 14 | |
| 15 function get_script_error(frame, url) { | |
| 16 return new Promise(function(resolve) { | |
| 17 messageCallback = resolve; | |
| 18 frame.contentWindow.postMessage({url: url}, host_info['HTTP_ORIGIN']) | |
|
falken
2015/05/26 01:23:35
nit: missing semicolon
horo
2015/05/26 03:12:14
Done.
| |
| 19 }); | |
| 20 } | |
| 21 | |
| 22 function check_script_error(frame, url, shuold_be_sanitized) { | |
|
falken
2015/05/26 01:23:35
nit: s/shuold/should
horo
2015/05/26 03:12:14
Done.
| |
| 23 if (shuold_be_sanitized) { | |
| 24 return get_script_error(frame, url) | |
| 25 .then(function(data) { | |
| 26 assert_equals(data.filename, ''); | |
| 27 assert_equals(data.colno, 0); | |
| 28 assert_equals(data.lineno, 0); | |
| 29 assert_equals(data.message, 'Script error.'); | |
|
falken
2015/05/26 01:23:35
I don't think this message will be the same across
horo
2015/05/26 03:12:14
Done.
| |
| 30 }); | |
| 31 } else { | |
| 32 return get_script_error(frame, url) | |
| 33 .then(function(data) { | |
| 34 assert_equals(data.filename, url); | |
| 35 assert_equals(data.colno, 1); | |
| 36 assert_equals(data.lineno, 1); | |
| 37 assert_equals(data.message, | |
| 38 'Uncaught ReferenceError: SampleData is not defined'); | |
| 39 }); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 async_test(function(t) { | |
| 44 var SCOPE = 'resources/fetch-script-onerror-iframe.html'; | |
| 45 var WORKER_SCRIPT = 'resources/fetch-rewrite-worker.js'; | |
| 46 var TARGET_PATH = '/serviceworker/resources/fetch-script-onerror.php'; | |
| 47 var SCRIPT_URL = host_info['HTTP_ORIGIN'] + TARGET_PATH; | |
| 48 var REMOTE_SCRIPT_URL = host_info['HTTP_REMOTE_ORIGIN'] + TARGET_PATH; | |
| 49 var frame; | |
| 50 service_worker_unregister_and_register(t, WORKER_SCRIPT, SCOPE) | |
| 51 .then(function(registration) { | |
| 52 return wait_for_state(t, registration.installing, 'activated'); | |
| 53 }) | |
| 54 .then(function() { return with_iframe(SCOPE); }) | |
| 55 .then(function(f) { | |
| 56 frame = f; | |
| 57 return check_script_error(frame, SCRIPT_URL, false); | |
| 58 }) | |
| 59 .then(function() { | |
| 60 return check_script_error(frame, REMOTE_SCRIPT_URL, true); | |
| 61 }) | |
| 62 .then(function() { | |
| 63 return check_script_error( | |
| 64 frame, | |
| 65 host_info['HTTP_ORIGIN'] + '/dummy?mode=cors&url=' + | |
| 66 encodeURIComponent(REMOTE_SCRIPT_URL), | |
| 67 false); | |
| 68 }) | |
| 69 .then(function() { | |
| 70 return check_script_error( | |
| 71 frame, | |
| 72 host_info['HTTP_ORIGIN'] + '/dummy?mode=no-cors&url=' + | |
| 73 encodeURIComponent(REMOTE_SCRIPT_URL), | |
| 74 true); | |
| 75 }) | |
| 76 .then(function() { | |
| 77 return check_script_error( | |
| 78 frame, | |
| 79 host_info['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=cors&url=' + | |
| 80 encodeURIComponent(REMOTE_SCRIPT_URL), | |
| 81 false); | |
| 82 }) | |
| 83 .then(function() { | |
| 84 return check_script_error( | |
| 85 frame, | |
| 86 host_info['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=no-cors&url=' + | |
| 87 encodeURIComponent(REMOTE_SCRIPT_URL), | |
| 88 true); | |
| 89 }) | |
| 90 .then(function() { | |
| 91 frame.remove(); | |
| 92 service_worker_unregister_and_done(t, SCOPE); | |
| 93 }) | |
| 94 .catch(unreached_rejection(t)); | |
| 95 }, 'Check script error sanitization'); | |
| 96 </script> | |
| OLD | NEW |