From 57aa2ac737eec9526ad6c4ace61e590730ec3b9e Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Tue, 7 Mar 2017 12:34:57 -0800 Subject: [PATCH] IndexedDB: Add tests for HTML monkey patches The IDB spec implicitly "monkey patches" HTML with imprecise prose when describing newly created transactions: "When control is returned to the event loop, the implementation must unset the active flag." The plan is replace that with a proper hook. Adding tests first to ensure the expected behavior is captured appropriately. https://github.com/w3c/IndexedDB/issues/87 --- IndexedDB/event-dispatch-active-flag.html | 154 ++++++++++++++++++ IndexedDB/support.js | 23 +++ .../transaction-deactivation-timing.html | 143 ++++++++++++++++ ...grade-transaction-deactivation-timing.html | 48 ++++++ 4 files changed, 368 insertions(+) create mode 100644 IndexedDB/event-dispatch-active-flag.html create mode 100644 IndexedDB/transaction-deactivation-timing.html create mode 100644 IndexedDB/upgrade-transaction-deactivation-timing.html diff --git a/IndexedDB/event-dispatch-active-flag.html b/IndexedDB/event-dispatch-active-flag.html new file mode 100644 index 00000000000000..4b97c98dd83972 --- /dev/null +++ b/IndexedDB/event-dispatch-active-flag.html @@ -0,0 +1,154 @@ + + +Transaction active flag is set during event dispatch + + + + + + diff --git a/IndexedDB/support.js b/IndexedDB/support.js index 1023e753dd0e15..cf3aa4d0ee23d8 100644 --- a/IndexedDB/support.js +++ b/IndexedDB/support.js @@ -165,3 +165,26 @@ function is_transaction_active(tx, store_name) { return false; } } + +// Keep the passed transaction alive indefinitely (by making requests +// against the named store). Returns a function to to let the +// transaction finish, and asserts that the transaction is not yet +// finished. +function keep_alive(tx, store_name) { + let completed = false; + tx.addEventListener('complete', () => { completed = true; }); + + let pin = true; + + function spin() { + if (!pin) + return; + tx.objectStore(store_name).get(0).onsuccess = spin; + } + spin(); + + return () => { + assert_false(completed, 'Transaction completed while kept alive'); + pin = false; + }; +} diff --git a/IndexedDB/transaction-deactivation-timing.html b/IndexedDB/transaction-deactivation-timing.html new file mode 100644 index 00000000000000..e3b4a968e87788 --- /dev/null +++ b/IndexedDB/transaction-deactivation-timing.html @@ -0,0 +1,143 @@ + + +Transactions deactivation timing + + + + + diff --git a/IndexedDB/upgrade-transaction-deactivation-timing.html b/IndexedDB/upgrade-transaction-deactivation-timing.html new file mode 100644 index 00000000000000..f941f219e563bc --- /dev/null +++ b/IndexedDB/upgrade-transaction-deactivation-timing.html @@ -0,0 +1,48 @@ + + +Upgrade transaction deactivation timing + + + + +