more WPTs

This commit is contained in:
Florian Dold 2021-02-16 16:45:15 +01:00
parent b814697fc9
commit f9df95ded5
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
7 changed files with 140 additions and 1 deletions

View File

@ -0,0 +1,63 @@
import test from "ava";
import { createdb, idbFactory } from "./wptsupport";
test("WPT idbfactory-cmp*.html", async (t) => {
const indexedDB = idbFactory;
var greater = indexedDB.cmp(2, 1);
var equal = indexedDB.cmp(2, 2);
var less = indexedDB.cmp(1, 2);
t.deepEqual(greater, 1, "greater");
t.deepEqual(equal, 0, "equal");
t.deepEqual(less, -1, "less");
t.throws(
() => {
// @ts-expect-error
indexedDB.cmp();
},
{ instanceOf: TypeError },
);
t.throws(
() => {
indexedDB.cmp(null, null);
},
{ name: "DataError" },
);
t.throws(
() => {
indexedDB.cmp(1, null);
},
{ name: "DataError" },
);
t.throws(
() => {
indexedDB.cmp(null, 1);
},
{ name: "DataError" },
);
t.throws(
() => {
indexedDB.cmp(NaN, NaN);
},
{ name: "DataError" },
);
t.throws(
() => {
indexedDB.cmp(1, NaN);
},
{ name: "DataError" },
);
t.throws(
() => {
indexedDB.cmp(NaN, 1);
},
{ name: "DataError" },
);
});

View File

@ -0,0 +1,76 @@
import test from "ava";
import { createdb, idbFactory } from "./wptsupport";
// IDBFactory.open() - request has no source
test("WPT idbfactory-open.htm", async (t) => {
await new Promise<void>((resolve, reject) => {
var open_rq = createdb(t, undefined, 9);
open_rq.onupgradeneeded = function (e) {};
open_rq.onsuccess = function (e: any) {
t.deepEqual(e.target.source, null, "source");
resolve();
};
});
t.pass();
});
// IDBFactory.open() - database 'name' and 'version' are correctly set
test("WPT idbfactory-open2.htm", async (t) => {
await new Promise<void>((resolve, reject) => {
var database_name = __filename + "-database_name";
var open_rq = createdb(t, database_name, 13);
open_rq.onupgradeneeded = function (e) {};
open_rq.onsuccess = function (e: any) {
var db = e.target.result;
t.deepEqual(db.name, database_name, "db.name");
t.deepEqual(db.version, 13, "db.version");
resolve;
};
});
t.pass();
});
// IDBFactory.open() - no version opens current database
test("WPT idbfactory-open3.htm", async (t) => {
const indexedDB = idbFactory;
await new Promise<void>((resolve, reject) => {
var open_rq = createdb(t, undefined, 13);
var did_upgrade = false;
open_rq.onupgradeneeded = function () {};
open_rq.onsuccess = function (e: any) {
var db = e.target.result;
db.close();
var open_rq2 = indexedDB.open(db.name);
open_rq2.onsuccess = function (e: any) {
t.deepEqual(e.target.result.version, 13, "db.version");
e.target.result.close();
resolve();
};
open_rq2.onupgradeneeded = () => t.fail("Unexpected upgradeneeded");
open_rq2.onerror = () => t.fail("Unexpected error");
};
});
t.pass();
});
// IDBFactory.open() - new database has default version
test("WPT idbfactory-open4.htm", async (t) => {
const indexedDB = idbFactory;
await new Promise<void>((resolve, reject) => {
var open_rq = createdb(t, __filename + '-database_name');
open_rq.onupgradeneeded = function(e: any) {
t.deepEqual(e.target.result.version, 1, "db.version");
};
open_rq.onsuccess = function(e: any) {
t.deepEqual(e.target.result.version, 1, "db.version");
resolve();
};
});
t.pass();
});

View File

@ -15,7 +15,7 @@ import { compareKeys } from "../util/cmp";
BridgeIDBFactory.enableTracing = true;
const backend = new MemoryBackend();
backend.enableTracing = true;
const idbFactory = new BridgeIDBFactory(backend);
export const idbFactory = new BridgeIDBFactory(backend);
const self = {
indexedDB: idbFactory,