Take into account removed caches in Caches::remove assertion
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 18:31:22 +0000 (18:31 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 18:31:22 +0000 (18:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176164

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-31
Reviewed by Alex Christensen.

Source/WebKit:

* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::Caches::remove):

LayoutTests:

* http/wpt/cache-storage/cache-remove-twice-expected.txt: Added.
* http/wpt/cache-storage/cache-remove-twice.html: Added.
* http/wpt/cache-storage/resources/cache-remove-twice-iframe.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221428 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/wpt/cache-storage/cache-remove-twice-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/cache-storage/cache-remove-twice.html [new file with mode: 0644]
LayoutTests/http/wpt/cache-storage/resources/cache-remove-twice-iframe.html [new file with mode: 0644]
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp

index 295a676..32eef58 100644 (file)
@@ -1,3 +1,14 @@
+2017-08-31  Youenn Fablet  <youenn@apple.com>
+
+        Take into account removed caches in Caches::remove assertion
+        https://bugs.webkit.org/show_bug.cgi?id=176164
+
+        Reviewed by Alex Christensen.
+
+        * http/wpt/cache-storage/cache-remove-twice-expected.txt: Added.
+        * http/wpt/cache-storage/cache-remove-twice.html: Added.
+        * http/wpt/cache-storage/resources/cache-remove-twice-iframe.html: Added.
+
 2017-08-31  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, remove crash expectation for hopefully-fixed test
diff --git a/LayoutTests/http/wpt/cache-storage/cache-remove-twice-expected.txt b/LayoutTests/http/wpt/cache-storage/cache-remove-twice-expected.txt
new file mode 100644 (file)
index 0000000..a45356b
--- /dev/null
@@ -0,0 +1,6 @@
+
+
+PASS Cleaning existing caches 
+PASS Removing the same cache from two different documents 
+PASS Cleaning added caches 
+
diff --git a/LayoutTests/http/wpt/cache-storage/cache-remove-twice.html b/LayoutTests/http/wpt/cache-storage/cache-remove-twice.html
new file mode 100644 (file)
index 0000000..beceaaf
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Cache Storage: testing persistency</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+    <div id="check">
+    </div>
+    <script>
+    promise_test(test => {
+        return self.caches.keys().then(keys => {
+            var pending = [];
+            for (key of keys)
+                pending.push(self.caches.delete(keys[0]));
+            return Promise.all(pending);
+        });
+    }, "Cleaning existing caches");
+
+    promise_test(test => {
+        check.innerHTML = "<iframe id='cacheFrame' src='resources/cache-remove-twice-iframe.html'></iframe>";
+        
+        var cacheName = "test-remove-twice";
+        return new Promise((resolve, reject) => {
+            window.addEventListener("message", test.step_func((event) => {
+                return Promise.all([self.caches.open(cacheName), cacheFrame.window.caches.open(cacheName) ]).then(() => {
+                    return Promise.all([self.caches.delete(cacheName), cacheFrame.window.caches.delete(cacheName)]);
+                }).then(resolve, reject);
+           }));
+       });
+    }, "Removing the same cache from two different documents");
+
+   promise_test(test => {
+        return self.caches.keys().then(keys => {
+            var pending = [];
+            for (key of keys)
+                pending.push(self.caches.delete(keys[0]));
+            return Promise.all(pending);
+        });
+    }, "Cleaning added caches");
+    </script>
+</body>
+</html>
+
diff --git a/LayoutTests/http/wpt/cache-storage/resources/cache-remove-twice-iframe.html b/LayoutTests/http/wpt/cache-storage/resources/cache-remove-twice-iframe.html
new file mode 100644 (file)
index 0000000..ef18009
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <script>
+window.parent.postMessage("ready", "*");
+    </script>
+</body>
+</html>
+
index e7d9f42..bb4bbc2 100644 (file)
@@ -1,5 +1,15 @@
 2017-08-31  Youenn Fablet  <youenn@apple.com>
 
+        Take into account removed caches in Caches::remove assertion
+        https://bugs.webkit.org/show_bug.cgi?id=176164
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+        (WebKit::CacheStorage::Caches::remove):
+
+2017-08-31  Youenn Fablet  <youenn@apple.com>
+
         Do not create a salt if the CacheStorage engine should not persist
         https://bugs.webkit.org/show_bug.cgi?id=176138
 
index 8b82438..f6525cf 100644 (file)
@@ -136,7 +136,11 @@ void Caches::remove(uint64_t identifier, CompletionCallback&& callback)
 
     auto position = m_caches.findMatching([&](const auto& item) { return item.identifier == identifier; });
 
-    ASSERT(position != notFound);
+    if (position == notFound) {
+        ASSERT(m_removedCaches.findMatching([&](const auto& item) { return item.identifier == identifier; }) != notFound);
+        callback(std::nullopt);
+        return;
+    }
 
     auto cache = WTFMove(m_caches[position]);
     m_caches.remove(position);