Adding linting and fixing linter warnings. Reducing timeouts to 7 seconds.

This commit is contained in:
Dmitry Blotsky
2015-12-02 19:20:44 -08:00
parent b11415da28
commit 0913325be5
5 changed files with 255 additions and 135 deletions

10
.gitignore vendored
View File

@@ -12,12 +12,4 @@ Thumbs.db
*.swp *.swp
*.user *.user
node_modules

24
.jscsrc Normal file
View File

@@ -0,0 +1,24 @@
{
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"validateLineBreaks": "CRLF",
"validateIndentation": 4,
"requireLineFeedAtFileEnd": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"requireSpaceAfterLineComment": true,
"requireCapitalizedConstructors": true,
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do"
]
}

91
.jshintrc Normal file
View File

@@ -0,0 +1,91 @@
{
// Copied from http://jshint.com/docs/
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"latedef" : true, // true: Require variables/functions to be defined before being used
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : true, // true: Prohibit use of empty blocks
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : true, // true: Prohibit use of `++` and `--`
"quotmark" : false, // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : "strict", // Unused variables:
// true : all variables, last function parameter
// "vars" : all variables only
// "strict" : all variables, all function parameters
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line
"varstmt" : false, // true: Disallow any var statements. Only `let` and `const` are allowed.
// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : false, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
"notypeof" : false, // true: Tolerate invalid typeof operator values
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function
// Environments
"browser" : true, // Web Browser (window, document, etc)
"browserify" : false, // Browserify (node.js code in the browser)
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jasmine" : true, // Jasmine
"jquery" : false, // jQuery
"mocha" : false, // Mocha
"mootools" : false, // MooTools
"node" : false, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"phantom" : false, // PhantomJS
"prototypejs" : false, // Prototype and Scriptaculous
"qunit" : false, // QUnit
"rhino" : false, // Rhino
"shelljs" : false, // ShellJS
"typed" : false, // Globals for typed array constructions
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface
// Custom Globals
"globals" : {} // additional predefined global variables
}

View File

@@ -18,6 +18,11 @@
"browser" "browser"
] ]
}, },
"scripts": {
"test": "npm run lint && npm run style",
"style": "node_modules/.bin/jscs tests/tests.js",
"lint": "node_modules/.bin/jshint tests/tests.js"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/apache/cordova-plugin-file-transfer" "url": "https://github.com/apache/cordova-plugin-file-transfer"
@@ -43,5 +48,9 @@
"cordova-plugin-file": "^3.0.0" "cordova-plugin-file": "^3.0.0"
}, },
"author": "Apache Software Foundation", "author": "Apache Software Foundation",
"license": "Apache 2.0" "license": "Apache 2.0",
"devDependencies": {
"jscs": "^2.6.0",
"jshint": "^2.8.0"
}
} }

View File

