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>
9 var host_info
= get_host_info();
11 window
.addEventListener('message', function(evt
) {
12 message_callback(evt
.data
);
15 function get_script_error(frame
, url
) {
16 return new Promise(function(resolve
) {
17 message_callback
= resolve
;
18 frame
.contentWindow
.postMessage({url
: url
}, host_info
['HTTP_ORIGIN']);
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.');
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 defined');
43 async_test(function(t
) {
44 var SCOPE
= 'resources/fetch-script-onerror-iframe.html';
45 var WORKER_SCRIPT
= 'resources/fetch-script-onerror-worker.js';
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
;
51 service_worker_unregister_and_register(t
, WORKER_SCRIPT
, SCOPE
)
52 .then(function(registration
) {
53 return wait_for_state(t
, registration
.installing
, 'activated');
55 .then(function() { return with_iframe(SCOPE
); })
58 return check_script_error(frame
, SCRIPT_URL
, false);
61 return check_script_error(frame
, REMOTE_SCRIPT_URL
, true);
64 return check_script_error(
66 host_info
['HTTP_ORIGIN'] + '/dummy?mode=cors&url=' +
67 encodeURIComponent(REMOTE_SCRIPT_URL
),
71 return check_script_error(
73 host_info
['HTTP_ORIGIN'] + '/dummy?mode=no-cors&url=' +
74 encodeURIComponent(REMOTE_SCRIPT_URL
),
78 return check_script_error(
80 host_info
['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=cors&url=' +
81 encodeURIComponent(REMOTE_SCRIPT_URL
),
85 return check_script_error(
87 host_info
['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=no-cors&url=' +
88 encodeURIComponent(REMOTE_SCRIPT_URL
),
93 service_worker_unregister_and_done(t
, SCOPE
);
95 .catch(unreached_rejection(t
));
96 }, 'Check script error sanitization');