dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 1 | if (this.importScripts) { |
beidson@apple.com | f321a85 | 2014-02-12 18:17:47 +0000 | [diff] [blame] | 2 | importScripts('../../../resources/js-test.js'); |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 3 | importScripts('shared.js'); |
| 4 | } |
| 5 | |
| 6 | description("Test consistency of IndexedDB's cursor objects."); |
| 7 | |
dgrogan@chromium.org | 7c1a471 | 2012-11-12 18:06:32 +0000 | [diff] [blame] | 8 | indexedDBTest(prepareDatabase, openBasicCursor); |
| 9 | function prepareDatabase() |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 10 | { |
dgrogan@chromium.org | 7c1a471 | 2012-11-12 18:06:32 +0000 | [diff] [blame] | 11 | db = event.target.result; |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 12 | debug("setVersionSuccess():"); |
dgrogan@chromium.org | 7c1a471 | 2012-11-12 18:06:32 +0000 | [diff] [blame] | 13 | self.trans = evalAndLog("trans = event.target.transaction"); |
jsbell@chromium.org | 6b1c22e | 2012-05-19 23:36:46 +0000 | [diff] [blame] | 14 | shouldBeNonNull("trans"); |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 15 | trans.onabort = unexpectedAbortCallback; |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 16 | |
| 17 | var objectStore = evalAndLog("objectStore = db.createObjectStore('basicStore')"); |
| 18 | evalAndLog("objectStore.add('someValue1', 'someKey1').onerror = unexpectedErrorCallback"); |
| 19 | evalAndLog("objectStore.add('someValue2', 'someKey2').onerror = unexpectedErrorCallback"); |
| 20 | evalAndLog("objectStore.add('someValue3', 'someKey3').onerror = unexpectedErrorCallback"); |
| 21 | evalAndLog("objectStore.add('someValue4', 'someKey4').onerror = unexpectedErrorCallback"); |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | function openBasicCursor() |
| 25 | { |
| 26 | debug("openBasicCursor()"); |
commit-queue@webkit.org | 98b75ae | 2012-05-07 19:12:00 +0000 | [diff] [blame] | 27 | evalAndLog("trans = db.transaction(['basicStore'], 'readwrite')"); |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 28 | trans.onabort = unexpectedAbortCallback; |
| 29 | trans.oncomplete = transactionComplete; |
| 30 | |
| 31 | keyRange = IDBKeyRange.lowerBound("someKey1"); |
| 32 | self.objectStore = evalAndLog("trans.objectStore('basicStore')"); |
| 33 | request = evalAndLog("objectStore.openCursor(keyRange)"); |
| 34 | request.onsuccess = checkCursor; |
| 35 | request.onerror = unexpectedErrorCallback; |
| 36 | counter = 1; |
| 37 | } |
| 38 | |
| 39 | storedCursor = null; |
| 40 | function checkCursor() |
| 41 | { |
| 42 | debug("") |
| 43 | debug("checkCursor()"); |
| 44 | if (event.target.result == null) { |
| 45 | shouldBe("counter", "5"); |
| 46 | return; |
| 47 | } |
| 48 | if (storedCursor == null) |
| 49 | storedCursor = evalAndLog("storedCursor = event.target.result"); |
| 50 | |
jsbell@chromium.org | 6b1c22e | 2012-05-19 23:36:46 +0000 | [diff] [blame] | 51 | shouldBe("storedCursor", "event.target.result"); |
dgrogan@chromium.org | dfb73a2 | 2012-03-27 03:50:43 +0000 | [diff] [blame] | 52 | shouldBeEqualToString("storedCursor.key", "someKey" + counter); |
| 53 | shouldBeEqualToString("event.target.result.key", "someKey" + counter); |
| 54 | shouldBeEqualToString("storedCursor.value", "someValue" + counter); |
| 55 | shouldBeEqualToString("event.target.result.value", "someValue" + counter); |
| 56 | counter++; |
| 57 | evalAndLog("event.target.result.continue()"); |
| 58 | } |
| 59 | |
| 60 | function transactionComplete() |
| 61 | { |
| 62 | debug("transactionComplete()"); |
| 63 | finishJSTest(); |
dgrogan@chromium.org | 7c1a471 | 2012-11-12 18:06:32 +0000 | [diff] [blame] | 64 | } |