michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: var testGenerator = testSteps(); michael@0: michael@0: function testSteps() michael@0: { michael@0: const dbname = this.window ? window.location.pathname : "Splendid Test"; michael@0: const RW = "readwrite" michael@0: let c1 = 1; michael@0: let c2 = 1; michael@0: michael@0: let openRequest = indexedDB.open(dbname, 1); michael@0: openRequest.onerror = errorHandler; michael@0: openRequest.onupgradeneeded = grabEventAndContinueHandler; michael@0: openRequest.onsuccess = unexpectedSuccessHandler; michael@0: let event = yield undefined; michael@0: let db = event.target.result; michael@0: let trans = event.target.transaction; michael@0: michael@0: // Create test stores michael@0: let store = db.createObjectStore("store"); michael@0: michael@0: // Test simple inserts michael@0: var keys = [ michael@0: -1/0, michael@0: -1.7e308, michael@0: -10000, michael@0: -2, michael@0: -1.5, michael@0: -1, michael@0: -1.00001e-200, michael@0: -1e-200, michael@0: 0, michael@0: 1e-200, michael@0: 1.00001e-200, michael@0: 1, michael@0: 2, michael@0: 10000, michael@0: 1.7e308, michael@0: 1/0, michael@0: new Date("1750-01-02"), michael@0: new Date("1800-12-31T12:34:56.001"), michael@0: new Date(-1000), michael@0: new Date(-10), michael@0: new Date(-1), michael@0: new Date(0), michael@0: new Date(1), michael@0: new Date(2), michael@0: new Date(1000), michael@0: new Date("1971-01-01"), michael@0: new Date("1971-01-01T01:01:01Z"), michael@0: new Date("1971-01-01T01:01:01.001Z"), michael@0: new Date("1971-01-01T01:01:01.01Z"), michael@0: new Date("1971-01-01T01:01:01.1Z"), michael@0: new Date("1980-02-02"), michael@0: new Date("3333-03-19T03:33:33.333"), michael@0: "", michael@0: "\x00", michael@0: "\x00\x00", michael@0: "\x00\x01", michael@0: "\x01", michael@0: "\x02", michael@0: "\x03", michael@0: "\x04", michael@0: "\x07", michael@0: "\x08", michael@0: "\x0F", michael@0: "\x10", michael@0: "\x1F", michael@0: "\x20", michael@0: "01234", michael@0: "\x3F", michael@0: "\x40", michael@0: "A", michael@0: "A\x00", michael@0: "A1", michael@0: "ZZZZ", michael@0: "a", michael@0: "a\x00", michael@0: "aa", michael@0: "azz", michael@0: "}", michael@0: "\x7E", michael@0: "\x7F", michael@0: "\x80", michael@0: "\xFF", michael@0: "\u0100", michael@0: "\u01FF", michael@0: "\u0200", michael@0: "\u03FF", michael@0: "\u0400", michael@0: "\u07FF", michael@0: "\u0800", michael@0: "\u0FFF", michael@0: "\u1000", michael@0: "\u1FFF", michael@0: "\u2000", michael@0: "\u3FFF", michael@0: "\u4000", michael@0: "\u7FFF", michael@0: "\u8000", michael@0: "\uD800", michael@0: "\uD800a", michael@0: "\uD800\uDC01", michael@0: "\uDBFF", michael@0: "\uDC00", michael@0: "\uDFFF\uD800", michael@0: "\uFFFE", michael@0: "\uFFFF", michael@0: "\uFFFF\x00", michael@0: "\uFFFFZZZ", michael@0: [], michael@0: [-1/0], michael@0: [-1], michael@0: [0], michael@0: [1], michael@0: [1, "a"], michael@0: [1, []], michael@0: [1, [""]], michael@0: [2, 3], michael@0: [2, 3.0000000000001], michael@0: [12, [[]]], michael@0: [12, [[[]]]], michael@0: [12, [[[""]]]], michael@0: [12, [[["foo"]]]], michael@0: [12, [[[[[3]]]]]], michael@0: [12, [[[[[[3]]]]]]], michael@0: [new Date(-1)], michael@0: [new Date(1)], michael@0: [""], michael@0: ["", [[]]], michael@0: ["", [[[]]]], michael@0: ["abc"], michael@0: ["abc", "def"], michael@0: ["abc\x00"], michael@0: ["abc\x00", "\x00\x01"], michael@0: ["abc\x00", "\x00def"], michael@0: ["abc\x00\x00def"], michael@0: ["x", [[]]], michael@0: ["x", [[[]]]], michael@0: [[]], michael@0: [[],"foo"], michael@0: [[],[]], michael@0: [[[]]], michael@0: [[[]], []], michael@0: [[[]], [[]]], michael@0: [[[]], [[1]]], michael@0: [[[]], [[[]]]], michael@0: [[[1]]], michael@0: [[[[]], []]], michael@0: ]; michael@0: michael@0: for (var i = 0; i < keys.length; ++i) { michael@0: let keyI = keys[i]; michael@0: is(indexedDB.cmp(keyI, keyI), 0, i + " compared to self"); michael@0: michael@0: function doCompare(keyI) { michael@0: for (var j = i-1; j >= i-10 && j >= 0; --j) { michael@0: is(indexedDB.cmp(keyI, keys[j]), 1, i + " compared to " + j); michael@0: is(indexedDB.cmp(keys[j], keyI), -1, j + " compared to " + i); michael@0: } michael@0: } michael@0: michael@0: doCompare(keyI); michael@0: store.add(i, keyI).onsuccess = function(e) { michael@0: is(indexedDB.cmp(e.target.result, keyI), 0, michael@0: "Returned key should cmp as equal"); michael@0: ok(compareKeys(e.target.result, keyI), michael@0: "Returned key should actually be equal"); michael@0: }; michael@0: michael@0: // Test that -0 compares the same as 0 michael@0: if (keyI === 0) { michael@0: doCompare(-0); michael@0: let req = store.add(i, -0); michael@0: req.addEventListener("error", new ExpectError("ConstraintError", true)); michael@0: req.onsuccess = unexpectedSuccessHandler; michael@0: yield undefined; michael@0: } michael@0: else if (Array.isArray(keyI) && keyI.length === 1 && keyI[0] === 0) { michael@0: doCompare([-0]); michael@0: let req = store.add(i, [-0]); michael@0: req.addEventListener("error", new ExpectError("ConstraintError", true)); michael@0: req.onsuccess = unexpectedSuccessHandler; michael@0: yield undefined; michael@0: } michael@0: } michael@0: michael@0: store.openCursor().onsuccess = grabEventAndContinueHandler; michael@0: for (i = 0; i < keys.length; ++i) { michael@0: event = yield undefined; michael@0: let cursor = event.target.result; michael@0: is(indexedDB.cmp(cursor.key, keys[i]), 0, michael@0: "Read back key should cmp as equal"); michael@0: ok(compareKeys(cursor.key, keys[i]), michael@0: "Read back key should actually be equal"); michael@0: is(cursor.value, i, "Stored with right value"); michael@0: michael@0: cursor.continue(); michael@0: } michael@0: event = yield undefined; michael@0: is(event.target.result, undefined, "no more results expected"); michael@0: michael@0: var nan = 0/0; michael@0: var invalidKeys = [ michael@0: nan, michael@0: undefined, michael@0: null, michael@0: /x/, michael@0: {}, michael@0: new Date(NaN), michael@0: new Date("foopy"), michael@0: [nan], michael@0: [undefined], michael@0: [null], michael@0: [/x/], michael@0: [{}], michael@0: [new Date(NaN)], michael@0: [1, nan], michael@0: [1, undefined], michael@0: [1, null], michael@0: [1, /x/], michael@0: [1, {}], michael@0: [1, [nan]], michael@0: [1, [undefined]], michael@0: [1, [null]], michael@0: [1, [/x/]], michael@0: [1, [{}]], michael@0: ]; michael@0: michael@0: for (i = 0; i < invalidKeys.length; ++i) { michael@0: try { michael@0: indexedDB.cmp(invalidKeys[i], 1); michael@0: ok(false, "didn't throw"); michael@0: } michael@0: catch(ex) { michael@0: ok(ex instanceof DOMException, "Threw DOMException"); michael@0: is(ex.name, "DataError", "Threw right DOMException"); michael@0: is(ex.code, 0, "Threw with right code"); michael@0: } michael@0: try { michael@0: indexedDB.cmp(1, invalidKeys[i]); michael@0: ok(false, "didn't throw2"); michael@0: } michael@0: catch(ex) { michael@0: ok(ex instanceof DOMException, "Threw DOMException2"); michael@0: is(ex.name, "DataError", "Threw right DOMException2"); michael@0: is(ex.code, 0, "Threw with right code2"); michael@0: } michael@0: try { michael@0: store.put(1, invalidKeys[i]); michael@0: ok(false, "didn't throw3"); michael@0: } michael@0: catch(ex) { michael@0: ok(ex instanceof DOMException, "Threw DOMException3"); michael@0: is(ex.name, "DataError", "Threw right DOMException3"); michael@0: is(ex.code, 0, "Threw with right code3"); michael@0: } michael@0: } michael@0: michael@0: openRequest.onsuccess = grabEventAndContinueHandler; michael@0: yield undefined; michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }