diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets index 3f125b529ad291e25b4466b41d1864fa371d006f..f34b432c2a3ec17cc8c7f206a6fbdf93d7216208 100644 --- a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets @@ -24,13 +24,6 @@ export default function imeAbilityTest(abilityContext) { id:'', extra:{} } - /** - * sleep function. - */ - function sleep(date, time){ - while(Date.now() - date <= time); - } - /** * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. @@ -75,12 +68,14 @@ export default function imeAbilityTest(abilityContext) { } inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{ - console.info('====>SUB_InputMethod_IMEAbility_0004 switchInputMethod to IME :' + data); + console.info('====>SUB_InputMethod_IMEAbility_0001 switchInputMethod to IME :' + data); expect(data == true).assertTrue(); }); - sleep(Date.now(), 3000); - console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------'); - done(); + let t = setTimeout(() => { + console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------' + t); + clearTimeout(t); + done(); + }, 500); }) /** @@ -105,9 +100,11 @@ export default function imeAbilityTest(abilityContext) { console.info('====>SUB_InputMethod_IMEAbility_0002 switchInputMethod to IME :' + data); expect(data == true).assertTrue(); }); - sleep(Date.now(), 2500); - console.info('====>-----------SUB_InputMethod_IMEAbility_0002 end-------------'); - done(); + let t = setTimeout(() => { + console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------' + t); + clearTimeout(t); + done(); + }, 500); }) }) } diff --git a/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts index c085dc5e02f8e192b2d2653863c6052e4c5dfe2b..4b120d62322af80c731a9b4631320ff67fbff8e4 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts +++ b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -59,7 +59,7 @@ export default class OpenHarmonyTestRunner implements TestRunner { } hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); - abilityDelegator.executeShellCommand("echo \"123456\" > /data/app/el2/100/base/com.acts.requesttest.test/haps/entry_test/cache/test.txt", + abilityDelegator.executeShellCommand("echo \"123456\" > /data/app/el2/100/base/com.acts.request.test/haps/entry_test/cache/test.txt", (err: any, d: any) => { console.info('executeShellCommand : err : ' + JSON.stringify(err)); console.info('executeShellCommand : data : ' + d.stdResult); 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 b50ebc73f4774a85def6bc1871d05b5f591dd356..37aaa5f6a0b89df9dd5392a249602e6ad5544978 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 @@ -14,7 +14,7 @@ */ import request from "@ohos.request"; -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import fileio from '@ohos.fileio'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; export default function requestDownloadJSUnit() { @@ -49,8 +49,7 @@ export default function requestDownloadJSUnit() { console.info('====>afterAll: Test suite-level cleanup condition is executed'); }); - let downloadTask; - + /** * @tc.number SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 * @tc.desc Starts a download session. @@ -63,7 +62,7 @@ export default function requestDownloadJSUnit() { 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 downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -75,18 +74,18 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, data)=>{ - downloadTask = data; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); try{ - expect(true).assertEqual(downloadTask != undefined); - await downloadTask.delete() + expect(downloadTask != undefined).assertEqual(true); }catch(e){ console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e); } + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------"); done(); - }); + }); }); /** @@ -101,7 +100,7 @@ export default function requestDownloadJSUnit() { 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`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -114,21 +113,22 @@ export default function requestDownloadJSUnit() { background: false } try{ - request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(async (data) => { - downloadTask = data; + request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(async (downloadTask) => { console.info("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); - expect(true).assertEqual(downloadTask != undefined); - await downloadTask.delete() + expect(downloadTask != undefined).assertEqual(true); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); }).catch(err => { console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err); + fileio.unlinkSync(downloadFilePath); done(); }) }catch(err){ console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err); + fileio.unlinkSync(downloadFilePath); done(); } - }); /** @@ -143,7 +143,7 @@ export default function requestDownloadJSUnit() { 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 downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -155,26 +155,30 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask); + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); - downloadTask.delete((err, data) => { + downloadTask.delete(async (err, data) => { try{ if (err) { console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task.'); + await downloadTask.delete(); expect().assertFail(); } console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success.'); expect(typeof data == "boolean").assertTrue(); }catch(err){ + await downloadTask.delete(); console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete throw error' + err); } + fileio.unlinkSync(downloadFilePath); done(); }); } catch (error) { console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error' + error); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); } }) @@ -192,7 +196,7 @@ export default function requestDownloadJSUnit() { 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 downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -203,27 +207,31 @@ export default function requestDownloadJSUnit() { filePath: downloadFilePath, title: 'XTS download test!', background: false - } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask); try { expect(downloadTask != undefined).assertEqual(true); - downloadTask.delete().then(data => { + downloadTask.delete().then(async data => { console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Download task delete success.'); expect(data).assertEqual(true); console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 end-----------------------"); + fileio.unlinkSync(downloadFilePath); done(); - }).catch((err) => { + }).catch(async (err) => { console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task.'); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); expect().assertFail(); done(); }) } catch (error) { console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 delete catch error'); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - } - }) + } + }) }); /** @@ -238,7 +246,7 @@ export default function requestDownloadJSUnit() { 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`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -250,30 +258,32 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.suspend((err, data) => { + downloadTask.suspend(async (err, data) => { try{ if (err) { - console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task.'); - expect().assertFail(); + console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task.'); + expect().assertFail(); } console.info('====>SUB_REQUEST_DOWNLOAD_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)); } + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); }); }catch(err){ console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error' + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); } }) - }); /** @@ -288,7 +298,7 @@ export default function requestDownloadJSUnit() { 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`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -300,24 +310,26 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.suspend().then(data => { - console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 Download task suspend success.'); + try{ + let data = await downloadTask.suspend(); expect(data == true).assertTrue(); - done(); - }).catch((err) => { + }catch(err){ console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 throw_err:' + JSON.stringify(err)); - done(); - }) + } + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); + done(); }catch(err){ console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 suspend catch error' + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - } - }) + } + }) }); /** @@ -332,7 +344,7 @@ export default function requestDownloadJSUnit() { 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`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -344,12 +356,11 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.restore((err, data) => { + downloadTask.restore(async (err, data) => { try{ if (err) { console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task.'); @@ -360,12 +371,16 @@ export default function requestDownloadJSUnit() { }catch(err){ console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 throw_err:' + JSON.stringify(err)); } + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); }); }catch(err){ console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error' + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - } + } }); }); @@ -381,7 +396,7 @@ export default function requestDownloadJSUnit() { 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`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -392,24 +407,29 @@ export default function requestDownloadJSUnit() { filePath: downloadFilePath, title: 'XTS download test!', background: false - } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.restore().then(data => { + downloadTask.restore().then(async data => { console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore.'); expect(data == true).assertTrue(); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - }).catch((err) => { + }).catch(async (err) => { console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task.'); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); }); }catch(err){ console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 restore catch error' +JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - } + } }); }); @@ -421,11 +441,11 @@ export default function requestDownloadJSUnit() { * @tc.level : Level 2 */ it('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001', 0, async function (done) { - console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 is starting---------------------"); + 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`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -437,12 +457,11 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.getTaskInfo((err, data) => { + downloadTask.getTaskInfo(async (err, data) => { try{ if (err) { console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.'); @@ -452,14 +471,18 @@ export default function requestDownloadJSUnit() { expect(typeof data == "object").assertTrue(); }catch(err){ console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 throw_error' +JSON.stringify(err)); - } - done(); + } + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); + done(); }); }catch(err){ console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error' + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); } - }); + }); }); /** @@ -474,7 +497,7 @@ export default function requestDownloadJSUnit() { 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`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -486,24 +509,29 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask); + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.getTaskInfo().then(data => { + downloadTask.getTaskInfo().then(async data => { console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.'); expect(typeof data == "object").assertTrue(); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - }).catch((err) => { - console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.'); + }).catch(async (err) => { + console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.'); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); }); }catch(err){ console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 getTaskInfo catch error' + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); } - }); + }); }); /** @@ -514,11 +542,11 @@ export default function requestDownloadJSUnit() { * @tc.level : Level 2 */ it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001', 0, async function (done) { - console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 is starting---------------------"); + console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 is starting---------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001.txt` console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001.txt`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -530,18 +558,21 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { - downloadTask = data; + let flag = false; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_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 && flag == false){ + flag = true; + downloadTask.off('progress'); downloadTask.getTaskMimeType(async (err, data)=>{ try{ if(err) { console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 err:'+ JSON.stringify(err)); + fileio.unlinkSync(downloadFilePath); expect().assertFail(); done(); } @@ -550,26 +581,33 @@ export default function requestDownloadJSUnit() { expect(typeof data == "string").assertTrue(); } else { console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err)); - expect().assertFail(); + expect().assertFail(); } }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 throw_error: " + JSON.stringify(err)); } - setTimeout(()=>{ + let t = setTimeout(async ()=>{ + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); + clearTimeout(t); done(); - },1000) + },1000) }); } }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - } - }) + } + }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - } - }) + } + }) }); /** @@ -580,11 +618,11 @@ export default function requestDownloadJSUnit() { * @tc.level : Level 2 */ it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002', 0, async function (done) { - console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 is starting----------------------"); + console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 is starting----------------------"); let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002.txt` console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002.txt`) let downloadFileConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { headers: 'http' }, @@ -596,31 +634,39 @@ export default function requestDownloadJSUnit() { title: 'XTS download test!', background: false } - request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, data) => { - downloadTask = data; + let flag = false; + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => { console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('progress', async (data1, data2) => { try{ - if(data1 > 0){ + if(data1 > 0 && flag == false){ + flag = true; + downloadTask.off('progress'); let data = await downloadTask.getTaskMimeType() console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 data:' + JSON.stringify(data)); - expect(typeof data == "string").assertTrue(); + expect(typeof data == "string").assertTrue(); } - setTimeout(()=>{ + let t = setTimeout(async ()=>{ + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); + clearTimeout(t); done(); - },1000) + },1000) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 throw_error: " + JSON.stringify(err)); + await downloadTask.delete(); + fileio.unlinkSync(downloadFilePath); done(); - } - }) + } + }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 error: " + JSON.stringify(err)); + await downloadTask.delete(); done(); - } - }) + } + }) }); }); } \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets index 0ae3541cf3dbc800cc0e92b941d4b8c20361ebe3..8b7b3dba84ab88e449a50d1c6e98f3fca53a2942 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets @@ -89,8 +89,7 @@ export default function requestUploadJSUnit() { it('SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) { console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------"); try { - request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data)=>{ - uploadTask = data; + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask)=>{ console.info("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask); try{ expect(true).assertEqual(uploadTask != undefined); @@ -101,8 +100,9 @@ export default function requestUploadJSUnit() { } catch (err) { console.error("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err); }; - setTimeout(()=>{ + let t = setTimeout(()=>{ console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------"); + clearTimeout(t); done(); }, 10000); }); @@ -117,8 +117,7 @@ export default function requestUploadJSUnit() { it('SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) { console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------"); try{ - request.uploadFile(globalThis.abilityContext, uploadConfig).then(data => { - uploadTask = data; + request.uploadFile(globalThis.abilityContext, uploadConfig).then(uploadTask => { console.info("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask); try{ expect(true).assertEqual(uploadTask != undefined); @@ -132,8 +131,9 @@ export default function requestUploadJSUnit() { }catch(err){ console.error("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err); } - setTimeout(()=>{ + let t = setTimeout(()=>{ console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------"); + clearTimeout(t); done(); }, 10000); }); @@ -147,9 +147,8 @@ export default function requestUploadJSUnit() { */ it('SUB_REQUEST_UPLOAD_API_DELETE_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------"); - request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => { try{ - uploadTask = data; console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask); expect(uploadTask != undefined).assertEqual(true); uploadTask.delete((err, data) => { @@ -184,8 +183,7 @@ export default function requestUploadJSUnit() { */ it('SUB_REQUEST_UPLOAD_API_DELETE_0002', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------"); - request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { - uploadTask = data; + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => { console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask); try{ expect(uploadTask != undefined).assertEqual(true); 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 eb1a01e8a1a44d06da30e9eeb2ba24c7c18489b4..7b1eaa2939cb0aebb3758400c94d9c363c41b0e4 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 @@ -15,7 +15,7 @@ import request from "@ohos.request"; import featureAbility from '@ohos.ability.featureAbility' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import fileio from '@ohos.fileio'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; export default function requestDownloadJSUnit() { @@ -23,42 +23,41 @@ export default function requestDownloadJSUnit() { console.info('====>################################request download Test start'); /** - * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. - */ + * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. + */ beforeAll(async function () { console.info('====>beforeAll: Prerequisites are executed.'); }); /** - * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. - */ + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ beforeEach(async function () { - console.info('====>beforeEach: Prerequisites is executed.'); + console.info('====>beforeEach: Prerequisites is executed.'); await setDownLoadConfig() }); /** - * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. - */ + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ afterEach(function () { console.info('====>afterEach: Test case-level clearance conditions is executed.'); }); /** - * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. - */ + * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. + */ afterAll(function () { console.info('====>afterAll: Test suite-level cleanup condition is executed'); }); - let downloadTask; let downloadConfig async function setDownLoadConfig(){ let downloadFilePath = await featureAbility.getContext().getFilesDir() downloadConfig = { - url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', header: { - headers: 'http' + headers: 'http' }, enableMetered: false, enableRoaming: false, @@ -79,31 +78,42 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001.txt' - request.download(downloadConfig, (err, data)=>{ + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ try{ - downloadTask = data; console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 downloadTask: " + JSON.stringify(downloadTask) ); - expect(true).assertEqual(downloadTask != undefined); - downloadTask.on('progress', (data1, data2) => { - try{ - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data1 =" + data1); - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data2 =" + data2); - expect(true).assertEqual(data1 != undefined); - expect(true).assertEqual(data2 != undefined); - if (data1 == data2){ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('progress', async (data1, data2) => { + if (data1 == data2 && flag == false){ + flag = true; + try{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data1 =" + data1); + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data2 =" + data2); + expect(true).assertEqual(data1 != undefined); + expect(true).assertEqual(data2 != undefined); + + downloadTask.off('progress'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); + done(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 throw_error: " + err); + downloadTask.off('progress'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }catch(err){ - console.error("====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 throw_error: " + err); - done(); - } + } }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } - }); + } + }); }); /** @@ -115,26 +125,36 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002.txt' - request.download(downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: " + downloadTask); try{ - expect(true).assertEqual(downloadTask != undefined); + expect(downloadTask != undefined).assertEqual(true); downloadTask.on('complete', async () => { - try{ - console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 task completed.') - expect(true).assertTrue(); - }catch(err){ - console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 throw_error: " + err); + if (flag == false){ + flag = true; + downloadTask.off('complete'); + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 task completed.') + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 throw_error: " + err); + } + downloadTask.off('complete'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); + done(); } - await downloadTask.remove() - done(); }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 error: " + err); + downloadTask.off('complete'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }); }); @@ -147,32 +167,39 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003.txt' - request.download(downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: " + downloadTask); try{ - expect(true).assertEqual(downloadTask != undefined); + expect(downloadTask != undefined).assertEqual(true); downloadTask.on('pause', async () => { try{ - console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task completed.') + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task pause.') expect(true).assertTrue(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 throw_error: " + err); } - await downloadTask.remove() + downloadTask.off('pause'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }); - downloadTask.on('progress', (data1, data2) => { - if(data1 > 0){ - downloadTask.pause() + downloadTask.on('progress', async (data1, data2) => { + if (flag == false){ + flag = true + await downloadTask.pause(); + downloadTask.off('progress'); } - }); + }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }); + }); }); /** @@ -184,31 +211,38 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004.txt' - request.download(downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('remove', () => { try{ - console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 remove completed') + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 remove remove') expect(true).assertTrue(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 throw_error: " + err); } + downloadTask.off('remove'); + fileio.unlinkSync(filePath); done(); }); - downloadTask.on('progress', (data1, data2) => { - if(data1 > 0){ - downloadTask.remove() + downloadTask.on('progress', async (data1, data2) => { + if(flag == false){ + flag = true; + await downloadTask.remove(); + downloadTask.off('progress'); } - }); + }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }); + }); }); /** @@ -220,28 +254,33 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005.txt' - downloadConfig.url += 'xxxxxxxxxx' - request.download(downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005.txt'; + downloadConfig.url = 'https://www.baidu.com/xxxxxx.jpg'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 downloadTask: " + downloadTask); try{ - expect(downloadTask != undefined).assertEqual(true); - downloadTask.on('fail', async()=>{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('fail', async (err) =>{ try{ - console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 fail completed') + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 fail fail' + err) expect(true).assertTrue(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 throw_error: " + err); } - await downloadTask.remove() + downloadTask.off('fail'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }); + }); }); /** @@ -253,28 +292,32 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006.txt' - request.download(downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('complete', async () => { try{ - request.download(downloadConfig, (err, data)=>{ - }) + await request.download(downloadConfig); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 second throw_error: " + err); - expect(err.code).assertEqual(13400002) - await downloadTask.remove() + expect(err.code).assertEqual(13400002); + downloadTask.off('complete'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }); + }); }); /** @@ -286,29 +329,38 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001.txt' - request.download(downloadConfig, (err, data)=>{ + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ try{ - downloadTask = data; console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); - downloadTask.on('progress', (data1, data2) => {}); - downloadTask.off('progress', async (data1, data2) => { - try{ - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on data1 =" + data1); - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on data2 =" + data2); - expect(data1).assertEqual(0); - expect(data2).assertEqual(0); - }catch(err){ - console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off_err: " + err); - } - await downloadTask.remove() - done(); + downloadTask.on('progress', async (data1, data2) => { + downloadTask.off('progress', async (data1, data2) => { + if (flag == false){ + flag = true; + try{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off data1 =" + data1); + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off data2 =" + data2); + expect(data1).assertEqual(0); + expect(data2).assertEqual(0); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off_err: " + err); + } + downloadTask.off('progress'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); + done(); + } + }); }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }); }); @@ -321,27 +373,32 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002.txt' - request.download(downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002.txt'; + let filePath = downloadConfig.filePath; + request.download(downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('complete', () => {}); downloadTask.off('complete',async () => { try{ console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 task complete.') expect(true).assertTrue(); + done(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 off_err: " + err); } - await downloadTask.remove() + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }); + }); }); /** @@ -353,24 +410,29 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('pause', () => {}); downloadTask.off('pause', async () => { try{ - console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 task complete.') + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 task pause.') expect(true).assertTrue(); + done(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: " + err); } - await downloadTask.remove() + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } }); @@ -385,24 +447,28 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.off('remove', async (data) => { + downloadTask.on('remove', () => {}); + downloadTask.off('remove', async () => { try{ - console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 remove data:' +JSON.stringify(data)) + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 remove success') expect(true).assertTrue(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: " + err); } - await downloadTask.remove() + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } }); @@ -417,28 +483,31 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('fail', (data) => {}); - downloadTask.off('fail', async (data) => { + downloadTask.off('fail', async (err) => { try{ - console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_data:' + JSON.stringify(data)) - expect(data).assertEqual(0) + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_data:' + JSON.stringify(err)) + expect(err).assertEqual(0) console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 end-----------------------"); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_error: " + err); - } - await downloadTask.remove() + } + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }); }); @@ -451,9 +520,9 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_REMOVE_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMOVE_0001.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMOVE_0001.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); @@ -473,12 +542,15 @@ export default function requestDownloadJSUnit() { }catch(err){ console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 remove_throw_err:' + JSON.stringify(err)) } + fileio.unlinkSync(filePath); done(); }); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }) }); @@ -491,31 +563,24 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_REMOVE_0002', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMOVE_0002.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMOVE_0002.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.remove().then(data => { - if (data) { - console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 removed data:' + JSON.stringify(data)); - expect(data == true).assertTrue(); - } else { - console.error('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.'); - expect().assertFail(); - } - done(); - }).catch((err) => { - console.error('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.'); - done(); - }) + let data = await downloadTask.remove(); + console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 removed data:' + JSON.stringify(data)); + expect(data == true).assertTrue(); + fileio.unlinkSync(filePath); + done(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } }) - }); /** @@ -527,9 +592,9 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_PAUSE_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_PAUSE_0001.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_PAUSE_0001.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); try{ @@ -539,12 +604,15 @@ export default function requestDownloadJSUnit() { expect(true).assertTrue(); }catch(err){ console.info('====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 pause_throw_err:' + JSON.stringify(err)) - } - await downloadTask.remove() - done(); + } + await downloadTask.remove(); + fileio.unlinkSync(filePath); + done(); }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } }) @@ -559,23 +627,20 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_PAUSE_0002', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_PAUSE_0002.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_PAUSE_0002.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.pause().then(async () => { - console.info('====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 Download task pause success.'); - expect(true).assertTrue(); - await downloadTask.remove() - done(); - }).catch((err) => { - console.error("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 throw_error: " + JSON.stringify(err)); - done(); - }) + await downloadTask.pause(); + await downloadTask.remove() + fileio.unlinkSync(filePath); + done(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 error: " + JSON.stringify(err)); + await downloadTask.remove() + fileio.unlinkSync(filePath); done(); } }) @@ -590,9 +655,9 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_REMUSE_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMUSE_0001.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMUSE_0001.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); try{ @@ -602,12 +667,15 @@ export default function requestDownloadJSUnit() { expect(true).assertTrue(); }catch(err){ console.info('====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 pause_throw_err:' + JSON.stringify(err)) - } - await downloadTask.remove() - done(); + } + await downloadTask.remove(); + fileio.unlinkSync(downloadConfig.filePath); + done(); }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(downloadConfig.filePath); done(); } }) @@ -622,25 +690,22 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_REMUSE_0002', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMUSE_0002.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMUSE_0002.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); - downloadTask.resume().then(async () => { - console.info('====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 Download task resume success.'); - expect(true).assertTrue(); - await downloadTask.remove() - done() - }).catch((err) => { - console.error("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 throw_error: " + JSON.stringify(err)); - done(); - }) + await downloadTask.resume(); + await downloadTask.remove(); + fileio.unlinkSync(filePath); + done(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }) }); @@ -653,10 +718,10 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_QUERY_0001', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0001 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERY_0001.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; - console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 downloadTask: " + downloadTask); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERY_0001.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.query(async (err, downloadInfo)=>{ @@ -681,11 +746,14 @@ export default function requestDownloadJSUnit() { }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 throw_error: " + JSON.stringify(err)); } - await downloadTask.remove() + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } }) @@ -700,9 +768,9 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_QUERY_0002', 0, async function (done) { console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0002 is starting-----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERY_0002.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERY_0002.txt'; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); @@ -725,21 +793,28 @@ export default function requestDownloadJSUnit() { console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.downloadTotalBytes); expect(true).assertTrue(); } - await downloadTask.remove() + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }).catch((err)=>{ + }).catch(async (err)=>{ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 catch_error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); expect().assertFail(); done(); }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(downloadConfig.filePath); done(); - } + } }) }); @@ -752,48 +827,57 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001', 0, async function (done) { console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 is starting---------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('progress', async (data1, data2)=>{ - try{ - if (data1 > 0 && downloadTask != null){ - downloadTask.queryMimeType((err, data) => { - try{ - if(err) { - console.error('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 return_err:'+ JSON.stringify(err)); - expect().assertFail(); + try { + if (data1 > 0 && flag == false) { + flag = true; + downloadTask.off('progress'); + downloadTask.queryMimeType(async (err, data) => { + try { + if (err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 return_err:' + JSON.stringify(err)); + fileio.unlinkSync(downloadConfig.filePath); + expect().assertFail(); + done(); + } + if (data) { + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data:' + JSON.stringify(data)); + expect(typeof data == "string").assertTrue(); + await downloadTask.remove(); + fileio.unlinkSync(filePath); + done(); + } else { + 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)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - if (data) { - 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 data_error: " + JSON.stringify(err)); - expect().assertFail(); - } - }catch(err){ - console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 throw_error: " + JSON.stringify(err)); - } - }); - } - if (data1 == data2){ - downloadTask = null - await downloadTask.remove() + }); + } + } catch (err) { + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); 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)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }) }); @@ -806,33 +890,39 @@ export default function requestDownloadJSUnit() { */ it('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002', 0, async function (done) { console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 is starting----------------------"); - downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002.txt' - request.download( downloadConfig, (err, data)=>{ - downloadTask = data; + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002.txt'; + let flag = false; + let filePath = downloadConfig.filePath; + request.download( downloadConfig, async (err, downloadTask)=>{ console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 downloadTask: " + downloadTask); try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('progress', async (data1, data2) => { try{ - 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(); - } - if(data1 == data2){ - downloadTask = null - await downloadTask.remove() + if(data1 > 0 && flag == false){ + flag = true; + downloadTask.off('progress'); + let data = await downloadTask.queryMimeType() + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.'); + expect(typeof data == "string").assertTrue(); + downloadTask.off('progress'); + await downloadTask.remove(); + fileio.unlinkSync(filePath); + done(); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: " + err); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); } - }catch(err){ - console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: " + JSON.stringify(err)); - done(); - } - }) + }) }catch(err){ console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 error: " + JSON.stringify(err)); + await downloadTask.remove(); + fileio.unlinkSync(filePath); done(); - } + } }) }); }) diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets index 2fe8649b76c2ca848dc016e23ae04d66576774c9..f4005da13829e3d1da2c3b71b642175fd872f8a8 100644 --- a/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets @@ -49,13 +49,6 @@ export default function requestUploadJSUnit() { console.info('====>afterAll: Test suite-level cleanup condition is executed'); }); - /** - * sleep function. - */ - function sleep(date, time){ - while(Date.now() - date <= time); - } - let uploadTask; let RequestData = { name: 'name', @@ -265,11 +258,9 @@ export default function requestUploadJSUnit() { console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 is starting-----------------------"); try { console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig)); - request.upload(uploadConfig, (err, data) => { - uploadTask = data; + request.upload(uploadConfig, (err, uploadTask) => { console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask)); expect(uploadTask != undefined).assertEqual(true); - uploadTask.on('progress', function (data1, data2) { console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data1 =" + data1); console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data2 =" + data2); @@ -282,15 +273,15 @@ export default function requestUploadJSUnit() { uploadTask.remove((err, data) => { console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 remove =" + data); + expect(data).assertEqual(true); + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------"); + done(); }); }); } catch (err) { console.error("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err); expect().assertFail(); } - sleep(Date.now(), 20000); - console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------"); - done(); }); /** @@ -305,33 +296,30 @@ export default function requestUploadJSUnit() { console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------"); try { console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); - request.upload(uploadConfig).then((data) => { - uploadTask = data; + request.upload(uploadConfig).then((uploadTask) => { console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask); - expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {})); - + expect(true).assertEqual((uploadTask != undefined)); uploadTask.on('headerReceive', (header) => { console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header); - expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); + expect(true).assertEqual((header != {} || header != undefined)); }); uploadTask.off('headerReceive', (header) => { console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header); - expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); + expect(true).assertEqual((header != {} || header != undefined)); }); uploadTask.remove().then((result)=>{ console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 remove result = " + result); expect(result).assertEqual(true); + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------"); + done(); }); }); } catch (e) { console.error("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e)); expect(true).assertFail(true); } - sleep(Date.now(), 20000); - console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------"); - done(); }); }) } diff --git a/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets b/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets index c4f6a9db7fe482ee6f1cb16f235491a595ba7489..ade0a75e5703893ab4d1dfe58f4349815cef95e7 100755 --- a/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets +++ b/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets @@ -170,7 +170,7 @@ export default function screenLockJSUnit() { screenLock.isSecureMode((err, data) => { try{ console.info("====>SUB_MISC_THEME_screenLock_API_0003 secureMode's result is " + data); - expect(data == result).assertTrue(); + expect(data == false).assertTrue(); console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0003-------------------"); done(); }catch(err){ @@ -288,7 +288,7 @@ export default function screenLockJSUnit() { try{ secured = screenLock.isSecure() console.info('====>SUB_MISC_THEME_screenLock_API_0011 data : ' + JSON.stringify(secured)); - if (typeof secured == "boolean") { + if (secured == false) { expect(true).assertTrue(); console.info('====>-------------SUB_MISC_THEME_screenLock_API_0011 end----------------------'); done()