summaryrefslogtreecommitdiff
path: root/test/test-database.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-11 14:24:03 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-18 21:33:14 -0400
commit5f49f0fed25b421b0142b306a968f2cd435804e1 (patch)
treef6d1a2875f902f07ce9810670725480b6ec305a4 /test/test-database.js
parentac603d54a3a53bec2881199756f3dd6a1aa44057 (diff)
Add tests
Diffstat (limited to 'test/test-database.js')
-rw-r--r--test/test-database.js52
1 files changed, 50 insertions, 2 deletions
diff --git a/test/test-database.js b/test/test-database.js
index 8b7a163a..e9ec3f0b 100644
--- a/test/test-database.js
+++ b/test/test-database.js
@@ -92,9 +92,56 @@ class XMLHttpRequest {
}
}
+class Image {
+ constructor() {
+ this._src = '';
+ this._loadCallbacks = [];
+ }
+
+ get src() {
+ return this._src;
+ }
+
+ set src(value) {
+ this._src = value;
+ this._delayTriggerLoad();
+ }
+
+ get naturalWidth() {
+ return 100;
+ }
+
+ get naturalHeight() {
+ return 100;
+ }
+
+ addEventListener(eventName, callback) {
+ if (eventName === 'load') {
+ this._loadCallbacks.push(callback);
+ }
+ }
+
+ removeEventListener(eventName, callback) {
+ if (eventName === 'load') {
+ const index = this._loadCallbacks.indexOf(callback);
+ if (index >= 0) {
+ this._loadCallbacks.splice(index, 1);
+ }
+ }
+ }
+
+ async _delayTriggerLoad() {
+ await Promise.resolve();
+ for (const callback of this._loadCallbacks) {
+ callback();
+ }
+ }
+}
+
const vm = new VM({
chrome,
+ Image,
XMLHttpRequest,
indexedDB: global.indexedDB,
IDBKeyRange: global.IDBKeyRange,
@@ -106,6 +153,7 @@ vm.execute([
'bg/js/json-schema.js',
'bg/js/dictionary.js',
'mixed/js/core.js',
+ 'bg/js/media-utility.js',
'bg/js/request.js',
'bg/js/dictionary-importer.js',
'bg/js/database.js'
@@ -235,8 +283,8 @@ async function testDatabase1() {
true
);
vm.assert.deepStrictEqual(counts, {
- counts: [{kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}],
- total: {kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}
+ counts: [{kanji: 2, kanjiMeta: 2, terms: 33, termMeta: 12, tagMeta: 14}],
+ total: {kanji: 2, kanjiMeta: 2, terms: 33, termMeta: 12, tagMeta: 14}
});
// Test find* functions