- Revision
- 86804
- Author
- [email protected]
- Date
- 2011-05-18 16:43:23 -0700 (Wed, 18 May 2011)
Log Message
2011-05-18 Mark Pilgrim <[email protected]>
Reviewed by Tony Chang.
IndexedDB put() should fail adding to object store that uses
out-of-line keys and has no key generator and the key parameter
was not provided
https://bugs.webkit.org/show_bug.cgi?id=58609
One new test and one fix to an existing test that relied on the old
broken behavior.
* storage/indexeddb/mozilla/key-requirements-put-no-key-expected.txt: Added.
* storage/indexeddb/mozilla/key-requirements-put-no-key.html: Added.
* storage/indexeddb/objectstore-autoincrement-expected.txt:
* storage/indexeddb/objectstore-autoincrement.html:
2011-05-18 Mark Pilgrim <[email protected]>
Reviewed by Tony Chang.
IndexedDB put() should fail adding to object store that uses
out-of-line keys and has no key generator and the key parameter
was not provided
https://bugs.webkit.org/show_bug.cgi?id=58609
Out-of-line keys means that objectStore->m_keyPath is null in ::put(),
no key generator means that objectStore->autoIncrement() is false, and
key parameter was not provided means that prpKey will be a null pointer.
The combination of these 3 should throw a DATA_ERR.
Test: storage/indexeddb/mozilla/key-requirements-put-no-key.html
* storage/IDBObjectStoreBackendImpl.cpp:
(WebCore::IDBObjectStoreBackendImpl::put):
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (86803 => 86804)
--- trunk/LayoutTests/ChangeLog 2011-05-18 23:34:52 UTC (rev 86803)
+++ trunk/LayoutTests/ChangeLog 2011-05-18 23:43:23 UTC (rev 86804)
@@ -1,3 +1,20 @@
+2011-05-18 Mark Pilgrim <[email protected]>
+
+ Reviewed by Tony Chang.
+
+ IndexedDB put() should fail adding to object store that uses
+ out-of-line keys and has no key generator and the key parameter
+ was not provided
+ https://bugs.webkit.org/show_bug.cgi?id=58609
+
+ One new test and one fix to an existing test that relied on the old
+ broken behavior.
+
+ * storage/indexeddb/mozilla/key-requirements-put-no-key-expected.txt: Added.
+ * storage/indexeddb/mozilla/key-requirements-put-no-key.html: Added.
+ * storage/indexeddb/objectstore-autoincrement-expected.txt:
+ * storage/indexeddb/objectstore-autoincrement.html:
+
2011-05-18 Siddharth Mathur <[email protected]>
Reviewed by Oliver Hunt.
Added: trunk/LayoutTests/storage/indexeddb/mozilla/key-requirements-put-no-key-expected.txt (0 => 86804)
--- trunk/LayoutTests/storage/indexeddb/mozilla/key-requirements-put-no-key-expected.txt (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/mozilla/key-requirements-put-no-key-expected.txt 2011-05-18 23:43:23 UTC (rev 86804)
@@ -0,0 +1,21 @@
+Test IndexedDB's behavior puting without key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
+PASS indexedDB == null is false
+IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;
+PASS IDBDatabaseException == null is false
+indexedDB.open(name, description)
+db = event.target.result
+request = db.setVersion('1')
+Deleted all object stores.
+objectStore = db.createObjectStore('bar');
+Expecting exception from objectStore.put({});
+PASS Exception was thrown.
+PASS code is IDBDatabaseException.DATA_ERR
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/storage/indexeddb/mozilla/key-requirements-put-no-key.html (0 => 86804)
--- trunk/LayoutTests/storage/indexeddb/mozilla/key-requirements-put-no-key.html (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/mozilla/key-requirements-put-no-key.html 2011-05-18 23:43:23 UTC (rev 86804)
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<!--
+ original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_key_requirements.html
+ license of original test:
+ " Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ "
+-->
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+description("Test IndexedDB's behavior puting without key");
+if (window.layoutTestController)
+ layoutTestController.waitUntilDone();
+
+function test()
+{
+ indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
+ shouldBeFalse("indexedDB == null");
+ IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
+ shouldBeFalse("IDBDatabaseException == null");
+
+ name = window.location.pathname;
+ description = "My Test Database";
+ request = evalAndLog("indexedDB.open(name, description)");
+ request._onsuccess_ = openSuccess;
+ request._onerror_ = unexpectedErrorCallback;
+}
+
+function openSuccess()
+{
+ db = evalAndLog("db = event.target.result");
+
+ request = evalAndLog("request = db.setVersion('1')");
+ request._onsuccess_ = cleanDatabase;
+ request._onerror_ = unexpectedErrorCallback;
+}
+
+function cleanDatabase()
+{
+ deleteAllObjectStores(db);
+ objectStore = evalAndLog("objectStore = db.createObjectStore('bar');");
+ evalAndExpectException("objectStore.put({});", "IDBDatabaseException.DATA_ERR");
+ done();
+}
+
+var successfullyParsed = true;
+
+test();
+
+</script>
+</body>
+</html>
+
Modified: trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement-expected.txt (86803 => 86804)
--- trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement-expected.txt 2011-05-18 23:34:52 UTC (rev 86803)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement-expected.txt 2011-05-18 23:43:23 UTC (rev 86804)
@@ -56,10 +56,9 @@
PASS event.target.result.number is "2107"
store = trans.objectStore('PlainOldStore')
Try adding with no key to object store without auto increment.
-store.add({name: 'Adam'})
-addAdamError():
-PASS event.target.errorCode is webkitIDBDatabaseException.DATA_ERR
-event.preventDefault()
+Expecting exception from store.add({name: 'Adam'})
+PASS Exception was thrown.
+PASS code is webkitIDBDatabaseException.DATA_ERR
store.add({name: 'Adam'}, 1)
addAdamSuccess():
PASS event.target.result is 1
Modified: trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement.html (86803 => 86804)
--- trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement.html 2011-05-18 23:34:52 UTC (rev 86803)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement.html 2011-05-18 23:43:23 UTC (rev 86804)
@@ -147,18 +147,7 @@
window.store = evalAndLog("store = trans.objectStore('PlainOldStore')");
debug("Try adding with no key to object store without auto increment.");
- request = evalAndLog("store.add({name: 'Adam'})");
- request._onsuccess_ = unexpectedSuccessCallback;
- request._onerror_ = addAdamError;
-}
-
-function addAdamError()
-{
- debug("addAdamError():");
- shouldBe("event.target.errorCode", "webkitIDBDatabaseException.DATA_ERR");
-
- evalAndLog("event.preventDefault()");
-
+ evalAndExpectException("store.add({name: 'Adam'})", "webkitIDBDatabaseException.DATA_ERR");
request = evalAndLog("store.add({name: 'Adam'}, 1)");
request._onsuccess_ = addAdamSuccess;
request._onerror_ = unexpectedErrorCallback;
Modified: trunk/Source/WebCore/ChangeLog (86803 => 86804)
--- trunk/Source/WebCore/ChangeLog 2011-05-18 23:34:52 UTC (rev 86803)
+++ trunk/Source/WebCore/ChangeLog 2011-05-18 23:43:23 UTC (rev 86804)
@@ -1,3 +1,22 @@
+2011-05-18 Mark Pilgrim <[email protected]>
+
+ Reviewed by Tony Chang.
+
+ IndexedDB put() should fail adding to object store that uses
+ out-of-line keys and has no key generator and the key parameter
+ was not provided
+ https://bugs.webkit.org/show_bug.cgi?id=58609
+
+ Out-of-line keys means that objectStore->m_keyPath is null in ::put(),
+ no key generator means that objectStore->autoIncrement() is false, and
+ key parameter was not provided means that prpKey will be a null pointer.
+ The combination of these 3 should throw a DATA_ERR.
+
+ Test: storage/indexeddb/mozilla/key-requirements-put-no-key.html
+
+ * storage/IDBObjectStoreBackendImpl.cpp:
+ (WebCore::IDBObjectStoreBackendImpl::put):
+
2011-05-18 Chris Rogers <[email protected]>
Reviewed by James Robinson.
Modified: trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp (86803 => 86804)
--- trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp 2011-05-18 23:34:52 UTC (rev 86803)
+++ trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp 2011-05-18 23:43:23 UTC (rev 86804)
@@ -135,6 +135,14 @@
ec = IDBDatabaseException::DATA_ERR;
return;
}
+
+ const bool autoIncrement = objectStore->autoIncrement();
+ const bool hasKeyPath = !objectStore->m_keyPath.isNull();
+ if (!key && !autoIncrement && !hasKeyPath) {
+ ec = IDBDatabaseException::DATA_ERR;
+ return;
+ }
+
// FIXME: This should throw a SERIAL_ERR on structured clone problems.
// FIXME: This should throw a DATA_ERR when the wrong key/keyPath data is supplied.
if (!transaction->scheduleTask(createCallbackTask(&IDBObjectStoreBackendImpl::putInternal, objectStore, value, key, putMode, callbacks, transaction)))