From ff38126caba99793f666101a087758b6a8f3a0bc Mon Sep 17 00:00:00 2001 From: zhangyushuai Date: Thu, 27 Jul 2023 03:10:45 +0000 Subject: [PATCH] =?UTF-8?q?request=20off=20=E7=94=A8=E4=BE=8B=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyushuai --- .../main/ets/test/requestDownload.test.ets | 10 +- .../main/ets/test/requestDownload001.test.ets | 153 ++++++++++++++++++ .../main/ets/test/requestDownload002.test.ets | 110 +++++++------ 3 files changed, 217 insertions(+), 56 deletions(-) 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 86da89df8..a525809a9 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 @@ -337,7 +337,7 @@ export default function requestDownloadJSUnit() { console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 downloadTask: " + downloadTask); expect(downloadTask != undefined).assertEqual(true); downloadTask.on('progress', async (data1, data2) => { - downloadTask.off('progress', async (data1, data2) => {}); + downloadTask.off('progress'); await downloadTask.remove(); fileio.unlinkSync(filePath); done(); @@ -368,7 +368,7 @@ export default function requestDownloadJSUnit() { try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('complete', () => {}); - downloadTask.off('complete',async () => {}); + downloadTask.off('complete'); await downloadTask.remove(); fileio.unlinkSync(filePath); done(); @@ -397,7 +397,7 @@ export default function requestDownloadJSUnit() { try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('pause', () => {}); - downloadTask.off('pause', async () => {}); + downloadTask.off('pause'); await downloadTask.remove(); fileio.unlinkSync(filePath); done(); @@ -426,7 +426,7 @@ export default function requestDownloadJSUnit() { try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('remove', () => {}); - downloadTask.off('remove', async () => {}); + downloadTask.off('remove'); await downloadTask.remove(); fileio.unlinkSync(filePath); done(); @@ -455,7 +455,7 @@ export default function requestDownloadJSUnit() { try{ expect(downloadTask != undefined).assertEqual(true); downloadTask.on('fail', (data) => {}); - downloadTask.off('fail', async (err) => {}); + downloadTask.off('fail'); await downloadTask.remove(); fileio.unlinkSync(filePath); done(); diff --git a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload001.test.ets b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload001.test.ets index 65558bb96..28636aca8 100755 --- a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload001.test.ets +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload001.test.ets @@ -1038,6 +1038,159 @@ export default function requestDownloadOneJSUnitTest() { } }) + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0070 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Callback_0070", 0, async function (done) { + let urls = 'x'; + for (let i = 0; i < 2030; i++){ + urls += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://' + urls + '/test.apk', + title: 'createTest', + description: "XTS download test!", + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Callback_0070.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Callback_0070 is start ---------------------"); + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + try { + if(err){ + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0070 task creat fail: ` + JSON.stringify(err)); + expect().assertFail(); + } + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0070 Succeeded download task length: ` + task.config.url.length); + await request.agent.remove(task.tid); + done(); + } catch (err) { + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0070 Succeeded in starting a download task.` + JSON.stringify(err)); + done(); + } + }); + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0070 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0070", 0, async function (done) { + let urls = 'x'; + for (let i = 0; i < 2030; i++){ + urls += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://' + urls + '/test.apk', + title: 'createTest', + description: "XTS download test!", + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0070.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------SUB_Misc_REQUEST_Create_Promise_0070 is starting----------------"); + try{ + let task = await request.agent.create(globalThis.abilityContext, config); + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0070 Succeeded download task length: ` + task.config.url.length); + await request.agent.remove(task.tid); + expect(true).assertTrue(); + done(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0070 create err: " + JSON.stringify(err)); + expect().assertFail(); + console.info("-----------------------SUB_Misc_REQUEST_Create_Promise_0070 is end-----------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0080 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Callback_0080", 0, async function (done) { + let urls = 'x'; + for (let i = 0; i < 2031; i++){ + urls += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://' + urls + '/test.apk', + title: 'createTest', + description: "XTS download test!", + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Callback_0080.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Callback_0080 is start ---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config, (err, task) => { + try { + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0080 Succeeded in starting a download task.`); + expect().assertFail(); + } catch (err) { + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0080 Succeeded in starting a download task.` + JSON.stringify(err)); + request.agent.remove(task.tid); + done(); + } + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Callback_0080 create err: " + JSON.stringify(err)); + console.info("-----------------------SUB_Misc_REQUEST_Create_Callback_0080 is end-----------------------"); + expect(err.code).assertEqual(401); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0080 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0080", 0, async function (done) { + let urls = 'x'; + for (let i = 0; i < 2031; i++){ + urls += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://' + urls + '/test.apk', + title: 'createTest', + description: "XTS download test!", + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0080.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------SUB_Misc_REQUEST_Create_Promise_0080 is starting----------------"); + try{ + await request.agent.create(globalThis.abilityContext, config); + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0080 Succeeded in starting a download task.`); + expect().assertFail(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0080 create err: " + JSON.stringify(err)); + expect(err.code).assertEqual(401); + console.info("-----------------------SUB_Misc_REQUEST_Create_Promise_0080 is end-----------------------"); + done(); + } + }) + /** * @tc.number SUB_Misc_REQUEST_Create_Promise_0110 * @tc.desc remove a download session. diff --git a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets index 4128159be..41ff4cf59 100755 --- a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets @@ -237,6 +237,7 @@ export default function requestDownloadTwoUnitTest() { console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 on_progressCallback flag: " + flag); } let on_progressCallback1 = (pro) => { + task.off('progress'); flag1 = false; console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 on_progressCallback1 flag1: " + flag1); expect(true).assertTrue(); @@ -537,6 +538,7 @@ export default function requestDownloadTwoUnitTest() { console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 on_progressCallback flag: " + flag); } let on_progressCallback1 = (pro) => { + task.off('completed'); flag1 = false; console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 on_progressCallback1 flag1: " + flag1); expect(true).assertTrue(); @@ -837,6 +839,7 @@ export default function requestDownloadTwoUnitTest() { console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 on_progressCallback flag: " + flag); } let on_progressCallback1 = (pro) => { + task.off('failed'); flag1 = false; console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 on_progressCallback1 flag1: " + flag1); expect(true).assertTrue(); @@ -1881,32 +1884,33 @@ export default function requestDownloadTwoUnitTest() { let task:request.agent.Task function onCompletedCallback(progress){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 onCompletedCallback start') + task.off('completed'); + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 onCompletedCallback start'); request.agent.touch(task.tid, config.token,(err, taskInfo)=>{ try{ if(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 err:' + JSON.stringify(err)); + expect().assertFail(); done(); } - expect(taskInfo.url).assertEqual(config.url) - expect(taskInfo.data).assertEqual("") - expect(taskInfo.title).assertEqual(config.title) + expect(taskInfo.url).assertEqual(config.url); + expect(taskInfo.data).assertEqual(""); + expect(taskInfo.title).assertEqual(config.title); done(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 touch throw_err:' + JSON.stringify(err)) + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 touch throw_err:' + JSON.stringify(err)); done(); } }) } try { - task = await request.agent.create(globalThis.abilityContext, config) - task.on('completed', onCompletedCallback) - await task.start() + task = await request.agent.create(globalThis.abilityContext, config); + task.on('completed', onCompletedCallback); + await task.start(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 create throw_err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 create throw_err:' + JSON.stringify(err)); + expect().assertFail(); done(); } @@ -1934,25 +1938,26 @@ export default function requestDownloadTwoUnitTest() { let task:request.agent.Task async function onCompletedCallback(progress){ - console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 onCompletedCallback start') + task.off('completed'); + console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 onCompletedCallback start'); try{ - let taskInfo = await request.agent.touch(task.tid, config.token) - expect(taskInfo.title).assertEqual(config.title) + let taskInfo = await request.agent.touch(task.tid, config.token); + expect(taskInfo.title).assertEqual(config.title); done(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 touch throw_err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 touch throw_err:' + JSON.stringify(err)); + expect().assertFail(); done(); } } try { - task = await request.agent.create(globalThis.abilityContext, config) - task.on('completed', onCompletedCallback) - await task.start() + task = await request.agent.create(globalThis.abilityContext, config); + task.on('completed', onCompletedCallback); + await task.start(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 create throw_err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 create throw_err:' + JSON.stringify(err)); + expect().assertFail(); done(); } @@ -1980,27 +1985,28 @@ export default function requestDownloadTwoUnitTest() { let task:request.agent.Task function onCompletedCallback(progress){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 onCompletedCallback start') + task.off('completed'); + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 onCompletedCallback start'); try{ // @ts-ignore request.agent.touch({}, config.token,(err, taskInfo)=>{ - expect().assertFail() + expect().assertFail(); done(); }) }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 touch throw_err:' + JSON.stringify(err)) - expect(err.code).assertEqual(401) + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 touch throw_err:' + JSON.stringify(err)); + expect(err.code).assertEqual(401); done(); } } try { - task = await request.agent.create(globalThis.abilityContext, config) - task.on('completed', onCompletedCallback) - await task.start() + task = await request.agent.create(globalThis.abilityContext, config); + task.on('completed', onCompletedCallback); + await task.start(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 create throw_err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 create throw_err:' + JSON.stringify(err)); + expect().assertFail(); done(); } @@ -2028,26 +2034,27 @@ export default function requestDownloadTwoUnitTest() { let task:request.agent.Task async function onCompletedCallback(progress){ - console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 onCompletedCallback start') + task.off('completed'); + console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 onCompletedCallback start'); try{ // @ts-ignore - let taskInfo = await request.agent.touch(task.tid, {}) - expect().assertFail() + let taskInfo = await request.agent.touch(task.tid, {}); + expect().assertFail(); done(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 touch throw_err:' + JSON.stringify(err)) - expect(err.code).assertEqual(401) + console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 touch throw_err:' + JSON.stringify(err)); + expect(err.code).assertEqual(401); done(); } } try { - task = await request.agent.create(globalThis.abilityContext, config) - task.on('completed', onCompletedCallback) - await task.start() + task = await request.agent.create(globalThis.abilityContext, config); + task.on('completed', onCompletedCallback); + await task.start(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 create throw_err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 create throw_err:' + JSON.stringify(err)); + expect().assertFail(); done(); } @@ -2075,27 +2082,28 @@ export default function requestDownloadTwoUnitTest() { let task:request.agent.Task function onCompletedCallback(progress){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 onCompletedCallback start') + task.off('completed'); + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 onCompletedCallback start'); try{ request.agent.touch(task.tid, config.token+'1',(err, taskInfo)=>{ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch err:' + JSON.stringify(err)) - expect(err.code).assertEqual(21900006) + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch err:' + JSON.stringify(err)); + expect(err.code).assertEqual(21900006); done(); }) }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch throw_err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch throw_err:' + JSON.stringify(err)); + expect().assertFail(); done(); } } try { - task = await request.agent.create(globalThis.abilityContext, config) - task.on('completed', onCompletedCallback) - await task.start() + task = await request.agent.create(globalThis.abilityContext, config); + task.on('completed', onCompletedCallback); + await task.start(); }catch(err){ - console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 create throw_err:' + JSON.stringify(err)) - expect().assertFail() + console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 create throw_err:' + JSON.stringify(err)); + expect().assertFail(); done(); } -- GitLab