123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /**
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
- var testGenerator = testSteps();
- function testSteps()
- {
- const dataCount = 30;
- let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
- request.onerror = errorHandler;
- request.onupgradeneeded = grabEventAndContinueHandler;
- let event = yield undefined;
- let db = event.target.result;
- db.onerror = errorHandler;
- event.target.onsuccess = continueToNextStep;
- let objectStore = db.createObjectStore("", { keyPath: "key" });
- objectStore.createIndex("", "index");
- for (let i = 0; i < dataCount; i++) {
- objectStore.add({ key: i, index: i });
- }
- yield undefined;
- function getObjectStore() {
- return db.transaction("").objectStore("");
- }
- function getIndex() {
- return db.transaction("").objectStore("").index("");
- }
- let count = 0;
- getObjectStore().openCursor().onsuccess = function(event) {
- let cursor = event.target.result;
- if (cursor) {
- count++;
- cursor.continue();
- }
- else {
- continueToNextStep();
- }
- };
- yield undefined;
- is(count, dataCount, "Saw all data");
- count = 0;
- getObjectStore().openCursor().onsuccess = function(event) {
- let cursor = event.target.result;
- if (cursor) {
- is(cursor.primaryKey, count, "Got correct object");
- if (count) {
- count++;
- cursor.continue();
- }
- else {
- count = 10;
- cursor.advance(10);
- }
- }
- else {
- continueToNextStep();
- }
- };
- yield undefined;
- is(count, dataCount, "Saw all data");
- count = 0;
- getIndex().openCursor().onsuccess = function(event) {
- let cursor = event.target.result;
- if (cursor) {
- is(cursor.primaryKey, count, "Got correct object");
- if (count) {
- count++;
- cursor.continue();
- }
- else {
- count = 10;
- cursor.advance(10);
- }
- }
- else {
- continueToNextStep();
- }
- };
- yield undefined;
- is(count, dataCount, "Saw all data");
- count = 0;
- getIndex().openKeyCursor().onsuccess = function(event) {
- let cursor = event.target.result;
- if (cursor) {
- is(cursor.primaryKey, count, "Got correct object");
- if (count) {
- count++;
- cursor.continue();
- }
- else {
- count = 10;
- cursor.advance(10);
- }
- }
- else {
- continueToNextStep();
- }
- };
- yield undefined;
- is(count, dataCount, "Saw all data");
- count = 0;
- getObjectStore().openCursor().onsuccess = function(event) {
- let cursor = event.target.result;
- if (cursor) {
- is(cursor.primaryKey, count, "Got correct object");
- if (count == 0) {
- cursor.advance(dataCount + 1);
- }
- else {
- ok(false, "Should never get here!");
- cursor.continue();
- }
- }
- else {
- continueToNextStep();
- }
- };
- yield undefined;
- is(count, 0, "Saw all data");
- count = dataCount - 1;
- getObjectStore().openCursor(null, "prev").onsuccess = function(event) {
- let cursor = event.target.result;
- if (cursor) {
- is(cursor.primaryKey, count, "Got correct object");
- count--;
- if (count == dataCount - 2) {
- cursor.advance(10);
- count -= 9;
- }
- else {
- cursor.continue();
- }
- }
- else {
- continueToNextStep();
- }
- };
- yield undefined;
- is(count, -1, "Saw all data");
- count = dataCount - 1;
- getObjectStore().openCursor(null, "prev").onsuccess = function(event) {
- let cursor = event.target.result;
- if (cursor) {
- is(cursor.primaryKey, count, "Got correct object");
- if (count == dataCount - 1) {
- cursor.advance(dataCount + 1);
- }
- else {
- ok(false, "Should never get here!");
- cursor.continue();
- }
- }
- else {
- continueToNextStep();
- }
- };
- yield undefined;
- is(count, dataCount - 1, "Saw all data");
- finishTest();
- yield undefined;
- }
|