2010-11-25 Hans Wennborg <hans@chromium.org>
authorhans@chromium.org <hans@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Nov 2010 18:18:11 +0000 (18:18 +0000)
committerhans@chromium.org <hans@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Nov 2010 18:18:11 +0000 (18:18 +0000)
        Reviewed by Jeremy Orlow.

        IndexedDB: Better errors for not yet implemented features
        https://bugs.webkit.org/show_bug.cgi?id=50075

        Test that inserting a record where the key is a Date (either
        explicitly, or via a key path) yields an error.

        Test that calling createObjectStore with autoIncrement = true
        raises an exception.

        * storage/indexeddb/create-object-store-options-expected.txt:
        * storage/indexeddb/create-object-store-options.html:
        * storage/indexeddb/objectstore-basics-expected.txt:
        * storage/indexeddb/objectstore-basics.html:
2010-11-25  Hans Wennborg  <hans@chromium.org>

        Reviewed by Jeremy Orlow.

        IndexedDB: Better errors for not yet implemented features
        https://bugs.webkit.org/show_bug.cgi?id=50075

        Raise an exception if createObjectStore is called with autoIncrement
        set to true.

        Be a little bit more explicit in IDBBindingUtilities that we don't
        allow using Date objects as keys yet.

        * bindings/v8/IDBBindingUtilities.cpp:
        (WebCore::createIDBKeyFromValue):
        * storage/IDBDatabase.cpp:
        (WebCore::IDBDatabase::createObjectStore):
        * storage/IDBObjectStoreBackendImpl.cpp:
        (WebCore::IDBObjectStoreBackendImpl::putInternal):

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

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/create-object-store-options-expected.txt
LayoutTests/storage/indexeddb/create-object-store-options.html
LayoutTests/storage/indexeddb/objectstore-basics-expected.txt
LayoutTests/storage/indexeddb/objectstore-basics.html
WebCore/ChangeLog
WebCore/bindings/v8/IDBBindingUtilities.cpp
WebCore/storage/IDBDatabase.cpp

index 3ec2d08..39352dd 100644 (file)
@@ -1,3 +1,21 @@
+2010-11-25  Hans Wennborg  <hans@chromium.org>
+
+        Reviewed by Jeremy Orlow.
+
+        IndexedDB: Better errors for not yet implemented features
+        https://bugs.webkit.org/show_bug.cgi?id=50075
+
+        Test that inserting a record where the key is a Date (either
+        explicitly, or via a key path) yields an error.
+
+        Test that calling createObjectStore with autoIncrement = true
+        raises an exception.
+
+        * storage/indexeddb/create-object-store-options-expected.txt:
+        * storage/indexeddb/create-object-store-options.html:
+        * storage/indexeddb/objectstore-basics-expected.txt:
+        * storage/indexeddb/objectstore-basics.html:
+
 2010-11-25  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Unreviewed. Enable tests in chromium.
index aec381f..f116280 100644 (file)
@@ -16,6 +16,9 @@ result = db.setVersion('version 1')
 Deleted all object stores.
 db.createObjectStore('a', {keyPath: 'a'})
 db.createObjectStore('b')
+db.createObjectStore('c', {autoIncrement: true});
+PASS Exception thrown
+PASS code is webkitIDBDatabaseException.UNKNOWN_ERR
 trans = db.transaction([], webkitIDBTransaction.READ_WRITE)
 trans.objectStore('a').put({'a': 0})
 trans.objectStore('b').put({'a': 0}, 0)
index b28d2d2..3db2dd4 100644 (file)
@@ -44,6 +44,17 @@ function cleaned()
     evalAndLog("db.createObjectStore('a', {keyPath: 'a'})");
     evalAndLog("db.createObjectStore('b')");
 
+    try {
+        // FIXME: This should work in the future.
+        debug("db.createObjectStore('c', {autoIncrement: true});");
+        db.createObjectStore('c', {autoIncrement: true});
+        testFailed('createObjectStore with autoIncrement = true should throw');
+    } catch (err) {
+        testPassed("Exception thrown");
+        code = err.code;
+        shouldBe("code", "webkitIDBDatabaseException.UNKNOWN_ERR");
+    }
+
     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
 
     req = evalAndLog("trans.objectStore('a').put({'a': 0})");
