2011-04-28 Mark Pilgrim <pilgrim@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Apr 2011 21:12:45 +0000 (21:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Apr 2011 21:12:45 +0000 (21:12 +0000)
        Reviewed by Tony Chang.

        IndexedDB createIndex should fail if name arg is null
        https://bugs.webkit.org/show_bug.cgi?id=58365

        * storage/indexeddb/mozilla/create-index-null-name-expected.txt: Added.
        * storage/indexeddb/mozilla/create-index-null-name.html: Added.
2011-04-28  Mark Pilgrim  <pilgrim@chromium.org>

        Reviewed by Tony Chang.

        IndexedDB createIndex should fail if name arg is null
        https://bugs.webkit.org/show_bug.cgi?id=58365

        Test: storage/indexeddb/mozilla/create-index-null-name.html

        * storage/IDBObjectStore.idl:
        * storage/IDBObjectStoreBackendImpl.cpp:
        (WebCore::IDBObjectStoreBackendImpl::createIndex):

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

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/mozilla/create-index-null-name-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/mozilla/create-index-null-name.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/storage/IDBObjectStore.idl
Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp

index 45497c9..136bf67 100644 (file)
@@ -2,6 +2,16 @@
 
         Reviewed by Tony Chang.
 
+        IndexedDB createIndex should fail if name arg is null
+        https://bugs.webkit.org/show_bug.cgi?id=58365
+
+        * storage/indexeddb/mozilla/create-index-null-name-expected.txt: Added.
+        * storage/indexeddb/mozilla/create-index-null-name.html: Added.
+
+2011-04-28  Mark Pilgrim  <pilgrim@chromium.org>
+
+        Reviewed by Tony Chang.
+
         IndexedDB put() should fail if second (key) parameter is null
         https://bugs.webkit.org/show_bug.cgi?id=58613
 
diff --git a/LayoutTests/storage/indexeddb/mozilla/create-index-null-name-expected.txt b/LayoutTests/storage/indexeddb/mozilla/create-index-null-name-expected.txt
new file mode 100644 (file)
index 0000000..ec9eae6
--- /dev/null
@@ -0,0 +1,21 @@
+Test IndexedDB's creating index with null name
+
+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('a', { keyPath: 'id', autoIncrement: true });
+Expecting exception from index = objectStore.createIndex(null, null);
+PASS Exception was thrown.
+PASS code is IDBDatabaseException.NON_TRANSIENT_ERR
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/mozilla/create-index-null-name.html b/LayoutTests/storage/indexeddb/mozilla/create-index-null-name.html
new file mode 100644 (file)
index 0000000..59b014c
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<!--
+  original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_create_index.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="../../../fast/js/resources/js-test-style.css">
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../../fast/js/resources/js-test-post-function.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+description("Test IndexedDB's creating index with null name");
+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('a', { keyPath: 'id', autoIncrement: true });");
+
+    index = evalAndExpectException("index = objectStore.createIndex(null, null);", "IDBDatabaseException.NON_TRANSIENT_ERR");
+
+    done();
+}
+
+var successfullyParsed = true;
+
+test();
+
+</script>
+</body>
+</html>
+
index 6b19c01..5ac36bf 100644 (file)
@@ -2,6 +2,19 @@
 
         Reviewed by Tony Chang.
 
+        IndexedDB createIndex should fail if name arg is null
+        https://bugs.webkit.org/show_bug.cgi?id=58365
+
+        Test: storage/indexeddb/mozilla/create-index-null-name.html
+
+        * storage/IDBObjectStore.idl:
+        * storage/IDBObjectStoreBackendImpl.cpp:
+        (WebCore::IDBObjectStoreBackendImpl::createIndex):
+
+2011-04-28  Mark Pilgrim  <pilgrim@chromium.org>
+
+        Reviewed by Tony Chang.
+
         IndexedDB put() should fail if second (key) parameter is null
         https://bugs.webkit.org/show_bug.cgi?id=58613
 
index c95fb9d..9d92f07 100644 (file)
@@ -28,7 +28,7 @@ module storage {
     interface [
         Conditional=INDEXED_DATABASE
     ] IDBObjectStore {
-        readonly attribute DOMString name;
+        readonly attribute [ConvertNullStringTo=Null] DOMString name;
         readonly attribute [ConvertNullStringTo=Null] DOMString keyPath;
         readonly attribute DOMStringList indexNames;
 
@@ -44,7 +44,7 @@ module storage {
             raises (IDBDatabaseException);
         [CallWith=ScriptExecutionContext] IDBRequest openCursor(in [Optional] IDBKeyRange range, in [Optional] unsigned short direction)
             raises (IDBDatabaseException);
-        IDBIndex createIndex(in DOMString name, in [ConvertNullToNullString] DOMString keyPath, in [Optional] OptionsObject options)
+        IDBIndex createIndex(in [ConvertNullToNullString] DOMString name, in [ConvertNullToNullString] DOMString keyPath, in [Optional] OptionsObject options)
             raises (IDBDatabaseException);
         IDBIndex index(in DOMString name)
             raises (IDBDatabaseException);
index 368af13..3b489a7 100644 (file)
@@ -375,6 +375,10 @@ static bool populateIndex(IDBBackingStore& backingStore, int64_t databaseId, int
 
 PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendImpl::createIndex(const String& name, const String& keyPath, bool unique, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
 {
+    if (name.isNull()) {
+        ec = IDBDatabaseException::NON_TRANSIENT_ERR;
+        return 0;
+    }
     if (m_indexes.contains(name)) {
         ec = IDBDatabaseException::CONSTRAINT_ERR;
         return 0;