You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by kn...@apache.org on 2019/03/12 04:11:28 UTC
[cordova-plugin-file] branch travis_tests updated: improve safari
only test to use open db everytime
This is an automated email from the ASF dual-hosted git repository.
knaito pushed a commit to branch travis_tests
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git
The following commit(s) were added to refs/heads/travis_tests by this push:
new 5a9a239 improve safari only test to use open db everytime
5a9a239 is described below
commit 5a9a2395611429e8af406aeae058bd42089b47b6
Author: knaito <kn...@asial.co.jp>
AuthorDate: Tue Mar 12 13:11:06 2019 +0900
improve safari only test to use open db everytime
---
tests/tests.js | 115 ++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 69 insertions(+), 46 deletions(-)
diff --git a/tests/tests.js b/tests/tests.js
index ca83ba6..a833156 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -208,6 +208,42 @@ exports.defineAutoTests = function () {
return (ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 && ua.indexOf('edge') === -1);
};
+ var openDb = function (nextTask, errorTask) {
+ var FILE_STORE_ = 'testentries';
+ var dbName = 'hogehoge';
+
+ var onError = function (e) {
+ window.customLog('log', 'db error');
+ window.customLog('log', e.toString());
+ errorTask();
+ };
+
+ var indexedDB = window.indexedDB || window.mozIndexedDB;
+
+ var mydb = null;
+ var request = indexedDB.open(dbName, '5');
+
+ request.onerror = onError;
+
+ request.onupgradeneeded = function (e) {
+ window.customLog('log', 'upgrade needed');
+ mydb = e.target.result;
+ mydb.onerror = onError;
+ if (!mydb.objectStoreNames.contains(FILE_STORE_)) {
+ mydb.createObjectStore(FILE_STORE_/*, {keyPath: 'id', autoIncrement: true} */);
+ }
+ };
+
+ request.onsuccess = function (e) {
+ mydb = e.target.result;
+ mydb.onerror = onError;
+ window.customLog('log', 'step 1');
+ nextTask(mydb, FILE_STORE_);
+ };
+
+ request.onblocked = onError;
+ };
+
describe('Safari only Test', function () {
window.customLog('log', 'Safari only test');
@@ -220,66 +256,53 @@ exports.defineAutoTests = function () {
return;
}
- var FILE_STORE_ = 'testentries';
- var dbName = 'hogehoge';
-
var onError = function (e) {
window.customLog('log', 'db error');
window.customLog('log', e.toString());
done();
};
- var indexedDB = window.indexedDB || window.mozIndexedDB;
+ openDb(
+ function (mydb, storeName) {
+ window.customLog('log', 'step 1');
- var mydb = null;
- var request = indexedDB.open(dbName, '4');
+ var myentry = { 'myname': 'hogehoge' };
+ var mypath = '/aaa/bbb';
- var myentry = { 'myname': 'hogehoge' };
- var mypath = '/aaa/bbb';
-
- request.onerror = onError;
-
- request.onupgradeneeded = function (e) {
- window.customLog('log', 'upgrade needed');
- mydb = e.target.result;
- mydb.onerror = onError;
- if (!mydb.objectStoreNames.contains(FILE_STORE_)) {
- mydb.createObjectStore(FILE_STORE_/*, {keyPath: 'id', autoIncrement: true} */);
- }
- };
-
- request.onsuccess = function (e) {
- mydb = e.target.result;
- mydb.onerror = onError;
- window.customLog('log', 'step 1');
-
- var tx = mydb.transaction([FILE_STORE_], 'readwrite');
- tx.objectStore(FILE_STORE_).put(myentry, mypath);
- tx.onabort = function (err) {
- window.customLog('log', 'db abort!!!');
- console.log(err);
- done();
- };
- tx.oncomplete = function () {
- window.customLog('log', 'step 2');
- var tx2 = mydb.transaction([FILE_STORE_], 'readonly');
- tx2.onabort = function (err) {
- window.customLog('log', 'db2 abort!!!');
+ var tx = mydb.transaction([storeName], 'readwrite');
+ tx.objectStore(storeName).put(myentry, mypath);
+ tx.onabort = function (err) {
+ window.customLog('log', 'db abort!!!');
console.log(err);
done();
};
- tx2.oncomplete = function () {
- window.customLog('log', 'ALL OK');
- window.customLog('log', !!request2.result);
- window.customLog('log', JSON.stringify(request2.result));
- done();
+ tx.oncomplete = function () {
+ window.customLog('log', 'step 2');
+
+ openDb(
+ function (mydb2, storeName2) {
+ var tx2 = mydb2.transaction([storeName2], 'readonly');
+ tx2.onabort = function (err) {
+ window.customLog('log', 'db2 abort!!!');
+ console.log(err);
+ done();
+ };
+ tx2.oncomplete = function () {
+ window.customLog('log', 'ALL OK');
+ window.customLog('log', !!request2.result);
+ window.customLog('log', JSON.stringify(request2.result));
+ done();
+ };
+ var request2 = tx2.objectStore(storeName2).get(mypath);
+ },
+ onError
+ );
};
- var request2 = tx2.objectStore(FILE_STORE_).get(mypath);
- };
- };
+ },
+ onError
+ );
- request.onblocked = onError;
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org