Skip to content

Commit 34c4d1c

Browse files
IDB WPTs: Extend idbtransaction WPTs to run on workers
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}
1 parent 8839956 commit 34c4d1c

10 files changed

+359
-346
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// META: title=IndexedDB: Verify [SameObject] behavior of IDBTransaction's db attribute
2+
// META: global=window,worker
3+
// META: script=resources/support.js
4+
5+
// Spec: https://w3c.github.io/IndexedDB/#dom-idbtransaction-db
6+
7+
'use strict';
8+
9+
indexeddb_test(
10+
(t, db, tx) => {
11+
const store = db.createObjectStore('store');
12+
assert_equals(
13+
tx.db, tx.db, 'Attribute should yield the same object each time');
14+
},
15+
(t, db) => {
16+
const tx = db.transaction('store', 'readonly');
17+
assert_equals(
18+
tx.db, tx.db, 'Attribute should yield the same object each time');
19+
t.done();
20+
},
21+
'IDBTransaction.db [SameObject]');

IndexedDB/idbtransaction-db-SameObject.html

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// META: title=IDBTransaction - complete event
2+
// META: global=window,worker
3+
// META: script=resources/support.js
4+
5+
'use strict';
6+
7+
async_test(t => {
8+
let db;
9+
let store;
10+
let open_rq = createdb(t);
11+
let stages = [];
12+
13+
open_rq.onupgradeneeded = function(e) {
14+
stages.push('upgradeneeded');
15+
16+
db = e.target.result;
17+
store = db.createObjectStore('store');
18+
19+
e.target.transaction.oncomplete = function() {
20+
stages.push('complete');
21+
};
22+
};
23+
24+
open_rq.onsuccess = function(e) {
25+
stages.push('success');
26+
27+
let tx = db.transaction('store', 'readonly');
28+
store = tx.objectStore('store');
29+
store.openCursor().onsuccess =
30+
function(e) {
31+
stages.push('opencursor');
32+
}
33+
34+
db.transaction('store', 'readonly')
35+
.objectStore('store')
36+
.count()
37+
.onsuccess = t.step_func(function(e) {
38+
assert_array_equals(stages, [
39+
'upgradeneeded', 'complete', 'success', 'opencursor'
40+
]);
41+
t.done();
42+
});
43+
}
44+
});

IndexedDB/idbtransaction-oncomplete.htm

Lines changed: 0 additions & 53 deletions
This file was deleted.

IndexedDB/idbtransaction.any.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// META: title=IDBTransaction
2+
// META: global=window,worker
3+
// META: script=resources/support.js
4+
5+
'use strict';
6+
7+
async_test(function(t) {
8+
let dbname = 'idbtransaction-' + location + t.name;
9+
indexedDB.deleteDatabase(dbname);
10+
let open_rq = indexedDB.open(dbname);
11+
12+
open_rq.onblocked = t.unreached_func('open_rq.onblocked');
13+
open_rq.onerror = t.unreached_func('open_rq.onerror');
14+
15+
open_rq.onupgradeneeded = t.step_func(function(e) {
16+
t.add_cleanup(function() {
17+
open_rq.onerror = function(e) {
18+
e.preventDefault();
19+
};
20+
open_rq.result.close();
21+
indexedDB.deleteDatabase(open_rq.result.name);
22+
});
23+
24+
assert_equals(
25+
e.target, open_rq, 'e.target is reusing the same IDBOpenDBRequest');
26+
assert_equals(
27+
e.target.transaction, open_rq.transaction,
28+
'IDBOpenDBRequest.transaction');
29+
30+
assert_true(
31+
e.target.transaction instanceof IDBTransaction,
32+
'transaction instanceof IDBTransaction');
33+
t.done();
34+
});
35+
}, 'IDBTransaction - request gotten by the handler');
36+
37+
async_test(function(t) {
38+
let dbname = 'idbtransaction-' + location + t.name;
39+
indexedDB.deleteDatabase(dbname);
40+
let open_rq = indexedDB.open(dbname);
41+
42+
assert_equals(open_rq.transaction, null, 'IDBOpenDBRequest.transaction');
43+
assert_equals(open_rq.source, null, 'IDBOpenDBRequest.source');
44+
assert_equals(open_rq.readyState, 'pending', 'IDBOpenDBRequest.readyState');
45+
46+
assert_true(
47+
open_rq instanceof IDBOpenDBRequest,
48+
'open_rq instanceof IDBOpenDBRequest');
49+
assert_equals(
50+
open_rq + '', '[object IDBOpenDBRequest]', 'IDBOpenDBRequest (open_rq)');
51+
52+
open_rq.onblocked = t.unreached_func('open_rq.onblocked');
53+
open_rq.onerror = t.unreached_func('open_rq.onerror');
54+
55+
open_rq.onupgradeneeded = t.step_func(function() {
56+
t.add_cleanup(function() {
57+
open_rq.onerror = function(e) {
58+
e.preventDefault();
59+
};
60+
open_rq.result.close();
61+
indexedDB.deleteDatabase(open_rq.result.name);
62+
});
63+
t.done();
64+
});
65+
}, 'IDBTransaction - request returned by open()');

IndexedDB/idbtransaction.htm

Lines changed: 0 additions & 63 deletions
This file was deleted.

IndexedDB/idbtransaction_abort.any.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// META: title=IDBTransaction - abort
2+
// META: global=window,worker
3+
// META: script=resources/support.js
4+
5+
'use strict';
6+
7+
async_test(t => {
8+
let db;
9+
let aborted;
10+
const record = {indexedProperty: 'bar'};
11+
12+
let open_rq = createdb(t);
13+
open_rq.onupgradeneeded = function(e) {
14+
db = e.target.result;
15+
let txn = e.target.transaction;
16+
let objStore = db.createObjectStore('store');
17+
18+
objStore.add(record, 1);
19+
objStore.add(record, 2);
20+
let index =
21+
objStore.createIndex('index', 'indexedProperty', {unique: true});
22+
23+
assert_true(index instanceof IDBIndex, 'IDBIndex');
24+
25+
e.target.transaction.onabort = t.step_func(function(e) {
26+
aborted = true;
27+
assert_equals(e.type, 'abort', 'event type');
28+
});
29+
30+
db.onabort = function(e) {
31+
assert_true(aborted, 'transaction.abort event has fired');
32+
t.done();
33+
};
34+
35+
e.target.transaction.oncomplete = fail(t, 'got complete, expected abort');
36+
};
37+
});

IndexedDB/idbtransaction_abort.htm

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)