2014-07-01 04:37:18 +08:00
/ *
*
* Licensed to the Apache Software Foundation ( ASF ) under one
* or more contributor license agreements . See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership . The ASF licenses this file
* to you under the Apache License , Version 2.0 ( the
* "License" ) ; you may not use this file except in compliance
* with the License . You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing ,
* software distributed under the License is distributed on an
* "AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND , either express or implied . See the License for the
* specific language governing permissions and limitations
* under the License .
*
* /
2020-07-23 19:16:36 +08:00
/* globals Camera, resolveLocalFileSystemURL, FileEntry, CameraPopoverOptions, LocalFileSystem, MSApp */
2017-07-15 05:19:05 +08:00
/* eslint-env jasmine */
2016-02-18 20:18:09 +08:00
2014-07-17 03:49:50 +08:00
exports . defineAutoTests = function ( ) {
2014-07-01 04:37:18 +08:00
describe ( 'Camera (navigator.camera)' , function ( ) {
2017-07-15 05:19:05 +08:00
it ( 'should exist' , function ( ) {
2014-07-01 04:37:18 +08:00
expect ( navigator . camera ) . toBeDefined ( ) ;
} ) ;
2017-07-15 05:19:05 +08:00
it ( 'should contain a getPicture function' , function ( ) {
2014-07-01 04:37:18 +08:00
expect ( navigator . camera . getPicture ) . toBeDefined ( ) ;
2017-07-15 05:19:05 +08:00
expect ( typeof navigator . camera . getPicture === 'function' ) . toBe ( true ) ;
2014-07-01 04:37:18 +08:00
} ) ;
} ) ;
describe ( 'Camera Constants (window.Camera + navigator.camera)' , function ( ) {
2017-07-15 05:19:05 +08:00
it ( 'camera.spec.1 window.Camera should exist' , function ( ) {
2014-07-01 04:37:18 +08:00
expect ( window . Camera ) . toBeDefined ( ) ;
} ) ;
2017-07-15 05:19:05 +08:00
it ( 'camera.spec.2 should contain three DestinationType constants' , function ( ) {
2014-07-01 04:37:18 +08:00
expect ( Camera . DestinationType . DATA _URL ) . toBe ( 0 ) ;
expect ( Camera . DestinationType . FILE _URI ) . toBe ( 1 ) ;
expect ( navigator . camera . DestinationType . DATA _URL ) . toBe ( 0 ) ;
expect ( navigator . camera . DestinationType . FILE _URI ) . toBe ( 1 ) ;
} ) ;
2017-07-15 05:19:05 +08:00
it ( 'camera.spec.3 should contain two EncodingType constants' , function ( ) {
2014-07-01 04:37:18 +08:00
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 ) ;
} ) ;
2017-07-15 05:19:05 +08:00
it ( 'camera.spec.4 should contain three MediaType constants' , function ( ) {
2014-07-01 04:37:18 +08:00
expect ( Camera . MediaType . PICTURE ) . toBe ( 0 ) ;
expect ( Camera . MediaType . VIDEO ) . toBe ( 1 ) ;
expect ( Camera . MediaType . ALLMEDIA ) . toBe ( 2 ) ;
expect ( navigator . camera . MediaType . PICTURE ) . toBe ( 0 ) ;
expect ( navigator . camera . MediaType . VIDEO ) . toBe ( 1 ) ;
expect ( navigator . camera . MediaType . ALLMEDIA ) . toBe ( 2 ) ;
} ) ;
2017-07-15 05:19:05 +08:00
it ( 'camera.spec.5 should contain three PictureSourceType constants' , function ( ) {
2014-07-01 04:37:18 +08:00
expect ( Camera . PictureSourceType . PHOTOLIBRARY ) . toBe ( 0 ) ;
expect ( Camera . PictureSourceType . CAMERA ) . toBe ( 1 ) ;
expect ( Camera . PictureSourceType . SAVEDPHOTOALBUM ) . toBe ( 2 ) ;
expect ( navigator . camera . PictureSourceType . PHOTOLIBRARY ) . toBe ( 0 ) ;
expect ( navigator . camera . PictureSourceType . CAMERA ) . toBe ( 1 ) ;
expect ( navigator . camera . PictureSourceType . SAVEDPHOTOALBUM ) . toBe ( 2 ) ;
} ) ;
} ) ;
} ;
2014-07-17 03:49:50 +08:00
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
exports . defineManualTests = function ( contentEl , createActionButton ) {
2023-08-17 23:59:25 +08:00
let pictureUrl = null ;
let fileObj = null ;
let fileEntry = null ;
const pageStartTime = + new Date ( ) ;
2014-07-17 03:49:50 +08:00
2017-07-15 05:19:05 +08:00
// default camera options
2023-08-17 23:59:25 +08:00
const camQualityDefault = [ '50' , 50 ] ;
const camDestinationTypeDefault = [ 'FILE_URI' , 1 ] ;
const camPictureSourceTypeDefault = [ 'CAMERA' , 1 ] ;
const camAllowEditDefault = [ 'allowEdit' , false ] ;
const camEncodingTypeDefault = [ 'JPEG' , 0 ] ;
const camMediaTypeDefault = [ 'mediaType' , 0 ] ;
const camCorrectOrientationDefault = [ 'correctOrientation' , false ] ;
const camSaveToPhotoAlbumDefault = [ 'saveToPhotoAlbum' , true ] ;
2014-07-17 03:49:50 +08:00
2017-07-15 05:19:05 +08:00
function log ( value ) {
2014-07-17 03:49:50 +08:00
console . log ( value ) ;
document . getElementById ( 'camera_status' ) . textContent += ( new Date ( ) - pageStartTime ) / 1000 + ': ' + value + '\n' ;
}
2017-07-15 05:19:05 +08:00
function clearStatus ( ) {
2014-07-17 03:49:50 +08:00
document . getElementById ( 'camera_status' ) . innerHTML = '' ;
document . getElementById ( 'camera_image' ) . src = 'about:blank' ;
2023-08-17 23:59:25 +08:00
const canvas = document . getElementById ( 'canvas' ) ;
2014-07-17 03:49:50 +08:00
canvas . width = canvas . height = 1 ;
pictureUrl = null ;
fileObj = null ;
fileEntry = null ;
}
2017-07-15 05:19:05 +08:00
function setPicture ( url , callback ) {
2014-07-17 03:49:50 +08:00
try {
window . atob ( url ) ;
// if we got here it is a base64 string (DATA_URL)
2017-07-15 05:19:05 +08:00
url = 'data:image/jpeg;base64,' + url ;
2014-07-17 03:49:50 +08:00
} catch ( e ) {
// not DATA_URL
}
2016-02-04 23:55:57 +08:00
log ( 'URL: "' + url . slice ( 0 , 90 ) + '"' ) ;
2014-07-17 03:49:50 +08:00
pictureUrl = url ;
2023-08-17 23:59:25 +08:00
const img = document . getElementById ( 'camera_image' ) ;
const startTime = new Date ( ) ;
2014-07-17 03:49:50 +08:00
img . src = url ;
2016-03-21 17:54:07 +08:00
img . onload = function ( ) {
log ( 'Img size: ' + img . naturalWidth + 'x' + img . naturalHeight ) ;
2014-07-17 03:49:50 +08:00
log ( 'Image tag load time: ' + ( new Date ( ) - startTime ) ) ;
2016-02-18 20:18:09 +08:00
if ( callback ) {
callback ( ) ;
}
2014-07-17 03:49:50 +08:00
} ;
}
2017-07-15 05:19:05 +08:00
function onGetPictureError ( e ) {
2014-09-19 17:16:20 +08:00
log ( 'Error getting picture: ' + ( e . code || e ) ) ;
2014-07-17 03:49:50 +08:00
}
2017-07-15 05:19:05 +08:00
function getPictureWin ( data ) {
2014-07-17 03:49:50 +08:00
setPicture ( data ) ;
// TODO: Fix resolveLocalFileSystemURI to work with native-uri.
2020-08-07 20:38:05 +08:00
if ( pictureUrl . indexOf ( 'file:' ) === 0 || pictureUrl . indexOf ( 'content:' ) === 0 ) {
2016-08-17 00:19:22 +08:00
resolveLocalFileSystemURL ( data , function ( e ) {
2014-07-17 03:49:50 +08:00
fileEntry = e ;
2016-08-17 00:19:22 +08:00
logCallback ( 'resolveLocalFileSystemURL()' , true ) ( e . toURL ( ) ) ;
2016-02-04 23:55:57 +08:00
readFile ( ) ;
2016-08-17 00:19:22 +08:00
} , logCallback ( 'resolveLocalFileSystemURL()' , false ) ) ;
2016-02-18 20:18:09 +08:00
} else if ( pictureUrl . indexOf ( 'data:image/jpeg;base64' ) === 0 ) {
2014-07-17 03:49:50 +08:00
// do nothing
} else {
2023-08-17 23:59:25 +08:00
const path = pictureUrl . replace ( /^file:\/\/(localhost)?/ , '' ) . replace ( /%20/g , ' ' ) ;
2014-07-17 03:49:50 +08:00
fileEntry = new FileEntry ( 'image_name.png' , path ) ;
}
}
2017-07-15 05:19:05 +08:00
function getPicture ( ) {
2014-07-17 03:49:50 +08:00
clearStatus ( ) ;
2023-08-17 23:59:25 +08:00
const options = extractOptions ( ) ;
2014-07-17 03:49:50 +08:00
log ( 'Getting picture with options: ' + JSON . stringify ( options ) ) ;
2023-08-17 23:59:25 +08:00
const popoverHandle = navigator . camera . getPicture ( getPictureWin , onGetPictureError , options ) ;
2014-07-17 03:49:50 +08:00
// Reposition the popover if the orientation changes.
window . onorientationchange = function ( ) {
2023-08-17 23:59:25 +08:00
const newPopoverOptions = new CameraPopoverOptions ( 0 , 0 , 100 , 100 , 0 , 300 , 400 ) ;
2014-07-17 03:49:50 +08:00
popoverHandle . setPosition ( newPopoverOptions ) ;
2016-02-18 20:18:09 +08:00
} ;
2014-07-17 03:49:50 +08:00
}
2017-07-15 05:19:05 +08:00
function logCallback ( apiName , success ) {
2014-07-17 03:49:50 +08:00
return function ( ) {
log ( 'Call to ' + apiName + ( success ? ' success: ' : ' failed: ' ) + JSON . stringify ( [ ] . slice . call ( arguments ) ) ) ;
} ;
}
/ * *
2020-08-07 20:38:05 +08:00
* Select image from library
2014-07-17 03:49:50 +08:00
* This calls FileEntry . getMetadata , FileEntry . setMetadata , FileEntry . getParent , FileEntry . file , and FileReader . readAsDataURL .
* /
2017-07-15 05:19:05 +08:00
function readFile ( ) {
function onFileReadAsDataURL ( evt ) {
2023-08-17 23:59:25 +08:00
const img = document . getElementById ( 'camera_image' ) ;
2017-07-15 05:19:05 +08:00
img . style . visibility = 'visible' ;
img . style . display = 'block' ;
2014-07-17 03:49:50 +08:00
img . src = evt . target . result ;
2017-07-15 05:19:05 +08:00
log ( 'FileReader.readAsDataURL success' ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
2017-07-15 05:19:05 +08:00
function onFileReceived ( file ) {
2014-07-17 03:49:50 +08:00
log ( 'Got file: ' + JSON . stringify ( file ) ) ;
fileObj = file ;
2017-07-15 05:19:05 +08:00
/* eslint-disable no-undef */
2023-08-17 23:59:25 +08:00
const reader = new FileReader ( ) ;
2017-07-15 05:19:05 +08:00
/* eslint-enable no-undef */
2014-07-17 03:49:50 +08:00
reader . onload = function ( ) {
log ( 'FileReader.readAsDataURL() - length = ' + reader . result . length ) ;
} ;
reader . onerror = logCallback ( 'FileReader.readAsDataURL' , false ) ;
2016-02-04 23:55:57 +08:00
reader . onloadend = onFileReadAsDataURL ;
2014-07-17 03:49:50 +08:00
reader . readAsDataURL ( file ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
// Test out onFileReceived when the file object was set via a native <input> elements.
if ( fileObj ) {
onFileReceived ( fileObj ) ;
} else {
fileEntry . file ( onFileReceived , logCallback ( 'FileEntry.file' , false ) ) ;
}
}
2016-02-18 20:18:09 +08:00
2017-07-15 05:19:05 +08:00
function getFileInfo ( ) {
2014-07-17 03:49:50 +08:00
// Test FileEntry API here.
fileEntry . getMetadata ( logCallback ( 'FileEntry.getMetadata' , true ) , logCallback ( 'FileEntry.getMetadata' , false ) ) ;
2017-07-15 05:19:05 +08:00
fileEntry . setMetadata ( logCallback ( 'FileEntry.setMetadata' , true ) , logCallback ( 'FileEntry.setMetadata' , false ) , { 'com.apple.MobileBackup' : 1 } ) ;
2014-07-17 03:49:50 +08:00
fileEntry . getParent ( logCallback ( 'FileEntry.getParent' , true ) , logCallback ( 'FileEntry.getParent' , false ) ) ;
fileEntry . getParent ( logCallback ( 'FileEntry.getParent' , true ) , logCallback ( 'FileEntry.getParent' , false ) ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
/ * *
2020-08-07 20:38:05 +08:00
* Copy image from library
2014-07-17 03:49:50 +08:00
* This calls FileEntry . copyTo and FileEntry . moveTo .
* /
2017-07-15 05:19:05 +08:00
function copyImage ( ) {
2023-08-17 23:59:25 +08:00
const onFileSystemReceived = function ( fileSystem ) {
const destDirEntry = fileSystem . root ;
const origName = fileEntry . name ;
2014-07-17 03:49:50 +08:00
// Test FileEntry API here.
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 ) ) ;
2014-09-04 23:04:33 +08:00
2017-07-15 05:19:05 +08:00
// cleanup
// rename moved file back to original name so other tests can reference image
resolveLocalFileSystemURL ( destDirEntry . nativeURL + 'moved_file.png' , function ( fileEntry ) {
2014-09-04 23:04:33 +08:00
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' ) ;
} ) ;
2017-07-15 05:19:05 +08:00
// remove copied file
resolveLocalFileSystemURL ( destDirEntry . nativeURL + 'copied_file.png' , function ( fileEntry ) {
2014-09-04 23:04:33 +08:00
fileEntry . remove ( logCallback ( 'FileEntry.remove' , true ) , logCallback ( 'FileEntry.remove' , false ) ) ;
console . log ( 'Cleanup: successfully removed copied file' ) ;
} , function ( ) {
console . log ( 'Cleanup: failed to remove copied file' ) ;
} ) ;
2014-07-17 03:49:50 +08:00
} ;
window . requestFileSystem ( LocalFileSystem . TEMPORARY , 0 , onFileSystemReceived , null ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
/ * *
2020-08-07 20:38:05 +08:00
* Write image to library
2014-07-17 03:49:50 +08:00
* This calls FileEntry . createWriter , FileWriter . write , and FileWriter . truncate .
* /
2017-07-15 05:19:05 +08:00
function writeImage ( ) {
2023-08-17 23:59:25 +08:00
const onFileWriterReceived = function ( fileWriter ) {
2014-07-17 03:49:50 +08:00
fileWriter . onwrite = logCallback ( 'FileWriter.write' , true ) ;
fileWriter . onerror = logCallback ( 'FileWriter.write' , false ) ;
2017-07-15 05:19:05 +08:00
fileWriter . write ( 'some text!' ) ;
2014-07-17 03:49:50 +08:00
} ;
2023-08-17 23:59:25 +08:00
const onFileTruncateWriterReceived = function ( fileWriter ) {
2014-07-17 03:49:50 +08:00
fileWriter . onwrite = logCallback ( 'FileWriter.truncate' , true ) ;
fileWriter . onerror = logCallback ( 'FileWriter.truncate' , false ) ;
fileWriter . truncate ( 10 ) ;
} ;
fileEntry . createWriter ( onFileWriterReceived , logCallback ( 'FileEntry.createWriter' , false ) ) ;
fileEntry . createWriter ( onFileTruncateWriterReceived , null ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
2017-07-15 05:19:05 +08:00
function displayImageUsingCanvas ( ) {
2023-08-17 23:59:25 +08:00
const canvas = document . getElementById ( 'canvas' ) ;
const img = document . getElementById ( 'camera_image' ) ;
let w = img . width ;
let h = img . height ;
2014-07-17 03:49:50 +08:00
h = 100 / w * h ;
w = 100 ;
canvas . width = w ;
canvas . height = h ;
2023-08-17 23:59:25 +08:00
const context = canvas . getContext ( '2d' ) ;
2014-07-17 03:49:50 +08:00
context . drawImage ( img , 0 , 0 , w , h ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
/ * *
2020-08-07 20:38:05 +08:00
* Remove image from library
2014-07-17 03:49:50 +08:00
* This calls FileEntry . remove .
* /
2017-07-15 05:19:05 +08:00
function removeImage ( ) {
2014-07-17 03:49:50 +08:00
fileEntry . remove ( logCallback ( 'FileEntry.remove' , true ) , logCallback ( 'FileEntry.remove' , false ) ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
2017-07-15 05:19:05 +08:00
function testInputTag ( inputEl ) {
2014-07-17 03:49:50 +08:00
clearStatus ( ) ;
// iOS 6 likes to dead-lock in the onchange context if you
// do any alerts or try to remote-debug.
window . setTimeout ( function ( ) {
testNativeFile2 ( inputEl ) ;
} , 0 ) ;
2016-02-18 20:18:09 +08:00
}
2014-07-17 03:49:50 +08:00
2017-07-15 05:19:05 +08:00
function testNativeFile2 ( inputEl ) {
/* eslint-disable no-undef */
2014-07-17 03:49:50 +08:00
if ( ! inputEl . value ) {
alert ( 'No file selected.' ) ;
return ;
}
fileObj = inputEl . files [ 0 ] ;
if ( ! fileObj ) {
alert ( 'Got value but no file.' ) ;
return ;
}
2017-07-15 05:19:05 +08:00
/* eslint-enable no-undef */
2023-08-17 23:59:25 +08:00
const URLApi = window . URL || window . webkitURL ;
2014-07-17 03:49:50 +08:00
if ( URLApi ) {
2023-08-17 23:59:25 +08:00
const blobURL = URLApi . createObjectURL ( fileObj ) ;
2014-07-17 03:49:50 +08:00
if ( blobURL ) {
setPicture ( blobURL , function ( ) {
URLApi . revokeObjectURL ( blobURL ) ;
} ) ;
} else {
log ( 'URL.createObjectURL returned null' ) ;
}
} else {
log ( 'URL.createObjectURL() not supported.' ) ;
}
}
2017-07-15 05:19:05 +08:00
function extractOptions ( ) {
2023-08-17 23:59:25 +08:00
const els = document . querySelectorAll ( '#image-options select' ) ;
const ret = { } ;
2017-07-15 05:19:05 +08:00
/* eslint-disable no-cond-assign */
2023-08-17 23:59:25 +08:00
for ( let i = 0 , el ; el = els [ i ] ; ++ i ) {
let value = el . value ;
2014-07-17 03:49:50 +08:00
if ( value === '' ) continue ;
2016-02-18 20:18:09 +08:00
value = + value ;
2014-07-17 03:49:50 +08:00
if ( el . isBool ) {
2017-07-15 05:19:05 +08:00
ret [ el . getAttribute ( 'name' ) ] = ! ! value ;
2014-07-17 03:49:50 +08:00
} else {
2017-07-15 05:19:05 +08:00
ret [ el . getAttribute ( 'name' ) ] = value ;
2014-07-17 03:49:50 +08:00
}
}
2017-07-15 05:19:05 +08:00
/* eslint-enable no-cond-assign */
2014-07-17 03:49:50 +08:00
return ret ;
}
2017-07-15 05:19:05 +08:00
function createOptionsEl ( name , values , selectionDefault ) {
2023-08-17 23:59:25 +08:00
const openDiv = '<div style="display: inline-block">' + name + ': ' ;
const select = '<select name=' + name + ' id="' + name + '">' ;
2014-07-17 03:49:50 +08:00
2023-08-17 23:59:25 +08:00
let defaultOption = '' ;
2016-02-18 20:18:09 +08:00
if ( selectionDefault === undefined ) {
2014-07-17 03:49:50 +08:00
defaultOption = '<option value="">default</option>' ;
}
2023-08-17 23:59:25 +08:00
let options = '' ;
2017-07-15 05:19:05 +08:00
if ( typeof values === 'boolean' ) {
2020-07-14 18:15:29 +08:00
values = { true : 1 , false : 0 } ;
2014-07-17 03:49:50 +08:00
}
2023-08-17 23:59:25 +08:00
for ( const k in values ) {
let isSelected = '' ;
2014-07-17 03:49:50 +08:00
if ( selectionDefault ) {
2017-07-15 05:19:05 +08:00
if ( selectionDefault [ 0 ] === k ) {
2014-07-17 03:49:50 +08:00
isSelected = 'selected' ;
}
}
options += '<option value="' + values [ k ] + '" ' + isSelected + '>' + k + '</option>' ;
}
2023-08-17 23:59:25 +08:00
const closeDiv = '</select></div>' ;
2014-07-17 03:49:50 +08:00
return openDiv + select + defaultOption + options + closeDiv ;
}
/******************************************************************************/
2023-08-17 23:59:25 +08:00
const info _div = '<h1>Camera</h1>' +
2014-07-17 03:49:50 +08:00
'<div id="info">' +
'<b>Status:</b> <div id="camera_status"></div>' +
'img: <img width="100" id="camera_image">' +
'canvas: <canvas id="canvas" width="1" height="1"></canvas>' +
2017-07-15 05:19:05 +08:00
'</div>' ;
2023-08-17 23:59:25 +08:00
const options _div = '<h2>Cordova Camera API Options</h2>' +
2014-07-17 03:49:50 +08:00
'<div id="image-options">' +
createOptionsEl ( 'sourceType' , Camera . PictureSourceType , camPictureSourceTypeDefault ) +
createOptionsEl ( 'destinationType' , Camera . DestinationType , camDestinationTypeDefault ) +
createOptionsEl ( 'encodingType' , Camera . EncodingType , camEncodingTypeDefault ) +
createOptionsEl ( 'mediaType' , Camera . MediaType , camMediaTypeDefault ) +
2020-07-14 18:15:29 +08:00
createOptionsEl ( 'quality' , { 0 : 0 , 50 : 50 , 80 : 80 , 100 : 100 } , camQualityDefault ) +
createOptionsEl ( 'targetWidth' , { 50 : 50 , 200 : 200 , 800 : 800 , 2048 : 2048 } ) +
createOptionsEl ( 'targetHeight' , { 50 : 50 , 200 : 200 , 800 : 800 , 2048 : 2048 } ) +
2014-07-17 03:49:50 +08:00
createOptionsEl ( 'allowEdit' , true , camAllowEditDefault ) +
createOptionsEl ( 'correctOrientation' , true , camCorrectOrientationDefault ) +
createOptionsEl ( 'saveToPhotoAlbum' , true , camSaveToPhotoAlbumDefault ) +
createOptionsEl ( 'cameraDirection' , Camera . Direction ) +
2017-07-15 05:19:05 +08:00
'</div>' ;
2023-08-17 23:59:25 +08:00
const getpicture _div = '<div id="getpicture"></div>' ;
const test _procedure = '<h4>Recommended Test Procedure</h4>' +
2014-07-31 01:54:58 +08:00
'Options not specified should be the default value' +
'<br>Status box should update with image and info whenever an image is taken or selected from library' +
'</p><div style="background:#B0C4DE;border:1px solid #FFA07A;margin:15px 6px 0px;min-width:295px;max-width:97%;padding:4px 0px 2px 10px;min-height:160px;max-height:200px;overflow:auto">' +
'<ol> <li>All default options. Should be able to edit once picture is taken and will be saved to library.</li>' +
'</p><li>sourceType=PHOTOLIBRARY<br>Should be able to see picture that was just taken in previous test and edit when selected</li>' +
'</p><li>sourceType=Camera<br>allowEdit=false<br>saveToPhotoAlbum=false<br>Should not be able to edit when taken and will not save to library</li>' +
'</p><li>encodingType=PNG<br>allowEdit=true<br>saveToPhotoAlbum=true<br>cameraDirection=FRONT<br>Should bring up front camera. Verify in status box info URL that image is encoded as PNG.</li>' +
'</p><li>sourceType=SAVEDPHOTOALBUM<br>mediaType=VIDEO<br>Should only be able to select a video</li>' +
'</p><li>sourceType=SAVEDPHOTOALBUM<br>mediaType=PICTURE<br>allowEdit=false<br>Should only be able to select a picture and not edit</li>' +
'</p><li>sourceType=PHOTOLIBRARY<br>mediaType=ALLMEDIA<br>allowEdit=true<br>Should be able to select pics and videos and edit picture if selected</li>' +
'</p><li>sourceType=CAMERA<br>targetWidth & targetHeight=50<br>allowEdit=false<br>Do Get File Metadata test below and take note of size<br>Repeat test but with width and height=800. Size should be significantly larger.</li>' +
'</p><li>quality=0<br>targetWidth & targetHeight=default<br>allowEdit=false<br>Do Get File Metadata test below and take note of size<br>Repeat test but with quality=80. Size should be significantly larger.</li>' +
2017-07-15 05:19:05 +08:00
'</ol></div>' ;
2023-08-17 23:59:25 +08:00
const inputs _div = '<h2>Native File Inputs</h2>' +
2014-07-31 01:54:58 +08:00
'For the following tests, status box should update with file selected' +
'</p><div>input type=file <input type="file" class="testInputTag"></div>' +
2014-07-17 03:49:50 +08:00
'<div>capture=camera <input type="file" accept="image/*;capture=camera" class="testInputTag"></div>' +
'<div>capture=camcorder <input type="file" accept="video/*;capture=camcorder" class="testInputTag"></div>' +
2017-07-15 05:19:05 +08:00
'<div>capture=microphone <input type="file" accept="audio/*;capture=microphone" class="testInputTag"></div>' ;
2023-08-17 23:59:25 +08:00
const actions _div = '<h2>Actions</h2>' +
2014-07-31 01:54:58 +08:00
'For the following tests, ensure that an image is set in status box' +
'</p><div id="metadata"></div>' +
'Expected result: Get metadata about file selected.<br>Status box will show, along with the metadata, "Call to FileEntry.getMetadata success, Call to FileEntry.setMetadata success, Call to FileEntry.getParent success"' +
'</p><div id="reader"></div>' +
'Expected result: Read contents of file.<br>Status box will show "Got file: {some metadata}, FileReader.readAsDataURL() - length = someNumber"' +
'</p><div id="copy"></div>' +
'Expected result: Copy image to new location and move file to different location.<br>Status box will show "Call to FileEntry.copyTo success:{some metadata}, Call to FileEntry.moveTo success:{some metadata}"' +
'</p><div id="write"></div>' +
'Expected result: Write image to library.<br>Status box will show "Call to FileWriter.write success:{some metadata}, Call to FileWriter.truncate success:{some metadata}"' +
'</p><div id="upload"></div>' +
'Expected result: Upload image to server.<br>Status box may print out progress. Once finished will show "upload complete"' +
'</p><div id="draw_canvas"></div>' +
'Expected result: Display image using canvas.<br>Image will be displayed in status box under "canvas:"' +
'</p><div id="remove"></div>' +
'Expected result: Remove image from library.<br>Status box will show "FileEntry.remove success:["OK"]' ;
2014-08-30 05:20:41 +08:00
// 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
2014-09-10 22:53:09 +08:00
if ( window . MSApp && window . MSApp . execUnsafeLocalFunction ) {
2017-07-15 05:19:05 +08:00
MSApp . execUnsafeLocalFunction ( function ( ) {
2014-08-30 05:20:41 +08:00
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 ;
}
2023-08-17 23:59:25 +08:00
const elements = document . getElementsByClassName ( 'testInputTag' ) ;
const listener = function ( e ) {
2014-07-17 03:49:50 +08:00
testInputTag ( e . target ) ;
2016-02-18 20:18:09 +08:00
} ;
2023-08-17 23:59:25 +08:00
for ( let i = 0 ; i < elements . length ; ++ i ) {
const item = elements [ i ] ;
2017-07-15 05:19:05 +08:00
item . addEventListener ( 'change' , listener , false ) ;
2014-07-17 03:49:50 +08:00
}
createActionButton ( 'Get picture' , function ( ) {
getPicture ( ) ;
} , 'getpicture' ) ;
createActionButton ( 'Clear Status' , function ( ) {
clearStatus ( ) ;
} , 'getpicture' ) ;
createActionButton ( 'Get File Metadata' , function ( ) {
getFileInfo ( ) ;
2014-07-31 01:54:58 +08:00
} , 'metadata' ) ;
2014-07-17 03:49:50 +08:00
createActionButton ( 'Read with FileReader' , function ( ) {
readFile ( ) ;
2014-07-31 01:54:58 +08:00
} , 'reader' ) ;
2014-07-17 03:49:50 +08:00
createActionButton ( 'Copy Image' , function ( ) {
copyImage ( ) ;
2014-07-31 01:54:58 +08:00
} , 'copy' ) ;
2014-07-17 03:49:50 +08:00
createActionButton ( 'Write Image' , function ( ) {
writeImage ( ) ;
2014-07-31 01:54:58 +08:00
} , 'write' ) ;
2014-07-17 03:49:50 +08:00
createActionButton ( 'Draw Using Canvas' , function ( ) {
displayImageUsingCanvas ( ) ;
2014-07-31 01:54:58 +08:00
} , 'draw_canvas' ) ;
2014-07-17 03:49:50 +08:00
createActionButton ( 'Remove Image' , function ( ) {
removeImage ( ) ;
2014-07-31 01:54:58 +08:00
} , 'remove' ) ;
2014-07-17 03:49:50 +08:00
} ;