| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-cors.html
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-cors.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-cors.html
|
| index 9bd9c2c9f0d7422f89efaffabb9d5c97515550a0..c2cbc19b2890e2b0e88abb45ea19346ccb1a2d67 100644
|
| --- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-cors.html
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-cors.html
|
| @@ -9,6 +9,7 @@
|
| var host_info = get_host_info();
|
| var origin = new URL(self.location).origin;
|
| var wrong_origin = 'https://example.com/';
|
| +var test_header = 'X-ServiceWorker-ServerHeader';
|
|
|
| function url_to_fetch(scope) {
|
| return host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + scope;
|
| @@ -61,17 +62,17 @@ function verify_network_error(url, t) {
|
| });
|
| }
|
|
|
| -// Verifies that fetching the URL returns a readable response.
|
| -// Also verifies that round-tripping this response through the cache doesn't
|
| -// cause issues.
|
| -function verify_cors_fetch(url) {
|
| +// Verifies that fetching the URL returns a cors response, with a specific value
|
| +// for a test_header on the response. Also verifies that round-tripping this
|
| +// response through the cache doesn't cause issues.
|
| +function verify_cors_fetch_with_header_value(url, header_value) {
|
| var response;
|
| var cache;
|
| return fetch(url)
|
| .then(r => {
|
| response = r.clone();
|
| - // TODO(mek): Uncomment when cors filtering is implemented.
|
| - // assert_equals(r.type, 'cors');
|
| + assert_equals(r.type, 'cors');
|
| + assert_equals(r.headers.get(test_header), header_value, 'From fetch');
|
| return r.text();
|
| })
|
| .then(response_text => {
|
| @@ -84,8 +85,8 @@ function verify_cors_fetch(url) {
|
| })
|
| .then(() => cache.match(url))
|
| .then(r => {
|
| - // TODO(mek): Uncomment when cors filtering is implemented.
|
| - // assert_equals(r.type, 'cors');
|
| + assert_equals(r.type, 'cors');
|
| + assert_equals(r.headers.get(test_header), header_value, 'From cache');
|
| return r.text();
|
| })
|
| .then(response_text => {
|
| @@ -102,9 +103,22 @@ function verify_cors_fetch(url) {
|
| }))
|
| .then(xhr => {
|
| assert_true(xhr.responseText.startsWith('report('));
|
| + assert_equals(xhr.getResponseHeader(test_header), header_value);
|
| + var headers = xhr.getAllResponseHeaders().toLowerCase();
|
| + if (header_value) {
|
| + assert_true(headers.includes(test_header.toLowerCase() + ': ' +
|
| + header_value.toLowerCase()));
|
| + } else {
|
| + assert_false(headers.includes(test_header.toLowerCase()));
|
| + }
|
| });
|
| }
|
|
|
| +verify_cors_fetch_with_header =
|
| + url => verify_cors_fetch_with_header_value(url, 'SetInTheServer');
|
| +verify_cors_fetch_without_header =
|
| + url => verify_cors_fetch_with_header_value(url, null);
|
| +
|
| var tests = [
|
| {
|
| description: 'Same origin fetch without CORS headers, not exposed',
|
| @@ -117,14 +131,25 @@ var tests = [
|
| expectation: verify_opaque_fetch
|
| },
|
| {
|
| - description: 'Same origin fetch without CORS headers, origin exposed',
|
| + description: 'Same origin fetch without CORS headers, only origin exposed',
|
| params: {
|
| cross_origin: false,
|
| with_aceheaders: false,
|
| with_acaorigin: false
|
| },
|
| response: {origin: origin},
|
| - expectation: verify_cors_fetch
|
| + expectation: verify_cors_fetch_without_header
|
| + },
|
| + {
|
| + description:
|
| + 'Same origin fetch without CORS headers, headers and origin exposed',
|
| + params: {
|
| + cross_origin: false,
|
| + with_aceheaders: false,
|
| + with_acaorigin: false
|
| + },
|
| + response: {origin: origin, headers: [test_header]},
|
| + expectation: verify_cors_fetch_with_header
|
| },
|
| {
|
| description:
|
| @@ -134,7 +159,7 @@ var tests = [
|
| with_aceheaders: false,
|
| with_acaorigin: false
|
| },
|
| - response: {origin: wrong_origin},
|
| + response: {origin: wrong_origin, headers: [test_header]},
|
| expectation: verify_network_error
|
| },
|
| {
|
| @@ -148,14 +173,25 @@ var tests = [
|
| expectation: verify_opaque_fetch
|
| },
|
| {
|
| - description: 'Same origin fetch with CORS headers, origin exposed',
|
| + description: 'Same origin fetch with CORS headers, only origin exposed',
|
| params: {
|
| cross_origin: false,
|
| with_aceheaders: true,
|
| with_acaorigin: true
|
| },
|
| response: {origin: origin},
|
| - expectation: verify_cors_fetch
|
| + expectation: verify_cors_fetch_without_header
|
| + },
|
| + {
|
| + description:
|
| + 'Same origin fetch with CORS headers, headers and origin exposed',
|
| + params: {
|
| + cross_origin: false,
|
| + with_aceheaders: true,
|
| + with_acaorigin: true
|
| + },
|
| + response: {origin: origin, headers: [test_header]},
|
| + expectation: verify_cors_fetch_with_header
|
| },
|
| {
|
| description: 'Same origin fetch with CORS headers, exposed to wrong origin',
|
| @@ -164,7 +200,7 @@ var tests = [
|
| with_aceheaders: true,
|
| with_acaorigin: true
|
| },
|
| - response: {origin: wrong_origin},
|
| + response: {origin: wrong_origin, headers: [test_header]},
|
| expectation: verify_network_error
|
| },
|
| {
|
| @@ -178,7 +214,7 @@ var tests = [
|
| expectation: verify_opaque_fetch
|
| },
|
| {
|
| - description: 'Cross origin fetch with CORS headers, not exposed',
|
| + description: 'Cross origin fetch with ACEHeaders header, not exposed',
|
| params: {
|
| cross_origin: true,
|
| with_aceheaders: true,
|
| @@ -188,25 +224,69 @@ var tests = [
|
| expectation: verify_opaque_fetch
|
| },
|
| {
|
| - description: 'Cross origin fetch with CORS headers, origin exposed',
|
| + description:
|
| + 'Cross origin fetch with ACEHeaders header, only origin exposed',
|
| params: {
|
| cross_origin: true,
|
| with_aceheaders: true,
|
| with_acaorigin: true
|
| },
|
| response: {origin: origin},
|
| - expectation: verify_cors_fetch
|
| + expectation: verify_cors_fetch_without_header
|
| + },
|
| + {
|
| + description:
|
| + 'Cross origin fetch with ACEHeaders header, headers and origin exposed',
|
| + params: {
|
| + cross_origin: true,
|
| + with_aceheaders: true,
|
| + with_acaorigin: true
|
| + },
|
| + response: {origin: origin, headers: [test_header]},
|
| + expectation: verify_cors_fetch_with_header
|
| },
|
| {
|
| description:
|
| - 'Cross origin fetch with CORS headers, exposed to wrong origin',
|
| + 'Cross origin fetch with ACEHeaders header, exposed to wrong origin',
|
| params: {
|
| cross_origin: true,
|
| with_aceheaders: true,
|
| with_acaorigin: true
|
| },
|
| - response: {origin: wrong_origin},
|
| + response: {origin: wrong_origin, headers: [test_header]},
|
| expectation: verify_network_error
|
| + },
|
| + {
|
| + description: 'Cross origin fetch without ACEHeaders header, not exposed',
|
| + params: {
|
| + cross_origin: true,
|
| + with_aceheaders: false,
|
| + with_acaorigin: true
|
| + },
|
| + response: {},
|
| + expectation: verify_opaque_fetch
|
| + },
|
| + {
|
| + description:
|
| + 'Cross origin fetch without ACEHeaders header, only origin exposed',
|
| + params: {
|
| + cross_origin: true,
|
| + with_aceheaders: false,
|
| + with_acaorigin: true
|
| + },
|
| + response: {origin: origin},
|
| + expectation: verify_cors_fetch_without_header
|
| + },
|
| + {
|
| + description: 'Cross origin fetch without ACEHeaders header, ' +
|
| + 'headers and origin exposed',
|
| + params: {
|
| + cross_origin: true,
|
| + with_aceheaders: false,
|
| + with_acaorigin: true
|
| + },
|
| + response: {origin: origin, headers: [test_header]},
|
| + expectation: verify_cors_fetch_without_header
|
| }
|
| ];
|
|
|
|
|