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 02:25:43 UTC

[cordova-plugin-file] branch travis_tests updated: file.spec.9 only test

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 ba2b583  file.spec.9 only test
ba2b583 is described below

commit ba2b58325128410f9b22f586552b5c43c6557ad4
Author: knaito <kn...@asial.co.jp>
AuthorDate: Tue Mar 12 11:25:26 2019 +0900

    file.spec.9 only test
---
 tests/tests.js | 451 ++++++++++++++++++++++++---------------------------------
 1 file changed, 187 insertions(+), 264 deletions(-)

diff --git a/tests/tests.js b/tests/tests.js
index 564f345..b083e18 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -42,243 +42,166 @@ exports.defineAutoTests = function () {
         }
     };
 
-    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_ = 'xentries';
-            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, '3');
-
-            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.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();
+    describe('File API', function () {
+        // Adding a Jasmine helper matcher, to report errors when comparing to FileError better.
+        var fileErrorMap = {
+            1: 'NOT_FOUND_ERR',
+            2: 'SECURITY_ERR',
+            3: 'ABORT_ERR',
+            4: 'NOT_READABLE_ERR',
+            5: 'ENCODING_ERR',
+            6: 'NO_MODIFICATION_ALLOWED_ERR',
+            7: 'INVALID_STATE_ERR',
+            8: 'SYNTAX_ERR',
+            9: 'INVALID_MODIFICATION_ERR',
+            10: 'QUOTA_EXCEEDED_ERR',
+            11: 'TYPE_MISMATCH_ERR',
+            12: 'PATH_EXISTS_ERR'
+        };
+        var root;
+        var temp_root;
+        var persistent_root;
+        beforeEach(function (done) {
+            // Custom Matchers
+            jasmine.Expectation.addMatchers({
+                toBeFileError: function () {
+                    return {
+                        compare: function (error, code) {
+                            var pass = error.code === code;
+                            return {
+                                pass: pass,
+                                message: 'Expected FileError with code ' + fileErrorMap[error.code] + ' (' + error.code + ') to be ' + fileErrorMap[code] + '(' + code + ')'
+                            };
+                        }
                     };
-                    tx2.oncomplete = function () {
-                        window.customLog('log', 'ALL OK');
-                        done();
+                },
+                toCanonicallyMatch: function () {
+                    return {
+                        compare: function (currentPath, path) {
+                            var a = path.split('/').join('').split('\\').join('');
+                            var b = currentPath.split('/').join('').split('\\').join('');
+                            var pass = a === b;
+                            return {
+                                pass: pass,
+                                message: 'Expected paths to match : ' + path + ' should be ' + currentPath
+                            };
+                        }
                     };
-                };
-
-                tx.objectStore(FILE_STORE_).put(myentry, mypath);
+                },
+                toFailWithMessage: function () {
+                    return {
+                        compare: function (error, message) { // eslint-disable-line handle-callback-err
+                            var pass = false;
+                            return {
+                                pass: pass,
+                                message: message
+                            };
+                        }
+                    };
+                },
+                toBeDataUrl: function () {
+                    return {
+                        compare: function (url) {
+                            var pass = false;
+                            // "data:application/octet-stream;base64,"
+                            var header = url.substr(0, url.indexOf(','));
+                            var headerParts = header.split(/[:;]/);
+                            if (headerParts.length === 3 &&
+                                headerParts[0] === 'data' &&
+                                headerParts[2] === 'base64') {
+                                pass = true;
+                            }
+                            var message = 'Expected ' + url + ' to be a valid data url. ' + header + ' is not valid header for data uris';
+                            return {
+                                pass: pass,
+                                message: message
+                            };
+                        }
+                    };
+                }
+            });
+            // Define global variables
+            var onError = function (e) {
+                console.log('[ERROR] Problem setting up root filesystem for test running! Error to follow.');
+                console.log(JSON.stringify(e));
             };
-
-            request.onblocked = onError;
+            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) { // eslint-disable-line no-undef
+                root = fileSystem.root;
+                // set in file.tests.js
+                persistent_root = root;
+                window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) { // eslint-disable-line no-undef
+                    temp_root = fileSystem.root;
+                    // set in file.tests.js
+                    done();
+                }, onError);
+            }, onError);
         });
