idb: fix test
This commit is contained in:
parent
f0d820d8c6
commit
9b9df089cf
@ -936,10 +936,6 @@ export class BridgeIDBFactory {
|
|||||||
|
|
||||||
await transaction._waitDone();
|
await transaction._waitDone();
|
||||||
|
|
||||||
// We don't explicitly exit the versionchange transaction,
|
|
||||||
// since this is already done by the BridgeIDBTransaction.
|
|
||||||
db._upgradeTransaction = null;
|
|
||||||
|
|
||||||
// We re-use the same transaction (as per spec) here.
|
// We re-use the same transaction (as per spec) here.
|
||||||
transaction._active = true;
|
transaction._active = true;
|
||||||
|
|
||||||
@ -2425,6 +2421,11 @@ export class BridgeIDBTransaction
|
|||||||
if (this._backendTransaction) {
|
if (this._backendTransaction) {
|
||||||
await this._backend.commit(this._backendTransaction);
|
await this._backend.commit(this._backendTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We must exit the upgrade transaction here, so that the "complete"
|
||||||
|
// event handler can already do other transactions.
|
||||||
|
this._db._upgradeTransaction = null;
|
||||||
|
|
||||||
this._committed = true;
|
this._committed = true;
|
||||||
if (!this._error) {
|
if (!this._error) {
|
||||||
if (BridgeIDBFactory.enableTracing) {
|
if (BridgeIDBFactory.enableTracing) {
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import test from "ava";
|
import test from "ava";
|
||||||
import { BridgeIDBCursor } from "..";
|
import { BridgeIDBCursor, BridgeIDBKeyRange } from "..";
|
||||||
import { BridgeIDBCursorWithValue } from "../bridge-idb";
|
import { BridgeIDBCursorWithValue } from "../bridge-idb";
|
||||||
|
import { IDBRequest } from "../idbtypes";
|
||||||
import { createdb } from "./wptsupport";
|
import { createdb } from "./wptsupport";
|
||||||
|
|
||||||
// Validate the overloads of IDBObjectStore.openCursor(), IDBIndex.openCursor() and IDBIndex.openKeyCursor()
|
const IDBKeyRange = BridgeIDBKeyRange;
|
||||||
|
|
||||||
|
// Validate the overloads of IDBObjectStore.openCursor(),
|
||||||
|
// IDBIndex.openCursor() and IDBIndex.openKeyCursor()
|
||||||
test.cb("WPT test cursor-overloads.htm", (t) => {
|
test.cb("WPT test cursor-overloads.htm", (t) => {
|
||||||
var db: any, trans: any, store: any, index: any;
|
var db: any, store: any, index: any;
|
||||||
|
|
||||||
var request = createdb(t);
|
var request = createdb(t);
|
||||||
request.onupgradeneeded = function (e) {
|
request.onupgradeneeded = function (e) {
|
||||||
@ -13,102 +17,107 @@ test.cb("WPT test cursor-overloads.htm", (t) => {
|
|||||||
store = db.createObjectStore("store");
|
store = db.createObjectStore("store");
|
||||||
index = store.createIndex("index", "value");
|
index = store.createIndex("index", "value");
|
||||||
store.put({ value: 0 }, 0);
|
store.put({ value: 0 }, 0);
|
||||||
trans = request.transaction;
|
const trans = request.transaction!;
|
||||||
trans.oncomplete = verifyOverloads;
|
trans.oncomplete = verifyOverloads;
|
||||||
};
|
};
|
||||||
|
|
||||||
function verifyOverloads() {
|
async function verifyOverloads() {
|
||||||
trans = db.transaction("store");
|
const trans = db.transaction("store");
|
||||||
store = trans.objectStore("store");
|
store = trans.objectStore("store");
|
||||||
index = store.index("index");
|
index = store.index("index");
|
||||||
|
|
||||||
checkCursorDirection("store.openCursor()", "next");
|
await checkCursorDirection(store.openCursor(), "next");
|
||||||
checkCursorDirection("store.openCursor(0)", "next");
|
await checkCursorDirection(store.openCursor(0), "next");
|
||||||
checkCursorDirection("store.openCursor(0, 'next')", "next");
|
await checkCursorDirection(store.openCursor(0, 'next'), "next");
|
||||||
checkCursorDirection("store.openCursor(0, 'nextunique')", "nextunique");
|
await checkCursorDirection(store.openCursor(0, 'nextunique'), "nextunique");
|
||||||
checkCursorDirection("store.openCursor(0, 'prev')", "prev");
|
await checkCursorDirection(store.openCursor(0, 'prev'), "prev");
|
||||||
checkCursorDirection("store.openCursor(0, 'prevunique')", "prevunique");
|
await checkCursorDirection(store.openCursor(0, 'prevunique'), "prevunique");
|
||||||
|
|
||||||
checkCursorDirection("store.openCursor(IDBKeyRange.only(0))", "next");
|
await checkCursorDirection(store.openCursor(IDBKeyRange.only(0)), "next");
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"store.openCursor(IDBKeyRange.only(0), 'next')",
|
store.openCursor(BridgeIDBKeyRange.only(0), 'next'),
|
||||||
"next",
|
"next",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"store.openCursor(IDBKeyRange.only(0), 'nextunique')",
|
store.openCursor(IDBKeyRange.only(0), 'nextunique'),
|
||||||
"nextunique",
|
"nextunique",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"store.openCursor(IDBKeyRange.only(0), 'prev')",
|
store.openCursor(IDBKeyRange.only(0), 'prev'),
|
||||||
"prev",
|
"prev",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"store.openCursor(IDBKeyRange.only(0), 'prevunique')",
|
store.openCursor(IDBKeyRange.only(0), 'prevunique'),
|
||||||
"prevunique",
|
"prevunique",
|
||||||
);
|
);
|
||||||
|
|
||||||
checkCursorDirection("index.openCursor()", "next");
|
await checkCursorDirection(index.openCursor(), "next");
|
||||||
checkCursorDirection("index.openCursor(0)", "next");
|
await checkCursorDirection(index.openCursor(0), "next");
|
||||||
checkCursorDirection("index.openCursor(0, 'next')", "next");
|
await checkCursorDirection(index.openCursor(0, 'next'), "next");
|
||||||
checkCursorDirection("index.openCursor(0, 'nextunique')", "nextunique");
|
await checkCursorDirection(index.openCursor(0, 'nextunique'), "nextunique");
|
||||||
checkCursorDirection("index.openCursor(0, 'prev')", "prev");
|
await checkCursorDirection(index.openCursor(0, 'prev'), "prev");
|
||||||
checkCursorDirection("index.openCursor(0, 'prevunique')", "prevunique");
|
await checkCursorDirection(index.openCursor(0, 'prevunique'), "prevunique");
|
||||||
|
|
||||||
checkCursorDirection("index.openCursor(IDBKeyRange.only(0))", "next");
|
await checkCursorDirection(index.openCursor(IDBKeyRange.only(0)), "next");
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openCursor(IDBKeyRange.only(0), 'next')",
|
index.openCursor(IDBKeyRange.only(0), 'next'),
|
||||||
"next",
|
"next",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openCursor(IDBKeyRange.only(0), 'nextunique')",
|
index.openCursor(IDBKeyRange.only(0), 'nextunique'),
|
||||||
"nextunique",
|
"nextunique",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openCursor(IDBKeyRange.only(0), 'prev')",
|
index.openCursor(IDBKeyRange.only(0), 'prev'),
|
||||||
"prev",
|
"prev",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openCursor(IDBKeyRange.only(0), 'prevunique')",
|
index.openCursor(IDBKeyRange.only(0), 'prevunique'),
|
||||||
"prevunique",
|
"prevunique",
|
||||||
);
|
);
|
||||||
|
|
||||||
checkCursorDirection("index.openKeyCursor()", "next");
|
await checkCursorDirection(index.openKeyCursor(), "next");
|
||||||
checkCursorDirection("index.openKeyCursor(0)", "next");
|
await checkCursorDirection(index.openKeyCursor(0), "next");
|
||||||
checkCursorDirection("index.openKeyCursor(0, 'next')", "next");
|
await checkCursorDirection(index.openKeyCursor(0, 'next'), "next");
|
||||||
checkCursorDirection("index.openKeyCursor(0, 'nextunique')", "nextunique");
|
await checkCursorDirection(index.openKeyCursor(0, 'nextunique'), "nextunique");
|
||||||
checkCursorDirection("index.openKeyCursor(0, 'prev')", "prev");
|
await checkCursorDirection(index.openKeyCursor(0, 'prev'), "prev");
|
||||||
checkCursorDirection("index.openKeyCursor(0, 'prevunique')", "prevunique");
|
await checkCursorDirection(index.openKeyCursor(0, 'prevunique'), "prevunique");
|
||||||
|
|
||||||
checkCursorDirection("index.openKeyCursor(IDBKeyRange.only(0))", "next");
|
await checkCursorDirection(index.openKeyCursor(IDBKeyRange.only(0)), "next");
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openKeyCursor(IDBKeyRange.only(0), 'next')",
|
index.openKeyCursor(IDBKeyRange.only(0), 'next'),
|
||||||
"next",
|
"next",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openKeyCursor(IDBKeyRange.only(0), 'nextunique')",
|
index.openKeyCursor(IDBKeyRange.only(0), 'nextunique'),
|
||||||
"nextunique",
|
"nextunique",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openKeyCursor(IDBKeyRange.only(0), 'prev')",
|
index.openKeyCursor(IDBKeyRange.only(0), 'prev'),
|
||||||
"prev",
|
"prev",
|
||||||
);
|
);
|
||||||
checkCursorDirection(
|
await checkCursorDirection(
|
||||||
"index.openKeyCursor(IDBKeyRange.only(0), 'prevunique')",
|
index.openKeyCursor(IDBKeyRange.only(0), 'prevunique'),
|
||||||
"prevunique",
|
"prevunique",
|
||||||
);
|
);
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCursorDirection(statement: string, direction: string) {
|
function checkCursorDirection(
|
||||||
request = eval(statement);
|
request: IDBRequest,
|
||||||
request.onsuccess = function (event: any) {
|
direction: string,
|
||||||
t.notDeepEqual(event.target.result, null, "Check the result is not null");
|
): Promise<void> {
|
||||||
t.deepEqual(
|
return new Promise<void>((resolve, reject) => {
|
||||||
event.target.result.direction,
|
request.onsuccess = function (event: any) {
|
||||||
direction,
|
t.notDeepEqual(event.target.result, null, "Check the result is not null");
|
||||||
"Check the result direction",
|
t.deepEqual(
|
||||||
);
|
event.target.result.direction,
|
||||||
};
|
direction,
|
||||||
|
"Check the result direction",
|
||||||
|
);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user