From b30c21b13f3e0561764cee64c2e70b6ec4ef65b5 Mon Sep 17 00:00:00 2001 From: 15829070344 Date: Tue, 29 Nov 2022 22:01:22 +0800 Subject: [PATCH] =?UTF-8?q?fixed=202e5f778=20from=20https://gitee.com/murp?= =?UTF-8?q?hy1984/acts/pulls/6745=20=E3=80=90=E4=B8=8A=E4=BC=A0=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E3=80=91XTS=5FqueryMimeType=E6=97=B6=E5=BA=8F?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 15829070344 Change-Id: I2cb4e59fe542b7b3cc82f3042fd59320958bf994 --- .../main/ets/test/requestDownload.test.ets | 4 +-- .../main/ets/test/requestDownload.test.ets | 34 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets index 29a381471..f9d7fc89b 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets @@ -75,7 +75,7 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadConfig, async (err, data)=>{ + request.download(globalThis.abilityContext, downloadConfig, async (err, data)=>{ downloadTask = data; console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); try { @@ -113,7 +113,7 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadConfig).then(async (data) => { + request.download(globalThis.abilityContext, downloadConfig).then(async (data) => { downloadTask = data; console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); expect(true).assertEqual(downloadTask != undefined); diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets index 8ed3a9558..36d1455f3 100644 --- a/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets @@ -758,13 +758,13 @@ export default function requestDownloadJSUnit() { console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.on('progress', (data1, data2)=>{ + downloadTask.on('progress', async (data1, data2)=>{ try{ - if (data1 > 0){ + if (data1 > 0 && downloadTask != null){ downloadTask.queryMimeType((err, data) => { try{ 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(); done(); } @@ -772,22 +772,23 @@ export default function requestDownloadJSUnit() { console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data:' + JSON.stringify(data)); expect(typeof data == "string").assertTrue(); } 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(); } }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 throw_error: " + JSON.stringify(err)); - } - setTimeout(async ()=>{ - await downloadTask.remove() - done(); - },1000) + } }); } + if (data1 == data2){ + downloadTask = null + await downloadTask.remove() + done(); + } }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err)); done(); - } + } }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err)); @@ -813,14 +814,15 @@ export default function requestDownloadJSUnit() { expect(downloadTask != undefined).assertEqual(true); downloadTask.on('progress', async (data1, data2) => { try{ - if(data1 > 0){ + if(data1 > 0 && downloadTask != null){ let data = await downloadTask.queryMimeType() console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.'); - expect(typeof data == "string").assertTrue(); - setTimeout(async ()=>{ - await downloadTask.remove() - done(); - },1000) + expect(typeof data == "string").assertTrue(); + } + if(data1 == data2){ + downloadTask = null + await downloadTask.remove() + done(); } }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: " + JSON.stringify(err)); -- GitLab