-    });
-
-//     describe('File API', function () {
-//         // Adding a Jasmine helper matcher, to report errors when comparing to FileError better.
-//         var fileErrorMap = {
-//             1: 'NOT_FOUND_ERR',
-//             2: 'SECURITY_ERR',
-//             3: 'ABORT_ERR',
-//             4: 'NOT_READABLE_ERR',
-//             5: 'ENCODING_ERR',
-//             6: 'NO_MODIFICATION_ALLOWED_ERR',
-//             7: 'INVALID_STATE_ERR',
-//             8: 'SYNTAX_ERR',
-//             9: 'INVALID_MODIFICATION_ERR',
-//             10: 'QUOTA_EXCEEDED_ERR',
-//             11: 'TYPE_MISMATCH_ERR',
-//             12: 'PATH_EXISTS_ERR'
-//         };
-//         var root;
-//         var temp_root;
-//         var persistent_root;
-//         beforeEach(function (done) {
-//             // Custom Matchers
-//             jasmine.Expectation.addMatchers({
-//                 toBeFileError: function () {
-//                     return {
-//                         compare: function (error, code) {
-//                             var pass = error.code === code;
-//                             return {
-//                                 pass: pass,
-//                                 message: 'Expected FileError with code ' + fileErrorMap[error.code] + ' (' + error.code + ') to be ' + fileErrorMap[code] + '(' + code + ')'
-//                             };
-//                         }
-//                     };
-//                 },
-//                 toCanonicallyMatch: function () {
-//                     return {
-//                         compare: function (currentPath, path) {
-//                             var a = path.split('/').join('').split('\\').join('');
-//                             var b = currentPath.split('/').join('').split('\\').join('');
-//                             var pass = a === b;
-//                             return {
-//                                 pass: pass,
-//                                 message: 'Expected paths to match : ' + path + ' should be ' + currentPath
-//                             };
-//                         }
-//                     };
-//                 },
-//                 toFailWithMessage: function () {
-//                     return {
-//                         compare: function (error, message) { // eslint-disable-line handle-callback-err
-//                             var pass = false;
-//                             return {
-//                                 pass: pass,
-//                                 message: message
-//                             };
-//                         }
-//                     };
-//                 },
-//                 toBeDataUrl: function () {
-//                     return {
-//                         compare: function (url) {
-//                             var pass = false;
-//                             // "data:application/octet-stream;base64,"
-//                             var header = url.substr(0, url.indexOf(','));
-//                             var headerParts = header.split(/[:;]/);
-//                             if (headerParts.length === 3 &&
-//                                 headerParts[0] === 'data' &&
-//                                 headerParts[2] === 'base64') {
-//                                 pass = true;
-//                             }
-//                             var message = 'Expected ' + url + ' to be a valid data url. ' + header + ' is not valid header for data uris';
-//                             return {
-//                                 pass: pass,
-//                                 message: message
-//                             };
-//                         }
-//                     };
-//                 }
-//             });
-//             // Define global variables
-//             var onError = function (e) {
-//                 console.log('[ERROR] Problem setting up root filesystem for test running! Error to follow.');
-//                 console.log(JSON.stringify(e));
-//             };
-//             window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) { // eslint-disable-line no-undef
-//                 root = fileSystem.root;
-//                 // set in file.tests.js
-//                 persistent_root = root;
-//                 window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) { // eslint-disable-line no-undef
-//                     temp_root = fileSystem.root;
-//                     // set in file.tests.js
-//                     done();
-//                 }, onError);
-//             }, onError);
-//         });
-//         // HELPER FUNCTIONS
-//         // deletes specified file or directory
-//         var deleteEntry = function (name, success, error) {
-//             // deletes entry, if it exists
-//             // entry.remove success callback is required: http://www.w3.org/TR/2011/WD-file-system-api-20110419/#the-entry-interface
-//             success = success || function () {};
-//             error = error || failed.bind(null, success, 'deleteEntry failed.');
-
-//             window.resolveLocalFileSystemURL(root.toURL() + '/' + name, function (entry) {
-//                 if (entry.isDirectory === true) {
-//                     entry.removeRecursively(success, error);
-//                 } else {
-//                     entry.remove(success, error);
-//                 }
-//             }, success);
-//         };
-//         // deletes file, if it exists, then invokes callback
-//         var deleteFile = function (fileName, callback) {
-//             // entry.remove success callback is required: http://www.w3.org/TR/2011/WD-file-system-api-20110419/#the-entry-interface
-//             callback = callback || function () {};
-
-//             root.getFile(fileName, null, // remove file system entry
-//                 function (entry) {
-//                     entry.remove(callback, function () {
-//                         console.log('[ERROR] deleteFile cleanup method invoked fail callback.');
-//                     });
-//                 }, // doesn't exist
-//                 callback);
-//         };
-//         // deletes and re-creates the specified file
-//         var createFile = function (fileName, success, error) {
-//             deleteEntry(fileName, function () {
-//                 root.getFile(fileName, {
-//                     create: true
-//                 }, success, error);
-//             }, error);
-//         };
-//         // deletes and re-creates the specified directory
-//         var createDirectory = function (dirName, success, error) {
-//             deleteEntry(dirName, function () {
-//                 root.getDirectory(dirName, {
-//                     create: true
-//                 }, success, error);
-//             }, error);
-//         };
-//         function failed (done, msg, error) {
-//             window.customLog('log', 'failed is called : ' + msg);
-//             var info = typeof msg === 'undefined' ? 'Unexpected error callback' : msg;
-//             var codeMsg = (error && error.code) ? (': ' + fileErrorMap[error.code]) : '';
-//             expect(true).toFailWithMessage(info + '\n' + JSON.stringify(error) + codeMsg);
-//             done();
-//         }
-//         var succeed = function (done, msg) {
-//             var info = typeof msg === 'undefined' ? 'Unexpected success callback' : msg;
-//             expect(true).toFailWithMessage(info);
-//             done();
-//         };
-//         var joinURL = function (base, extension) {
-//             if (base.charAt(base.length - 1) !== '/' && extension.charAt(0) !== '/') {
-//                 return base + '/' + extension;
-//             }
-//             if (base.charAt(base.length - 1) === '/' && extension.charAt(0) === '/') {
-//                 return base + extension.substring(1);
-//             }
-//             return base + extension;
-//         };
+        // HELPER FUNCTIONS
+        // deletes specified file or directory
+        var deleteEntry = function (name, success, error) {
+            // deletes entry, if it exists
+            // entry.remove success callback is required: http://www.w3.org/TR/2011/WD-file-system-api-20110419/#the-entry-interface
+            success = success || function () {};
+            error = error || failed.bind(null, success, 'deleteEntry failed.');
+
+            window.resolveLocalFileSystemURL(root.toURL() + '/' + name, function (entry) {
+                if (entry.isDirectory === true) {
+                    entry.removeRecursively(success, error);
+                } else {
+                    entry.remove(success, error);
+                }
+            }, success);
+        };
+        // deletes file, if it exists, then invokes callback
+        var deleteFile = function (fileName, callback) {
+            // entry.remove success callback is required: http://www.w3.org/TR/2011/WD-file-system-api-20110419/#the-entry-interface
+            callback = callback || function () {};
+
+            root.getFile(fileName, null, // remove file system entry
+                function (entry) {
+                    entry.remove(callback, function () {
+                        console.log('[ERROR] deleteFile cleanup method invoked fail callback.');
+                    });
+                }, // doesn't exist
+                callback);
+        };
+        // deletes and re-creates the specified file
+        var createFile = function (fileName, success, error) {
+            deleteEntry(fileName, function () {
+                root.getFile(fileName, {
+                    create: true
+                }, success, error);
+            }, error);
+        };
+        // deletes and re-creates the specified directory
+        var createDirectory = function (dirName, success, error) {
+            deleteEntry(dirName, function () {
+                root.getDirectory(dirName, {
+                    create: true
+                }, success, error);
+            }, error);
+        };
+        function failed (done, msg, error) {
+            window.customLog('log', 'failed is called : ' + msg);
+            var info = typeof msg === 'undefined' ? 'Unexpected error callback' : msg;
+            var codeMsg = (error && error.code) ? (': ' + fileErrorMap[error.code]) : '';
+            expect(true).toFailWithMessage(info + '\n' + JSON.stringify(error) + codeMsg);
+            done();
+        }
+        var succeed = function (done, msg) {
+            var info = typeof msg === 'undefined' ? 'Unexpected success callback' : msg;
+            expect(true).toFailWithMessage(info);
+            done();
+        };
+        var joinURL = function (base, extension) {
+            if (base.charAt(base.length - 1) !== '/' && extension.charAt(0) !== '/') {
+                return base + '/' + extension;
+            }
+            if (base.charAt(base.length - 1) === '/' && extension.charAt(0) === '/') {
+                return base + extension.substring(1);
+            }
+            return base + extension;
+        };
 //         describe('FileError object', function () {
 //             /* eslint-disable no-undef */
 //             it('file.spec.1 should define FileError constants', function () {
@@ -296,7 +219,7 @@ exports.defineAutoTests = function () {
 //                 expect(FileError.PATH_EXISTS_ERR).toBe(12);
 //             });
 //         });
-//         describe('LocalFileSystem', function () {
+        describe('LocalFileSystem', function () {
 //             it('file.spec.2 should define LocalFileSystem constants', function () {
 //                 expect(LocalFileSystem.TEMPORARY).toBe(0);
 //                 expect(LocalFileSystem.PERSISTENT).toBe(1);
@@ -383,34 +306,34 @@ exports.defineAutoTests = function () {
 //                     window.requestFileSystem(-1, 0, succeed.bind(null, done, 'window.requestFileSystem'), fail);
 //                 });
 //             });
-//             describe('window.resolveLocalFileSystemURL', function () {
+            describe('window.resolveLocalFileSystemURL', 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) {
@@ -527,8 +450,8 @@ exports.defineAutoTests = function () {
 //                     // lookup file system entry
 //                     window.resolveLocalFileSystemURL(fileName, succeed.bind(null, done, 'window.resolveLocalFileSystemURL - Error unexpected callback resolving file URI: ' + fileName), fail);
 //                 });
-//             });
-//         });
+            });
+        });
 //         // LocalFileSystem
 //         describe('Metadata interface', function () {
 //             it('file.spec.13 should exist and have the right properties', function () {
@@ -4079,9 +4002,9 @@ exports.defineAutoTests = function () {
 //                 }, failed.bind(null, done, 'deleteEntry - Error removing directory : ' + dstDir));
 //             }, MEDIUM_TIMEOUT);
 //         }
-//     });
+    });
 
-// };
+};
 // //* *****************************************************************************************
 // //* **************************************Manual Tests***************************************
 // //* *****************************************************************************************
@@ -4255,4 +4178,4 @@ exports.defineAutoTests = function () {
 //     createActionButton('show-contact-image', function () {
 //         resolveFsContactImage();
 //     }, 'contactButton');
-};
+// };


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