Skip to content

Commit 9a1f194

Browse files
Garima Chadhachromium-wpt-export-bot
Garima Chadha
authored andcommitted
IDB WPTs: Extend upgrade transaction tests to workers
The update modifies "upgrade transaction" related WPTs to run not only in window environments but also on dedicated, service, and shared workers. Bug: 41455766 Change-Id: Ibdb5474722733d3a1c0d950f6893fe2c5bede6bc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5905028 Reviewed-by: Steve Becker <[email protected]> Reviewed-by: Abhishek Shanthkumar <[email protected]> Commit-Queue: Garima Chadha <[email protected]> Auto-Submit: Garima Chadha <[email protected]> Cr-Commit-Position: refs/heads/main@{#1370305}
1 parent 9a4e8cb commit 9a1f194

7 files changed

+205
-229
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// META: title=Upgrade transaction deactivation timing
2+
// META: global=window,worker
3+
// META: script=resources/support.js
4+
// META: script=resources/support-promises.js
5+
6+
// Spec: "https://w3c.github.io/IndexedDB/#upgrade-transaction-steps"
7+
8+
'use strict';
9+
10+
indexeddb_test(
11+
(t, db, tx) => {
12+
db.createObjectStore('store');
13+
assert_true(is_transaction_active(tx, 'store'),
14+
'Transaction should be active in upgradeneeded callback');
15+
},
16+
(t, db) => { t.done(); },
17+
'Upgrade transactions are active in upgradeneeded callback');
18+
19+
indexeddb_test(
20+
(t, db, tx) => {
21+
db.createObjectStore('store');
22+
assert_true(is_transaction_active(tx, 'store'),
23+
'Transaction should be active in upgradeneeded callback');
24+
25+
Promise.resolve().then(t.step_func(() => {
26+
assert_true(is_transaction_active(tx, 'store'),
27+
'Transaction should be active in microtask checkpoint');
28+
}));
29+
},
30+
(t, db) => { t.done(); },
31+
'Upgrade transactions are active in upgradeneeded callback and microtasks');
32+
33+
34+
indexeddb_test(
35+
(t, db, tx) => {
36+
db.createObjectStore('store');
37+
const release_tx = keep_alive(tx, 'store');
38+
39+
setTimeout(t.step_func(() => {
40+
assert_false(is_transaction_active(tx, 'store'),
41+
'Transaction should be inactive in next task');
42+
release_tx();
43+
}), 0);
44+
},
45+
(t, db) => { t.done(); },
46+
'Upgrade transactions are deactivated before next task');

IndexedDB/upgrade-transaction-deactivation-timing.html

-48
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// META: title=IndexedDB: backend-aborted versionchange transaction lifecycle
2+
// META: global=window,worker
3+
// META: script=resources/support.js
4+
// META: script=resources/support-promises.js
5+
6+
// Spec: "https://w3c.github.io/IndexedDB/#upgrade-transaction-steps"
7+
// "https://w3c.github.io/IndexedDB/#dom-idbdatabase-createobjectstore"
8+
// "https://w3c.github.io/IndexedDB/#dom-idbdatabase-deleteobjectstore"
9+
'use strict';
10+
11+
promise_test(t => {
12+
return createDatabase(t, database => {
13+
createBooksStore(t, database);
14+
}).then(database => {
15+
database.close();
16+
}).then(() => migrateDatabase(t, 2, (database, transaction, request) => {
17+
return new Promise((resolve, reject) => {
18+
transaction.addEventListener('abort', () => {
19+
resolve(new Promise((resolve, reject) => {
20+
assert_equals(
21+
request.transaction, transaction,
22+
"The open request's transaction should be reset after onabort");
23+
assert_throws_dom(
24+
'InvalidStateError',
25+
() => { database.createObjectStore('books2'); },
26+
'createObjectStore exception should reflect that the ' +
27+
'transaction is no longer running');
28+
assert_throws_dom(
29+
'InvalidStateError',
30+
() => { database.deleteObjectStore('books'); },
31+
'deleteObjectStore exception should reflect that the ' +
32+
'transaction is no longer running');
33+
resolve();
34+
}));
35+
}, false);
36+
transaction.objectStore('books').add(BOOKS_RECORD_DATA[0]);
37+
transaction._willBeAborted();
38+
});
39+
}));
40+
}, 'in the abort event handler for a transaction aborted due to an unhandled ' +
41+
'request error');
42+
43+
promise_test(t => {
44+
return createDatabase(t, database => {
45+
createBooksStore(t, database);
46+
}).then(database => {
47+
database.close();
48+
}).then(() => migrateDatabase(t, 2, (database, transaction, request) => {
49+
return new Promise((resolve, reject) => {
50+
transaction.addEventListener('abort', () => {
51+
setTimeout(() => {
52+
resolve(new Promise((resolve, reject) => {
53+
assert_equals(
54+
request.transaction, null,
55+
"The open request's transaction should be reset after " +
56+
'onabort microtasks');
57+
assert_throws_dom(
58+
'InvalidStateError',
59+
() => { database.createObjectStore('books2'); },
60+
'createObjectStore exception should reflect that the ' +
61+
'transaction is no longer running');
62+
assert_throws_dom(
63+
'InvalidStateError',
64+
() => { database.deleteObjectStore('books'); },
65+
'deleteObjectStore exception should reflect that the ' +
66+
'transaction is no longer running');
67+
resolve();
68+
}));
69+
}, 0);
70+
}, false);
71+
transaction.objectStore('books').add(BOOKS_RECORD_DATA[0]);
72+
transaction._willBeAborted();
73+
});
74+
}));
75+
}, 'in a setTimeout(0) callback after the abort event is fired for a ' +
76+
'transaction aborted due to an unhandled request failure');

IndexedDB/upgrade-transaction-lifecycle-backend-aborted.html

-84
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// META: title=IndexedDB: committed versionchange transaction lifecycle
2+
// META: global=window,worker
3+
// META: script=resources/support.js
4+
// META: script=resources/support-promises.js
5+
6+
// Spec: "https://w3c.github.io/IndexedDB/#upgrade-transaction-steps"
7+
// "https://w3c.github.io/IndexedDB/#dom-idbdatabase-createobjectstore"
8+
// "https://w3c.github.io/IndexedDB/#dom-idbdatabase-deleteobjectstore"
9+
10+
'use strict';
11+
12+
promise_test(t => {
13+
return createDatabase(t, database => {
14+
createBooksStore(t, database);
15+
}).then(database => {
16+
database.close();
17+
}).then(() => migrateDatabase(t, 2, (database, transaction, request) => {
18+
return new Promise((resolve, reject) => {
19+
transaction.addEventListener('complete', () => {
20+
resolve(new Promise((resolve, reject) => {
21+
assert_equals(
22+
request.transaction, transaction,
23+
"The open request's transaction should be reset after " +
24+
'oncomplete');
25+
assert_throws_dom(
26+
'InvalidStateError',
27+
() => { database.createObjectStore('books2'); },
28+
'createObjectStore exception should reflect that the ' +
29+
'transaction is no longer running');
30+
assert_throws_dom(
31+
'InvalidStateError',
32+
() => { database.deleteObjectStore('books'); },
33+
'deleteObjectStore exception should reflect that the ' +
34+
'transaction is no longer running');
35+
resolve();
36+
}));
37+
}, false);
38+
});
39+
})).then(database => { database.close(); });
40+
}, 'in the complete event handler for a committed transaction');
41+
42+
promise_test(t => {
43+
return createDatabase(t, database => {
44+
createBooksStore(t, database);
45+
}).then(database => {
46+
database.close();
47+
}).then(() => migrateDatabase(t, 2, (database, transaction, request) => {
48+
return new Promise((resolve, reject) => {
49+
transaction.addEventListener('complete', () => {
50+
setTimeout(() => {
51+
resolve(new Promise((resolve, reject) => {
52+
assert_equals(
53+
request.transaction, null,
54+
"The open request's transaction should be reset after " +
55+
'oncomplete microtasks');
56+
assert_throws_dom(
57+
'InvalidStateError',
58+
() => { database.createObjectStore('books2'); },
59+
'createObjectStore exception should reflect that the ' +
60+
'transaction is no longer running');
61+
assert_throws_dom(
62+
'InvalidStateError',
63+
() => { database.deleteObjectStore('books'); },
64+
'deleteObjectStore exception should reflect that the ' +
65+
'transaction is no longer running');
66+
resolve();
67+
}));
68+
}, 0);
69+
}, false);
70+
});
71+
})).then(database => { database.close(); });
72+
}, 'in a setTimeout(0) callback after the complete event is fired for a ' +
73+
'committed transaction');

0 commit comments

Comments
 (0)