Title: [104506] trunk
Revision
104506
Author
[email protected]
Date
2012-01-09 16:13:12 -0800 (Mon, 09 Jan 2012)

Log Message

IndexedDB: Throw exception if IDBCursor.continue() called with lower key than current
https://bugs.webkit.org/show_bug.cgi?id=74213

Patch by Joshua Bell <[email protected]> on 2012-01-09
Reviewed by Tony Chang.

Source/WebCore:

* storage/IDBCursorBackendImpl.cpp:
(WebCore::IDBCursorBackendImpl::continueFunction):

LayoutTests:

* storage/indexeddb/cursor-continue-expected.txt:
* storage/indexeddb/cursor-continue.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (104505 => 104506)


--- trunk/LayoutTests/ChangeLog	2012-01-10 00:12:18 UTC (rev 104505)
+++ trunk/LayoutTests/ChangeLog	2012-01-10 00:13:12 UTC (rev 104506)
@@ -1,3 +1,13 @@
+2012-01-09  Joshua Bell  <[email protected]>
+
+        IndexedDB: Throw exception if IDBCursor.continue() called with lower key than current
+        https://bugs.webkit.org/show_bug.cgi?id=74213
+
+        Reviewed by Tony Chang.
+
+        * storage/indexeddb/cursor-continue-expected.txt:
+        * storage/indexeddb/cursor-continue.html:
+
 2012-01-09  Ojan Vafai  <[email protected]>
 
         Tests for nested flexboxes

Modified: trunk/LayoutTests/storage/indexeddb/cursor-continue-expected.txt (104505 => 104506)


--- trunk/LayoutTests/storage/indexeddb/cursor-continue-expected.txt	2012-01-10 00:12:18 UTC (rev 104505)
+++ trunk/LayoutTests/storage/indexeddb/cursor-continue-expected.txt	2012-01-10 00:13:12 UTC (rev 104506)
@@ -3,7 +3,13 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-webkitIndexedDB.open('cursor-continue')
+window.indexedDB = window.indexedDB || window.webkitIndexedDB
+PASS indexedDB != null is true
+window.IDBCursor = window.IDBCursor || window.webkitIDBCursor
+PASS IDBCursor != null is true
+window.IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException
+PASS IDBDatabaseException != null is true
+indexedDB.open('cursor-continue')
 db = event.target.result
 db.setVersion('new version')
 trans = event.target.result
@@ -30,7 +36,7 @@
 objectStore.add({'x': testData[nextToAdd]}, nextToAdd)
 objectStore.add({'x': testData[nextToAdd]}, nextToAdd)
 
-indexObject.openKeyCursor(null, webkitIDBCursor.NEXT)
+indexObject.openKeyCursor(null, IDBCursor.NEXT)
 PASS event.target.result.primaryKey is 0
 event.target.result.continue(3.14159)
 PASS event.target.result.primaryKey is 3
@@ -55,7 +61,7 @@
 event.target.result.continue('the BIGGEST string')
 PASS event.target.result is null
 
-indexObject.openKeyCursor(null, webkitIDBCursor.PREV)
+indexObject.openKeyCursor(null, IDBCursor.PREV)
 PASS event.target.result.primaryKey is 17
 event.target.result.continue('A bit2')
 PASS event.target.result.primaryKey is 15
@@ -71,8 +77,24 @@
 PASS event.target.result.primaryKey is 1
 event.target.result.continue(1)
 PASS event.target.result.primaryKey is 0
-event.target.result.continue(1)
+event.target.result.continue()
 PASS event.target.result is null
+
+indexObject.openKeyCursor(null, IDBCursor.NEXT)
+PASS event.target.result.primaryKey is 0
+event.target.result.continue(3.14159)
+PASS event.target.result.primaryKey is 3
+Expecting exception from event.target.result.continue(1)
+PASS Exception was thrown.
+PASS code is IDBDatabaseException.DATA_ERR
+
+indexObject.openKeyCursor(null, IDBCursor.PREV)
+PASS event.target.result.primaryKey is 17
+event.target.result.continue('A bit2')
+PASS event.target.result.primaryKey is 15
+Expecting exception from event.target.result.continue('A bit3')
+PASS Exception was thrown.
+PASS code is IDBDatabaseException.DATA_ERR
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/storage/indexeddb/cursor-continue.html (104505 => 104506)


--- trunk/LayoutTests/storage/indexeddb/cursor-continue.html	2012-01-10 00:12:18 UTC (rev 104505)
+++ trunk/LayoutTests/storage/indexeddb/cursor-continue.html	2012-01-10 00:13:12 UTC (rev 104506)
@@ -35,10 +35,21 @@
     "A bit3",
     "the BIGGEST string"
 ];
- 
+
+function test()
+{
+    evalAndLog("window.indexedDB = window.indexedDB || window.webkitIndexedDB");
+    shouldBeTrue("indexedDB != null");
+    evalAndLog("window.IDBCursor = window.IDBCursor || window.webkitIDBCursor");
+    shouldBeTrue("IDBCursor != null");
+    evalAndLog("window.IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException");
+    shouldBeTrue("IDBDatabaseException != null");
+    openDatabase();
+}
+
 function openDatabase()
 {
-    result = evalAndLog("webkitIndexedDB.open('cursor-continue')");
+    result = evalAndLog("indexedDB.open('cursor-continue')");
     result._onsuccess_ = setVersion;
     result._onerror_ = unexpectedErrorCallback;
 }
@@ -76,7 +87,7 @@
 function ascendingTest()
 {
     debug("");
-    var request = evalAndLog("indexObject.openKeyCursor(null, webkitIDBCursor.NEXT)");
+    var request = evalAndLog("indexObject.openKeyCursor(null, IDBCursor.NEXT)");
     request._onsuccess_ = ascendingCallback;
     request._onerror_ = unexpectedErrorCallback;
     window.stage = 0;
@@ -131,7 +142,7 @@
 function descendingTest()
 {
     debug("");
-    var request = evalAndLog("indexObject.openKeyCursor(null, webkitIDBCursor.PREV)");
+    var request = evalAndLog("indexObject.openKeyCursor(null, IDBCursor.PREV)");
     request._onsuccess_ = descendingCallback;
     request._onerror_ = unexpectedErrorCallback;
     window.stage = 0;
@@ -162,19 +173,63 @@
         evalAndLog("event.target.result.continue(1)");
     } else if (window.stage == 7) {
         shouldBe("event.target.result.primaryKey", "0");
-        evalAndLog("event.target.result.continue(1)");
+        evalAndLog("event.target.result.continue()");
     } else if (window.stage == 8) {
         shouldBeNull("event.target.result");
-        done();
+        ascendingErrorTest();
         return;
     } else {
         testFailed("Illegal stage.");
     }
     window.stage++;
 }
+
+function ascendingErrorTest()
+{
+    debug("");
+    var request = evalAndLog("indexObject.openKeyCursor(null, IDBCursor.NEXT)");
+    window.stage = 0;
+    request._onerror_ = unexpectedErrorCallback;
+    request._onsuccess_ = function() {
+        if (window.stage === 0) {
+            shouldBe("event.target.result.primaryKey", "0");
+            evalAndLog("event.target.result.continue(3.14159)");
+        } else if (window.stage == 1) {
+            shouldBe("event.target.result.primaryKey", "3");
+            evalAndExpectException("event.target.result.continue(1)", "IDBDatabaseException.DATA_ERR");
+            descendingErrorTest();
+            return;
+        } else {
+           testFailed("Illegal stage.");
+        }
+        window.stage++;
+    };
+}
+
+function descendingErrorTest()
+{
+    debug("");
+    var request = evalAndLog("indexObject.openKeyCursor(null, IDBCursor.PREV)");
+    window.stage = 0;
+    request._onerror_ = unexpectedErrorCallback;
+    request._onsuccess_ = function() {
+        if (window.stage == 0) {
+            shouldBe("event.target.result.primaryKey", "17");
+            evalAndLog("event.target.result.continue('A bit2')");
+        } else if (window.stage == 1) {
+            shouldBe("event.target.result.primaryKey", "15");
+            evalAndExpectException("event.target.result.continue('A bit3')", "IDBDatabaseException.DATA_ERR");
+            done();
+            return;
+        } else {
+           testFailed("Illegal stage.");
+        }
+        window.stage++;
+    };
+}
+
+test();
  
-openDatabase(); // The first step.
- 
 </script>
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (104505 => 104506)


--- trunk/Source/WebCore/ChangeLog	2012-01-10 00:12:18 UTC (rev 104505)
+++ trunk/Source/WebCore/ChangeLog	2012-01-10 00:13:12 UTC (rev 104506)
@@ -1,3 +1,13 @@
+2012-01-09  Joshua Bell  <[email protected]>
+
+        IndexedDB: Throw exception if IDBCursor.continue() called with lower key than current
+        https://bugs.webkit.org/show_bug.cgi?id=74213
+
+        Reviewed by Tony Chang.
+
+        * storage/IDBCursorBackendImpl.cpp:
+        (WebCore::IDBCursorBackendImpl::continueFunction):
+
 2012-01-09  Justin Novosad  <[email protected]>
 
         [chromium win] Creating lots of temporary canvas contexts will crash.

Modified: trunk/Source/WebCore/storage/IDBCursorBackendImpl.cpp (104505 => 104506)


--- trunk/Source/WebCore/storage/IDBCursorBackendImpl.cpp	2012-01-10 00:12:18 UTC (rev 104505)
+++ trunk/Source/WebCore/storage/IDBCursorBackendImpl.cpp	2012-01-10 00:13:12 UTC (rev 104506)
@@ -97,6 +97,22 @@
 void IDBCursorBackendImpl::continueFunction(PassRefPtr<IDBKey> prpKey, PassRefPtr<IDBCallbacks> prpCallbacks, ExceptionCode& ec)
 {
     RefPtr<IDBKey> key = prpKey;
+
+    if (m_cursor && key) {
+        ASSERT(m_cursor->key());
+        if (m_direction == IDBCursor::NEXT || m_direction == IDBCursor::NEXT_NO_DUPLICATE) {
+            if (key->isLessThan(m_cursor->key().get())) {
+                ec = IDBDatabaseException::DATA_ERR;
+                return;
+            }
+        } else {
+            if (m_cursor->key()->isLessThan(key.get())) {
+                ec = IDBDatabaseException::DATA_ERR;
+                return;
+            }
+        }
+    }
+
     if (!m_transaction->scheduleTask(createCallbackTask(&IDBCursorBackendImpl::continueFunctionInternal, this, key, prpCallbacks)))
         ec = IDBDatabaseException::NOT_ALLOWED_ERR;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to