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"></script> | |
7 <script> | |
8 var messageCallback; | |
falken
2015/05/26 03:27:41
nit: message_callback
horo
2015/05/26 03:58:41
Done.
| |
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']); | |
19 }); | |
20 } | |
21 | |
22 function check_script_error(frame, url, should_be_sanitized) { | |
23 if (should_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.'); | |
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: UndefinedReference is not defi ned'); | |
39 }); | |
40 } | |
41 } | |
42 | |
43 async_test(function(t) { | |
44 var SCOPE = 'resources/fetch-script-onerror-iframe.html'; | |
45 var WORKER_SCRIPT = 'resources/fetch-script-onerror-worker.js'; | |
46 var TARGET_PATH = | |
47 '/serviceworker/chromium/resources/fetch-script-onerror.php'; | |
48 var SCRIPT_URL = host_info['HTTP_ORIGIN'] + TARGET_PATH; | |
49 var REMOTE_SCRIPT_URL = host_info['HTTP_REMOTE_ORIGIN'] + TARGET_PATH; | |
50 var frame; | |
51 service_worker_unregister_and_register(t, WORKER_SCRIPT, SCOPE) | |
52 .then(function(registration) { | |
53 return wait_for_state(t, registration.installing, 'activated'); | |
54 }) | |
55 .then(function() { return with_iframe(SCOPE); }) | |
56 .then(function(f) { | |
57 frame = f; | |
58 return check_script_error(frame, SCRIPT_URL, false); | |
59 }) | |
60 .then(function() { | |
61 return check_script_error(frame, REMOTE_SCRIPT_URL, true); | |
62 }) | |
63 .then(function() { | |
64 return check_script_error( | |
65 frame, | |
66 host_info['HTTP_ORIGIN'] + '/dummy?mode=cors&url=' + | |
67 encodeURIComponent(REMOTE_SCRIPT_URL), | |
68 false); | |
69 }) | |
70 .then(function() { | |
71 return check_script_error( | |
72 frame, | |
73 host_info['HTTP_ORIGIN'] + '/dummy?mode=no-cors&url=' + | |
74 encodeURIComponent(REMOTE_SCRIPT_URL), | |
75 true); | |
76 }) | |
77 .then(function() { | |
78 return check_script_error( | |
79 frame, | |
80 host_info['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=cors&url=' + | |
81 encodeURIComponent(REMOTE_SCRIPT_URL), | |
82 false); | |
83 }) | |
84 .then(function() { | |
85 return check_script_error( | |
86 frame, | |
87 host_info['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=no-cors&url=' + | |
88 encodeURIComponent(REMOTE_SCRIPT_URL), | |
89 true); | |
90 }) | |
91 .then(function() { | |
92 frame.remove(); | |
93 service_worker_unregister_and_done(t, SCOPE); | |
94 }) | |
95 .catch(unreached_rejection(t)); | |
96 }, 'Check script error sanitization'); | |
97 </script> | |
OLD | NEW |