Best JavaScript code snippet using wpt
idbobjectstore-add-put-exception-order.test.ts
Source:idbobjectstore-add-put-exception-order.test.ts
...3import { BridgeIDBRequest } from "../bridge-idb";4import { InvalidStateError } from "../util/errors";5import { createdb, indexeddb_test } from "./wptsupport";6async function t1(t: ExecutionContext, method: string): Promise<void> {7 await indexeddb_test(8 t,9 (done, db) => {10 const store = db.createObjectStore("s");11 const store2 = db.createObjectStore("s2");12 db.deleteObjectStore("s2");13 setTimeout(() => {14 t.throws(15 () => {16 (store2 as any)[method]("key", "value");17 },18 { name: "InvalidStateError" },19 '"has been deleted" check (InvalidStateError) should precede ' +20 '"not active" check (TransactionInactiveError)',21 );22 done();23 }, 0);24 },25 (done, db) => {},26 "t1",27 );28}29/**30 * IDBObjectStore.${method} exception order: 'TransactionInactiveError vs. ReadOnlyError'31 */32async function t2(t: ExecutionContext, method: string): Promise<void> {33 await indexeddb_test(34 t,35 (done, db) => {36 const store = db.createObjectStore("s");37 },38 (done, db) => {39 const tx = db.transaction("s", "readonly");40 const store = tx.objectStore("s");41 setTimeout(() => {42 t.throws(43 () => {44 console.log(`calling ${method}`);45 (store as any)[method]("key", "value");46 },47 {48 name: "TransactionInactiveError",49 },50 '"not active" check (TransactionInactiveError) should precede ' +51 '"read only" check (ReadOnlyError)',52 );53 done();54 }, 0);55 console.log(`queued task for ${method}`);56 },57 "t2",58 );59}60/**61 * IDBObjectStore.${method} exception order: 'ReadOnlyError vs. DataError'62 */63async function t3(t: ExecutionContext, method: string): Promise<void> {64 await indexeddb_test(65 t,66 (done, db) => {67 const store = db.createObjectStore("s");68 },69 (done, db) => {70 const tx = db.transaction("s", "readonly");71 const store = tx.objectStore("s");72 t.throws(73 () => {74 (store as any)[method]({}, "value");75 },76 { name: "ReadOnlyError" },77 '"read only" check (ReadOnlyError) should precede ' +78 "key/data check (DataError)",...
indexedDB.js
Source:indexedDB.js
1/**2 * Created by gaopengfei on 2015/9/2.3 */4var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;5if (indexedDB)6 alert("æ¯æindexedDB");7else8 alert("ä¸æ¯æindexedDB");9$(function () {10 $('#connect').click(function () {11 connectDB();12 });13 $('#update').click(function () {14 versionUpdate();15 });16 $('#createObjectStore').click(function () {17 createObjectStore();18 });19});20/**21 * è¿æ¥æ°æ®åº22 */23function connectDB() {24 var dbName = 'indexedDB_test';25 var dbVersion = 1;26 var idb;27 var dbConnect = indexedDB.open(dbName, dbVersion);28 dbConnect.onsuccess = function (e) {29 idb = e.target.result;30 console.info('æ°æ®åºè¿æ¥æåï¼');31 };32 dbConnect.onerror = function () {33 console.error('æ°æ®åºè¿æ¥å¤±è´¥ï¼');34 };35}36/**37 * æ°æ®åºçæ¬æ´æ°38 */39function versionUpdate() {40 var dbName = 'indexedDB_test';41 var dbVersion = 2;42 var idb;43 var dbConnect = indexedDB.open(dbName, dbVersion);44 // æå45 dbConnect.onsuccess = function (e) {46 idb = e.target.result;47 console.info('æ°æ®åºè¿æ¥æåï¼');48 };49 // 失败50 dbConnect.onerror = function () {51 console.error('æ°æ®åºè¿æ¥å¤±è´¥ï¼');52 };53 // çæ¬åå54 dbConnect.onupgradeneeded = function (e) {55 idb = e.target.result;56 var tx = e.target.transation;57 var oldVersion = e.oldVersion;58 var newVersion = e.newVersion;59 console.info('æ°æ®åºçæ¬æ´æ°æåï¼' + oldVersion + '--->' + newVersion);60 };61}62/**63 * å建对象ä»åº64 */65function createObjectStore() {66 var dbName = 'indexedDB_test';67 var dbVersion = 3;68 var idb;69 var dbConnect = indexedDB.open(dbName, dbVersion);70 dbConnect.onsuccess = function (e) {71 idb = e.target.result;72 console.info('æ°æ®åºè¿æ¥æåï¼');73 };74 dbConnect.onerror = function () {75 console.error('æ°æ®åºè¿æ¥å¤±è´¥ï¼');76 };77 dbConnect.onupgradeneeded = function (e) {78 idb = e.target.result;79 var name = 'user';80 var optionalParameters = {81 keyPath: 'uid',82 autoIncrement: false83 };84 var store = idb.createObjectStore(name, optionalParameters);85 console.info('对象ä»åºå建æåï¼');86 };...
idbcursor-delete-exception-order.test.ts
Source:idbcursor-delete-exception-order.test.ts
1import test from "ava";2import { createdb, indexeddb_test } from "./wptsupport";3test("WPT idbcursor-delete-exception-order.htm", async (t) => {4 // 'IDBCursor.delete exception order: TransactionInactiveError vs. ReadOnlyError'5 await indexeddb_test(6 t,7 (done, db) => {8 const s = db.createObjectStore("s");9 s.put("value", "key");10 },11 (done, db) => {12 const s = db.transaction("s", "readonly").objectStore("s");13 const r = s.openCursor();14 r.onsuccess = () => {15 r.onsuccess = null;16 setTimeout(() => {17 const cursor = r.result;18 t.assert(!!cursor);19 t.throws(20 () => {21 cursor!.delete();22 },23 { name: "TransactionInactiveError" },24 '"Transaction inactive" check (TransactionInactivError) ' +25 'should precede "read only" check (ReadOnlyError)',26 );27 done();28 }, 0);29 };30 },31 );32 indexeddb_test(33 t,34 (done, db) => {35 const s = db.createObjectStore("s");36 s.put("value", "key");37 },38 (done, db) => {39 const s = db.transaction("s", "readonly").objectStore("s");40 const r = s.openCursor();41 r.onsuccess = () => {42 r.onsuccess = null;43 const cursor = r.result!;44 t.assert(cursor);45 cursor.continue();46 t.throws(47 () => {48 cursor.delete();49 },50 { name: "ReadOnlyError" },51 '"Read only" check (ReadOnlyError) should precede ' +52 '"got value flag" (InvalidStateError) check',53 );54 done();55 };56 },57 "IDBCursor.delete exception order: ReadOnlyError vs. InvalidStateError #1",58 );59 indexeddb_test(60 t,61 (done, db) => {62 const s = db.createObjectStore("s");63 s.put("value", "key");64 },65 (done, db) => {66 const s = db.transaction("s", "readonly").objectStore("s");67 const r = s.openKeyCursor();68 r.onsuccess = () => {69 r.onsuccess = null;70 const cursor = r.result;71 t.throws(72 () => {73 cursor!.delete();...
Using AI Code Generation
1var indexeddb_test = async_test;2 t = async_test(),3 records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },4 { pKey: "primaryKey_1", iKey: "indexKey_1" } ];5var open_rq = createdb(t);6open_rq.onupgradeneeded = function(e) {7 db = e.target.result;8 var objStore = db.createObjectStore("test", { keyPath: "pKey" });9 objStore.createIndex("index", "iKey");10 for (var i = 0; i < records.length; i++)11 objStore.add(records[i]);12};13open_rq.onsuccess = function(e) {14 var rq = db.transaction("test")15 .objectStore("test")16 .index("index")17 .openCursor();18 rq.onsuccess = t.step_func(function(e) {19 var cursor = e.target.result;20 assert_true(cursor instanceof IDBCursor, "cursor exist");21 assert_equals(cursor.source, rq.source, "cursor.source");22 assert_equals(cursor.direction, "next", "cursor.direction");23 assert_equals(cursor.key, records[0].iKey, "cursor.key");24 assert_equals(cursor.primaryKey, records[0].pKey, "cursor.primaryKey");25 assert_equals(cursor.value, records[0], "cursor.value");26 t.done();27 });28};29IndexedDB uses the Object.keys() method, which is defined in
Using AI Code Generation
1var indexeddb_test = wpt.indexeddb_test;2var db_name = "test_db";3var open_rq = createdb(async_test(), db_name);4open_rq.onupgradeneeded = function(e) {5 assert_equals(e.oldVersion, 0, "oldVersion");6 assert_equals(e.newVersion, 1, "newVersion");7 var db = e.target.result;8 var objStore = db.createObjectStore("store");9 objStore.createIndex("index", "indexedProperty");10 objStore.add({ indexedProperty: "data" }, 1);11};12open_rq.onsuccess = function(e) {13 var db = e.target.result;14 var tx = db.transaction("store", "readonly");15 var objStore = tx.objectStore("store");16 var index = objStore.index("index");17 var rq = index.openCursor();18 rq.onsuccess = t.step_func(function(e) {19 var cursor = e.target.result;20 assert_equals(cursor.value.indexedProperty, "data", "cursor.value");21 assert_equals(cursor.key, "data", "cursor.key");22 assert_equals(cursor.primaryKey, 1, "cursor.primaryKey");23 t.done();24 });25};26var indexeddb_test = wpt.indexeddb_test;27var db_name = "test_db";28var open_rq = createdb(async_test(), db_name);29open_rq.onupgradeneeded = function(e) {30 assert_equals(e.oldVersion, 0, "oldVersion");31 assert_equals(e.newVersion, 1, "newVersion");32 var db = e.target.result;33 var objStore = db.createObjectStore("store");34 objStore.add({ property: "data1" }, 1);35 objStore.add({ property: "data2" }, 2);36};37open_rq.onsuccess = function(e) {38 var db = e.target.result;39 var tx = db.transaction("store", "readonly");40 var objStore = tx.objectStore("store");41 var rq = objStore.openCursor();42 rq.onsuccess = t.step_func(function(e) {43 var cursor = e.target.result;44 if (cursor
Using AI Code Generation
1var test = async_test("IndexedDB: test that a database can be deleted");2var open_rq = createdb(test);3open_rq.onupgradeneeded = function(e) {4 e.target.result.createObjectStore("store");5 test.step(function() {6 assert_true(true, "upgrade needed called");7 });8}9open_rq.onsuccess = function(e) {10 var db = e.target.result;11 var del_rq = db.deleteDatabase();12 del_rq.onsuccess = test.step_func(function(e) {13 assert_equals(e.target.result, undefined, "deleteDatabase result");14 });15 del_rq.onblocked = test.step_func(function(e) {16 assert_true(false, "deleteDatabase should not be blocked");17 });18}19var test = async_test("IndexedDB: test that a database can be deleted (with version change)");20var open_rq = createdb(test);21open_rq.onupgradeneeded = function(e) {22 e.target.result.createObjectStore("store");23 test.step(function() {24 assert_true(true, "upgrade needed called");25 });26}27open_rq.onsuccess = function(e) {28 var db = e.target.result;29 var del_rq = db.deleteDatabase(2);30 del_rq.onsuccess = test.step_func(function(e) {31 assert_equals(e.target.result, undefined, "deleteDatabase result");32 });33 del_rq.onblocked = test.step_func(function(e) {34 assert_true(false, "deleteDatabase should not be blocked");35 });36}37var test = async_test("IndexedDB: test that a database can be deleted (with version change) - name only");38var open_rq = createdb(test);39open_rq.onupgradeneeded = function(e) {40 e.target.result.createObjectStore("store");41 test.step(function() {42 assert_true(true, "upgrade needed called");43 });44}45open_rq.onsuccess = function(e) {46 var db = e.target.result;47 var del_rq = db.deleteDatabase("name_only");48 del_rq.onsuccess = test.step_func(function(e) {49 assert_equals(e.target.result, undefined, "deleteDatabase result");50 });51 del_rq.onblocked = test.step_func(function(e) {52 assert_true(false, "deleteDatabase
Using AI Code Generation
1importScripts('/resources/testharness.js');2importScripts('/resources/testharnessreport.js');3importScripts('/resources/testharness-helpers.js');4test(function() {5 indexeddb_test();6}, "IndexedDB test");7function indexeddb_test() {8 let request = indexedDB.open("testDB");9 request.onerror = function(event) {10 assert_unreached("Error opening database");11 };12 request.onsuccess = function(event) {13 let db = event.target.result;14 let objectStore = db.createObjectStore("testObjectStore", {keyPath: "id"});15 objectStore.createIndex("testIndex", "testIndex");16 objectStore.add({id: 1, testIndex: 1});17 objectStore.add({id: 2, testIndex: 2});18 objectStore.add({id: 3, testIndex: 3});19 objectStore.add({id: 4, testIndex: 4});20 objectStore.add({id: 5, testIndex: 5});21 objectStore.add({id: 6, testIndex: 6});22 objectStore.add({id: 7, testIndex: 7});23 objectStore.add({id: 8, testIndex: 8});24 objectStore.add({id: 9, testIndex: 9});25 objectStore.add({id: 10, testIndex: 10});26 objectStore.add({id: 11, testIndex: 11});27 objectStore.add({id: 12, testIndex: 12});28 objectStore.add({id: 13, testIndex: 13});29 objectStore.add({id: 14, testIndex: 14});30 objectStore.add({id: 15, testIndex: 15});31 objectStore.add({id: 16, testIndex: 16});32 objectStore.add({id: 17, testIndex: 17});33 objectStore.add({id: 18, testIndex: 18});34 objectStore.add({id: 19, testIndex: 19});35 objectStore.add({id: 20, testIndex: 20});36 objectStore.add({id: 21, testIndex: 21});37 objectStore.add({id:
Using AI Code Generation
1var indexeddb_test = wpt.indexeddb_test;2var indexeddb_test = wpt.indexeddb_test;3indexeddb_test(function (t, db) {4}, 'Test description');5var indexeddb_test = function (test, description) {6 async_test(function (t) {7 var openRequest = indexedDB.open('testdb', 1);8 openRequest.onupgradeneeded = function (e) {9 var db = e.target.result;10 var objectStore = db.createObjectStore('teststore', { keyPath: 'id' });11 objectStore.createIndex('testindex', 'testindex', { unique: true });12 };13 openRequest.onsuccess = function (e) {14 var db = e.target.result;15 test(t, db);16 };17 }, description);18};19var indexeddb_test = function (test, description) {20 async_test(function (t) {21 var openRequest = indexedDB.open('testdb', 1);22 openRequest.onupgradeneeded = function (e) {23 var db = e.target.result;24 var objectStore = db.createObjectStore('teststore', { keyPath: 'id' });25 objectStore.createIndex('testindex', 'testindex', { unique: true });26 };27 openRequest.onsuccess = function (e) {28 var db = e.target.result;29 test(t, db);30 };31 }, description);32};33var indexeddb_test = wpt.indexeddb_test;34var indexeddb_test = wpt.indexeddb_test;35indexeddb_test(function (t, db) {36}, 'Test description');37var db;38var request = indexedDB.open("mydb", 1);39request.onerror = function(event) {40 console.log("Why didn't you allow my web
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!