https://bugs.webkit.org/show_bug.cgi?id=175825
Patch by Youenn Fablet <youenn@apple.com> on 2017-08-22
Reviewed by Geoffrey Garen.
LayoutTests/imported/w3c:
* web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
* web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
Source/WebCore:
Tests: http/wpt/cache-storage/cache-put-keys.https.any.html
http/wpt/cache-storage/cache-put-keys.https.any.worker.html
Adding support for the new response update counter.
Overwriting local cached response with new retrieved response when the counter is different.
Adding support for passing this value from/to workers.
* Modules/cache/Cache.cpp:
(WebCore::Cache::queryCacheWithTargetStorage):
(WebCore::toConnectionRecord):
(WebCore::Cache::updateRecords):
* Modules/cache/CacheStorageConnection.cpp:
(WebCore::CacheStorageConnection::Record::copy const):
* Modules/cache/CacheStorageConnection.h:
* Modules/cache/CacheStorageRecord.h:
* Modules/cache/WorkerCacheStorageConnection.cpp:
(WebCore::toCrossThreadRecordData):
(WebCore::fromCrossThreadRecordData):
Source/WebKit:
Add support for encoding/decoding the update counter.
Incrementing it when overwriting an existing response.
Storing the new body in addition to the new response.
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorageEngine::putRecords):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<CacheStorageConnection::Record>::encode):
(IPC::ArgumentCoder<CacheStorageConnection::Record>::decode):
LayoutTests:
Adding update counter for response
Skipping new test on WK1.
* platform/ios-wk1/TestExpectations:
* platform/mac-wk1/TestExpectations:
* http/wpt/cache-storage/cache-put-keys.https.any-expected.txt: Added.
* http/wpt/cache-storage/cache-put-keys.https.any.html: Added.
* http/wpt/cache-storage/cache-put-keys.https.any.js: Added.
(cache_test):
* http/wpt/cache-storage/cache-put-keys.https.any.worker-expected.txt: Added.
* http/wpt/cache-storage/cache-put-keys.https.any.worker.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221024
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2017-08-22 Youenn Fablet <youenn@apple.com>
+
+ [Cache API] Add support for overwriting responses with put on an existing record
+ https://bugs.webkit.org/show_bug.cgi?id=175825
+
+ Reviewed by Geoffrey Garen.
+
+ Adding update counter for response
+ Skipping new test on WK1.
+
+ * platform/ios-wk1/TestExpectations:
+ * platform/mac-wk1/TestExpectations:
+ * http/wpt/cache-storage/cache-put-keys.https.any-expected.txt: Added.
+ * http/wpt/cache-storage/cache-put-keys.https.any.html: Added.
+ * http/wpt/cache-storage/cache-put-keys.https.any.js: Added.
+ (cache_test):
+ * http/wpt/cache-storage/cache-put-keys.https.any.worker-expected.txt: Added.
+ * http/wpt/cache-storage/cache-put-keys.https.any.worker.html: Added.
+
2017-08-22 Matt Lewis <jlewis3@apple.com>
Marked imported/w3c/web-platform-tests/fetch/http-cache/invalidate.html as flaky on macOS WK2.
--- /dev/null
+
+PASS Cache.put called twice with matching Requests - keys should remain the same
+
--- /dev/null
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
--- /dev/null
+// META: script=/service-workers/cache-storage/resources/test-helpers.js
+
+var test_url = 'https://example.com/foo';
+var test_body = 'Hello world!';
+
+cache_test(function(cache) {
+ var cache_keys;
+ var alternate_response_body = 'New body';
+ var alternate_response = new Response(alternate_response_body, { statusText: 'New status' });
+ return cache.put(new Request(test_url), new Response('Old body', { statusText: 'Old status' })).then(function() {
+ return cache.keys();
+ }).then(function(keys) {
+ cache_keys = keys;
+ }).then(function() {
+ return cache.put(new Request(test_url), alternate_response);
+ }).then(function() {
+ return cache.keys();
+ }).then(function(keys) {
+ assert_request_array_equals(keys, cache_keys);
+ }).then(function() {
+ return cache.match(test_url);
+ }).then(function(result) {
+ assert_response_equals(result, alternate_response, 'Cache.put should replace existing ' + 'response with new response.');
+ return result.text();
+ }).then(function(body) {
+ assert_equals(body, alternate_response_body, 'Cache put should store new response body.');
+ });
+}, 'Cache.put called twice with matching Requests - keys should remain the same');
+
+done();
--- /dev/null
+
+PASS Cache.put called twice with matching Requests - keys should remain the same
+
--- /dev/null
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file
+2017-08-22 Youenn Fablet <youenn@apple.com>
+
+ [Cache API] Add support for overwriting responses with put on an existing record
+ https://bugs.webkit.org/show_bug.cgi?id=175825
+
+ Reviewed by Geoffrey Garen.
+
+ * web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt:
+ * web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt:
+
2017-08-22 Andy Estes <aestes@apple.com>
[Payment Request] Implement error checking for show(), abort(), and canMakePayment()
PASS Cache.put with synthetic 206 response
PASS Cache.put with HTTP 206 response
PASS Cache.put with HTTP 500 response
-FAIL Cache.put called twice with matching Requests and different Responses assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
-FAIL Cache.put called twice with request URLs that differ only by a fragment assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
+PASS Cache.put called twice with matching Requests and different Responses
+PASS Cache.put called twice with request URLs that differ only by a fragment
PASS Cache.put with a string request
PASS Cache.put with an invalid response
PASS Cache.put with a non-HTTP/HTTPS request
PASS Cache.put with synthetic 206 response
PASS Cache.put with HTTP 206 response
PASS Cache.put with HTTP 500 response
-FAIL Cache.put called twice with matching Requests and different Responses assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
-FAIL Cache.put called twice with request URLs that differ only by a fragment assert_equals: Cache put should store new response body. expected "New body" but got "Old body"
+PASS Cache.put called twice with matching Requests and different Responses
+PASS Cache.put called twice with request URLs that differ only by a fragment
PASS Cache.put with a string request
PASS Cache.put with an invalid response
PASS Cache.put with a non-HTTP/HTTPS request
# No service worker implementation for WK1
imported/w3c/web-platform-tests/service-workers [ Skip ]
+http/wpt/cache-storage [ Skip ]
# Skip WebRTC for now in WK1
imported/w3c/web-platform-tests/webrtc [ Skip ]
# No service worker implementation for WK1
imported/w3c/web-platform-tests/service-workers [ Skip ]
+http/wpt/cache-storage [ Skip ]
# Skip WebRTC for now in WK1
imported/w3c/web-platform-tests/webrtc [ Skip ]
+2017-08-22 Youenn Fablet <youenn@apple.com>
+
+ [Cache API] Add support for overwriting responses with put on an existing record
+ https://bugs.webkit.org/show_bug.cgi?id=175825
+
+ Reviewed by Geoffrey Garen.
+
+ Tests: http/wpt/cache-storage/cache-put-keys.https.any.html
+ http/wpt/cache-storage/cache-put-keys.https.any.worker.html
+
+ Adding support for the new response update counter.
+ Overwriting local cached response with new retrieved response when the counter is different.
+ Adding support for passing this value from/to workers.
+
+ * Modules/cache/Cache.cpp:
+ (WebCore::Cache::queryCacheWithTargetStorage):
+ (WebCore::toConnectionRecord):
+ (WebCore::Cache::updateRecords):
+ * Modules/cache/CacheStorageConnection.cpp:
+ (WebCore::CacheStorageConnection::Record::copy const):
+ * Modules/cache/CacheStorageConnection.h:
+ * Modules/cache/CacheStorageRecord.h:
+ * Modules/cache/WorkerCacheStorageConnection.cpp:
+ (WebCore::toCrossThreadRecordData):
+ (WebCore::fromCrossThreadRecordData):
+
2017-08-22 Alex Christensen <achristensen@webkit.org>
Remove ChromeClient::hasOpenedPopup
Vector<CacheStorageRecord> records;
for (auto& record : targetStorage) {
if (queryCacheMatch(request, record.request.get(), record.response->resourceResponse(), options))
- records.append({ record.identifier, record.request.copyRef(), record.response.copyRef() });
+ records.append({ record.identifier, record.updateResponseCounter, record.request.copyRef(), record.response.copyRef() });
}
return records;
}
ASSERT(!cachedRequest.isNull());
ASSERT(!cachedResponse.isNull());
- return { 0,
+ return { 0, 0,
request.headers().guard(), WTFMove(cachedRequest), request.fetchOptions(), request.internalRequestReferrer(),
response.headers().guard(), WTFMove(cachedResponse), WTFMove(responseBody)
};
for (auto& record : records) {
size_t index = m_records.findMatching([&](const auto& item) { return item.identifier == record.identifier; });
- if (index != notFound)
- newRecords.append(WTFMove(m_records[index]));
- else {
+ if (index != notFound) {
+ auto& current = m_records[index];
+ if (current.updateResponseCounter != record.updateResponseCounter) {
+ auto responseHeaders = FetchHeaders::create(record.responseHeadersGuard, HTTPHeaderMap { record.response.httpHeaderFields() });
+ auto response = FetchResponse::create(*scriptExecutionContext(), std::nullopt, WTFMove(responseHeaders), WTFMove(record.response));
+ response->setBodyData(WTFMove(record.responseBody));
+
+ current.response = WTFMove(response);
+ current.updateResponseCounter = record.updateResponseCounter;
+ }
+ newRecords.append(WTFMove(current));
+ } else {
auto requestHeaders = FetchHeaders::create(record.requestHeadersGuard, HTTPHeaderMap { record.request.httpHeaderFields() });
FetchRequest::InternalRequest internalRequest = { WTFMove(record.request), WTFMove(record.options), WTFMove(record.referrer) };
auto request = FetchRequest::create(*scriptExecutionContext(), std::nullopt, WTFMove(requestHeaders), WTFMove(internalRequest));
auto response = FetchResponse::create(*scriptExecutionContext(), std::nullopt, WTFMove(responseHeaders), WTFMove(record.response));
response->setBodyData(WTFMove(record.responseBody));
- newRecords.append(CacheStorageRecord { record.identifier, WTFMove(request), WTFMove(response) });
+ newRecords.append(CacheStorageRecord { record.identifier, record.updateResponseCounter, WTFMove(request), WTFMove(response) });
}
}
m_records = WTFMove(newRecords);
CacheStorageConnection::Record CacheStorageConnection::Record::copy() const
{
- return Record { identifier, requestHeadersGuard, request, options, referrer, responseHeadersGuard, response, copyResponseBody(responseBody) };
+ return Record { identifier, updateResponseCounter, requestHeadersGuard, request, options, referrer, responseHeadersGuard, response, copyResponseBody(responseBody) };
}
} // namespace WebCore
WEBCORE_EXPORT Record copy() const;
uint64_t identifier;
+ uint64_t updateResponseCounter;
FetchHeaders::Guard requestHeadersGuard;
ResourceRequest request;
struct CacheStorageRecord {
uint64_t identifier;
+ uint64_t updateResponseCounter;
Ref<FetchRequest> request;
Ref<FetchResponse> response;
struct CrossThreadRecordData {
uint64_t identifier;
+ uint64_t updateResponseCounter;
FetchHeaders::Guard requestHeadersGuard;
ResourceRequest request;
{
return CrossThreadRecordData {
record.identifier,
+ record.updateResponseCounter,
record.requestHeadersGuard,
record.request.isolatedCopy(),
record.options.isolatedCopy(),
{
return CacheStorageConnection::Record {
data.identifier,
+ data.updateResponseCounter,
data.requestHeadersGuard,
WTFMove(data.request),
WTFMove(data.options),
+2017-08-22 Youenn Fablet <youenn@apple.com>
+
+ [Cache API] Add support for overwriting responses with put on an existing record
+ https://bugs.webkit.org/show_bug.cgi?id=175825
+
+ Reviewed by Geoffrey Garen.
+
+ Add support for encoding/decoding the update counter.
+ Incrementing it when overwriting an existing response.
+ Storing the new body in addition to the new response.
+
+ * NetworkProcess/cache/CacheStorageEngine.cpp:
+ (WebKit::CacheStorageEngine::putRecords):
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::ArgumentCoder<CacheStorageConnection::Record>::encode):
+ (IPC::ArgumentCoder<CacheStorageConnection::Record>::decode):
+
2017-08-22 Alex Christensen <achristensen@webkit.org>
Remove ChromeClient::hasOpenedPopup
recordIdentifiers.uncheckedAppend(identifier);
existingRecord.responseHeadersGuard = record.responseHeadersGuard;
existingRecord.response = WTFMove(record.response);
+ existingRecord.responseBody = WTFMove(record.responseBody);
+ ++existingRecord.updateResponseCounter;
}
}
}
encoder << record.responseHeadersGuard;
encoder << record.response;
+ encoder << record.updateResponseCounter;
WTF::switchOn(record.responseBody, [&](const Ref<SharedBuffer>& buffer) {
encoder << true;
if (!decoder.decode(response))
return false;
+ uint64_t updateResponseCounter;
+ if (!decoder.decode(updateResponseCounter))
+ return false;
+
WebCore::CacheStorageConnection::ResponseBody responseBody;
bool hasSharedBufferBody;
if (!decoder.decode(hasSharedBufferBody))
record.responseHeadersGuard = responseHeadersGuard;
record.response = WTFMove(response);
+ record.updateResponseCounter = updateResponseCounter;
record.responseBody = WTFMove(responseBody);
return true;