From 6f1bfaf234675290c0dc669ba37048c2d0003bce Mon Sep 17 00:00:00 2001 From: zhangyushuai Date: Wed, 5 Jul 2023 07:25:01 +0000 Subject: [PATCH] =?UTF-8?q?request=20=E5=9C=BA=E6=99=AF=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=A6=86=E7=9B=96=20004?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyushuai --- request/newRequestAuthorityTest/Test.json | 3 +- .../entry/src/main/ets/test/List.test.ets | 11 +- .../main/ets/test/requestDownload.test.ets | 203 ++- .../main/ets/test/requestDownload001.test.ets | 1197 +++++++++++++++ .../main/ets/test/requestDownload002.test.ets | 1256 ++++++++++++++++ .../src/main/ets/test/requestUpload.test.ets | 27 +- .../main/ets/test/requestUpload001.test.ets | 1334 +++++++++++++++++ 7 files changed, 3954 insertions(+), 77 deletions(-) create mode 100755 request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload001.test.ets create mode 100755 request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets create mode 100755 request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload001.test.ets diff --git a/request/newRequestAuthorityTest/Test.json b/request/newRequestAuthorityTest/Test.json index dc04e6b12..8429d7068 100644 --- a/request/newRequestAuthorityTest/Test.json +++ b/request/newRequestAuthorityTest/Test.json @@ -15,7 +15,8 @@ "power-shell wakeup", "power-shell setmode 602", "uinput -T -m 300 720 300 360 200", - "uinput -T -m 650 2760 650 1380 200" + "uinput -T -m 650 2760 650 1380 200", + "pidof download_server | xargs kill -9" ] }, { diff --git a/request/newRequestAuthorityTest/entry/src/main/ets/test/List.test.ets b/request/newRequestAuthorityTest/entry/src/main/ets/test/List.test.ets index c4e084fa5..9a942c28f 100644 --- a/request/newRequestAuthorityTest/entry/src/main/ets/test/List.test.ets +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/List.test.ets @@ -14,9 +14,16 @@ */ import requestUploadJSUnit from './requestUpload.test'; +import requestUploadOneJSUnit from './requestUpload001.test'; import requestDownloadJSUnit from './requestDownload.test'; +import requestDownloadOneJSUnit from './requestDownload001.test'; +import requestDownloadTwoJSUnit from './requestDownload002.test'; export default function testsuite() { - requestDownloadJSUnit() - requestUploadJSUnit() + requestDownloadJSUnit(); + requestDownloadOneJSUnit(); + requestDownloadTwoJSUnit(); + requestUploadJSUnit(); + requestUploadOneJSUnit(); + } \ No newline at end of file diff --git a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload.test.ets b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload.test.ets index 71fd6392d..a90b9c997 100644 --- a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload.test.ets +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload.test.ets @@ -12,9 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import request from "@ohos.request"; -import fileio from '@ohos.fileio'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; export default function requestDownloadJSUnit() { @@ -94,19 +92,19 @@ export default function requestDownloadJSUnit() { * @tc.type : Function * @tc.level : Level 0 */ - it('SUB_MISC_REQUEST_DOWNLOAD_broken_0010', 0, async function (done) { + it('SUB_MISC_REQUEST_DOWNLOAD_faults_0010', 0, async function (done) { console.info("====>-----------------------SUB_MISC_REQUEST_DOWNLOAD_broken_0010 is starting-----------------------"); try { - console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Broken.OTHERS: " + request.agent.Broken.OTHERS); - expect(request.agent.Broken.OTHERS).assertEqual(255); - console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Broken.DISCONNECTED: " + request.agent.Broken.DISCONNECTED); - expect(request.agent.Broken.DISCONNECTED).assertEqual(0); - console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Broken.TIMEOUT: " + request.agent.Broken.TIMEOUT); - expect(request.agent.Broken.TIMEOUT).assertEqual(16); - console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Broken.PROTOCOL: " + request.agent.Broken.PROTOCOL); - expect(request.agent.Broken.PROTOCOL).assertEqual(32); - console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Broken.FSIO: " + request.agent.Broken.FSIO); - expect(request.agent.Broken.FSIO).assertEqual(64); + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Faults.OTHERS: " + request.agent.Faults.OTHERS); + expect(request.agent.Faults.OTHERS).assertEqual(255); + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Faults.DISCONNECTED: " + request.agent.Faults.DISCONNECTED); + expect(request.agent.Faults.DISCONNECTED).assertEqual(0); + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Faults.TIMEOUT: " + request.agent.Faults.TIMEOUT); + expect(request.agent.Faults.TIMEOUT).assertEqual(16); + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Faults.PROTOCOL: " + request.agent.Faults.PROTOCOL); + expect(request.agent.Faults.PROTOCOL).assertEqual(32); + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 request.agent.Faults.FSIO: " + request.agent.Faults.FSIO); + expect(request.agent.Faults.FSIO).assertEqual(64); } catch (err) { console.error("====>SUB_MISC_REQUEST_DOWNLOAD_broken_0010 error: " + err); expect().assertFail(); @@ -124,7 +122,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Create_Download_Callback_0010', 0, async function (done) { console.info("-----------------------SUB_Misc_REQUEST_Create_Download_Callback_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -134,7 +132,7 @@ export default function requestDownloadJSUnit() { mode:request.agent.Mode.BACKGROUND }; - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0010 downloadTask: " + task); try{ if(err){ @@ -161,7 +159,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Create_Download_Promise_0010', 0, async function (done) { console.info("-----------------------SUB_Misc_REQUEST_Create_Download_Promise_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -172,7 +170,7 @@ export default function requestDownloadJSUnit() { }; try { - var task = await request.agent.create(globalThis.abilityContext, conf); + var task = await request.agent.create(globalThis.abilityContext, config); expect(task !== undefined).assertEqual(true); await request.agent.remove(task.tid); console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0010 create success: " + task); @@ -194,7 +192,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Remove_Download_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Callback_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -204,7 +202,7 @@ export default function requestDownloadJSUnit() { }; try { - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); request.agent.remove(task.tid, err => { try { if(err){ @@ -234,7 +232,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Remove_Download_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Promise_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -244,7 +242,7 @@ export default function requestDownloadJSUnit() { }; try { - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); await request.agent.remove(task.tid); expect(true).assertEqual(true); console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0010 remove success: " + task); @@ -265,7 +263,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Start_Download_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Start_Download_Callback_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -274,7 +272,7 @@ export default function requestDownloadJSUnit() { network: request.agent.Network.ANY, }; - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Start_Download_Callback_0010 downloadTask: " + task); task.start(async err => { try{ @@ -304,7 +302,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Start_Download_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Start_Download_Promise_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -314,7 +312,7 @@ export default function requestDownloadJSUnit() { }; try { - var task = await request.agent.create(globalThis.abilityContext, conf); + var task = await request.agent.create(globalThis.abilityContext, config); await task.start(); expect(true).assertEqual(true); await request.agent.remove(task.tid); @@ -337,7 +335,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Pause_Download_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Download_Callback_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -346,7 +344,7 @@ export default function requestDownloadJSUnit() { network: request.agent.Network.WIFI, }; - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Pause_Download_Callback_0010 downloadTask: " + task); task.start(err => { console.info("====>SUB_Misc_REQUEST_Pause_Download_Callback_0010 download start: " + JSON.stringify(err)); @@ -378,7 +376,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Pause_Download_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Download_Promise_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -387,7 +385,7 @@ export default function requestDownloadJSUnit() { network: request.agent.Network.WIFI, }; - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); task.start(async err => { try { console.info("====>SUB_Misc_REQUEST_Pause_Download_Promise_0010 download start: " + JSON.stringify(err)); @@ -414,7 +412,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Resume_Download_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Download_Callback_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -423,7 +421,7 @@ export default function requestDownloadJSUnit() { network: request.agent.Network.WIFI, }; - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 downloadTask: " + task); task.start(err => { console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 start: " + JSON.stringify(err)); @@ -458,7 +456,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Resume_Download_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Download_Promise_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -467,7 +465,7 @@ export default function requestDownloadJSUnit() { network: request.agent.Network.WIFI, }; - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); task.start(err => { console.info("====>SUB_Misc_REQUEST_Resume_Download_Promise_0010 start: " + JSON.stringify(err)); task.pause(async err => { @@ -497,7 +495,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Stop_Download_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Download_Callback_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -506,7 +504,7 @@ export default function requestDownloadJSUnit() { network: request.agent.Network.WIFI, }; - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Stop_Download_Callback_0010 downloadTask: " + task); task.start(err => { console.info("====>SUB_Misc_REQUEST_Stop_Download_Callback_0010 start: " + JSON.stringify(err)); @@ -538,7 +536,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Stop_Download_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Download_Promise_0010 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -547,7 +545,7 @@ export default function requestDownloadJSUnit() { network: request.agent.Network.WIFI, }; - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); task.start(async err => { console.info("====>SUB_Misc_REQUEST_Stop_Download_Promise_0010 start: " + JSON.stringify(err)); try { @@ -572,7 +570,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_On_Download_Progress_0040', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Progress_0040 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -584,7 +582,7 @@ export default function requestDownloadJSUnit() { }; try { - request.agent.create(globalThis.abilityContext, conf, async (err, task) => { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { let on_progressCallback = async (pro) => { task.off('progress', on_progressCallback); console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.state: " + pro.state); @@ -627,7 +625,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Off_Download_Progress_0040', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Progress_0040 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', title: 'reeateTest', @@ -640,7 +638,7 @@ export default function requestDownloadJSUnit() { try { let flag = true; - request.agent.create(globalThis.abilityContext, conf, async (err, task) => { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { let on_progressCallback = (pro) => { flag = false; console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 on_progressCallback flag: " + flag); @@ -685,7 +683,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_On_Download_Completed_0040', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Completed_0040 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', title: 'reeateTest', @@ -696,7 +694,7 @@ export default function requestDownloadJSUnit() { mode:request.agent.Mode.FOREGROUND }; try { - request.agent.create(globalThis.abilityContext, conf, async (err, task) => { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { let on_completedCallback =async (pro) => { task.off('completed', on_completedCallback); console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.state: " + pro.state); @@ -735,7 +733,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Off_Download_Completed_0040', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Completed_0040 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', title: 'reeateTest', @@ -748,7 +746,7 @@ export default function requestDownloadJSUnit() { try { let flag = true; - request.agent.create(globalThis.abilityContext, conf, async (err, task) => { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { let on_offCompletedCallback = (pro) => { flag = false; console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 on_offCompletedCallback flag: " + flag); @@ -785,51 +783,51 @@ export default function requestDownloadJSUnit() { }); /** - * @tc.number SUB_Misc_REQUEST_On_Download_Failed_0010 + * @tc.number SUB_Misc_REQUEST_On_Download_Failed_0040 * @tc.desc download task * @tc.size : MEDIUM * @tc.type : Function * @tc.level : Level 2 */ - it('SUB_Misc_REQUEST_On_Download_Failed_0010', 0, async function (done) { - console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Failed_0010 is starting-----------------------"); - let conf = { + it('SUB_Misc_REQUEST_On_Download_Failed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Failed_0040 is starting-----------------------"); + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/xxxxxxxxxxx/test.apk', title: 'reeateTest', description: 'XTS download test!', - saveas: './SUB_Misc_REQUEST_On_Download_Failed_0010.txt', + saveas: './SUB_Misc_REQUEST_On_Download_Failed_0040.txt', network: request.agent.Network.WIFI, overwrite: true, mode:request.agent.Mode.FOREGROUND }; try { - request.agent.create(globalThis.abilityContext, conf, async (err, task) => { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { let on_failedCallback = async (pro) => { task.off('failed', on_failedCallback); - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.state: " + pro.state); - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.index: " + pro.index); - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.processed: " + pro.processed); - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.size: " + pro.size); - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.extras: " + JSON.stringify(pro.extras)); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.state: " + pro.state); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.index: " + pro.index); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.processed: " + pro.processed); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.size: " + pro.size); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.extras: " + JSON.stringify(pro.extras)); expect(true).assertTrue(); done(); } try { if(err){ - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 create err: " + JSON.stringify(err)); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 create err: " + JSON.stringify(err)); expect().assertFail(); } task.on('failed', on_failedCallback); await task.start(); } catch (err) { - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 catch err: " + JSON.stringify(err)); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 catch err: " + JSON.stringify(err)); await request.agent.remove(task.tid); done(); } }); } catch (err) { - console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 create catch err: " + JSON.stringify(err)); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 create catch err: " + JSON.stringify(err)); done(); } }); @@ -843,7 +841,7 @@ export default function requestDownloadJSUnit() { */ it('SUB_Misc_REQUEST_Off_Download_Failed_0040', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Failed_0040 is starting-----------------------"); - let conf = { + let config = { action: request.agent.Action.DOWNLOAD, url: 'https://gitee.com/xxxxxxxxxxx/test.apk', title: 'reeateTest', @@ -856,7 +854,7 @@ export default function requestDownloadJSUnit() { try { let flag = true; - request.agent.create(globalThis.abilityContext, conf, async (err, task) => { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { let on_failedCallback = (pro) => { flag = false; console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 on_failedCallback flag: " + flag); @@ -892,6 +890,89 @@ export default function requestDownloadJSUnit() { } }); + /** + * @tc.number SUB_Misc_REQUEST_Create_Download_Callback_0060 + * @tc.desc Suspend the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Download_Callback_0060', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Download_Callback_0060 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'reeateTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Create_Download_Callback_0060.txt', + overwrite: true, + network: request.agent.Network.WIFI, + mode:request.agent.Mode.FOREGROUND + }; + request.agent.create(globalThis.abilityContext, config, async (err, task1)=>{ + console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 uploadTask: " + task1); + try{ + if(err){ + console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + request.agent.create(globalThis.abilityContext, config, async (err, task2)=>{ + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 task1 failed"); + await task1.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create success: " + JSON.stringify(err)); + expect(err.code).assertEqual(21900007); + await request.agent.remove(task2.tid); + done(); + } + }); + }catch(error){ + console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create fail: " + JSON.stringify(error)); + done(); + } + console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0060 end-----------------------"); + }); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Create_Download_Promise_0060 + * @tc.desc Suspend the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Download_Promise_0060', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Download_Promise_0060 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'reeateTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Create_Download_Promise_0060.txt', + overwrite: true, + network: request.agent.Network.WIFI, + mode:request.agent.Mode.FOREGROUND + }; + try { + let task1 = await request.agent.create(globalThis.abilityContext, config); + var task2 = await request.agent.create(globalThis.abilityContext, config); + console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0060 task1 failed"); + await task1.start(); + expect().assertFail(); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0060 create catch err: " + JSON.stringify(err)); + await request.agent.remove(task2.tid); + expect(err.code).assertEqual(21900007); + 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 new file mode 100755 index 000000000..65558bb96 --- /dev/null +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload001.test.ets @@ -0,0 +1,1197 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import request from "@ohos.request"; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function requestDownloadOneJSUnitTest() { + describe('requestDownloadOneJSUnit', function () { + console.info('====>################################request download Test start'); + + let sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + clearTimeout(st); + }, timeout); + }); + }; + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0140 + * @tc.desc Create a download Task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_create_Callback_0140", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND , + overwrite: true, + saveas: "./SUB_Misc_REQUEST_create_Callback_0140.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 0, + ends: 100, + }; + console.info("====>-------------------SUB_Misc_REQUEST_create_Callback_0140 is starting---------------------"); + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + try{ + if (err) { + console.info("====>SUB_Misc_REQUEST_create_Callback_0140 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on("completed", (progress) => { + task.off("completed"); + let downloadSize = progress.sizes[0]; + console.debug('====>downloadSize:' + downloadSize); + let fileSize = config.ends - config.begins + 1; + console.debug('====>fileSize:'+ fileSize); + expect(downloadSize).assertEqual(fileSize); + console.info("====>----------SUB_Misc_REQUEST_create_Callback_0140 is end---------------"); + done(); + }); + await task.start(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_create_Callback_0140 create err: " + JSON.stringify(err)); + done(); + } + }); + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0140 + * @tc.desc Create a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0140", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0140.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 0, + ends: 100, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0140 is starting---------------------"); + + try{ + let task = await request.agent.create(globalThis.abilityContext, config) + async function onCompletedCallback(progress){ + task.off("completed"); + let downloadSize = progress.sizes[0] + console.debug('====>downloadSize:' + downloadSize) + let fileSize = config.ends - config.begins + 1 + console.debug('====>fileSize:'+ fileSize) + expect(downloadSize).assertEqual(fileSize) + done(); + } + task.on("completed", onCompletedCallback) + await task.start() + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0140 create err: " + JSON.stringify(err)); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0160 + * @tc.desc Create a download Task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_create_Callback_0160", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_create_Callback_0160.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 150335340, + ends: -1, + }; + console.info("====>-------------------SUB_Misc_REQUEST_create_Callback_0160 is starting---------------------"); + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + try{ + if (err) { + console.info("====>SUB_Misc_REQUEST_create_Callback_0160 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on("completed", (progress) => { + task.off("completed"); + let downloadSize = progress.sizes[0]; + console.debug('====>downloadSize:' + downloadSize); + expect(downloadSize).assertEqual(100); + console.info("====>----------SUB_Misc_REQUEST_create_Callback_0160 is end---------------"); + done(); + }); + await task.start(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_create_Callback_0160 create err: " + JSON.stringify(err)); + done(); + } + }); + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0160 + * @tc.desc Create a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0160", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0160.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 150335340, + ends: -1, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0160 is starting---------------------"); + + try{ + let task = await request.agent.create(globalThis.abilityContext, config); + async function onCompletedCallback(progress){ + task.off("completed"); + let downloadSize = progress.sizes[0]; + console.debug('====>downloadSize:' + downloadSize); + expect(downloadSize).assertEqual(100); + done(); + } + task.on("completed", onCompletedCallback); + await task.start(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0160 create err: " + JSON.stringify(err)); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0170 + * @tc.desc Create a download Task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_create_Callback_0170", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_create_Callback_0170.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 30, + ends: 60, + }; + console.info("====>-------------------SUB_Misc_REQUEST_create_Callback_0170 is starting---------------------"); + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + try{ + if (err) { + console.info("====>SUB_Misc_REQUEST_create_Callback_0170 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on("completed", (progress) => { + task.off("completed"); + let downloadSize = progress.sizes[0]; + console.debug('====>downloadSize:' + downloadSize); + let fileSize = config.ends - config.begins + 1; + console.debug('====>fileSize:'+ fileSize); + expect(downloadSize).assertEqual(fileSize); + console.info("====>-----------------SUB_Misc_REQUEST_create_Callback_0170 is end--------------------"); + done(); + }); + await task.start(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_create_Callback_0170 create err: " + JSON.stringify(err)); + done(); + } + }); + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0170 + * @tc.desc Create a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0170", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0170.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 30, + ends: 60, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0170 is starting---------------------"); + + try{ + let task = await request.agent.create(globalThis.abilityContext, config) + async function onCompletedCallback(progress){ + task.off("completed"); + let downloadSize = progress.sizes[0]; + console.debug('====>downloadSize:' + downloadSize); + let fileSize = config.ends - config.begins + 1; + console.debug('====>fileSize:'+ fileSize); + expect(downloadSize).assertEqual(fileSize); + done(); + } + task.on("completed", onCompletedCallback); + await task.start(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0170 create err: " + JSON.stringify(err)); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0180 + * @tc.desc Create a download Task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_create_Callback_0180", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_create_Callback_0180.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 60, + ends: 30, + }; + console.info("====>-------------------SUB_Misc_REQUEST_create_Callback_0180 is starting---------------------"); + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + try{ + if (err) { + console.info("====>SUB_Misc_REQUEST_create_Callback_0180 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on("failed", (progress) => { + task.off("failed"); + console.info('====>upload task failed.' + JSON.stringify(progress)); + expect(progress.state).assertEqual(65); + done(); + }); + await task.start(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_create_Callback_0170 create err: " + JSON.stringify(err)); + done(); + } + }); + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0180 + * @tc.desc Create a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0180", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0180.txt", + network: request.agent.Network.WIFI, + index: 0, + begins: 60, + ends: 30, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0180 is starting---------------------"); + try{ + let task = await request.agent.create(globalThis.abilityContext, config); + let createOffCallback = (progress) => { + console.info('====>upload task failed.' + JSON.stringify(progress)); + task.off("failed"); + expect(progress.state).assertEqual(65); + done(); + }; + task.on("failed", createOffCallback); + await task.start(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0180 create err: " + JSON.stringify(err)); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0090 + * @tc.desc Create a download Task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_create_Callback_0090", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: undefined, + description: undefined, + mode: undefined, + overwrite: undefined, + method: undefined, + data: undefined, + saveas: undefined, + network: undefined, + metered: undefined, + roaming: undefined, + retry: undefined, + redirect: undefined, + index: undefined, + begins: undefined, + ends: undefined, + gauge: undefined, + precise: undefined, + token: undefined + }; + console.info("====>-------------------SUB_Misc_REQUEST_create_Callback_0090 is starting---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config, async(err, task) => { + if (err) { + console.info("====>SUB_Misc_REQUEST_create_Callback_0090 create err: " + JSON.stringify(err)); + done(); + } + task.start(async (err) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_create_Callback_0090 Failed to start the download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + return; + } + console.info(`====>SUB_Misc_REQUEST_create_Callback_0090 Succeeded in starting a download task.`); + expect(true).assertEqual(true); + await request.agent.remove(task.tid); + console.info("====>----------------SUB_Misc_REQUEST_create_Callback_0090 is end-------------------"); + done(); + }); + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_create_Callback_0090 create err: " + JSON.stringify(err)); + done(); + } + }) + + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0090 + * @tc.desc Create a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0090", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: undefined, + description: undefined, + mode: undefined, + overwrite: undefined, + method: undefined, + data: undefined, + saveas: undefined, + network: undefined, + metered: undefined, + roaming: undefined, + retry: undefined, + redirect: undefined, + index: undefined, + begins: undefined, + ends: undefined, + gauge: undefined, + precise: undefined, + token: undefined + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0180 is starting---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config).then(async (task)=> { + task.start(async (err) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Promise_0180 Failed to start the download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + return; + } + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0180 Succeeded in starting a download task.`); + expect(true).assertEqual(true); + await request.agent.remove(task.tid); + console.info("====>------------------SUB_Misc_REQUEST_Create_Promise_0180 is end-------------------"); + done(); + }); + }).catch((err) => { + console.info("====>SUB_Misc_REQUEST_Create_Promise_0180 create err: " + JSON.stringify(err)); + done(); + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0180 create err: " + JSON.stringify(err)); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Callback_0020 + * @tc.desc remove the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Callback_0020', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Callback_0020 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + overwrite: true, + saveas: './SUB_Misc_REQUEST_Remove_Download_Callback_0020.txt', + network: request.agent.Network.ANY, + }; + let a='a'; + let callback = err => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0020 remove err: " + JSON.stringify(err)); + expect().assertFail(); + } + expect(task !== undefined).assertEqual(true); + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0020 remove success: " + task); + console.info("====>-----------------SUB_Misc_REQUEST_Remove_Download_Callback_0020 end--------------------"); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0020 remove fail: " + JSON.stringify(err)); + done(); + } + }; + let task = await request.agent.create(globalThis.abilityContext, config); + try { + // @ts-ignore + request.agent.remove(task.tid, a, callback); + } catch (error) { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0020 catch error: " + JSON.stringify(error)); + expect().assertFail(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Promise_0020 + * @tc.desc remove the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Promise_0020', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Promise_0020 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + overwrite: true, + saveas: './SUB_Misc_REQUEST_Remove_Download_Promise_0020.txt', + network: request.agent.Network.ANY, + }; + let a='a'; + let task = await request.agent.create(globalThis.abilityContext, config); + // @ts-ignore + await request.agent.remove(task.tid,a).then(()=>{ + expect(true).assertEqual(true); + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0020 remove success: " + task);} + ).catch ((err)=>{ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0020 catch error: " + JSON.stringify(err)); + expect().assertFail(); + }) + console.info("====>---------------SUB_Misc_REQUEST_Remove_Download_Promise_0020 end-------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Callback_0030 + * @tc.desc remove the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_MISC_REQUEST_DOWNLOAD_removeNormal_callback_0030', 0, async function (done) { + console.info("====>-----------------------SUB_MISC_REQUEST_DOWNLOAD_removeNormal_callback_0030 is starting-----------------------"); + try { + // @ts-ignore + request.agent.remove(true, (err) => { + try { + if(err){ + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_removeNormal_callback_0030 err.message: " + err.message); + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_removeNormal_callback_0030 err.code: " + err.code); + expect(err.code).assertEqual(401); + }else{ + expect().assertFail(); + } + done(); + }catch (err){ + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_removeNormal_callback_0030 remove fail: " + JSON.stringify(err)); + done(); + } + }); + }catch (err){ + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_removeNormal_callback_0030 remove fail: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Promise_0030 + * @tc.desc remove the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Promise_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Promise_0030 is starting-----------------------"); + try { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0030 remove"); + // @ts-ignore + await request.agent.remove(true); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0030 catch error: " + JSON.stringify(err)); + expect(err.code).assertEqual(401); + } + console.info("====>---------------SUB_Misc_REQUEST_Remove_Download_Promise_0030 end--------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Promise_0040 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Promise_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Promise_0040 is starting-----------------------"); + try { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0040 remove"); + // @ts-ignore + await request.agent.remove(1); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0040 catch error: " + JSON.stringify(err)); + expect(err.code).assertEqual(401); + } + console.info("====>---------------SUB_Misc_REQUEST_Remove_Download_Promise_0040 end-------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Callback_0040 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Callback_0040', 0, async function (done) { + console.info("====>------------SUB_Misc_REQUEST_Remove_Download_Callback_0040 is starting-----------------"); + try { + // @ts-ignore + request.agent.remove(1, (err) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0040 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0040 err.code: " + err.code); + expect(err.code).assertEqual(401); + }else{ + expect().assertFail(); + } + done(); + }catch (err){ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0040 remove fail: " + JSON.stringify(err)); + done(); + } + }); + }catch (err){ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0040 remove fail: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Callback_0050 + * @tc.desc remove the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Callback_0050', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Callback_0050 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + overwrite: true, + saveas: './SUB_Misc_REQUEST_Remove_Download_Callback_0050.txt', + network: request.agent.Network.ANY, + }; + let task = await request.agent.create(globalThis.abilityContext, config); + request.agent.remove(task.tid, (err) => { + try { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Remove_Download_Callback_0050 Failed to removing first a download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + } + request.agent.remove(task.tid, (err) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0050 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0050 err.code: " + err.code); + expect(err.code).assertEqual(21900006); + done(); + }else{ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0050 remove second not err: "); + expect().assertFail(); + } + done(); + }catch (err){ + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0050 remove second fail: " + JSON.stringify(err)); + console.info("====>-------------SUB_Misc_REQUEST_Remove_Download_Callback_0050 end------------------"); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0050 remove first fail: " + JSON.stringify(err)); + done(); + } + }); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Promise_0050 + * @tc.desc remove the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Promise_0050', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Promise_0050 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Remove_Download_Promise_0050.txt', + network: request.agent.Network.ANY, + overwrite: true, + }; + try { + let task = await request.agent.create(globalThis.abilityContext, config); + await request.agent.remove(task.tid); + await sleep(10); + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0050 remove first: " + task); + await request.agent.remove(task.tid); + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0050 remove second: " + task); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0050 catch error: " + JSON.stringify(err)); + console.info("====>----------------SUB_Misc_REQUEST_Remove_Download_Promise_0050 end------------------"); + expect(err.code).assertEqual(21900006); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Promise_0060 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Download_Promise_0060', 0, async function (done) { + console.info("====>---------------SUB_Misc_REQUEST_Remove_Download_Promise_0060 is starting-------------------"); + try { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0060 remove"); + await request.agent.remove('abc'); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0060 catch error: " + JSON.stringify(err)); + expect(err.code).assertEqual(21900006); + } + console.info("====>-------------------SUB_Misc_REQUEST_Remove_Download_Promise_0060 end-------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Download_Callback_0060 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_MISC_REQUEST_DOWNLOAD_remove_callback_0060', 0, async function (done) { + console.info("====>-----------------------SUB_MISC_REQUEST_DOWNLOAD_remove_callback_0060 is starting-----------------------"); + request.agent.remove('abc', (err) => { + try { + if(err){ + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_remove_callback_0060 err.message: " + err.message); + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_remove_callback_0060 err.code: " + err.code); + expect(err.code).assertEqual(21900006); + }else{ + expect().assertFail(); + } + done(); + }catch (err){ + console.info("====>SUB_MISC_REQUEST_DOWNLOAD_remove_callback_0060 remove fail: " + JSON.stringify(err)); + done(); + } + }); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0030 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0030", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: '//gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0030.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0030 is starting---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config).then(async (task)=> { + task.start(async (err) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Promise_0030 Failed to start the download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + return; + } + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0030 Succeeded in starting a download task.`); + expect(true).assertEqual(true); + await request.agent.remove(task.tid); + console.info("====>--------------------SUB_Misc_REQUEST_Create_Promise_0030 is end---------------------"); + done(); + }); + }).catch((err) => { + console.info("====>SUB_Misc_REQUEST_Create_Promise_0030 create err: " + JSON.stringify(err)); + console.info("====>--------------------SUB_Misc_REQUEST_Create_Promise_0030 is end---------------------"); + done(); + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0030 create err: " + JSON.stringify(err)); + console.info("====>--------------------SUB_Misc_REQUEST_Create_Promise_0030 is end---------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0040 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0040", 0, async function (done) { + let config = { + action: 3, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'Sample code for create task', + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0040.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0040 is starting---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config).then(async (task)=> { + task.start(async (err) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Promise_0040 Failed to start the download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + return; + } + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0040 Succeeded in starting a download task.`); + expect(true).assertEqual(true); + await request.agent.remove(task.tid); + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0040 is end--------------------"); + done(); + }); + }).catch((err) => { + console.info("====>SUB_Misc_REQUEST_Create_Promise_0040 create err: " + JSON.stringify(err)); + console.info("====>--------------------SUB_Misc_REQUEST_Create_Promise_0040 is end---------------------"); + done(); + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0040 create err: " + JSON.stringify(err)); + console.info("====>--------------------SUB_Misc_REQUEST_Create_Promise_0040 is end-----------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Download_Promise_0020 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Download_Promise_0020", 0, async function (done) { + let config = {}; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Download_Promise_0020 is starting---------------------"); + try{ + // @ts-ignore + request.agent.create(globalThis.abilityContext, config).then(async (task)=> { + task.start(async (err) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Download_Promise_0020 Failed to start the download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + return; + } + console.info(`====>SUB_Misc_REQUEST_Create_Download_Promise_0020 Succeeded in starting a download task.`); + expect(true).assertEqual(true); + await request.agent.remove(task.tid); + console.info("====>-----------------SUB_Misc_REQUEST_Create_Download_Promise_0020 is end-----------------"); + done(); + }); + }).catch((err) => { + console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0020 create err: " + JSON.stringify(err)); + console.info("====>-------------SUB_Misc_REQUEST_Create_Download_Promise_0020 is end------------------"); + done(); + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0020 create err: " + JSON.stringify(err)); + console.info("====>-----------------SUB_Misc_REQUEST_Create_Download_Promise_0020 is end--------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0130 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0130", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'Sample code for create task', + mode: 0, + overwrite: true, + saveas: "./SSUB_Misc_REQUEST_Create_Promise_0130.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0130 is starting---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config).then(async (task)=> { + task.start(async (err) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Promise_0130 Failed to start the download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + } + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0130 Succeeded in starting a download task.`); + expect(true).assertEqual(true); + await request.agent.remove(task.tid); + done(); + }); + }).catch((err) => { + console.info("====>SUB_Misc_REQUEST_Create_Promise_0130 create err: " + JSON.stringify(err)); + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0130 is end---------------------"); + done(); + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0130 create err: " + JSON.stringify(err)); + console.info("====>--------------------SUB_Misc_REQUEST_Create_Promise_0130 is end---------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0060 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Callback_0060", 0, async function (done) { + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'Sample code for create task', + mode: 1, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Callback_0060.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Callback_0060 is starting---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config, (err, task) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Callback_0060 Failed to create a download task, Code: ${err.code}, message: ${err.message}`); + return; + } + task.start((err) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Callback_0060 Failed to start the download task, Code: ${err.code}, message: ${err.message}`); + expect().assertFail(); + return; + } + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0060 Succeeded in starting a download task.`); + expect(true).assertEqual(true); + request.agent.remove(task.tid); + console.info("====>----------------SUB_Misc_REQUEST_Create_Callback_0060 is end---------------------"); + done(); + }); + }) + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Callback_0060 create err: " + JSON.stringify(err)); + done(); + } + })//mode1 + + /** + * @tc.number SUB_Misc_REQUEST_Create_Download_Callback_0050 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Download_Callback_0050", 0, async function (done) { + let config = {}; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Download_Callback_0050 is starting---------------------"); + try{ + // @ts-ignore + request.agent.create(globalThis.abilityContext, config, (err, task) => { + if (err) { + console.error(`====>SUB_Misc_REQUEST_Create_Download_Callback_0050 Failed to create a download task, Code: ${err.code}, message: ${err.message}`); + return; + } + console.info(`====>SUB_Misc_REQUEST_Create_Download_Callback_0050 Succeeded in creating a download task`); + }); + expect().assertFail(); + }catch(err){ + expect(err.code).assertEqual(401); + console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0050 create err: " + JSON.stringify(err)); + console.info("====>----------------SUB_Misc_REQUEST_Create_Download_Callback_0050 is end------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0110 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0110", 0, async function (done) { + let des = 'x'; + for (let i = 0; i < 1025; i++){ + des += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: des, + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0110.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------SUB_Misc_REQUEST_Create_Promise_0110 is starting----------------"); + try{ + await request.agent.create(globalThis.abilityContext, config); + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0110 Succeeded in starting a download task.`); + expect().assertFail(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0110 create err: " + JSON.stringify(err)); + expect(err.code).assertEqual(401); + console.info("-----------------------SUB_Misc_REQUEST_Create_Promise_0110 is end-----------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0110 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Callback_0110", 0, async function (done) { + let des = 'x'; + for (let i = 0; i < 1025; i++){ + des += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: des, + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Callback_0110.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Callback_0110 is start ---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config, (err, task) => { + try { + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0110 Succeeded in starting a download task.`); + expect().assertFail(); + } catch (err) { + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0110 Succeeded in starting a download task.` + JSON.stringify(err)); + request.agent.remove(task.tid); + done(); + } + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Callback_0110 create err: " + JSON.stringify(err)); + console.info("-----------------------SUB_Misc_REQUEST_Create_Callback_0110 is end-----------------------"); + expect(err.code).assertEqual(401); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Promise_0150 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Promise_0150", 0, async function (done) { + let tit = 'x'; + for (let i = 0; i < 257; i++){ + tit += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: tit, + description: 'Sample code for create task', + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Promise_0150.txt", + network: request.agent.Network.WIFI, + }; + + console.info("====>-------------------SUB_Misc_REQUEST_Create_Promise_0150 is starting---------------------"); + try{ + await request.agent.create(globalThis.abilityContext, config); + console.info(`====>SUB_Misc_REQUEST_Create_Promise_0150 Succeeded in starting a download task.`); + expect().assertFail(); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Promise_0150 create err: " + JSON.stringify(err)); + expect(err.code).assertEqual(401); + console.info("-----------------------SUB_Misc_REQUEST_Create_Promise_0150 is end-----------------------"); + done(); + } + }) + + /** + * @tc.number SUB_Misc_REQUEST_Create_Callback_0150 + * @tc.desc remove a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it("SUB_Misc_REQUEST_Create_Callback_0150", 0, async function (done) { + let tit = 'x'; + for (let i = 0; i < 257; i++){ + tit += 'x'; + } + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: tit, + description: 'Sample code for create task', + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + saveas: "./SUB_Misc_REQUEST_Create_Callback_0150.txt", + network: request.agent.Network.WIFI, + }; + console.info("====>-------------------SUB_Misc_REQUEST_Create_Callback_0150 is start---------------------"); + try{ + request.agent.create(globalThis.abilityContext, config, (err, task) => { + try { + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0150 Succeeded in starting a download task.`); + expect().assertFail(); + } catch (err) { + console.info(`====>SUB_Misc_REQUEST_Create_Callback_0150 Succeeded in starting a download task.` + JSON.stringify(err)); + request.agent.remove(task.tid); + done(); + } + }); + }catch(err){ + console.info("====>SUB_Misc_REQUEST_Create_Callback_0150 create err: " + JSON.stringify(err)); + console.info("====>-----------------SUB_Misc_REQUEST_Create_Callback_0150 is end-------------------"); + expect(err.code).assertEqual(401); + done(); + } + }) + + }); +} \ No newline at end of file diff --git a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets new file mode 100755 index 000000000..81eeae475 --- /dev/null +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestDownload002.test.ets @@ -0,0 +1,1256 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import request from "@ohos.request"; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function requestDownloadTwoUnitTest() { + describe('requestDownloadTwoJSUnit', function () { + console.info('====>################################request download Test start'); + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Progress_0040 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Progress_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Progress_0040 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Progress_0040.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = async (pro) => { + task.off('progress', on_progressCallback); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.state: " + pro.state); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.index: " + pro.index); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.processed: " + pro.processed); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.size: " + pro.size); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.extras: " + JSON.stringify(pro.extras)); + try { + await request.agent.remove(task.tid); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 task has complete: " + JSON.stringify(task.tid)); + } + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Progress_0030 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Progress_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Progress_0030 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Progress_0030.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let flag = true + let flag1 = true + let on_progressCallback = async (pro) => { + flag = false + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0030 pro.state: " + pro.state); + } + let on_progressCallback1 = async (pro) => { + flag1 = false + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0030 pro.extras: " + JSON.stringify(pro.extras)); + try { + await request.agent.remove(task.tid); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0030 task has complete: " + JSON.stringify(task.tid)); + } + expect(!flag && !flag1).assertTrue(); + task.off('progress', on_progressCallback); + task.off('progress', on_progressCallback1); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + task.on('progress', on_progressCallback1); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Progress_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Progress_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Progress_0010 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Progress_0010.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = async (pro) => { + task.off('progress', on_progressCallback); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 pro.state: " + pro.state); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 pro.index: " + pro.index); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 pro.processed: " + pro.processed); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 pro.size: " + pro.size); + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 pro.extras: " + JSON.stringify(pro.extras)); + try { + await request.agent.remove(task.tid); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 task has complete: " + JSON.stringify(task.tid)); + } + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + let a='a' + // @ts-ignore + task.on('progress', on_progressCallback,a); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Progress_0040 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Progress_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Progress_0040 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Progress_0040.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 on_progressCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + task.off('progress', on_progressCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 offProgress success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 5000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Progress_0030 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Progress_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Progress_0030 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Progress_0030.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + let flag = true; + let flag1 = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 on_progressCallback flag: " + flag); + } + let on_progressCallback1 = (pro) => { + flag1 = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 on_progressCallback1 flag1: " + flag1); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + task.on('progress', on_progressCallback1); + task.off('progress'); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 offProgress success flag: " + flag); + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 offProgress success flag1: " + flag1); + clearTimeout(t); + expect(flag && flag1).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Progress_0020 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Progress_0020', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Progress_0020 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Progress_0020.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + let flag = true; + let flag1 = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 on_progressCallback flag: " + flag); + } + let on_progressCallback1 = (pro) => { + flag1 = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 on_progressCallback1 flag1: " + flag1); + expect(true).assertTrue(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + task.on('progress', on_progressCallback1); + task.off('progress',on_progressCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 offProgress success flag: " + flag); + clearTimeout(t); + expect(flag ).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Progress_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Progress_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Progress_0010 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Progress_0010.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0010 on_progressCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + let a='a'; + // @ts-ignore + task.off('progress', on_progressCallback,a); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0010 offProgress success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0010 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0010 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Completed_0040 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Completed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Completed_0040 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Completed_0040.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_completedCallback =async (pro) => { + task.off('completed', on_completedCallback); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.state: " + pro.state); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.index: " + pro.index); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.processed: " + pro.processed); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.size: " + pro.size); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.extras: " + JSON.stringify(pro.extras)); + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_completedCallback); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Completed_0030 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Completed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Completed_0030 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Completed_0030.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let flag = true + let flag1 = true + let on_progressCallback = async (pro) => { + flag = false + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0030 pro.state: " + pro.state); + } + let on_progressCallback1 = async (pro) => { + flag1 = false + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0030 pro.extras: " + JSON.stringify(pro.extras)); + try { + await request.agent.remove(task.tid); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0030 task has complete: " + JSON.stringify(task.tid)); + } + expect(!flag && !flag1).assertTrue(); + task.off('completed', on_progressCallback); + task.off('completed', on_progressCallback1); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_progressCallback); + task.on('completed', on_progressCallback1); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Completed_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Completed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Completed_0010 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Completed_0010.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_completedCallback =async (pro) => { + task.off('completed', on_completedCallback); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 pro.state: " + pro.state); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 pro.index: " + pro.index); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 pro.processed: " + pro.processed); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 pro.size: " + pro.size); + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 pro.extras: " + JSON.stringify(pro.extras)); + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + let a='a' + // @ts-ignore + task.on('completed', on_completedCallback,a); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Completed_0040 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Completed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Completed_0040 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Completed_0040.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_offCompletedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 on_offCompletedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_offCompletedCallback); + task.off('completed', on_offCompletedCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 offCompleted success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 offCompleted fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Completed_0030 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Completed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Completed_0030 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Completed_0030.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + let flag = true; + let flag1 = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 on_progressCallback flag: " + flag); + } + let on_progressCallback1 = (pro) => { + flag1 = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 on_progressCallback1 flag1: " + flag1); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_progressCallback); + task.on('completed', on_progressCallback1); + task.off('completed'); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 offProgress success flag: " + flag); + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 offProgress success flag1: " + flag1); + clearTimeout(t); + expect(flag && flag1).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Completed_0020 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Completed_0020', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Completed_0020 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Completed_0020.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + let flag = true; + let flag1 = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 on_progressCallback flag: " + flag); + } + let on_progressCallback1 = (pro) => { + flag1 = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 on_progressCallback1 flag1: " + flag1); + expect(true).assertTrue(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_progressCallback); + task.on('completed', on_progressCallback1); + task.off('completed',on_progressCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 offProgress success flag: " + flag); + clearTimeout(t); + expect(flag ).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Completed_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Completed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Completed_0010 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Completed_0010.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_offCompletedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0010 on_offCompletedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_offCompletedCallback); + let a='a'; + // @ts-ignore + task.off('completed', on_offCompletedCallback,a); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0010 offCompleted success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0010 offCompleted fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0010 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Failed_0040 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Failed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Failed_0040 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/xxxxxxxxxxx/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Failed_0040.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_failedCallback = async (pro) => { + task.off('failed', on_failedCallback); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.state: " + pro.state); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.index: " + pro.index); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.processed: " + pro.processed); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.size: " + pro.size); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.extras: " + JSON.stringify(pro.extras)); + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_failedCallback); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Failed_0030 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Failed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Failed_0030 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Failed_0030.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let flag = true + let flag1 = true + let on_progressCallback = async (pro) => { + flag = false + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0030 pro.state: " + pro.state); + } + let on_progressCallback1 = async (pro) => { + flag1 = false + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0030 pro.extras: " + JSON.stringify(pro.extras)); + try { + await request.agent.remove(task.tid); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0030 task has complete: " + JSON.stringify(task.tid)); + } + expect(!flag && !flag1).assertTrue(); + task.off('completed', on_progressCallback); + task.off('completed', on_progressCallback1); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_progressCallback); + task.on('completed', on_progressCallback1); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Download_Failed_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Download_Failed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Failed_0010 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/xxxxxxxxxxx/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_On_Download_Failed_0010.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_failedCallback = async (pro) => { + task.off('failed', on_failedCallback); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.state: " + pro.state); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.index: " + pro.index); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.processed: " + pro.processed); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.size: " + pro.size); + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 pro.extras: " + JSON.stringify(pro.extras)); + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + let a='a' + // @ts-ignore + task.on('failed', on_failedCallback,a); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Failed_0040 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Failed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Failed_0040 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/xxxxxxxxxxx/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Failed_0040.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_failedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 on_failedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_failedCallback); + task.off('failed', on_failedCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 offFailed success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 offFailed fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Failed_0030 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Failed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Failed_0030 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Failed_0030.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + let flag = true; + let flag1 = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 on_progressCallback flag: " + flag); + } + let on_progressCallback1 = (pro) => { + flag1 = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 on_progressCallback1 flag1: " + flag1); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_progressCallback); + task.on('failed', on_progressCallback1); + task.off('failed'); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 offProgress success flag: " + flag); + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 offProgress success flag1: " + flag1); + clearTimeout(t); + expect(flag && flag1).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Failed_0020 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Failed_0020', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Failed_0020 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Failed_0020.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + try { + let flag = true; + let flag1 = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 on_progressCallback flag: " + flag); + } + let on_progressCallback1 = (pro) => { + flag1 = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 on_progressCallback1 flag1: " + flag1); + expect(true).assertTrue(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_progressCallback); + task.on('failed', on_progressCallback1); + task.off('failed',on_progressCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 offProgress success flag: " + flag); + clearTimeout(t); + expect(flag ).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 offProgress fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Download_Failed_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Download_Failed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Failed_0010 is starting-----------------------"); + let config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://gitee.com/xxxxxxxxxxx/test.apk', + title: 'createTest', + description: 'XTS download test!', + saveas: './SUB_Misc_REQUEST_Off_Download_Failed_0010.txt', + network: request.agent.Network.WIFI, + overwrite: true, + mode:request.agent.Mode.FOREGROUND + }; + + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config, async (err, task) => { + let on_failedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0010 on_failedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_failedCallback); + let a='a'; + // @ts-ignore + task.off('failed', on_failedCallback,a); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0010 offFailed success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0010 offFailed fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 3000) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0010 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + }); +} \ No newline at end of file diff --git a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload.test.ets b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload.test.ets index f53beb0ad..6b19d880b 100644 --- a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload.test.ets +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload.test.ets @@ -58,7 +58,7 @@ export default function requestUploadJSUnit() { } }]; - let conf = { + let config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'uploadTest', @@ -84,6 +84,7 @@ export default function requestUploadJSUnit() { let sleep = function (timeout) { return new Promise(resolve => { const st = setTimeout(() => { + clearTimeout(st); resolve(null); }, timeout); }); @@ -98,7 +99,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Create_Upload_Callback_0010', 0, async function (done) { console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0010 is starting-----------------------"); - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0010 uploadTask: " + task); try{ if(err){ @@ -127,7 +128,7 @@ export default function requestUploadJSUnit() { it('SUB_Misc_REQUEST_Create_Upload_Promise_0010', 0, async function (done) { console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Promise_0010 is starting-----------------------"); try { - var task = await request.agent.create(globalThis.abilityContext, conf); + var task = await request.agent.create(globalThis.abilityContext, config); expect(task !== undefined).assertEqual(true); await request.agent.remove(task.tid); console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0010 create success: " + task); @@ -150,7 +151,7 @@ export default function requestUploadJSUnit() { it('SUB_Misc_REQUEST_Remove_Upload_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0010 is starting-----------------------"); try { - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); request.agent.remove(task.tid, err => { try { if(err){ @@ -181,7 +182,7 @@ export default function requestUploadJSUnit() { it('SUB_Misc_REQUEST_Remove_Upload_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0010 is starting-----------------------"); try { - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); await request.agent.remove(task.tid); expect(true).assertEqual(true); console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0010 remove success: " + task); @@ -202,7 +203,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Start_Upload_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Start_Upload_Callback_0010 is starting-----------------------"); - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Start_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); task.start(async err => { try{ @@ -232,7 +233,7 @@ export default function requestUploadJSUnit() { it('SUB_Misc_REQUEST_Start_Upload_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Start_Upload_Promise_0010 is starting-----------------------"); try { - var task = await request.agent.create(globalThis.abilityContext, conf); + var task = await request.agent.create(globalThis.abilityContext, config); await task.start(); expect(true).assertEqual(true); console.info("====>SUB_Misc_REQUEST_Start_Upload_Promise_0010 upload start success: " + JSON.stringify(task)); @@ -254,7 +255,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Pause_Upload_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Upload_Callback_0010 is starting-----------------------"); - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Pause_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); task.start(err => { console.info("====>SUB_Misc_REQUEST_Pause_Upload_Callback_0010 upload start: " + JSON.stringify(err)); @@ -286,7 +287,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Pause_Upload_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Upload_Promise_0010 is starting-----------------------"); - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); console.info("====>SUB_Misc_REQUEST_Pause_Upload_Promise_0010 create task: " + JSON.stringify(task)); task.start(async err => { try { @@ -314,7 +315,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Resume_Upload_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Upload_Callback_0010 is starting-----------------------"); - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); task.start(err => { console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 start: " + JSON.stringify(err)); @@ -349,7 +350,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Resume_Upload_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Upload_Promise_0010 is starting-----------------------"); - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); console.info("====>SUB_Misc_REQUEST_Resume_Upload_Promise_0010 create task: " + JSON.stringify(task)); task.start(err => { console.info("====>SUB_Misc_REQUEST_Resume_Upload_Promise_0010 start: " + JSON.stringify(err)); @@ -380,7 +381,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Stop_Upload_Callback_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Upload_Callback_0010 is starting-----------------------"); - request.agent.create(globalThis.abilityContext, conf, async (err, task)=>{ + request.agent.create(globalThis.abilityContext, config, async (err, task)=>{ console.info("====>SUB_Misc_REQUEST_Stop_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); task.start(err => { console.info("====>SUB_Misc_REQUEST_Stop_Upload_Callback_0010 start: " + JSON.stringify(err)); @@ -412,7 +413,7 @@ export default function requestUploadJSUnit() { */ it('SUB_Misc_REQUEST_Stop_Upload_Promise_0010', 0, async function (done) { console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Upload_Promise_0010 is starting-----------------------"); - let task = await request.agent.create(globalThis.abilityContext, conf); + let task = await request.agent.create(globalThis.abilityContext, config); console.info("====>SUB_Misc_REQUEST_Stop_Upload_Promise_0010 create task: " + JSON.stringify(task)); task.start(async err => { console.info("====>SUB_Misc_REQUEST_Stop_Upload_Promise_0010 start: " + JSON.stringify(err)); diff --git a/request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload001.test.ets b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload001.test.ets new file mode 100755 index 000000000..04a9aa499 --- /dev/null +++ b/request/newRequestAuthorityTest/entry/src/main/ets/test/requestUpload001.test.ets @@ -0,0 +1,1334 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; +import request from "@ohos.request"; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function requestUploadOnetJSUnitTest() { + describe('requestUploadOneJSUnit', function () { + let attachments = [{ + name: "uploadTest", + value: { + path: "./test.txt", + filename: "test.txt", + mimetype: "application/octet-stream" + } + }]; + + let config = { + action: request.agent.Action.UPLOAD, + url: 'http://127.0.0.1', + title: 'uploadTest', + description: 'Sample code for event listening', + mode: request.agent.Mode.BACKGROUND, + overwrite: true, + method: "POST", + data: attachments, + saveas: "./", + network: request.agent.Network.CELLULAR, + metered: false, + roaming: true, + retry: true, + redirect: true, + index: 0, + begins: 0, + ends: -1, + gauge: false, + precise: false, + token: "it is a secret" + }; + + let sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + clearTimeout(st); + }, timeout); + }); + }; + + /** + * @tc.number SUB_Misc_REQUEST_Create_Upload_Callback_0020 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Upload_Callback_0020', 0, async function (done) { + console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0020 is starting-----------------------"); + let config_ = {}; + try { + //@ts-ignore + request.agent.create(globalThis.abilityContext, config_, async (err, task)=>{ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0020 downloadTask: " + task); + try{ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0020 create err: " + JSON.stringify(err)); + expect().assertFail(); + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0020 create success: " + task); + }catch(error){ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0020 create fail: " + JSON.stringify(error)); + } + await request.agent.remove(task.tid); + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0020 end-----------------------"); + done(); + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0020 parameter create fail: " + JSON.stringify(err)); + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0020 end-----------------------"); + expect(err.code).assertEqual(401); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Create_Upload_Promise_0020 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Upload_Promise_0020', 0, async function (done) { + console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Promise_0020 is starting-----------------------"); + let config_ = {}; + try { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0020 downloadTask"); + //@ts-ignore + let task = await request.agent.create(globalThis.abilityContext, config_); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0020 parameter create fail: " + JSON.stringify(err)); + console.info("====>------------------SUB_Misc_REQUEST_Create_Upload_Promise_0020 end-----------------------"); + expect(err.code).assertEqual(401); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Create_Upload_Callback_0050 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Upload_Callback_0050', 0, async function (done) { + console.info("====>---------------SUB_Misc_REQUEST_Create_Upload_Callback_0050 is starting------------------"); + try { + //@ts-ignore + request.agent.create(config, async (err, task)=>{ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0050 downloadTask: " + task); + try{ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0050 create err: " + JSON.stringify(err)); + expect().assertFail(); + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0050 create success: " + task); + }catch(error){ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0050 create fail: " + JSON.stringify(error)); + } + await request.agent.remove(task.tid); + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0050 end-----------------------"); + done(); + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0050 parameter create fail: " + JSON.stringify(err)); + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0050 end-----------------------"); + expect(err.code).assertEqual(401); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Create_Upload_Promise_0050 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Upload_Promise_0050', 0, async function (done) { + console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Promise_0050 is starting-----------------------"); + try { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0050 downloadTask"); + //@ts-ignore + request.agent.create(config); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0050 parameter create fail: " + JSON.stringify(err)); + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Upload_Promise_0050 end-----------------------"); + expect(err.code).assertEqual(401); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Callback_0020 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Callback_0020', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0020 is starting-----------------------"); + try { + let task = await request.agent.create(globalThis.abilityContext, config); + // @ts-ignore + request.agent.remove(task.tid, 'a' ,(err) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0020 remove err: " + JSON.stringify(err)); + expect().assertFail(); + } + expect(task !== undefined).assertEqual(true); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0020 remove success: " + task); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0020 remove fail: " + JSON.stringify(err)); + } + }); + done(); + } catch (error) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0020 catch error: " + JSON.stringify(error)); + console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0020 end-----------------------"); + expect().assertFail(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Promise_0020 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Promise_0020', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0020 is starting-----------------------"); + try { + let task = await request.agent.create(globalThis.abilityContext, config); + //@ts-ignore + await request.agent.remove(task.tid, 'a'); + expect(true).assertEqual(true); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0020 remove success: " + task); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0020 catch error: " + JSON.stringify(err)); + expect().assertFail(); + } + console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0020 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Callback_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Callback_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0030 is starting-----------------------"); + try { + // @ts-ignore + request.agent.remove(true, (err) => { + try { + expect().assertFail(); + }catch (err){ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0030 remove fail: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0030 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0030 err.code: " + err.code); + expect(err.code).assertEqual(401); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Promise_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Promise_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0030 is starting-----------------------"); + try { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0030 remove"); + // @ts-ignore + await request.agent.remove(true); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0030 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0030 err.code: " + err.code); + expect(err.code).assertEqual(401); + done(); + } + console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0030 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Callback_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Callback_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0040 is starting-----------------------"); + try { + // @ts-ignore + request.agent.remove(1, (err) => { + try { + expect().assertFail(); + }catch (err){ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0040 remove fail: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0040 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0040 err.code: " + err.code); + expect(err.code).assertEqual(401); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Promise_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Promise_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0040 is starting-----------------------"); + try { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0040 remove"); + // @ts-ignore + await request.agent.remove(1); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0040 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0040 err.code: " + err.code); + expect(err.code).assertEqual(401); + done(); + } + console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0040 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Callback_0050 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Callback_0050', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0050 is starting-----------------------"); + try { + request.agent.remove('abc', (err) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0050 remove fail: " + JSON.stringify(err)); + expect(err.code).assertEqual(21900006); + done(); + }else{ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0050 remove abc err: " + JSON.stringify(err)); + expect().assertFail(); + } + }catch (err){ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0050 remove catch fail: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0050 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0050 err.code: " + err.code); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Promise_0050 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Promise_0050', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0050 is starting-----------------------"); + try { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0050 remove"); + await request.agent.remove('abc'); + expect().assertFail(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0050 err.message: " + err.message); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0050 err.code: " + err.code); + expect(err.code).assertEqual(21900006); + done(); + } + console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0050 end-----------------------"); + done(); + }); + + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Callback_0060 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Callback_0060', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0060 is starting-----------------------"); + let task = await request.agent.create(globalThis.abilityContext, config); + request.agent.remove(task.tid, (err) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0060 remove err: " + JSON.stringify(err)); + expect().assertFail(); + } + expect(task !== undefined).assertEqual(true); + try { + request.agent.remove(task.tid, (err) => { + if(err){ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0060 remove second err: " + JSON.stringify(err)); + expect(err.code).assertEqual(21900006); + done(); + }else{ + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0060 remove second: " + JSON.stringify(err)); + expect().assertFail(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0060 remove second catch err: " + JSON.stringify(err)); + done(); + } + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0060 remove fail: " + JSON.stringify(err)); + done(); + } + }); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Remove_Upload_Promise_0060 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Remove_Upload_Promise_0060', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0060 is starting-----------------------"); + try { + let task = await request.agent.create(globalThis.abilityContext, config); + await request.agent.remove(task.tid); + await sleep(10); + await request.agent.remove(task.tid); + expect().assertFail(); + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0060 remove success: " + task); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0060 catch error: " + JSON.stringify(err)); + expect(err.code).assertEqual(21900006); + } + console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0060 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Progress_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Progress_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Progress_0010 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_progressCallback = async (pro) => { + task.off('progress', on_progressCallback); + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0010 pro: " + JSON.stringify(pro)); + expect(true).assertTrue(); + await sleep(10); + done(); + } + + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + //@ts-ignore + task.on('progress', on_progressCallback, 'a'); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0010 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Progress_0010 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Progress_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Progress_0010 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0010 on_progressCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + //@ts-ignore + task.off('progress', on_progressCallback, 'a'); + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0010 offProgress success flag: " + flag); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0010 offProgress success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0010 offProgress fail err: " + JSON.stringify(err)); + } + done(); + }, 100) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0010 catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0010 create catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Progress_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Progress_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Progress_0030 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + let arr = new Array(); + let arr1 = [0, 1, 2]; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', (pro1) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0030 pro1: " + JSON.stringify(pro1)); + arr.push(0); + }); + task.on('progress', (pro2) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0030 pro2: " + JSON.stringify(pro2)); + arr.push(1); + }); + task.on('progress', (pro3) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0030 pro3: " + JSON.stringify(pro3)); + arr.push(2); + }); + await task.start(); + await sleep(10); + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0030 task progress on arr: " + JSON.stringify(arr)); + task.off('progress'); + expect(arr.join()).assertEqual(arr1.join()); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Progress_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Progress_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Progress_0030 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + let arr = new Array(); + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_progressCallback1 =async (pro1) => { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0030 pro1: " + JSON.stringify(pro1)); + arr.push(1); + } + let on_progressCallback2 =async (pro2) => { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0030 pro2: " + JSON.stringify(pro2)); + arr.push(2); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback1); + task.on('progress', on_progressCallback2); + task.off('progress'); + await task.start(); + await sleep(10); + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0030 task progress on arr: " + JSON.stringify(arr)); + expect(arr.length).assertEqual(0); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Progress_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Progress_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Progress_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_progressCallback = async (pro) => { + task.off('progress', on_progressCallback); + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0040 pro: " + JSON.stringify(pro)); + expect(true).assertTrue(); + await sleep(10); + done(); + } + + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0040 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Progress_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Progress_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Progress_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Progress_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_progressCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0040 on_progressCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('progress', on_progressCallback); + task.off('progress', on_progressCallback); + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0040 offProgress success flag: " + flag); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 offProgress success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 offProgress fail err: " + JSON.stringify(err)); + } + done(); + }, 100) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0040 catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Progress_0040 create catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Completed_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Completed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Completed_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_completedCallback =async (pro) => { + task.off('completed', on_completedCallback); + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 pro: " + JSON.stringify(pro)); + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + //@ts-ignore + task.on('completed', on_completedCallback, 'a'); + await task.start(); + await sleep(10); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Completed_0010 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Completed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Completed_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_offCompletedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 on_offCompletedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_offCompletedCallback); + //@ts-ignore + task.off('completed', on_offCompletedCallback, 'a'); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 offCompleted success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 offCompleted fail err: " + JSON.stringify(err)); + } + done(); + }, 100) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 create catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Completed_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Completed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Completed_0030 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + let arr = new Array(); + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', (pro1) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0030 pro1: " + JSON.stringify(pro1)); + arr.push(0); + }); + task.on('completed', (pro2) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0030 pro2: " + JSON.stringify(pro2)); + arr.push(1); + }); + task.on('completed', (pro3) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0030 pro3: " + JSON.stringify(pro3)); + arr.push(2); + });; + await task.start(); + await sleep(10); + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0030 task completed on arr: " + arr); + task.off('completed'); + expect(true).assertEqual(true); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Completed_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Completed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Completed_0030 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + let arr = new Array(); + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_offCompletedCallback1 =async (pro1) => { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0030 pro1: " + JSON.stringify(pro1)); + arr.push(1); + } + let on_offCompletedCallback2 =async (pro2) => { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0030 pro2: " + JSON.stringify(pro2)); + arr.push(2); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_offCompletedCallback1); + task.on('completed', on_offCompletedCallback2); + task.off('completed'); + await task.start(); + await sleep(10); + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0030 task completed on arr: " + JSON.stringify(arr)); + expect(arr.length).assertEqual(0); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Completed_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Completed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Completed_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_completedCallback =async (pro) => { + task.off('completed', on_completedCallback); + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 pro: " + JSON.stringify(pro)); + expect(true).assertTrue(); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_completedCallback); + await task.start(); + await sleep(10); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Completed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Completed_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Completed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Completed_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_offCompletedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 on_offCompletedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('completed', on_offCompletedCallback); + task.off('completed', on_offCompletedCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 offCompleted success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 offCompleted fail err: " + JSON.stringify(err)); + } + done(); + }, 100) + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Completed_0040 create catch err: " + JSON.stringify(err)); + await sleep(10); + done(); + } + }); + + /** + * + * @tc.number SUB_Misc_REQUEST_On_Upload_Failed_0010 + * @tc.desc download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Failed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Failed_0010 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_failedCallback = async (pro) => { + task.off('failed', on_failedCallback); + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0010 pro: " + JSON.stringify(pro)); + expect(pro.state).assertEqual(65); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + //@ts-ignore + task.on('failed', on_failedCallback, 'a'); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0010 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Failed_0010 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Failed_0010', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Failed_0010 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_failedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0010 on_failedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0010 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_failedCallback); + //@ts-ignore + task.off('failed', on_failedCallback, 'a'); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0010 offFailed success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0010 offFailed fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 100); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0010 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0010 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Failed_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Failed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Failed_0030 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + let arr = new Array(); + let arr1 = [0, 1, 2]; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', (pro1) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0030 pro1: " + JSON.stringify(pro1)); + arr.push(0); + }); + task.on('failed', (pro2) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0030 pro2: " + JSON.stringify(pro2)); + arr.push(1); + }); + task.on('failed', (pro3) => { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0030 pro3: " + JSON.stringify(pro3)); + arr.push(2); + }); + await task.start(); + await sleep(10); + task.off('failed'); + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0030 task progress on arr: " + JSON.stringify(arr)); + expect(arr.join()).assertEqual(arr1.join()); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Failed_0030 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Failed_0030', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Failed_0030 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + let arr = new Array(); + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_offCompletedCallback1 =async (pro1) => { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0030 pro1: " + JSON.stringify(pro1)); + arr.push(1); + } + let on_offCompletedCallback2 =async (pro2) => { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0030 pro2: " + JSON.stringify(pro2)); + arr.push(2); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0030 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_offCompletedCallback1); + task.on('failed', on_offCompletedCallback2); + task.off('failed'); + await task.start(); + await sleep(10); + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0030 task failed on arr: " + JSON.stringify(arr)); + expect(arr.length).assertEqual(0); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0030 catch err: " + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0030 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_On_Upload_Failed_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_On_Upload_Failed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_On_Upload_Failed_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_failedCallback = async (pro) => { + task.off('failed', on_failedCallback); + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0040 pro: " + JSON.stringify(pro)); + expect(pro.state).assertEqual(65); + done(); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_failedCallback); + await task.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0040 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_On_Upload_Failed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Off_Upload_Failed_0040 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Off_Upload_Failed_0040', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Off_Upload_Failed_0040 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + let flag = true; + request.agent.create(globalThis.abilityContext, config_, async (err, task) => { + let on_failedCallback = (pro) => { + flag = false; + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0040 on_failedCallback flag: " + flag); + } + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0040 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + task.on('failed', on_failedCallback); + task.off('failed', on_failedCallback); + await task.start(); + let t = setTimeout(async () => { + try { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0040 offFailed success flag: " + flag); + clearTimeout(t); + expect(flag).assertTrue(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0040 offFailed fail err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + } + done(); + }, 100); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0040 catch err: " + JSON.stringify(err)); + await request.agent.remove(task.tid); + done(); + } + }); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Off_Upload_Failed_0040 create catch err: " + JSON.stringify(err)); + done(); + } + }); + + /** + * @tc.number SUB_Misc_REQUEST_Create_Upload_Callback_0060 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Upload_Callback_0060', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0060 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + request.agent.create(globalThis.abilityContext, config_, async (err, task1)=>{ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0060 uploadTask: " + task1); + try{ + if(err){ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0060 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + request.agent.create(globalThis.abilityContext, config_, async (err, task2)=>{ + try { + if(err){ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0060 create err: " + JSON.stringify(err)); + expect().assertFail(); + } + await task1.start(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0060 create success: " + JSON.stringify(err)); + expect(err.code).assertEqual(21900007); + await request.agent.remove(task2.tid); + done(); + } + }); + }catch(error){ + console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0060 create fail: " + JSON.stringify(error)); + done(); + } + console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0060 end-----------------------"); + }); + }); + + /** + * @tc.number SUB_Misc_REQUEST_Create_Upload_Promise_0060 + * @tc.desc Starts a upload session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_Misc_REQUEST_Create_Upload_Promise_0060', 0, async function (done) { + console.info("====>-----------------------SUB_Misc_REQUEST_Create_Upload_Promise_0060 is starting-----------------------"); + let config_ = config + config_.mode = request.agent.Mode.FOREGROUND; + try { + let task1 = await request.agent.create(globalThis.abilityContext, config_); + var task2 = await request.agent.create(globalThis.abilityContext, config_); + console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0060 task1 failed"); + await task1.start(); + expect().assertFail(); + done(); + } catch (err) { + console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0060 create catch err: " + JSON.stringify(err)); + await request.agent.remove(task2.tid); + expect(err.code).assertEqual(21900007); + done(); + } + }); + + }) +} \ No newline at end of file -- GitLab