Title: [103762] trunk
Revision
103762
Author
[email protected]
Date
2011-12-28 04:58:43 -0800 (Wed, 28 Dec 2011)

Log Message

IndexedDB: IDBKeyRange constructor should throw when lower > upper
https://bugs.webkit.org/show_bug.cgi?id=74705

Reviewed by Tony Chang.

Source/WebCore:

Make IDBKeyRange throw an exception when lower > upper,
or lower == upper and one or both of the bounds is open.

Tested in storage/indexeddb/keyrange.html.

* storage/IDBKeyRange.cpp:
(WebCore::IDBKeyRange::bound):

LayoutTests:

Update tests to check that the IDBKeyRange constructor throws when
trying to specify illegal key ranges, and update tests that were
doing that.

* storage/indexeddb/index-cursor-expected.txt:
* storage/indexeddb/index-cursor.html:
* storage/indexeddb/keyrange-expected.txt:
* storage/indexeddb/keyrange.html:
* storage/indexeddb/objectstore-cursor-expected.txt:
* storage/indexeddb/objectstore-cursor.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (103761 => 103762)


--- trunk/LayoutTests/ChangeLog	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/ChangeLog	2011-12-28 12:58:43 UTC (rev 103762)
@@ -1,3 +1,21 @@
+2011-12-28  Hans Wennborg  <[email protected]>
+
+        IndexedDB: IDBKeyRange constructor should throw when lower > upper
+        https://bugs.webkit.org/show_bug.cgi?id=74705
+
+        Reviewed by Tony Chang.
+
+        Update tests to check that the IDBKeyRange constructor throws when
+        trying to specify illegal key ranges, and update tests that were
+        doing that.
+
+        * storage/indexeddb/index-cursor-expected.txt:
+        * storage/indexeddb/index-cursor.html:
+        * storage/indexeddb/keyrange-expected.txt:
+        * storage/indexeddb/keyrange.html:
+        * storage/indexeddb/objectstore-cursor-expected.txt:
+        * storage/indexeddb/objectstore-cursor.html:
+
 2011-12-28  Alexander Pavlov  <[email protected]>
 
         Web Inspector: [protocol] empty enum constant should be replaced with identifier

