Commit 3973b69c authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Have http/tests/xmlhttprequest/open-in-body-* use testharness

With out-of-blink CORS, CORS errors for XHR are displayed in
ResourceLoader, which brings flakiness to open-in-body-* tests, because
Resource and ResourceLoader continue working a while after
ThreadableLoader::Cancel is called, because of the async cancellation
mechanism in ResourceLoader. These tests make ill cross-origin requests,
and then abort them (by calling open() of the same XMLHttpRequest
object) after that. When a response arrives befor the cancellation is
performed but after async cancellation is started, then we see a
console log of a CORS error for an aborted XHR.

Let's have such tests use testharness.js instead of js-test.js so that
such console errors don't affect the test results.

Bug: 736308
Change-Id: I680ce2997a6c10e06368db8a89d789534c47097d
Reviewed-on: https://chromium-review.googlesource.com/1156329
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580035}
parent f22da7dc
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/test.html' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
XMLHttpRequest doesn't crash even when open() is invoked synchronously to handling of a response to a cross-origin request.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!doctype html> <!doctype html>
<script src="/js-test-resources/js-test.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body onload="openXHR();"> <body onload="openXHR();">
<!-- This embed is necessary to cause the synchronous invocation of onload --> <!-- This embed is necessary to cause the synchronous invocation of onload -->
<embed type="text/html; charset=utf-8"> <embed type="text/html; charset=utf-8">
<script> <script>
window.jsTestIsAsync = true; const xhr = new XMLHttpRequest();
description('XMLHttpRequest doesn\'t crash even when open() is invoked ' +
'synchronously to handling of a response to a cross-origin ' +
'request.');
var xhr = new XMLHttpRequest;
var count = 10; // The crash doesn't always happen. Repeat to capture it.
function openXHR() { function openXHR() {
xhr.open('GET', '/'); xhr.open('GET', '/');
...@@ -18,18 +13,25 @@ function openXHR() { ...@@ -18,18 +13,25 @@ function openXHR() {
} }
function openAndSendCrossOriginSimpleXHR() { function openAndSendCrossOriginSimpleXHR() {
xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/test.html"); xhr.open('GET', 'http://localhost:8000/xmlhttprequest/resources/test.html');
xhr.send(); xhr.send();
} }
xhr.onerror = function() { async_test((test) => {
--count; // The crash doesn't always happen. Repeat to capture it.
if (count <= 0) { let count = 10;
setTimeout(finishJSTest, 0);
} else { xhr.onerror = test.step_func(() => {
--count;
if (count <= 0) {
test.done();
return;
}
openAndSendCrossOriginSimpleXHR(); openAndSendCrossOriginSimpleXHR();
} });
} openAndSendCrossOriginSimpleXHR();
}, 'XMLHttpRequest doesn\'t crash even when open() is invoked ' +
'synchronously to handling of a response to a cross-origin request.');
openAndSendCrossOriginSimpleXHR(); openAndSendCrossOriginSimpleXHR();
</script> </script>
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
XMLHttpRequest doesn't crash even when open() is invoked synchronously to handling of an invalid preflight response.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!doctype html> <!doctype html>
<script src="/js-test-resources/js-test.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body onload="openXHR();"> <body onload="openXHR();">
<!-- This embed is necessary to cause the synchronous invocation of onload --> <!-- This embed is necessary to cause the synchronous invocation of onload -->
<embed type="text/html; charset=utf-8"> <embed type="text/html; charset=utf-8">
<script> <script>
window.jsTestIsAsync = true; const xhr = new XMLHttpRequest();
description('XMLHttpRequest doesn\'t crash even when open() is invoked ' +
'synchronously to handling of an invalid preflight response.');
var xhr = new XMLHttpRequest;
var count = 10; // The crash doesn't always happen. Repeat to capture it.
function openXHR() { function openXHR() {
xhr.open('GET', '/'); xhr.open('GET', '/');
...@@ -17,18 +13,25 @@ function openXHR() { ...@@ -17,18 +13,25 @@ function openXHR() {
} }
function openAndSendCrossOriginNonSimpleXHR() { function openAndSendCrossOriginNonSimpleXHR() {
xhr.open("PUT", "http://localhost:8000/xmlhttprequest/"); xhr.open('PUT', 'http://localhost:8000/');
xhr.send(); xhr.send();
} }
xhr.onerror = function() { async_test((test) => {
--count; // The crash doesn't always happen. Repeat to capture it.
if (count <= 0) { let count = 10;
setTimeout(finishJSTest, 0);
} else { xhr.onerror = test.step_func(() => {
--count;
if (count <= 0) {
test.done();
return;
}
openAndSendCrossOriginNonSimpleXHR(); openAndSendCrossOriginNonSimpleXHR();
} });
} openAndSendCrossOriginNonSimpleXHR();
}, 'XMLHttpRequest doesn\'t crash even when open() is invoked ' +
'synchronously to handling of an invalid preflight response.');
openAndSendCrossOriginNonSimpleXHR(); openAndSendCrossOriginNonSimpleXHR();
</script> </script>
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
CONSOLE ERROR: Access to XMLHttpRequest at 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
XMLHttpRequest doesn't crash even when open() is invoked synchronously to handling of a redirect response to a cross-origin request.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS successfullyParsed is true
TEST COMPLETE
<!doctype html> <!doctype html>
<script src="/js-test-resources/js-test.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body onload="openXHR();"> <body onload="openXHR();">
<!-- This embed is necessary to cause the synchronous invocation of onload --> <!-- This embed is necessary to cause the synchronous invocation of onload -->
<embed type="text/html; charset=utf-8"> <embed type="text/html; charset=utf-8">
<script> <script>
window.jsTestIsAsync = true; const xhr = new XMLHttpRequest();
description('XMLHttpRequest doesn\'t crash even when open() is invoked ' +
'synchronously to handling of a redirect response to a ' +
'cross-origin request.');
var xhr = new XMLHttpRequest;
var count = 10; // The crash doesn't always happen. Repeat to capture it.
function openXHR() { function openXHR() {
xhr.open('GET', '/'); xhr.open('GET', '/');
...@@ -18,18 +13,23 @@ function openXHR() { ...@@ -18,18 +13,23 @@ function openXHR() {
} }
function openAndSendCrossOriginSimpleXHRExpectingRedirect() { function openAndSendCrossOriginSimpleXHRExpectingRedirect() {
xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/"); xhr.open('GET', 'http://localhost:8000/xmlhttprequest/resources/redirect.php?url=/');
xhr.send(); xhr.send();
} }
xhr.onerror = function() { async_test((test) => {
--count; // The crash doesn't always happen. Repeat to capture it.
if (count <= 0) { let count = 10;
setTimeout(finishJSTest, 0);
} else {
openAndSendCrossOriginSimpleXHRExpectingRedirect();
}
}
openAndSendCrossOriginSimpleXHRExpectingRedirect(); xhr.onerror = test.step_func(() => {
--count;
if (count <= 0) {
test.done();
return;
}
openAndSendCrossOriginSimpleXHRExpectingRedirect();
});
openAndSendCrossOriginSimpleXHRExpectingRedirect();
}, 'XMLHttpRequest doesn\'t crash even when open() is invoked synchronously' +
'to handling of a redirect response to a cross-origin request.');
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment