Don't try to restore deleted MemoryIndexes if their owning object store is not restored.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Mar 2016 22:48:41 +0000 (22:48 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Mar 2016 22:48:41 +0000 (22:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155068

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/deleteindex-4-private.html

* Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
(WebCore::IDBServer::MemoryBackingStoreTransaction::indexDeleted):

LayoutTests:

* storage/indexeddb/modern/deleteindex-4-private-expected.txt: Added.
* storage/indexeddb/modern/deleteindex-4-private.html: Added.
* storage/indexeddb/modern/resources/deleteindex-4.js: Added.

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

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/modern/deleteindex-4-private-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/deleteindex-4-private.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/resources/deleteindex-4.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp

index f4e5433..4ac669e 100644 (file)
@@ -1,3 +1,14 @@
+2016-03-17  Brady Eidson  <beidson@apple.com>
+
+        Don't try to restore deleted MemoryIndexes if their owning object store is not restored.
+        https://bugs.webkit.org/show_bug.cgi?id=155068
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/deleteindex-4-private-expected.txt: Added.
+        * storage/indexeddb/modern/deleteindex-4-private.html: Added.
+        * storage/indexeddb/modern/resources/deleteindex-4.js: Added.
+
 2016-03-17  Doug Russell  <d_russell@apple.com>
 
         AX: attributes to retrieve focusable and editable ancestors
diff --git a/LayoutTests/storage/indexeddb/modern/deleteindex-4-private-expected.txt b/LayoutTests/storage/indexeddb/modern/deleteindex-4-private-expected.txt
new file mode 100644 (file)
index 0000000..5e4b0e9
--- /dev/null
@@ -0,0 +1,16 @@
+This tests deleting an object store with an index, when aborting the transaction would *not* restore that object store, and makes sure the transaction successfully aborts
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
+
+indexedDB.deleteDatabase(dbname)
+indexedDB.open(dbname)
+first put success
+second put success
+Aborted!
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/modern/deleteindex-4-private.html b/LayoutTests/storage/indexeddb/modern/deleteindex-4-private.html
new file mode 100644 (file)
index 0000000..cb4e5ef
--- /dev/null
@@ -0,0 +1,12 @@
+<html>
+<head>
+<script>
+enablePrivateBrowsing = true;
+</script>
+<script src="../../../resources/js-test.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<script src="resources/deleteindex-4.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/storage/indexeddb/modern/resources/deleteindex-4.js b/LayoutTests/storage/indexeddb/modern/resources/deleteindex-4.js
new file mode 100644 (file)
index 0000000..bd046b5
--- /dev/null
@@ -0,0 +1,35 @@
+description("This tests deleting an object store with an index, when aborting the transaction would *not* restore that object store, and makes sure the transaction successfully aborts");
+
+indexedDBTest(prepareDatabase);
+
+function prepareDatabase(event)
+{
+    tx = event.target.transaction;
+    tx.onabort = function() {
+        debug("Aborted!");
+        finishJSTest();
+    }
+    tx.onerror = function() {
+        debug("Unexpected error");
+        finishJSTest();
+    }
+    tx.oncomplete = function() {
+        debug("Unexpected completion");
+        finishJSTest();
+    }
+    
+    db = event.target.result;
+    db.createObjectStore("name");
+    db.deleteObjectStore("name");
+    
+    os = db.createObjectStore("name");
+    os.createIndex("index", "foo");
+    os.put("bar", "foo").onsuccess = function() {
+        debug("first put success");
+        db.deleteObjectStore("name");
+        db.createObjectStore("name").put("bar", "foo").onsuccess = function() {
+            debug("second put success");
+            tx.abort();
+        }
+    }
+}
index dcf3882..7f5af07 100644 (file)
@@ -1,3 +1,15 @@
+2016-03-17  Brady Eidson  <beidson@apple.com>
+
+        Don't try to restore deleted MemoryIndexes if their owning object store is not restored.
+        https://bugs.webkit.org/show_bug.cgi?id=155068
+
+        Reviewed by Alex Christensen.
+
+        Test: storage/indexeddb/modern/deleteindex-4-private.html
+
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::indexDeleted):
+
 2016-03-17  Doug Russell  <d_russell@apple.com>
 
         AX: attributes to retrieve focusable and editable ancestors
index 008e596..e7ab040 100644 (file)
@@ -94,6 +94,14 @@ void MemoryBackingStoreTransaction::indexDeleted(Ref<MemoryIndex>&& index)
 {
     m_indexes.remove(&index.get());
 
+    // If this MemoryIndex belongs to an object store that will not get restored if this transaction aborts,
+    // then we can forget about it altogether.
+    auto& objectStore = index->objectStore();
+    if (auto deletedObjectStore = m_deletedObjectStores.get(objectStore.info().name())) {
+        if (deletedObjectStore != &objectStore)
+            return;
+    }
+
     auto addResult = m_deletedIndexes.add(index->info().name(), nullptr);
     if (addResult.isNewEntry)
         addResult.iterator->value = WTFMove(index);