| OLD | NEW |
| 1 if (this.importScripts) { | 1 if (this.importScripts) { |
| 2 importScripts('../../../resources/js-test.js'); | 2 importScripts('../../../resources/js-test.js'); |
| 3 importScripts('shared.js'); | 3 importScripts('shared.js'); |
| 4 } | 4 } |
| 5 | 5 |
| 6 description("Test IndexedDB keyPath with intrinsic properties"); | 6 description("Test IndexedDB keyPath with intrinsic properties"); |
| 7 | 7 |
| 8 indexedDBTest(prepareDatabase, testKeyPaths); | 8 indexedDBTest(prepareDatabase, testKeyPaths); |
| 9 function prepareDatabase() | 9 function prepareDatabase() |
| 10 { | 10 { |
| 11 db = event.target.result; | 11 db = event.target.result; |
| 12 event.target.transaction.onabort = unexpectedAbortCallback; | 12 event.target.transaction.onabort = unexpectedAbortCallback; |
| 13 evalAndLog("store = db.createObjectStore('store', {keyPath: 'id'})"); | 13 evalAndLog("store = db.createObjectStore('store', {keyPath: 'id'})"); |
| 14 evalAndLog("store.createIndex('string length', 'string.length')"); | 14 evalAndLog("store.createIndex('string length', 'string.length')"); |
| 15 evalAndLog("store.createIndex('array length', 'array.length')"); | 15 evalAndLog("store.createIndex('array length', 'array.length')"); |
| 16 evalAndLog("store.createIndex('blob size', 'blob.size')"); |
| 17 evalAndLog("store.createIndex('blob type', 'blob.type')"); |
| 16 } | 18 } |
| 17 | 19 |
| 18 function testKeyPaths() | 20 function testKeyPaths() |
| 19 { | 21 { |
| 20 debug(""); | 22 preamble(); |
| 21 debug("testKeyPaths():"); | |
| 22 | 23 |
| 23 transaction = evalAndLog("transaction = db.transaction('store', 'readwrite')
"); | 24 transaction = evalAndLog("transaction = db.transaction('store', 'readwrite')
"); |
| 24 transaction.onabort = unexpectedAbortCallback; | 25 transaction.onabort = unexpectedAbortCallback; |
| 25 store = evalAndLog("store = transaction.objectStore('store')"); | 26 store = evalAndLog("store = transaction.objectStore('store')"); |
| 26 | 27 |
| 27 for (var i = 0; i < 5; i += 1) { | 28 for (var i = 0; i < 5; i += 1) { |
| 28 var datum = { | 29 var datum = { |
| 29 id: 'id#' + i, | 30 id: 'id#' + i, |
| 30 string: Array(i * 2 + 1).join('x'), | 31 string: Array(i * 2 + 1).join('x'), |
| 31 array: Array(i * 3 + 1).join('x').split(/(?:)/) | 32 array: Array(i * 3 + 1).join('x').split(/(?:)/), |
| 33 blob: new Blob([Array(i * 4 + 1).join('x')], {type: "type " + i}) |
| 32 }; | 34 }; |
| 33 evalAndLog("store.put("+JSON.stringify(datum)+")"); | 35 debug("store.put(" + JSON.stringify(datum) + ")"); |
| 36 store.put(datum); |
| 34 } | 37 } |
| 35 | 38 |
| 36 checkStringLengths(); | 39 checkStringLengths(); |
| 37 | 40 |
| 38 function checkStringLengths() { | 41 function checkStringLengths() { |
| 39 evalAndLog("request = store.index('string length').openCursor()"); | 42 evalAndLog("request = store.index('string length').openCursor()"); |
| 40 request.onerror = unexpectedErrorCallback; | 43 request.onerror = unexpectedErrorCallback; |
| 41 request.onsuccess = function (e) { | 44 request.onsuccess = function (e) { |
| 42 cursor = e.target.result; | 45 cursor = e.target.result; |
| 43 if (cursor) { | 46 if (cursor) { |
| 44 shouldBe("cursor.key", "cursor.value.string.length"); | 47 shouldBe("cursor.key", "cursor.value.string.length"); |
| 45 cursor.continue(); | 48 cursor.continue(); |
| 46 } else { | 49 } else { |
| 47 checkArrayLengths(); | 50 checkArrayLengths(); |
| 48 } | 51 } |
| 49 } | 52 } |
| 50 } | 53 } |
| 51 | 54 |
| 52 function checkArrayLengths() { | 55 function checkArrayLengths() { |
| 53 evalAndLog("request = store.index('array length').openCursor()"); | 56 evalAndLog("request = store.index('array length').openCursor()"); |
| 54 request.onerror = unexpectedErrorCallback; | 57 request.onerror = unexpectedErrorCallback; |
| 55 request.onsuccess = function (e) { | 58 request.onsuccess = function (e) { |
| 56 cursor = e.target.result; | 59 cursor = e.target.result; |
| 57 if (cursor) { | 60 if (cursor) { |
| 58 shouldBe("cursor.key", "cursor.value.array.length"); | 61 shouldBe("cursor.key", "cursor.value.array.length"); |
| 59 cursor.continue(); | 62 cursor.continue(); |
| 63 } else { |
| 64 checkBlobSizes(); |
| 65 } |
| 66 } |
| 67 } |
| 68 |
| 69 function checkBlobSizes() { |
| 70 evalAndLog("request = store.index('blob size').openCursor()"); |
| 71 request.onerror = unexpectedErrorCallback; |
| 72 request.onsuccess = function (e) { |
| 73 cursor = e.target.result; |
| 74 if (cursor) { |
| 75 shouldBe("cursor.key", "cursor.value.blob.size"); |
| 76 cursor.continue(); |
| 77 } else { |
| 78 checkBlobTypes(); |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 function checkBlobTypes() { |
| 84 evalAndLog("request = store.index('blob type').openCursor()"); |
| 85 request.onerror = unexpectedErrorCallback; |
| 86 request.onsuccess = function (e) { |
| 87 cursor = e.target.result; |
| 88 if (cursor) { |
| 89 shouldBe("cursor.key", "cursor.value.blob.type"); |
| 90 cursor.continue(); |
| 60 } | 91 } |
| 61 } | 92 } |
| 62 } | 93 } |
| 63 | 94 |
| 64 transaction.oncomplete = finishJSTest; | 95 transaction.oncomplete = finishJSTest; |
| 65 } | 96 } |
| OLD | NEW |