index 3252bcc..decd36c 100644 (file)
@@ -97,6 +97,13 @@ PASS store.indexNames.item(1) is null
 PASS store.indexNames.item(100) is null
 transaction = db.transaction()
 store = transaction.objectStore('storeName')
+Try to insert data with a Date key:
+store.add({x: 'foo'}, new Date())
+PASS Exception thrown
+PASS code is DOMException.TYPE_MISMATCH_ERR
+Try to insert data where key path yields a Date key:
+store.add({x: new Date()}, 'foo')
+PASS Adding data where key path yielded Date key resulted in error.
 store.add({x: 'value'}, 'key')
 PASS 'onsuccess' in result is true
 PASS 'onerror' in result is true
index 0501f30..5ff50c2 100644 (file)
@@ -142,6 +142,30 @@ function addData()
     var transaction = evalAndLog("transaction = db.transaction()");
     transaction.onabort = unexpectedAbortCallback;
     window.store = evalAndLog("store = transaction.objectStore('storeName')");
+
+    debug("Try to insert data with a Date key:");
+    // FIXME: This should work in the future.
+    try {
+        debug("store.add({x: 'foo'}, new Date())");
+        store.add({x: 'foo'}, new Date());
+        testFailed("Passing a Date as key argument should have thrown.");
+    } catch (err) {
+        testPassed("Exception thrown");
+        code = err.code;
+        shouldBe("code", "DOMException.TYPE_MISMATCH_ERR");
+    }
+
+    // FIXME: This should work in the future.
+    debug("Try to insert data where key path yields a Date key:");
+    result = evalAndLog("store.add({x: new Date()}, 'foo')");
+    result.onsuccess = unexpectedSuccessCallback;
+    result.onerror = addKeyPathYieldingDateFailure;
+}
+
+function addKeyPathYieldingDateFailure()
+{
+    testPassed("Adding data where key path yielded Date key resulted in error.");
+
     result = evalAndLog("store.add({x: 'value'}, 'key')");
     verifyResult(result);
     result.onsuccess = addSuccess;
index 2f50ded..403ef8f 100644 (file)
@@ -1,3 +1,23 @@
+2010-11-25  Hans Wennborg  <hans@chromium.org>
+
+        Reviewed by Jeremy Orlow.
+
+        IndexedDB: Better errors for not yet implemented features
+        https://bugs.webkit.org/show_bug.cgi?id=50075
+
+        Raise an exception if createObjectStore is called with autoIncrement
+        set to true.
+
+        Be a little bit more explicit in IDBBindingUtilities that we don't
+        allow using Date objects as keys yet.
+
+        * bindings/v8/IDBBindingUtilities.cpp:
+        (WebCore::createIDBKeyFromValue):
+        * storage/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::createObjectStore):
+        * storage/IDBObjectStoreBackendImpl.cpp:
+        (WebCore::IDBObjectStoreBackendImpl::putInternal):
+
 2010-11-25  Pavel Feldman  <pfeldman@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index 123b15c..644e2d2 100644 (file)
@@ -45,7 +45,8 @@ PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value)
         return IDBKey::create(value->Int32Value());
     if (value->IsString())
         return IDBKey::create(v8ValueToWebCoreString(value));
-    // FIXME: Implement dates.
+    if (value->IsDate())
+        return 0; // Signals type error. FIXME: Implement dates.
 
     return 0; // Signals type error.
 }
index 72ff17d..9a8727f 100644 (file)
@@ -69,9 +69,15 @@ PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, co
     options.getKeyBool("autoIncrement", autoIncrement);
     // FIXME: Look up evictable and pass that on as well.
 
+    if (autoIncrement) {
+        // FIXME: Implement support for auto increment.
+        ec = IDBDatabaseException::UNKNOWN_ERR;
+        return 0;
+    }
+
     RefPtr<IDBObjectStoreBackendInterface> objectStore = m_backend->createObjectStore(name, keyPath, autoIncrement, m_setVersionTransaction.get(), ec);
     if (!objectStore) {
-        // FIXME: ASSERT(ec) once UNKNOWN_ERR is not 0.
+        ASSERT(ec);
         return 0;
     }
     return IDBObjectStore::create(objectStore.release(), m_setVersionTransaction.get());