Commit 733a4764 authored by hiroshige's avatar hiroshige Committed by Commit bot

Do not revalidate when ResourceLoaderOptions.synchronousPolicy is different

This CL adds a check of synchronousPolicy to
ResourceLoaderOptions::canReuseRequest() to avoid Resources to be reused
between sync and async requests.
This CL also removes a condition from
ResourceFetcher::determineRevalidationPolicy() that is covered by the newly
added check.

CachingCorrectnessTest is updated so that it doesn't use synchronous
RawResource requests.

BUG=652172

Review-Url: https://codereview.chromium.org/2391523002
Cr-Commit-Position: refs/heads/master@{#422725}
parent b72069a0
......@@ -3,5 +3,5 @@
// revalidating requests to test failed revalidation.
header('ETag: foo');
header('Cache-control: max-age=0');
echo rand();
?>
foo
CONSOLE WARNING: line 12: 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/.
Async XHR should not turn sync due to revalidation.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS xhr2SendIsReturned is true
PASS xhr1.responseText is not xhr2.responseText
PASS successfullyParsed is true
TEST COMPLETE
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script>
description('Async XHR should not turn sync due to revalidation.');
window.jsTestIsAsync = true;
const url = '/cache/resources/etag-200.php?' +
Math.floor(100000000 * Math.random());
xhr1 = new XMLHttpRequest();
xhr2SendIsReturned = false;
xhr1.open('GET', url, false);
xhr1.onload = setTimeout(function() {
xhr2 = new XMLHttpRequest();
xhr2.open('GET', url, true);
xhr2.onload = function() {
shouldBeTrue("xhr2SendIsReturned");
shouldNotBe("xhr1.responseText", "xhr2.responseText");
finishJSTest();
};
xhr2.send();
xhr2SendIsReturned = true;
}, 0);
xhr1.send();
</script>
</body>
</html>
CONSOLE WARNING: line 15: 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/.
Sync XHR should not turn async due to revalidation.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS xhr2SendIsReturned is false
PASS xhr1.responseText is not xhr2.responseText
PASS successfullyParsed is true
TEST COMPLETE
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script>
description('Sync XHR should not turn async due to revalidation.');
window.jsTestIsAsync = true;
const url = '/cache/resources/etag-200.php?' +
Math.floor(100000000 * Math.random());
xhr1 = new XMLHttpRequest();
xhr2SendIsReturned = false;
xhr1.open('GET', url, true);
xhr1.onload = setTimeout(function() {
xhr2 = new XMLHttpRequest();
xhr2.open('GET', url, false);
xhr2.onload = function() {
shouldBeFalse("xhr2SendIsReturned");
shouldNotBe("xhr1.responseText", "xhr2.responseText");
finishJSTest();
};
xhr2.send();
xhr2SendIsReturned = true;
}, 0);
xhr1.send();
</script>
</body>
</html>
......@@ -118,10 +118,10 @@ class CachingCorrectnessTest : public ::testing::Test {
}
Resource* fetch() {
FetchRequest fetchRequest(
ResourceRequest(KURL(ParsedURLString, kResourceURL)),
FetchInitiatorInfo());
return RawResource::fetchSynchronously(fetchRequest, fetcher());
ResourceRequest resourceRequest(KURL(ParsedURLString, kResourceURL));
resourceRequest.setRequestContext(WebURLRequest::RequestContextInternal);
FetchRequest fetchRequest(resourceRequest, FetchInitiatorInfo());
return RawResource::fetch(fetchRequest, fetcher());
}
Resource* fetchImage() {
......
......@@ -841,11 +841,6 @@ ResourceFetcher::determineRevalidationPolicy(Resource::Type type,
existingResource->response().httpStatusCode() == 304)
return Reload;
// Don't try to reuse an in-progress async request for a new sync request.
if (fetchRequest.options().synchronousPolicy == RequestSynchronously &&
existingResource->isLoading())
return Reload;
// Don't reload resources while pasting.
if (m_allowStaleResources)
return Use;
......
......@@ -104,7 +104,8 @@ struct ResourceLoaderOptions {
// FIXME: check contentSecurityPolicyOption.
// initiatorInfo is purely informational and should be benign for re-use.
// requestInitiatorContext is benign (indicates document vs. worker)
// synchronousPolicy (safe to re-use an async XHR response for sync, etc.)
if (synchronousPolicy != other.synchronousPolicy)
return false;
return corsEnabled == other.corsEnabled;
// securityOrigin has more complicated checks which callers are responsible
// for.
......
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