| Index: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/service-worker-csp-worker.py
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/service-worker-csp-worker.php b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/service-worker-csp-worker.py
|
| similarity index 55%
|
| copy from third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/service-worker-csp-worker.php
|
| copy to third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/service-worker-csp-worker.py
|
| index 89cd382b4aec9b61f4d38bcb6dfc1628810b698c..4e5c6f3b6ea08f09caa1600bea31b7c52853d3a4 100644
|
| --- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/service-worker-csp-worker.php
|
| +++ b/third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/service-worker-csp-worker.py
|
| @@ -1,22 +1,15 @@
|
| -<?php
|
| -header('Content-Type: application/javascript');
|
| -$directive = $_GET['directive'];
|
| -
|
| -if ($directive == 'default') {
|
| - header('Content-Security-Policy: default-src \'self\'');
|
| -
|
| -?>
|
| +bodyDefault = '''
|
| importScripts('worker-testharness.js');
|
| -importScripts('test-helpers.js');
|
| -importScripts('../../resources/get-host-info.js');
|
| +importScripts('test-helpers.sub.js');
|
| +importScripts('../resources/get-host-info.sub.js');
|
|
|
| var host_info = get_host_info();
|
|
|
| test(function() {
|
| var import_script_failed = false;
|
| try {
|
| - importScripts(host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/empty.js');
|
| + importScripts(host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'empty.js');
|
| } catch(e) {
|
| import_script_failed = true;
|
| }
|
| @@ -25,8 +18,8 @@ test(function() {
|
| }, 'importScripts test for default-src');
|
|
|
| async_test(function(t) {
|
| - fetch(host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*',
|
| + fetch(host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'fetch-access-control.py?ACAOrigin=*',
|
| {mode: 'cors'})
|
| .then(function(response){
|
| assert_unreached('fetch should fail.');
|
| @@ -37,10 +30,10 @@ async_test(function(t) {
|
| }, 'Fetch test for default-src');
|
|
|
| async_test(function(t) {
|
| - var REDIRECT_URL = host_info.HTTP_ORIGIN +
|
| - '/serviceworker/resources/redirect.php?Redirect=';
|
| - var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/fetch-access-control.php?'
|
| + var REDIRECT_URL = host_info.HTTPS_ORIGIN +
|
| + base_path() + 'redirect.py?Redirect=';
|
| + var OTHER_BASE_URL = host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'fetch-access-control.py?'
|
| fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
|
| {mode: 'cors'})
|
| .then(function(response){
|
| @@ -49,25 +42,20 @@ async_test(function(t) {
|
| t.done();
|
| })
|
| .catch(unreached_rejection(t));
|
| - }, 'Redirected fetch test for default-src');
|
| -
|
| -<?php
|
| -
|
| -} else if ($directive == 'script') {
|
| - header('Content-Security-Policy: script-src \'self\'');
|
| + }, 'Redirected fetch test for default-src');'''
|
|
|
| -?>
|
| +bodyScript = '''
|
| importScripts('worker-testharness.js');
|
| -importScripts('test-helpers.js');
|
| -importScripts('../../resources/get-host-info.js');
|
| +importScripts('test-helpers.sub.js');
|
| +importScripts('../resources/get-host-info.sub.js');
|
|
|
| var host_info = get_host_info();
|
|
|
| test(function() {
|
| var import_script_failed = false;
|
| try {
|
| - importScripts(host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/empty.js');
|
| + importScripts(host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'empty.js');
|
| } catch(e) {
|
| import_script_failed = true;
|
| }
|
| @@ -76,8 +64,8 @@ test(function() {
|
| }, 'importScripts test for script-src');
|
|
|
| async_test(function(t) {
|
| - fetch(host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*',
|
| + fetch(host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'fetch-access-control.py?ACAOrigin=*',
|
| {mode: 'cors'})
|
| .then(function(response){
|
| t.done();
|
| @@ -88,10 +76,10 @@ async_test(function(t) {
|
| }, 'Fetch test for script-src');
|
|
|
| async_test(function(t) {
|
| - var REDIRECT_URL = host_info.HTTP_ORIGIN +
|
| - '/serviceworker/resources/redirect.php?Redirect=';
|
| - var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/fetch-access-control.php?'
|
| + var REDIRECT_URL = host_info.HTTPS_ORIGIN +
|
| + base_path() + 'redirect.py?Redirect=';
|
| + var OTHER_BASE_URL = host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'fetch-access-control.py?'
|
| fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
|
| {mode: 'cors'})
|
| .then(function(response){
|
| @@ -100,25 +88,20 @@ async_test(function(t) {
|
| assert_unreached('Redirected fetch should not fail.');
|
| })
|
| .catch(unreached_rejection(t));
|
| - }, 'Redirected fetch test for script-src');
|
| + }, 'Redirected fetch test for script-src');'''
|
|
|
| -<?php
|
| -
|
| -} else if ($directive == 'connect') {
|
| - header('Content-Security-Policy: connect-src \'self\'');
|
| -
|
| -?>
|
| +bodyConnect = '''
|
| importScripts('worker-testharness.js');
|
| -importScripts('test-helpers.js');
|
| -importScripts('../../resources/get-host-info.js');
|
| +importScripts('test-helpers.sub.js');
|
| +importScripts('../resources/get-host-info.sub.js');
|
|
|
| var host_info = get_host_info();
|
|
|
| test(function() {
|
| var import_script_failed = false;
|
| try {
|
| - importScripts(host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/empty.js');
|
| + importScripts(host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'empty.js');
|
| } catch(e) {
|
| import_script_failed = true;
|
| }
|
| @@ -127,8 +110,8 @@ test(function() {
|
| }, 'importScripts test for connect-src');
|
|
|
| async_test(function(t) {
|
| - fetch(host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*',
|
| + fetch(host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'fetch-access-control.py?ACAOrigin=*',
|
| {mode: 'cors'})
|
| .then(function(response){
|
| assert_unreached('fetch should fail.');
|
| @@ -139,10 +122,10 @@ async_test(function(t) {
|
| }, 'Fetch test for connect-src');
|
|
|
| async_test(function(t) {
|
| - var REDIRECT_URL = host_info.HTTP_ORIGIN +
|
| - '/serviceworker/resources/redirect.php?Redirect=';
|
| - var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN +
|
| - '/serviceworker/resources/fetch-access-control.php?'
|
| + var REDIRECT_URL = host_info.HTTPS_ORIGIN +
|
| + base_path() + 'redirect.py?Redirect=';
|
| + var OTHER_BASE_URL = host_info.HTTPS_REMOTE_ORIGIN +
|
| + base_path() + 'fetch-access-control.py?'
|
| fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
|
| {mode: 'cors'})
|
| .then(function(response){
|
| @@ -151,8 +134,20 @@ async_test(function(t) {
|
| t.done();
|
| })
|
| .catch(unreached_rejection(t));
|
| - }, 'Redirected fetch test for connect-src');
|
| -
|
| -<?php
|
| -}
|
| -?>
|
| + }, 'Redirected fetch test for connect-src');'''
|
| +
|
| +def main(request, response):
|
| + headers = []
|
| + headers.append(('Content-Type', 'application/javascript'))
|
| + directive = request.GET['directive']
|
| + body = 'ERROR: Unknown directive'
|
| + if directive == 'default':
|
| + headers.append(('Content-Security-Policy', "default-src 'self'"))
|
| + body = bodyDefault
|
| + elif directive == 'script':
|
| + headers.append(('Content-Security-Policy', "script-src 'self'"))
|
| + body = bodyScript
|
| + elif directive == 'connect':
|
| + headers.append(('Content-Security-Policy', "connect-src 'self'"))
|
| + body = bodyConnect
|
| + return headers, body
|
|
|