@@ -19,21 +19,22 @@
* *
*/ */
/*global exports, cordova, FileTransfer, FileTransferError, /* global exports, cordova, FileTransfer, FileTransferError, FileUploadOptions, LocalFileSystem */
FileUploadOptions, LocalFileSystem, requestFileSystem, TEMPORARY */
/*global describe, it, expect, beforeEach, afterEach, spyOn, /* global describe, it, expect, beforeEach, afterEach, spyOn, jasmine, pending */
jasmine, pending*/
exports.defineAutoTests = function () { exports.defineAutoTests = function () {
"use strict";
// constants // constants
var ONE_SECOND = 1000; // in milliseconds
var GRACE_TIME_DELTA = 600; // in milliseconds var GRACE_TIME_DELTA = 600; // in milliseconds
var DEFAULT_FILESYSTEM_SIZE = 1024*50; //filesystem size in bytes var DEFAULT_FILESYSTEM_SIZE = 1024 * 50; // filesystem size in bytes
var UNKNOWN_HOST = "http://foobar.apache.org"; var UNKNOWN_HOST = "http://foobar.apache.org";
var HEADERS_ECHO = "http://whatheaders.com"; // NOTE: this site is very useful! var HEADERS_ECHO = "http://whatheaders.com"; // NOTE: this site is very useful!
var DOWNLOAD_TIMEOUT = 30 * 1000; // download tests sometimes need a higher timeout to complete successfully var DOWNLOAD_TIMEOUT = 7 * ONE_SECOND;
var UPLOAD_TIMEOUT = 30 * 1000; // upload tests sometimes need a higher timeout to complete successfully var UPLOAD_TIMEOUT = 7 * ONE_SECOND;
var ABORT_DELAY = 100; // for abort() tests var ABORT_DELAY = 100; // for abort() tests
// config for upload test server // config for upload test server
@@ -43,23 +44,24 @@ exports.defineAutoTests = function () {
var SERVER_WITH_CREDENTIALS = "http://cordova_user:cordova_password@cordova-vm.apache.org:5000"; var SERVER_WITH_CREDENTIALS = "http://cordova_user:cordova_password@cordova-vm.apache.org:5000";
// flags // flags
var isWindows = cordova.platformId === 'windows8' || cordova.platformId === 'windows'; var isWindows = cordova.platformId === "windows8" || cordova.platformId === "windows";
var isWP8 = cordova.platformId === 'windowsphone'; var isWP8 = cordova.platformId === "windowsphone";
var isBrowser = cordova.platformId === 'browser'; var isBrowser = cordova.platformId === "browser";
var isIE = isBrowser && navigator.userAgent.indexOf('Trident') >= 0; var isIE = isBrowser && navigator.userAgent.indexOf("Trident") >= 0;
describe('FileTransferError', function () { // tests
describe("FileTransferError", function () {
it('should exist', function () { it("should exist", function () {
expect(FileTransferError).toBeDefined(); expect(FileTransferError).toBeDefined();
}); });
it('should be constructable', function () { it("should be constructable", function () {
var transferError = new FileTransferError(); var transferError = new FileTransferError();
expect(transferError).toBeDefined(); expect(transferError).toBeDefined();
}); });
it('filetransfer.spec.3 should expose proper constants', function () { it("filetransfer.spec.3 should expose proper constants", function () {
expect(FileTransferError.FILE_NOT_FOUND_ERR).toBeDefined(); expect(FileTransferError.FILE_NOT_FOUND_ERR).toBeDefined();
expect(FileTransferError.INVALID_URL_ERR).toBeDefined(); expect(FileTransferError.INVALID_URL_ERR).toBeDefined();
@@ -75,19 +77,19 @@ exports.defineAutoTests = function () {
}); });
}); });
describe('FileUploadOptions', function () { describe("FileUploadOptions", function () {
it('should exist', function () { it("should exist", function () {
expect(FileUploadOptions).toBeDefined(); expect(FileUploadOptions).toBeDefined();
}); });
it('should be constructable', function () { it("should be constructable", function () {
var transferOptions = new FileUploadOptions(); var transferOptions = new FileUploadOptions();
expect(transferOptions).toBeDefined(); expect(transferOptions).toBeDefined();
}); });
}); });
describe('FileTransfer', function () { describe("FileTransfer", function () {
var persistentRoot, tempRoot; var persistentRoot, tempRoot;
@@ -103,7 +105,7 @@ exports.defineAutoTests = function () {
var expectedCallbacks = { var expectedCallbacks = {
unsupportedOperation: function (response) { unsupportedOperation: function (response) {
console.log('spec called unsupported functionality; response:', response); console.log("spec called unsupported functionality; response:", response);
}, },
}; };
@@ -116,7 +118,7 @@ exports.defineAutoTests = function () {
done(); done();
}, },
function () { function () {
throw new Error('failed to delete: \'' + name + '\''); throw new Error("failed to delete: '" + name + "'");
} }
); );
}, },
@@ -136,17 +138,15 @@ exports.defineAutoTests = function () {
}; };
writer.onabort = function (evt) { writer.onabort = function (evt) {
throw new Error('aborted creating test file \'' + name + '\': ' + evt); throw new Error("aborted creating test file '" + name + "': " + evt);
}; };
writer.error = function (evt) { writer.error = function (evt) {
throw new Error('aborted creating test file \'' + name + '\': ' + evt); throw new Error("aborted creating test file '" + name + "': " + evt);
}; };
if (cordova.platformId === 'browser') { if (cordova.platformId === "browser") {
// var builder = new BlobBuilder(); var blob = new Blob([content + "\n"], { type: "text/plain" });
// builder.append(content + '\n');
var blob = new Blob([content + '\n'], { type: 'text/plain' });
writer.write(blob); writer.write(blob);
} else { } else {
writer.write(content + "\n"); writer.write(content + "\n");
@@ -155,7 +155,7 @@ exports.defineAutoTests = function () {
}, unexpectedCallbacks.fileOperationFail); }, unexpectedCallbacks.fileOperationFail);
}, },
function () { function () {
throw new Error('could not create test file \'' + name + '\''); throw new Error("could not create test file '" + name + "'");
} }
); );
}; };
@@ -169,7 +169,7 @@ exports.defineAutoTests = function () {
expect(event.loaded).toBeGreaterThan(1); expect(event.loaded).toBeGreaterThan(1);
expect(event.total).toBeGreaterThan(0); expect(event.total).toBeGreaterThan(0);
expect(event.total).not.toBeLessThan(event.loaded); expect(event.total).not.toBeLessThan(event.loaded);
expect(event.lengthComputable).toBe(true, 'lengthComputable'); expect(event.lengthComputable).toBe(true, "lengthComputable");
} else { } else {
// In IE, when lengthComputable === false, event.total somehow is equal to 2^64 // In IE, when lengthComputable === false, event.total somehow is equal to 2^64
if (isIE) { if (isIE) {
@@ -182,7 +182,7 @@ exports.defineAutoTests = function () {
}; };
var getMalformedUrl = function () { var getMalformedUrl = function () {
if (cordova.platformId === 'android' || cordova.platformId === 'amazon-fireos') { if (cordova.platformId === "android" || cordova.platformId === "amazon-fireos") {
// bad protocol causes a MalformedUrlException on Android // bad protocol causes a MalformedUrlException on Android
return "httpssss://example.com"; return "httpssss://example.com";
} else { } else {
@@ -202,7 +202,7 @@ exports.defineAutoTests = function () {
done(); done();
}, },
function () { function () {
throw new Error('Failed to initialize persistent file system.'); throw new Error("Failed to initialize persistent file system.");
} }
); );
}); });
@@ -214,7 +214,7 @@ exports.defineAutoTests = function () {
done(); done();
}, },
function () { function () {
throw new Error('Failed to initialize temporary file system.'); throw new Error("Failed to initialize temporary file system.");
} }
); );
}); });
@@ -230,7 +230,7 @@ exports.defineAutoTests = function () {
} }
// but run the implementations of the expected callbacks // but run the implementations of the expected callbacks
for (callback in expectedCallbacks) { //jshint ignore: line for (callback in expectedCallbacks) { // jshint ignore: line
if (expectedCallbacks.hasOwnProperty(callback)) { if (expectedCallbacks.hasOwnProperty(callback)) {
spyOn(expectedCallbacks, callback).and.callThrough(); spyOn(expectedCallbacks, callback).and.callThrough();
} }
@@ -251,21 +251,21 @@ exports.defineAutoTests = function () {
} }
}); });
it('should initialise correctly', function() { it("should initialise correctly", function() {
expect(persistentRoot).toBeDefined(); expect(persistentRoot).toBeDefined();
expect(tempRoot).toBeDefined(); expect(tempRoot).toBeDefined();
}); });
it('should exist', function () { it("should exist", function () {
expect(FileTransfer).toBeDefined(); expect(FileTransfer).toBeDefined();
}); });
it('filetransfer.spec.1 should be constructable', function () { it("filetransfer.spec.1 should be constructable", function () {
var transfer = new FileTransfer(); var transfer = new FileTransfer();
expect(transfer).toBeDefined(); expect(transfer).toBeDefined();
}); });
it('filetransfer.spec.2 should expose proper functions', function () { it("filetransfer.spec.2 should expose proper functions", function () {
var transfer = new FileTransfer(); var transfer = new FileTransfer();
@@ -276,7 +276,7 @@ exports.defineAutoTests = function () {
expect(transfer.download).toEqual(jasmine.any(Function)); expect(transfer.download).toEqual(jasmine.any(Function));
}); });
describe('methods', function() { describe("methods", function() {
var transfer; var transfer;
@@ -292,10 +292,10 @@ exports.defineAutoTests = function () {
transfer.onprogress = isWP8 ? wp8OnProgressHandler : defaultOnProgressHandler; transfer.onprogress = isWP8 ? wp8OnProgressHandler : defaultOnProgressHandler;
// spy on the onprogress handler, but still call through to it // spy on the onprogress handler, but still call through to it
spyOn(transfer, 'onprogress').and.callThrough(); spyOn(transfer, "onprogress").and.callThrough();
root = persistentRoot; root = persistentRoot;
fileName = 'testFile.txt'; fileName = "testFile.txt";
localFilePath = root.toURL() + fileName; localFilePath = root.toURL() + fileName;
}); });
@@ -305,7 +305,7 @@ exports.defineAutoTests = function () {
// - 'httpssss://example.com' // - 'httpssss://example.com'
// - 'apache.org', with subdomains="true" // - 'apache.org', with subdomains="true"
// - 'cordova-filetransfer.jitsu.com' // - 'cordova-filetransfer.jitsu.com'
describe('download', function () { describe("download", function () {
// helpers // helpers
var verifyDownload = function (fileEntry) { var verifyDownload = function (fileEntry) {
@@ -317,13 +317,13 @@ exports.defineAutoTests = function () {
deleteFile(root, fileName, done); deleteFile(root, fileName, done);
}); });
it('ensures that test file does not exist', function (done) { it("ensures that test file does not exist", function (done) {
deleteFile(root, fileName, done); deleteFile(root, fileName, done);
}); });
it('filetransfer.spec.4 should download a file', function (done) { it("filetransfer.spec.4 should download a file", function (done) {
var fileURL = SERVER + '/robots.txt'; var fileURL = SERVER + "/robots.txt";
var fileWin = function (blob) { var fileWin = function (blob) {
@@ -331,7 +331,7 @@ exports.defineAutoTests = function () {
var lastProgressEvent = transfer.onprogress.calls.mostRecent().args[0]; var lastProgressEvent = transfer.onprogress.calls.mostRecent().args[0];
expect(lastProgressEvent.loaded).not.toBeGreaterThan(blob.size); expect(lastProgressEvent.loaded).not.toBeGreaterThan(blob.size);
} else { } else {
console.log('no progress events were emitted'); console.log("no progress events were emitted");
} }
done(); done();
@@ -348,9 +348,9 @@ exports.defineAutoTests = function () {
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail); transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
}, DOWNLOAD_TIMEOUT); }, DOWNLOAD_TIMEOUT);
it('filetransfer.spec.5 should download a file using http basic auth', function (done) { it("filetransfer.spec.5 should download a file using http basic auth", function (done) {
var fileURL = SERVER_WITH_CREDENTIALS + '/download_basic_auth'; var fileURL = SERVER_WITH_CREDENTIALS + "/download_basic_auth";
var downloadWin = function (entry) { var downloadWin = function (entry) {
verifyDownload(entry); verifyDownload(entry);
@@ -360,11 +360,11 @@ exports.defineAutoTests = function () {
transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail); transfer.download(fileURL, localFilePath, downloadWin, unexpectedCallbacks.httpFail);
}, DOWNLOAD_TIMEOUT); }, DOWNLOAD_TIMEOUT);
it('filetransfer.spec.6 should get 401 status on http basic auth failure', function (done) { it("filetransfer.spec.6 should get 401 status on http basic auth failure", function (done) {
// NOTE: // NOTE:
// using server without credentials // using server without credentials
var fileURL = SERVER + '/download_basic_auth'; var fileURL = SERVER + "/download_basic_auth";
var downloadFail = function (error) { var downloadFail = function (error) {
expect(error.http_status).toBe(401); expect(error.http_status).toBe(401);
@@ -375,7 +375,7 @@ exports.defineAutoTests = function () {
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail, null, transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail, null,
{ {
headers: { headers: {
'If-Modified-Since': 'Thu, 19 Mar 2015 00:00:00 GMT' "If-Modified-Since": "Thu, 19 Mar 2015 00:00:00 GMT"
} }
}); });
}, DOWNLOAD_TIMEOUT); }, DOWNLOAD_TIMEOUT);
@@ -388,11 +388,12 @@ exports.defineAutoTests = function () {
return; return;
} }
var fileURL = window.location.protocol + '//' + window.location.pathname.replace(/ /g, '%20'); var fileURL = window.location.protocol + "//" + window.location.pathname.replace(/ /g, "%20");
if (!/^file:/.exec(fileURL) && cordova.platformId !== 'blackberry10') { if (!/^file:/.exec(fileURL) && cordova.platformId !== "blackberry10") {
if (cordova.platformId === 'windowsphone') if (cordova.platformId === "windowsphone") {
expect(fileURL).toMatch(/^x-wmapp0:/); expect(fileURL).toMatch(/^x-wmapp0:/);
}
done(); done();
return; return;
} }
@@ -432,8 +433,8 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.11 should call the error callback on abort()", function (done) { it("filetransfer.spec.11 should call the error callback on abort()", function (done) {
var fileURL = 'http://cordova.apache.org/downloads/BlueZedEx.mp3'; var fileURL = "http://cordova.apache.org/downloads/BlueZedEx.mp3";
fileURL = fileURL + '?q=' + (new Date()).getTime(); fileURL = fileURL + "?q=" + (new Date()).getTime();
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, done); transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, done);
setTimeout(function() { setTimeout(function() {
@@ -443,7 +444,7 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.9 should not leave partial file due to abort", function (done) { it("filetransfer.spec.9 should not leave partial file due to abort", function (done) {
var fileURL = 'http://cordova.apache.org/downloads/logos_2.zip'; var fileURL = "http://cordova.apache.org/downloads/logos_2.zip";
var downloadFail = function (error) { var downloadFail = function (error) {
@@ -461,15 +462,15 @@ exports.defineAutoTests = function () {
} }
}; };
spyOn(transfer, 'onprogress').and.callThrough(); spyOn(transfer, "onprogress").and.callThrough();
transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail); transfer.download(fileURL, localFilePath, unexpectedCallbacks.httpWin, downloadFail);
}, DOWNLOAD_TIMEOUT); }, DOWNLOAD_TIMEOUT);
it("filetransfer.spec.10 should be stopped by abort() right away", function (done) { it("filetransfer.spec.10 should be stopped by abort() right away", function (done) {
var fileURL = 'http://cordova.apache.org/downloads/BlueZedEx.mp3'; var fileURL = "http://cordova.apache.org/downloads/BlueZedEx.mp3";
fileURL = fileURL + '?q=' + (new Date()).getTime(); fileURL = fileURL + "?q=" + (new Date()).getTime();
expect(transfer.abort).not.toThrow(); // should be a no-op. expect(transfer.abort).not.toThrow(); // should be a no-op.
@@ -527,7 +528,7 @@ exports.defineAutoTests = function () {
expect(error.http_status).toBe(404); expect(error.http_status).toBe(404);
expect(error.body).toBeDefined(); expect(error.body).toBeDefined();
expect(error.body).toMatch('You requested a 404'); expect(error.body).toMatch("You requested a 404");
done(); done();
}; };
@@ -575,7 +576,7 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.17 progress should work with gzip encoding", function (done) { it("filetransfer.spec.17 progress should work with gzip encoding", function (done) {
// lengthComputable false on bb10 when downloading gzip // lengthComputable false on bb10 when downloading gzip
if (cordova.platformId === 'blackberry10') { if (cordova.platformId === "blackberry10") {
pending(); pending();
return; return;
} }
@@ -592,7 +593,7 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.30 downloaded file entries should have a toNativeURL method", function (done) { it("filetransfer.spec.30 downloaded file entries should have a toNativeURL method", function (done) {
if (cordova.platformId === 'browser') { if (cordova.platformId === "browser") {
pending(); pending();
return; return;
} }
@@ -610,11 +611,11 @@ exports.defineAutoTests = function () {
expect(nativeURL).toEqual(jasmine.any(String)); expect(nativeURL).toEqual(jasmine.any(String));
if (isWindows) { if (isWindows) {
expect(nativeURL.substring(0, 14)).toBe('ms-appdata:///'); expect(nativeURL.substring(0, 14)).toBe("ms-appdata:///");
} else if (isWP8) { } else if (isWP8) {
expect(nativeURL.substring(0, 1)).toBe('/'); expect(nativeURL.substring(0, 1)).toBe("/");
} else { } else {
expect(nativeURL.substring(0, 7)).toBe('file://'); expect(nativeURL.substring(0, 7)).toBe("file://");
} }
done(); done();
@@ -650,12 +651,12 @@ exports.defineAutoTests = function () {
// paths are still valid. // paths are still valid.
cordova.exec(function (localPath) { cordova.exec(function (localPath) {
transfer.download(fileURL, localPath, downloadWin, unexpectedCallbacks.httpFail); transfer.download(fileURL, localPath, downloadWin, unexpectedCallbacks.httpFail);
}, unsupported, 'File', '_getLocalFilesystemPath', [internalFilePath]); }, unsupported, "File", "_getLocalFilesystemPath", [internalFilePath]);
}); });
it('filetransfer.spec.33 should properly handle 304', function (done) { it("filetransfer.spec.33 should properly handle 304", function (done) {
if(isWP8) { if (isWP8) {
pending(); pending();
return; return;
} }
@@ -672,14 +673,14 @@ exports.defineAutoTests = function () {
transfer.download(imageURL + "?q=" + lastModified.getTime(), localFilePath, unexpectedCallbacks.httpWin, downloadFail, null, transfer.download(imageURL + "?q=" + lastModified.getTime(), localFilePath, unexpectedCallbacks.httpWin, downloadFail, null,
{ {
headers: { headers: {
'If-Modified-Since': lastModified.toUTCString() "If-Modified-Since": lastModified.toUTCString()
} }
}); });
}, DOWNLOAD_TIMEOUT); }, DOWNLOAD_TIMEOUT);
it('filetransfer.spec.35 304 should not result in the deletion of a cached file', function (done) { it("filetransfer.spec.35 304 should not result in the deletion of a cached file", function (done) {
if(isWP8) { if (isWP8) {
pending(); pending();
return; return;
} }
@@ -700,7 +701,7 @@ exports.defineAutoTests = function () {
reader.onloadend = function () { reader.onloadend = function () {
expect(reader.result).toBeTruthy(); expect(reader.result).toBeTruthy();
if(reader.result != null) { if (reader.result !== null) {
expect(reader.result.length).toBeGreaterThan(0); expect(reader.result.length).toBeGreaterThan(0);
} }
@@ -713,7 +714,7 @@ exports.defineAutoTests = function () {
entry.file(fileWin, unexpectedCallbacks.fileSystemFail); entry.file(fileWin, unexpectedCallbacks.fileSystemFail);
}, },
function (err) { function (err) {
expect('Could not open test file \'' + fileName + '\': ' + JSON.stringify(err)).not.toBeDefined(); expect("Could not open test file '" + fileName + "': " + JSON.stringify(err)).not.toBeDefined();
done(); done();
} }
); );
@@ -725,14 +726,14 @@ exports.defineAutoTests = function () {
transfer.download(imageURL + "?q=" + (lastModified.getTime() + 1), localFilePath, unexpectedCallbacks.httpWin, downloadFail, null, transfer.download(imageURL + "?q=" + (lastModified.getTime() + 1), localFilePath, unexpectedCallbacks.httpWin, downloadFail, null,
{ {
headers: { headers: {
'If-Modified-Since': lastModified.toUTCString() "If-Modified-Since": lastModified.toUTCString()
} }
}); });
}, unexpectedCallbacks.httpFail); }, unexpectedCallbacks.httpFail);
}, DOWNLOAD_TIMEOUT); }, DOWNLOAD_TIMEOUT);
}); });
describe('upload', function() { describe("upload", function() {
var uploadParams; var uploadParams;
var uploadOptions; var uploadOptions;
@@ -754,7 +755,7 @@ exports.defineAutoTests = function () {
expect(obj.fields.value1).toBe("test"); expect(obj.fields.value1).toBe("test");
expect(obj.fields.value2).toBe("param"); expect(obj.fields.value2).toBe("param");
} catch (e) { } catch (e) {
expect(obj).not.toBeNull('returned data from server should be valid json'); expect(obj).not.toBeNull("returned data from server should be valid json");
} }
expect(transfer.onprogress).toHaveBeenCalled(); expect(transfer.onprogress).toHaveBeenCalled();
@@ -762,8 +763,8 @@ exports.defineAutoTests = function () {
beforeEach(function(done) { beforeEach(function(done) {
fileName = 'fileToUpload.txt'; fileName = "fileToUpload.txt";
fileContents = 'upload test file'; fileContents = "upload test file";
uploadParams = {}; uploadParams = {};
uploadParams.value1 = "test"; uploadParams.value1 = "test";
@@ -791,15 +792,15 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.18 should be able to upload a file", function (done) { it("filetransfer.spec.18 should be able to upload a file", function (done) {
var fileURL = SERVER + '/upload'; var fileURL = SERVER + "/upload";
var uploadWin = function (uploadResult) { var uploadWin = function (uploadResult) {
verifyUpload(uploadResult); verifyUpload(uploadResult);
if (cordova.platformId === 'ios') { if (cordova.platformId === "ios") {
expect(uploadResult.headers).toBeDefined('Expected headers to be defined.'); expect(uploadResult.headers).toBeDefined("Expected headers to be defined.");
expect(uploadResult.headers['Content-Type']).toBeDefined('Expected content-type header to be defined.'); expect(uploadResult.headers["Content-Type"]).toBeDefined("Expected content-type header to be defined.");
} }
done(); done();
@@ -824,7 +825,7 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.21 should be stopped by abort() right away", function (done) { it("filetransfer.spec.21 should be stopped by abort() right away", function (done) {
var fileURL = SERVER + '/upload'; var fileURL = SERVER + "/upload";
var startTime; var startTime;
var uploadFail = function (e) { var uploadFail = function (e) {
@@ -852,12 +853,12 @@ exports.defineAutoTests = function () {
}, GRACE_TIME_DELTA); }, GRACE_TIME_DELTA);
}; };
writeFile(root, fileName, new Array(100000).join('aborttest!'), fileWin); writeFile(root, fileName, new Array(100000).join("aborttest!"), fileWin);
}, UPLOAD_TIMEOUT); }, UPLOAD_TIMEOUT);
it("filetransfer.spec.22 should get http status and body on failure", function (done) { it("filetransfer.spec.22 should get http status and body on failure", function (done) {
var fileURL = SERVER + '/403'; var fileURL = SERVER + "/403";
var uploadFail = function (error) { var uploadFail = function (error) {
expect(error.http_status).toBe(403); expect(error.http_status).toBe(403);
@@ -904,7 +905,7 @@ exports.defineAutoTests = function () {
done(); done();
}; };
transfer.upload('does_not_exist.txt', fileURL, unexpectedCallbacks.httpWin, uploadFail); transfer.upload("does_not_exist.txt", fileURL, unexpectedCallbacks.httpWin, uploadFail);
}, UPLOAD_TIMEOUT); }, UPLOAD_TIMEOUT);
it("filetransfer.spec.26 should handle bad file path", function (done) { it("filetransfer.spec.26 should handle bad file path", function (done) {
@@ -973,20 +974,20 @@ exports.defineAutoTests = function () {
// paths are still valid. // paths are still valid.
cordova.exec(function (localPath) { cordova.exec(function (localPath) {
transfer.upload(localPath, fileURL, uploadWin, unexpectedCallbacks.httpFail, uploadOptions); transfer.upload(localPath, fileURL, uploadWin, unexpectedCallbacks.httpFail, uploadOptions);
}, unsupported, 'File', '_getLocalFilesystemPath', [internalFilePath]); }, unsupported, "File", "_getLocalFilesystemPath", [internalFilePath]);
}, UPLOAD_TIMEOUT); }, UPLOAD_TIMEOUT);
it("filetransfer.spec.31 should be able to upload a file using PUT method", function (done) { it("filetransfer.spec.31 should be able to upload a file using PUT method", function (done) {
var fileURL = SERVER + '/upload'; var fileURL = SERVER + "/upload";
var uploadWin = function (uploadResult) { var uploadWin = function (uploadResult) {
verifyUpload(uploadResult); verifyUpload(uploadResult);
if (cordova.platformId === 'ios') { if (cordova.platformId === "ios") {
expect(uploadResult.headers).toBeDefined('Expected headers to be defined.'); expect(uploadResult.headers).toBeDefined("Expected headers to be defined.");
expect(uploadResult.headers['Content-Type']).toBeDefined('Expected content-type header to be defined.'); expect(uploadResult.headers["Content-Type"]).toBeDefined("Expected content-type header to be defined.");
} }
done(); done();
@@ -1000,7 +1001,7 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.32 should be able to upload a file (non-multipart)", function (done) { it("filetransfer.spec.32 should be able to upload a file (non-multipart)", function (done) {
var fileURL = SERVER + '/upload'; var fileURL = SERVER + "/upload";
var uploadWin = function (uploadResult) { var uploadWin = function (uploadResult) {
@@ -1012,9 +1013,9 @@ exports.defineAutoTests = function () {
} }
expect(transfer.onprogress).toHaveBeenCalled(); expect(transfer.onprogress).toHaveBeenCalled();
if (cordova.platformId === 'ios') { if (cordova.platformId === "ios") {
expect(uploadResult.headers).toBeDefined('Expected headers to be defined.'); expect(uploadResult.headers).toBeDefined("Expected headers to be defined.");
expect(uploadResult.headers['Content-Type']).toBeDefined('Expected content-type header to be defined.'); expect(uploadResult.headers["Content-Type"]).toBeDefined("Expected content-type header to be defined.");
} }
done(); done();
@@ -1031,7 +1032,7 @@ exports.defineAutoTests = function () {
it("filetransfer.spec.34 should not delete a file on upload error", function (done) { it("filetransfer.spec.34 should not delete a file on upload error", function (done) {
var fileURL = SERVER + '/upload'; var fileURL = SERVER + "/upload";
var uploadFail = function (e) { var uploadFail = function (e) {
expect(e.code).toBe(FileTransferError.ABORT_ERR); expect(e.code).toBe(FileTransferError.ABORT_ERR);
@@ -1063,10 +1064,10 @@ exports.defineAutoTests = function () {
} }
}; };
spyOn(transfer, 'onprogress').and.callThrough(); spyOn(transfer, "onprogress").and.callThrough();
}; };
writeFile(root, fileName, new Array(100000).join('aborttest!'), fileWin); writeFile(root, fileName, new Array(100000).join("aborttest!"), fileWin);
}, UPLOAD_TIMEOUT); }, UPLOAD_TIMEOUT);
}); });
}); });
@@ -1078,17 +1079,20 @@ exports.defineAutoTests = function () {
/******************************************************************************/ /******************************************************************************/
exports.defineManualTests = function (contentEl, createActionButton) { exports.defineManualTests = function (contentEl, createActionButton) {
"use strict";
var imageURL = "http://apache.org/images/feather-small.gif"; var imageURL = "http://apache.org/images/feather-small.gif";
var videoURL = "http://techslides.com/demos/sample-videos/small.mp4"; var videoURL = "http://techslides.com/demos/sample-videos/small.mp4";
function clearResults() { function clearResults() {
var results = document.getElementById("info"); var results = document.getElementById("info");
results.innerHTML = ''; results.innerHTML = "";
} }
function downloadImg(source, urlFn, element, directory) { function downloadImg(source, urlFn, element, directory) {
var filename = source.substring(source.lastIndexOf("/") + 1); var filename = source.substring(source.lastIndexOf("/") + 1);
filename = (directory || '') + filename; filename = (directory || "") + filename;
function download(fileSystem) { function download(fileSystem) {
var ft = new FileTransfer(); var ft = new FileTransfer();
@@ -1120,7 +1124,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
clearResults(); clearResults();
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) { window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fileSystem) {
console.log("Checking for existing file"); console.log("Checking for existing file");
if (typeof directory !== 'undefined') { if (typeof directory !== "undefined") {
console.log("Checking for existing directory."); console.log("Checking for existing directory.");
fileSystem.root.getDirectory(directory, {}, function (dirEntry) { fileSystem.root.getDirectory(directory, {}, function (dirEntry) {
dirEntry.removeRecursively(function () { dirEntry.removeRecursively(function () {
@@ -1144,41 +1148,41 @@ exports.defineManualTests = function (contentEl, createActionButton) {
/******************************************************************************/ /******************************************************************************/
var progress_tag = '<progress id="loadingStatus" value="0" max="100" style="width: 100%;"></progress>'; var progress_tag = "<progress id=\"loadingStatus\" value=\"0\" max=\"100\" style=\"width: 100%;\"></progress>";
var file_transfer_tests = '<h2>Image File Transfer Tests</h2>' + var file_transfer_tests = "<h2>Image File Transfer Tests</h2>" +
'<h3>The following tests should display an image of the Apache feather in the status box</h3>' + "<h3>The following tests should display an image of the Apache feather in the status box</h3>" +
'<div id="cdv_image"></div>' + "<div id=\"cdv_image\"></div>" +
'<div id="native_image"></div>' + "<div id=\"native_image\"></div>" +
'<div id="non-existent_dir"></div>' + "<div id=\"non-existent_dir\"></div>" +
'<h2>Video File Transfer Tests</h2>' + "<h2>Video File Transfer Tests</h2>" +
'<h3>The following tests should display a video in the status box. The video should play when play is pressed</h3>' + "<h3>The following tests should display a video in the status box. The video should play when play is pressed</h3>" +
'<div id="cdv_video"></div>' + "<div id=\"cdv_video\"></div>" +
'<div id="native_video"></div>'; "<div id=\"native_video\"></div>";
contentEl.innerHTML = '<div id="info"></div>' + '<br>' + progress_tag + contentEl.innerHTML = "<div id=\"info\"></div>" + "<br>" + progress_tag +
file_transfer_tests; file_transfer_tests;
createActionButton('Download and display img (cdvfile)', function () { createActionButton("Download and display img (cdvfile)", function () {
downloadImg(imageURL, function (entry) { return entry.toInternalURL(); }, new Image()); downloadImg(imageURL, function (entry) { return entry.toInternalURL(); }, new Image());
}, 'cdv_image'); }, "cdv_image");
createActionButton('Download and display img (native)', function () { createActionButton("Download and display img (native)", function () {
downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image()); downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image());
}, 'native_image'); }, "native_image");
createActionButton('Download to a non-existent dir (should work)', function () { createActionButton("Download to a non-existent dir (should work)", function () {
downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image(), '/nonExistentDirTest/'); downloadImg(imageURL, function (entry) { return entry.toURL(); }, new Image(), "/nonExistentDirTest/");
}, 'non-existent_dir'); }, "non-existent_dir");
createActionButton('Download and play video (cdvfile)', function () { createActionButton("Download and play video (cdvfile)", function () {
var videoElement = document.createElement('video'); var videoElement = document.createElement("video");
videoElement.controls = "controls"; videoElement.controls = "controls";
downloadImg(videoURL, function (entry) { return entry.toInternalURL(); }, videoElement); downloadImg(videoURL, function (entry) { return entry.toInternalURL(); }, videoElement);
}, 'cdv_video'); }, "cdv_video");
createActionButton('Download and play video (native)', function () { createActionButton("Download and play video (native)", function () {
var videoElement = document.createElement('video'); var videoElement = document.createElement("video");
videoElement.controls = "controls"; videoElement.controls = "controls";
downloadImg(videoURL, function (entry) { return entry.toURL(); }, videoElement); downloadImg(videoURL, function (entry) { return entry.toURL(); }, videoElement);
}, 'native_video'); }, "native_video");
}; };