Commit 4f2cec77 authored by yhirano's avatar yhirano Committed by Commit bot

Sync XHR on Worker should not crash when response arrives immediately

A WorkerThreadableLoader::MainThreadLoaderHolder instance is created on the
main thread and its reference is sent to the worker thread. The current
implementation sends the reference after the loading starts (on the main
thread), but it's problematic because the loading may exit immediately and
hence it breaks WorkerThreadableLoader::WaitableEventWithTasks's assumption.

BUG=637980

Review-Url: https://codereview.chromium.org/2250203003
Cr-Commit-Position: refs/heads/master@{#414302}
parent 1014f297
CONSOLE WARNING: line 14: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 1: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
Test cross-origin XHRs to CORS-unsupported protocol schemes in the URL.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS errorEvent.name is "NetworkError"
PASS errorEvent.type is "error"
PASS xhr.send() did not throw exception.
PASS successfullyParsed is true
......
......@@ -10,7 +10,22 @@ var errorEvent;
function issueRequest(url, contentType)
{
xhr = new XMLHttpRequest();
xhr.open('POST', url);
// async = false
xhr.open('POST', url, false);
xhr.onerror = () => testFailed("onerror callback should not be called.");
// Assumed a Content-Type that turns it into a non-simple CORS request.
if (contentType)
xhr.setRequestHeader('Content-Type', contentType);
try {
xhr.send();
} catch(e) {
errorEvent = e;
shouldBeEqualToString("errorEvent.name", "NetworkError");
}
xhr = new XMLHttpRequest();
// async = true
xhr.open('POST', url, true);
xhr.onerror = function (a) {
errorEvent = a;
shouldBeEqualToString("errorEvent.type", "error");
......
CONSOLE ERROR: line 20: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load http://localhost:1291a/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load ftp://127.0.0.1/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load localhost:8080/. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: line 20: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
CONSOLE ERROR: XMLHttpRequest cannot load tel:1234. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.
[Worker] Test cross-origin XHRs to CORS-unsupported protocol schemes in the URL.
......@@ -12,20 +20,28 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Starting worker: ../resources/cross-origin-unsupported-url.js
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS [Worker] errorEvent.name is "NetworkError"
PASS [Worker] xhr.send() did not throw exception.
PASS [Worker] errorEvent.type is "error"
PASS successfullyParsed is true
......
......@@ -852,6 +852,26 @@ TEST_P(ThreadableLoaderTest, ClearInDidFailRedirectCheck)
serveRequests();
}
// This test case checks blink doesn't crash even when the response arrives
// synchronously.
TEST_P(ThreadableLoaderTest, GetResponseSynchronously)
{
InSequence s;
EXPECT_CALL(checkpoint(), Call(1));
createLoader(UseAccessControl);
callCheckpoint(1);
EXPECT_CALL(*client(), didFailAccessControlCheck(_));
EXPECT_CALL(checkpoint(), Call(2));
// Currently didFailAccessControlCheck is dispatched synchronously. This
// test is not saying that didFailAccessControlCheck should be dispatched
// synchronously, but is saying that even when a response is served
// synchronously it should not lead to a crash.
startLoader(KURL(KURL(), "about:blank"));
callCheckpoint(2);
}
} // namespace
} // namespace blink
......@@ -446,8 +446,8 @@ void WorkerThreadableLoader::MainThreadLoaderHolder::createAndStart(
return;
}
mainThreadLoaderHolder->m_workerLoader = workerLoader;
mainThreadLoaderHolder->start(*toDocument(executionContext), std::move(request), options, resourceLoaderOptions);
forwarder->forwardTask(BLINK_FROM_HERE, createCrossThreadTask(&WorkerThreadableLoader::didStart, wrapCrossThreadPersistent(workerLoader), wrapCrossThreadPersistent(mainThreadLoaderHolder)));
mainThreadLoaderHolder->start(*toDocument(executionContext), std::move(request), options, resourceLoaderOptions);
}
WorkerThreadableLoader::MainThreadLoaderHolder::~MainThreadLoaderHolder()
......
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