123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- /**
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
- var testGenerator = testSteps();
- function testSteps()
- {
- const testName = "schema18upgrade";
- const testKeys = [
- -1/0,
- -1.7e308,
- -10000,
- -2,
- -1.5,
- -1,
- -1.00001e-200,
- -1e-200,
- 0,
- 1e-200,
- 1.00001e-200,
- 1,
- 2,
- 10000,
- 1.7e308,
- 1/0,
- new Date("1750-01-02"),
- new Date("1800-12-31T12:34:56.001Z"),
- new Date(-1000),
- new Date(-10),
- new Date(-1),
- new Date(0),
- new Date(1),
- new Date(2),
- new Date(1000),
- new Date("1971-01-01"),
- new Date("1971-01-01T01:01:01Z"),
- new Date("1971-01-01T01:01:01.001Z"),
- new Date("1971-01-01T01:01:01.01Z"),
- new Date("1971-01-01T01:01:01.1Z"),
- new Date("1980-02-02"),
- new Date("3333-03-19T03:33:33.333Z"),
- "",
- "\x00",
- "\x00\x00",
- "\x00\x01",
- "\x01",
- "\x02",
- "\x03",
- "\x04",
- "\x07",
- "\x08",
- "\x0F",
- "\x10",
- "\x1F",
- "\x20",
- "01234",
- "\x3F",
- "\x40",
- "A",
- "A\x00",
- "A1",
- "ZZZZ",
- "a",
- "a\x00",
- "aa",
- "azz",
- "}",
- "\x7E",
- "\x7F",
- "\x80",
- "\xFF",
- "\u0100",
- "\u01FF",
- "\u0200",
- "\u03FF",
- "\u0400",
- "\u07FF",
- "\u0800",
- "\u0FFF",
- "\u1000",
- "\u1FFF",
- "\u2000",
- "\u3FFF",
- "\u4000",
- "\u7FFF",
- "\u8000",
- "\uD800",
- "\uD800a",
- "\uD800\uDC01",
- "\uDBFF",
- "\uDC00",
- "\uDFFF\uD800",
- "\uFFFE",
- "\uFFFF",
- "\uFFFF\x00",
- "\uFFFFZZZ",
- [],
- [-1/0],
- [-1],
- [0],
- [1],
- [1, "a"],
- [1, []],
- [1, [""]],
- [2, 3],
- [2, 3.0000000000001],
- [12, [[]]],
- [12, [[[]]]],
- [12, [[[""]]]],
- [12, [[["foo"]]]],
- [12, [[[[[3]]]]]],
- [12, [[[[[[3]]]]]]],
- [12, [[[[[[3],[[[[[4.2]]]]]]]]]]],
- [new Date(-1)],
- [new Date(1)],
- [""],
- ["", [[]]],
- ["", [[[]]]],
- ["abc"],
- ["abc", "def"],
- ["abc\x00"],
- ["abc\x00", "\x00\x01"],
- ["abc\x00", "\x00def"],
- ["abc\x00\x00def"],
- ["x", [[]]],
- ["x", [[[]]]],
- [[]],
- [[],"foo"],
- [[],[]],
- [[[]]],
- [[[]], []],
- [[[]], [[]]],
- [[[]], [[1]]],
- [[[]], [[[]]]],
- [[[1]]],
- [[[[]], []]],
- ];
- const testString =
- "abcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-_+=,<.>/?\\|";
- clearAllDatabases(continueToNextStepSync);
- yield undefined;
- info("Installing profile");
- installPackagedProfile(testName + "_profile");
- info("Opening database with no version");
- let request = indexedDB.open(testName);
- request.onerror = errorHandler;
- request.onupgradeneeded = unexpectedSuccessHandler;
- request.onsuccess = grabEventAndContinueHandler;
- let event = yield undefined;
- let db = event.target.result;
- is(db.version, 1, "Correct db version");
- let transaction = db.transaction(testName);
- transaction.oncomplete = grabEventAndContinueHandler;
- let objectStore = transaction.objectStore(testName);
- let index = objectStore.index("uniqueIndex");
- info("Starting 'uniqueIndex' cursor");
- let keyIndex = 0;
- index.openCursor().onsuccess = event => {
- let cursor = event.target.result;
- if (cursor) {
- info("Comparing " + JSON.stringify(cursor.primaryKey) + " to " +
- JSON.stringify(testKeys[cursor.key]) +
- " [" + cursor.key + "]");
- is(indexedDB.cmp(cursor.primaryKey, testKeys[cursor.key]), 0,
- "Keys compare equally via 'indexedDB.cmp'");
- is(compareKeys(cursor.primaryKey, testKeys[cursor.key]), true,
- "Keys compare equally via 'compareKeys'");
- let indexProperty = cursor.value.index;
- is(Array.isArray(indexProperty), true, "index property is Array");
- is(indexProperty[0], cursor.key, "index property first item correct");
- is(indexProperty[1], cursor.key + 1, "index property second item correct");
- is(cursor.key, keyIndex, "Cursor key property is correct");
- is(cursor.value.testString, testString, "Test string compared equally");
- keyIndex++;
- cursor.continue();
- }
- };
- yield undefined;
- is(keyIndex, testKeys.length, "Saw all keys");
- transaction = db.transaction(testName, "readwrite");
- transaction.oncomplete = grabEventAndContinueHandler;
- objectStore = transaction.objectStore(testName);
- index = objectStore.index("index");
- info("Getting all 'index' keys");
- index.getAllKeys().onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result.length, testKeys.length * 2, "Got all keys");
- info("Starting objectStore cursor");
- objectStore.openCursor().onsuccess = event => {
- let cursor = event.target.result;
- if (cursor) {
- let value = cursor.value;
- is(value.testString, testString, "Test string compared equally");
- delete value.index;
- cursor.update(value);
- cursor.continue();
- } else {
- continueToNextStepSync();
- }
- };
- yield undefined;
- info("Getting all 'index' keys");
- index.getAllKeys().onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.target.result.length, 0, "Removed all keys");
- yield undefined;
- db.close();
- info("Opening database with new version");
- request = indexedDB.open(testName, 2);
- request.onerror = errorHandler;
- request.onupgradeneeded = grabEventAndContinueHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- info("Deleting indexes");
- objectStore = event.target.transaction.objectStore(testName);
- objectStore.deleteIndex("index");
- objectStore.deleteIndex("uniqueIndex");
- event = yield undefined;
- db = event.target.result;
- transaction = db.transaction(testName, "readwrite");
- transaction.oncomplete = grabEventAndContinueHandler;
- info("Starting objectStore cursor");
- objectStore = transaction.objectStore(testName);
- objectStore.openCursor().onsuccess = event => {
- let cursor = event.target.result;
- if (cursor) {
- let value = cursor.value;
- is(value.testString, testString, "Test string compared equally");
- value.index = value.keyPath;
- cursor.update(value);
- cursor.continue();
- }
- };
- event = yield undefined;
- db.close();
- info("Opening database with new version");
- request = indexedDB.open(testName, 3);
- request.onerror = errorHandler;
- request.onupgradeneeded = grabEventAndContinueHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- info("Creating indexes");
- objectStore = event.target.transaction.objectStore(testName);
- objectStore.createIndex("index", "index");
- event = yield undefined;
- db = event.target.result;
- transaction = db.transaction(testName);
- transaction.oncomplete = grabEventAndContinueHandler;
- objectStore = transaction.objectStore(testName);
- index = objectStore.index("index");
- info("Starting 'index' cursor");
- keyIndex = 0;
- index.openCursor().onsuccess = event => {
- let cursor = event.target.result;
- if (cursor) {
- is(indexedDB.cmp(cursor.primaryKey, testKeys[keyIndex]), 0,
- "Keys compare equally via 'indexedDB.cmp'");
- is(compareKeys(cursor.primaryKey, testKeys[keyIndex]), true,
- "Keys compare equally via 'compareKeys'");
- is(indexedDB.cmp(cursor.key, testKeys[keyIndex]), 0,
- "Keys compare equally via 'indexedDB.cmp'");
- is(compareKeys(cursor.key, testKeys[keyIndex]), true,
- "Keys compare equally via 'compareKeys'");
- let indexProperty = cursor.value.index;
- is(indexedDB.cmp(indexProperty, testKeys[keyIndex]), 0,
- "Keys compare equally via 'indexedDB.cmp'");
- is(compareKeys(indexProperty, testKeys[keyIndex]), true,
- "Keys compare equally via 'compareKeys'");
- is(cursor.value.testString, testString, "Test string compared equally");
- keyIndex++;
- cursor.continue();
- }
- };
- yield undefined;
- is(keyIndex, testKeys.length, "Added all keys again");
- finishTest();
- yield undefined;
- }
|