Modified: trunk/LayoutTests/storage/indexeddb/index-count-expected.txt (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/index-count-expected.txt	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/index-count-expected.txt	2011-12-28 12:58:43 UTC (rev 103762)
@@ -78,15 +78,10 @@
 PASS typeof request.result == 'number' is true
 PASS request.result is 1
 
-test = {"lower":0,"lowerOpen":true,"upper":0,"upperOpen":true,"expected":0}
+test = {"lower":500,"lowerOpen":false,"upper":500,"upperOpen":false,"expected":0}
 request = index.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
 PASS typeof request.result == 'number' is true
 PASS request.result is 0
-
-test = {"lower":20,"lowerOpen":true,"upper":10,"upperOpen":true,"expected":0}
-request = index.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
-PASS typeof request.result == 'number' is true
-PASS request.result is 0
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/storage/indexeddb/index-count.html (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/index-count.html	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/index-count.html	2011-12-28 12:58:43 UTC (rev 103762)
@@ -95,8 +95,7 @@
         { lower: 0, lowerOpen: false, upper: 100, upperOpen: false, expected: 100 },
         { lower: 10, lowerOpen: false, upper: 100, upperOpen: false, expected: 90 },
         { lower: 0, lowerOpen: false, upper: 0, upperOpen: false, expected: 1 },
-        { lower: 0, lowerOpen: true, upper: 0, upperOpen: true, expected: 0 },
-        { lower: 20, lowerOpen: true, upper: 10, upperOpen: true, expected: 0 }
+        { lower: 500, lowerOpen: false, upper: 500, upperOpen: false, expected: 0 }
     ];
 
     function nextTest() {

Modified: trunk/LayoutTests/storage/indexeddb/index-cursor-expected.txt (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/index-cursor-expected.txt	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/index-cursor-expected.txt	2011-12-28 12:58:43 UTC (rev 103762)
@@ -1695,13 +1695,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 6; upper open bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 6; upper bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper open bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper bound is 6; sorted ascending.
 PASS event.target.result.primaryKey is expectedIndex
@@ -1711,13 +1711,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 6; upper open bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 6; upper bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper open bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper bound is 6; sorted descending.
 PASS event.target.result.primaryKey is expectedIndex
@@ -1727,13 +1727,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 6; upper open bound is 7; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 6; upper bound is 7; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper open bound is 7; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper bound is 7; sorted ascending.
 PASS event.target.result.primaryKey is expectedIndex
@@ -1743,13 +1743,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 6; upper open bound is 7; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 6; upper bound is 7; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper open bound is 7; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper bound is 7; sorted descending.
 PASS event.target.result.primaryKey is expectedIndex
@@ -1847,13 +1847,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 7; upper open bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 7; upper bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper open bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper bound is 6; sorted ascending.
 PASS event.target.result.primaryKey is expectedIndex
@@ -1863,13 +1863,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 7; upper open bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 7; upper bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper open bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper bound is 6; sorted descending.
 PASS event.target.result.primaryKey is expectedIndex
@@ -1879,13 +1879,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 7; upper open bound is 7; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 7; upper bound is 7; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper open bound is 7; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper bound is 7; sorted ascending.
 PASS event.target.result.primaryKey is expectedIndex
@@ -1895,13 +1895,13 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 7; upper open bound is 7; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 7; upper bound is 7; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper open bound is 7; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 7; upper bound is 7; sorted descending.
 PASS event.target.result.primaryKey is expectedIndex

Modified: trunk/LayoutTests/storage/indexeddb/index-cursor.html (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/index-cursor.html	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/index-cursor.html	2011-12-28 12:58:43 UTC (rev 103762)
@@ -166,6 +166,12 @@
     }
     testWithinBounds();
  
+    if (testData[lower] === testData[upper] && (lowerIsOpen || upperIsOpen)) {
+        debug("Skipping illegal key range.");
+        runNextTest();
+        return;
+    }
+
     var keyRange;
     if (lower !== null && upper !== null)
         keyRange = webkitIDBKeyRange.bound(testData[lower], testData[upper], lowerIsOpen, upperIsOpen);

Modified: trunk/LayoutTests/storage/indexeddb/keyrange-expected.txt (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/keyrange-expected.txt	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/keyrange-expected.txt	2011-12-28 12:58:43 UTC (rev 103762)
@@ -219,6 +219,23 @@
 PASS Caught exception: Error: DATA_ERR: DOM IDBDatabase Exception 5
 Passing an invalid key into bound({}, {})
 PASS Caught exception: Error: DATA_ERR: DOM IDBDatabase Exception 5
+Lower key greater than higher key, bound(4, 3)
+Expecting exception from webkitIDBKeyRange.bound(4, 3)
+PASS Exception was thrown.
+PASS code is webkitIDBDatabaseException.DATA_ERR
+Equal keys, either of the bounds is open, bound(4, 4, true, false)
+Expecting exception from webkitIDBKeyRange.bound(4, 4, true, false)
+PASS Exception was thrown.
+PASS code is webkitIDBDatabaseException.DATA_ERR
+Equal keys, either of the bounds is open, bound(4, 4, false, true)
+Expecting exception from webkitIDBKeyRange.bound(4, 4, false, true)
+PASS Exception was thrown.
+PASS code is webkitIDBDatabaseException.DATA_ERR
+Equal keys, either of the bounds is open, bound(4, 4, true, true)
+Expecting exception from webkitIDBKeyRange.bound(4, 4, true, true)
+PASS Exception was thrown.
+PASS code is webkitIDBDatabaseException.DATA_ERR
+Equal keys, none of the bounds is open, bound(4, 4, false, false)
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/storage/indexeddb/keyrange.html (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/keyrange.html	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/keyrange.html	2011-12-28 12:58:43 UTC (rev 103762)
@@ -171,6 +171,21 @@
     } catch (e) {
         testPassed("Caught exception: " + e.toString());
     }
+
+    debug("Lower key greater than higher key, bound(4, 3)");
+    evalAndExpectException("webkitIDBKeyRange.bound(4, 3)", "webkitIDBDatabaseException.DATA_ERR");
+
+    debug("Equal keys, either of the bounds is open, bound(4, 4, true, false)");
+    evalAndExpectException("webkitIDBKeyRange.bound(4, 4, true, false)", "webkitIDBDatabaseException.DATA_ERR");
+
+    debug("Equal keys, either of the bounds is open, bound(4, 4, false, true)");
+    evalAndExpectException("webkitIDBKeyRange.bound(4, 4, false, true)", "webkitIDBDatabaseException.DATA_ERR");
+
+    debug("Equal keys, either of the bounds is open, bound(4, 4, true, true)");
+    evalAndExpectException("webkitIDBKeyRange.bound(4, 4, true, true)", "webkitIDBDatabaseException.DATA_ERR");
+
+    debug("Equal keys, none of the bounds is open, bound(4, 4, false, false)");
+    webkitIDBKeyRange.bound(4, 4, false, false);
 }
 
 test();

Modified: trunk/LayoutTests/storage/indexeddb/objectstore-count-expected.txt (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/objectstore-count-expected.txt	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-count-expected.txt	2011-12-28 12:58:43 UTC (rev 103762)
@@ -72,15 +72,10 @@
 PASS typeof request.result == 'number' is true
 PASS request.result is 1
 
-test = {"lower":0,"lowerOpen":true,"upper":0,"upperOpen":true,"expected":0}
+test = {"lower":500,"lowerOpen":false,"upper":500,"upperOpen":false,"expected":0}
 request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
 PASS typeof request.result == 'number' is true
 PASS request.result is 0
-
-test = {"lower":20,"lowerOpen":true,"upper":10,"upperOpen":true,"expected":0}
-request = store.count(IDBKeyRange.bound(test.lower, test.upper, test.lowerOpen, test.upperOpen))
-PASS typeof request.result == 'number' is true
-PASS request.result is 0
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/storage/indexeddb/objectstore-count.html (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/objectstore-count.html	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-count.html	2011-12-28 12:58:43 UTC (rev 103762)
@@ -88,8 +88,7 @@
         { lower: 0, lowerOpen: false, upper: 100, upperOpen: false, expected: 100 },
         { lower: 10, lowerOpen: false, upper: 100, upperOpen: false, expected: 90 },
         { lower: 0, lowerOpen: false, upper: 0, upperOpen: false, expected: 1 },
-        { lower: 0, lowerOpen: true, upper: 0, upperOpen: true, expected: 0 },
-        { lower: 20, lowerOpen: true, upper: 10, upperOpen: true, expected: 0 }
+        { lower: 500, lowerOpen: false, upper: 500, upperOpen: false, expected: 0 }
     ];
 
     function nextTest() {

Modified: trunk/LayoutTests/storage/indexeddb/objectstore-cursor-expected.txt (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/objectstore-cursor-expected.txt	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-cursor-expected.txt	2011-12-28 12:58:43 UTC (rev 103762)
@@ -697,26 +697,26 @@
 PASS event.target.result is null
 
 Next test: lower open bound is 6; upper open bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 6; upper bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper open bound is 6; sorted ascending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper bound is 6; sorted ascending.
 PASS event.target.result.key is testData[6]
 PASS event.target.result is null
 
 Next test: lower open bound is 6; upper open bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower open bound is 6; upper bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper open bound is 6; sorted descending.
-PASS event.target.result is null
+Skipping illegal key range.
 
 Next test: lower bound is 6; upper bound is 6; sorted descending.
 PASS event.target.result.key is testData[6]

Modified: trunk/LayoutTests/storage/indexeddb/objectstore-cursor.html (103761 => 103762)


--- trunk/LayoutTests/storage/indexeddb/objectstore-cursor.html	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-cursor.html	2011-12-28 12:58:43 UTC (rev 103762)
@@ -144,6 +144,12 @@
     }
     testWithinBounds();
  
+    if (testData[lower] === testData[upper] && (lowerIsOpen || upperIsOpen)) {
+        debug("Skipping illegal key range.");
+        runNextTest();
+        return;
+    }
+
     var keyRange;
     if (lower !== null && upper !== null)
         keyRange = webkitIDBKeyRange.bound(testData[lower], testData[upper], lowerIsOpen, upperIsOpen);

Modified: trunk/Source/WebCore/ChangeLog (103761 => 103762)


--- trunk/Source/WebCore/ChangeLog	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/Source/WebCore/ChangeLog	2011-12-28 12:58:43 UTC (rev 103762)
@@ -1,3 +1,18 @@
+2011-12-28  Hans Wennborg  <[email protected]>
+
+        IndexedDB: IDBKeyRange constructor should throw when lower > upper
+        https://bugs.webkit.org/show_bug.cgi?id=74705
+
+        Reviewed by Tony Chang.
+
+        Make IDBKeyRange throw an exception when lower > upper,
+        or lower == upper and one or both of the bounds is open.
+
+        Tested in storage/indexeddb/keyrange.html.
+
+        * storage/IDBKeyRange.cpp:
+        (WebCore::IDBKeyRange::bound):
+
 2011-12-28  Alexander Pavlov  <[email protected]>
 
         Web Inspector: [protocol] empty enum constant should be replaced with identifier

Modified: trunk/Source/WebCore/storage/IDBKeyRange.cpp (103761 => 103762)


--- trunk/Source/WebCore/storage/IDBKeyRange.cpp	2011-12-28 12:28:04 UTC (rev 103761)
+++ trunk/Source/WebCore/storage/IDBKeyRange.cpp	2011-12-28 12:58:43 UTC (rev 103762)
@@ -78,6 +78,14 @@
         ec = IDBDatabaseException::DATA_ERR;
         return 0;
     }
+    if (lower && upper && upper->isLessThan(lower.get())) {
+        ec = IDBDatabaseException::DATA_ERR;
+        return 0;
+    }
+    if (lower && upper && upper->isEqual(lower.get()) && (lowerOpen || upperOpen)) {
+        ec = IDBDatabaseException::DATA_ERR;
+        return 0;
+    }
 
     return IDBKeyRange::create(lower, upper, lowerOpen ? LowerBoundOpen : LowerBoundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to