Title: [221024] trunk
Revision
221024
Author
[email protected]
Date
2017-08-22 11:02:43 -0700 (Tue, 22 Aug 2017)

Log Message

[Cache API] Add support for overwriting responses with put on an existing record
https://bugs.webkit.org/show_bug.cgi?id=175825

Patch by Youenn Fablet <[email protected]> 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221023 => 221024)


--- trunk/LayoutTests/ChangeLog	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/LayoutTests/ChangeLog	2017-08-22 18:02:43 UTC (rev 221024)
@@ -1,3 +1,22 @@
+2017-08-22  Youenn Fablet  <[email protected]>
+
+        [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  <[email protected]>
 
         Marked imported/w3c/web-platform-tests/fetch/http-cache/invalidate.html as flaky on macOS WK2.

Added: trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any-expected.txt (0 => 221024)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any-expected.txt	2017-08-22 18:02:43 UTC (rev 221024)
@@ -0,0 +1,3 @@
+
+PASS Cache.put called twice with matching Requests - keys should remain the same 
+

Added: trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.html (0 => 221024)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.html	2017-08-22 18:02:43 UTC (rev 221024)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.js (0 => 221024)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.js	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.js	2017-08-22 18:02:43 UTC (rev 221024)
@@ -0,0 +1,30 @@
+// 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();

Added: trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.worker-expected.txt (0 => 221024)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.worker-expected.txt	2017-08-22 18:02:43 UTC (rev 221024)
@@ -0,0 +1,3 @@
+
+PASS Cache.put called twice with matching Requests - keys should remain the same 
+

Added: trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.worker.html (0 => 221024)


--- trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.worker.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/cache-storage/cache-put-keys.https.any.worker.html	2017-08-22 18:02:43 UTC (rev 221024)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (221023 => 221024)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-08-22 18:02:43 UTC (rev 221024)
@@ -1,3 +1,13 @@
+2017-08-22  Youenn Fablet  <[email protected]>
+
+        [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  <[email protected]>
 
         [Payment Request] Implement error checking for show(), abort(), and canMakePayment()

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt (221023 => 221024)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/window/cache-put.https-expected.txt	2017-08-22 18:02:43 UTC (rev 221024)
@@ -8,8 +8,8 @@
 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 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt (221023 => 221024)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/cache-storage/worker/cache-put.https-expected.txt	2017-08-22 18:02:43 UTC (rev 221024)
@@ -8,8 +8,8 @@
 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 

Modified: trunk/LayoutTests/platform/ios-wk1/TestExpectations (221023 => 221024)


--- trunk/LayoutTests/platform/ios-wk1/TestExpectations	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/LayoutTests/platform/ios-wk1/TestExpectations	2017-08-22 18:02:43 UTC (rev 221024)
@@ -9,6 +9,7 @@
 
 # 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 ]

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (221023 => 221024)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2017-08-22 18:02:43 UTC (rev 221024)
@@ -96,6 +96,7 @@
 
 # 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 ]

Modified: trunk/Source/WebCore/ChangeLog (221023 => 221024)


--- trunk/Source/WebCore/ChangeLog	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebCore/ChangeLog	2017-08-22 18:02:43 UTC (rev 221024)
@@ -1,3 +1,29 @@
+2017-08-22  Youenn Fablet  <[email protected]>
+
+        [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  <[email protected]>
 
         Remove ChromeClient::hasOpenedPopup

Modified: trunk/Source/WebCore/Modules/cache/Cache.cpp (221023 => 221024)


--- trunk/Source/WebCore/Modules/cache/Cache.cpp	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebCore/Modules/cache/Cache.cpp	2017-08-22 18:02:43 UTC (rev 221024)
@@ -411,7 +411,7 @@
     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;
 }
@@ -440,7 +440,7 @@
     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)
     };
@@ -472,9 +472,18 @@
 
     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));
@@ -483,7 +492,7 @@
             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);

Modified: trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp (221023 => 221024)


--- trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp	2017-08-22 18:02:43 UTC (rev 221024)
@@ -180,7 +180,7 @@
 
 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

Modified: trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h (221023 => 221024)


--- trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h	2017-08-22 18:02:43 UTC (rev 221024)
@@ -67,6 +67,7 @@
         WEBCORE_EXPORT Record copy() const;
 
         uint64_t identifier;
+        uint64_t updateResponseCounter;
 
         FetchHeaders::Guard requestHeadersGuard;
         ResourceRequest request;

Modified: trunk/Source/WebCore/Modules/cache/CacheStorageRecord.h (221023 => 221024)


--- trunk/Source/WebCore/Modules/cache/CacheStorageRecord.h	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebCore/Modules/cache/CacheStorageRecord.h	2017-08-22 18:02:43 UTC (rev 221024)
@@ -32,6 +32,7 @@
 
 struct CacheStorageRecord {
     uint64_t identifier;
+    uint64_t updateResponseCounter;
 
     Ref<FetchRequest> request;
     Ref<FetchResponse> response;

Modified: trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp (221023 => 221024)


--- trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp	2017-08-22 18:02:43 UTC (rev 221024)
@@ -40,6 +40,7 @@
 
 struct CrossThreadRecordData {
     uint64_t identifier;
+    uint64_t updateResponseCounter;
 
     FetchHeaders::Guard requestHeadersGuard;
     ResourceRequest request;
@@ -56,6 +57,7 @@
 {
     return CrossThreadRecordData {
         record.identifier,
+        record.updateResponseCounter,
         record.requestHeadersGuard,
         record.request.isolatedCopy(),
         record.options.isolatedCopy(),
@@ -70,6 +72,7 @@
 {
     return CacheStorageConnection::Record {
         data.identifier,
+        data.updateResponseCounter,
         data.requestHeadersGuard,
         WTFMove(data.request),
         WTFMove(data.options),

Modified: trunk/Source/WebKit/ChangeLog (221023 => 221024)


--- trunk/Source/WebKit/ChangeLog	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebKit/ChangeLog	2017-08-22 18:02:43 UTC (rev 221024)
@@ -1,3 +1,20 @@
+2017-08-22  Youenn Fablet  <[email protected]>
+
+        [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  <[email protected]>
 
         Remove ChromeClient::hasOpenedPopup

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (221023 => 221024)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-08-22 18:02:43 UTC (rev 221024)
@@ -174,6 +174,8 @@
                     recordIdentifiers.uncheckedAppend(identifier);
                     existingRecord.responseHeadersGuard = record.responseHeadersGuard;
                     existingRecord.response = WTFMove(record.response);
+                    existingRecord.responseBody = WTFMove(record.responseBody);
+                    ++existingRecord.updateResponseCounter;
                 }
             }
         }

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (221023 => 221024)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2017-08-22 17:56:48 UTC (rev 221023)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2017-08-22 18:02:43 UTC (rev 221024)
@@ -311,6 +311,7 @@
 
     encoder << record.responseHeadersGuard;
     encoder << record.response;
+    encoder << record.updateResponseCounter;
 
     WTF::switchOn(record.responseBody, [&](const Ref<SharedBuffer>& buffer) {
         encoder << true;
@@ -355,6 +356,10 @@
     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))
@@ -386,6 +391,7 @@
 
     record.responseHeadersGuard = responseHeadersGuard;
     record.response = WTFMove(response);
+    record.updateResponseCounter = updateResponseCounter;
     record.responseBody = WTFMove(responseBody);
 
     return true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to