Modern IDB: IDBObjectStore.add() support.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 17:17:06 +0000 (17:17 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 17:17:06 +0000 (17:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150711

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/basic-add.html

* Modules/indexeddb/client/IDBObjectStoreImpl.cpp:
(WebCore::IDBClient::IDBObjectStore::add):

* Modules/indexeddb/client/IDBTransactionImpl.cpp:
(WebCore::IDBClient::IDBTransaction::requestGetRecord):

LayoutTests:

* storage/indexeddb/modern/basic-add-expected.txt: Added.
* storage/indexeddb/modern/basic-add.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/modern/basic-add-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/basic-add.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp

index faee4b63a85add261a97b17457f2b708bbe50ce7..bdce478d8449f6ae3e0d6690219763990bf778aa 100644 (file)
@@ -1,3 +1,13 @@
+2015-10-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: IDBObjectStore.add() support.
+        https://bugs.webkit.org/show_bug.cgi?id=150711
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/basic-add-expected.txt: Added.
+        * storage/indexeddb/modern/basic-add.html: Added.
+
 2015-10-29  Ryan Haddad  <ryanhaddad@apple.com>
 
         Removing flaky expectations for storage/indexeddb/modern tests since the failure was fixed in r191758
diff --git a/LayoutTests/storage/indexeddb/modern/basic-add-expected.txt b/LayoutTests/storage/indexeddb/modern/basic-add-expected.txt
new file mode 100644 (file)
index 0000000..32e942e
--- /dev/null
@@ -0,0 +1,10 @@
+ALERT: Upgrade needed: Old version - 0 New version - 1
+ALERT: [object IDBTransaction] - versionchange
+ALERT: [object IDBDatabase]
+ALERT: put 1 succeeded - key was 'foo'
+ALERT: put 2 failed - error
+ALERT: get succeeded - key was 'bar'
+ALERT: version change transaction completed
+ALERT: Done
+This test does basic testing of IDBObjectStore.add(), making sure that an attempt to overwrite an already-existing key fails with the appropriate error.
+
diff --git a/LayoutTests/storage/indexeddb/modern/basic-add.html b/LayoutTests/storage/indexeddb/modern/basic-add.html
new file mode 100644 (file)
index 0000000..f7c9ea4
--- /dev/null
@@ -0,0 +1,77 @@
+This test does basic testing of IDBObjectStore.add(), making sure that an attempt to overwrite an already-existing key fails with the appropriate error.<br>
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+var request = window.indexedDB.open("NewDatabaseAddTestDatabase");
+
+function done()
+{
+    alert("Done");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+request.onupgradeneeded = function(event) {
+    alert("Upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
+    
+    var tx = request.transaction;
+    var db = event.target.result;
+
+    alert(tx + " - " + tx.mode);
+    alert(db);
+
+    var os = db.createObjectStore("TestObjectStore");
+    var putRequest1 = os.add("bar", "foo");
+    var putRequest2 = os.add("baz", "foo");
+
+    putRequest1.onsuccess = function(event) {
+        alert("put 1 succeeded - key was '" + putRequest1.result + "'");
+    }
+
+    putRequest1.onerror = function(event) {
+        alert("put 1 unexpectedly failed - " + event);
+        done();
+    }
+
+    putRequest2.onsuccess = function(event) {
+        alert("put 2 unexpectedly succeeded - key was '" + putRequest2.result + "'");
+        done();
+    }
+
+    putRequest2.onerror = function(event) {
+        alert("put 2 failed - " + event.type);
+
+        var getRequest = os.get("foo");
+        
+        getRequest.onsuccess = function(event) {
+            alert("get succeeded - key was '" + getRequest.result + "'");
+        }
+
+        getRequest.onerror = function(event) {
+            alert("get unexpectedly failed - " + event.type);
+            done();
+        }
+        
+        event.stopPropagation();
+    }
+        
+    tx.onabort = function(event) {
+        alert("version change transaction unexpected abort");
+        done();
+    }
+
+    tx.oncomplete = function(event) {
+        alert("version change transaction completed");
+        done();
+    }
+
+    tx.onerror = function(event) {
+        alert("version change transaction unexpected error - " + event);
+        done();
+    }
+}
+</script>
index a77ac88cc9c8dda85484c63761336707016aa354..aa802699c0672e343486fed51397b52c58299c9f 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: IDBObjectStore.add() support.
+        https://bugs.webkit.org/show_bug.cgi?id=150711
+
+        Reviewed by Alex Christensen.
+
+        Test: storage/indexeddb/modern/basic-add.html
+
+        * Modules/indexeddb/client/IDBObjectStoreImpl.cpp:
+        (WebCore::IDBClient::IDBObjectStore::add):
+
+        * Modules/indexeddb/client/IDBTransactionImpl.cpp:
+        (WebCore::IDBClient::IDBTransaction::requestGetRecord):
+
 2015-10-30  Hunseop Jeong  <hs85.jeong@samsung.com>
 
         Use modern for-loops in WebCore/dom.
index ac58e55c31155d2eef0f1f524cb6890dde53a00b..cce2b1dd79eb4fb069d955ad50d5eeae22b050f2 100644 (file)
@@ -86,9 +86,9 @@ bool IDBObjectStore::autoIncrement() const
     return m_info.autoIncrement();
 }
 
-RefPtr<WebCore::IDBRequest> IDBObjectStore::add(JSC::ExecState&, Deprecated::ScriptValue&, ExceptionCode&)
+RefPtr<WebCore::IDBRequest> IDBObjectStore::add(JSC::ExecState& state, Deprecated::ScriptValue& value, ExceptionCode& ec)
 {
-    RELEASE_ASSERT_NOT_REACHED();
+    return putOrAdd(state, value, nullptr, IndexedDB::ObjectStoreOverwriteMode::NoOverwrite, ec);
 }
 
 RefPtr<WebCore::IDBRequest> IDBObjectStore::put(JSC::ExecState& state, Deprecated::ScriptValue& value, ExceptionCode& ec)
@@ -156,9 +156,10 @@ RefPtr<WebCore::IDBRequest> IDBObjectStore::get(ScriptExecutionContext*, IDBKeyR
     RELEASE_ASSERT_NOT_REACHED();
 }
 
-RefPtr<WebCore::IDBRequest> IDBObjectStore::add(JSC::ExecState&, Deprecated::ScriptValue&, const Deprecated::ScriptValue&, ExceptionCode&)
+RefPtr<WebCore::IDBRequest> IDBObjectStore::add(JSC::ExecState& execState, Deprecated::ScriptValue& value, const Deprecated::ScriptValue& key, ExceptionCode& ec)
 {
-    RELEASE_ASSERT_NOT_REACHED();
+    auto idbKey = scriptValueToIDBKey(execState, key);
+    return putOrAdd(execState, value, idbKey, IndexedDB::ObjectStoreOverwriteMode::NoOverwrite, ec);
 }
 
 RefPtr<WebCore::IDBRequest> IDBObjectStore::put(JSC::ExecState& execState, Deprecated::ScriptValue& value, const Deprecated::ScriptValue& key, ExceptionCode& ec)
index f08c242d0ea53fae4ff4fca1fc6636fcddd9a670..bbaf66b4d758ff1d18cffa3a3e37d914142bd6d9 100644 (file)
@@ -387,7 +387,7 @@ void IDBTransaction::didCreateObjectStoreOnServer(const IDBResultData& resultDat
 
 Ref<IDBRequest> IDBTransaction::requestGetRecord(ScriptExecutionContext& context, IDBObjectStore& objectStore, IDBKey& key)
 {
-    LOG(IndexedDB, "IDBTransaction::requestPutOrAdd");
+    LOG(IndexedDB, "IDBTransaction::requestGetRecord");
     ASSERT(isActive());
     ASSERT(key.isValid());