IndexedDB: IDBDatabase.objectStoreNames and IDObjectStore.indexNames results should...
authorjsbell@chromium.org <jsbell@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Mar 2012 05:22:57 +0000 (05:22 +0000)
committerjsbell@chromium.org <jsbell@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Mar 2012 05:22:57 +0000 (05:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79950

Reviewed by Tony Chang.

Source/WebCore:

Test: storage/indexeddb/list-ordering.html

* dom/DOMStringList.cpp: Added sort method, not exposed via IDL.
(WebCore::DOMStringList::sort):
(WebCore):
* dom/DOMStringList.h:
(DOMStringList):
* storage/IDBDatabaseBackendImpl.cpp:
(WebCore::IDBDatabaseBackendImpl::objectStoreNames):
* storage/IDBObjectStoreBackendImpl.cpp:
(WebCore::IDBObjectStoreBackendImpl::indexNames):

LayoutTests:

* storage/indexeddb/list-ordering-expected.txt: Added.
* storage/indexeddb/list-ordering.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/list-ordering-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/list-ordering.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/DOMStringList.cpp
Source/WebCore/dom/DOMStringList.h
Source/WebCore/storage/IDBDatabaseBackendImpl.cpp
Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp

index 6abb285..e70b97e 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-29  Joshua Bell  <jsbell@chromium.org>
+
+        IndexedDB: IDBDatabase.objectStoreNames and IDObjectStore.indexNames results should be sorted
+        https://bugs.webkit.org/show_bug.cgi?id=79950
+
+        Reviewed by Tony Chang.
+
+        * storage/indexeddb/list-ordering-expected.txt: Added.
+        * storage/indexeddb/list-ordering.html: Added.
+
 2012-02-29  Kentaro Hara  <haraken@chromium.org>
 
         Unreviewed, gardening.
diff --git a/LayoutTests/storage/indexeddb/list-ordering-expected.txt b/LayoutTests/storage/indexeddb/list-ordering-expected.txt
new file mode 100644 (file)
index 0000000..4971db0
--- /dev/null
@@ -0,0 +1,65 @@
+
+Test string list ordering in IndexedDB.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB = window.indexedDB || window.webkitIndexedDB
+PASS indexedDB != null is true
+check that the expected order is the canonical JS sort order:
+sorted_order = expected_order.slice(); sorted_order.sort()
+PASS areArraysEqual(sorted_order, expected_order) is true
+
+testStoresAndIndexes():
+indexedDB.deleteDatabase('list-ordering')
+indexedDB.open('list-ordering')
+db = request.result
+PASS db.version is ""
+db.setVersion('1')
+
+Object stores:
+db.createObjectStore("𝄞")
+db.createObjectStore("�")
+db.createObjectStore("Ā")
+db.createObjectStore("က")
+db.createObjectStore("á")
+db.createObjectStore("ÿ")
+db.createObjectStore("Á")
+db.createObjectStore("à")
+db.createObjectStore("\7f")
+db.createObjectStore("À")
+db.createObjectStore("a")
+db.createObjectStore("b")
+db.createObjectStore("A")
+db.createObjectStore("B")
+db.createObjectStore("0")
+db.createObjectStore("1")
+db.createObjectStore("\u0000")
+db.createObjectStore("")
+PASS areArraysEqual(db.objectStoreNames, expected_order) is true
+
+Indexes:
+store = db.createObjectStore('store')
+store.createIndex("𝄞", 'keyPath')
+store.createIndex("�", 'keyPath')
+store.createIndex("Ā", 'keyPath')
+store.createIndex("က", 'keyPath')
+store.createIndex("á", 'keyPath')
+store.createIndex("ÿ", 'keyPath')
+store.createIndex("Á", 'keyPath')
+store.createIndex("à", 'keyPath')
+store.createIndex("\7f", 'keyPath')
+store.createIndex("À", 'keyPath')
+store.createIndex("a", 'keyPath')
+store.createIndex("b", 'keyPath')
+store.createIndex("A", 'keyPath')
+store.createIndex("B", 'keyPath')
+store.createIndex("0", 'keyPath')
+store.createIndex("1", 'keyPath')
+store.createIndex("\u0000", 'keyPath')
+store.createIndex("", 'keyPath')
+PASS areArraysEqual(store.indexNames, expected_order) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/list-ordering.html b/LayoutTests/storage/indexeddb/list-ordering.html
new file mode 100644 (file)
index 0000000..08fd54f
--- /dev/null
@@ -0,0 +1,100 @@
+<html>
+<head>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/shared.js"></script>
+</head>
+<body>
+<input type="file" id="fileInput" multiple></input>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+
+description("Test string list ordering in IndexedDB.");
+if (window.layoutTestController)
+    layoutTestController.waitUntilDone();
+
+var expected_order = [
+  "",
+  "\x00", // 'NULL' (U+0000)
+  "0",
+  "1",
+  "A",
+  "B",
+  "a",
+  "b",
+  "\x7F", // 'DELETE' (U+007F)
+  "\xC0", // 'LATIN CAPITAL LETTER A WITH GRAVE' (U+00C0)
+  "\xC1", // 'LATIN CAPITAL LETTER A WITH ACUTE' (U+00C1)
+  "\xE0", // 'LATIN SMALL LETTER A WITH GRAVE' (U+00E0)
+  "\xE1", // 'LATIN SMALL LETTER A WITH ACUTE' (U+00E1)
+  "\xFF", // 'LATIN SMALL LETTER Y WITH DIAERESIS' (U+00FF)
+  "\u0100", // 'LATIN CAPITAL LETTER A WITH MACRON' (U+0100)
+  "\u1000", // 'MYANMAR LETTER KA' (U+1000)
+  "\uD834\uDD1E", // 'MUSICAL SYMBOL G-CLEF' (U+1D11E), UTF-16 surrogate pairs
+  "\uFFFD" // 'REPLACEMENT CHARACTER' (U+FFFD)
+];
+var i, tmp, permuted_order = expected_order.slice(); permuted_order.reverse();
+for (i = 0; i < permuted_order.length - 2; i += 2) {
+    tmp = permuted_order[i];
+    permuted_order[i] = permuted_order[i + 1];
+    permuted_order[i + 1] = tmp;
+}
+
+function test()
+{
+    evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB");
+    shouldBeTrue("indexedDB != null");
+
+    debug("check that the expected order is the canonical JS sort order:");
+    evalAndLog("sorted_order = expected_order.slice(); sorted_order.sort()");
+    shouldBeTrue("areArraysEqual(sorted_order, expected_order)");
+    testStoresAndIndexes();
+}
+
+
+
+function testStoresAndIndexes()
+{
+    debug("");
+    debug("testStoresAndIndexes():");
+    request = evalAndLog("indexedDB.deleteDatabase('list-ordering')");
+    request.onerror = unexpectedErrorCallback;
+    request.onsuccess = function(e) {
+        request = evalAndLog("indexedDB.open('list-ordering')");
+        request.onerror = unexpectedErrorCallback;
+        request.onsuccess = function(e) {
+            evalAndLog("db = request.result");
+            shouldBeEqualToString("db.version", "");
+            request = evalAndLog("db.setVersion('1')");
+            request.onerror = unexpectedErrorCallback;
+            request.onsuccess = function(e) {
+                trans = request.result;
+
+                debug("");
+                debug("Object stores:");
+                permuted_order.forEach(function (name) {
+                    evalAndLog("db.createObjectStore(" + JSON.stringify(name) +")");
+                });
+
+                shouldBeTrue("areArraysEqual(db.objectStoreNames, expected_order)");
+
+                debug("");
+                debug("Indexes:");
+                store = evalAndLog("store = db.createObjectStore('store')");
+                permuted_order.forEach(function (name) {
+                    evalAndLog("store.createIndex(" + JSON.stringify(name) +", 'keyPath')");
+                });
+
+                shouldBeTrue("areArraysEqual(store.indexNames, expected_order)");
+
+                trans.oncomplete = done;
+            };
+        };
+    };
+}
+
+test();
+
+</script>
+</body>
+</html>
index b82fac7..4d2994e 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-29  Joshua Bell  <jsbell@chromium.org>
+
+        IndexedDB: IDBDatabase.objectStoreNames and IDObjectStore.indexNames results should be sorted
+        https://bugs.webkit.org/show_bug.cgi?id=79950
+
+        Reviewed by Tony Chang.
+
+        Test: storage/indexeddb/list-ordering.html
+
+        * dom/DOMStringList.cpp: Added sort method, not exposed via IDL.
+        (WebCore::DOMStringList::sort):
+        (WebCore):
+        * dom/DOMStringList.h:
+        (DOMStringList):
+        * storage/IDBDatabaseBackendImpl.cpp:
+        (WebCore::IDBDatabaseBackendImpl::objectStoreNames):
+        * storage/IDBObjectStoreBackendImpl.cpp:
+        (WebCore::IDBObjectStoreBackendImpl::indexNames):
+
 2012-02-29  W. James MacLean  <wjmaclean@chromium.org>
 
         [chromium] Estimate pixel count for frame rate control
index 430265a..bcc0d23 100644 (file)
@@ -48,4 +48,9 @@ bool DOMStringList::contains(const String& string) const
     return false;
 }
 
