diff --git a/multimedia/medialibrary/common.js b/multimedia/medialibrary/common.js index a5625bdf6919ad732f4b51fda2577ca614e48b4c..f72265ae87e1802915678ae0f9e25c7987fa5774 100644 --- a/multimedia/medialibrary/common.js +++ b/multimedia/medialibrary/common.js @@ -235,20 +235,26 @@ const getPermission = async function (name, context) { console.info("getPermission start", name); let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_MEDIA"]; - context.requestPermissionsFromUser(permissions, (data) => { - console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`); - }); - await sleep(200); + let atManager = abilityAccessCtrl.createAtManager(); + try { + atManager.requestPermissionsFromUser(context, permissions, (err, data) => { + console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`); + }); + } catch (err) { + console.log(`get permission catch err -> ${JSON.stringify(err)}`); + } + await sleep(1000); let driver = uitest.Driver.create(); - await sleep(200); - + + await sleep(2000); let button = await driver.findComponent(uitest.ON.text("允许")); await button.click(); + await sleep(2000); let appInfo = await bundle.getApplicationInfo(name, 0, 100); let tokenID = appInfo.accessTokenId; - let atManager = abilityAccessCtrl.createAtManager(); + let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION"); let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA"); diff --git a/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets b/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets index 2bd7cc07ba2419bb1c8abb47efd37c9768f1894d..5d2ae06753debf6f1cc260e746f9f7fb54f0ba49 100644 --- a/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets +++ b/multimedia/medialibrary/mediaLibrary_getExifNoLocation/entry/src/main/ets/test/getExifNoLocation.test.ets @@ -25,21 +25,27 @@ export default function getExifNoLocation(abilityContext) { describe("getExifNoLocation", function () { beforeAll(async function () { console.info("beforeAll case"); - + let atManager = abilityAccessCtrl.createAtManager(); let permissions = ["ohos.permission.READ_MEDIA"]; - abilityContext.requestPermissionsFromUser(permissions, (data) => { - console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`); - }); - await sleep(200); + + try { + atManager.requestPermissionsFromUser(abilityContext, permissions, (err, data) => { + console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`); + }); + } catch (err) { + console.log(`get permission catch err -> ${JSON.stringify(err)}`); + } + await sleep(1000); let driver = uitest.Driver.create(); - await sleep(200); + await sleep(2000); let button = await driver.findComponent(uitest.ON.text("允许")); await button.click(); + await sleep(2000); let appInfo = await bundle.getApplicationInfo("ohos.acts.multimedia.mediaLibrary", 0, 100); let tokenID = appInfo.accessTokenId; - let atManager = abilityAccessCtrl.createAtManager(); + let isGranted = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); if (isGranted != 0) { console.info("getpermission failed"); diff --git a/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets b/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets index 231f3e99e5fe5eb2b4d58dc1e370867b1eec9440..0cdb6d5a8b02f69ab8eddb5c28c9a610a5941b5e 100644 --- a/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets +++ b/multimedia/medialibrary/mediaLibrary_getExiflocation/entry/src/main/ets/test/getExifLocation.test.ets @@ -25,22 +25,28 @@ export default function getExifLocation(abilityContext) { describe("getExifLocation", function () { beforeAll(async function () { console.info("beforeAll case"); + let atManager = abilityAccessCtrl.createAtManager(); let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA"]; - abilityContext.requestPermissionsFromUser(permissions, (data) => { - console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`); - }); - await sleep(200); + try { + atManager.requestPermissionsFromUser(abilityContext, permissions, (err, data) => { + console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`); + }); + } catch (err) { + console.log(`get permission catch err -> ${JSON.stringify(err)}`); + } + await sleep(1000); let driver = uitest.Driver.create(); - await sleep(200); + await sleep(2000); let button = await driver.findComponent(uitest.ON.text("允许")); await button.click(); + await sleep(2000); let appInfo = await bundle.getApplicationInfo("ohos.acts.multimedia.mediaLibrary", 0, 100); let tokenID = appInfo.accessTokenId; - let atManager = abilityAccessCtrl.createAtManager(); + let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION"); let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); if (!(isGranted1 == 0 && isGranted2 == 0)) {