From 16c4325fef80327bceccedb491e29064da79b556 Mon Sep 17 00:00:00 2001 From: Audrey So Date: Fri, 14 Jul 2017 14:19:05 -0700 Subject: [PATCH] CB-12895 : updated src files to use eslint format --- appium-tests/android/android.spec.js | 2 - appium-tests/helpers/cameraHelper.js | 1 - appium-tests/ios/ios.spec.js | 2 - package.json | 2 +- src/blackberry10/index.js | 170 +++++++++++++-------------- src/browser/CameraProxy.js | 6 +- src/windows/CameraProxy.js | 123 ++++++++++--------- tests/tests.js | 138 +++++++++++----------- 8 files changed, 219 insertions(+), 225 deletions(-) diff --git a/appium-tests/android/android.spec.js b/appium-tests/android/android.spec.js index d21959f..b756987 100644 --- a/appium-tests/android/android.spec.js +++ b/appium-tests/android/android.spec.js @@ -1,5 +1,3 @@ -/*jshint node: true, jasmine: true */ - /* * * Licensed to the Apache Software Foundation (ASF) under one diff --git a/appium-tests/helpers/cameraHelper.js b/appium-tests/helpers/cameraHelper.js index e1d21bc..72f7a27 100644 --- a/appium-tests/helpers/cameraHelper.js +++ b/appium-tests/helpers/cameraHelper.js @@ -1,4 +1,3 @@ -/*jshint node: true */ /* global Q, resolveLocalFileSystemURL, Camera, cordova */ /* * diff --git a/appium-tests/ios/ios.spec.js b/appium-tests/ios/ios.spec.js index 1c5f65d..d4eebde 100644 --- a/appium-tests/ios/ios.spec.js +++ b/appium-tests/ios/ios.spec.js @@ -1,5 +1,3 @@ -/*jshint node: true, jasmine: true */ - /* * * Licensed to the Apache Software Foundation (ASF) under one diff --git a/package.json b/package.json index b99e8f4..0d89a1f 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ }, "devDependencies": { "dmd-plugin-cordova-plugin": "^0.1.0", - "eslint": "^4.2.0", + "eslint": "^4.3.0", "eslint-config-semistandard": "^11.0.0", "eslint-config-standard": "^10.2.1", "eslint-plugin-import": "^2.3.0", diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js index 094e897..2ec7f69 100644 --- a/src/blackberry10/index.js +++ b/src/blackberry10/index.js @@ -22,17 +22,17 @@ /* globals qnx, FileError, PluginResult */ var PictureSourceType = { - PHOTOLIBRARY: 0, // Choose image from picture library (same as SAVEDPHOTOALBUM for Android) - CAMERA: 1, // Take picture from camera - SAVEDPHOTOALBUM: 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) - }, - DestinationType = { - DATA_URL: 0, // Return base64 encoded string - FILE_URI: 1, // Return file uri (content://media/external/images/media/2 for Android) - NATIVE_URI: 2 // Return native uri (eg. asset-library://... for iOS) - }, - savePath = window.qnx.webplatform.getApplication().getEnv('HOME').replace('/data', '') + '/shared/camera/', - invokeAvailable = true; + PHOTOLIBRARY: 0, // Choose image from picture library (same as SAVEDPHOTOALBUM for Android) + CAMERA: 1, // Take picture from camera + SAVEDPHOTOALBUM: 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) +}; +var DestinationType = { + DATA_URL: 0, // Return base64 encoded string + FILE_URI: 1, // Return file uri (content://media/external/images/media/2 for Android) + NATIVE_URI: 2 // Return native uri (eg. asset-library://... for iOS) +}; +var savePath = window.qnx.webplatform.getApplication().getEnv('HOME').replace('/data', '') + '/shared/camera/'; +var invokeAvailable = true; // check for camera card - it isn't currently availble in work perimeter window.qnx.webplatform.getApplication().invocation.queryTargets( @@ -54,7 +54,7 @@ function showCameraDialog (done, cancel, fail) { wv.allowQnxObject = true; wv.allowRpc = true; wv.zOrder = 1; - wv.setGeometry(0, 0, screen.width, screen.height); + wv.setGeometry(0, 0, screen.width, screen.height); /* eslint no-undef : 0 */ wv.backgroundColor = 0x00000000; wv.active = true; wv.visible = true; @@ -71,7 +71,7 @@ function showCameraDialog (done, cancel, fail) { } else { saveImage(args[1], done, fail); } - wv.un('JavaScriptCallback', arguments.callee); + wv.un('JavaScriptCallback', arguments.callee); /* eslint no-caller : 0 */ wv.visible = false; wv.destroy(); qnx.webplatform.getApplication().unlockRotation(); @@ -87,19 +87,19 @@ function showCameraDialog (done, cancel, fail) { // create unique name for saved file (same pattern as BB10 camera app) function imgName () { - var date = new Date(), - pad = function (n) { return n < 10 ? '0' + n : n; }; + var date = new Date(); + var pad = function (n) { return n < 10 ? '0' + n : n; }; return 'IMG_' + date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) + '_' + pad(date.getHours()) + pad(date.getMinutes()) + pad(date.getSeconds()) + '.png'; } // convert dataURI to Blob function dataURItoBlob (dataURI) { - var byteString = atob(dataURI.split(',')[1]), - mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0], - arrayBuffer = new ArrayBuffer(byteString.length), - ia = new Uint8Array(arrayBuffer), - i; + var byteString = atob(dataURI.split(',')[1]); + var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; + var arrayBuffer = new ArrayBuffer(byteString.length); + var ia = new Uint8Array(arrayBuffer); + var i; for (i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } @@ -124,85 +124,85 @@ function saveImage (data, success, fail) { } function encodeBase64 (filePath, callback) { - var sandbox = window.qnx.webplatform.getController().setFileSystemSandbox, // save original sandbox value - errorHandler = function (err) { - var msg = 'An error occured: '; + var sandbox = window.qnx.webplatform.getController().setFileSystemSandbox; // save original sandbox value + var errorHandler = function (err) { + var msg = 'An error occured: '; - switch (err.code) { - case FileError.NOT_FOUND_ERR: - msg += 'File or directory not found'; - break; + switch (err.code) { + case FileError.NOT_FOUND_ERR: + msg += 'File or directory not found'; + break; - case FileError.NOT_READABLE_ERR: - msg += 'File or directory not readable'; - break; + case FileError.NOT_READABLE_ERR: + msg += 'File or directory not readable'; + break; - case FileError.PATH_EXISTS_ERR: - msg += 'File or directory already exists'; - break; + case FileError.PATH_EXISTS_ERR: + msg += 'File or directory already exists'; + break; - case FileError.TYPE_MISMATCH_ERR: - msg += 'Invalid file type'; - break; + case FileError.TYPE_MISMATCH_ERR: + msg += 'Invalid file type'; + break; - default: - msg += 'Unknown Error'; - break; - } + default: + msg += 'Unknown Error'; + break; + } - // set it back to original value - window.qnx.webplatform.getController().setFileSystemSandbox = sandbox; - callback(msg); - }, - gotFile = function (fileEntry) { - fileEntry.file(function (file) { - var reader = new FileReader(); + // set it back to original value + window.qnx.webplatform.getController().setFileSystemSandbox = sandbox; + callback(msg); + }; + var gotFile = function (fileEntry) { + fileEntry.file(function (file) { + var reader = new FileReader(); - reader.onloadend = function (e) { - // set it back to original value - window.qnx.webplatform.getController().setFileSystemSandbox = sandbox; - callback(this.result); - }; + reader.onloadend = function (e) { + // set it back to original value + window.qnx.webplatform.getController().setFileSystemSandbox = sandbox; + callback(this.result); + }; - reader.readAsDataURL(file); - }, errorHandler); - }, - onInitFs = function (fs) { - window.qnx.webplatform.getController().setFileSystemSandbox = false; - fs.root.getFile(filePath, {create: false}, gotFile, errorHandler); - }; + reader.readAsDataURL(file); + }, errorHandler); + }; + var onInitFs = function (fs) { + window.qnx.webplatform.getController().setFileSystemSandbox = false; + fs.root.getFile(filePath, {create: false}, gotFile, errorHandler); + }; window.webkitRequestFileSystem(window.TEMPORARY, 10 * 1024 * 1024, onInitFs, errorHandler); // set size to 10MB max } module.exports = { takePicture: function (success, fail, args, env) { - var destinationType = JSON.parse(decodeURIComponent(args[1])), - sourceType = JSON.parse(decodeURIComponent(args[2])), - result = new PluginResult(args, env), - done = function (data) { - if (destinationType === DestinationType.FILE_URI) { - data = 'file://' + data; - result.callbackOk(data, false); - } else { - encodeBase64(data, function (data) { - if (/^data:/.test(data)) { - data = data.slice(data.indexOf(',') + 1); - result.callbackOk(data, false); - } else { - result.callbackError(data, false); - } - }); - } - }, - cancel = function (reason) { - result.callbackError(reason, false); - }, - invoked = function (error) { - if (error) { - result.callbackError(error, false); - } - }; + var destinationType = JSON.parse(decodeURIComponent(args[1])); + var sourceType = JSON.parse(decodeURIComponent(args[2])); + var result = new PluginResult(args, env); + var done = function (data) { + if (destinationType === DestinationType.FILE_URI) { + data = 'file://' + data; + result.callbackOk(data, false); + } else { + encodeBase64(data, function (data) { + if (/^data:/.test(data)) { + data = data.slice(data.indexOf(',') + 1); + result.callbackOk(data, false); + } else { + result.callbackError(data, false); + } + }); + } + }; + var cancel = function (reason) { + result.callbackError(reason, false); + }; + var invoked = function (error) { + if (error) { + result.callbackError(error, false); + } + }; switch (sourceType) { case PictureSourceType.CAMERA: diff --git a/src/browser/CameraProxy.js b/src/browser/CameraProxy.js index ff4971a..38f241f 100644 --- a/src/browser/CameraProxy.js +++ b/src/browser/CameraProxy.js @@ -33,7 +33,7 @@ function takePicture (success, error, opts) { input.name = 'files[]'; input.onchange = function (inputEvent) { - var reader = new FileReader(); + var reader = new FileReader(); /* eslint no-undef : 0 */ reader.onload = function (readerEvent) { input.parentNode.removeChild(input); @@ -54,8 +54,8 @@ function capture (success, errorCallback, opts) { var targetWidth = opts[3]; var targetHeight = opts[4]; - targetWidth = targetWidth == -1 ? 320 : targetWidth; - targetHeight = targetHeight == -1 ? 240 : targetHeight; + targetWidth = targetWidth === -1 ? 320 : targetWidth; + targetHeight = targetHeight === -1 ? 240 : targetHeight; var video = document.createElement('video'); var button = document.createElement('button'); diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js index 7a2594f..e20d28d 100644 --- a/src/windows/CameraProxy.js +++ b/src/windows/CameraProxy.js @@ -19,7 +19,6 @@ * */ -/* jshint unused:true, undef:true, browser:true */ /* global Windows:true, URL:true, module:true, require:true, WinJS:true */ var Camera = require('./Camera'); @@ -56,7 +55,7 @@ module.exports = { takePicture: function (successCallback, errorCallback, args) { var sourceType = args[2]; - if (sourceType != Camera.PictureSourceType.CAMERA) { + if (sourceType !== Camera.PictureSourceType.CAMERA) { takePictureFromFile(successCallback, errorCallback, args); } else { takePictureFromCamera(successCallback, errorCallback, args); @@ -79,7 +78,7 @@ function resizeImage (successCallback, errorCallback, file, targetWidth, targetH var tempPhotoFileName = ''; var targetContentType = ''; - if (encodingType == Camera.EncodingType.PNG) { + if (encodingType === Camera.EncodingType.PNG) { tempPhotoFileName = 'camera_cordova_temp_return.png'; targetContentType = 'image/png'; } else { @@ -95,7 +94,7 @@ function resizeImage (successCallback, errorCallback, file, targetWidth, targetH .then(function (buffer) { var strBase64 = encodeToBase64String(buffer); var imageData = 'data:' + file.contentType + ';base64,' + strBase64; - var image = new Image(); + var image = new Image(); /* eslint no-undef : 0 */ image.src = imageData; image.onload = function () { var ratio = Math.min(targetWidth / this.width, targetHeight / this.height); @@ -127,8 +126,7 @@ function resizeImage (successCallback, errorCallback, file, targetWidth, targetH }) .done(null, function (err) { errorCallback(err); - } - ); + }); } // Because of asynchronous method, so let the successCallback be called in it. @@ -137,7 +135,7 @@ function resizeImageBase64 (successCallback, errorCallback, file, targetWidth, t var strBase64 = encodeToBase64String(buffer); var imageData = 'data:' + file.contentType + ';base64,' + strBase64; - var image = new Image(); + var image = new Image(); /* eslint no-undef : 0 */ image.src = imageData; image.onload = function () { @@ -173,11 +171,11 @@ function takePictureFromFile (successCallback, errorCallback, args) { } function takePictureFromFileWP (successCallback, errorCallback, args) { - var mediaType = args[6], - destinationType = args[1], - targetWidth = args[3], - targetHeight = args[4], - encodingType = args[5]; + var mediaType = args[6]; + var destinationType = args[1]; + var targetWidth = args[3]; + var targetHeight = args[4]; + var encodingType = args[5]; /* Need to add and remove an event listener to catch activation state @@ -192,13 +190,13 @@ function takePictureFromFileWP (successCallback, errorCallback, args) { webUIApp.removeEventListener('activated', filePickerActivationHandler); return; } - if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) { + if (destinationType === Camera.DestinationType.FILE_URI || destinationType === Camera.DestinationType.NATIVE_URI) { if (targetHeight > 0 && targetWidth > 0) { resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType); } else { var storageFolder = getAppData().localFolder; file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) { - if (destinationType == Camera.DestinationType.NATIVE_URI) { + if (destinationType === Camera.DestinationType.NATIVE_URI) { successCallback('ms-appdata:///local/' + storageFile.name); } else { successCallback(URL.createObjectURL(storageFile)); @@ -222,10 +220,10 @@ function takePictureFromFileWP (successCallback, errorCallback, args) { }; var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker(); - if (mediaType == Camera.MediaType.PICTURE) { + if (mediaType === Camera.MediaType.PICTURE) { fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']); fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary; - } else if (mediaType == Camera.MediaType.VIDEO) { + } else if (mediaType === Camera.MediaType.VIDEO) { fileOpenPicker.fileTypeFilter.replaceAll(windowsPhoneVideoContainers); fileOpenPicker.suggestedStartLocation = pickerLocId.videosLibrary; } else { @@ -238,17 +236,17 @@ function takePictureFromFileWP (successCallback, errorCallback, args) { } function takePictureFromFileWindows (successCallback, errorCallback, args) { - var mediaType = args[6], - destinationType = args[1], - targetWidth = args[3], - targetHeight = args[4], - encodingType = args[5]; + var mediaType = args[6]; + var destinationType = args[1]; + var targetWidth = args[3]; + var targetHeight = args[4]; + var encodingType = args[5]; var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker(); - if (mediaType == Camera.MediaType.PICTURE) { + if (mediaType === Camera.MediaType.PICTURE) { fileOpenPicker.fileTypeFilter.replaceAll(['.png', '.jpg', '.jpeg']); fileOpenPicker.suggestedStartLocation = pickerLocId.picturesLibrary; - } else if (mediaType == Camera.MediaType.VIDEO) { + } else if (mediaType === Camera.MediaType.VIDEO) { fileOpenPicker.fileTypeFilter.replaceAll(windowsVideoContainers); fileOpenPicker.suggestedStartLocation = pickerLocId.videosLibrary; } else { @@ -261,13 +259,13 @@ function takePictureFromFileWindows (successCallback, errorCallback, args) { errorCallback("User didn't choose a file."); return; } - if (destinationType == Camera.DestinationType.FILE_URI || destinationType == Camera.DestinationType.NATIVE_URI) { + if (destinationType === Camera.DestinationType.FILE_URI || destinationType === Camera.DestinationType.NATIVE_URI) { if (targetHeight > 0 && targetWidth > 0) { resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight, encodingType); } else { var storageFolder = getAppData().localFolder; file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).done(function (storageFile) { - if (destinationType == Camera.DestinationType.NATIVE_URI) { + if (destinationType === Camera.DestinationType.NATIVE_URI) { successCallback('ms-appdata:///local/' + storageFile.name); } else { successCallback(URL.createObjectURL(storageFile)); @@ -303,19 +301,19 @@ function takePictureFromCamera (successCallback, errorCallback, args) { function takePictureFromCameraWP (successCallback, errorCallback, args) { // We are running on WP8.1 which lacks CameraCaptureUI class // so we need to use MediaCapture class instead and implement custom UI for camera - var destinationType = args[1], - targetWidth = args[3], - targetHeight = args[4], - encodingType = args[5], - saveToPhotoAlbum = args[9], - cameraDirection = args[11], - capturePreview = null, - cameraCaptureButton = null, - cameraCancelButton = null, - capture = null, - captureSettings = null, - CaptureNS = Windows.Media.Capture, - sensor = null; + var destinationType = args[1]; + var targetWidth = args[3]; + var targetHeight = args[4]; + var encodingType = args[5]; + var saveToPhotoAlbum = args[9]; + var cameraDirection = args[11]; + var capturePreview = null; + var cameraCaptureButton = null; + var cameraCancelButton = null; + var capture = null; + var captureSettings = null; + var CaptureNS = Windows.Media.Capture; + var sensor = null; function createCameraUI () { // create style for take and cancel buttons @@ -367,7 +365,7 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) { } devices.forEach(function (currDev) { - if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel == expectedPanel) { + if (currDev.enclosureLocation.panel && currDev.enclosureLocation.panel === expectedPanel) { captureSettings.videoDeviceId = currDev.id; } }); @@ -480,11 +478,11 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) { function captureAction () { - var encodingProperties, - fileName, - tempFolder = getAppData().temporaryFolder; + var encodingProperties; + var fileName; + var tempFolder = getAppData().temporaryFolder; - if (encodingType == Camera.EncodingType.PNG) { + if (encodingType === Camera.EncodingType.PNG) { fileName = 'photo.png'; encodingProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createPng(); } else { @@ -656,22 +654,22 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) { // https://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmaprotation.aspx switch (orientation) { - // portrait + // portrait case Windows.Devices.Sensors.SimpleOrientation.notRotated: return Windows.Media.Capture.VideoRotation.clockwise90Degrees; - // landscape + // landscape case Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise: return Windows.Media.Capture.VideoRotation.none; - // portrait-flipped (not supported by WinPhone Apps) + // portrait-flipped (not supported by WinPhone Apps) case Windows.Devices.Sensors.SimpleOrientation.rotated180DegreesCounterclockwise: - // Falling back to portrait default + // Falling back to portrait default return Windows.Media.Capture.VideoRotation.clockwise90Degrees; - // landscape-flipped + // landscape-flipped case Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise: return Windows.Media.Capture.VideoRotation.clockwise180Degrees; - // faceup & facedown + // faceup & facedown default: - // Falling back to portrait default + // Falling back to portrait default return Windows.Media.Capture.VideoRotation.clockwise90Degrees; } } @@ -693,18 +691,18 @@ function takePictureFromCameraWP (successCallback, errorCallback, args) { } function takePictureFromCameraWindows (successCallback, errorCallback, args) { - var destinationType = args[1], - targetWidth = args[3], - targetHeight = args[4], - encodingType = args[5], - allowCrop = !!args[7], - saveToPhotoAlbum = args[9], - WMCapture = Windows.Media.Capture, - cameraCaptureUI = new WMCapture.CameraCaptureUI(); + var destinationType = args[1]; + var targetWidth = args[3]; + var targetHeight = args[4]; + var encodingType = args[5]; + var allowCrop = !!args[7]; + var saveToPhotoAlbum = args[9]; + var WMCapture = Windows.Media.Capture; + var cameraCaptureUI = new WMCapture.CameraCaptureUI(); cameraCaptureUI.photoSettings.allowCropping = allowCrop; - if (encodingType == Camera.EncodingType.PNG) { + if (encodingType === Camera.EncodingType.PNG) { cameraCaptureUI.photoSettings.format = WMCapture.CameraCaptureUIPhotoFormat.png; } else { cameraCaptureUI.photoSettings.format = WMCapture.CameraCaptureUIPhotoFormat.jpeg; @@ -715,14 +713,13 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) { var UIMaxRes = WMCapture.CameraCaptureUIMaxPhotoResolution; var totalPixels = targetWidth * targetHeight; - if (targetWidth == -1 && targetHeight == -1) { + if (targetWidth === -1 && targetHeight === -1) { maxRes = UIMaxRes.highestAvailable; - } // Temp fix for CB-10539 /* else if (totalPixels <= 320 * 240) { maxRes = UIMaxRes.verySmallQvga; } */ - else if (totalPixels <= 640 * 480) { + } else if (totalPixels <= 640 * 480) { maxRes = UIMaxRes.smallVga; } else if (totalPixels <= 1024 * 768) { maxRes = UIMaxRes.mediumXga; @@ -784,7 +781,7 @@ function takePictureFromCameraWindows (successCallback, errorCallback, args) { function savePhoto (picture, options, successCallback, errorCallback) { // success callback for capture operation var success = function (picture) { - if (options.destinationType == Camera.DestinationType.FILE_URI || options.destinationType == Camera.DestinationType.NATIVE_URI) { + if (options.destinationType === Camera.DestinationType.FILE_URI || options.destinationType === Camera.DestinationType.NATIVE_URI) { if (options.targetHeight > 0 && options.targetWidth > 0) { resizeImage(successCallback, errorCallback, picture, options.targetWidth, options.targetHeight, options.encodingType); } else { diff --git a/tests/tests.js b/tests/tests.js index 0c85188..f45b8b6 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -20,26 +20,26 @@ */ /* globals Camera, resolveLocalFileSystemURL, FileEntry, CameraPopoverOptions, FileTransfer, FileUploadOptions, LocalFileSystem, MSApp */ -/* jshint jasmine: true */ +/* eslint-env jasmine */ exports.defineAutoTests = function () { describe('Camera (navigator.camera)', function () { - it("should exist", function () { + it('should exist', function () { expect(navigator.camera).toBeDefined(); }); - it("should contain a getPicture function", function () { + it('should contain a getPicture function', function () { expect(navigator.camera.getPicture).toBeDefined(); - expect(typeof navigator.camera.getPicture == 'function').toBe(true); + expect(typeof navigator.camera.getPicture === 'function').toBe(true); }); }); describe('Camera Constants (window.Camera + navigator.camera)', function () { - it("camera.spec.1 window.Camera should exist", function () { + it('camera.spec.1 window.Camera should exist', function () { expect(window.Camera).toBeDefined(); }); - it("camera.spec.2 should contain three DestinationType constants", function () { + it('camera.spec.2 should contain three DestinationType constants', function () { expect(Camera.DestinationType.DATA_URL).toBe(0); expect(Camera.DestinationType.FILE_URI).toBe(1); expect(Camera.DestinationType.NATIVE_URI).toBe(2); @@ -48,14 +48,14 @@ exports.defineAutoTests = function () { expect(navigator.camera.DestinationType.NATIVE_URI).toBe(2); }); - it("camera.spec.3 should contain two EncodingType constants", function () { + it('camera.spec.3 should contain two EncodingType constants', function () { expect(Camera.EncodingType.JPEG).toBe(0); expect(Camera.EncodingType.PNG).toBe(1); expect(navigator.camera.EncodingType.JPEG).toBe(0); expect(navigator.camera.EncodingType.PNG).toBe(1); }); - it("camera.spec.4 should contain three MediaType constants", function () { + it('camera.spec.4 should contain three MediaType constants', function () { expect(Camera.MediaType.PICTURE).toBe(0); expect(Camera.MediaType.VIDEO).toBe(1); expect(Camera.MediaType.ALLMEDIA).toBe(2); @@ -64,7 +64,7 @@ exports.defineAutoTests = function () { expect(navigator.camera.MediaType.ALLMEDIA).toBe(2); }); - it("camera.spec.5 should contain three PictureSourceType constants", function () { + it('camera.spec.5 should contain three PictureSourceType constants', function () { expect(Camera.PictureSourceType.PHOTOLIBRARY).toBe(0); expect(Camera.PictureSourceType.CAMERA).toBe(1); expect(Camera.PictureSourceType.SAVEDPHOTOALBUM).toBe(2); @@ -75,7 +75,6 @@ exports.defineAutoTests = function () { }); }; - /******************************************************************************/ /******************************************************************************/ /******************************************************************************/ @@ -86,7 +85,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { var fileEntry = null; var pageStartTime = +new Date(); - //default camera options + // default camera options var camQualityDefault = ['50', 50]; var camDestinationTypeDefault = ['FILE_URI', 1]; var camPictureSourceTypeDefault = ['CAMERA', 1]; @@ -96,12 +95,12 @@ exports.defineManualTests = function (contentEl, createActionButton) { var camCorrectOrientationDefault = ['correctOrientation', false]; var camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true]; - function log(value) { + function log (value) { console.log(value); document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n'; } - function clearStatus() { + function clearStatus () { document.getElementById('camera_status').innerHTML = ''; document.getElementById('camera_image').src = 'about:blank'; var canvas = document.getElementById('canvas'); @@ -111,11 +110,11 @@ exports.defineManualTests = function (contentEl, createActionButton) { fileEntry = null; } - function setPicture(url, callback) { + function setPicture (url, callback) { try { window.atob(url); // if we got here it is a base64 string (DATA_URL) - url = "data:image/jpeg;base64," + url; + url = 'data:image/jpeg;base64,' + url; } catch (e) { // not DATA_URL } @@ -134,11 +133,11 @@ exports.defineManualTests = function (contentEl, createActionButton) { }; } - function onGetPictureError(e) { + function onGetPictureError (e) { log('Error getting picture: ' + (e.code || e)); } - function getPictureWin(data) { + function getPictureWin (data) { setPicture(data); // TODO: Fix resolveLocalFileSystemURI to work with native-uri. if (pictureUrl.indexOf('file:') === 0 || pictureUrl.indexOf('content:') === 0 || pictureUrl.indexOf('ms-appdata:') === 0 || pictureUrl.indexOf('assets-library:') === 0) { @@ -155,7 +154,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { } } - function getPicture() { + function getPicture () { clearStatus(); var options = extractOptions(); log('Getting picture with options: ' + JSON.stringify(options)); @@ -168,27 +167,27 @@ exports.defineManualTests = function (contentEl, createActionButton) { }; } - function uploadImage() { - var ft = new FileTransfer(), - options = new FileUploadOptions(); - options.fileKey = "photo"; + function uploadImage () { + var ft = new FileTransfer(); + var options = new FileUploadOptions(); + options.fileKey = 'photo'; options.fileName = 'test.jpg'; - options.mimeType = "image/jpeg"; + options.mimeType = 'image/jpeg'; ft.onprogress = function (progressEvent) { console.log('progress: ' + progressEvent.loaded + ' of ' + progressEvent.total); }; - var server = "http://sheltered-retreat-43956.herokuapp.com"; + var server = 'http://sheltered-retreat-43956.herokuapp.com'; ft.upload(pictureUrl, server + '/upload', win, fail, options); - function win(information_back) { + function win (information_back) { log('upload complete'); } - function fail(message) { + function fail (message) { log('upload failed: ' + JSON.stringify(message)); } } - function logCallback(apiName, success) { + function logCallback (apiName, success) { return function () { log('Call to ' + apiName + (success ? ' success: ' : ' failed: ') + JSON.stringify([].slice.call(arguments))); }; @@ -198,20 +197,21 @@ exports.defineManualTests = function (contentEl, createActionButton) { * Select image from library using a NATIVE_URI destination type * This calls FileEntry.getMetadata, FileEntry.setMetadata, FileEntry.getParent, FileEntry.file, and FileReader.readAsDataURL. */ - function readFile() { - function onFileReadAsDataURL(evt) { + function readFile () { + function onFileReadAsDataURL (evt) { var img = document.getElementById('camera_image'); - img.style.visibility = "visible"; - img.style.display = "block"; + img.style.visibility = 'visible'; + img.style.display = 'block'; img.src = evt.target.result; - log("FileReader.readAsDataURL success"); + log('FileReader.readAsDataURL success'); } - function onFileReceived(file) { + function onFileReceived (file) { log('Got file: ' + JSON.stringify(file)); fileObj = file; - + /* eslint-disable no-undef */ var reader = new FileReader(); + /* eslint-enable no-undef */ reader.onload = function () { log('FileReader.readAsDataURL() - length = ' + reader.result.length); }; @@ -228,10 +228,10 @@ exports.defineManualTests = function (contentEl, createActionButton) { } } - function getFileInfo() { + function getFileInfo () { // Test FileEntry API here. fileEntry.getMetadata(logCallback('FileEntry.getMetadata', true), logCallback('FileEntry.getMetadata', false)); - fileEntry.setMetadata(logCallback('FileEntry.setMetadata', true), logCallback('FileEntry.setMetadata', false), { "com.apple.MobileBackup": 1 }); + fileEntry.setMetadata(logCallback('FileEntry.setMetadata', true), logCallback('FileEntry.setMetadata', false), { 'com.apple.MobileBackup': 1 }); fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false)); fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false)); } @@ -240,7 +240,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { * Copy image from library using a NATIVE_URI destination type * This calls FileEntry.copyTo and FileEntry.moveTo. */ - function copyImage() { + function copyImage () { var onFileSystemReceived = function (fileSystem) { var destDirEntry = fileSystem.root; var origName = fileEntry.name; @@ -249,17 +249,17 @@ exports.defineManualTests = function (contentEl, createActionButton) { fileEntry.copyTo(destDirEntry, 'copied_file.png', logCallback('FileEntry.copyTo', true), logCallback('FileEntry.copyTo', false)); fileEntry.moveTo(destDirEntry, 'moved_file.png', logCallback('FileEntry.moveTo', true), logCallback('FileEntry.moveTo', false)); - //cleanup - //rename moved file back to original name so other tests can reference image - resolveLocalFileSystemURL(destDirEntry.nativeURL+'moved_file.png', function(fileEntry) { + // cleanup + // rename moved file back to original name so other tests can reference image + resolveLocalFileSystemURL(destDirEntry.nativeURL + 'moved_file.png', function (fileEntry) { fileEntry.moveTo(destDirEntry, origName, logCallback('FileEntry.moveTo', true), logCallback('FileEntry.moveTo', false)); console.log('Cleanup: successfully renamed file back to original name'); }, function () { console.log('Cleanup: failed to rename file back to original name'); }); - //remove copied file - resolveLocalFileSystemURL(destDirEntry.nativeURL+'copied_file.png', function(fileEntry) { + // remove copied file + resolveLocalFileSystemURL(destDirEntry.nativeURL + 'copied_file.png', function (fileEntry) { fileEntry.remove(logCallback('FileEntry.remove', true), logCallback('FileEntry.remove', false)); console.log('Cleanup: successfully removed copied file'); }, function () { @@ -274,11 +274,11 @@ exports.defineManualTests = function (contentEl, createActionButton) { * Write image to library using a NATIVE_URI destination type * This calls FileEntry.createWriter, FileWriter.write, and FileWriter.truncate. */ - function writeImage() { + function writeImage () { var onFileWriterReceived = function (fileWriter) { fileWriter.onwrite = logCallback('FileWriter.write', true); fileWriter.onerror = logCallback('FileWriter.write', false); - fileWriter.write("some text!"); + fileWriter.write('some text!'); }; var onFileTruncateWriterReceived = function (fileWriter) { @@ -291,7 +291,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { fileEntry.createWriter(onFileTruncateWriterReceived, null); } - function displayImageUsingCanvas() { + function displayImageUsingCanvas () { var canvas = document.getElementById('canvas'); var img = document.getElementById('camera_image'); var w = img.width; @@ -308,11 +308,11 @@ exports.defineManualTests = function (contentEl, createActionButton) { * Remove image from library using a NATIVE_URI destination type * This calls FileEntry.remove. */ - function removeImage() { + function removeImage () { fileEntry.remove(logCallback('FileEntry.remove', true), logCallback('FileEntry.remove', false)); } - function testInputTag(inputEl) { + function testInputTag (inputEl) { clearStatus(); // iOS 6 likes to dead-lock in the onchange context if you // do any alerts or try to remote-debug. @@ -321,7 +321,8 @@ exports.defineManualTests = function (contentEl, createActionButton) { }, 0); } - function testNativeFile2(inputEl) { + function testNativeFile2 (inputEl) { + /* eslint-disable no-undef */ if (!inputEl.value) { alert('No file selected.'); return; @@ -331,6 +332,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { alert('Got value but no file.'); return; } + /* eslint-enable no-undef */ var URLApi = window.URL || window.webkitURL; if (URLApi) { var blobURL = URLApi.createObjectURL(fileObj); @@ -346,26 +348,26 @@ exports.defineManualTests = function (contentEl, createActionButton) { } } - function extractOptions() { + function extractOptions () { var els = document.querySelectorAll('#image-options select'); var ret = {}; - /*jshint -W084 */ + /* eslint-disable no-cond-assign */ for (var i = 0, el; el = els[i]; ++i) { var value = el.value; if (value === '') continue; value = +value; if (el.isBool) { - ret[el.getAttribute("name")] = !!value; + ret[el.getAttribute('name')] = !!value; } else { - ret[el.getAttribute("name")] = value; + ret[el.getAttribute('name')] = value; } } - /*jshint +W084 */ + /* eslint-enable no-cond-assign */ return ret; } - function createOptionsEl(name, values, selectionDefault) { + function createOptionsEl (name, values, selectionDefault) { var openDiv = '
' + name + ': '; var select = '
' + '
capture=camera
' + '
capture=camcorder
' + - '
capture=microphone
', - actions_div = '

Actions

' + + '
capture=microphone
'; + var actions_div = '

Actions

' + 'For the following tests, ensure that an image is set in status box' + '

' + 'Expected result: Get metadata about file selected.
Status box will show, along with the metadata, "Call to FileEntry.getMetadata success, Call to FileEntry.setMetadata success, Call to FileEntry.getParent success"' + @@ -456,20 +458,20 @@ exports.defineManualTests = function (contentEl, createActionButton) { // We need to wrap this code due to Windows security restrictions // see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details if (window.MSApp && window.MSApp.execUnsafeLocalFunction) { - MSApp.execUnsafeLocalFunction(function() { + MSApp.execUnsafeLocalFunction(function () { contentEl.innerHTML = info_div + options_div + getpicture_div + test_procedure + inputs_div + actions_div; }); } else { contentEl.innerHTML = info_div + options_div + getpicture_div + test_procedure + inputs_div + actions_div; } - var elements = document.getElementsByClassName("testInputTag"); + var elements = document.getElementsByClassName('testInputTag'); var listener = function (e) { testInputTag(e.target); }; for (var i = 0; i < elements.length; ++i) { var item = elements[i]; - item.addEventListener("change", listener, false); + item.addEventListener('change', listener, false); } createActionButton('Get picture', function () {