Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: LayoutTests/http/tests/serviceworker/chromium/fetch-script-onerror.html

Issue 1151433002: Add LayoutTest for the script error sanitization for ServiceWorker fetched scripts. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: s/messageCallback/message_callback Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/chromium/fetch-script-onerror-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/serviceworker/chromium/fetch-script-onerror.html
diff --git a/LayoutTests/http/tests/serviceworker/chromium/fetch-script-onerror.html b/LayoutTests/http/tests/serviceworker/chromium/fetch-script-onerror.html
new file mode 100644
index 0000000000000000000000000000000000000000..1dcbe2a52b0420f64e1a8bf750c7ac7c425ac03c
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/chromium/fetch-script-onerror.html
@@ -0,0 +1,97 @@
+<!DOCTYPE html>
+<title>Service Worker: Check script error sanitization</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/get-host-info.js"></script>
+<script src="../resources/test-helpers.js"></script>
+<script>
+var message_callback;
+var host_info = get_host_info();
+
+window.addEventListener('message', function(evt) {
+ message_callback(evt.data);
+ });
+
+function get_script_error(frame, url) {
+ return new Promise(function(resolve) {
+ message_callback = resolve;
+ frame.contentWindow.postMessage({url: url}, host_info['HTTP_ORIGIN']);
+ });
+}
+
+function check_script_error(frame, url, should_be_sanitized) {
+ if (should_be_sanitized) {
+ return get_script_error(frame, url)
+ .then(function(data) {
+ assert_equals(data.filename, '');
+ assert_equals(data.colno, 0);
+ assert_equals(data.lineno, 0);
+ assert_equals(data.message, 'Script error.');
+ });
+ } else {
+ return get_script_error(frame, url)
+ .then(function(data) {
+ assert_equals(data.filename, url);
+ assert_equals(data.colno, 1);
+ assert_equals(data.lineno, 1);
+ assert_equals(data.message,
+ 'Uncaught ReferenceError: UndefinedReference is not defined');
+ });
+ }
+}
+
+async_test(function(t) {
+ var SCOPE = 'resources/fetch-script-onerror-iframe.html';
+ var WORKER_SCRIPT = 'resources/fetch-script-onerror-worker.js';
+ var TARGET_PATH =
+ '/serviceworker/chromium/resources/fetch-script-onerror.php';
+ var SCRIPT_URL = host_info['HTTP_ORIGIN'] + TARGET_PATH;
+ var REMOTE_SCRIPT_URL = host_info['HTTP_REMOTE_ORIGIN'] + TARGET_PATH;
+ var frame;
+ service_worker_unregister_and_register(t, WORKER_SCRIPT, SCOPE)
+ .then(function(registration) {
+ return wait_for_state(t, registration.installing, 'activated');
+ })
+ .then(function() { return with_iframe(SCOPE); })
+ .then(function(f) {
+ frame = f;
+ return check_script_error(frame, SCRIPT_URL, false);
+ })
+ .then(function() {
+ return check_script_error(frame, REMOTE_SCRIPT_URL, true);
+ })
+ .then(function() {
+ return check_script_error(
+ frame,
+ host_info['HTTP_ORIGIN'] + '/dummy?mode=cors&url=' +
+ encodeURIComponent(REMOTE_SCRIPT_URL),
+ false);
+ })
+ .then(function() {
+ return check_script_error(
+ frame,
+ host_info['HTTP_ORIGIN'] + '/dummy?mode=no-cors&url=' +
+ encodeURIComponent(REMOTE_SCRIPT_URL),
+ true);
+ })
+ .then(function() {
+ return check_script_error(
+ frame,
+ host_info['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=cors&url=' +
+ encodeURIComponent(REMOTE_SCRIPT_URL),
+ false);
+ })
+ .then(function() {
+ return check_script_error(
+ frame,
+ host_info['HTTP_REMOTE_ORIGIN'] + '/dummy?mode=no-cors&url=' +
+ encodeURIComponent(REMOTE_SCRIPT_URL),
+ true);
+ })
+ .then(function() {
+ frame.remove();
+ service_worker_unregister_and_done(t, SCOPE);
+ })
+ .catch(unreached_rejection(t));
+ }, 'Check script error sanitization');
+</script>
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/chromium/fetch-script-onerror-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698