aboutsummaryrefslogtreecommitdiff
path: root/test/unit/utils.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-01-10 23:38:56 +0100
committerWojtek Kosior <koszko@koszko.org>2022-01-10 23:38:56 +0100
commit19304cd1ae4e4ba4f6dcf4f1db14de1e4e70c250 (patch)
tree2e7e6f904ad16f9402827a7bc215a419de5c2656 /test/unit/utils.py
parent38650a8102fe0841617cd80f3a6e45b1f5f62fd5 (diff)
downloadbrowser-extension-19304cd1ae4e4ba4f6dcf4f1db14de1e4e70c250.tar.gz
browser-extension-19304cd1ae4e4ba4f6dcf4f1db14de1e4e70c250.zip
improve item list styling; add payload creation form; exend dialog mechanism
Diffstat (limited to 'test/unit/utils.py')
-rw-r--r--test/unit/utils.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/unit/utils.py b/test/unit/utils.py
index b6b389f..a61e215 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -66,3 +66,56 @@ def sample_data_dict(items):
"""
return dict([(it['identifier'], {item_version_string(it): it})
for it in items])
+
+def clear_indexeddb(execute_in_page):
+ """
+ Remove Haketilo data from IndexedDB. If variables from common/indexeddb.js
+ are in the global scope, this function will handle closing the opened
+ database instance (if any). Otherwise, the caller is responsible for making
+ sure the database being deleted is not opened anywhere.
+ """
+ execute_in_page(
+ '''{
+ async function delete_db() {
+ if (typeof db !== "undefined" && db) {
+ db.close();
+ db = null;
+ }
+ let resolve, reject;
+ const result = new Promise((...cbs) => [resolve, reject] = cbs);
+ const request = indexedDB.deleteDatabase("haketilo");
+ [request.onsuccess, request.onerror] = [resolve, reject];
+ await result;
+ }
+
+ returnval(delete_db());
+ }'''
+ )
+
+def get_db_contents(execute_in_page):
+ """
+ Retrieve all IndexedDB contents. It is expected that either variables from
+ common/indexeddb.js are in the global scope or common/indexeddb.js is
+ imported as haketilodb.
+ """
+ return execute_in_page(
+ '''{
+ async function get_database_contents()
+ {
+ const db_getter =
+ typeof haketilodb === "undefined" ? get_db : haketilodb.get;
+ const db = await db_getter();
+
+ const transaction = db.transaction(db.objectStoreNames);
+ const result = {};
+
+ for (const store_name of db.objectStoreNames) {
+ const req = transaction.objectStore(store_name).getAll();
+ await new Promise(cb => req.onsuccess = cb);
+ result[store_name] = req.result;
+ }
+
+ return result;
+ }
+ returnval(get_database_contents());
+ }''')