From 76d9c8a2d16f7ed196794f8e1b4a131623e876e7 Mon Sep 17 00:00:00 2001 From: hu0475 Date: Fri, 14 Jul 2023 19:52:10 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=A0=B9=E6=8D=AE=E6=A3=80=E8=A7=86=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hu0475 --- .../main/ets/test/requestConstant.test.ets | 2 +- .../main/ets/test/requestDownload.test.ets | 506 +++++++++++++----- 2 files changed, 370 insertions(+), 138 deletions(-) diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets index 1e7b3fffe..e8e276c73 100644 --- a/request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets +++ b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets @@ -56,7 +56,7 @@ export default function requestUploadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it('subRequestConstant0001', 0, async function (done) { + it('SUB_REQUEST_CONSTANT_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_CONSTANT_0001 is starting-----------------------"); expect(typeof request.EXCEPTION_PERMISSION == 'number').assertTrue(); expect(typeof request.EXCEPTION_PARAMCHECK == 'number').assertTrue(); diff --git a/request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets index 270736a57..00b86d3ea 100644 --- a/request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets +++ b/request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets @@ -60,10 +60,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadFileStageApiCallback0001", 0, async function (done) { - console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`); + it("SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001", 0, async function (done) { + console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -78,15 +78,15 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); } catch (e) { - console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e); + console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 except error: " + e); } await downloadTask.delete(); removeFile(downloadFilePath); - console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------"); + console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 end-----------------------"); done(); }); }); @@ -98,11 +98,11 @@ export default function requestDownloadJSUnit() { * @tc.size : MediumTest * @tc.type : Function * @tc.level : Level 2 - */ - it("subRequestDownloadFileStageApiCallback0002", 0, async function (done) { + */ + it("SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002", 0, async function (done) { console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0002 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -117,15 +117,15 @@ export default function requestDownloadJSUnit() { background: true, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); } catch (e) { - console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e); + console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 except error: " + e); } await downloadTask.delete(); removeFile(downloadFilePath); - console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------"); + console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 end-----------------------"); done(); }); }); @@ -138,10 +138,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadFileStageApiPromise0001", 0, async function (done) { - console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`); + it("SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001", 0, async function (done) { + console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -159,19 +159,19 @@ export default function requestDownloadJSUnit() { request .downloadFile(globalThis.abilityContext, downloadFileConfig) .then(async (downloadTask) => { - console.info("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); await downloadTask.delete(); }) .catch((err) => { - console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err); + console.error("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 error: " + err); }) .finally(() => { removeFile(downloadFilePath); done(); }); } catch (err) { - console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err); + console.error("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 catch error: " + err); done(); } }); @@ -184,10 +184,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiDelete0001", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_DELETE_0001", 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0001.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -202,20 +202,20 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); downloadTask.delete(async (err, data) => { try { if (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task."); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 Failed to delete the download task."); expect().assertFail(); done(); } - console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 Download task delete success."); expect(typeof data == "boolean").assertTrue(); } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete throw error" + err); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 delete throw error" + err); } finally { await downloadTask.delete(); removeFile(downloadFilePath); @@ -223,7 +223,7 @@ export default function requestDownloadJSUnit() { } }); } catch (error) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error" + error); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 delete catch error" + error); await downloadTask.delete(); removeFile(downloadFilePath); done(); @@ -239,10 +239,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiDelete0002", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_DELETE_0002", 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0002.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -257,18 +257,18 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); downloadTask .delete() .then(async (data) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Download task delete success."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 Download task delete success."); expect(data).assertEqual(true); - console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 end-----------------------"); + console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 end-----------------------"); }) .catch(async (err) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 Failed to delete the download task."); expect().assertFail(); }) .finally(async () => { @@ -293,10 +293,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiSuspend0001", 0, async function (done) { - console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`); + it("SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -311,27 +311,27 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); downloadTask.suspend(async (err, data) => { try { if (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task."); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 Failed to suspend the download task."); expect().assertFail(); done(); } - console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Download task suspend success."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 Download task suspend success."); expect(data == true).assertTrue(); } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err)); } await downloadTask.delete(); removeFile(downloadFilePath); done(); }); } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error" + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 suspend catch error" + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); @@ -347,10 +347,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiSuspend0002", 0, async function (done) { - console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`); + it("SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -365,17 +365,17 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); try { let data = await downloadTask.suspend(); expect(data == true).assertTrue(); } catch (err) { - console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 throw_err:" + JSON.stringify(err)); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 throw_err:" + JSON.stringify(err)); } } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 suspend catch error" + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 suspend catch error" + JSON.stringify(err)); } finally { await downloadTask.delete(); removeFile(downloadFilePath); @@ -392,10 +392,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiRestore0001", 0, async function (done) { - console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`); + it("SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -410,27 +410,27 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); downloadTask.restore(async (err, data) => { try { if (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task."); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 Failed to restore the download task."); expect().assertFail(); done(); } - console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Download restore success."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 Download restore success."); expect(data == true).assertTrue(); } catch (err) { - console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 throw_err:" + JSON.stringify(err)); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 throw_err:" + JSON.stringify(err)); } await downloadTask.delete(); removeFile(downloadFilePath); done(); }); } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error" + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 restore catch error" + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); @@ -446,10 +446,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiRestore0002", 0, async function (done) { - console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 is starting-----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`); + it("SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002", 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -464,18 +464,17 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); downloadTask .restore() .then(async (data) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 Download task restore."); expect(data == true).assertTrue(); - await downloadTask.delete(); }) .catch(async (err) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 Failed to restore the download task."); }) .finally(async () => { await downloadTask.delete(); @@ -499,10 +498,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiGetTaskInfo0001", 0, async function (done) { - console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 is starting---------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`); + it("SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001", 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 is starting---------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -517,27 +516,27 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); downloadTask.getTaskInfo(async (err, data) => { try { if (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task."); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task."); expect().assertFail(); done(); } - console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Download getTaskInfo success."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 Download getTaskInfo success."); expect(typeof data == "object").assertTrue(); } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 throw_error" + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 throw_error" + JSON.stringify(err)); } await downloadTask.delete(); removeFile(downloadFilePath); done(); }); } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); @@ -553,10 +552,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiGetTaskInfo0002", 0, async function (done) { - console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 is starting----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`); + it("SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002", 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 is starting----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", header: { @@ -571,17 +570,17 @@ export default function requestDownloadJSUnit() { background: false, }; request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); downloadTask .getTaskInfo() .then(async (data) => { - console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success."); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success."); expect(typeof data == "object").assertTrue(); }) .catch(async (err) => { - console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task."); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task."); }) .finally(async () => { await downloadTask.delete(); @@ -589,7 +588,59 @@ export default function requestDownloadJSUnit() { done(); }); } catch (err) { - console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 + * *@tc.name subRequestDownloadApigetTaskMimeType0001 + * @tc.desc Get mimetype of the download task + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001", 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 is starting---------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001.txt`); + + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.getTaskMimeType(async (err, data) => { + try { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType enter"); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType err: " + err); + expect(data != null).assertEqual(true); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 callback error: " + JSON.stringify(err)); + } finally { + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 error: " + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); @@ -605,7 +656,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApigetTaskMimeType0002", 0, async function (done) { + it("SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`); @@ -646,7 +697,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiTaskInfo0001", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001", 0, async function (done) { console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 is starting---------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`); @@ -667,32 +718,36 @@ export default function requestDownloadJSUnit() { console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); - downloadTask.getTaskInfo(async (err, data) => { - try { - if (err) { - console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Failed to getTaskInfo the download task."); - expect().assertFail(); - done(); + downloadTask.on("complete", async () => { + downloadTask.getTaskInfo(async (err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Failed to getTaskInfo the download task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Download getTaskInfo success."); + expect(typeof data == "object").assertTrue(); + + console.info('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 data:' + JSON.stringify(data)); + expect(data.description).assertEqual('XTS download test!'); + expect(data.downloadedBytes).assertEqual(1042003); + expect(typeof data.downloadId == "number").assertTrue(); + expect(data.failedReason).assertEqual(0); + expect(data.fileName).assertEqual('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt'); + expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`); + expect(data.pausedReason).assertEqual(0); + expect(data.status).assertEqual(0); + expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk'); + expect(data.downloadTitle).assertEqual('XTS download test!'); + expect(data.downloadTotalBytes).assertEqual(1042003); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 throw_error" + JSON.stringify(err)); } - console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Download getTaskInfo success."); - expect(typeof data == "object").assertTrue(); - expect(typeof data.description == "string").assertTrue(); - expect(typeof data.downloadedBytes == "number").assertTrue(); - expect(typeof data.downloadId == "number").assertTrue(); - expect(typeof data.failedReason == "number").assertTrue(); - expect(typeof data.fileName == "string").assertTrue(); - expect(typeof data.filePath == "string").assertTrue(); - expect(typeof data.pausedReason == "number").assertTrue(); - expect(typeof data.status == "number").assertTrue(); - expect(typeof data.targetURI == "string").assertTrue(); - expect(typeof data.downloadTitle == "string").assertTrue(); - expect(typeof data.downloadTotalBytes == "number").assertTrue(); - } catch (err) { - console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 throw_error" + JSON.stringify(err)); - } - await downloadTask.delete(); - removeFile(downloadFilePath); - done(); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); }); } catch (err) { console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err)); @@ -703,6 +758,76 @@ export default function requestDownloadJSUnit() { }); }); + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 + * *@tc.name subRequestDownloadApiTaskInfo0002 + * @tc.desc Get the error download task info, and test the field of TaskInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002", 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 is starting---------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test_not_exists.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('fail', err => { + downloadTask.getTaskInfo(async (err, data) => { + try { + if (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 Failed to getTaskInfo the download task."); + expect().assertFail(); + done(); + } + console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 Download getTaskInfo success."); + expect(typeof data == "object").assertTrue(); + + console.info('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 data:' + JSON.stringify(data)); + expect(data.description).assertEqual('XTS download test!'); + expect(data.downloadedBytes).assertEqual(0); + expect(data.failedReason).assertEqual(8); + expect(typeof data.downloadId == "number").assertTrue(); + expect(data.fileName).assertEqual('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt'); + expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt`); + expect(data.pausedReason).assertEqual(0); + expect(data.status).assertEqual(4); + expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test_not_exists.apk'); + expect(data.downloadTitle).assertEqual('XTS download test!'); + expect(data.downloadTotalBytes).assertEqual(-1); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 throw_error" + JSON.stringify(err)); + } + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + }); + }) + + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + /** * @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0001 * *@tc.name subRequestDownloadApiEvent0001 @@ -710,8 +835,8 @@ export default function requestDownloadJSUnit() { * @tc.size : MediumTest * @tc.type : Function * @tc.level : Level 2 - */ - it("subRequestDownloadApiEvent0001", 0, async function (done) { + */ + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0001", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0001 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0001_bk.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0001_bk.txt`); @@ -765,7 +890,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiEvent0002", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0002", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0002 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0002_bk.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0002_bk.txt`); @@ -818,10 +943,10 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiEvent0003", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0003", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0003 is starting----------------------"); - let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0003_bk.txt`; - console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0003_bk.txt`); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0003.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0003.txt`); let downloadFileConfig = { url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk", header: { @@ -870,7 +995,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiEvent0004", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0004", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0004 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0004.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0004.txt`); @@ -930,7 +1055,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiEvent0005", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0005", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0005.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0005.txt`); @@ -957,7 +1082,7 @@ export default function requestDownloadJSUnit() { try { console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); - downloadTask.on("complete", onFailedCallback) + downloadTask.on("complete", onFailedCallback); downloadTask.off("complete", onFailedCallback); const t = setTimeout(async () => { @@ -993,7 +1118,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiEvent0006", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0006", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0006.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0006.txt`); @@ -1055,7 +1180,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiEvent0007", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0007", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0007.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0007.txt`); @@ -1077,15 +1202,15 @@ export default function requestDownloadJSUnit() { let result2 = true; let onFailedCallback = function() { result1 = false; - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 onFailedCallback"); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 onFailedCallback"); } let onFailedCallback2 = function() { result2 = false; - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 onFailedCallback"); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 onFailedCallback"); } request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { try { - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); downloadTask.on("complete", onFailedCallback) downloadTask.on("complete", onFailedCallback2) @@ -1094,14 +1219,14 @@ export default function requestDownloadJSUnit() { const t = setTimeout(async () => { try { - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 in setTimeout"); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 in setTimeout"); clearTimeout(t); expect(result2).assertFalse(); await downloadTask.delete(); removeFile(downloadFilePath); done(); } catch (err) { - console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 throw_error in setTimeout: " + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 throw_error in setTimeout: " + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); @@ -1109,7 +1234,7 @@ export default function requestDownloadJSUnit() { }, 5000); } catch (err) { - console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 throw_error: " + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 throw_error: " + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); @@ -1125,7 +1250,7 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 2 */ - it("subRequestDownloadApiEvent0008", 0, async function (done) { + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0008", 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0008.txt`; console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0008.txt`); @@ -1147,15 +1272,15 @@ export default function requestDownloadJSUnit() { let result2 = true; let onFailedCallback = function() { result1 = false; - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 onFailedCallback"); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 onFailedCallback"); } let onFailedCallback2 = function() { result2 = false; - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 onFailedCallback"); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 onFailedCallback"); } request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { try { - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 downloadTask: " + downloadTask); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); downloadTask.on("fail", onFailedCallback); downloadTask.on("fail", onFailedCallback2); @@ -1163,21 +1288,128 @@ export default function requestDownloadJSUnit() { const t = setTimeout(async () => { try { - console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 in setTimeout"); + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 in setTimeout"); clearTimeout(t); expect(result2).assertFalse(); await downloadTask.delete(); removeFile(downloadFilePath); done(); } catch (err) { - console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 throw_error in setTimeout: " + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 throw_error in setTimeout: " + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); } }, 5000); } catch (err) { - console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 throw_error: " + JSON.stringify(err)); + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 throw_error: " + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 + * *@tc.name subRequestDownloadApiEvent0009 + * @tc.desc Start download task, and test the event of it. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0009", 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 is starting----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0009.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0009.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 downloadTask: " + downloadTask); + expect(downloadTask != undefined).assertEqual(true); + try { + downloadTask.on("pause", async () => { + try { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 downloadTask in pause"); + expect(true).assertTrue(); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 on api throw_error: " + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + await downloadTask.suspend(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 throw_error: " + JSON.stringify(err)); + await downloadTask.delete(); + removeFile(downloadFilePath); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 + * *@tc.name subRequestDownloadApiEvent0010 + * @tc.desc Start download task, and test the event of it. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0010", 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 is starting----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0010.txt`; + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0010.txt`); + let downloadFileConfig = { + url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk", + header: { + headers: "http", + }, + enableMetered: false, + enableRoaming: false, + description: "XTS download test!", + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: "XTS download test!", + background: false, + }; + + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 downloadTask: " + downloadTask); + expect(downloadTask != undefined).assertEqual(true); + try { + downloadTask.on("remove", async () => { + try { + console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 downloadTask in remove"); + expect(true).assertTrue(); + removeFile(downloadFilePath); + done(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 on api throw_error: " + JSON.stringify(err)); + removeFile(downloadFilePath); + done(); + } + }); + + await downloadTask.delete(); + } catch (err) { + console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 throw_error: " + JSON.stringify(err)); await downloadTask.delete(); removeFile(downloadFilePath); done(); -- GitLab