From 61a0206ad33abc50ef12f4f4b5d6cd907dee1ee7 Mon Sep 17 00:00:00 2001 From: Garima Chadha Date: Wed, 3 Jul 2024 16:18:05 -0700 Subject: [PATCH] IDB WPTs: Extend idbdatabase transaction tests to worker environments. The change updates IDBDatabase transaction() related WPTs to also run on dedicated, service, and shared workers. Currently, these only run in window environments. Bug: 41455766 Change-Id: I1e21af2c3402e58747848c19bfcf85c2e528b284 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5671037 Commit-Queue: Rahul Singh Auto-Submit: Garima Chadha Reviewed-by: Evan Stade Reviewed-by: Rahul Singh Cr-Commit-Position: refs/heads/main@{#1323082} --- IndexedDB/idbdatabase_transaction.any.js | 82 ++++++++++++++++++++++++ IndexedDB/idbdatabase_transaction.htm | 24 ------- IndexedDB/idbdatabase_transaction2.htm | 27 -------- IndexedDB/idbdatabase_transaction3.htm | 28 -------- IndexedDB/idbdatabase_transaction4.htm | 26 -------- IndexedDB/idbdatabase_transaction5.htm | 22 ------- 6 files changed, 82 insertions(+), 127 deletions(-) create mode 100644 IndexedDB/idbdatabase_transaction.any.js delete mode 100644 IndexedDB/idbdatabase_transaction.htm delete mode 100644 IndexedDB/idbdatabase_transaction2.htm delete mode 100644 IndexedDB/idbdatabase_transaction3.htm delete mode 100644 IndexedDB/idbdatabase_transaction4.htm delete mode 100644 IndexedDB/idbdatabase_transaction5.htm diff --git a/IndexedDB/idbdatabase_transaction.any.js b/IndexedDB/idbdatabase_transaction.any.js new file mode 100644 index 00000000000000..17859ec99e68f5 --- /dev/null +++ b/IndexedDB/idbdatabase_transaction.any.js @@ -0,0 +1,82 @@ +// META: title=IDBDatabase.transaction() +// META: global=window,worker +// META: script=resources/support.js + +'use strict'; + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function () { }; + open_rq.onsuccess = function (e) { + db = e.target.result; + + assert_throws_dom('NotFoundError', function () { db.transaction('non-existing'); }); + t.done(); + }; +}, "Attempt to open a transaction with invalid scope"); + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function (e) { + db = e.target.result; + db.createObjectStore('readonly'); + }; + open_rq.onsuccess = function (e) { + var txn = db.transaction('readonly', 'readonly', { durability: 'relaxed' }); + assert_equals(txn.mode, "readonly", 'txn.mode'); + + t.done(); + }; +}, "Opening a transaction defaults to a read-only mode"); + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function (e) { + db = e.target.result; + db.createObjectStore('test'); + }; + + open_rq.onsuccess = function (e) { + db.close(); + + assert_throws_dom('InvalidStateError', + function () { db.transaction('test', 'readonly', { durability: 'relaxed' }); }); + + t.done(); + }; +}, "Attempt to open a transaction from closed database connection"); + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function (e) { + db = e.target.result; + db.createObjectStore('test'); + }; + + open_rq.onsuccess = function (e) { + assert_throws_js(TypeError, + function () { db.transaction('test', 'whatever'); }); + + t.done(); + }; +}, "Attempt to open a transaction with invalid mode"); + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function () { }; + open_rq.onsuccess = function (e) { + db = e.target.result; + assert_throws_dom('InvalidAccessError', function () { db.transaction([]); }); + t.done(); + }; +}, "If storeNames is an empty list, the implementation must throw a DOMException of type InvalidAccessError"); \ No newline at end of file diff --git a/IndexedDB/idbdatabase_transaction.htm b/IndexedDB/idbdatabase_transaction.htm deleted file mode 100644 index 8e8264f8eab9ab..00000000000000 --- a/IndexedDB/idbdatabase_transaction.htm +++ /dev/null @@ -1,24 +0,0 @@ - -IDBDatabase.transaction() - attempt to open a transaction with invalid scope - - - - - - - -
diff --git a/IndexedDB/idbdatabase_transaction2.htm b/IndexedDB/idbdatabase_transaction2.htm deleted file mode 100644 index 37b11229194deb..00000000000000 --- a/IndexedDB/idbdatabase_transaction2.htm +++ /dev/null @@ -1,27 +0,0 @@ - -IDBDatabase.transaction() - opening a transaction defaults to a read-only mode - - - - - - - -
diff --git a/IndexedDB/idbdatabase_transaction3.htm b/IndexedDB/idbdatabase_transaction3.htm deleted file mode 100644 index 1eea31f764a773..00000000000000 --- a/IndexedDB/idbdatabase_transaction3.htm +++ /dev/null @@ -1,28 +0,0 @@ - -IDBDatabase.transaction() - attempt to open a transaction from closed database connection - - - - - - - -
diff --git a/IndexedDB/idbdatabase_transaction4.htm b/IndexedDB/idbdatabase_transaction4.htm deleted file mode 100644 index 3a164c25f59ced..00000000000000 --- a/IndexedDB/idbdatabase_transaction4.htm +++ /dev/null @@ -1,26 +0,0 @@ - -IDBDatabase.transaction() - attempt to open a transaction with invalid mode - - - - - - - -
diff --git a/IndexedDB/idbdatabase_transaction5.htm b/IndexedDB/idbdatabase_transaction5.htm deleted file mode 100644 index 451939731faa24..00000000000000 --- a/IndexedDB/idbdatabase_transaction5.htm +++ /dev/null @@ -1,22 +0,0 @@ - - -IDBDatabase.transaction() - If storeNames is an empty list, the implementation must throw a DOMException of type InvalidAccessError - - - - - -
- -