Skip to content

Commit

Permalink
IDB WPTs: Extend idbtransaction WPTs to run on workers
Browse files Browse the repository at this point in the history
This set of IndexedDB WPTs currently only run in a window environment.
This change extends them to also run in dedicated, shared, and service
worker environments.

Bug: 41455766
Change-Id: I8b7afb20cbc670091980c8bbb66a1246a0e260b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6217662
Reviewed-by: Steve Becker <[email protected]>
Commit-Queue: Rahul Singh <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1413811}
  • Loading branch information
rahulsingh-msft authored and chromium-wpt-export-bot committed Jan 31, 2025
1 parent 8839956 commit 34c4d1c
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 346 deletions.
21 changes: 21 additions & 0 deletions IndexedDB/idbtransaction-db-SameObject.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// META: title=IndexedDB: Verify [SameObject] behavior of IDBTransaction's db attribute
// META: global=window,worker
// META: script=resources/support.js

// Spec: https://w3c.github.io/IndexedDB/#dom-idbtransaction-db

'use strict';

indexeddb_test(
(t, db, tx) => {
const store = db.createObjectStore('store');
assert_equals(
tx.db, tx.db, 'Attribute should yield the same object each time');
},
(t, db) => {
const tx = db.transaction('store', 'readonly');
assert_equals(
tx.db, tx.db, 'Attribute should yield the same object each time');
t.done();
},
'IDBTransaction.db [SameObject]');
24 changes: 0 additions & 24 deletions IndexedDB/idbtransaction-db-SameObject.html

This file was deleted.

44 changes: 44 additions & 0 deletions IndexedDB/idbtransaction-oncomplete.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// META: title=IDBTransaction - complete event
// META: global=window,worker
// META: script=resources/support.js

'use strict';

async_test(t => {
let db;
let store;
let open_rq = createdb(t);
let stages = [];

open_rq.onupgradeneeded = function(e) {
stages.push('upgradeneeded');

db = e.target.result;
store = db.createObjectStore('store');

e.target.transaction.oncomplete = function() {
stages.push('complete');
};
};

open_rq.onsuccess = function(e) {
stages.push('success');

let tx = db.transaction('store', 'readonly');
store = tx.objectStore('store');
store.openCursor().onsuccess =
function(e) {
stages.push('opencursor');
}

db.transaction('store', 'readonly')
.objectStore('store')
.count()
.onsuccess = t.step_func(function(e) {
assert_array_equals(stages, [
'upgradeneeded', 'complete', 'success', 'opencursor'
]);
t.done();
});
}
});
53 changes: 0 additions & 53 deletions IndexedDB/idbtransaction-oncomplete.htm

This file was deleted.

65 changes: 65 additions & 0 deletions IndexedDB/idbtransaction.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// META: title=IDBTransaction
// META: global=window,worker
// META: script=resources/support.js

'use strict';

async_test(function(t) {
let dbname = 'idbtransaction-' + location + t.name;
indexedDB.deleteDatabase(dbname);
let open_rq = indexedDB.open(dbname);

open_rq.onblocked = t.unreached_func('open_rq.onblocked');
open_rq.onerror = t.unreached_func('open_rq.onerror');

open_rq.onupgradeneeded = t.step_func(function(e) {
t.add_cleanup(function() {
open_rq.onerror = function(e) {
e.preventDefault();
};
open_rq.result.close();
indexedDB.deleteDatabase(open_rq.result.name);
});

assert_equals(
e.target, open_rq, 'e.target is reusing the same IDBOpenDBRequest');
assert_equals(
e.target.transaction, open_rq.transaction,
'IDBOpenDBRequest.transaction');

assert_true(
e.target.transaction instanceof IDBTransaction,
'transaction instanceof IDBTransaction');
t.done();
});
}, 'IDBTransaction - request gotten by the handler');

async_test(function(t) {
let dbname = 'idbtransaction-' + location + t.name;
indexedDB.deleteDatabase(dbname);
let open_rq = indexedDB.open(dbname);

assert_equals(open_rq.transaction, null, 'IDBOpenDBRequest.transaction');
assert_equals(open_rq.source, null, 'IDBOpenDBRequest.source');
assert_equals(open_rq.readyState, 'pending', 'IDBOpenDBRequest.readyState');

assert_true(
open_rq instanceof IDBOpenDBRequest,
'open_rq instanceof IDBOpenDBRequest');
assert_equals(
open_rq + '', '[object IDBOpenDBRequest]', 'IDBOpenDBRequest (open_rq)');

open_rq.onblocked = t.unreached_func('open_rq.onblocked');
open_rq.onerror = t.unreached_func('open_rq.onerror');

open_rq.onupgradeneeded = t.step_func(function() {
t.add_cleanup(function() {
open_rq.onerror = function(e) {
e.preventDefault();
};
open_rq.result.close();
indexedDB.deleteDatabase(open_rq.result.name);
});
t.done();
});
}, 'IDBTransaction - request returned by open()');
63 changes: 0 additions & 63 deletions IndexedDB/idbtransaction.htm

This file was deleted.

37 changes: 37 additions & 0 deletions IndexedDB/idbtransaction_abort.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// META: title=IDBTransaction - abort
// META: global=window,worker
// META: script=resources/support.js

'use strict';

async_test(t => {
let db;
let aborted;
const record = {indexedProperty: 'bar'};

let open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
let txn = e.target.transaction;
let objStore = db.createObjectStore('store');

objStore.add(record, 1);
objStore.add(record, 2);
let index =
objStore.createIndex('index', 'indexedProperty', {unique: true});

assert_true(index instanceof IDBIndex, 'IDBIndex');

e.target.transaction.onabort = t.step_func(function(e) {
aborted = true;
assert_equals(e.type, 'abort', 'event type');
});

db.onabort = function(e) {
assert_true(aborted, 'transaction.abort event has fired');
t.done();
};

e.target.transaction.oncomplete = fail(t, 'got complete, expected abort');
};
});
41 changes: 0 additions & 41 deletions IndexedDB/idbtransaction_abort.htm

This file was deleted.

Loading

0 comments on commit 34c4d1c

Please sign in to comment.