diff --git a/multimedia/medialibrary/common.js b/multimedia/medialibrary/common.js index 8b96e2730d0cded799f40f71e8b936815ced8e0f..b4c77ac2e20509a1ee6fbb734c8733baae696b68 100755 --- a/multimedia/medialibrary/common.js +++ b/multimedia/medialibrary/common.js @@ -36,11 +36,18 @@ const FILE_TYPE = mediaLibrary.MediaType.FILE; const FILEKEY = mediaLibrary.FileKey; const { RELATIVE_PATH, ALBUM_NAME, MEDIA_TYPE } = FILEKEY -const sleep = async function sleep(times = 10) { - await new Promise(res => setTimeout(res, times)); -} -const allFetchOp = function (others = {}) { +const sleep = async function sleep(times) { + if (!times) { + times = 10; + } + await new Promise((res) => setTimeout(res, times)); +}; + +const allFetchOp = function (others) { + if (!others) { + others = {}; + } return { selections: '', selectionArgs: [], @@ -48,7 +55,10 @@ const allFetchOp = function (others = {}) { }; } -const fetchOps = function (testNum, path, type, others = {}) { +const fetchOps = function (testNum, path, type, others) { + if (!others) { + others = {}; + } let ops = { selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?', selectionArgs: [path, type.toString()], @@ -84,8 +94,10 @@ const fileIdFetchOps = function (testNum, id) { return ops; }; -const albumFetchOps = function (testNum, path, albumName, type, - others = { order: FILEKEY.DATE_ADDED + " DESC", }) { +const albumFetchOps = function (testNum, path, albumName, type, others) { + if (!others) { + others = { order: FILEKEY.DATE_ADDED + " DESC", }; + } let ops = { selections: RELATIVE_PATH + '= ? AND ' + ALBUM_NAME + '= ? AND ' + MEDIA_TYPE + '= ?', selectionArgs: [path, albumName, type.toString()], @@ -96,8 +108,10 @@ const albumFetchOps = function (testNum, path, albumName, type, } // albums of two resource types -const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, - others = { order: FILEKEY.DATE_ADDED + " DESC", }) { +const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others) { + if (!others) { + others = { order: FILEKEY.DATE_ADDED + " DESC" }; + } try { let ops = { selections: '(' + RELATIVE_PATH + '= ? or ' + @@ -116,7 +130,10 @@ const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, } // albums of three resource types -const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, others = { order: FILEKEY.DATE_ADDED, }) { +const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, others) { + if (!others) { + others = { order: FILEKEY.DATE_ADDED + " DESC" }; + } try { let ops = { selections: '(' + RELATIVE_PATH + '= ? or ' + @@ -181,9 +198,12 @@ const checkAlbumsCount = function (done, testNum, albumList, expectCount) { return albumsCount == expectCount; } -const getPermission = async function (name = 'ohos.acts.multimedia.mediaLibrary') { +const getPermission = async function (name) { + if (!name) { + name = "ohos.acts.multimedia.mediaLibrary"; + } console.info('getPermission start', name) - let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.mediaLibrary', 0, 100); + let appInfo = await bundle.getApplicationInfo(name, 0, 100); let tokenID = appInfo.accessTokenId; let atManager = abilityAccessCtrl.createAtManager(); let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1); diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestCallback.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestCallback.test.ets index be2bb9ae68545766e5fabc5ab5745071528d876d..1f1e7f08935c4fbdc47486964e302db075bb6ef4 100755 --- a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestCallback.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestCallback.test.ets @@ -77,6 +77,7 @@ export default function fileAssetTestCallbackTest(abilityContext) { console.info(`fd1:${fd1},fd:${fd}`) await asset.close(fd); await asset1.close(fd1); + await sleep(50); let newFetchFileResult = await media.getFileAssets(fileIdFetchOps(testNum, asset.id)); let checkAssetCountPass = await checkAssetsCount(done, testNum, newFetchFileResult, 1); if (!checkAssetCountPass) return; diff --git a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets index 19506c1a4a0e52b358e5d7cd97d9830a02aa0bfd..0cfdc1ab9115068bc378f24d49274ce381cb254e 100755 --- a/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets +++ b/multimedia/medialibrary/mediaLibrary_fileAsset/entry/src/main/ets/test/fileAssetTestPromise.test.ets @@ -71,6 +71,7 @@ export default function fileAssetTestPromiseTest(abilityContext) { console.info(`fd1:${fd1},fd:${fd}`) await asset.close(fd); await asset1.close(fd1); + await sleep(50); let newFetchFileResult = await media.getFileAssets(fileIdFetchOps(testNum, asset.id)); checkAssetCountPass = await checkAssetsCount(done, testNum, newFetchFileResult, 1); if (!checkAssetCountPass) return;