未验证 提交 ff9d2549 编写于 作者: O openharmony_ci 提交者: Gitee

!9919 修复获取权限异常

Merge pull request !9919 from yangbo/xts_acts
...@@ -26,11 +26,13 @@ export default function getExifNoLocation(abilityContext) { ...@@ -26,11 +26,13 @@ export default function getExifNoLocation(abilityContext) {
try { try {
let permissions = ["ohos.permission.READ_MEDIA"]; let permissions = ["ohos.permission.READ_MEDIA"];
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
let permissionCheck = false;
atManager.requestPermissionsFromUser(abilityContext, permissions, (err, result) => { atManager.requestPermissionsFromUser(abilityContext, permissions, (err, result) => {
if (err) { if (err) {
console.info('getPermission failed: ' + JSON.stringify(err)); console.info('getPermission failed: ' + JSON.stringify(err));
} else { } else {
console.info('getPermission suc: ' + JSON.stringify(result)); console.info('getPermission suc: ' + JSON.stringify(result));
permissionCheck = true;
} }
}); });
...@@ -38,6 +40,9 @@ export default function getExifNoLocation(abilityContext) { ...@@ -38,6 +40,9 @@ export default function getExifNoLocation(abilityContext) {
await sleep(500); await sleep(500);
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
if (permissionCheck) {
break;
}
await sleep(500); await sleep(500);
let button = await driver.findComponent(uitest.ON.text('允许')); let button = await driver.findComponent(uitest.ON.text('允许'));
if (button != undefined) { if (button != undefined) {
......
...@@ -26,11 +26,13 @@ export default function getExifLocation(abilityContext) { ...@@ -26,11 +26,13 @@ export default function getExifLocation(abilityContext) {
try { try {
let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA"]; let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA"];
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
let permissionCheck = false;
atManager.requestPermissionsFromUser(abilityContext, permissions, (err, result) => { atManager.requestPermissionsFromUser(abilityContext, permissions, (err, result) => {
if (err) { if (err) {
console.info('getPermission failed: ' + JSON.stringify(err)); console.info('getPermission failed: ' + JSON.stringify(err));
} else { } else {
console.info('getPermission suc: ' + JSON.stringify(result)); console.info('getPermission suc: ' + JSON.stringify(result));
permissionCheck = true;
} }
}); });
...@@ -38,6 +40,9 @@ export default function getExifLocation(abilityContext) { ...@@ -38,6 +40,9 @@ export default function getExifLocation(abilityContext) {
await sleep(500); await sleep(500);
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
if (permissionCheck) {
break;
}
await sleep(500); await sleep(500);
let button = await driver.findComponent(uitest.ON.text('允许')); let button = await driver.findComponent(uitest.ON.text('允许'));
if (button != undefined) { if (button != undefined) {
......
...@@ -20,6 +20,7 @@ import { ...@@ -20,6 +20,7 @@ import {
photoFetchOption, photoFetchOption,
getFileAsset, getFileAsset,
getPermission, getPermission,
sleep,
} from '../../../../../../common' } from '../../../../../../common'
export default function openTest() { export default function openTest() {
...@@ -30,14 +31,17 @@ export default function openTest() { ...@@ -30,14 +31,17 @@ export default function openTest() {
}) })
async function rwOpenCallback(done, testNum, fetchOp, assetBytes) { async function rwOpenCallback(done, testNum, fetchOp, assetBytes) {
let asset;
let fd;
try { try {
const asset = await getFileAsset(testNum, fetchOp); asset = await getFileAsset(testNum, fetchOp);
asset.open('rw', async (err, fd) => { asset.open('rw', async (err, data) => {
try { try {
if (err) { if (err) {
console.info(`${testNum} err: ${err}`); console.info(`${testNum} err: ${err}`);
expect(false).assertTrue(); expect(false).assertTrue();
} else { } else {
fd = data;
console.info(`${testNum} fd: ${fd}`); console.info(`${testNum} fd: ${fd}`);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf); let res = await fileio.read(fd, buf);
...@@ -49,72 +53,109 @@ export default function openTest() { ...@@ -49,72 +53,109 @@ export default function openTest() {
} catch (error) { } catch (error) {
console.info(`${testNum} error: ${error}`); console.info(`${testNum} error: ${error}`);
} }
await asset.close(fd);
done(); done();
}); });
await sleep(50);
} catch (error) { } catch (error) {
console.info(`${testNum} failed, error: ${error}`); console.info(`${testNum} failed, error: ${error}`);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} finally {
if (asset) {
await asset.close(fd);
}
} }
}; };
async function rOpenCallback(done, testNum, fetchOp, assetBytes) { async function rOpenCallback(done, testNum, fetchOp, assetBytes) {
let asset;
let fd;
try { try {
const asset = await getFileAsset(testNum, fetchOp); asset = await getFileAsset(testNum, fetchOp);
asset.open('r', async (err, fd) => { asset.open('r', async (err, data) => {
try { try {
if (err) { if (err) {
console.info(`${testNum} err: ${err}`); console.info(`${testNum} err: ${err}`);
expect(false).assertTrue(); expect(false).assertTrue();
} else { } else {
fd = data;
console.info(`${testNum} fd: ${fd}`); console.info(`${testNum} fd: ${fd}`);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
let res = await fileio.read(fd, buf); fileio.read(fd, buf).then((result) => {
expect(res.bytesRead).assertEqual(assetBytes); expect(result.bytesRead).assertEqual(assetBytes);
console.info(`${testNum} read suc`); }).catch((rErr) => {
await fileio.write(fd, testNum); console.info(`${testNum} rErr: ${rErr}`);
expect(false).assertTrue();
})
await sleep(50);
fileio.write(fd, testNum).then((result) => {
expect(false).assertTrue(); expect(false).assertTrue();
}).catch((wErr) => {
console.info(`${testNum} wErr: ${wErr}`);
})
await sleep(50);
} }
} catch (error) { } catch (error) {
console.info(`${testNum} error: ${error}`); console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
} }
await asset.close(fd);
done(); done();
}); });
await sleep(50);
} catch (error) { } catch (error) {
console.info(`${testNum} failed, error: ${error}`); console.info(`${testNum} failed, error: ${error}`);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} finally {
if (asset) {
await asset.close(fd);
}
} }
}; };
async function wOpenCallback(done, testNum, fetchOp) { async function wOpenCallback(done, testNum, fetchOp) {
let asset;
let fd;
try { try {
const asset = await getFileAsset(testNum, fetchOp); asset = await getFileAsset(testNum, fetchOp);
asset.open('w', async (err, fd) => { asset.open('w', async (err, data) => {
try { try {
if (err) { if (err) {
console.info(`${testNum} err: ${err}`); console.info(`${testNum} err: ${err}`);
expect(false).assertTrue(); expect(false).assertTrue();
} else { } else {
let write = await fileio.write(fd, testNum); fd = data;
expect(write).assertEqual(testNum.length); console.info(`${testNum} fd: ${fd}`);
fileio.write(fd, testNum).then((result) => {
expect(result).assertEqual(testNum.length);
}).catch((wErr) => {
console.info(`${testNum} wErr: ${wErr}`);
expect(false).assertTrue();
})
await sleep(50);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
await fileio.read(fd, buf); fileio.read(fd, buf).then((result) => {
expect(false).assertTrue(); expect(false).assertTrue();
}).catch((rErr) => {
console.info(`${testNum} rErr: ${rErr}`);
})
await sleep(50);
} }
} catch (error) { } catch (error) {
console.info(`${testNum} error: ${error}`); console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
} }
await asset.close(fd);
done(); done();
}); });
await sleep(50);
} catch (error) { } catch (error) {
console.info(`${testNum} failed, error: ${error}`); console.info(`${testNum} failed, error: ${error}`);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
} finally {
if (asset) {
await asset.close(fd);
}
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册