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 03:37:27 UTC

[cordova-plugin-file] branch travis_tests updated: safari test 2

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 a6e66bc  safari test 2
a6e66bc is described below

commit a6e66bc0fc33266d562d6729b42677b8a8f547d5
Author: knaito <kn...@asial.co.jp>
AuthorDate: Tue Mar 12 12:37:03 2019 +0900

    safari test 2
---
 tests/tests.js | 128 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 104 insertions(+), 24 deletions(-)

diff --git a/tests/tests.js b/tests/tests.js
index b083e18..2fbb203 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -202,6 +202,86 @@ exports.defineAutoTests = function () {
             }
             return base + extension;
         };
+
+        var isSafari = function () {
+            var ua = window.navigator.userAgent.toLowerCase();
+            return (ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 && ua.indexOf('edge') === -1);
+        };
+
+        describe('Safari only Test', function () {
+
+            window.customLog('log', 'Safari only test');
+
+            it('file.spec.0 can use indexed db', function (done) {
+
+                if (!isSafari()) {
+                    window.customLog('log', 'The system is not safari.');
+                    done();
+                    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;
+
+                var mydb = null;
+                var request = indexedDB.open(dbName, '4');
+
+                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');
+                    var request2 = 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!!!');
+                            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();
+                        };
+                    };
+
+                };
+
+                request.onblocked = onError;
+            });
+        });
+
 //         describe('FileError object', function () {
 //             /* eslint-disable no-undef */
 //             it('file.spec.1 should define FileError constants', function () {
@@ -310,30 +390,30 @@ exports.defineAutoTests = function () {
 //                 it('file.spec.8 should be defined', function () {
 //                     expect(window.resolveLocalFileSystemURL).toBeDefined();
 //                 });
-                it('file.spec.9 should resolve a valid file name', function (done) {
-                    var fileName = 'file.spec.9';
-                    var win = function (fileEntry) {
-                        window.customLog('log', '----- win is called ----');
-                        expect(fileEntry).toBeDefined();
-                        expect(fileEntry.isFile).toBe(true);
-                        expect(fileEntry.isDirectory).toBe(false);
-                        expect(fileEntry.name).toCanonicallyMatch(fileName);
-                        expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
-                        expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');
-                        // Clean-up
-                        deleteEntry(fileName, done);
-                    };
-                    createFile(fileName, function (entry) {
-                        window.customLog('log', '----- entry.toURL() ----');
-                        window.customLog('log', entry.toURL());
-                        setTimeout(function () {
-                            window.resolveLocalFileSystemURL(entry.toURL(), win, function (err) {
-                                window.customLog('log', '********* called *******');
-                                (failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toURL()))(err);
-                            });
-                        }, 1000);
-                    }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName), failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
-                });
+                // it('file.spec.9 should resolve a valid file name', function (done) {
+                //     var fileName = 'file.spec.9';
+                //     var win = function (fileEntry) {
+                //         window.customLog('log', '----- win is called ----');
+                //         expect(fileEntry).toBeDefined();
+                //         expect(fileEntry.isFile).toBe(true);
+                //         expect(fileEntry.isDirectory).toBe(false);
+                //         expect(fileEntry.name).toCanonicallyMatch(fileName);
+                //         expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
+                //         expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');
+                //         // Clean-up
+                //         deleteEntry(fileName, done);
+                //     };
+                //     createFile(fileName, function (entry) {
+                //         window.customLog('log', '----- entry.toURL() ----');
+                //         window.customLog('log', entry.toURL());
+                //         setTimeout(function () {
+                //             window.resolveLocalFileSystemURL(entry.toURL(), win, function (err) {
+                //                 window.customLog('log', '********* called *******');
+                //                 (failed.bind(null, done, 'window.resolveLocalFileSystemURL - Error resolving file URL: ' + entry.toURL()))(err);
+                //             });
+                //         }, 1000);
+                //     }, failed.bind(null, done, 'createFile - Error creating file: ' + fileName), failed.bind(null, done, 'createFile - Error creating file: ' + fileName));
+                // });
 //                 it('file.spec.9.1 should resolve a file even with a terminating slash', function (done) {
 //                     var fileName = 'file.spec.9.1';
 //                     var win = function (fileEntry) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org