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

!6746 【monthly_20221018】【上传下载】XTS_queryMimeType时序优化

Merge pull request !6746 from 何海涛/cherry-pick-1669730678
...@@ -75,7 +75,7 @@ export default function requestDownloadJSUnit() { ...@@ -75,7 +75,7 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!', title: 'XTS download test!',
background: false background: false
} }
request.downloadFile(globalThis.abilityContext, downloadConfig, async (err, data)=>{ request.download(globalThis.abilityContext, downloadConfig, async (err, data)=>{
downloadTask = data; downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try { try {
...@@ -113,7 +113,7 @@ export default function requestDownloadJSUnit() { ...@@ -113,7 +113,7 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!', title: 'XTS download test!',
background: false background: false
} }
request.downloadFile(globalThis.abilityContext, downloadConfig).then(async (data) => { request.download(globalThis.abilityContext, downloadConfig).then(async (data) => {
downloadTask = data; downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined); expect(true).assertEqual(downloadTask != undefined);
......
...@@ -758,13 +758,13 @@ export default function requestDownloadJSUnit() { ...@@ -758,13 +758,13 @@ export default function requestDownloadJSUnit() {
console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 downloadTask: " + downloadTask); console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 downloadTask: " + downloadTask);
try{ try{
expect(downloadTask != undefined).assertEqual(true); expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('progress', (data1, data2)=>{ downloadTask.on('progress', async (data1, data2)=>{
try{ try{
if (data1 > 0){ if (data1 > 0 && downloadTask != null){
downloadTask.queryMimeType((err, data) => { downloadTask.queryMimeType((err, data) => {
try{ try{
if(err) { if(err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 err:'+ JSON.stringify(err)); console.error('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 return_err:'+ JSON.stringify(err));
expect().assertFail(); expect().assertFail();
done(); done();
} }
...@@ -772,17 +772,18 @@ export default function requestDownloadJSUnit() { ...@@ -772,17 +772,18 @@ export default function requestDownloadJSUnit() {
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data:' + JSON.stringify(data)); console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data:' + JSON.stringify(data));
expect(typeof data == "string").assertTrue(); expect(typeof data == "string").assertTrue();
} else { } else {
console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err)); console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data_error: " + JSON.stringify(err));
expect().assertFail(); expect().assertFail();
} }
}catch(err){ }catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 throw_error: " + JSON.stringify(err)); console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 throw_error: " + JSON.stringify(err));
} }
setTimeout(async ()=>{ });
}
if (data1 == data2){
downloadTask = null
await downloadTask.remove() await downloadTask.remove()
done(); done();
},1000)
});
} }
}catch(err){ }catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err)); console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err));
...@@ -813,14 +814,15 @@ export default function requestDownloadJSUnit() { ...@@ -813,14 +814,15 @@ export default function requestDownloadJSUnit() {
expect(downloadTask != undefined).assertEqual(true); expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('progress', async (data1, data2) => { downloadTask.on('progress', async (data1, data2) => {
try{ try{
if(data1 > 0){ if(data1 > 0 && downloadTask != null){
let data = await downloadTask.queryMimeType() let data = await downloadTask.queryMimeType()
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.'); console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.');
expect(typeof data == "string").assertTrue(); expect(typeof data == "string").assertTrue();
setTimeout(async ()=>{ }
if(data1 == data2){
downloadTask = null
await downloadTask.remove() await downloadTask.remove()
done(); done();
},1000)
} }
}catch(err){ }catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: " + JSON.stringify(err)); console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: " + JSON.stringify(err));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册