1/* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import request from "@ohos.request"; 16import common from '@ohos.app.ability.common'; 17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; 18 19export default function requestDownloadJSUnit() { 20 describe('requestDownloadJSUnit', () => { 21 console.info('====>################################request download Test start'); 22 let baseContext: common.Context; 23 /** 24 * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. 25 */ 26 beforeAll((done: Function) => { 27 try { 28 let context: common.Context | undefined = AppStorage.get('context'); 29 if (context !== undefined){ 30 baseContext = context; 31 console.info('====>beforeAll requestDownloadJSUnit baseContext:'+JSON.stringify(baseContext)) 32 done(); 33 } else { 34 console.info('====>beforeAll requestDownloadJSUnit baseContext is undefined') 35 done(); 36 } 37 } catch (err) { 38 console.info('====>beforeAll requestDownloadJSUnit catch err:'+JSON.stringify(err)) 39 done(); 40 } 41 }); 42 43 /** 44 * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. 45 */ 46 beforeEach(() => { 47 console.info('====>beforeEach: Prerequisites is executed.'); 48 }); 49 50 /** 51 * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. 52 */ 53 afterEach(() => { 54 console.info('====>afterEach: Test case-level clearance conditions is executed.'); 55 }); 56 57 /** 58 * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. 59 */ 60 afterAll(() => { 61 console.info('====>afterAll: Test suite-level cleanup condition is executed'); 62 }); 63 64 /** 65 * @tc.number SUB_MISC_REQUEST_DOWNLOAD_state_0010 66 * @tc.name T download task 67 * @tc.desc Test requestUploadTest API functionality. 68 * @tc.size MEDIUMTEST 69 * @tc.type : Function 70 * @tc.level : Level 0 71 */ 72 it('SUB_MISC_REQUEST_DOWNLOAD_state_0010', 0, async (done: Function) => { 73 console.info("====>-----------------------SUB_MISC_REQUEST_DOWNLOAD_state_0010 is starting-----------------------"); 74 try { 75 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.INITIALIZED:" + request.agent.State.INITIALIZED); 76 expect(request.agent.State.INITIALIZED).assertEqual(0); 77 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.WAITING:" + request.agent.State.WAITING); 78 expect(request.agent.State.WAITING).assertEqual(16); 79 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.RUNNING:" + request.agent.State.RUNNING); 80 expect(request.agent.State.RUNNING).assertEqual(32); 81 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.RETRYING:" + request.agent.State.RETRYING); 82 expect(request.agent.State.RETRYING).assertEqual(33); 83 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.PAUSED:" + request.agent.State.PAUSED); 84 expect(request.agent.State.PAUSED).assertEqual(48); 85 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.STOPPED:" + request.agent.State.STOPPED); 86 expect(request.agent.State.STOPPED).assertEqual(49); 87 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.COMPLETED:" + request.agent.State.COMPLETED); 88 expect(request.agent.State.COMPLETED).assertEqual(64); 89 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.FAILED:" + request.agent.State.FAILED); 90 expect(request.agent.State.FAILED).assertEqual(65); 91 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 request.agent.State.REMOVED:" + request.agent.State.REMOVED); 92 expect(request.agent.State.REMOVED).assertEqual(80); 93 } catch (err) { 94 console.error("====>SUB_MISC_REQUEST_DOWNLOAD_state_0010 error: " + err); 95 expect().assertFail(); 96 } 97 console.info("====>-----------------------SUB_MISC_REQUEST_DOWNLOAD_state_0010 end-----------------------"); 98 done(); 99 }) 100 101 /** 102 * @tc.number SUB_MISC_REQUEST_DOWNLOAD_faults_0010 103 * @tc.name T download task 104 * @tc.desc Test requestUploadTest API functionality. 105 * @tc.size MEDIUMTEST 106 * @tc.type : Function 107 * @tc.level : Level 0 108 */ 109 it('SUB_MISC_REQUEST_DOWNLOAD_faults_0010', 0, async (done: Function) => { 110 console.info("====>-----------------------SUB_MISC_REQUEST_DOWNLOAD_faults_0010 is starting-----------------------"); 111 try { 112 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.OTHERS: " + request.agent.Faults.OTHERS); 113 expect(request.agent.Faults.OTHERS).assertEqual(255); 114 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.DISCONNECTED: " + request.agent.Faults.DISCONNECTED); 115 expect(request.agent.Faults.DISCONNECTED).assertEqual(0); 116 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.TIMEOUT: " + request.agent.Faults.TIMEOUT); 117 expect(request.agent.Faults.TIMEOUT).assertEqual(16); 118 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.PROTOCOL: " + request.agent.Faults.PROTOCOL); 119 expect(request.agent.Faults.PROTOCOL).assertEqual(32); 120 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.FSIO: " + request.agent.Faults.FSIO); 121 expect(request.agent.Faults.FSIO).assertEqual(64); 122 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.PARAM: " + request.agent.Faults.PARAM); 123 expect(request.agent.Faults.PARAM).assertEqual(48); 124 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.DNS: " + request.agent.Faults.DNS); 125 expect(request.agent.Faults.DNS).assertEqual(80); 126 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.TCP: " + request.agent.Faults.TCP); 127 expect(request.agent.Faults.TCP).assertEqual(96); 128 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.SSL: " + request.agent.Faults.SSL); 129 expect(request.agent.Faults.SSL).assertEqual(112); 130 console.info("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 request.agent.Faults.REDIRECT: " + request.agent.Faults.REDIRECT); 131 expect(request.agent.Faults.REDIRECT).assertEqual(128); 132 } catch (err) { 133 console.error("====>SUB_MISC_REQUEST_DOWNLOAD_faults_0010 error: " + err); 134 expect().assertFail(); 135 } 136 console.info("====>-----------------------SUB_MISC_REQUEST_DOWNLOAD_faults_0010 end-----------------------"); 137 done(); 138 }); 139 140 /** 141 * @tc.number SUB_Misc_REQUEST_Create_Download_Callback_0010 142 * @tc.name SUB_Misc_REQUEST_Create_Download_Callback_0010 143 * @tc.desc Starts a download session. 144 * @tc.size MEDIUMTEST 145 * @tc.type : Function 146 * @tc.level : Level 2 147 */ 148 it('SUB_Misc_REQUEST_Create_Download_Callback_0010', 0, async (done: Function) => { 149 console.info("-----------------------SUB_Misc_REQUEST_Create_Download_Callback_0010 is starting-----------------------"); 150 let config: request.agent.Config = { 151 action: request.agent.Action.DOWNLOAD, 152 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 153 title: 'reeateTest', 154 description: 'XTS download test!', 155 saveas: './SUB_Misc_REQUEST_Create_Download_Callback_0010.txt', 156 network: request.agent.Network.WIFI, 157 mode:request.agent.Mode.BACKGROUND 158 }; 159 160 request.agent.create(baseContext, config, async (err, task)=>{ 161 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0010 downloadTask: " + task); 162 try{ 163 if(err){ 164 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0010 create err: " + JSON.stringify(err)); 165 expect().assertFail(); 166 } 167 expect(task !== undefined).assertEqual(true); 168 expect(typeof(task.config) === "object").assertEqual(true); 169 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0010 create success: " + task); 170 }catch(error){ 171 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0010 create fail: " + JSON.stringify(error)); 172 } 173 await request.agent.remove(task.tid); 174 console.info("-----------------------SUB_Misc_REQUEST_Create_Download_Callback_0010 end-----------------------"); 175 done(); 176 }); 177 }); 178 179 /** 180 * @tc.number SUB_Misc_REQUEST_Create_Download_Promise_0010 181 * @tc.name SUB_Misc_REQUEST_Create_Download_Promise_0010 182 * @tc.desc Starts a download session. 183 * @tc.size MEDIUMTEST 184 * @tc.type : Function 185 * @tc.level : Level 2 186 */ 187 it('SUB_Misc_REQUEST_Create_Download_Promise_0010', 0, async (done: Function) => { 188 console.info("-----------------------SUB_Misc_REQUEST_Create_Download_Promise_0010 is starting-----------------------"); 189 let config: request.agent.Config = { 190 action: request.agent.Action.DOWNLOAD, 191 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 192 title: 'reeateTest', 193 description: 'XTS download test!', 194 saveas: './SUB_Misc_REQUEST_Create_Download_Promise_0010.txt', 195 network: request.agent.Network.WIFI, 196 mode:request.agent.Mode.BACKGROUND 197 }; 198 let task: request.agent.Task | undefined; 199 try { 200 task = await request.agent.create(baseContext, config); 201 expect(task !== undefined).assertEqual(true); 202 await request.agent.remove(task.tid); 203 console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0010 create success: " + task); 204 } catch (err) { 205 console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0010 catch error: " + JSON.stringify(err)); 206 if(task !== undefined){ 207 await request.agent.remove(task.tid); 208 } 209 expect().assertFail(); 210 } 211 console.info("-----------------------SUB_Misc_REQUEST_Create_Download_Promise_0010 end-----------------------"); 212 done(); 213 }); 214 215 /** 216 * @tc.number SUB_Misc_REQUEST_Remove_Download_Callback_0010 217 * @tc.name SUB_Misc_REQUEST_Remove_Download_Callback_0010 218 * @tc.desc Delete the download task. 219 * @tc.size MEDIUMTEST 220 * @tc.type : Function 221 * @tc.level : Level 2 222 */ 223 it('SUB_Misc_REQUEST_Remove_Download_Callback_0010', 0, async (done: Function) => { 224 console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Callback_0010 is starting-----------------------"); 225 let config: request.agent.Config = { 226 action: request.agent.Action.DOWNLOAD, 227 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 228 title: 'reeateTest', 229 description: 'XTS download test!', 230 saveas: './SUB_Misc_REQUEST_Remove_Download_Callback_0010.txt', 231 network: request.agent.Network.ANY, 232 }; 233 234 try { 235 let task = await request.agent.create(baseContext, config); 236 request.agent.remove(task.tid, err => { 237 try { 238 if(err){ 239 console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0010 remove err: " + JSON.stringify(err)); 240 expect().assertFail(); 241 } 242 expect(task !== undefined).assertEqual(true); 243 console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0010 remove success: " + task); 244 } catch (err) { 245 console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0010 remove fail: " + JSON.stringify(err)); 246 } 247 }); 248 done(); 249 } catch (error) { 250 console.info("====>SUB_Misc_REQUEST_Remove_Download_Callback_0010 catch error: " + JSON.stringify(error)); 251 expect().assertFail(); 252 } 253 console.info("-----------------------SUB_Misc_REQUEST_Remove_Download_Callback_0010 end-----------------------"); 254 }); 255 256 /** 257 * @tc.number SUB_Misc_REQUEST_Remove_Download_Promise_0010 258 * @tc.name SUB_Misc_REQUEST_Remove_Download_Promise_0010 259 * @tc.desc Delete the download task. 260 * @tc.size MEDIUMTEST 261 * @tc.type : Function 262 * @tc.level : Level 2 263 */ 264 it('SUB_Misc_REQUEST_Remove_Download_Promise_0010', 0, async (done: Function) => { 265 console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Download_Promise_0010 is starting-----------------------"); 266 let config: request.agent.Config = { 267 action: request.agent.Action.DOWNLOAD, 268 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 269 title: 'reeateTest', 270 description: 'XTS download test!', 271 saveas: './SUB_Misc_REQUEST_Remove_Download_Promise_0010.txt', 272 network: request.agent.Network.ANY, 273 }; 274 275 try { 276 let task = await request.agent.create(baseContext, config); 277 await request.agent.remove(task.tid); 278 expect(true).assertEqual(true); 279 console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0010 remove success: " + task); 280 } catch (err) { 281 console.info("====>SUB_Misc_REQUEST_Remove_Download_Promise_0010 catch error: " + JSON.stringify(err)); 282 expect().assertFail(); 283 } 284 console.info("-----------------------SUB_Misc_REQUEST_Remove_Download_Promise_0010 end-----------------------"); 285 done(); 286 }); 287 288 /** 289 * @tc.number SUB_Misc_REQUEST_Start_Download_Callback_0010 290 * @tc.name SUB_Misc_REQUEST_Start_Download_Callback_0010 291 * @tc.desc Suspend the download task 292 * @tc.size MEDIUMTEST 293 * @tc.type : Function 294 * @tc.level : Level 2 295 */ 296 it('SUB_Misc_REQUEST_Start_Download_Callback_0010', 0, async (done: Function) => { 297 console.info("====>-----------------------SUB_Misc_REQUEST_Start_Download_Callback_0010 is starting-----------------------"); 298 let config: request.agent.Config = { 299 action: request.agent.Action.DOWNLOAD, 300 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 301 title: 'reeateTest', 302 description: 'XTS download test!', 303 saveas: './SUB_Misc_REQUEST_Start_Download_Callback_0010.txt', 304 network: request.agent.Network.ANY, 305 }; 306 307 request.agent.create(baseContext, config, async (err, task)=>{ 308 console.info("====>SUB_Misc_REQUEST_Start_Download_Callback_0010 downloadTask: " + task); 309 task.start(async err => { 310 try{ 311 if(err){ 312 console.info("====>SUB_Misc_REQUEST_Start_Download_Callback_0010 download start err: " + JSON.stringify(err)); 313 expect().assertFail(); 314 } 315 expect(true).assertEqual(true); 316 console.info("====>SUB_Misc_REQUEST_Start_Download_Callback_0010 download start success: " + task); 317 }catch(err){ 318 console.info("====>SUB_Misc_REQUEST_Start_Download_Callback_0010 catch err: " + JSON.stringify(err)); 319 await request.agent.remove(task.tid); 320 } 321 await request.agent.remove(task.tid); 322 console.info("-----------------------SUB_Misc_REQUEST_Start_Download_Callback_0010 end-----------------------"); 323 done(); 324 }) 325 }); 326 }); 327 328 /** 329 * @tc.number SUB_Misc_REQUEST_Start_Download_Promise_0010 330 * @tc.name SUB_Misc_REQUEST_Start_Download_Promise_0010 331 * @tc.desc Suspend the download task 332 * @tc.size MEDIUMTEST 333 * @tc.type : Function 334 * @tc.level : Level 2 335 */ 336 it('SUB_Misc_REQUEST_Start_Download_Promise_0010', 0, async (done: Function) => { 337 console.info("====>-----------------------SUB_Misc_REQUEST_Start_Download_Promise_0010 is starting-----------------------"); 338 let config: request.agent.Config = { 339 action: request.agent.Action.DOWNLOAD, 340 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 341 title: 'reeateTest', 342 description: 'XTS download test!', 343 saveas: './SUB_Misc_REQUEST_Start_Download_Promise_0010.txt', 344 network: request.agent.Network.ANY, 345 }; 346 347 let task: request.agent.Task| undefined; 348 try { 349 task = await request.agent.create(baseContext, config); 350 await task.start(); 351 expect(true).assertEqual(true); 352 await request.agent.remove(task.tid); 353 console.info("====>SUB_Misc_REQUEST_Start_Download_Promise_0010 download start success: " + task); 354 } catch (err) { 355 console.info("====>SUB_Misc_REQUEST_Start_Download_Promise_0010 download start err: " + JSON.stringify(err)); 356 if(task !== undefined){ 357 await request.agent.remove(task.tid); 358 } 359 expect().assertFail(); 360 } 361 console.info("-----------------------SUB_Misc_REQUEST_Start_Download_Promise_0010 end-----------------------"); 362 done(); 363 }); 364 365 /** 366 * @tc.number SUB_Misc_REQUEST_Pause_Download_Callback_0010 367 * @tc.name SUB_Misc_REQUEST_Pause_Download_Callback_0010 368 * @tc.desc Restore the download task 369 * @tc.size MEDIUMTEST 370 * @tc.type : Function 371 * @tc.level : Level 2 372 */ 373 it('SUB_Misc_REQUEST_Pause_Download_Callback_0010', 0, async (done: Function) => { 374 console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Download_Callback_0010 is starting-----------------------"); 375 let config: request.agent.Config = { 376 action: request.agent.Action.DOWNLOAD, 377 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 378 title: 'reeateTest', 379 description: 'XTS download test!', 380 saveas: './SUB_Misc_REQUEST_Pause_Download_Callback_0010.txt', 381 network: request.agent.Network.WIFI, 382 }; 383 384 request.agent.create(baseContext, config, async (err, task)=>{ 385 console.info("====>SUB_Misc_REQUEST_Pause_Download_Callback_0010 downloadTask: " + task); 386 task.start(err => { 387 console.info("====>SUB_Misc_REQUEST_Pause_Download_Callback_0010 download start: " + JSON.stringify(err)); 388 task.pause(async err => { 389 try{ 390 if(err){ 391 console.info("====>SUB_Misc_REQUEST_Pause_Download_Callback_0010 download pause err: " + JSON.stringify(err)); 392 expect().assertFail(); 393 } 394 expect(true).assertEqual(true); 395 console.info("====>SUB_Misc_REQUEST_Pause_Download_Callback_0010 download pause success: " + task); 396 }catch(err){ 397 console.info("====>SUB_Misc_REQUEST_Pause_Download_Callback_0010 catch err: " + JSON.stringify(err)); 398 } 399 await request.agent.remove(task.tid); 400 console.info("-----------------------SUB_Misc_REQUEST_Pause_Download_Callback_0010 end-----------------------"); 401 done(); 402 }) 403 }) 404 }); 405 }); 406 407 /** 408 * @tc.number SUB_Misc_REQUEST_Pause_Download_Promise_0010 409 * @tc.name SUB_Misc_REQUEST_Pause_Download_Promise_0010 410 * @tc.desc Restore the download task 411 * @tc.size MEDIUMTEST 412 * @tc.type : Function 413 * @tc.level : Level 2 414 */ 415 it('SUB_Misc_REQUEST_Pause_Download_Promise_0010', 0, async (done: Function) => { 416 console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Download_Promise_0010 is starting-----------------------"); 417 let config: request.agent.Config = { 418 action: request.agent.Action.DOWNLOAD, 419 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 420 title: 'reeateTest', 421 description: 'XTS download test!', 422 saveas: './SUB_Misc_REQUEST_Pause_Download_Promise_0010.txt', 423 network: request.agent.Network.WIFI, 424 }; 425 426 let task = await request.agent.create(baseContext, config); 427 task.start(async err => { 428 try { 429 console.info("====>SUB_Misc_REQUEST_Pause_Download_Promise_0010 download start: " + JSON.stringify(err)); 430 await task.pause(); 431 expect(true).assertEqual(true); 432 await request.agent.remove(task.tid); 433 console.info("====>SUB_Misc_REQUEST_Pause_Download_Promise_0010 download pause success: " + task); 434 done(); 435 } catch (err) { 436 console.info("====>SUB_Misc_REQUEST_Pause_Download_Promise_0010 download pause err: " + JSON.stringify(err)); 437 await request.agent.remove(task.tid); 438 expect().assertFail(); 439 done(); 440 } 441 }) 442 }); 443 444 /** 445 * @tc.number SUB_Misc_REQUEST_Resume_Download_Callback_0010 446 * @tc.name SUB_Misc_REQUEST_Resume_Download_Callback_0010 447 * @tc.desc Get the download task info 448 * @tc.size MEDIUMTEST 449 * @tc.type : Function 450 * @tc.level : Level 2 451 */ 452 it('SUB_Misc_REQUEST_Resume_Download_Callback_0010', 0, async (done: Function) => { 453 console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Download_Callback_0010 is starting-----------------------"); 454 let config: request.agent.Config = { 455 action: request.agent.Action.DOWNLOAD, 456 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 457 title: 'reeateTest', 458 description: 'XTS download test!', 459 saveas: './SUB_Misc_REQUEST_Resume_Download_Callback_0010.txt', 460 network: request.agent.Network.WIFI, 461 }; 462 463 request.agent.create(baseContext, config, async (err, task)=>{ 464 console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 downloadTask: " + task); 465 task.start(err => { 466 console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 start: " + JSON.stringify(err)); 467 task.pause(err => { 468 console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 pause: " + JSON.stringify(err)); 469 task.resume(async err => { 470 try{ 471 if(err){ 472 console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 download resume err: " + JSON.stringify(err)); 473 expect().assertFail(); 474 } 475 expect(true).assertEqual(true); 476 console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 download resume success: " + task); 477 }catch(err){ 478 console.info("====>SUB_Misc_REQUEST_Resume_Download_Callback_0010 catch err: " + JSON.stringify(err)); 479 } 480 await request.agent.remove(task.tid); 481 console.info("-----------------------SUB_Misc_REQUEST_Resume_Download_Callback_0010 end-----------------------"); 482 done(); 483 }) 484 }) 485 }) 486 }); 487 }); 488 489 /** 490 * @tc.number SUB_Misc_REQUEST_Resume_Download_Promise_0010 491 * @tc.name SUB_Misc_REQUEST_Resume_Download_Promise_0010 492 * @tc.desc Get the download task info 493 * @tc.size MEDIUMTEST 494 * @tc.type : Function 495 * @tc.level : Level 2 496 */ 497 it('SUB_Misc_REQUEST_Resume_Download_Promise_0010', 0, async (done: Function) => { 498 console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Download_Promise_0010 is starting-----------------------"); 499 let config: request.agent.Config = { 500 action: request.agent.Action.DOWNLOAD, 501 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 502 title: 'reeateTest', 503 description: 'XTS download test!', 504 saveas: './SUB_Misc_REQUEST_Resume_Download_Promise_0010.txt', 505 network: request.agent.Network.WIFI, 506 }; 507 508 let task = await request.agent.create(baseContext, config); 509 task.start(err => { 510 console.info("====>SUB_Misc_REQUEST_Resume_Download_Promise_0010 start: " + JSON.stringify(err)); 511 task.pause(async err => { 512 console.info("====>SUB_Misc_REQUEST_Resume_Download_Promise_0010 pause: " + JSON.stringify(err)); 513 try { 514 await task.resume(); 515 expect(true).assertEqual(true); 516 await request.agent.remove(task.tid); 517 console.info("====>SUB_Misc_REQUEST_Resume_Download_Promise_0010 download resume success: " + task); 518 done(); 519 } catch (err) { 520 console.info("====>SUB_Misc_REQUEST_Resume_Download_Promise_0010 download resume err: " + JSON.stringify(err)); 521 await request.agent.remove(task.tid); 522 expect().assertFail(); 523 done(); 524 } 525 }); 526 }); 527 }); 528 529 /** 530 * @tc.number SUB_Misc_REQUEST_Stop_Download_Callback_0010 531 * @tc.name SUB_Misc_REQUEST_Stop_Download_Callback_0010 532 * @tc.desc Get mimetype of the download task 533 * @tc.size MEDIUMTEST 534 * @tc.type : Function 535 * @tc.level : Level 2 536 */ 537 it('SUB_Misc_REQUEST_Stop_Download_Callback_0010', 0, async (done: Function) => { 538 console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Download_Callback_0010 is starting-----------------------"); 539 let config: request.agent.Config = { 540 action: request.agent.Action.DOWNLOAD, 541 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 542 title: 'reeateTest', 543 description: 'XTS download test!', 544 saveas: './SUB_Misc_REQUEST_Stop_Download_Callback_0010.txt', 545 network: request.agent.Network.WIFI, 546 }; 547 548 request.agent.create(baseContext, config, async (err, task)=>{ 549 console.info("====>SUB_Misc_REQUEST_Stop_Download_Callback_0010 downloadTask: " + task); 550 task.start(err => { 551 console.info("====>SUB_Misc_REQUEST_Stop_Download_Callback_0010 start: " + JSON.stringify(err)); 552 task.stop(async err => { 553 try{ 554 if(err){ 555 console.info("====>SUB_Misc_REQUEST_Stop_Download_Callback_0010 download stop err: " + JSON.stringify(err)); 556 expect().assertFail(); 557 } 558 expect(true).assertEqual(true); 559 console.info("====>SUB_Misc_REQUEST_Stop_Download_Callback_0010 download stop success: " + task); 560 }catch(err){ 561 console.info("====>SUB_Misc_REQUEST_Stop_Download_Callback_0010 catch err: " + JSON.stringify(err)); 562 await request.agent.remove(task.tid); 563 } 564 console.info("-----------------------SUB_Misc_REQUEST_Stop_Download_Callback_0010 end-----------------------"); 565 done(); 566 }) 567 }) 568 }); 569 }); 570 571 /** 572 * @tc.number SUB_Misc_REQUEST_Stop_Download_Promise_0010 573 * @tc.name SUB_Misc_REQUEST_Stop_Download_Promise_0010 574 * @tc.desc download task 575 * @tc.size MEDIUMTEST 576 * @tc.type : Function 577 * @tc.level : Level 2 578 */ 579 it('SUB_Misc_REQUEST_Stop_Download_Promise_0010', 0, async (done: Function) => { 580 console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Download_Promise_0010 is starting-----------------------"); 581 let config: request.agent.Config = { 582 action: request.agent.Action.DOWNLOAD, 583 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 584 title: 'reeateTest', 585 description: 'XTS download test!', 586 saveas: './SUB_Misc_REQUEST_Stop_Download_Promise_0010.txt', 587 network: request.agent.Network.WIFI, 588 }; 589 590 let task = await request.agent.create(baseContext, config); 591 task.start(async err => { 592 console.info("====>SUB_Misc_REQUEST_Stop_Download_Promise_0010 start: " + JSON.stringify(err)); 593 try { 594 await task.stop(); 595 expect(true).assertEqual(true); 596 console.info("====>SUB_Misc_REQUEST_Stop_Download_Promise_0010 download stop success: " + task); 597 done(); 598 } catch (err) { 599 console.info("====>SUB_Misc_REQUEST_Stop_Download_Promise_0010 download stop err: " + JSON.stringify(err)); 600 expect().assertFail(); 601 done(); 602 } 603 }) 604 }); 605 606 /** 607 * @tc.number SUB_Misc_REQUEST_On_Download_Progress_0040 608 * @tc.name SUB_Misc_REQUEST_On_Download_Progress_0040 609 * @tc.desc download task 610 * @tc.size MEDIUMTEST 611 * @tc.type : Function 612 * @tc.level : Level 2 613 */ 614 it('SUB_Misc_REQUEST_On_Download_Progress_0040', 0, async (done: Function) => { 615 console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Progress_0040 is starting-----------------------"); 616 let config: request.agent.Config = { 617 action: request.agent.Action.DOWNLOAD, 618 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 619 title: 'reeateTest', 620 description: 'XTS download test!', 621 saveas: './SUB_Misc_REQUEST_On_Download_Progress_0040.txt', 622 network: request.agent.Network.WIFI, 623 overwrite: true, 624 mode:request.agent.Mode.FOREGROUND 625 }; 626 627 try { 628 request.agent.create(baseContext, config, async (err, task) => { 629 let on_progressCallback = async (pro: request.agent.Progress) => { 630 task.off('progress', on_progressCallback); 631 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.state: " + pro.state); 632 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.index: " + pro.index); 633 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.processed: " + pro.processed); 634 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.size: " + pro.sizes); 635 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 pro.extras: " + JSON.stringify(pro.extras)); 636 try { 637 await request.agent.remove(task.tid); 638 } catch (err) { 639 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 task has complete: " + JSON.stringify(task.tid)); 640 } 641 expect(true).assertTrue(); 642 done(); 643 } 644 try { 645 if(err){ 646 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 create err: " + JSON.stringify(err)); 647 expect().assertFail(); 648 } 649 task.on('progress', on_progressCallback); 650 await task.start(); 651 } catch (err) { 652 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 catch err: " + JSON.stringify(err)); 653 done(); 654 } 655 }); 656 } catch (err) { 657 console.info("====>SUB_Misc_REQUEST_On_Download_Progress_0040 create catch err: " + JSON.stringify(err)); 658 done(); 659 } 660 }); 661 662 /** 663 * @tc.number SUB_Misc_REQUEST_Off_Download_Progress_0040 664 * @tc.name SUB_Misc_REQUEST_Off_Download_Progress_0040 665 * @tc.desc download task 666 * @tc.size MEDIUMTEST 667 * @tc.type : Function 668 * @tc.level : Level 2 669 */ 670 it('SUB_Misc_REQUEST_Off_Download_Progress_0040', 0, async (done: Function) => { 671 console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Progress_0040 is starting-----------------------"); 672 let config: request.agent.Config = { 673 action: request.agent.Action.DOWNLOAD, 674 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 675 title: 'reeateTest', 676 description: 'XTS download test!', 677 saveas: './SUB_Misc_REQUEST_Off_Download_Progress_0040.txt', 678 network: request.agent.Network.WIFI, 679 overwrite: true, 680 mode:request.agent.Mode.FOREGROUND 681 }; 682 683 try { 684 let flag = true; 685 request.agent.create(baseContext, config, async (err, task) => { 686 let on_progressCallback = (pro: request.agent.Progress) => { 687 flag = false; 688 console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 on_progressCallback flag: " + flag); 689 } 690 try { 691 if(err){ 692 console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 create err: " + JSON.stringify(err)); 693 expect().assertFail(); 694 } 695 task.on('progress', on_progressCallback); 696 task.off('progress', on_progressCallback); 697 await task.start(); 698 let t = setTimeout(async () => { 699 try { 700 clearTimeout(t); 701 expect(flag).assertTrue(); 702 console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 offProgress success flag: " + flag); 703 } catch (err) { 704 console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 offProgress fail err: " + JSON.stringify(err)); 705 await request.agent.remove(task.tid); 706 } 707 done(); 708 }, 3000) 709 } catch (err) { 710 console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 catch err: " + JSON.stringify(err)); 711 await request.agent.remove(task.tid); 712 done(); 713 } 714 }); 715 } catch (err) { 716 console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0040 create catch err: " + JSON.stringify(err)); 717 done(); 718 } 719 }); 720 721 /** 722 * @tc.number SUB_Misc_REQUEST_On_Download_Completed_0040 723 * @tc.name SUB_Misc_REQUEST_On_Download_Completed_0040 724 * @tc.desc download task 725 * @tc.size MEDIUMTEST 726 * @tc.type : Function 727 * @tc.level : Level 2 728 */ 729 it('SUB_Misc_REQUEST_On_Download_Completed_0040', 0, async (done: Function) => { 730 console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Completed_0040 is starting-----------------------"); 731 let config: request.agent.Config = { 732 action: request.agent.Action.DOWNLOAD, 733 url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', 734 title: 'reeateTest', 735 description: 'XTS download test!', 736 saveas: './SUB_Misc_REQUEST_On_Download_Completed_0040.txt', 737 network: request.agent.Network.WIFI, 738 overwrite: true, 739 mode:request.agent.Mode.FOREGROUND 740 }; 741 try { 742 request.agent.create(baseContext, config, async (err, task) => { 743 let on_completedCallback = async (pro: request.agent.Progress) => { 744 task.off('completed', on_completedCallback); 745 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.state: " + pro.state); 746 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.index: " + pro.index); 747 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.processed: " + pro.processed); 748 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.sizes: " + pro.sizes); 749 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 pro.extras: " + JSON.stringify(pro.extras)); 750 expect(true).assertTrue(); 751 done(); 752 } 753 try { 754 if(err){ 755 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 create err: " + JSON.stringify(err)); 756 expect().assertFail(); 757 } 758 task.on('completed', on_completedCallback); 759 await task.start(); 760 } catch (err) { 761 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 catch err: " + JSON.stringify(err)); 762 await request.agent.remove(task.tid); 763 done(); 764 } 765 }); 766 } catch (err) { 767 console.info("====>SUB_Misc_REQUEST_On_Download_Completed_0040 create catch err: " + JSON.stringify(err)); 768 done(); 769 } 770 }); 771 772 /** 773 * @tc.number SUB_Misc_REQUEST_Off_Download_Completed_0040 774 * @tc.name SUB_Misc_REQUEST_Off_Download_Completed_0040 775 * @tc.desc download task 776 * @tc.size MEDIUMTEST 777 * @tc.type : Function 778 * @tc.level : Level 2 779 */ 780 it('SUB_Misc_REQUEST_Off_Download_Completed_0040', 0, async (done: Function) => { 781 console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Completed_0040 is starting-----------------------"); 782 let config: request.agent.Config = { 783 action: request.agent.Action.DOWNLOAD, 784 url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', 785 title: 'reeateTest', 786 description: 'XTS download test!', 787 saveas: './SUB_Misc_REQUEST_Off_Download_Completed_0040.txt', 788 network: request.agent.Network.WIFI, 789 overwrite: true, 790 mode:request.agent.Mode.FOREGROUND 791 }; 792 793 try { 794 let flag = true; 795 request.agent.create(baseContext, config, async (err, task) => { 796 let on_offCompletedCallback = (pro: request.agent.Progress) => { 797 flag = false; 798 console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 on_offCompletedCallback flag: " + flag); 799 } 800 try { 801 if(err){ 802 console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 create err: " + JSON.stringify(err)); 803 expect().assertFail(); 804 } 805 task.on('completed', on_offCompletedCallback); 806 task.off('completed', on_offCompletedCallback); 807 await task.start(); 808 let t = setTimeout(async () => { 809 try { 810 clearTimeout(t); 811 expect(flag).assertTrue(); 812 console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 offCompleted success flag: " + flag); 813 } catch (err) { 814 console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 offCompleted fail err: " + JSON.stringify(err)); 815 await request.agent.remove(task.tid); 816 } 817 done(); 818 }, 3000) 819 } catch (err) { 820 console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 catch err: " + JSON.stringify(err)); 821 await request.agent.remove(task.tid); 822 done(); 823 } 824 }); 825 } catch (err) { 826 console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0040 create catch err: " + JSON.stringify(err)); 827 done(); 828 } 829 }); 830 831 /** 832 * @tc.number SUB_Misc_REQUEST_On_Download_Failed_0040 833 * @tc.name SUB_Misc_REQUEST_On_Download_Failed_0040 834 * @tc.desc download task 835 * @tc.size MEDIUMTEST 836 * @tc.type : Function 837 * @tc.level : Level 2 838 */ 839 it('SUB_Misc_REQUEST_On_Download_Failed_0040', 0, async (done: Function) => { 840 console.info("====>-----------------------SUB_Misc_REQUEST_On_Download_Failed_0040 is starting-----------------------"); 841 let config: request.agent.Config = { 842 action: request.agent.Action.DOWNLOAD, 843 url: 'https://gitee.com/xxxxxxxxxxx/test.apk', 844 title: 'reeateTest', 845 description: 'XTS download test!', 846 saveas: './SUB_Misc_REQUEST_On_Download_Failed_0040.txt', 847 network: request.agent.Network.WIFI, 848 overwrite: true, 849 mode:request.agent.Mode.FOREGROUND 850 }; 851 try { 852 request.agent.create(baseContext, config, async (err, task) => { 853 let on_failedCallback = async (pro: request.agent.Progress) => { 854 task.off('failed', on_failedCallback); 855 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.state: " + pro.state); 856 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.index: " + pro.index); 857 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.processed: " + pro.processed); 858 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.size: " + pro.sizes); 859 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 pro.extras: " + JSON.stringify(pro.extras)); 860 expect(true).assertTrue(); 861 done(); 862 } 863 try { 864 if(err){ 865 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 create err: " + JSON.stringify(err)); 866 expect().assertFail(); 867 } 868 task.on('failed', on_failedCallback); 869 await task.start(); 870 } catch (err) { 871 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 catch err: " + JSON.stringify(err)); 872 await request.agent.remove(task.tid); 873 done(); 874 } 875 }); 876 } catch (err) { 877 console.info("====>SUB_Misc_REQUEST_On_Download_Failed_0040 create catch err: " + JSON.stringify(err)); 878 done(); 879 } 880 }); 881 882 /** 883 * @tc.number SUB_Misc_REQUEST_Off_Download_Failed_0040 884 * @tc.name SUB_Misc_REQUEST_Off_Download_Failed_0040 885 * @tc.desc download task 886 * @tc.size MEDIUMTEST 887 * @tc.type : Function 888 * @tc.level : Level 2 889 */ 890 it('SUB_Misc_REQUEST_Off_Download_Failed_0040', 0, async (done: Function) => { 891 console.info("====>-----------------------SUB_Misc_REQUEST_Off_Download_Failed_0040 is starting-----------------------"); 892 let config: request.agent.Config = { 893 action: request.agent.Action.DOWNLOAD, 894 url: 'https://gitee.com/xxxxxxxxxxx/test.apk', 895 title: 'reeateTest', 896 description: 'XTS download test!', 897 saveas: './SUB_Misc_REQUEST_Off_Download_Failed_0040.txt', 898 network: request.agent.Network.WIFI, 899 overwrite: true, 900 mode:request.agent.Mode.FOREGROUND 901 }; 902 903 try { 904 let flag = true; 905 request.agent.create(baseContext, config, async (err, task) => { 906 let on_failedCallback = (pro: request.agent.Progress) => { 907 flag = false; 908 console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 on_failedCallback flag: " + flag); 909 } 910 try { 911 if(err){ 912 console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 create err: " + JSON.stringify(err)); 913 expect().assertFail(); 914 } 915 task.on('failed', on_failedCallback); 916 task.off('failed', on_failedCallback); 917 await task.start(); 918 let t = setTimeout(async () => { 919 try { 920 clearTimeout(t); 921 expect(flag).assertTrue(); 922 console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 offFailed success flag: " + flag); 923 } catch (err) { 924 console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 offFailed fail err: " + JSON.stringify(err)); 925 await request.agent.remove(task.tid); 926 } 927 done(); 928 }, 3000) 929 } catch (err) { 930 console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 catch err: " + JSON.stringify(err)); 931 await request.agent.remove(task.tid); 932 done(); 933 } 934 }); 935 } catch (err) { 936 console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0040 create catch err: " + JSON.stringify(err)); 937 done(); 938 } 939 }); 940 941 /** 942 * @tc.number SUB_Misc_REQUEST_Create_Download_Callback_0060 943 * @tc.name SUB_Misc_REQUEST_Create_Download_Callback_0060 944 * @tc.desc Suspend the download task 945 * @tc.size MEDIUMTEST 946 * @tc.type : Function 947 * @tc.level : Level 2 948 */ 949 it('SUB_Misc_REQUEST_Create_Download_Callback_0060', 0, async (done: Function) => { 950 console.info("====>-----------------------SUB_Misc_REQUEST_Create_Download_Callback_0060 is starting-----------------------"); 951 let config: request.agent.Config = { 952 action: request.agent.Action.DOWNLOAD, 953 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 954 title: 'reeateTest', 955 description: 'XTS download test!', 956 saveas: './SUB_Misc_REQUEST_Create_Download_Callback_0060.txt', 957 overwrite: true, 958 network: request.agent.Network.WIFI, 959 mode:request.agent.Mode.FOREGROUND 960 }; 961 request.agent.create(baseContext, config, async (err, task1)=>{ 962 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 uploadTask: " + task1); 963 try{ 964 if(err){ 965 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create err: " + JSON.stringify(err)); 966 expect().assertFail(); 967 } 968 request.agent.create(baseContext, config, async (err, task2)=>{ 969 try { 970 if(err){ 971 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create err: " + JSON.stringify(err)); 972 expect().assertFail(); 973 } 974 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 task2 create success"); 975 await task1.start(); 976 await request.agent.remove(task1.tid); 977 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 task1 remove"); 978 await request.agent.remove(task2.tid); 979 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 task2 remove"); 980 expect(true).assertTrue() 981 done(); 982 } catch (err) { 983 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create success: " + JSON.stringify(err)); 984 done(); 985 } 986 }); 987 }catch(error){ 988 console.info("====>SUB_Misc_REQUEST_Create_Download_Callback_0060 create fail: " + JSON.stringify(error)); 989 done(); 990 } 991 console.info("-----------------------SUB_Misc_REQUEST_Create_Download_Callback_0060 end-----------------------"); 992 }); 993 }); 994 995 /** 996 * @tc.number SUB_Misc_REQUEST_Create_Download_Promise_0060 997 * @tc.name SUB_Misc_REQUEST_Create_Download_Promise_0060 998 * @tc.desc Suspend the download task 999 * @tc.size MEDIUMTEST 1000 * @tc.type : Function 1001 * @tc.level : Level 2 1002 */ 1003 it('SUB_Misc_REQUEST_Create_Download_Promise_0060', 0, async (done: Function) => { 1004 console.info("====>-----------------------SUB_Misc_REQUEST_Create_Download_Promise_0060 is starting-----------------------"); 1005 let config: request.agent.Config = { 1006 action: request.agent.Action.DOWNLOAD, 1007 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 1008 title: 'reeateTest', 1009 description: 'XTS download test!', 1010 saveas: './SUB_Misc_REQUEST_Create_Download_Promise_0060.txt', 1011 overwrite: true, 1012 network: request.agent.Network.WIFI, 1013 mode:request.agent.Mode.FOREGROUND 1014 }; 1015 1016 try { 1017 let task1 = await request.agent.create(baseContext, config); 1018 let task2 = await request.agent.create(baseContext, config); 1019 console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0060 task1 and task2 create success"); 1020 await request.agent.remove(task1.tid); 1021 console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0060 task1 remove"); 1022 await request.agent.remove(task2.tid); 1023 console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0060 task2 remove"); 1024 expect(true).assertTrue() 1025 done(); 1026 } catch (err) { 1027 console.info("====>SUB_Misc_REQUEST_Create_Download_Promise_0060 create catch err: " + JSON.stringify(err)); 1028 expect().assertFail(); 1029 done(); 1030 } 1031 }); 1032 1033 /** 1034 * @tc.number SUB_REQUEST_Agent_GetTask_Promise_0100 1035 * @tc.name SUB_REQUEST_Agent_GetTask_Promise_0100 1036 * @tc.desc request.agent.getTask(),Promise 1037 * @tc.size MEDIUMTEST 1038 * @tc.type : Function 1039 * @tc.level : Level 2 1040 */ 1041 it('SUB_REQUEST_Agent_GetTask_Promise_0100', 0, async (done: Function) => { 1042 console.info("====>-----------------------SUB_REQUEST_Agent_GetTask_Promise_0100 is starting-----------------------"); 1043 let config: request.agent.Config = { 1044 action: request.agent.Action.DOWNLOAD, 1045 url: 'https://gitee.com/murphy1984/download/releases/download/V1/test.hap', 1046 title: 'reeateTest', 1047 description: 'XTS download test!', 1048 saveas: './SUB_REQUEST_Agent_GetTask_Promise_0100.txt', 1049 network: request.agent.Network.ANY, 1050 priority:0, 1051 }; 1052 1053 try { 1054 let task = await request.agent.create(baseContext, config); 1055 let task1 = await request.agent.getTask(baseContext, task.tid); 1056 console.info("====>SUB_REQUEST_Agent_GetTask_Promise_0100 Succeeded in querying a download task: " + JSON.stringify(task)); 1057 console.info("====>SUB_REQUEST_Agent_GetTask_Promise_0100 Succeeded in querying a download task1: " + JSON.stringify(task1)); 1058 let taskStr1 = JSON.stringify(task); 1059 let taskStr2 = JSON.stringify(task1); 1060 expect(taskStr1 === taskStr2).assertTrue(); 1061 try { 1062 await request.agent.remove(task1.tid); 1063 console.info("====>SUB_REQUEST_Agent_GetTask_Promise_0100 remove success: " + task); 1064 } catch (err) { 1065 console.info('====>SUB_REQUEST_Agent_GetTask_Promise_0100 task not remove: ' + JSON.stringify(task1.tid)); 1066 } 1067 done(); 1068 } catch (err) { 1069 console.info("====>SUB_REQUEST_Agent_GetTask_Promise_0100 Failed: " + JSON.stringify(err)); 1070 expect().assertFail(); 1071 done(); 1072 } 1073 }); 1074 1075 }); 1076} 1077