From ef56362796a4a3d04ad476c1c8ded90e7684d7bc Mon Sep 17 00:00:00 2001 From: chenfangyuan Date: Thu, 27 Oct 2016 09:11:21 +0800 Subject: [PATCH] [common][tct-globalization-cordova-tests][Testcase sync from Suprem] Change-Id: Ic483bb534553646706d7937cc94678076092b16b Signed-off-by: chenfangyuan --- .../tct-globalization-cordova-tests/COPYING | 13 + .../LICENSE.Apache-2.0 | 202 ++ common/tct-globalization-cordova-tests/README | 56 + .../config.xml | 9 + .../cordova/COPYING | 7 + .../cordova/cordova-5.1.1.js | 1651 ++++++++++++ .../cordova/cordova.js | 70 + .../cordova/cordova_plugins.js | 376 +++ .../www/console-via-logger.js | 189 ++ .../cordova-plugin-console/www/logger.js | 357 +++ .../tizen/Accelerometer.js | 66 + .../www/Acceleration.js | 32 + .../www/accelerometer.js | 201 ++ .../cordova-plugin-device/tizen/Device.js | 86 + .../cordova-plugin-device/www/device.js | 85 + .../tizen/Notification.js | 376 +++ .../www/notification.js | 114 + .../cordova-plugin-events/tizen/Events.js | 191 ++ .../cordova-plugin-events/www/register.js | 81 + .../tizen/FileTransfer.js | 292 ++ .../www/FileTransfer.js | 237 ++ .../www/FileTransferError.js | 43 + .../tizen/DirectoryEntry.js | 214 ++ .../tizen/DirectoryReader.js | 58 + .../cordova-plugin-file/tizen/Entry.js | 224 ++ .../cordova-plugin-file/tizen/Errors.js | 46 + .../plugins/cordova-plugin-file/tizen/File.js | 51 + .../cordova-plugin-file/tizen/FileReader.js | 99 + .../cordova-plugin-file/tizen/FileSystem.js | 31 + .../cordova-plugin-file/tizen/FileWriter.js | 163 ++ .../tizen/fileSystemPaths.js | 105 + .../tizen/fileSystems-roots.js | 40 + .../tizen/requestFileSystem.js | 85 + .../tizen/resolveLocalFileSystemURI.js | 66 + .../cordova-plugin-file/tizen/rootUtils.js | 222 ++ .../cordova-plugin-file/www/DirectoryEntry.js | 119 + .../www/DirectoryReader.js | 75 + .../plugins/cordova-plugin-file/www/Entry.js | 262 ++ .../plugins/cordova-plugin-file/www/File.js | 81 + .../cordova-plugin-file/www/FileEntry.js | 83 + .../cordova-plugin-file/www/FileError.js | 48 + .../cordova-plugin-file/www/FileReader.js | 392 +++ .../cordova-plugin-file/www/FileSystem.js | 50 + .../www/FileUploadOptions.js | 43 + .../www/FileUploadResult.js | 31 + .../cordova-plugin-file/www/FileWriter.js | 304 +++ .../plugins/cordova-plugin-file/www/Flags.js | 38 + .../www/LocalFileSystem.js | 25 + .../cordova-plugin-file/www/Metadata.js | 42 + .../cordova-plugin-file/www/ProgressEvent.js | 69 + .../www/fileSystemPaths.js | 65 + .../www/fileSystems-roots.js | 45 + .../cordova-plugin-file/www/fileSystems.js | 27 + .../www/requestFileSystem.js | 78 + .../www/resolveLocalFileSystemURI.js | 89 + .../tizen/Globalization.js | 170 ++ .../www/GlobalizationError.js | 43 + .../www/globalization.js | 393 +++ .../cordova-plugin-media/tizen/Media.js | 422 +++ .../plugins/cordova-plugin-media/www/Media.js | 231 ++ .../cordova-plugin-media/www/MediaError.js | 58 + .../tizen/Connection.js | 49 + .../tizen/NetworkStatus.js | 93 + .../www/Connection.js | 36 + .../www/network.js | 93 + ...n_ArrayStringSuccessCallback_notexist.html | 52 + ..._ArrayStringSuccessCallback_onsuccess.html | 63 + ...alization_DSTSuccessCallback_notexist.html | 52 + ...lization_DSTSuccessCallback_onsuccess.html | 64 + ...zation_DoubleSuccessCallback_notexist.html | 52 + ...ation_DoubleSuccessCallback_onsuccess.html | 63 + ...etDatePatternSuccessCallback_notexist.html | 52 + ...tDatePatternSuccessCallback_onsuccess.html | 66 + ...NumberPatternSuccessCallback_notexist.html | 52 + ...umberPatternSuccessCallback_onsuccess.html | 70 + ...alizationDateSuccessCallback_notexist.html | 52 + ...lizationDateSuccessCallback_onsuccess.html | 78 + ...alizationError_FORMATTING_ERROR_const.html | 54 + ...lobalizationError_PARSING_ERROR_const.html | 54 + ...lobalizationError_PATTERN_ERROR_const.html | 54 + ...lobalizationError_UNKNOWN_ERROR_const.html | 54 + ...ion_GlobalizationError_code_attribute.html | 60 + ..._GlobalizationError_message_attribute.html | 60 + ...alization_GlobalizationError_notexist.html | 52 + ...n_GlobalizationManagerObject_notexist.html | 52 + ...lization_LongSuccessCallback_notexist.html | 52 + ...ization_LongSuccessCallback_onsuccess.html | 63 + ...ation_PatternSuccessCallback_notexist.html | 52 + ...tion_PatternSuccessCallback_onsuccess.html | 68 + ...uccessCallback_dateToString_onsuccess.html | 64 + ...ccessCallback_getLocaleName_onsuccess.html | 63 + ...llback_getPreferredLanguage_onsuccess.html | 63 + ...zation_StringSuccessCallback_notexist.html | 52 + ...cessCallback_numberToString_onsuccess.html | 63 + .../cordova_globalization_dateToString.html | 61 + ...zation_dateToString_date_TypeMismatch.html | 62 + ...dateToString_errorCallback_invalid_cb.html | 65 + ...dova_globalization_dateToString_exist.html | 52 + ...ova_globalization_dateToString_misarg.html | 57 + ...ion_dateToString_options_TypeMismatch.html | 63 + ...balization_dateToString_options_empty.html | 60 + ...teToString_successCallback_invalid_cb.html | 65 + ...obalization_dateToString_with_options.html | 63 + .../cordova_globalization_extend.html | 52 + ...dova_globalization_getCurrencyPattern.html | 60 + ...rencyPattern_errorCallback_invalid_cb.html | 64 + ...lobalization_getCurrencyPattern_exist.html | 52 + ...obalization_getCurrencyPattern_misarg.html | 57 + ...ncyPattern_successCallback_invalid_cb.html | 64 + .../cordova_globalization_getDateNames.html | 60 + ...getDateNames_errorCallback_invalid_cb.html | 64 + ...dova_globalization_getDateNames_exist.html | 52 + ...ova_globalization_getDateNames_misarg.html | 57 + ...ion_getDateNames_options_TypeMismatch.html | 62 + ...balization_getDateNames_options_empty.html | 59 + ...tDateNames_successCallback_invalid_cb.html | 64 + ...obalization_getDateNames_with_options.html | 61 + .../cordova_globalization_getDatePattern.html | 60 + ...tDatePattern_errorCallback_invalid_cb.html | 64 + ...va_globalization_getDatePattern_exist.html | 52 + ...a_globalization_getDatePattern_misarg.html | 58 + ...n_getDatePattern_options_TypeMismatch.html | 62 + ...lization_getDatePattern_options_empty.html | 59 + ...atePattern_successCallback_invalid_cb.html | 64 + ...alization_getDatePattern_with_options.html | 62 + ...rdova_globalization_getFirstDayOfWeek.html | 60 + ...rstDayOfWeek_errorCallback_invalid_cb.html | 64 + ...globalization_getFirstDayOfWeek_exist.html | 52 + ...lobalization_getFirstDayOfWeek_misarg.html | 57 + ...tDayOfWeek_successCallback_invalid_cb.html | 64 + .../cordova_globalization_getLocaleName.html | 60 + ...etLocaleName_errorCallback_invalid_cb.html | 64 + ...ova_globalization_getLocaleName_exist.html | 52 + ...va_globalization_getLocaleName_misarg.html | 57 + ...LocaleName_successCallback_invalid_cb.html | 64 + ...ordova_globalization_getNumberPattern.html | 60 + ...umberPattern_errorCallback_invalid_cb.html | 64 + ..._globalization_getNumberPattern_exist.html | 52 + ...globalization_getNumberPattern_misarg.html | 57 + ...getNumberPattern_options_TypeMismatch.html | 62 + ...zation_getNumberPattern_options_empty.html | 59 + ...berPattern_successCallback_invalid_cb.html | 64 + ...ization_getNumberPattern_with_options.html | 62 + ...va_globalization_getPreferredLanguage.html | 60 + ...rredLanguage_errorCallback_invalid_cb.html | 64 + ...balization_getPreferredLanguage_exist.html | 52 + ...alization_getPreferredLanguage_misarg.html | 57 + ...edLanguage_successCallback_invalid_cb.html | 64 + .../cordova_globalization_in_navigator.html | 53 + ...a_globalization_isDayLightSavingsTime.html | 62 + ...DayLightSavingsTime_date_TypeMismatch.html | 62 + ...tSavingsTime_errorCallback_invalid_cb.html | 65 + ...alization_isDayLightSavingsTime_exist.html | 52 + ...lization_isDayLightSavingsTime_misarg.html | 57 + ...avingsTime_successCallback_invalid_cb.html | 65 + .../cordova_globalization_notexist.html | 52 + .../cordova_globalization_numberToString.html | 61 + ...mberToString_errorCallback_invalid_cb.html | 64 + ...va_globalization_numberToString_exist.html | 52 + ...a_globalization_numberToString_misarg.html | 57 + ...n_numberToString_options_TypeMismatch.html | 62 + ...lization_numberToString_options_empty.html | 59 + ...erToString_successCallback_invalid_cb.html | 64 + ...alization_numberToString_with_options.html | 62 + .../cordova_globalization_stringToDate.html | 73 + ...stringToDate_errorCallback_invalid_cb.html | 64 + ...dova_globalization_stringToDate_exist.html | 52 + ...ova_globalization_stringToDate_misarg.html | 57 + ...ion_stringToDate_options_TypeMismatch.html | 62 + ...balization_stringToDate_options_empty.html | 68 + ...ringToDate_successCallback_invalid_cb.html | 64 + ...obalization_stringToDate_with_options.html | 71 + .../cordova_globalization_stringToNumber.html | 61 + ...ringToNumber_errorCallback_invalid_cb.html | 64 + ...va_globalization_stringToNumber_exist.html | 52 + ...a_globalization_stringToNumber_misarg.html | 57 + ...n_stringToNumber_options_TypeMismatch.html | 62 + ...lization_stringToNumber_options_empty.html | 59 + ...ngToNumber_successCallback_invalid_cb.html | 64 + ...alization_stringToNumber_with_options.html | 61 + ...lobalization_successCallback_notexist.html | 52 + .../globalization/support/unitcommon.js | 564 ++++ .../tct-globalization-cordova-tests/icon.png | Bin 0 -> 15972 bytes .../inst.apk.py | 108 + .../inst.wgt.py | 224 ++ .../inst.xpk.py | 231 ++ .../manifest.json | 13 + .../tct-globalization-cordova-tests/pack.py | 1104 ++++++++ .../resources/COPYING | 11 + .../resources/testharness.css | 107 + .../resources/testharness.js | 2353 +++++++++++++++++ .../resources/testharnessreport.js | 397 +++ .../suite.json | 30 + .../testcase.xsl | 200 ++ .../testresult.xsl | 491 ++++ .../tct-globalization-cordova-tests/tests.css | 132 + .../tests.full.xml | 936 +++++++ .../tct-globalization-cordova-tests/tests.xml | 588 ++++ .../webrunner/index.html | 137 + .../webrunner/jquery-1.10.2.min.js | 6 + .../webrunner/testrunner.js | 938 +++++++ 201 files changed, 25178 insertions(+) create mode 100755 common/tct-globalization-cordova-tests/COPYING create mode 100755 common/tct-globalization-cordova-tests/LICENSE.Apache-2.0 create mode 100755 common/tct-globalization-cordova-tests/README create mode 100755 common/tct-globalization-cordova-tests/config.xml create mode 100755 common/tct-globalization-cordova-tests/cordova/COPYING create mode 100755 common/tct-globalization-cordova-tests/cordova/cordova-5.1.1.js create mode 100755 common/tct-globalization-cordova-tests/cordova/cordova.js create mode 100755 common/tct-globalization-cordova-tests/cordova/cordova_plugins.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/console-via-logger.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/logger.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/tizen/Accelerometer.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/Acceleration.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/accelerometer.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/tizen/Device.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/www/device.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/tizen/Notification.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/www/notification.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/tizen/Events.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/www/register.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransfer.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransferError.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryEntry.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryReader.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Entry.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Errors.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/File.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileReader.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileSystem.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileWriter.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystemPaths.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystems-roots.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/requestFileSystem.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/rootUtils.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryEntry.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryReader.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/Entry.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/File.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/FileEntry.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/FileError.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/FileReader.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/FileSystem.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/FileUploadOptions.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/FileUploadResult.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/FileWriter.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/Flags.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/LocalFileSystem.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/Metadata.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/ProgressEvent.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/fileSystemPaths.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/fileSystems-roots.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/fileSystems.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/requestFileSystem.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-globalization/tizen/Globalization.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-globalization/www/GlobalizationError.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-globalization/www/globalization.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-media/tizen/Media.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-media/www/Media.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-media/www/MediaError.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-network-information/tizen/Connection.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-network-information/www/Connection.js create mode 100755 common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-network-information/www/network.js create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_ArrayStringSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_ArrayStringSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_DSTSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_DSTSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_DoubleSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_DoubleSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GetDatePatternSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GetDatePatternSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GetNumberPatternSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GetNumberPatternSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationDateSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationDateSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationError_FORMATTING_ERROR_const.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationError_PARSING_ERROR_const.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationError_PATTERN_ERROR_const.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationError_UNKNOWN_ERROR_const.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationError_code_attribute.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationError_message_attribute.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationError_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_GlobalizationManagerObject_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_LongSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_LongSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_PatternSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_PatternSuccessCallback_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_StringSuccessCallback_dateToString_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_StringSuccessCallback_getLocaleName_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_StringSuccessCallback_getPreferredLanguage_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_StringSuccessCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_StringSuccessCallback_numberToString_onsuccess.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_date_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_options_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_options_empty.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_dateToString_with_options.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_extend.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getCurrencyPattern.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getCurrencyPattern_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getCurrencyPattern_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getCurrencyPattern_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getCurrencyPattern_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames_options_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames_options_empty.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDateNames_with_options.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern_options_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern_options_empty.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getDatePattern_with_options.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getFirstDayOfWeek.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getFirstDayOfWeek_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getFirstDayOfWeek_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getFirstDayOfWeek_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getFirstDayOfWeek_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getLocaleName.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getLocaleName_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getLocaleName_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getLocaleName_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getLocaleName_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern_options_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern_options_empty.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getNumberPattern_with_options.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getPreferredLanguage.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getPreferredLanguage_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getPreferredLanguage_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getPreferredLanguage_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_getPreferredLanguage_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_in_navigator.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_isDayLightSavingsTime.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_isDayLightSavingsTime_date_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_isDayLightSavingsTime_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_isDayLightSavingsTime_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_isDayLightSavingsTime_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_isDayLightSavingsTime_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString_options_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString_options_empty.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_numberToString_with_options.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate_options_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate_options_empty.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToDate_with_options.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber_errorCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber_exist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber_misarg.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber_options_TypeMismatch.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber_options_empty.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber_successCallback_invalid_cb.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_stringToNumber_with_options.html create mode 100755 common/tct-globalization-cordova-tests/globalization/cordova_globalization_successCallback_notexist.html create mode 100755 common/tct-globalization-cordova-tests/globalization/support/unitcommon.js create mode 100755 common/tct-globalization-cordova-tests/icon.png create mode 100755 common/tct-globalization-cordova-tests/inst.apk.py create mode 100755 common/tct-globalization-cordova-tests/inst.wgt.py create mode 100755 common/tct-globalization-cordova-tests/inst.xpk.py create mode 100755 common/tct-globalization-cordova-tests/manifest.json create mode 100755 common/tct-globalization-cordova-tests/pack.py create mode 100755 common/tct-globalization-cordova-tests/resources/COPYING create mode 100755 common/tct-globalization-cordova-tests/resources/testharness.css create mode 100755 common/tct-globalization-cordova-tests/resources/testharness.js create mode 100755 common/tct-globalization-cordova-tests/resources/testharnessreport.js create mode 100755 common/tct-globalization-cordova-tests/suite.json create mode 100755 common/tct-globalization-cordova-tests/testcase.xsl create mode 100755 common/tct-globalization-cordova-tests/testresult.xsl create mode 100755 common/tct-globalization-cordova-tests/tests.css create mode 100755 common/tct-globalization-cordova-tests/tests.full.xml create mode 100755 common/tct-globalization-cordova-tests/tests.xml create mode 100755 common/tct-globalization-cordova-tests/webrunner/index.html create mode 100755 common/tct-globalization-cordova-tests/webrunner/jquery-1.10.2.min.js create mode 100755 common/tct-globalization-cordova-tests/webrunner/testrunner.js diff --git a/common/tct-globalization-cordova-tests/COPYING b/common/tct-globalization-cordova-tests/COPYING new file mode 100755 index 000000000..0683069e5 --- /dev/null +++ b/common/tct-globalization-cordova-tests/COPYING @@ -0,0 +1,13 @@ +Copyright (c) 2015 Samsung Electronics Co., Ltd. + +Licensed 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. diff --git a/common/tct-globalization-cordova-tests/LICENSE.Apache-2.0 b/common/tct-globalization-cordova-tests/LICENSE.Apache-2.0 new file mode 100755 index 000000000..7a4a3ea24 --- /dev/null +++ b/common/tct-globalization-cordova-tests/LICENSE.Apache-2.0 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. \ No newline at end of file diff --git a/common/tct-globalization-cordova-tests/README b/common/tct-globalization-cordova-tests/README new file mode 100755 index 000000000..3aeb45692 --- /dev/null +++ b/common/tct-globalization-cordova-tests/README @@ -0,0 +1,56 @@ +---------------------------------------------- +License +---------------------------------------------- +Copyright (c) 2015 Samsung Electronics Co., Ltd. + +Licensed 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. + +Authors: + Wei Ji + + + +---------------------------------------------- +Introduction +---------------------------------------------- +This test suite is for testing Cordova Globalization API, which covers the following specifications: +https://www.npmjs.com/package/cordova-plugin-globalization + +---------------------------------------------- +Test Environment +---------------------------------------------- +1. Testkit-stub must be installed on target device. +2. Testkit-lite must be installed on test machine. + +---------------------------------------------- +Build and Run +---------------------------------------------- +(Suppose you only get the source code and Testkit-Lite has been set up on your test machine. + If you have got tct-globalization-cordova-tests ZIP packages, you can directly go to step 3 on the test machine; + if you have not installed Testkit-Lite, you need to install the latest version.) + +Steps: +1. Prepare for building by running the following command: + cd tct-globalization-cordova-tests + +2. Build ZIP package by running the following command: + ./pack.sh + +3. Unzip the package on the test machine by running the following command: + unzip -o tct-globalization-cordova-tests-.zip -d /home/owner/share/tct + +4. Install the package on the test machine by running the following command: + /home/owner/share/tct/opt/tct-globalization-cordova-tests/inst.sh + +5. Run test cases by running the following command on host: + testkit-lite -f device:/home/owner/share/tct/opt/tct-globalization-cordova-tests/tests.xml -e "WRTLauncher" -o tct-globalization-cordova-tests.results.xml diff --git a/common/tct-globalization-cordova-tests/config.xml b/common/tct-globalization-cordova-tests/config.xml new file mode 100755 index 000000000..06a1c0f91 --- /dev/null +++ b/common/tct-globalization-cordova-tests/config.xml @@ -0,0 +1,9 @@ + + + tct-globalization-cordova-tests + + + + + + diff --git a/common/tct-globalization-cordova-tests/cordova/COPYING b/common/tct-globalization-cordova-tests/cordova/COPYING new file mode 100755 index 000000000..11ff1a757 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/COPYING @@ -0,0 +1,7 @@ +All test files under this folder except COPYING come from +https://github.com/apache/cordova-tizen +without any modification + +These tests are copyright by the author listed in the test +file. The tests are licensed under Apache License, Version 2.0: +http://www.apache.org/licenses/LICENSE-2.0 \ No newline at end of file diff --git a/common/tct-globalization-cordova-tests/cordova/cordova-5.1.1.js b/common/tct-globalization-cordova-tests/cordova/cordova-5.1.1.js new file mode 100755 index 000000000..cb58c1ddb --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/cordova-5.1.1.js @@ -0,0 +1,1651 @@ +/* +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. +*/ + +// adapted from cordova.js for browser + +;(function() { +var PLATFORM_VERSION_BUILD_LABEL = '5.1.1'; +//file: src/scripts/require.js + +/*jshint -W079 */ +/*jshint -W020 */ + +var require, + define; + +(function () { + var modules = {}, + // Stack of moduleIds currently being built. + requireStack = [], + // Map of module ID -> index into requireStack of modules currently being built. + inProgressModules = {}, + SEPARATOR = "."; + + + + function build(module) { + var factory = module.factory, + localRequire = function (id) { + var resultantId = id; + //Its a relative path, so lop off the last portion and add the id (minus "./") + if (id.charAt(0) === ".") { + resultantId = module.id.slice(0, module.id.lastIndexOf(SEPARATOR)) + SEPARATOR + id.slice(2); + } + return require(resultantId); + }; + module.exports = {}; + delete module.factory; + factory(localRequire, module.exports, module); + return module.exports; + } + + require = function (id) { + if (!modules[id]) { + throw "module " + id + " not found"; + } else if (id in inProgressModules) { + var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id; + throw "Cycle in require graph: " + cycle; + } + if (modules[id].factory) { + try { + inProgressModules[id] = requireStack.length; + requireStack.push(id); + return build(modules[id]); + } finally { + delete inProgressModules[id]; + requireStack.pop(); + } + } + return modules[id].exports; + }; + + define = function (id, factory) { + if (modules[id]) { + throw "module " + id + " already defined"; + } + + modules[id] = { + id: id, + factory: factory + }; + }; + + define.remove = function (id) { + delete modules[id]; + }; + + define.moduleMap = modules; +})(); + +//Export for use in node +if (typeof module === "object" && typeof require === "function") { + module.exports.require = require; + module.exports.define = define; +} + +//file: src/cordova.js +define("cordova", function(require, exports, module) { + +if(window.cordova){ + throw new Error("cordova already defined"); +} + + +var channel = require('cordova/channel'); +var platform = require('cordova/platform'); + + +/** +* Intercept calls to addEventListener + removeEventListener and handle deviceready, +* resume, and pause events. +*/ +var m_document_addEventListener = document.addEventListener; +var m_document_removeEventListener = document.removeEventListener; +var m_window_addEventListener = window.addEventListener; +var m_window_removeEventListener = window.removeEventListener; + +/** +* Houses custom event handlers to intercept on document + window event listeners. +*/ +var documentEventHandlers = {}, + windowEventHandlers = {}; + +document.addEventListener = function(evt, handler, capture) { + var e = evt.toLowerCase(); + if (typeof documentEventHandlers[e] != 'undefined') { + documentEventHandlers[e].subscribe(handler); + } else { + m_document_addEventListener.call(document, evt, handler, capture); + } +}; + +window.addEventListener = function(evt, handler, capture) { + var e = evt.toLowerCase(); + if (typeof windowEventHandlers[e] != 'undefined') { + windowEventHandlers[e].subscribe(handler); + } else { + m_window_addEventListener.call(window, evt, handler, capture); + } +}; + +document.removeEventListener = function(evt, handler, capture) { + var e = evt.toLowerCase(); + // If unsubscribing from an event that is handled by a plugin + if (typeof documentEventHandlers[e] != "undefined") { + documentEventHandlers[e].unsubscribe(handler); + } else { + m_document_removeEventListener.call(document, evt, handler, capture); + } +}; + +window.removeEventListener = function(evt, handler, capture) { + var e = evt.toLowerCase(); + // If unsubscribing from an event that is handled by a plugin + if (typeof windowEventHandlers[e] != "undefined") { + windowEventHandlers[e].unsubscribe(handler); + } else { + m_window_removeEventListener.call(window, evt, handler, capture); + } +}; + +function createEvent(type, data) { + var event = document.createEvent('Events'); + event.initEvent(type, false, false); + if (data) { + for (var i in data) { + if (data.hasOwnProperty(i)) { + event[i] = data[i]; + } + } + } + return event; +} + + +var cordova = { + define:define, + require:require, + version:PLATFORM_VERSION_BUILD_LABEL, + platformVersion:PLATFORM_VERSION_BUILD_LABEL, + platformId:platform.id, + /** + * Methods to add/remove your own addEventListener hijacking on document + window. + */ + addWindowEventHandler:function(event) { + return (windowEventHandlers[event] = channel.create(event)); + }, + addStickyDocumentEventHandler:function(event) { + return (documentEventHandlers[event] = channel.createSticky(event)); + }, + addDocumentEventHandler:function(event) { + return (documentEventHandlers[event] = channel.create(event)); + }, + removeWindowEventHandler:function(event) { + delete windowEventHandlers[event]; + }, + removeDocumentEventHandler:function(event) { + delete documentEventHandlers[event]; + }, + /** + * Retrieve original event handlers that were replaced by Cordova + * + * @return object + */ + getOriginalHandlers: function() { + return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener}, + 'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}}; + }, + /** + * Method to fire event from native code + * bNoDetach is required for events which cause an exception which needs to be caught in native code + */ + fireDocumentEvent: function(type, data, bNoDetach) { + var evt = createEvent(type, data); + if (typeof documentEventHandlers[type] != 'undefined') { + if( bNoDetach ) { + documentEventHandlers[type].fire(evt); + } + else { + setTimeout(function() { + // Fire deviceready on listeners that were registered before cordova.js was loaded. + if (type == 'deviceready') { + document.dispatchEvent(evt); + } + documentEventHandlers[type].fire(evt); + }, 0); + } + } else { + document.dispatchEvent(evt); + } + }, + fireWindowEvent: function(type, data) { + var evt = createEvent(type,data); + if (typeof windowEventHandlers[type] != 'undefined') { + setTimeout(function() { + windowEventHandlers[type].fire(evt); + }, 0); + } else { + window.dispatchEvent(evt); + } + }, + + /** + * Plugin callback mechanism. + */ + // Randomize the starting callbackId to avoid collisions after refreshing or navigating. + // This way, it's very unlikely that any new callback would get the same callbackId as an old callback. + callbackId: Math.floor(Math.random() * 2000000000), + callbacks: {}, + callbackStatus: { + NO_RESULT: 0, + OK: 1, + CLASS_NOT_FOUND_EXCEPTION: 2, + ILLEGAL_ACCESS_EXCEPTION: 3, + INSTANTIATION_EXCEPTION: 4, + MALFORMED_URL_EXCEPTION: 5, + IO_EXCEPTION: 6, + INVALID_ACTION: 7, + JSON_EXCEPTION: 8, + ERROR: 9 + }, + + /** + * Called by native code when returning successful result from an action. + */ + callbackSuccess: function(callbackId, args) { + cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback); + }, + + /** + * Called by native code when returning error result from an action. + */ + callbackError: function(callbackId, args) { + // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative. + // Derive success from status. + cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback); + }, + + /** + * Called by native code when returning the result from an action. + */ + callbackFromNative: function(callbackId, isSuccess, status, args, keepCallback) { + try { + var callback = cordova.callbacks[callbackId]; + if (callback) { + if (isSuccess && status == cordova.callbackStatus.OK) { + callback.success && callback.success.apply(null, args); + } else if (!isSuccess) { + callback.fail && callback.fail.apply(null, args); + } + /* + else + Note, this case is intentionally not caught. + this can happen if isSuccess is true, but callbackStatus is NO_RESULT + which is used to remove a callback from the list without calling the callbacks + typically keepCallback is false in this case + */ + // Clear callback if not expecting any more results + if (!keepCallback) { + delete cordova.callbacks[callbackId]; + } + } + } + catch (err) { + var msg = "Error in " + (isSuccess ? "Success" : "Error") + " callbackId: " + callbackId + " : " + err; + console && console.log && console.log(msg); + cordova.fireWindowEvent("cordovacallbackerror", { 'message': msg }); + throw err; + } + }, + addConstructor: function(func) { + channel.onCordovaReady.subscribe(function() { + try { + func(); + } catch(e) { + console.log("Failed to run constructor: " + e); + } + }); + } +}; + + +module.exports = cordova; + +}); + +//file: src/common/argscheck.js +define("cordova/argscheck", function(require, exports, module) { + +var utils = require('cordova/utils'); + +var moduleExports = module.exports; + +var typeMap = { + 'A': 'Array', + 'D': 'Date', + 'N': 'Number', + 'S': 'String', + 'F': 'Function', + 'O': 'Object' +}; + +function extractParamName(callee, argIndex) { + return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex]; +} + +function checkArgs(spec, functionName, args, opt_callee) { + if (!moduleExports.enableChecks) { + return; + } + var errMsg = null; + var typeName; + for (var i = 0; i < spec.length; ++i) { + var c = spec.charAt(i), + cUpper = c.toUpperCase(), + arg = args[i]; + // Asterix means allow anything. + if (c == '*') { + continue; + } + typeName = utils.typeName(arg); + if ((arg === null || arg === undefined) && c == cUpper) { + continue; + } + if (typeName != typeMap[cUpper]) { + errMsg = 'Expected ' + typeMap[cUpper]; + break; + } + } + if (errMsg) { + errMsg += ', but got ' + typeName + '.'; + errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg; + // Don't log when running unit tests. + if (typeof jasmine == 'undefined') { + console.error(errMsg); + } + throw TypeError(errMsg); + } +} + +function getValue(value, defaultValue) { + return value === undefined ? defaultValue : value; +} + +moduleExports.checkArgs = checkArgs; +moduleExports.getValue = getValue; +moduleExports.enableChecks = true; + + +}); + +//file: src/common/base64.js +define("cordova/base64", function(require, exports, module) { + +var base64 = exports; + +base64.fromArrayBuffer = function(arrayBuffer) { + var array = new Uint8Array(arrayBuffer); + return uint8ToBase64(array); +}; + +base64.toArrayBuffer = function(str) { + var decodedStr = typeof atob != 'undefined' ? atob(str) : new Buffer(str,'base64').toString('binary'); + var arrayBuffer = new ArrayBuffer(decodedStr.length); + var array = new Uint8Array(arrayBuffer); + for (var i=0, len=decodedStr.length; i < len; i++) { + array[i] = decodedStr.charCodeAt(i); + } + return arrayBuffer; +}; + +//------------------------------------------------------------------------------ + +/* This code is based on the performance tests at http://jsperf.com/b64tests +* This 12-bit-at-a-time algorithm was the best performing version on all +* platforms tested. +*/ + +var b64_6bit = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +var b64_12bit; + +var b64_12bitTable = function() { + b64_12bit = []; + for (var i=0; i<64; i++) { + for (var j=0; j<64; j++) { + b64_12bit[i*64+j] = b64_6bit[i] + b64_6bit[j]; + } + } + b64_12bitTable = function() { return b64_12bit; }; + return b64_12bit; +}; + +function uint8ToBase64(rawData) { + var numBytes = rawData.byteLength; + var output=""; + var segment; + var table = b64_12bitTable(); + for (var i=0;i> 12]; + output += table[segment & 0xfff]; + } + if (numBytes - i == 2) { + segment = (rawData[i] << 16) + (rawData[i+1] << 8); + output += table[segment >> 12]; + output += b64_6bit[(segment & 0xfff) >> 6]; + output += '='; + } else if (numBytes - i == 1) { + segment = (rawData[i] << 16); + output += table[segment >> 12]; + output += '=='; + } + return output; +} + +}); + +//file: src/common/builder.js +define("cordova/builder", function(require, exports, module) { + +var utils = require('cordova/utils'); + +function each(objects, func, context) { + for (var prop in objects) { + if (objects.hasOwnProperty(prop)) { + func.apply(context, [objects[prop], prop]); + } + } +} + +function clobber(obj, key, value) { + exports.replaceHookForTesting(obj, key); + var needsProperty = false; + try { + obj[key] = value; + } catch (e) { + needsProperty = true; + } + // Getters can only be overridden by getters. + if (needsProperty || obj[key] !== value) { + utils.defineGetter(obj, key, function() { + return value; + }); + } +} + +function assignOrWrapInDeprecateGetter(obj, key, value, message) { + if (message) { + utils.defineGetter(obj, key, function() { + console.log(message); + delete obj[key]; + clobber(obj, key, value); + return value; + }); + } else { + clobber(obj, key, value); + } +} + +function include(parent, objects, clobber, merge) { + each(objects, function (obj, key) { + try { + var result = obj.path ? require(obj.path) : {}; + + if (clobber) { + // Clobber if it doesn't exist. + if (typeof parent[key] === 'undefined') { + assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); + } else if (typeof obj.path !== 'undefined') { + // If merging, merge properties onto parent, otherwise, clobber. + if (merge) { + recursiveMerge(parent[key], result); + } else { + assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); + } + } + result = parent[key]; + } else { + // Overwrite if not currently defined. + if (typeof parent[key] == 'undefined') { + assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated); + } else { + // Set result to what already exists, so we can build children into it if they exist. + result = parent[key]; + } + } + + if (obj.children) { + include(result, obj.children, clobber, merge); + } + } catch(e) { + utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"'); + } + }); +} + +/** +* Merge properties from one object onto another recursively. Properties from +* the src object will overwrite existing target property. +* +* @param target Object to merge properties into. +* @param src Object to merge properties from. +*/ +function recursiveMerge(target, src) { + for (var prop in src) { + if (src.hasOwnProperty(prop)) { + if (target.prototype && target.prototype.constructor === target) { + // If the target object is a constructor override off prototype. + clobber(target.prototype, prop, src[prop]); + } else { + if (typeof src[prop] === 'object' && typeof target[prop] === 'object') { + recursiveMerge(target[prop], src[prop]); + } else { + clobber(target, prop, src[prop]); + } + } + } + } +} + +exports.buildIntoButDoNotClobber = function(objects, target) { + include(target, objects, false, false); +}; +exports.buildIntoAndClobber = function(objects, target) { + include(target, objects, true, false); +}; +exports.buildIntoAndMerge = function(objects, target) { + include(target, objects, true, true); +}; +exports.recursiveMerge = recursiveMerge; +exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter; +exports.replaceHookForTesting = function() {}; + +}); + +//file: src/common/channel.js +define("cordova/channel", function(require, exports, module) { + +var utils = require('cordova/utils'), + nextGuid = 1; + +/** +* Custom pub-sub "channel" that can have functions subscribed to it +* This object is used to define and control firing of events for +* cordova initialization, as well as for custom events thereafter. +* +* The order of events during page load and Cordova startup is as follows: +* +* onDOMContentLoaded* Internal event that is received when the web page is loaded and parsed. +* onNativeReady* Internal event that indicates the Cordova native side is ready. +* onCordovaReady* Internal event fired when all Cordova JavaScript objects have been created. +* onDeviceReady* User event fired to indicate that Cordova is ready +* onResume User event fired to indicate a start/resume lifecycle event +* onPause User event fired to indicate a pause lifecycle event +* +* The events marked with an * are sticky. Once they have fired, they will stay in the fired state. +* All listeners that subscribe after the event is fired will be executed right away. +* +* The only Cordova events that user code should register for are: +* deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript +* pause App has moved to background +* resume App has returned to foreground +* +* Listeners can be registered as: +* document.addEventListener("deviceready", myDeviceReadyListener, false); +* document.addEventListener("resume", myResumeListener, false); +* document.addEventListener("pause", myPauseListener, false); +* +* The DOM lifecycle events should be used for saving and restoring state +* window.onload +* window.onunload +* +*/ + +/** +* Channel +* @constructor +* @param type String the channel name +*/ +var Channel = function(type, sticky) { + this.type = type; + // Map of guid -> function. + this.handlers = {}; + // 0 = Non-sticky, 1 = Sticky non-fired, 2 = Sticky fired. + this.state = sticky ? 1 : 0; + // Used in sticky mode to remember args passed to fire(). + this.fireArgs = null; + // Used by onHasSubscribersChange to know if there are any listeners. + this.numHandlers = 0; + // Function that is called when the first listener is subscribed, or when + // the last listener is unsubscribed. + this.onHasSubscribersChange = null; +}, + channel = { + /** + * Calls the provided function only after all of the channels specified + * have been fired. All channels must be sticky channels. + */ + join: function(h, c) { + var len = c.length, + i = len, + f = function() { + if (!(--i)) h(); + }; + for (var j=0; j + if (strategy == 'r') { + continue; + } + var symbolPath = symbolList[i + 2]; + var lastDot = symbolPath.lastIndexOf('.'); + var namespace = symbolPath.substr(0, lastDot); + var lastName = symbolPath.substr(lastDot + 1); + + var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null; + var parentObj = prepareNamespace(namespace, context); + var target = parentObj[lastName]; + + if (strategy == 'm' && target) { + builder.recursiveMerge(target, module); + } else if ((strategy == 'd' && !target) || (strategy != 'd')) { + if (!(symbolPath in origSymbols)) { + origSymbols[symbolPath] = target; + } + builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg); + } + } +}; + +exports.getOriginalSymbol = function(context, symbolPath) { + var origSymbols = context.CDV_origSymbols; + if (origSymbols && (symbolPath in origSymbols)) { + return origSymbols[symbolPath]; + } + var parts = symbolPath.split('.'); + var obj = context; + for (var i = 0; i < parts.length; ++i) { + obj = obj && obj[parts[i]]; + } + return obj; +}; + +exports.reset(); + + +}); + +//file: src/common/modulemapper_b.js +define("cordova/modulemapper_b", function(require, exports, module) { + +var builder = require('cordova/builder'), + symbolList = [], + deprecationMap; + +exports.reset = function() { + symbolList = []; + deprecationMap = {}; +}; + +function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) { + symbolList.push(strategy, moduleName, symbolPath); + if (opt_deprecationMessage) { + deprecationMap[symbolPath] = opt_deprecationMessage; + } +} + +//Note: Android 2.3 does have Function.bind(). +exports.clobbers = function(moduleName, symbolPath, opt_deprecationMessage) { + addEntry('c', moduleName, symbolPath, opt_deprecationMessage); +}; + +exports.merges = function(moduleName, symbolPath, opt_deprecationMessage) { + addEntry('m', moduleName, symbolPath, opt_deprecationMessage); +}; + +exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) { + addEntry('d', moduleName, symbolPath, opt_deprecationMessage); +}; + +exports.runs = function(moduleName) { + addEntry('r', moduleName, null); +}; + +function prepareNamespace(symbolPath, context) { + if (!symbolPath) { + return context; + } + var parts = symbolPath.split('.'); + var cur = context; + for (var i = 0, part; part = parts[i]; ++i) { + cur = cur[part] = cur[part] || {}; + } + return cur; +} + +exports.mapModules = function(context) { + var origSymbols = {}; + context.CDV_origSymbols = origSymbols; + for (var i = 0, len = symbolList.length; i < len; i += 3) { + var strategy = symbolList[i]; + var moduleName = symbolList[i + 1]; + var module = require(moduleName); + // + if (strategy == 'r') { + continue; + } + var symbolPath = symbolList[i + 2]; + var lastDot = symbolPath.lastIndexOf('.'); + var namespace = symbolPath.substr(0, lastDot); + var lastName = symbolPath.substr(lastDot + 1); + + var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null; + var parentObj = prepareNamespace(namespace, context); + var target = parentObj[lastName]; + + if (strategy == 'm' && target) { + builder.recursiveMerge(target, module); + } else if ((strategy == 'd' && !target) || (strategy != 'd')) { + if (!(symbolPath in origSymbols)) { + origSymbols[symbolPath] = target; + } + builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg); + } + } +}; + +exports.getOriginalSymbol = function(context, symbolPath) { + var origSymbols = context.CDV_origSymbols; + if (origSymbols && (symbolPath in origSymbols)) { + return origSymbols[symbolPath]; + } + var parts = symbolPath.split('.'); + var obj = context; + for (var i = 0; i < parts.length; ++i) { + obj = obj && obj[parts[i]]; + } + return obj; +}; + +exports.reset(); + + +}); + +// Tizen platform +define("cordova/platform", function(require, exports, module) { + +module.exports = { + id: 'tizen', + cordovaVersion: '5.1.1', + + bootstrap: function() { + + var modulemapper = require('cordova/modulemapper'); + var channel = require('cordova/channel'); + + modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy'); + + channel.onNativeReady.fire(); + + // End of bootstrap + } +}; + +}); + +//file: src/common/pluginloader.js +define("cordova/pluginloader", function(require, exports, module) { + +/* + NOTE: this file is NOT used when we use the browserify workflow +*/ + +var modulemapper = require('cordova/modulemapper'); +var urlutil = require('cordova/urlutil'); + +//Helper function to inject a '); +} + +function backHome() { + if (window.device && device.platform && device.platform.toLowerCase() === 'android') { + navigator.app.backHistory(); + } else { + window.history.go(-1); + } +} diff --git a/common/tct-globalization-cordova-tests/cordova/cordova_plugins.js b/common/tct-globalization-cordova-tests/cordova/cordova_plugins.js new file mode 100755 index 000000000..00817caba --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/cordova_plugins.js @@ -0,0 +1,376 @@ +cordova.define('cordova/plugin_list', function(require, exports, module) { +module.exports = [ + { + "file": "plugins/cordova-plugin-console/www/logger.js", + "id": "cordova-plugin-console.logger", + "clobbers": [ + "cordova.logger" + ] + }, + { + "file": "plugins/cordova-plugin-console/www/console-via-logger.js", + "id": "cordova-plugin-console.console", + "clobbers": [ + "console" + ] + }, + { + "file": "plugins/cordova-plugin-device/www/device.js", + "id": "cordova-plugin-device.device", + "clobbers": [ + "device" + ] + }, + { + "file": "plugins/cordova-plugin-device/tizen/Device.js", + "id": "cordova-plugin-device.tizen.Device", + "runs": true + }, + { + "file": "plugins/cordova-plugin-device-motion/www/accelerometer.js", + "id": "cordova-plugin-device-motion.Accelerometer", + "clobbers": [ + "navigator.accelerometer" + ] + }, + { + "file": "plugins/cordova-plugin-device-motion/www/Acceleration.js", + "id": "cordova-plugin-device-motion.Acceleration", + "clobbers": [ + "navigator.Acceleration" + ] + }, + { + "file": "plugins/cordova-plugin-device-motion/tizen/Accelerometer.js", + "id": "cordova-plugin-device-motion.tizen.Accelerometer", + "runs": true + }, + { + "file": "plugins/cordova-plugin-dialogs/www/notification.js", + "id": "cordova-plugin-dialogs.notification", + "merges": [ + "navigator.notification" + ] + }, + { + "file": "plugins/cordova-plugin-dialogs/tizen/Notification.js", + "id": "cordova-plugin-dialogs.tizen.Notification", + "runs": true + }, + { + "file": "plugins/cordova-plugin-events/www/register.js", + "id": "cordova-plugin-events.register", + "runs": true + }, + { + "file": "plugins/cordova-plugin-events/tizen/Events.js", + "id": "cordova-plugin-events.tizen.Events", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryEntry.js", + "id": "cordova-plugin-file.DirectoryEntry", + "clobbers": [ + "window.DirectoryEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryReader.js", + "id": "cordova-plugin-file.DirectoryReader", + "clobbers": [ + "window.DirectoryReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Entry.js", + "id": "cordova-plugin-file.Entry", + "clobbers": [ + "window.Entry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/File.js", + "id": "cordova-plugin-file.File", + "clobbers": [ + "window.File" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileEntry.js", + "id": "cordova-plugin-file.FileEntry", + "clobbers": [ + "window.FileEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileError.js", + "id": "cordova-plugin-file.FileError", + "clobbers": [ + "window.FileError" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileReader.js", + "id": "cordova-plugin-file.FileReader", + "clobbers": [ + "window.FileReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileSystem.js", + "id": "cordova-plugin-file.FileSystem", + "clobbers": [ + "window.FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadOptions.js", + "id": "cordova-plugin-file.FileUploadOptions", + "clobbers": [ + "window.FileUploadOptions" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadResult.js", + "id": "cordova-plugin-file.FileUploadResult", + "clobbers": [ + "window.FileUploadResult" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileWriter.js", + "id": "cordova-plugin-file.FileWriter", + "clobbers": [ + "window.FileWriter" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Flags.js", + "id": "cordova-plugin-file.Flags", + "clobbers": [ + "window.Flags" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/LocalFileSystem.js", + "id": "cordova-plugin-file.LocalFileSystem", + "clobbers": [ + "window.LocalFileSystem" + ], + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Metadata.js", + "id": "cordova-plugin-file.Metadata", + "clobbers": [ + "window.Metadata" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/ProgressEvent.js", + "id": "cordova-plugin-file.ProgressEvent", + "clobbers": [ + "window.ProgressEvent" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems.js", + "id": "cordova-plugin-file.fileSystems" + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems-roots.js", + "id": "cordova-plugin-file.fileSystems-roots" + }, + { + "file": "plugins/cordova-plugin-file/www/requestFileSystem.js", + "id": "cordova-plugin-file.requestFileSystem", + "clobbers": [ + "window.requestFileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js", + "id": "cordova-plugin-file.resolveLocalFileSystemURI", + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystemPaths.js", + "id": "cordova-plugin-file.fileSystemPaths", + "merges": [ + "cordova" + ], + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/Errors.js", + "id": "cordova-plugin-file.tizen.Errors", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/rootUtils.js", + "id": "cordova-plugin-file.tizen.rootUtils", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/DirectoryEntry.js", + "id": "cordova-plugin-file.tizen.DirectoryEntry", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/DirectoryReader.js", + "id": "cordova-plugin-file.tizen.DirectoryReader", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/Entry.js", + "id": "cordova-plugin-file.tizen.Entry", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/FileReader.js", + "id": "cordova-plugin-file.tizen.FileReader", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/fileSystemPaths.js", + "id": "cordova-plugin-file.tizen.fileSystemPaths", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/fileSystems-roots.js", + "id": "cordova-plugin-file.tizen.fileSystems-roots", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/FileWriter.js", + "id": "cordova-plugin-file.tizen.FileWriter", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/requestFileSystem.js", + "id": "cordova-plugin-file.tizen.requestFileSystem", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js", + "id": "cordova-plugin-file.tizen.resolveLocalFileSystemURI", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/File.js", + "id": "cordova-plugin-file.tizen.File", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/tizen/FileSystem.js", + "id": "cordova-plugin-file.tizen.FileSystem", + "merges": [ + "window.FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file-transfer/www/FileTransferError.js", + "id": "cordova-plugin-file-transfer.FileTransferError", + "clobbers": [ + "window.FileTransferError" + ] + }, + { + "file": "plugins/cordova-plugin-file-transfer/www/FileTransfer.js", + "id": "cordova-plugin-file-transfer.FileTransfer", + "clobbers": [ + "window.FileTransfer" + ] + }, + { + "file": "plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js", + "id": "cordova-plugin-file-transfer.tizen.FileTransfer", + "runs": true + }, + { + "file": "plugins/cordova-plugin-network-information/www/network.js", + "id": "cordova-plugin-network-information.network", + "clobbers": [ + "navigator.connection", + "navigator.network.connection" + ] + }, + { + "file": "plugins/cordova-plugin-network-information/www/Connection.js", + "id": "cordova-plugin-network-information.Connection", + "clobbers": [ + "Connection" + ] + }, + { + "file": "plugins/cordova-plugin-network-information/tizen/NetworkStatus.js", + "id": "cordova-plugin-network-information.tizen.NetworkStatus", + "runs": true + }, + { + "file": "plugins/cordova-plugin-network-information/tizen/Connection.js", + "id": "cordova-plugin-network-information.tizen.Connection", + "clobbers": [ + "navigator.connection", + "navigator.network.connection" + ] + }, + { + "file": "plugins/cordova-plugin-globalization/www/GlobalizationError.js", + "id": "cordova-plugin-globalization.GlobalizationError", + "clobbers": [ + "window.GlobalizationError" + ] + }, + { + "file": "plugins/cordova-plugin-globalization/www/globalization.js", + "id": "cordova-plugin-globalization.globalization", + "clobbers": [ + "navigator.globalization" + ] + }, + { + "file": "plugins/cordova-plugin-globalization/tizen/Globalization.js", + "id": "cordova-plugin-globalization.tizen.Globalization", + "runs": true + }, + { + "file": "plugins/cordova-plugin-media/www/MediaError.js", + "id": "cordova-plugin-media.MediaError", + "clobbers": [ + "window.MediaError" + ] + }, + { + "file": "plugins/cordova-plugin-media/www/Media.js", + "id": "cordova-plugin-media.Media", + "clobbers": [ + "window.Media" + ] + }, + { + "file": "plugins/cordova-plugin-media/tizen/Media.js", + "id": "cordova-plugin-media.tizen.Media", + "runs": true + } +]; +module.exports.metadata = +// TOP OF METADATA +{ + "cordova-plugin-console": "1.0.1", + "cordova-plugin-device": "1.0.1", + "cordova-plugin-device-motion": "1.2.0", + "cordova-plugin-dialogs": "1.1.1", + "cordova-plugin-events": "0.0.1", + "cordova-plugin-file": "3.0.0", + "cordova-plugin-file-transfer": "1.3.0", + "cordova-plugin-globalization": "1.0.1", + "cordova-plugin-media": "1.0.1", + "cordova-plugin-network-information": "1.0.1", +} +// BOTTOM OF METADATA +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/console-via-logger.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/console-via-logger.js new file mode 100755 index 000000000..0ce8cea89 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/console-via-logger.js @@ -0,0 +1,189 @@ +cordova.define("cordova-plugin-console.console", function(require, exports, module) { /* + * + * 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. + * +*/ + +//------------------------------------------------------------------------------ + +var logger = require("./logger"); +var utils = require("cordova/utils"); + +//------------------------------------------------------------------------------ +// object that we're exporting +//------------------------------------------------------------------------------ +var console = module.exports; + +//------------------------------------------------------------------------------ +// copy of the original console object +//------------------------------------------------------------------------------ +var WinConsole = window.console; + +//------------------------------------------------------------------------------ +// whether to use the logger +//------------------------------------------------------------------------------ +var UseLogger = false; + +//------------------------------------------------------------------------------ +// Timers +//------------------------------------------------------------------------------ +var Timers = {}; + +//------------------------------------------------------------------------------ +// used for unimplemented methods +//------------------------------------------------------------------------------ +function noop() {} + +//------------------------------------------------------------------------------ +// used for unimplemented methods +//------------------------------------------------------------------------------ +console.useLogger = function (value) { + if (arguments.length) UseLogger = !!value; + + if (UseLogger) { + if (logger.useConsole()) { + throw new Error("console and logger are too intertwingly"); + } + } + + return UseLogger; +}; + +//------------------------------------------------------------------------------ +console.log = function() { + if (logger.useConsole()) return; + logger.log.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.error = function() { + if (logger.useConsole()) return; + logger.error.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.warn = function() { + if (logger.useConsole()) return; + logger.warn.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.info = function() { + if (logger.useConsole()) return; + logger.info.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.debug = function() { + if (logger.useConsole()) return; + logger.debug.apply(logger, [].slice.call(arguments)); +}; + +//------------------------------------------------------------------------------ +console.assert = function(expression) { + if (expression) return; + + var message = logger.format.apply(logger.format, [].slice.call(arguments, 1)); + console.log("ASSERT: " + message); +}; + +//------------------------------------------------------------------------------ +console.clear = function() {}; + +//------------------------------------------------------------------------------ +console.dir = function(object) { + console.log("%o", object); +}; + +//------------------------------------------------------------------------------ +console.dirxml = function(node) { + console.log(node.innerHTML); +}; + +//------------------------------------------------------------------------------ +console.trace = noop; + +//------------------------------------------------------------------------------ +console.group = console.log; + +//------------------------------------------------------------------------------ +console.groupCollapsed = console.log; + +//------------------------------------------------------------------------------ +console.groupEnd = noop; + +//------------------------------------------------------------------------------ +console.time = function(name) { + Timers[name] = new Date().valueOf(); +}; + +//------------------------------------------------------------------------------ +console.timeEnd = function(name) { + var timeStart = Timers[name]; + if (!timeStart) { + console.warn("unknown timer: " + name); + return; + } + + var timeElapsed = new Date().valueOf() - timeStart; + console.log(name + ": " + timeElapsed + "ms"); +}; + +//------------------------------------------------------------------------------ +console.timeStamp = noop; + +//------------------------------------------------------------------------------ +console.profile = noop; + +//------------------------------------------------------------------------------ +console.profileEnd = noop; + +//------------------------------------------------------------------------------ +console.count = noop; + +//------------------------------------------------------------------------------ +console.exception = console.log; + +//------------------------------------------------------------------------------ +console.table = function(data, columns) { + console.log("%o", data); +}; + +//------------------------------------------------------------------------------ +// return a new function that calls both functions passed as args +//------------------------------------------------------------------------------ +function wrappedOrigCall(orgFunc, newFunc) { + return function() { + var args = [].slice.call(arguments); + try { orgFunc.apply(WinConsole, args); } catch (e) {} + try { newFunc.apply(console, args); } catch (e) {} + }; +} + +//------------------------------------------------------------------------------ +// For every function that exists in the original console object, that +// also exists in the new console object, wrap the new console method +// with one that calls both +//------------------------------------------------------------------------------ +for (var key in console) { + if (typeof WinConsole[key] == "function") { + console[key] = wrappedOrigCall(WinConsole[key], console[key]); + } +} + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/logger.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/logger.js new file mode 100755 index 000000000..7a9a75d34 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-console/www/logger.js @@ -0,0 +1,357 @@ +cordova.define("cordova-plugin-console.logger", function(require, exports, module) { /* + * + * 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. + * +*/ + +//------------------------------------------------------------------------------ +// The logger module exports the following properties/functions: +// +// LOG - constant for the level LOG +// ERROR - constant for the level ERROR +// WARN - constant for the level WARN +// INFO - constant for the level INFO +// DEBUG - constant for the level DEBUG +// logLevel() - returns current log level +// logLevel(value) - sets and returns a new log level +// useConsole() - returns whether logger is using console +// useConsole(value) - sets and returns whether logger is using console +// log(message,...) - logs a message at level LOG +// error(message,...) - logs a message at level ERROR +// warn(message,...) - logs a message at level WARN +// info(message,...) - logs a message at level INFO +// debug(message,...) - logs a message at level DEBUG +// logLevel(level,message,...) - logs a message specified level +// +//------------------------------------------------------------------------------ + +var logger = exports; + +var exec = require('cordova/exec'); +var utils = require('cordova/utils'); + +var UseConsole = false; +var UseLogger = true; +var Queued = []; +var DeviceReady = false; +var CurrentLevel; + +var originalConsole = console; + +/** + * Logging levels + */ + +var Levels = [ + "LOG", + "ERROR", + "WARN", + "INFO", + "DEBUG" +]; + +/* + * add the logging levels to the logger object and + * to a separate levelsMap object for testing + */ + +var LevelsMap = {}; +for (var i=0; i 0){ + formatArgs.unshift(fmtString); // add formatString + } + + var message = logger.format.apply(logger.format, formatArgs); + + if (LevelsMap[level] === null) { + throw new Error("invalid logging level: " + level); + } + + if (LevelsMap[level] > CurrentLevel) return; + + // queue the message if not yet at deviceready + if (!DeviceReady && !UseConsole) { + Queued.push([level, message]); + return; + } + + // Log using the native logger if that is enabled + if (UseLogger) { + exec(null, null, "Console", "logLevel", [level, message]); + } + + // Log using the console if that is enabled + if (UseConsole) { + // make sure console is not using logger + if (console.useLogger()) { + throw new Error("console and logger are too intertwingly"); + } + + // log to the console + switch (level) { + case logger.LOG: originalConsole.log(message); break; + case logger.ERROR: originalConsole.log("ERROR: " + message); break; + case logger.WARN: originalConsole.log("WARN: " + message); break; + case logger.INFO: originalConsole.log("INFO: " + message); break; + case logger.DEBUG: originalConsole.log("DEBUG: " + message); break; + } + } +}; + + +/** + * Formats a string and arguments following it ala console.log() + * + * Any remaining arguments will be appended to the formatted string. + * + * for rationale, see FireBug's Console API: + * http://getfirebug.com/wiki/index.php/Console_API + */ +logger.format = function(formatString, args) { + return __format(arguments[0], [].slice.call(arguments,1)).join(' '); +}; + + +//------------------------------------------------------------------------------ +/** + * Formats a string and arguments following it ala vsprintf() + * + * format chars: + * %j - format arg as JSON + * %o - format arg as JSON + * %c - format arg as '' + * %% - replace with '%' + * any other char following % will format it's + * arg via toString(). + * + * Returns an array containing the formatted string and any remaining + * arguments. + */ +function __format(formatString, args) { + if (formatString === null || formatString === undefined) return [""]; + if (arguments.length == 1) return [formatString.toString()]; + + if (typeof formatString != "string") + formatString = formatString.toString(); + + var pattern = /(.*?)%(.)(.*)/; + var rest = formatString; + var result = []; + + while (args.length) { + var match = pattern.exec(rest); + if (!match) break; + + var arg = args.shift(); + rest = match[3]; + result.push(match[1]); + + if (match[2] == '%') { + result.push('%'); + args.unshift(arg); + continue; + } + + result.push(__formatted(arg, match[2])); + } + + result.push(rest); + + var remainingArgs = [].slice.call(args); + remainingArgs.unshift(result.join('')); + return remainingArgs; +} + +function __formatted(object, formatChar) { + + try { + switch(formatChar) { + case 'j': + case 'o': return JSON.stringify(object); + case 'c': return ''; + } + } + catch (e) { + return "error JSON.stringify()ing argument: " + e; + } + + if ((object === null) || (object === undefined)) { + return Object.prototype.toString.call(object); + } + + return object.toString(); +} + + +//------------------------------------------------------------------------------ +// when deviceready fires, log queued messages +logger.__onDeviceReady = function() { + if (DeviceReady) return; + + DeviceReady = true; + + for (var i=0; i begin +var plugin_name = 'cordova-plugin-device-motion.tizen.Accelerometer'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + +var successCB = null; +var count = 0; + +function listener(eventData) { + var accel = {}; + + accel.x = eventData.acceleration.x; + accel.y = eventData.acceleration.y; + accel.z = eventData.acceleration.z; + accel.timestamp = new Date().getTime(); + + if (accel.x === null || accel.y === null || accel.z === null) { + // Ignore first event with nulls + return; + } + + if (count++ === 0) { + return; + } + + successCB && successCB(accel); +} + +var Accelerometer = { + start: function (success, error) { + if (!successCB) { + count = 0; + successCB = success; + window.addEventListener('devicemotion', listener, false); + } + }, stop: function () { + window.removeEventListener('devicemotion', listener, false); + successCB = null; + } +}; + +module.exports = Accelerometer; +require('cordova/exec/proxy').add('Accelerometer', Accelerometer); + +console.log('Loaded cordova.device-motion API'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/Acceleration.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/Acceleration.js new file mode 100755 index 000000000..00957952b --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/Acceleration.js @@ -0,0 +1,32 @@ +/* + * + * 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. + * +*/ +cordova.define("cordova-plugin-device-motion.Acceleration", function(require, exports, module) { + +var Acceleration = function(x, y, z, timestamp) { + this.x = x; + this.y = y; + this.z = z; + this.timestamp = timestamp || (new Date()).getTime(); +}; + +module.exports = Acceleration; + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/accelerometer.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/accelerometer.js new file mode 100755 index 000000000..206c69c09 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device-motion/www/accelerometer.js @@ -0,0 +1,201 @@ +/* + * + * 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. + * +*/ +cordova.define("cordova-plugin-device-motion.Accelerometer", function(require, exports, module) { + +/** + * This class provides access to device accelerometer data. + * @constructor + */ +var argscheck = require('cordova/argscheck'), + utils = require("cordova/utils"), + exec = require("cordova/exec"), + Acceleration = require('./Acceleration'); + +// Is the accel sensor running? +var running = false; + +// Keeps reference to watchAcceleration calls. +var timers = {}; + +// Array of listeners; used to keep track of when we should call start and stop. +var listeners = []; + +// Last returned acceleration object from native +var accel = null; + +// Timer used when faking up devicemotion events +var eventTimerId = null; + +// Tells native to start. +function start() { + exec(function (a) { + var tempListeners = listeners.slice(0); + accel = new Acceleration(a.x, a.y, a.z, a.timestamp); + for (var i = 0, l = tempListeners.length; i < l; i++) { + tempListeners[i].win(accel); + } + }, function (e) { + var tempListeners = listeners.slice(0); + for (var i = 0, l = tempListeners.length; i < l; i++) { + tempListeners[i].fail(e); + } + }, "Accelerometer", "start", []); + running = true; +} + +// Tells native to stop. +function stop() { + exec(null, null, "Accelerometer", "stop", []); + accel = null; + running = false; +} + +// Adds a callback pair to the listeners array +function createCallbackPair(win, fail) { + return { win: win, fail: fail }; +} + +// Removes a win/fail listener pair from the listeners array +function removeListeners(l) { + var idx = listeners.indexOf(l); + if (idx > -1) { + listeners.splice(idx, 1); + if (listeners.length === 0) { + stop(); + } + } +} + +var accelerometer = { + /** + * Asynchronously acquires the current acceleration. + * + * @param {Function} successCallback The function to call when the acceleration data is available + * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL) + * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL) + */ + getCurrentAcceleration: function (successCallback, errorCallback, options) { + argscheck.checkArgs('fFO', 'accelerometer.getCurrentAcceleration', arguments); + + if (cordova.platformId === "windowsphone") { + exec(function (a) { + accel = new Acceleration(a.x, a.y, a.z, a.timestamp); + successCallback(accel); + }, function (e) { + errorCallback(e); + }, "Accelerometer", "getCurrentAcceleration", []); + + return; + } + + var p; + var win = function (a) { + removeListeners(p); + successCallback(a); + }; + var fail = function (e) { + removeListeners(p); + errorCallback && errorCallback(e); + }; + + p = createCallbackPair(win, fail); + listeners.push(p); + + if (!running) { + start(); + } + }, + + /** + * Asynchronously acquires the acceleration repeatedly at a given interval. + * + * @param {Function} successCallback The function to call each time the acceleration data is available + * @param {Function} errorCallback The function to call when there is an error getting the acceleration data. (OPTIONAL) + * @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL) + * @return String The watch id that must be passed to #clearWatch to stop watching. + */ + watchAcceleration: function (successCallback, errorCallback, options) { + argscheck.checkArgs('fFO', 'accelerometer.watchAcceleration', arguments); + // Default interval (10 sec) + var frequency = (options && options.frequency && typeof options.frequency == 'number') ? options.frequency : 10000; + + // Keep reference to watch id, and report accel readings as often as defined in frequency + var id = utils.createUUID(); + + var p = createCallbackPair(function () { }, function (e) { + removeListeners(p); + errorCallback && errorCallback(e); + }); + listeners.push(p); + + timers[id] = { + timer: window.setInterval(function () { + if (accel) { + successCallback(accel); + } + }, frequency), + listeners: p + }; + + if (running) { + // If we're already running then immediately invoke the success callback + // but only if we have retrieved a value, sample code does not check for null ... + if (accel) { + successCallback(accel); + } + } else { + start(); + } + + if (cordova.platformId === "browser" && !eventTimerId) { + // Start firing devicemotion events if we haven't already + var devicemotionEvent = new Event('devicemotion'); + eventTimerId = window.setInterval(function() { + window.dispatchEvent(devicemotionEvent); + }, 200); + } + + return id; + }, + + /** + * Clears the specified accelerometer watch. + * + * @param {String} id The id of the watch returned from #watchAcceleration. + */ + clearWatch: function (id) { + // Stop javascript timer & remove from timer list + if (id && timers[id]) { + window.clearInterval(timers[id].timer); + removeListeners(timers[id].listeners); + delete timers[id]; + + if (eventTimerId && Object.keys(timers).length === 0) { + // No more watchers, so stop firing 'devicemotion' events + window.clearInterval(eventTimerId); + eventTimerId = null; + } + } + } +}; +module.exports = accelerometer; + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/tizen/Device.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/tizen/Device.js new file mode 100755 index 000000000..16c9d8256 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/tizen/Device.js @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name = 'cordova-plugin-device.tizen.Device'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + +function DeviceInfo() { + try { + this.model = tizen.systeminfo.getCapability('http://tizen.org/system/model_name'); + this.isVirtual = -1 !== this.model.toLowerCase().indexOf('emulator'); + } catch (e) { + console.log(e); + this.model = undefined; + this.isVirtual = undefined; + } + try { + this.platform = tizen.systeminfo.getCapability('http://tizen.org/system/platform.name'); + } catch (e) { + console.log(e); + this.platform = undefined; + } + try { + this.uuid = tizen.systeminfo.getCapability('http://tizen.org/system/tizenid'); + this.serial = this.uuid; + } catch (e) { + console.log(e); + this.uuid = undefined; + this.serial = undefined; + } + try { + this.version = tizen.systeminfo.getCapability('http://tizen.org/feature/platform.version'); + } catch (e) { + console.log(e); + this.version = undefined; + } + try { + this.manufacturer = tizen.systeminfo.getCapability('http://tizen.org/system/manufacturer'); + } catch (e) { + console.log(e); + this.manufacturer = undefined; + } +} + +var di; + +exports = { + getDeviceInfo: function (success, error) { + if (!di) { + di = new DeviceInfo(); + } + success({ + cordova: di.cordovaVersion, + model: di.model, + platform: di.platform, + uuid: di.uuid, + version: di.version, + manufacturer: di.manufacturer, // not documented, but required by tests + isVirtual: di.isVirtual, + serial: di.serial + }); + } +}; + +require("cordova/exec/proxy").add("Device", exports); + +console.log('Loaded cordova.device API'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/www/device.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/www/device.js new file mode 100755 index 000000000..ff0c5b48c --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-device/www/device.js @@ -0,0 +1,85 @@ +cordova.define("cordova-plugin-device.device", function(require, exports, module) { /* + * + * 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. + * +*/ + +var argscheck = require('cordova/argscheck'), + channel = require('cordova/channel'), + utils = require('cordova/utils'), + exec = require('cordova/exec'), + cordova = require('cordova'); + +channel.createSticky('onCordovaInfoReady'); +// Tell cordova channel to wait on the CordovaInfoReady event +channel.waitForInitialization('onCordovaInfoReady'); + +/** + * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the + * phone, etc. + * @constructor + */ +function Device() { + this.available = false; + this.platform = null; + this.version = null; + this.uuid = null; + this.cordova = null; + this.model = null; + this.manufacturer = null; + this.isVirtual = null; + this.serial = null; + + var me = this; + + channel.onCordovaReady.subscribe(function() { + me.getInfo(function(info) { + //ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js + //TODO: CB-5105 native implementations should not return info.cordova + var buildLabel = cordova.version; + me.available = true; + me.platform = info.platform; + me.version = info.version; + me.uuid = info.uuid; + me.cordova = buildLabel; + me.model = info.model; + me.isVirtual = info.isVirtual; + me.manufacturer = info.manufacturer || 'unknown'; + me.serial = info.serial || 'unknown'; + channel.onCordovaInfoReady.fire(); + },function(e) { + me.available = false; + utils.alert("[ERROR] Error initializing Cordova: " + e); + }); + }); +} + +/** + * Get device info + * + * @param {Function} successCallback The function to call when the heading data is available + * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL) + */ +Device.prototype.getInfo = function(successCallback, errorCallback) { + argscheck.checkArgs('fF', 'Device.getInfo', arguments); + exec(successCallback, errorCallback, "Device", "getDeviceInfo", []); +}; + +module.exports = new Device(); + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/tizen/Notification.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/tizen/Notification.js new file mode 100755 index 000000000..9b1143d53 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/tizen/Notification.js @@ -0,0 +1,376 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name = 'cordova-plugin-dialogs.tizen.Notification'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + +var _document = document || {}; + +var playback = (function() { + var soundElement; + var counter = 1; + var soundPathArray = ['/usr/share/feedback/sound/operation/operation.wav', '/usr/share/feedback/sound/operation/home.wav']; + var soundPathCount = 0; + + function win(v) { + console.log('Success to get the notification sound: ' + v); + soundElement = new Audio(v); + soundElement.addEventListener('ended', function() { + if (--counter > 0) { + soundElement.play(); + } + }); + } + + function fail(e) { + console.error('Failed to get the notification sound: ' + e); + } + + function recursiveFailCallback(e) { + fail(e); + console.warn("Retry with another path"); + + if(soundPathCount >= soundPathArray.length){ + console.error('Failed to get the notification sound: There is no available sound file path'); + return; + } + + tizen.filesystem.resolve(soundPathArray[soundPathCount++], function(file) { + win(file.toURI()); + }, recursiveFailCallback, 'r'); + + } + + if ('tv' === tizen.systeminfo.getCapability('http://tizen.org/feature/profile').toLowerCase()) { + tizen.filesystem.resolve(soundPathArray[soundPathCount++], function(file) { + win(file.toURI()); + }, recursiveFailCallback, 'r'); + } else { + tizen.systemsetting.getProperty('NOTIFICATION_EMAIL', win, fail); + } + + function beep(times) { + counter = times || 1; + if (soundElement) { + soundElement.play(); + } + } + + return { + beep: beep + } +})(); + +var popup = (function () { + var boxId = 'cordova-modal-box'; + var overlayId = 'cordova-modal-overlay'; + var popupId = 'cordova-modal-popup'; + var buttonIdPrefix = 'cordova-modal-popup-button-'; + var inputId = 'cordova-modal-popup-input'; + var d = _document; + var sheet; + var box; + var overlay; + var popup; + var dismissCallback; + var tizenHwKeyListener = null; + + function isPopupVisible() { + if (box) { + return box.style.display === 'block'; + } else { + return false; + } + } + + function tizenHwKeyFunc(evt) { + if (evt.keyName === "back") { + evt.stopImmediatePropagation(); + if (dismissCallback) { + dismissCallback(); + } + } + } + + function showPopup() { + box.style.display = 'block'; + } + + function hidePopup() { + box.style.display = 'none'; + } + + function createCloseCallback(callback, id, prompt) { + return function() { + var text; + if (prompt) { + text = d.getElementById(inputId).value; + } + + if (tizenHwKeyListener) { + window.removeEventListener('tizenhwkey', tizenHwKeyListener, true); + tizenHwKeyListener = null; + } + + hidePopup(); + callback(id, text); + } + } + + function hasCssClass(name) { + for (var i = 0; i < d.styleSheets.length; ++i) { + for (var j = 0; j < d.styleSheets[i].rules.length; ++j) { + if (name === d.styleSheets[i].rules[j].selectorText) { + return true; + } + } + } + return false; + } + + function createStyleSheet() { + if (!sheet) { + var style = document.createElement('style'); + d.head.appendChild(style); + sheet = style.sheet; + } + } + + function initCss() { + var hasOverlay = hasCssClass('.cordova-ui-popupwindow-overlay'); + var hasPopup = hasCssClass('.cordova-ui-popupwindow'); + + if (!hasOverlay) { + createStyleSheet(); + + sheet.insertRule('.cordova-ui-popupwindow-overlay {' + + 'background: #000000;' + + 'opacity: 0.6;' + + 'position: fixed;' + + 'top: 0;' + + 'left: 0;' + + 'margin: 0;' + + 'padding: 0;' + + 'width: 100%;' + + 'height: 100%;' + + 'z-index: 1200;' + + '}'); + } + + if (!hasPopup) { + createStyleSheet(); + + sheet.insertRule('.cordova-ui-popupwindow {' + + 'position: fixed;' + + 'top: 50%;' + + 'left: 50%;' + + 'margin-right: -50%;' + + 'transform: translate(-50%, -50%);' + + '-webkit-transform: translate(-50%, -50%);' + + 'z-index: 1201 !important;' + + 'color: #f8f6ef;' + + 'background: #2a2d30;' + + 'width: 90%;' + + 'padding: 6px;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-title {' + + 'width: 100%;' + + 'height: 100%;' + + 'font-size: 1.0909090909090908rem;' + + 'background: #5093b6;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-title p {' + + 'margin: 0rem 0rem;' + + 'padding: 0.5909090909090909rem 0.5rem;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-text {' + + 'width: 100%;' + + 'color: #f9f9f9;' + + 'font-size: 1.0909090909090908rem;' + + 'background: #2a2d30;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-text p {' + + 'text-align: left;' + + 'padding: 0.4rem;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-input {' + + 'width: 100%;' + + 'padding-bottom: 0.4rem;' + + 'text-align: center;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-input input {' + + 'width: 90%;' + + 'color: #222222;' + + 'font-size: 1rem;' + + 'line-height: 1.2;' + + 'font-weight: normal;' + + 'border: 1px solid #555;' + + 'border-radius: 5px;' + + '-webkit-border-radius: 5px;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-button-bg {' + + 'font-size: 1.4545454545454546rem;' + + 'background: #2a2d30;' + + 'width: 100%;' + + 'padding-top: 0.5rem;' + + 'padding-bottom: 0.5rem;' + + 'vertical-align: middle;' + + 'text-align: right;' + + '}'); + sheet.insertRule('.cordova-ui-popupwindow .popup-button-bg input {' + + 'border: 1px solid #555;' + + 'border-radius: 5px;' + + '-webkit-border-radius: 5px;' + + 'text-align: center;' + + 'display: inline-block;' + + 'background: #444;' + + 'color: #9ab;' + + 'font-size: 0.8em;' + + 'text-decoration: none;' + + 'margin: 1px 1px 1px 3px;' + + '}'); + } + } + + function initHtml() { + var touchMoveDisable = function(e) { + e.preventDefault(); // disable the touch-move of the background + }; + + box = d.createElement('div'); + box.id = boxId; + + overlay = box.appendChild(d.createElement('div')); + overlay.id = overlayId; + overlay.className = 'cordova-ui-popupwindow-overlay'; + overlay.addEventListener('click', function() { + if (dismissCallback) { + dismissCallback(); + } + }, false); + overlay.addEventListener('touchmove', touchMoveDisable); + + popup = box.appendChild(d.createElement('div')); + popup.id = popupId; + popup.className = 'cordova-ui-popupwindow'; + popup.addEventListener('touchmove', touchMoveDisable); + + hidePopup(); + + d.getElementsByTagName('body')[0].appendChild(box); + } + + function init() { + if (!box) { + initCss(); + initHtml(); + } + } + + function show(options) { + if (isPopupVisible()) { + console.warn('Popup is already shown, ignoring.'); + return; + } + + init(); + + options = options || {}; + + // prepare contents of the popup + var html = ''; + html += ''; + html += ''; + if (options.prompt) { + html += ''; + } + var buttons = options.buttons || ['Button']; + html += ''; + + popup.innerHTML = html; + + // link callbacks + var callback = options.callback || function(){}; + dismissCallback = createCloseCallback(callback, 0, options.prompt); + + for (var i = 0; i < buttons.length; ++i) { + var e = d.getElementById(buttonIdPrefix + (i + 1)); + e.addEventListener('click', createCloseCallback(callback, i + 1, options.prompt), false); + } + + if (!tizenHwKeyListener) { + tizenHwKeyListener = tizenHwKeyFunc; + window.addEventListener('tizenhwkey', tizenHwKeyListener, true); + } + + // show popup + showPopup(); + } + + return { + show: show + }; +})(); + +exports = { + alert: function(successCallback, errorCallback, args) { + popup.show({ + message: args[0], + callback: successCallback, + title: args[1], + buttons: [args[2]] + }); + }, + confirm: function(successCallback, errorCallback, args) { + popup.show({ + message: args[0], + callback: successCallback, + title: args[1], + buttons: args[2] + }); + }, + prompt: function(successCallback, errorCallback, args) { + popup.show({ + message: args[0], + callback: function(idx, text) { + successCallback({buttonIndex: idx, input1: text}); + }, + title: args[1], + buttons: args[2], + prompt: true, + promptDefaultText: args[3] + }); + }, + beep: function(successCallback, errorCallback, args) { + playback.beep(args[0]); + } +}; + +require("cordova/exec/proxy").add("Notification", exports); + +console.log('Loaded cordova.dialog API'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/www/notification.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/www/notification.js new file mode 100755 index 000000000..9331997c5 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-dialogs/www/notification.js @@ -0,0 +1,114 @@ +cordova.define("cordova-plugin-dialogs.notification", function(require, exports, module) { /* + * + * 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. + * +*/ + +var exec = require('cordova/exec'); +var platform = require('cordova/platform'); + +/** + * Provides access to notifications on the device. + */ + +module.exports = { + + /** + * Open a native alert dialog, with a customizable title and button text. + * + * @param {String} message Message to print in the body of the alert + * @param {Function} completeCallback The callback that is called when user clicks on a button. + * @param {String} title Title of the alert dialog (default: Alert) + * @param {String} buttonLabel Label of the close button (default: OK) + */ + alert: function(message, completeCallback, title, buttonLabel) { + var _title = (title || "Alert"); + var _buttonLabel = (buttonLabel || "OK"); + exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]); + }, + + /** + * Open a native confirm dialog, with a customizable title and button text. + * The result that the user selects is returned to the result callback. + * + * @param {String} message Message to print in the body of the alert + * @param {Function} resultCallback The callback that is called when user clicks on a button. + * @param {String} title Title of the alert dialog (default: Confirm) + * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) + */ + confirm: function(message, resultCallback, title, buttonLabels) { + var _title = (title || "Confirm"); + var _buttonLabels = (buttonLabels || ["OK", "Cancel"]); + + // Strings are deprecated! + if (typeof _buttonLabels === 'string') { + console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); + } + + // Some platforms take an array of button label names. + // Other platforms take a comma separated list. + // For compatibility, we convert to the desired type based on the platform. + if (platform.id == "amazon-fireos" || platform.id == "android" || platform.id == "ios" || + platform.id == "windowsphone" || platform.id == "firefoxos" || platform.id == "ubuntu" || + platform.id == "windows8" || platform.id == "windows" || platform.id == "tizen") { + + if (typeof _buttonLabels === 'string') { + _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here + } + } else { + if (Array.isArray(_buttonLabels)) { + var buttonLabelArray = _buttonLabels; + _buttonLabels = buttonLabelArray.toString(); + } + } + exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]); + }, + + /** + * Open a native prompt dialog, with a customizable title and button text. + * The following results are returned to the result callback: + * buttonIndex Index number of the button selected. + * input1 The text entered in the prompt dialog box. + * + * @param {String} message Dialog message to display (default: "Prompt message") + * @param {Function} resultCallback The callback that is called when user clicks on a button. + * @param {String} title Title of the dialog (default: "Prompt") + * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) + * @param {String} defaultText Textbox input value (default: empty string) + */ + prompt: function(message, resultCallback, title, buttonLabels, defaultText) { + var _message = (message || "Prompt message"); + var _title = (title || "Prompt"); + var _buttonLabels = (buttonLabels || ["OK","Cancel"]); + var _defaultText = (defaultText || ""); + exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]); + }, + + /** + * Causes the device to beep. + * On Android, the default notification ringtone is played "count" times. + * + * @param {Integer} count The number of beeps. + */ + beep: function(count) { + var defaultedCount = count || 1; + exec(null, null, "Notification", "beep", [ defaultedCount ]); + } +}; + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/tizen/Events.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/tizen/Events.js new file mode 100755 index 000000000..6c4f048e5 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/tizen/Events.js @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name = 'cordova-plugin-events.tizen.Events'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + +//////////////////////////// EventHandler +function EventHandler(name) { + this.name = name; +} + +EventHandler.prototype.startListener = function(l) { + console.error('Event \"' + this.name + '\" is not suported.'); +}; + +EventHandler.prototype.stopListener = function() { + console.error('Event \"' + this.name + '\" is not suported.'); +}; + +//////////////////////////// WindowEventHandler +function WindowEventHandler(name, event_type, callback, target) { + EventHandler.call(this, name); + this.event_type = event_type; + this.callback = callback; + this.target = target || window; +} + +WindowEventHandler.prototype = Object.create(EventHandler.prototype); +WindowEventHandler.prototype.constructor = WindowEventHandler; + +WindowEventHandler.prototype.startListener = function(l) { + if (this.callback) { + this.listener = l; + this.target.addEventListener(this.event_type, this.callback); + } else { + Object.getPrototypeOf(WindowEventHandler.prototype).startListener.call(this, l); + } +}; + +WindowEventHandler.prototype.stopListener = function() { + if (this.callback) { + this.target.removeEventListener(this.event_type, this.callback); + this.listener = undefined; + } else { + Object.getPrototypeOf(WindowEventHandler.prototype).stopListener.call(this); + } +}; + +//////////////////////////// HwKeyEventHandler +function HwKeyEventHandler(name, type) { + var that = this; + var callback = function(e) { + if (type === e.keyName && that.listener) { + that.listener(that.name); + } + }; + WindowEventHandler.call(this, name, 'tizenhwkey', callback); +} + +HwKeyEventHandler.prototype = Object.create(WindowEventHandler.prototype); +HwKeyEventHandler.prototype.constructor = HwKeyEventHandler; + +//////////////////////////// VisibilityEventHandler +function VisibilityEventHandler(name, hidden) { + var prop, visibility_event, callback; + + if (typeof document.hidden !== 'undefined') { + prop = 'hidden'; + visibility_event = 'visibilitychange'; + } else if (typeof document.webkitHidden !== 'undefined') { + prop = 'webkitHidden'; + visibility_event = 'webkitvisibilitychange'; + } + + if (prop) { + var that = this; + callback = function() { + if (hidden === document[prop] && that.listener) { + that.listener(that.name); + } + }; + } + + WindowEventHandler.call(this, name, visibility_event, callback, document); +} + +VisibilityEventHandler.prototype = Object.create(WindowEventHandler.prototype); +VisibilityEventHandler.prototype.constructor = VisibilityEventHandler; + +//////////////////////////// InputDeviceEventHandler +function InputDeviceEventHandler(name, type) { + var callback; + + try { + this.key = tizen.inputdevice.getKey(type); + + var that = this; + callback = function(e) { + if (that.key.code === e.keyCode && that.listener) { + that.listener(that.name); + } + }; + } catch (e) { + console.error('Exception: ' + e.message); + } + + WindowEventHandler.call(this, name, 'keydown', callback); +} + +InputDeviceEventHandler.prototype = Object.create(WindowEventHandler.prototype); +InputDeviceEventHandler.prototype.constructor = InputDeviceEventHandler; + +InputDeviceEventHandler.prototype.startListener = function(l) { + if (this.key) { + try { + tizen.inputdevice.registerKey(this.key.name); + } catch (e) { + console.error('Exception: ' + e.message); + } + } + + Object.getPrototypeOf(InputDeviceEventHandler.prototype).startListener.call(this, l); +}; + +InputDeviceEventHandler.prototype.stopListener = function() { + if (this.key) { + try { + tizen.inputdevice.unregisterKey(this.key.name); + } catch (e) { + console.error('Exception: ' + e.message); + } + } + + Object.getPrototypeOf(InputDeviceEventHandler.prototype).stopListener.call(this); +}; + +//////////////////////////// all handlers +var handlers = { + backbutton: new HwKeyEventHandler('backbutton', 'back'), + menubutton: new HwKeyEventHandler('menubutton', 'menu'), + searchbutton: new EventHandler('searchbutton'), + startcallbutton: new EventHandler('startcallbutton'), + endcallbutton: new EventHandler('endcallbutton'), + volumedownbutton: new InputDeviceEventHandler('volumedownbutton', 'VolumeDown'), + volumeupbutton: new InputDeviceEventHandler('volumeupbutton', 'VolumeUp'), + pause: new VisibilityEventHandler('pause', true), + resume: new VisibilityEventHandler('resume', false) +}; + +exports = { + startListener: function(successCallback, errorCallback, args) { + var e = args[0]; + if (handlers[e]) { + handlers[e].startListener(successCallback); + } else { + console.error('Unknown event: ' + e); + } + }, + stopListener: function(successCallback, errorCallback, args) { + var e = args[0]; + if (handlers[e]) { + handlers[e].stopListener(); + } else { + console.error('Unknown event: ' + e); + } + } +}; + +require('cordova/exec/proxy').add('Events', exports); + +console.log('Loaded cordova.events API'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/www/register.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/www/register.js new file mode 100755 index 000000000..d0b95fc39 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-events/www/register.js @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +cordova.define("cordova-plugin-events.register", function(require, exports, module) { + +var cordova = require('cordova'); +var channel = require('cordova/channel'); +var exec = require('cordova/exec'); + +var PLUGIN_NAME = 'Events'; + +var handled_events = {}; + +function fireEventListener(e) { + if (handled_events[e]) { + if ('pause' === e) { + // pause event needs to be fired synchronously, otherwise it will appear + // after the application is resumed + cordova.fireDocumentEvent(e, null, true); + } else { + cordova.fireDocumentEvent(e); + } + } else { + console.error('Unknown event: ' + e); + } +} + +function addChannelListener(ch, event_name) { + ch.onHasSubscribersChange = function() { + var start = this.numHandlers > 0; + var method = start ? 'startListener' : 'stopListener'; + var callback = start ? fireEventListener : null; + exec(callback, null, PLUGIN_NAME, method, [event_name]); + }; + handled_events[event_name] = event_name; +} + +function createChannelForButton(button) { + var ch = cordova.addDocumentEventHandler(button); + addChannelListener(ch, button); +} + +var buttons = [ + 'backbutton', + 'menubutton', + 'searchbutton', + 'startcallbutton', + 'endcallbutton', + 'volumedownbutton', + 'volumeupbutton' +]; + +for (var i = 0; i < buttons.length; ++i) { + createChannelForButton(buttons[i]); +} + +var events = { + pause: channel.onPause, + resume: channel.onResume +}; + +for (var e in events) { + if (events.hasOwnProperty(e)) { + addChannelListener(events[e], e); + } +} + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js new file mode 100755 index 000000000..692e75e17 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name = 'cordova-plugin-file-transfer.tizen.FileTransfer'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + +function getParentPath(filePath) { + var pos = filePath.lastIndexOf('/'); + return filePath.substring(0, pos + 1); +} + +function getFileName(filePath) { + var pos = filePath.lastIndexOf('/'); + return filePath.substring(pos + 1); +} + +function TizenErrCodeToErrCode(err_code) { + switch (err_code) { + case WebAPIException.NOT_FOUND_ERR: + return FileTransferError.FILE_NOT_FOUND_ERR; + + case WebAPIException.URL_MISMATCH_ERR: + return FileTransferError.INVALID_URL_ERR; + + case WebAPIException.NETWORK_ERR: + return FileTransferError.CONNECTION_ERR; + + case WebAPIException.ABORT_ERR: + return FileTransferError.ABORT_ERR; + + default: + return FileTransferError.NOT_MODIFIED_ERR; + } +} + +function checkURL(url) { + return url.indexOf(' ') === -1; +} + +var uploads = {}; +var downloads = {}; + +var filePrefix = 'file://'; + +exports = { + upload: function(successCallback, errorCallback, args) { + var filePath = args[0], + server = args[1], + fileKey = args[2] || 'file', + fileName = args[3] || 'image.jpg', + mimeType = args[4] || 'image/jpeg', + params = args[5], + trustAllHosts = args[6], // not used + chunkedMode = args[7], + headers = args[8], + id = args[9], + httpMethod = args[10] || 'POST'; + + if (0 !== filePath.indexOf(filePrefix)) { + filePath = filePrefix + filePath; + } + + var fail = function(code, status, response) { + uploads[id] && delete uploads[id]; + var error = new FileTransferError(code, filePath, server, status, response); + errorCallback && errorCallback(error); + }; + + if (!checkURL(server)) { + fail(FileTransferError.INVALID_URL_ERR); + return; + } + + function successCB(entry) { + if (entry.isFile) { + entry.file(function(file) { + function uploadFile(blobFile) { + var fd = new FormData(); + + fd.append(fileKey, blobFile, fileName); + + for (var prop in params) { + if(params.hasOwnProperty(prop)) { + fd.append(prop, params[prop]); + } + } + var xhr = uploads[id] = new XMLHttpRequest(); + + xhr.open(httpMethod, server); + + // Fill XHR headers + for (var header in headers) { + if (headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + xhr.onload = function(evt) { + if (xhr.status === 200) { + uploads[id] && delete uploads[id]; + successCallback({ + bytesSent: file.size, + responseCode: xhr.status, + response: xhr.response + }); + } else if (xhr.status === 404) { + fail(FileTransferError.INVALID_URL_ERR, this.status, this.response); + } else { + fail(FileTransferError.CONNECTION_ERR, this.status, this.response); + } + }; + + xhr.ontimeout = function(evt) { + fail(FileTransferError.CONNECTION_ERR, this.status, this.response); + }; + + xhr.onerror = function() { + fail(FileTransferError.CONNECTION_ERR, this.status, this.response); + }; + + xhr.onabort = function () { + fail(FileTransferError.ABORT_ERR, this.status, this.response); + }; + + xhr.upload.onprogress = function (e) { + successCallback(e); + }; + + xhr.send(fd); + + // Special case when transfer already aborted, but XHR isn't sent. + // In this case XHR won't fire an abort event, so we need to check if transfers record + // isn't deleted by filetransfer.abort and if so, call XHR's abort method again + if (!uploads[id]) { + xhr.abort(); + } + } + + uploadFile(file); + + }, function(error) { + fail(FileTransferError.CONNECTION_ERR); + }); + } + } + + function errorCB() { + fail(FileTransferError.FILE_NOT_FOUND_ERR); + } + + resolveLocalFileSystemURL(filePath, successCB, errorCB); + }, + download: function(successCallback, errorCallback, args) { + var url = args[0], + filePath = args[1], + trustAllHosts = args[2], // not used + id = args[3], + headers = args[4]; + + if (!checkURL(url)) { + errorCallback(new FileTransferError(FileTransferError.INVALID_URL_ERR, url, filePath)); + return; + } + + var dirPath = getParentPath(filePath); + var fileName = getFileName(filePath); + + var xhr = downloads[id] = new XMLHttpRequest(); + + function fail(code, body) { + delete downloads[id]; + errorCallback(new FileTransferError(code, + url, + filePath, + xhr.status, + body, + null)); + } + + xhr.addEventListener('progress', function (evt) { + successCallback(evt); + }); + + xhr.addEventListener('abort', function (evt) { + fail(FileTransferError.ABORT_ERR, xhr.response); + }); + + xhr.addEventListener('error', function (evt) { + fail(FileTransferError.CONNECTION_ERR, xhr.response); + }); + + xhr.addEventListener('load', function (evt) { + if ((xhr.status === 200 || xhr.status === 0) && xhr.response) { + + tizen.filesystem.resolve(dirPath, function (dir) { + if (dir.isFile) { + fail(FileTransferError.FILE_NOT_FOUND_ERR); + return; + } + + function writeFile(dir) { + var file = dir.createFile(fileName); + + file.openStream( + 'rw', + function (stream) { + stream.writeBytes(Array.prototype.slice.call(new Uint8Array(xhr.response))); + + delete downloads[id]; + + resolveLocalFileSystemURL( + filePath, + function (fileEntry) { + fileEntry.filesystemName = fileEntry.filesystem.name; + successCallback(fileEntry); + }, function (err) { + fail(TizenErrCodeToErrCode(err.code)); + }); + }, function (err) { + fail(TizenErrCodeToErrCode(err.code)); + } + ); + } + + dir.deleteFile( + filePath, + function() { + writeFile(dir); + }, function (err) { + writeFile(dir); + }); + + }, function (err) { + fail(TizenErrCodeToErrCode(err.code)); + }, + 'rw'); + } else if (xhr.status === 404) { + fail(FileTransferError.INVALID_URL_ERR, + String.fromCharCode.apply(null, new Uint8Array(xhr.response))); + } else { + fail(FileTransferError.CONNECTION_ERR, + String.fromCharCode.apply(null, new Uint8Array(xhr.response))); + } + }); + + xhr.open('GET', url, true); + xhr.responseType = 'arraybuffer'; + // Fill XHR headers + for (var header in headers) { + if (headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + xhr.send(); + }, + abort: function(successCallback, errorCallback, args) { + var id = args[0]; + if (uploads[id]) { + uploads[id].abort(); + delete uploads[id]; + } else if (downloads[id]) { + downloads[id].abort(); + delete downloads[id]; + } else { + console.warn('Unknown file transfer ID: ' + id); + } + }, +}; + +require("cordova/exec/proxy").add("FileTransfer", exports); + +console.log('Loaded cordova.file-transfer API'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransfer.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransfer.js new file mode 100755 index 000000000..ff0e6c914 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransfer.js @@ -0,0 +1,237 @@ +cordova.define("cordova-plugin-file-transfer.FileTransfer", function(require, exports, module) { /* + * + * 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. + * +*/ + +var argscheck = require('cordova/argscheck'), + exec = require('cordova/exec'), + FileTransferError = require('./FileTransferError'), + ProgressEvent = require('cordova-plugin-file.ProgressEvent'); + +function newProgressEvent(result) { + var pe = new ProgressEvent(); + pe.lengthComputable = result.lengthComputable; + pe.loaded = result.loaded; + pe.total = result.total; + return pe; +} + +function getUrlCredentials(urlString) { + var credentialsPattern = /^https?\:\/\/(?:(?:(([^:@\/]*)(?::([^@\/]*))?)?@)?([^:\/?#]*)(?::(\d*))?).*$/, + credentials = credentialsPattern.exec(urlString); + + return credentials && credentials[1]; +} + +function getBasicAuthHeader(urlString) { + var header = null; + + + // This is changed due to MS Windows doesn't support credentials in http uris + // so we detect them by regexp and strip off from result url + // Proof: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/a327cf3c-f033-4a54-8b7f-03c56ba3203f/windows-foundation-uri-security-problem + + if (window.btoa) { + var credentials = getUrlCredentials(urlString); + if (credentials) { + var authHeader = "Authorization"; + var authHeaderValue = "Basic " + window.btoa(credentials); + + header = { + name : authHeader, + value : authHeaderValue + }; + } + } + + return header; +} + +function convertHeadersToArray(headers) { + var result = []; + for (var header in headers) { + if (headers.hasOwnProperty(header)) { + var headerValue = headers[header]; + result.push({ + name: header, + value: headerValue.toString() + }); + } + } + return result; +} + +var idCounter = 0; + +/** + * FileTransfer uploads a file to a remote server. + * @constructor + */ +var FileTransfer = function() { + this._id = ++idCounter; + this.onprogress = null; // optional callback +}; + +/** +* Given an absolute file path, uploads a file on the device to a remote server +* using a multipart HTTP request. +* @param filePath {String} Full path of the file on the device +* @param server {String} URL of the server to receive the file +* @param successCallback (Function} Callback to be invoked when upload has completed +* @param errorCallback {Function} Callback to be invoked upon error +* @param options {FileUploadOptions} Optional parameters such as file name and mimetype +* @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false +*/ +FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, trustAllHosts) { + argscheck.checkArgs('ssFFO*', 'FileTransfer.upload', arguments); + // check for options + var fileKey = null; + var fileName = null; + var mimeType = null; + var params = null; + var chunkedMode = true; + var headers = null; + var httpMethod = null; + var basicAuthHeader = getBasicAuthHeader(server); + if (basicAuthHeader) { + server = server.replace(getUrlCredentials(server) + '@', ''); + + options = options || {}; + options.headers = options.headers || {}; + options.headers[basicAuthHeader.name] = basicAuthHeader.value; + } + + if (options) { + fileKey = options.fileKey; + fileName = options.fileName; + mimeType = options.mimeType; + headers = options.headers; + httpMethod = options.httpMethod || "POST"; + if (httpMethod.toUpperCase() == "PUT"){ + httpMethod = "PUT"; + } else { + httpMethod = "POST"; + } + if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") { + chunkedMode = options.chunkedMode; + } + if (options.params) { + params = options.params; + } + else { + params = {}; + } + } + + if (cordova.platformId === "windowsphone") { + headers = headers && convertHeadersToArray(headers); + params = params && convertHeadersToArray(params); + } + + var fail = errorCallback && function(e) { + var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception); + errorCallback(error); + }; + + var self = this; + var win = function(result) { + if (typeof result.lengthComputable != "undefined") { + if (self.onprogress) { + self.onprogress(newProgressEvent(result)); + } + } else { + successCallback && successCallback(result); + } + }; + exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]); +}; + +/** + * Downloads a file form a given URL and saves it to the specified directory. + * @param source {String} URL of the server to receive the file + * @param target {String} Full path of the file on the device + * @param successCallback (Function} Callback to be invoked when upload has completed + * @param errorCallback {Function} Callback to be invoked upon error + * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false + * @param options {FileDownloadOptions} Optional parameters such as headers + */ +FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts, options) { + argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments); + var self = this; + + var basicAuthHeader = getBasicAuthHeader(source); + if (basicAuthHeader) { + source = source.replace(getUrlCredentials(source) + '@', ''); + + options = options || {}; + options.headers = options.headers || {}; + options.headers[basicAuthHeader.name] = basicAuthHeader.value; + } + + var headers = null; + if (options) { + headers = options.headers || null; + } + + if (cordova.platformId === "windowsphone" && headers) { + headers = convertHeadersToArray(headers); + } + + var win = function(result) { + if (typeof result.lengthComputable != "undefined") { + if (self.onprogress) { + return self.onprogress(newProgressEvent(result)); + } + } else if (successCallback) { + var entry = null; + if (result.isDirectory) { + entry = new (require('cordova-plugin-file.DirectoryEntry'))(); + } + else if (result.isFile) { + entry = new (require('cordova-plugin-file.FileEntry'))(); + } + entry.isDirectory = result.isDirectory; + entry.isFile = result.isFile; + entry.name = result.name; + entry.fullPath = result.fullPath; + entry.filesystem = new FileSystem(result.filesystemName || (result.filesystem == window.PERSISTENT ? 'persistent' : 'temporary')); + entry.nativeURL = result.nativeURL; + successCallback(entry); + } + }; + + var fail = errorCallback && function(e) { + var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception); + errorCallback(error); + }; + + exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id, headers]); +}; + +/** + * Aborts the ongoing file transfer on this object. The original error + * callback for the file transfer will be called if necessary. + */ +FileTransfer.prototype.abort = function() { + exec(null, null, 'FileTransfer', 'abort', [this._id]); +}; + +module.exports = FileTransfer; + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransferError.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransferError.js new file mode 100755 index 000000000..8339c2bf5 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file-transfer/www/FileTransferError.js @@ -0,0 +1,43 @@ +cordova.define("cordova-plugin-file-transfer.FileTransferError", function(require, exports, module) { /* + * + * 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. + * +*/ + +/** + * FileTransferError + * @constructor + */ +var FileTransferError = function(code, source, target, status, body, exception) { + this.code = code || null; + this.source = source || null; + this.target = target || null; + this.http_status = status || null; + this.body = body || null; + this.exception = exception || null; +}; + +FileTransferError.FILE_NOT_FOUND_ERR = 1; +FileTransferError.INVALID_URL_ERR = 2; +FileTransferError.CONNECTION_ERR = 3; +FileTransferError.ABORT_ERR = 4; +FileTransferError.NOT_MODIFIED_ERR = 5; + +module.exports = FileTransferError; + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryEntry.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryEntry.js new file mode 100755 index 000000000..4349e335b --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryEntry.js @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exports, module) { +// TODO: remove -> end + + var convertTizenFileError = require('cordova-plugin-file.tizen.Errors'); + var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + + function sanitizePath(path) { + var prepend = '/' === path[0]; + var input = path.split('/'); + var output = []; + + for (var i = 0; i < input.length; ++i) { + var part = input[i]; + switch (part) { + case '': + case '.': + // ignore + break; + + case '..': + // remove previous part + output.pop(); + break; + + default: + output.push(part); + break; + } + } + + return (prepend ? '/' : '') + output.join('/'); + } + + var getFunction = function(successCallback, errorCallback, args, isDirectory) { + var uri = rootUtils.internalUrlToNativePath(args[0]), + path = rootUtils.stripTrailingSlash(args[1]), + options = args[2] || {}, + create_flag = !!options.create, + exclusive_flag = !!options.exclusive, + absolute_path = ''; + + if (!uri) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + if ('/' === path[0]) { + // path seems absolute, checking if path is a child of this object URI + if (0 === path.indexOf(uri)) { + // path is child - OK + absolute_path = path; + } else { + // path is not a child - calling error callback + console.error('Error - path is not a child of current directory entry') + errorCallback && errorCallback(FileError.INVALID_STATE_ERR); + return; + } + } else { + // path seems to be relative path, combining absolute path + absolute_path = uri + '/' + path; + } + + var root = rootUtils.findFilesystem(absolute_path).nativeURL; + var clean_path = sanitizePath(absolute_path); + + if (0 !== clean_path.indexOf(root)) { + // we went above the root directory, force the absolute path to be + // at least in that directory + clean_path = root + '/' + sanitizePath(absolute_path.substring(root.length + 1)); + } + + var parent_path = clean_path.substring(0, clean_path.lastIndexOf('/')); + var child_name = clean_path.substring(clean_path.lastIndexOf('/') + 1); + + if (!rootUtils.isValidFileName(child_name)) { + console.error('Disallowed character detected in file name: ' + child_name); + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + var resolveSuccess = function(dir) { + // clean_path points to existing destination + if (create_flag && exclusive_flag) { + console.error('Error while resolving dir - already exist dir'); + errorCallback && errorCallback(FileError.PATH_EXISTS_ERR); + } else if (!create_flag && dir.isDirectory !== isDirectory) { + console.error('Error while resolving dir - already exist file'); + errorCallback && errorCallback(FileError.TYPE_MISMATCH_ERR); + } else { + successCallback && successCallback(rootUtils.createEntry(dir)); + } + }; + + var resolveError = function(e) { + if (create_flag) { + // should create directory + try { + // resolve parent + tizen.filesystem.resolve(parent_path, + function(dir) { + // create object + var new_obj; + if (isDirectory) { + new_obj = dir.createDirectory(child_name); + } else { + new_obj = dir.createFile(child_name); + } + + successCallback && successCallback(rootUtils.createEntry(new_obj)); + }, + function () { + console.error('Error - immediate parent does not exist'); + errorCallback && errorCallback(FileError.INVALID_STATE_ERR); + }, + 'rw' + ); + } catch (err) { + console.error('Error - Could not resolve'); + errorCallback && errorCallback(convertTizenFileError(err)); + } + } else { + console.error('Error - create flag is false - new directory would not be created'); + errorCallback && errorCallback(FileError.NOT_FOUND_ERR); + } + }; + + // try to resolve + try { + tizen.filesystem.resolve(clean_path, resolveSuccess, resolveError, 'rw'); + } catch (err) { + console.error('Error - Could not resolve'); + errorCallback && errorCallback(convertTizenFileError(err)); + } + }; + +module.exports = { + getDirectory: function(successCallback, errorCallback, args) { + getFunction(successCallback, errorCallback, args, true); + }, + removeRecursively: function(successCallback, errorCallback, args) { + var uri = rootUtils.internalUrlToNativePath(args[0]); + + if (!uri) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + if (rootUtils.isRootUri(uri)) { + console.error('It is not allowed to remove root directory.'); + errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR); + return; + } + + // resolve parent + var tmp_path = uri[uri.length-1] === '/' ? uri.substring(0, uri.lastIndexOf('/')) : uri; + var parent_path = tmp_path.substring(0, tmp_path.lastIndexOf('/')+1); + try { + tizen.filesystem.resolve( + parent_path, + function(dir) { + try { + if (dir.isDirectory) { + dir.deleteDirectory( + uri, + true, + function() { + successCallback && successCallback(); + }, function(e) { + console.error('Error - recursively deletion failed'); + errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR); + }); + } else { + console.error('Error - entry is not a directory'); + errorCallback && errorCallback(FileError.INVALID_STATE_ERR); + } + } catch (err) { + console.error('Error - Could not deleteDirectory'); + errorCallback && errorCallback(convertTizenFileError(err)); + } + }, function(e) { + console.error('Error: ' + e.message); + errorCallback && errorCallback(convertTizenFileError(e)); + }, 'rw' + ); + } catch (err) { + console.error('Error - Could not resolve'); + errorCallback && errorCallback(convertTizenFileError(err)); + } + }, + getFile: function(successCallback, errorCallback, args) { + getFunction(successCallback, errorCallback, args, false); + } +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryReader.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryReader.js new file mode 100755 index 000000000..4d864ff9b --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/DirectoryReader.js @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.DirectoryReader', function(require, exports, module) { +// TODO: remove -> end + +var convertTizenFileError = require('cordova-plugin-file.tizen.Errors'); +var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + +module.exports = { + readEntries: function(successCallback, errorCallback, args) { + var uri = rootUtils.internalUrlToNativePath(args[0]); + + if (!uri) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + var fail = function(e) { + errorCallback && errorCallback(convertTizenFileError(e)); + } + try { + tizen.filesystem.resolve(uri, + function (f) { + f.listFiles(function(v) { + var retVal = []; + for (var i = 0; i < v.length; ++i) { + var obj = rootUtils.createEntry(v[i], rootUtils.findFilesystem(v[i].toURI()).filesystemName); + obj.isDirectory = v[i].isDirectory; + obj.isFile = v[i].isFile; + retVal.push(obj); + }; + successCallback(retVal); + }, fail); + }, fail, 'r'); + } catch (e) { + fail(e); + } + } +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Entry.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Entry.js new file mode 100755 index 000000000..a677fea78 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Entry.js @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.Entry', function(require, exports, module) { +// TODO: remove -> end + +var convertTizenFileError = require('cordova-plugin-file.tizen.Errors'); +var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + +var resolveParent = function(srcURL, errorCallback, rest){ + try { + tizen.filesystem.resolve( + srcURL, + function (srcFile) { + var parentDir = srcFile.parent; + if (!parentDir) { + console.error('Error - could not resolve file ' + srcURL); + errorCallback && errorCallback(FileError.ENCODING_ERR); + } else { + rest(srcFile, parentDir); + } + }, function (err) { + console.error('Error - resolve file ' + srcURL + ' failed'); + errorCallback && errorCallback(convertTizenFileError(err)); + }, + 'r'); + } catch (exception) { + console.error('Error - resolve ' + srcURL + ' file thrown exception'); + errorCallback && errorCallback(convertTizenFileError(exception)); + } +}; + +var changeFile = function(method, successCallback, errorCallback, args) { + var srcURL = rootUtils.internalUrlToNativePath(args[0]); + var name = args[2]; + var destDir = rootUtils.internalUrlToNativePath(args[1]); + var destURL = destDir + '/' + name; + + function fail(e, msg) { + console.error(msg); + if (errorCallback) { + errorCallback(e); + } + } + + if (!srcURL || !destDir) { + fail(FileError.ENCODING_ERR, 'Error - Failed to decode internal URL.'); + return; + } + + if (!rootUtils.isValidFileName(name)) { + fail(FileError.ENCODING_ERR, 'Error - Disallowed character detected in the file name: ' + name); + return; + } + + if (-1 !== (destURL + '/').indexOf(srcURL + '/')) { + fail(FileError.INVALID_MODIFICATION_ERR, 'Error - Cannot copy/move onto itself.'); + return; + } + + function performAction(srcFile, parentDir) { + try { + parentDir[method](srcFile.fullPath, + destURL, + true, + function () { + try { + tizen.filesystem.resolve( + destURL, + function (destFile) { + var destEntry = rootUtils.createEntry(destFile); + destEntry.isDirectory = destFile.isDirectory; + successCallback && successCallback(destEntry); + }, function (err) { + fail(convertTizenFileError(err), 'Error - resolve result entry failed'); + } + ); + } catch (exception) { + fail(convertTizenFileError(exception), 'Error - resolve result entry thrown exception'); + } + }, function (err) { + fail(convertTizenFileError(err), 'Error - ' + method + ' operation failed'); + } + ); + } catch (exception) { + fail(convertTizenFileError(exception), 'Error - ' + method + ' operation thrown exception'); + } + } + + try { + tizen.filesystem.resolve(destDir, function(d) { + resolveParent (srcURL, errorCallback, + function(srcFile, parentDir) { + try { + // check if destination entry exists + tizen.filesystem.resolve(destURL, function(d) { + // destination exists, we may proceed only if it's the same type + // as source + if (d.isFile === srcFile.isFile && d.isDirectory === srcFile.isDirectory) { + performAction(srcFile, parentDir); + } else { + fail(FileError.INVALID_MODIFICATION_ERR, 'Error - source and destination have mismatched types'); + } + }, function() { + // error means that we're safe to proceed + performAction(srcFile, parentDir); + }, 'r'); + } catch (exception) { + fail(convertTizenFileError(exception), 'Error - resolve destination entry threw exception'); + } + } + ); + }, function() { + fail(FileError.NOT_FOUND_ERR, 'Error - destination directory does not exist'); + }, 'r'); + } catch (e) { + fail(convertTizenFileError(e), 'Error - resolve destination directory threw exception'); + } +}; + +module.exports = { + getFileMetadata: function(successCallback, errorCallback, args) { + var uri = rootUtils.internalUrlToNativePath(args[0]); + if (!uri) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + try { + tizen.filesystem.resolve(uri, function (file) { + var result = { 'size': file.fileSize, 'lastModifiedDate': file.modified }; + successCallback && successCallback(result); + }, function (err) { + errorCallback && errorCallback(convertTizenFileError(err)); + }, 'r'); + } catch (exception) { + console.error('Error - resolve failed'); + errorCallback && errorCallback(convertTizenFileError(exception)); + } + }, + setMetadata: function(successCallback, errorCallback, args) { + console.error('setMetadata - Not supported'); + errorCallback && errorCallback(FileError.ENCODING_ERR); + }, + moveTo: function(successCallback, errorCallback, args) { + changeFile('moveTo', successCallback, errorCallback, args); + }, + copyTo: function(successCallback, errorCallback, args) { + changeFile('copyTo', successCallback, errorCallback, args); + }, + remove: function(successCallback, errorCallback, args) { + var url = rootUtils.internalUrlToNativePath(args[0]); + + if (!url) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + if (rootUtils.isRootUri(url)) { + console.error('It is not allowed to remove root directory.'); + errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR); + return; + } + + resolveParent(url, errorCallback, + function(srcFile, parentDir){ + var method = srcFile.isFile ? 'deleteFile' : 'deleteDirectory'; + var args = [srcFile.fullPath, + false, + function() {successCallback && successCallback();}, + function(err) { + console.error('Error - ' + method + ' failed'); + errorCallback && errorCallback(convertTizenFileError(err)); + }]; + if (srcFile.isFile) { + //remove recursive flag + args.splice(1, 1); + } + try { + parentDir[method].apply(parentDir, args); + } catch (exception) { + console.error('Error - ' + method + ' thrown exception ' + JSON.stringify(exception)); + errorCallback && errorCallback(convertTizenFileError(exception)); + } + } + ); + }, + getParent: function(successCallback, errorCallback, args) { + var url = rootUtils.internalUrlToNativePath(args[0]); + + if (!url) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + if (rootUtils.isRootUri(url)) { + successCallback && successCallback(rootUtils.findFilesystem(url)); + return; + } + + resolveParent(url, errorCallback, + function(srcFile, parentDir){ + successCallback && successCallback(rootUtils.createEntry(srcFile.parent)); + } + ); + } +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Errors.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Errors.js new file mode 100755 index 000000000..c31ff4c33 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/Errors.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.Errors', function(require, exports, module) { +// TODO: remove -> end + +/** + * Function converting a Tizen error to a cordova error + * + * {unsigned short} WebAPIError error + */ +function convertTizenFileError(err) { + switch (err.name) { + case 'InvalidValuesError': + return FileError.ENCODING_ERR; + + case 'NotFoundError': + return FileError.NOT_FOUND_ERR; + + case 'IOError': + return FileError.INVALID_MODIFICATION_ERR; + + default: + return FileError.ENCODING_ERR; + } +} + +module.exports = convertTizenFileError; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/File.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/File.js new file mode 100755 index 000000000..35c2f6bc0 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/File.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name = 'cordova-plugin-file.tizen.File'; + +cordova.define(plugin_name, function(require, exports, module) { +// TODO: remove -> end + +var modules = [ + 'DirectoryEntry', + 'DirectoryReader', + 'Entry', + 'FileReader', + 'fileSystemPaths', + 'fileSystems-roots', + 'FileWriter', + 'requestFileSystem', + 'resolveLocalFileSystemURI' +]; + +// merge methods from submodules into this one +for (var i = 0; i < modules.length; ++i) { + var m = require('cordova-plugin-file.tizen.' + modules[i]); + for (var prop in m) { + if (m.hasOwnProperty(prop)) { + exports[prop] = m[prop]; + } + } +} + +require("cordova/exec/proxy").add("File", exports); + +console.log('Loaded cordova.file API'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileReader.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileReader.js new file mode 100755 index 000000000..b6c321c3b --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileReader.js @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.FileReader', function(require, exports, module) { +// TODO: remove -> end + +var convertTizenFileError = require('cordova-plugin-file.tizen.Errors'); +var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + +function read(operation, url, start, end, successCallback, errorCallback, encoding) { + url = rootUtils.internalUrlToNativePath(url); + + if (!url) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + var fail = function(e) { + errorCallback && errorCallback(convertTizenFileError(e)); + } + var win = function(size) { + successCallback && successCallback(size); + } + try { + tizen.filesystem.resolve(url, function(file) { + if (0 === end - start) { + // nothing to read, report success + win(); + } else { + try { + file.openStream('r', function(stream) { + try { + stream.position = start; + var r = stream[operation](end - start); + stream.close(); + win(r); + } catch (e) { + fail(e); + } + }, fail, encoding); + } catch (e) { + fail(e); + } + } + }, fail, 'r'); + } catch (e) { + fail(e); + } +} + +module.exports = { + readAsText: function(successCallback, errorCallback, args) { + read('read', args[0], args[2], args[3], function(r) { + successCallback && successCallback(r || ''); + }, errorCallback, args[1]); + }, + readAsDataURL: function(successCallback, errorCallback, args) { + read('readBase64', args[0], args[1], args[2], function(r) { + r = 'data:;base64,' + (r || ''); // MIME is missing because it's not passed to exec() + successCallback && successCallback(r); + }, errorCallback); + }, + readAsBinaryString: function(successCallback, errorCallback, args) { + read('readBytes', args[0], args[1], args[2], function(r) { + r = r || []; + var str = ''; + // this may be not so efficient, but + // String.fromCharCode.apply(null, r); + // may throw if r.length is large enough + for (var i = 0; i < r.length; ++i) { + str += String.fromCharCode(r[i]); + } + successCallback && successCallback(str); + }, errorCallback); + }, + readAsArrayBuffer: function(successCallback, errorCallback, args) { + read('readBytes', args[0], args[1], args[2], function(r) { + successCallback && successCallback(r || []); + }, errorCallback); + }, +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileSystem.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileSystem.js new file mode 100755 index 000000000..8eacf9993 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileSystem.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.FileSystem', function(require, exports, module) { +// TODO: remove -> end + +module.exports = { + __format__: function(fullPath) { + return 'cdvfile://localhost/' + this.name + fullPath; + } +}; + +console.log('Loaded cordova.file FileSystem'); + +// TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileWriter.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileWriter.js new file mode 100755 index 000000000..e5921660d --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/FileWriter.js @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.FileWriter', function(require, exports, module) { +// TODO: remove -> end + +var convertTizenFileError = require('cordova-plugin-file.tizen.Errors'); +var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + +// https://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array +function toUTF8Array(str) { + var utf8 = []; + for (var i = 0; i < str.length; ++i) { + var charcode = str.charCodeAt(i); + if (charcode < 0x80) utf8.push(charcode); + else if (charcode < 0x800) { + utf8.push(0xc0 | (charcode >> 6), + 0x80 | (charcode & 0x3f)); + } + else if (charcode < 0xd800 || charcode >= 0xe000) { + utf8.push(0xe0 | (charcode >> 12), + 0x80 | ((charcode>>6) & 0x3f), + 0x80 | (charcode & 0x3f)); + } + // surrogate pair + else { + i++; + // UTF-16 encodes 0x10000-0x10FFFF by + // subtracting 0x10000 and splitting the + // 20 bits of 0x0-0xFFFFF into two halves + charcode = 0x10000 + (((charcode & 0x3ff)<<10) + | (str.charCodeAt(i) & 0x3ff)); + utf8.push(0xf0 | (charcode >>18), + 0x80 | ((charcode>>12) & 0x3f), + 0x80 | ((charcode>>6) & 0x3f), + 0x80 | (charcode & 0x3f)); + } + } + return utf8; +} + +module.exports = { + write: function(successCallback, errorCallback, args) { + var uri = rootUtils.internalUrlToNativePath(args[0]); + var data = args[1]; + var position = args[2]; + var isBinary = args[3]; + + if (!uri) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + if (!isBinary) { + if ('string' === typeof data) { + // convert to UTF-8, as this is the default encoding for read operations + data = toUTF8Array(data); + } else { + // we don't support other types + errorCallback && errorCallback(FileError.TYPE_MISMATCH_ERR); + return; + } + } else { + if (data instanceof ArrayBuffer) { + var a = new Uint8Array(data); + data = []; + for (var i = 0; i < a.length; ++i) { + data.push(a[i]); + } + } else { + // we don't support other types + errorCallback && errorCallback(FileError.TYPE_MISMATCH_ERR); + return; + } + } + + var onSuccess = function (file) { + if (file.isDirectory) { + errorCallback && errorCallback(FileError.INVALID_MODIFICATION_ERR); + return; + } + + var openStreamSuccess = function (stream) { + try { + stream.position = position; + stream.writeBytes(data); + var length = stream.position - position; + stream.close(); + + // The cordova documentation points to: http://dev.w3.org/2009/dap/file-system/file-writer.html + // This spec states that file length after write operation should be the greater of + // (pre-write length) and (pre-write position + data.size), however + // the cordova implementation sets it to the latter. In order to accommodate + // for this, we need to truncate after write... + module.exports.truncate(function() { + successCallback && successCallback(length); + }, errorCallback, [args[0], stream.position]); + } catch (error) { + errorCallback && errorCallback(convertTizenFileError(error)); + } + } + + var openStreamError = function (error) { + errorCallback && errorCallback(convertTizenFileError(error)); + } + + try { + file.openStream('rw', openStreamSuccess, openStreamError); + } catch (error) { + errorCallback && errorCallback(convertTizenFileError(error)); + } + } + + var onError = function (error) { + errorCallback && errorCallback(convertTizenFileError(error)); + } + + try { + tizen.filesystem.resolve(uri, onSuccess, onError, 'rw'); + } catch (error) { + errorCallback && errorCallback(convertTizenFileError(error)); + } + }, + + truncate: function(successCallback, errorCallback, args) { + var uri = rootUtils.internalUrlToNativePath(args[0]); + var length = args[1]; + + if (!uri) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + var uriPrefix = 'file://'; + if (0 === uri.indexOf(uriPrefix)) { + uri = uri.substring(uriPrefix.length); + } + + tizen.cordova.file.truncate(uri, length, successCallback, function(error) { + if (errorCallback) { + errorCallback(convertTizenFileError(error)); + } + }); + } +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystemPaths.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystemPaths.js new file mode 100755 index 000000000..ec1bb69f4 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystemPaths.js @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.fileSystemPaths', function(require, exports, module) { +// TODO: remove -> end + +var pathsPrefix = { + sharedDirectory: 'file:///opt/usr/media/' +}; + +function setExternalStorage(callback) { + var label = ''; + + var onError = function(error) { + console.error('Failed to get external storage: ' + error.message); + callback(pathsPrefix); + } + + var onSuccess = function(storages) { + for (var i = 0; i < storages.length; ++i) { + if (storages[i].type === 'EXTERNAL' && storages[i].state === 'MOUNTED') { + label = storages[i].label; + break; + } + } + + var onSuccessStorage = function(storage) { + pathsPrefix.externalRootDirectory = 'file://' + storage.fullPath + '/'; + callback(pathsPrefix); + } + + try { + if (label) { + tizen.filesystem.resolve(label, onSuccessStorage, onError); + } else { + callback(pathsPrefix); + } + } catch(error) { + console.error('Failed to resolve external storage: ' + error.message); + callback(pathsPrefix); + } + } + + try { + tizen.filesystem.listStorages(onSuccess, onError); + } catch(error) { + console.error('Failed to list storages: ' + error.message); + callback(pathsPrefix); + } +} + +function setApplicationStorageDirectory(callback) { + var onError = function (error) { + console.error('Failed to get directory: ' + error.message); + callback(pathsPrefix); + }; + + try { + tizen.filesystem.resolve('wgt-package', function(appDir) { + pathsPrefix.applicationDirectory = appDir.toURI() + '/'; + + tizen.filesystem.resolve('wgt-private', function(dataDir) { + pathsPrefix.applicationStorageDirectory = dataDir.toURI() + '/'; + pathsPrefix.dataDirectory = dataDir.toURI() + '/'; + + tizen.filesystem.resolve('wgt-private-tmp', function(cacheDir) { + pathsPrefix.cacheDirectory = cacheDir.toURI() + '/'; + + setExternalStorage(callback); + }, onError, 'r'); + }, onError, 'r'); + }, onError, 'r'); + } catch(error) { + console.error('Failed to get current application: ' + error.message); + callback(pathsPrefix); + } +} + +module.exports = { + requestAllPaths: function(successCallback, errorCallback, args) { + // we ignore errorCallback here, as we're always reporting as much + // information as we currently have + setApplicationStorageDirectory(function(r) { + successCallback && successCallback(r); + }); + } +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystems-roots.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystems-roots.js new file mode 100755 index 000000000..af983b721 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/fileSystems-roots.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.fileSystems-roots', function(require, exports, module) { +// TODO: remove -> end + +var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + +var channel = require('cordova/channel'); + +channel.waitForInitialization('onGetRootsReady'); +channel.onCordovaReady.subscribe(function() { + rootUtils.getRoots(function () { + channel.initializationComplete('onGetRootsReady'); + }); +}); + +module.exports = { + requestAllFileSystems: function(successCallback, errorCallback, args) { + rootUtils.getRoots(successCallback); + } +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/requestFileSystem.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/requestFileSystem.js new file mode 100755 index 000000000..ddd3f10b4 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/requestFileSystem.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.requestFileSystem', function(require, exports, module) { +// TODO: remove -> end + +var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + +module.exports = { + requestFileSystem: function(successCallback, errorCallback, args) { + var type = args[0]; + var size = args[1]; + var fsName; + + switch(type) { + case LocalFileSystem.TEMPORARY: + fsName = 'temporary'; + break; + + case LocalFileSystem.PERSISTENT: + fsName = 'persistent'; + break; + + default: + console.error('Unknown FS type: ' + type); + errorCallback && errorCallback(FileError.TYPE_MISMATCH_ERR); + return; + } + + try { + tizen.systeminfo.getPropertyValue('STORAGE', function (r) { + for (var i = 0; i < r.units.length; ++i) { + // both filesystems are located on internal storage + if ('INTERNAL' === r.units[i].type) { + if (size < r.units[i].availableCapacity) { + rootUtils.getRoots(function(roots) { + for (var i = 0; i < roots.length; ++i) { + if (fsName === roots[i].filesystemName) { + successCallback({ 'name': fsName, 'root': roots[i] }); + return; + } + } + + console.error('Filesystem not found: ' + fsName); + errorCallback && errorCallback(FileError.NOT_FOUND_ERR); + }); + } else { + console.error('Quote exceeded, requested: ' + size + ', available: ' + r.units[i].availableCapacity); + errorCallback && errorCallback(FileError.QUOTA_EXCEEDED_ERR); + } + return; + } + } + + console.error('Internal storage not found'); + errorCallback && errorCallback(FileError.NOT_FOUND_ERR); + }, function(e) { + console.error('Failed to get storage info: ' + fsName); + errorCallback && errorCallback(FileError.NOT_FOUND_ERR); + } + ); + } catch (e) { + console.error('Exception: ' + e); + errorCallback && errorCallback(FileError.NOT_FOUND_ERR); + } + } +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js new file mode 100755 index 000000000..8ad212d8e --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.resolveLocalFileSystemURI', function(require, exports, module) { +// TODO: remove -> end + +var convertTizenFileError = require('cordova-plugin-file.tizen.Errors'); +var rootUtils = require('cordova-plugin-file.tizen.rootUtils'); + +var filePrefix = 'file://'; + +module.exports = { + resolveLocalFileSystemURI: function(successCallback, errorCallback, args) { + var path = rootUtils.internalUrlToNativePath(args[0]); + + if (!path) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + return; + } + + function onResolve(file) { + var filesystem = rootUtils.findFilesystem(file.toURI()); + + var entry = rootUtils.createEntry(file, filesystem.filesystemName); + entry.isDirectory = file.isDirectory; + + successCallback(entry); + } + + function onError(error) { + errorCallback && errorCallback(convertTizenFileError(error)); + } + + tizen.filesystem.resolve(path, onResolve, onError, 'r'); + }, + _getLocalFilesystemPath: function(successCallback, errorCallback, args) { + var path = rootUtils.internalUrlToNativePath(args[0]); + + if (!path) { + errorCallback && errorCallback(FileError.ENCODING_ERR); + } else { + if (0 === path.indexOf(filePrefix)) { + path = path.substring(filePrefix.length); + } + successCallback && successCallback(path); + } + }, +}; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/rootUtils.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/rootUtils.js new file mode 100755 index 000000000..294ee613a --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/tizen/rootUtils.js @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +// TODO: remove when added to public cordova repository -> begin +cordova.define('cordova-plugin-file.tizen.rootUtils', function(require, exports, module) { +// TODO: remove -> end + +var rootUtils = (function() { + var filePrefix = 'file:///'; + + function stripTrailingSlash(str) { + if (filePrefix !== str && '/' === str.substr(-1)) { + return str.substr(0, str.length - 1); + } + return str; + } + + function getName(uri) { + return getFullPath(uri).replace(/^.*(\\|\/|\:)/, ''); + } + + function getFullPath(uri) { + var tmp = findFilesystem(uri); + tmp = getNativeUrl(uri).substring(tmp.nativeURL.length); + if (!tmp) { + tmp = '/'; + } + if ('/' !== tmp[0]) { + tmp = '/' + tmp; + } + return tmp; + } + + function getNativeUrl(uri) { + return stripTrailingSlash(uri); + } + + function createEntry(file, fsName) { + var uri = file.toURI(); + return { + name: getName(uri), + fullPath: getFullPath(uri), + nativeURL: encodeURI(getNativeUrl(uri)), + filesystemName: fsName + }; + } + + var roots_to_resolve = [ + { + filesystemName: 'temporary', + name: '', + fullPath: '/', + nativeURL: 'wgt-private-tmp' + }, + { + filesystemName: 'persistent', + name: '', + fullPath: '/', + nativeURL: 'wgt-private' + } + ]; + + var roots = [ + { + filesystemName: 'root', + name: '', + fullPath: '/', + nativeURL: 'file:///' + } + ]; + + var name_to_root; + + function getRoots(successCallback) { + if (roots_to_resolve.length > 0) { + tizen.filesystem.resolve(roots_to_resolve[0].nativeURL, function(dir) { + roots_to_resolve[0].nativeURL = getNativeUrl(dir.toURI()); + roots.push(roots_to_resolve[0]); + roots_to_resolve.splice(0, 1); // remove first item + + // we've resolved one root, check if there are any other + getRoots(successCallback); + }, function(e) { + console.error(e); + // in case of an error, return the roots we have so far + successCallback(roots); + }); + } else { + if (!name_to_root) { + name_to_root = {}; + for (var i = 0; i < roots.length; ++i) { + name_to_root[roots[i].filesystemName] = roots[i]; + } + } + successCallback(roots.slice()); + } + } + + function strncmp(str1, str2, n) { + str1 = str1.substring(0, n); + str2 = str2.substring(0, n); + return ((str1 === str2) ? 0 : ((str1 > str2) ? 1 : -1 )); + } + + function findFilesystem(uri) { + var nativeUrl = getNativeUrl(uri); + for (var i = roots.length - 1; i > 0; --i) { + if (0 === strncmp(nativeUrl, roots[i].nativeURL, roots[i].nativeURL.length)) { + return roots[i]; + } + } + + return roots[0]; // root filesystem + } + + function isRootUri(uri) { + var fs = findFilesystem(uri); + return (fs.nativeURL === getNativeUrl(uri)); + } + + // http://www.w3.org/TR/2011/WD-file-system-api-20110419/#naming-restrictions + var disallowedCharacters = [ '/', '\\', '<', '>', ':', '?', '*', '"', '|' ]; + + function isValidFileName(name) { + for (var i = 0; i < disallowedCharacters.length; ++i) { + if (-1 !== name.indexOf(disallowedCharacters[i])) { + return false; + } + } + + return true; + } + + var localhost = '//localhost/' + var cdvPrefix = 'cdvfile:///'; + + function internalUrlToNativePath(url) { + var input = url; + + // skip parameters + url = url.split('?')[0]; + + // remove localhost + url = url.replace(localhost, '///'); + + if (0 === url.indexOf(cdvPrefix)) { + // cdvfile protocol + url = url.substring(cdvPrefix.length); + + var idx = url.indexOf('/'); + + if (-1 !== idx) { + var fsName = url.substring(0, idx); + var fullPath = url.substring(idx); + url = name_to_root[fsName] ? name_to_root[fsName].nativeURL + fullPath : undefined; + } else { + // malformed URL + url = undefined; + } + } else if (0 === url.indexOf(filePrefix)) { + // check if the filesystem for this URL exists + var found = false; + for (var i = 0; i < roots.length && !found; ++i) { + if (0 === url.indexOf(roots[i].nativeURL)) { + found = true; + } + } + + if (!found) { + url = undefined; + } + } else { + // backwards compatibility, device absolute path + // only TEMPORARY and PERSISTENT paths are allowed + url = filePrefix + url.substring(1); // skip '/' + if (0 !== url.indexOf(name_to_root.temporary.nativeURL) && + 0 !== url.indexOf(name_to_root.persistent.nativeURL)) { + url = undefined; + } + } + + if (url) { + url = decodeURI(getNativeUrl(url)); + } else { + console.error('Failed to decode internal URL: ' + input); + } + + return url; + } + + return { + getRoots: getRoots, + findFilesystem: findFilesystem, + getName: getName, + getFullPath: getFullPath, + getNativeUrl: getNativeUrl, + stripTrailingSlash: stripTrailingSlash, + createEntry: createEntry, + isRootUri: isRootUri, + isValidFileName: isValidFileName, + internalUrlToNativePath: internalUrlToNativePath + }; +})(); + +module.exports = rootUtils; + +//TODO: remove when added to public cordova repository -> begin +}); +//TODO: remove -> end diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryEntry.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryEntry.js new file mode 100755 index 000000000..464d33932 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryEntry.js @@ -0,0 +1,119 @@ +cordova.define("cordova-plugin-file.DirectoryEntry", function(require, exports, module) { /* + * + * 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. + * +*/ + +var argscheck = require('cordova/argscheck'), + utils = require('cordova/utils'), + exec = require('cordova/exec'), + Entry = require('./Entry'), + FileError = require('./FileError'), + DirectoryReader = require('./DirectoryReader'); + +/** + * An interface representing a directory on the file system. + * + * {boolean} isFile always false (readonly) + * {boolean} isDirectory always true (readonly) + * {DOMString} name of the directory, excluding the path leading to it (readonly) + * {DOMString} fullPath the absolute full path to the directory (readonly) + * {FileSystem} filesystem on which the directory resides (readonly) + */ +var DirectoryEntry = function(name, fullPath, fileSystem, nativeURL) { + + // add trailing slash if it is missing + if ((fullPath) && !/\/$/.test(fullPath)) { + fullPath += "/"; + } + // add trailing slash if it is missing + if (nativeURL && !/\/$/.test(nativeURL)) { + nativeURL += "/"; + } + DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath, fileSystem, nativeURL); +}; + +utils.extend(DirectoryEntry, Entry); + +/** + * Creates a new DirectoryReader to read entries from this directory + */ +DirectoryEntry.prototype.createReader = function() { + return new DirectoryReader(this.toInternalURL()); +}; + +/** + * Creates or looks up a directory + * + * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory + * @param {Flags} options to create or exclusively create the directory + * @param {Function} successCallback is called with the new entry + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) { + argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments); + var fs = this.filesystem; + var win = successCallback && function(result) { + var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL); + successCallback(entry); + }; + var fail = errorCallback && function(code) { + errorCallback(new FileError(code)); + }; + exec(win, fail, "File", "getDirectory", [this.toInternalURL(), path, options]); +}; + +/** + * Deletes a directory and all of it's contents + * + * @param {Function} successCallback is called with no parameters + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) { + argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments); + var fail = errorCallback && function(code) { + errorCallback(new FileError(code)); + }; + exec(successCallback, fail, "File", "removeRecursively", [this.toInternalURL()]); +}; + +/** + * Creates or looks up a file + * + * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file + * @param {Flags} options to create or exclusively create the file + * @param {Function} successCallback is called with the new entry + * @param {Function} errorCallback is called with a FileError + */ +DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) { + argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments); + var fs = this.filesystem; + var win = successCallback && function(result) { + var FileEntry = require('./FileEntry'); + var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL); + successCallback(entry); + }; + var fail = errorCallback && function(code) { + errorCallback(new FileError(code)); + }; + exec(win, fail, "File", "getFile", [this.toInternalURL(), path, options]); +}; + +module.exports = DirectoryEntry; + +}); diff --git a/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryReader.js b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryReader.js new file mode 100755 index 000000000..921b48660 --- /dev/null +++ b/common/tct-globalization-cordova-tests/cordova/plugins/cordova-plugin-file/www/DirectoryReader.js @@ -0,0 +1,75 @@ +cordova.define("cordova-plugin-file.DirectoryReader", function(require, exports, module) { /* + * + * 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. + * +*/ + +var exec = require('cordova/exec'), + FileError = require('./FileError') ; + +/** + * An interface that lists the files and directories in a directory. + */ +function DirectoryReader(localURL) { + this.localURL = localURL || null; + this.hasReadEntries = false; +} + +/** + * Returns a list of entries from a directory. + * + * @param {Function} successCallback is called with a list of entries + * @param {Function} errorCallback is called with a FileError + */ +DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) { + // If we've already read and passed on this directory's entries, return an empty list. + if (this.hasReadEntries) { + successCallback([]); + return; + } + var reader = this; + var win = typeof successCallback !== 'function' ? null : function(result) { + var retVal = []; + for (var i=0; i or + *