| OLD | NEW |
| (Empty) |
| 1 if (this.importScripts) { | |
| 2 importScripts('../../../fast/js/resources/js-test-pre.js'); | |
| 3 importScripts('shared.js'); | |
| 4 } | |
| 5 | |
| 6 description("Test IndexedDB binary keys"); | |
| 7 | |
| 8 indexedDBTest(prepareDatabase, testValidBinaryKeys); | |
| 9 function prepareDatabase() | |
| 10 { | |
| 11 db = event.target.result; | |
| 12 event.target.transaction.onabort = unexpectedAbortCallback; | |
| 13 objectStore = evalAndLog("db.createObjectStore('store');"); | |
| 14 debug(""); | |
| 15 } | |
| 16 | |
| 17 function testValidBinaryKeys() | |
| 18 { | |
| 19 preamble(); | |
| 20 evalAndLog("trans = db.transaction('store', 'readwrite')"); | |
| 21 evalAndLog("store = trans.objectStore('store')"); | |
| 22 | |
| 23 var n = 0, cases = [ | |
| 24 "[]", | |
| 25 "[0]", | |
| 26 "[0, 0]", | |
| 27 "[0, 1]", | |
| 28 "[1]", | |
| 29 "[1, 0]", | |
| 30 "[1, 1]", | |
| 31 "[255]", | |
| 32 ]; | |
| 33 | |
| 34 (function testCase() { | |
| 35 if (!cases.length) | |
| 36 return; | |
| 37 | |
| 38 key = cases.shift(); | |
| 39 value = n++; | |
| 40 | |
| 41 debug(""); | |
| 42 request = evalAndLog("store.put(" + JSON.stringify(value) + ", new Uint8
Array(" + key + "));"); | |
| 43 request.onerror = unexpectedErrorCallback; | |
| 44 request.onsuccess = function() { | |
| 45 shouldBeEqualToString("request.result.toString()", "[object Uint8Arr
ay]"); | |
| 46 shouldBe("[].slice.call(request.result).toString()", key + ".toStrin
g()"); | |
| 47 | |
| 48 request = evalAndLog("store.get(new Uint8Array(" + key + "));"); | |
| 49 request.onerror = unexpectedErrorCallback; | |
| 50 request.onsuccess = function() { | |
| 51 shouldBe("request.result", JSON.stringify(value)); | |
| 52 testCase(); | |
| 53 }; | |
| 54 }; | |
| 55 }()); | |
| 56 | |
| 57 trans.oncomplete = testInvalidBinaryKeys; | |
| 58 } | |
| 59 | |
| 60 function testInvalidBinaryKeys() | |
| 61 { | |
| 62 preamble(); | |
| 63 evalAndLog("trans = db.transaction('store', 'readwrite')"); | |
| 64 evalAndLog("store = trans.objectStore('store')"); | |
| 65 | |
| 66 var cases = [ | |
| 67 "new Uint8ClampedArray([1,2,3])", | |
| 68 "new Uint16Array([1,2,3])", | |
| 69 "new Uint32Array([1,2,3])", | |
| 70 "new Int8Array([1,2,3])", | |
| 71 "new Int16Array([1,2,3])", | |
| 72 "new Int32Array([1,2,3])", | |
| 73 "new Float32Array([1,2,3])", | |
| 74 "new Float64Array([1,2,3])", | |
| 75 "new Uint8Array([1,2,3]).buffer", | |
| 76 "new DataView(new Uint8Array([1,2,3]).buffer)" | |
| 77 ]; | |
| 78 | |
| 79 cases.forEach(function(testCase) { | |
| 80 debug(""); | |
| 81 evalAndExpectException("store.put('value', " + testCase + ")", "0", "'Da
taError'"); | |
| 82 }); | |
| 83 | |
| 84 finishJSTest(); | |
| 85 } | |
| OLD | NEW |