+void DOMStringList::sort()
+{
+    std::sort(m_strings.begin(), m_strings.end(), WTF::codePointCompareLessThan);
+}
+
 } // namespace WebCore
index 6719f17..057dac4 100644 (file)
@@ -45,6 +45,7 @@ public:
     bool isEmpty() const { return m_strings.isEmpty(); }
     void clear() { m_strings.clear(); }
     void append(const String& string) { m_strings.append(string); }
+    void sort();
 
     // Implements the IDL.
     size_t length() const { return m_strings.size(); }
index 6720fe2..b05b328 100644 (file)
@@ -133,6 +133,7 @@ PassRefPtr<DOMStringList> IDBDatabaseBackendImpl::objectStoreNames() const
     RefPtr<DOMStringList> objectStoreNames = DOMStringList::create();
     for (ObjectStoreMap::const_iterator it = m_objectStores.begin(); it != m_objectStores.end(); ++it)
         objectStoreNames->append(it->first);
+    objectStoreNames->sort();
     return objectStoreNames.release();
 }
 
index b9ecce3..548f1a2 100644 (file)
@@ -79,6 +79,7 @@ PassRefPtr<DOMStringList> IDBObjectStoreBackendImpl::indexNames() const
     RefPtr<DOMStringList> indexNames = DOMStringList::create();
     for (IndexMap::const_iterator it = m_indexes.begin(); it != m_indexes.end(); ++it)
         indexNames->append(it->first);
+    indexNames->sort();
     return indexNames.release();
 }