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

Unified Diff: LayoutTests/http/tests/serviceworker/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: 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
Index: LayoutTests/http/tests/serviceworker/fetch-script-onerror.html
diff --git a/LayoutTests/http/tests/serviceworker/fetch-script-onerror.html b/LayoutTests/http/tests/serviceworker/fetch-script-onerror.html
new file mode 100644
index 0000000000000000000000000000000000000000..915330aed7559de4aa794ac65e700ce1bfe70601
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/fetch-script-onerror.html
@@ -0,0 +1,96 @@
+<!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?pipe=sub"></script>
+<script>
+var messageCallback;
+var host_info = get_host_info();
+
+window.addEventListener('message', function(evt) {
+ messageCallback(evt.data);
+ });
+
+function get_script_error(frame, url) {
+ return new Promise(function(resolve) {
+ messageCallback = resolve;
+ 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.
+ });
+}
+
+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.
+ if (shuold_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.');
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.
+ });
+ } 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: SampleData is not defined');
+ });
+ }
+}
+
+async_test(function(t) {
+ var SCOPE = 'resources/fetch-script-onerror-iframe.html';
+ var WORKER_SCRIPT = 'resources/fetch-rewrite-worker.js';
+ var TARGET_PATH = '/serviceworker/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>

Powered by Google App Engine
This is Rietveld 408576698