Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
1a161190
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1a161190
编写于
7月 15, 2023
作者:
H
hu0475
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
'upload测试,x增加download场景'
Signed-off-by:
N
hu0475
<
huyanqiang5@huawei.com
>
上级
76d9c8a2
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
1349 addition
and
298 deletion
+1349
-298
request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json
...questTest_ets/AppScope/resources/base/element/string.json
+1
-1
request/crossplatform/RequestTest_ets/Test.json
request/crossplatform/RequestTest_ets/Test.json
+9
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets
...splatform/RequestTest_ets/src/main/ets/test/List.test.ets
+6
-4
request/crossplatform/RequestTest_ets/src/main/ets/test/RequestUpload.test.ets
.../RequestTest_ets/src/main/ets/test/RequestUpload.test.ets
+541
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets
...equestTest_ets/src/main/ets/test/requestConstant.test.ets
+36
-35
request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets
...equestTest_ets/src/main/ets/test/requestDownload.test.ets
+756
-258
未找到文件。
request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json
浏览文件 @
1a161190
...
...
@@ -2,7 +2,7 @@
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"
xtsDemo1
"
"value"
:
"
ActsRequestETSApiCrossplatformTest
"
}
]
}
request/crossplatform/RequestTest_ets/Test.json
浏览文件 @
1a161190
...
...
@@ -15,6 +15,15 @@
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"power-shell wakeup"
,
"power-shell setmode 602"
,
"uinput -T -m 300 720 300 360 200"
,
"uinput -T -m 650 2760 650 1380 200"
]
}
]
}
\ No newline at end of file
request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets
浏览文件 @
1a161190
...
...
@@ -13,10 +13,12 @@
* limitations under the License.
*/
import requestDownloadJSUnit from './requestDownload.test';
import requestConstantJSUnit from './requestConstant.test';
import crossplatformRequestDownloadTest from './requestDownload.test';
import crossplatformRequestConstantTest from './requestConstant.test';
import crossplatformRequestUploadTest from './RequestUpload.test';
export default function testsuite() {
requestDownloadJSUnit()
requestConstantJSUnit()
crossplatformRequestDownloadTest();
crossplatformRequestConstantTest();
crossplatformRequestUploadTest();
}
\ No newline at end of file
request/crossplatform/RequestTest_ets/src/main/ets/test/RequestUpload.test.ets
0 → 100644
浏览文件 @
1a161190
/*
* Copyright (c) 2023 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 fileIO from "@ohos.file.fs";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium";
function prepareFile(fpath, content) {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
fileIO.truncateSync(file.fd);
fileIO.writeSync(file.fd, content);
fileIO.fsyncSync(file.fd);
fileIO.closeSync(file);
return true;
} catch (e) {
console.log("Failed to prepareFile for " + e);
return false;
}
}
export default function requestUploadCrossplatformJSUnit() {
let testFilePath = '';
describe('requestUploadCrossplatformTest', function () {
console.info('====>################################request upload Test start');
/**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
*/
beforeAll(function () {
console.info('====>beforeAll: Prerequisites are executed.');
testFilePath = globalThis.abilityContext.cacheDir + '/test.txt';
console.log('testFilePath: ' + testFilePath)
prepareFile(testFilePath, '123');
});
/**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
*/
beforeEach(function () {
console.info('====>beforeEach: Prerequisites is executed.');
});
/**
* afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
*/
afterEach(function () {
console.info('====>afterEach: Test case-level clearance conditions is executed.');
});
/**
* afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed.
*/
afterAll(function () {
console.info('====>afterAll: Test suite-level cleanup condition is executed');
});
let uploadTask;
let RequestData = {
name: 'name',
value: '123'
}
let File = {
filename: 'test',
name: 'test',
uri: 'internal://cache/test.txt',
type: 'txt'
}
let uploadConfig = {
url: 'http://127.0.0.1',
header: {
headers: 'http'
},
method: 'POST',
files: [File],
data: [RequestData]
};
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.NETWORK_MOBILE:" + request.NETWORK_MOBILE);
expect(request.NETWORK_MOBILE).assertEqual(1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.NETWORK_WIFI:" + request.NETWORK_WIFI);
expect(request.NETWORK_WIFI).assertEqual(65536);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.ERROR_CANNOT_RESUME:" + request.ERROR_CANNOT_RESUME);
expect(request.ERROR_CANNOT_RESUME).assertEqual(0);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.ERROR_DEVICE_NOT_FOUND:" + request.ERROR_DEVICE_NOT_FOUND);
expect(request.ERROR_DEVICE_NOT_FOUND).assertEqual(1);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_FILE_ALREADY_EXISTS:" + request.ERROR_FILE_ALREADY_EXISTS);
expect(request.ERROR_FILE_ALREADY_EXISTS).assertEqual(2);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_FILE_ERROR:" + request.ERROR_FILE_ERROR);
expect(request.ERROR_FILE_ERROR).assertEqual(3);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_HTTP_DATA_ERROR:" + request.ERROR_HTTP_DATA_ERROR);
expect(request.ERROR_HTTP_DATA_ERROR).assertEqual(4);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_INSUFFICIENT_SPACE:" + request.ERROR_INSUFFICIENT_SPACE);
expect(request.ERROR_INSUFFICIENT_SPACE).assertEqual(5);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.ERROR_TOO_MANY_REDIRECTS:" + request.ERROR_TOO_MANY_REDIRECTS);
expect(request.ERROR_TOO_MANY_REDIRECTS).assertEqual(6);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.ERROR_UNHANDLED_HTTP_CODE:" + request.ERROR_UNHANDLED_HTTP_CODE);
expect(request.ERROR_UNHANDLED_HTTP_CODE).assertEqual(7);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.ERROR_UNKNOWN:" + request.ERROR_UNKNOWN);
expect(request.ERROR_UNKNOWN).assertEqual(8);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.PAUSED_QUEUED_FOR_WIFI:" + request.PAUSED_QUEUED_FOR_WIFI);
expect(request.PAUSED_QUEUED_FOR_WIFI).assertEqual(0);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_UNKNOWN:" + request.PAUSED_UNKNOWN);
expect(request.PAUSED_UNKNOWN).assertEqual(4);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_WAITING_FOR_NETWORK:" + request.PAUSED_WAITING_FOR_NETWORK);
expect(request.PAUSED_WAITING_FOR_NETWORK).assertEqual(1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_WAITING_TO_RETRY:" + request.PAUSED_WAITING_TO_RETRY);
expect(request.PAUSED_WAITING_TO_RETRY).assertEqual(2);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_BY_USER:" + request.PAUSED_BY_USER);
expect(request.PAUSED_BY_USER).assertEqual(3);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_FAILED:" + request.SESSION_FAILED);
expect(request.SESSION_FAILED).assertEqual(4);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_PAUSED:" + request.SESSION_PAUSED);
expect(request.SESSION_PAUSED).assertEqual(3);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_PENDING:" + request.SESSION_PENDING);
expect(request.SESSION_PENDING).assertEqual(2);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_RUNNING:" + request.SESSION_RUNNING);
expect(request.SESSION_RUNNING).assertEqual(1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_SUCCESSFUL:" + request.SESSION_SUCCESSFUL);
expect(request.SESSION_SUCCESSFUL).assertEqual(0);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_PERMISSION:" + request.EXCEPTION_PERMISSION);
expect(request.EXCEPTION_PERMISSION).assertEqual(201);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_PARAMCHECK:" + request.EXCEPTION_PARAMCHECK);
expect(request.EXCEPTION_PARAMCHECK).assertEqual(401);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_UNSUPPORTED:" + request.EXCEPTION_UNSUPPORTED);
expect(request.EXCEPTION_UNSUPPORTED).assertEqual(801);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_FILEIO:" + request.EXCEPTION_FILEIO);
expect(request.EXCEPTION_FILEIO).assertEqual(13400001);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_FILEPATH:" + request.EXCEPTION_FILEPATH);
expect(request.EXCEPTION_FILEPATH).assertEqual(13400002);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_SERVICE:" + request.EXCEPTION_SERVICE);
expect(request.EXCEPTION_SERVICE).assertEqual(13400003);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_OTHERS:" + request.EXCEPTION_OTHERS);
expect(request.EXCEPTION_OTHERS).assertEqual(13499999);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.ERROR_OFFLINE:" + request.ERROR_OFFLINE);
expect(request.ERROR_OFFLINE).assertEqual(9);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.ERROR_UNSUPPORTED_NETWORK_TYPE:" + request.ERROR_UNSUPPORTED_NETWORK_TYPE);
expect(request.ERROR_UNSUPPORTED_NETWORK_TYPE).assertEqual(10);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig, async (err, uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on('progress', (data1, data2) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 on data1 =" + data1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 on data2 =" + data2);
});
uploadTask.off('progress', (data1, data2) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 off data1 =" + data1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 off data2 =" + data2);
});
uploadTask.delete((err, data) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 remove =" + data);
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 end-----------------------");
done();
});
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
});
/**
* @tc.number : SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('headerReceive', (header) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != {} || header != undefined));
});
uploadTask.off('headerReceive', (header) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != {} || header != undefined));
});
uploadTask.delete().then((result)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 remove result = " + result);
expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 end-----------------------");
done();
});
});
} catch (e) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(true).assertFail();
}
});
/**
* @tc.number : SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 UploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('complete', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 on_complete" );
});
uploadTask.off('complete', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 off_complete");
});
uploadTask.delete().then((result)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 remove result = " + result);
expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 end-----------------------");
done();
});
});
} catch (e) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 error: " + JSON.stringify(e));
expect().assertFail();
}
});
/**
* @tc.number : SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 UploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('fail', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 on_fail");
});
uploadTask.off('fail', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 off_fail");
});
uploadTask.delete().then((result)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 remove result = " + result);
expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 end-----------------------");
done();
});
});
} catch (e) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 error: " + JSON.stringify(e));
expect().assertFail();
}
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
};
let t = setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------");
clearTimeout(t);
done();
}, 10000);
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
try{
request.uploadFile(globalThis.abilityContext, uploadConfig).then(uploadTask => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 except error: " + e);
}
}).catch(err => {
console.error("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
}catch(err){
console.error("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err);
}
let t = setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 end-----------------------");
clearTimeout(t);
done();
}, 10000);
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
try{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task.');
expect().assertFail();
done();
}
console.info('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 uploadTask task delete success.');
expect(typeof data == "boolean").assertTrue();
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 end-----------------------");
done();
}catch(err){
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 delete error' + err);
done();
}
});
} catch (error) {
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 delete catch error' + error);
done();
}
})
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
try{
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete().then(data => {
console.info('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 delete data:' + JSON.stringify(data));
expect(data).assertEqual(true);
done();
}).catch((err) => {
console.info('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task.');
expect().assertFail();
done();
})
}catch(err){
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 delete catch err');
done();
}
})
});
})
}
request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets
浏览文件 @
1a161190
...
...
@@ -16,8 +16,8 @@
import request from "@ohos.request";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function request
Upload
JSUnit() {
describe('requestConstant
JSUni
t', function () {
export default function request
ConstantCrossplatform
JSUnit() {
describe('requestConstant
CrossplatformTes
t', function () {
console.info('====>################################request upload Test start');
/**
...
...
@@ -49,45 +49,46 @@ export default function requestUploadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0001
* *@tc.name
subRequestConstant
0001
* @tc.number SUB_REQUEST_C
ROSSPLATFORM_C
ONSTANT_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_CONSTANT_
0001
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CONSTANT_0001', 0, async function (done) {
it('SUB_REQUEST_C
ROSSPLATFORM_C
ONSTANT_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0001 is starting-----------------------");
expect(typeof request.EXCEPTION_PERMISSION == 'number').assertTrue();
expect(typeof request.EXCEPTION_PARAMCHECK == 'number').assertTrue();
expect(typeof request.EXCEPTION_UNSUPPORTED == 'number').assertTrue();
expect(typeof request.EXCEPTION_FILEIO == 'number').assertTrue();
expect(typeof request.EXCEPTION_FILEPATH == 'number').assertTrue();
expect(typeof request.EXCEPTION_SERVICE == 'number').assertTrue();
expect(typeof request.EXCEPTION_OTHERS == 'number').assertTrue();
expect(typeof request.NETWORK_MOBILE == 'number').assertTrue();
expect(typeof request.NETWORK_WIFI == 'number').assertTrue();
expect(typeof request.ERROR_CANNOT_RESUME == 'number').assertTrue();
expect(typeof request.ERROR_DEVICE_NOT_FOUND == 'number').assertTrue();
expect(typeof request.ERROR_FILE_ALREADY_EXISTS == 'number').assertTrue();
expect(typeof request.ERROR_FILE_ERROR == 'number').assertTrue();
expect(typeof request.ERROR_HTTP_DATA_ERROR == 'number').assertTrue();
expect(typeof request.ERROR_INSUFFICIENT_SPACE == 'number').assertTrue();
expect(typeof request.ERROR_TOO_MANY_REDIRECTS == 'number').assertTrue();
expect(typeof request.ERROR_UNHANDLED_HTTP_CODE == 'number').assertTrue();
expect(typeof request.ERROR_UNKNOWN == 'number').assertTrue();
expect(typeof request.ERROR_OFFLINE == 'number').assertTrue();
expect(typeof request.ERROR_UNSUPPORTED_NETWORK_TYPE == 'number').assertTrue();
expect(typeof request.PAUSED_QUEUED_FOR_WIFI == 'number').assertTrue();
expect(typeof request.PAUSED_WAITING_FOR_NETWORK == 'number').assertTrue();
expect(typeof request.PAUSED_WAITING_TO_RETRY == 'number').assertTrue();
expect(typeof request.PAUSED_BY_USER == 'number').assertTrue();
expect(typeof request.PAUSED_UNKNOWN == 'number').assertTrue();
expect(typeof request.SESSION_SUCCESSFUL == 'number').assertTrue();
expect(typeof request.SESSION_RUNNING == 'number').assertTrue();
expect(typeof request.SESSION_PENDING == 'number').assertTrue();
expect(typeof request.SESSION_PAUSED == 'number').assertTrue();
expect(typeof request.SESSION_FAILED == 'number').assertTrue();
expect(request.EXCEPTION_PERMISSION === 201).assertTrue();
expect(request.EXCEPTION_PARAMCHECK === 401).assertTrue();
expect(request.EXCEPTION_UNSUPPORTED === 801).assertTrue();
expect(request.EXCEPTION_FILEIO === 13400001).assertTrue();
expect(request.EXCEPTION_FILEPATH === 13400002).assertTrue();
expect(request.EXCEPTION_SERVICE === 13400003).assertTrue();
expect(request.EXCEPTION_OTHERS === 13499999).assertTrue();
expect(request.NETWORK_MOBILE === 1).assertTrue();
expect(request.NETWORK_WIFI === 65536).assertTrue();
expect(request.ERROR_CANNOT_RESUME === 0).assertTrue();
expect(request.ERROR_DEVICE_NOT_FOUND === 1).assertTrue();
expect(request.ERROR_FILE_ALREADY_EXISTS === 2).assertTrue();
expect(request.ERROR_FILE_ERROR === 3).assertTrue();
expect(request.ERROR_HTTP_DATA_ERROR === 4).assertTrue();
expect(request.ERROR_INSUFFICIENT_SPACE === 5).assertTrue();
expect(request.ERROR_TOO_MANY_REDIRECTS === 6).assertTrue();
expect(request.ERROR_UNHANDLED_HTTP_CODE === 7).assertTrue();
expect(request.ERROR_UNKNOWN === 8).assertTrue();
expect(request.ERROR_OFFLINE === 9).assertTrue();
expect(request.ERROR_UNSUPPORTED_NETWORK_TYPE === 10).assertTrue();
expect(request.PAUSED_QUEUED_FOR_WIFI === 0).assertTrue();
expect(request.PAUSED_WAITING_FOR_NETWORK === 1).assertTrue();
expect(request.PAUSED_WAITING_TO_RETRY === 2).assertTrue();
expect(request.PAUSED_BY_USER === 3).assertTrue();
expect(request.PAUSED_UNKNOWN === 4).assertTrue();
expect(request.SESSION_SUCCESSFUL === 0).assertTrue();
expect(request.SESSION_RUNNING === 1).assertTrue();
expect(request.SESSION_PENDING === 2).assertTrue();
expect(request.SESSION_PAUSED === 3).assertTrue();
expect(request.SESSION_FAILED === 4).assertTrue();
done();
});
...
...
request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets
浏览文件 @
1a161190
...
...
@@ -20,8 +20,8 @@ const removeFile = (filePath: string): void => {
if (fileIo.accessSync(filePath)) fileIo.unlinkSync(filePath);
};
export default function requestDownloadJSUnit() {
describe("request
DownloadJSUni
t", function () {
export default function request
Crossplatform
DownloadJSUnit() {
describe("request
CrossplatformDownloadTes
t", function () {
console.info("====>################################request download Test start");
/**
...
...
@@ -53,17 +53,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001
* *@tc.name
subRequestDownloadFileStageApiCallback
0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_
0001
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -78,31 +78,31 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
} catch (e) {
console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 except error: " + e);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 except error: " + e);
}
await downloadTask.delete();
removeFile(downloadFilePath);
console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 end-----------------------");
console.info("-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 end-----------------------");
done();
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002
* *@tc.name
subRequestDownloadFileStageApiCallback
0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_
0002
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002", 0, async function (done) {
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`);
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -117,31 +117,31 @@ export default function requestDownloadJSUnit() {
background: true,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
} catch (e) {
console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 except error: " + e);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 except error: " + e);
}
await downloadTask.delete();
removeFile(downloadFilePath);
console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 end-----------------------");
console.info("-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 end-----------------------");
done();
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001
* *@tc.name
subRequestDownloadFileStageApiPromise
0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_
0001
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -159,35 +159,35 @@ export default function requestDownloadJSUnit() {
request
.downloadFile(globalThis.abilityContext, downloadFileConfig)
.then(async (downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
await downloadTask.delete();
})
.catch((err) => {
console.error("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 error: " + err);
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 error: " + err);
})
.finally(() => {
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 catch error: " + err);
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 catch error: " + err);
done();
}
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_DELETE_0001
* *@tc.name
subRequestDownloadApiDelete
0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_
0001
* @tc.desc Delete the download task.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_DELETE_0001", 0, async function (done) {
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0001.txt`);
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -202,20 +202,20 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 Failed to delete the download task.");
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001 Failed to delete the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 Download task delete success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001 Download task delete success.");
expect(typeof data == "boolean").assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 delete throw error" + err);
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001 delete throw error" + err);
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
...
...
@@ -223,7 +223,7 @@ export default function requestDownloadJSUnit() {
}
});
} catch (error) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0001 delete catch error" + error);
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0001 delete catch error" + error);
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -232,17 +232,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_DELETE_0002
* *@tc.name
subRequestDownloadApiDelete
0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_
0002
* @tc.desc Delete the download task.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_DELETE_0002", 0, async function (done) {
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_DELETE_0002.txt`);
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -257,18 +257,18 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.delete()
.then(async (data) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 Download task delete success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002 Download task delete success.");
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 end-----------------------");
console.info("====>-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002 end-----------------------");
})
.catch(async (err) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_DELETE_0002 Failed to delete the download task.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_DELETE_0002 Failed to delete the download task.");
expect().assertFail();
})
.finally(async () => {
...
...
@@ -286,17 +286,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001
* *@tc.name
subRequestDownloadApiSuspend
0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_
0001
* @tc.desc Suspend the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -311,27 +311,27 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 Failed to suspend the download task.");
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001 Failed to suspend the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 Download task suspend success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001 Download task suspend success.");
expect(data == true).assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001 suspend catch error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0001 suspend catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -340,17 +340,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002
* *@tc.name
subRequestDownloadApiSuspend
0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_
0002
* @tc.desc Suspend the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -365,17 +365,17 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
try {
let data = await downloadTask.suspend();
expect(data == true).assertTrue();
} catch (err) {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 throw_err:" + JSON.stringify(err));
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002 throw_err:" + JSON.stringify(err));
}
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002 suspend catch error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_SUSPEND_0002 suspend catch error" + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
...
...
@@ -385,17 +385,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001
* *@tc.name
subRequestDownloadApiRestore
0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_
0001
* @tc.desc Restore the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -410,27 +410,27 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 Failed to restore the download task.");
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001 Failed to restore the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 Download restore success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001 Download restore success.");
expect(data == true).assertTrue();
} catch (err) {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 throw_err:" + JSON.stringify(err));
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001 throw_err:" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001 restore catch error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0001 restore catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -439,17 +439,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002
* *@tc.name
subRequestDownloadApiRestore
0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_
0002
* @tc.desc Restore the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -464,17 +464,17 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.restore()
.then(async (data) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 Download task restore.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002 Download task restore.");
expect(data == true).assertTrue();
})
.catch(async (err) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002 Failed to restore the download task.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_RESTORE_0002 Failed to restore the download task.");
})
.finally(async () => {
await downloadTask.delete();
...
...
@@ -491,17 +491,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001
* *@tc.name
subRequestDownloadApiGetTaskInfo
0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_
0001
* @tc.desc Get the download task info
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -516,27 +516,27 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.");
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 Download getTaskInfo success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 throw_error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -545,17 +545,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002
* *@tc.name subRequestDownloadApiGetTaskInfo0002
* @tc.desc Get the download task info
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -570,17 +570,17 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.getTaskInfo()
.then(async (data) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.");
expect(typeof data == "object").assertTrue();
})
.catch(async (err) => {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.");
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.");
})
.finally(async () => {
await downloadTask.delete();
...
...
@@ -588,7 +588,7 @@ export default function requestDownloadJSUnit() {
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -597,17 +597,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001
* *@tc.name
subRequestDownloadApigetTaskMimeType
0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_
0001
* @tc.desc Get mimetype of the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
...
...
@@ -623,16 +623,16 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskMimeType(async (err, data) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType enter");
console.info("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType err: " + err);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType enter");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType err: " + err);
expect(data != null).assertEqual(true);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 callback error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001 callback error: " + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
...
...
@@ -640,7 +640,7 @@ export default function requestDownloadJSUnit() {
}
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_GETTASKMINETYPE_0001 error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_GETTASKMINETYPE_0001 error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -649,17 +649,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002
* *@tc.name
subRequestDownloadApigetTaskMimeType
0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNLOAD_API_GETTASKMINETYPE_0002
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_
0002
* @tc.desc Get mimetype of the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNLOAD_API_GETTASKMINETYPE_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNLOAD_API_GETTASKMINETYPE_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNLOAD_API_GETTASKMINETYPE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNLOAD_API_GETTASKMINETYPE_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -675,12 +675,12 @@ export default function requestDownloadJSUnit() {
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNLOAD_API_GETTASKMINETYPE_0002 downloadTask: " + downloadTask);
try {
let data = await downloadTask.getTaskMimeType();
expect(data != undefined).assertEqual(true);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNLOAD_API_GETTASKMINETYPE_0002 throw_error: " + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
...
...
@@ -690,17 +690,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001
* *@tc.name subRequestDownloadApiTaskInfo0001
* @tc.desc Get the download task info, and test the field of TaskInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -715,34 +715,34 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", async () => {
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Failed to getTaskInfo the download task.");
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Download getTaskInfo success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
console.info('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 data:' + JSON.stringify(data));
console.info('SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001 data:' + JSON.stringify(data));
expect(data.description).assertEqual('XTS download test!');
expect(data.downloadedBytes).assertEqual(1042003);
expect(typeof data.downloadId == "number").assertTrue();
expect(data.failedReason).assertEqual(0);
expect(data.fileName).assertEqual('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`);
expect(data.fileName).assertEqual('SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001.txt');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001.txt`);
expect(data.pausedReason).assertEqual(0);
expect(data.status).assertEqual(0);
expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk');
expect(data.downloadTitle).assertEqual('XTS download test!');
expect(data.downloadTotalBytes).assertEqual(1042003);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 throw_error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
...
...
@@ -750,7 +750,7 @@ export default function requestDownloadJSUnit() {
});
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -759,17 +759,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002
* *@tc.name
subRequestDownloadApiTaskInfo
0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_
0002
* @tc.desc Get the error download task info, and test the field of TaskInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test_not_exists.apk",
header: {
...
...
@@ -784,34 +784,34 @@ export default function requestDownloadJSUnit() {
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('fail', err => {
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 Failed to getTaskInfo the download task.");
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 Download getTaskInfo success.");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
console.info('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 data:' + JSON.stringify(data));
console.info('SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002 data:' + JSON.stringify(data));
expect(data.description).assertEqual('XTS download test!');
expect(data.downloadedBytes).assertEqual(0);
expect(data.failedReason).assertEqual(8);
expect(typeof data.downloadId == "number").assertTrue();
expect(data.fileName).assertEqual('SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002.txt`);
expect(data.fileName).assertEqual('SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002.txt');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002.txt`);
expect(data.pausedReason).assertEqual(0);
expect(data.status).assertEqual(4);
expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test_not_exists.apk');
expect(data.downloadTitle).assertEqual('XTS download test!');
expect(data.downloadTotalBytes).assertEqual(-1);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 throw_error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
...
...
@@ -820,7 +820,7 @@ export default function requestDownloadJSUnit() {
})
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_TASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -829,17 +829,85 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0001
* *@tc.name subRequestDownloadApiEvent0001
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003
* @tc.desc Get the download task info, and test the field of TaskInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
background: true,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", async () => {
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
console.info('SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 data:' + JSON.stringify(data));
expect(data.description).assertEqual('XTS download test!');
expect(data.downloadedBytes).assertEqual(1042003);
expect(typeof data.downloadId == "number").assertTrue();
expect(data.failedReason).assertEqual(0);
expect(data.fileName).assertEqual('test.apk');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.cacheDir}/test.apk`);
expect(data.pausedReason).assertEqual(0);
expect(data.status).assertEqual(0);
expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk');
expect(data.downloadTitle).assertEqual('download');
expect(data.downloadTotalBytes).assertEqual(1042003);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0001", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0001 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0001_bk.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0001_bk.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001_bk.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001_bk.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -855,26 +923,26 @@ export default function requestDownloadJSUnit() {
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("progress", async (receivedSize: number, totalSize: number) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0001 downloadTask in progress");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001 downloadTask in progress");
expect(receivedSize != null).assertTrue();
expect(totalSize != null).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0001 on api throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001 on api throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0001 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0001 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -883,17 +951,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0002
* *@tc.name
subRequestDownloadApiEvent
0002
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0002
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0002_bk.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0002_bk.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002_bk.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002_bk.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -910,24 +978,24 @@ export default function requestDownloadJSUnit() {
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0002 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", async () => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0002 complete in callback");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002 complete in callback");
expect(true).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0002 complete api throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002 complete api throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0002 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0002 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -936,17 +1004,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0003
* *@tc.name
subRequestDownloadApiEvent
0003
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0003
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0003", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0003 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0003.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0003.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk",
header: {
...
...
@@ -963,7 +1031,7 @@ export default function requestDownloadJSUnit() {
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0003 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", async () => {
try {
...
...
@@ -972,14 +1040,14 @@ export default function requestDownloadJSUnit() {
removeFile(downloadFilePath);
done();
} catch {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0003 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0003 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0003 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -988,17 +1056,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0004
* *@tc.name
subRequestDownloadApiEvent
0004
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0004
* @tc.desc Start download task, and test the event 'off progress' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0004", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0004 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0004.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0004.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -1015,7 +1083,7 @@ export default function requestDownloadJSUnit() {
let count = 0;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0004 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("progress", () => {
...
...
@@ -1025,13 +1093,13 @@ export default function requestDownloadJSUnit() {
downloadTask.on("complete", async () => {
try {
console.log("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0004 count: " + count);
console.log("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004 count: " + count);
expect(count).assertEqual(1);
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0004 throw_error in complete: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004 throw_error in complete: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1039,7 +1107,7 @@ export default function requestDownloadJSUnit() {
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0004 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0004 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1048,17 +1116,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0005
* *@tc.name
subRequestDownloadApiEvent
0005
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0005
* @tc.desc Start download task, and test the event 'off complete' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0005", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0005.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0005.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -1076,25 +1144,25 @@ export default function requestDownloadJSUnit() {
let result = true;
let onFailedCallback = function() {
result = false;
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 onFailedCallback");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", onFailedCallback);
downloadTask.off("complete", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 in setTimeout");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005 in setTimeout");
clearTimeout(t);
expect(result).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 throw_error in setTimeout: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1102,7 +1170,7 @@ export default function requestDownloadJSUnit() {
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0005 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0005 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1111,17 +1179,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0006
* *@tc.name
subRequestDownloadApiEvent
0006
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0006
* @tc.desc Start download task, and test the event 'off error' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0006", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0006.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0006.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk",
header: {
...
...
@@ -1139,32 +1207,32 @@ export default function requestDownloadJSUnit() {
let result = true;
let onFailedCallback = function() {
result = false;
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 onFailedCallback");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", onFailedCallback);
downloadTask.off("fail", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 in setTimeout");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006 in setTimeout");
clearTimeout(t);
expect(result).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 throw_error in setTimeout: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0006 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0006 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1173,17 +1241,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0007
* *@tc.name
subRequestDownloadApiEvent
0007
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0007
* @tc.desc Start download task, and test the event 'off complete' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0007", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0007.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0007.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -1202,15 +1270,15 @@ export default function requestDownloadJSUnit() {
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 onFailedCallback");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 onFailedCallback");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", onFailedCallback)
downloadTask.on("complete", onFailedCallback2)
...
...
@@ -1219,14 +1287,15 @@ export default function requestDownloadJSUnit() {
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 in setTimeout");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertFalse();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 throw_error in setTimeout: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1234,7 +1303,7 @@ export default function requestDownloadJSUnit() {
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0007 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0007 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1243,17 +1312,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0008
* *@tc.name
subRequestDownloadApiEvent
0008
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0008
* @tc.desc Start download task, and test the event 'off error' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0008", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0008.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0008.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk",
header: {
...
...
@@ -1272,15 +1341,15 @@ export default function requestDownloadJSUnit() {
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 onFailedCallback");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 onFailedCallback");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", onFailedCallback);
downloadTask.on("fail", onFailedCallback2);
...
...
@@ -1288,21 +1357,22 @@ export default function requestDownloadJSUnit() {
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 in setTimeout");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertFalse();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 throw_error in setTimeout: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0008 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0008 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1311,17 +1381,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0009
* *@tc.name
subRequestDownloadApiEvent
0009
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0009
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0009", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0009.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0009.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -1337,18 +1407,18 @@ export default function requestDownloadJSUnit() {
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("pause", async () => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 downloadTask in pause");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009 downloadTask in pause");
expect(true).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 on api throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009 on api throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1356,7 +1426,7 @@ export default function requestDownloadJSUnit() {
});
await downloadTask.suspend();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0009 throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0009 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
@@ -1365,17 +1435,17 @@ export default function requestDownloadJSUnit() {
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_EVENT_0010
* *@tc.name
subRequestDownloadApiEvent
0010
* @tc.number SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0010
* *@tc.name
SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_
0010
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_DOWNDLOAD_API_EVENT_0010", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0010.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_EVENT_0010.txt`);
it("SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0010", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0010 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0010.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0010.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
...
...
@@ -1391,25 +1461,453 @@ export default function requestDownloadJSUnit() {
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0010 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("remove", async () => {
try {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 downloadTask in remove");
console.info("====>SUB_REQUEST_
CROSSPLATFORM_
DOWNDLOAD_API_EVENT_0010 downloadTask in remove");
expect(true).assertTrue();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_EVENT_0010 on api throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010 on api throw_error: " + JSON.stringify(err));
removeFile(downloadFilePath);
done();
}
});
await downloadTask.delete();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011
* @tc.desc Start download task, and test the event 'off complete' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", onFailedCallback)
downloadTask.on("complete", onFailedCallback2)
downloadTask.off("complete");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012
* @tc.desc Start download task, and test the event 'off error' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", onFailedCallback);
downloadTask.on("fail", onFailedCallback2);
downloadTask.off("fail");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 onFailedCallback");
}
downloadTask.on("pause", onFailedCallback);
downloadTask.on("pause", onFailedCallback2);
downloadTask.off("pause", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2 == false).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.suspend();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 onFailedCallback");
}
downloadTask.on("pause", onFailedCallback);
downloadTask.on("pause", onFailedCallback2);
downloadTask.off("pause");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.suspend();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 onFailedCallback");
}
downloadTask.on("remove", onFailedCallback);
downloadTask.on("remove", onFailedCallback2);
downloadTask.off("remove", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2 == false).assertTrue();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 throw_error in setTimeout: " + JSON.stringify(err));
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.delete();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 onFailedCallback");
}
downloadTask.on("remove", onFailedCallback);
downloadTask.on("remove", onFailedCallback2);
downloadTask.off("remove");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 throw_error in setTimeout: " + JSON.stringify(err));
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.delete();
} catch (err) {
console.error("====>SUB_REQUEST_
DOWNDLOAD_API_EVENT_0010
throw_error: " + JSON.stringify(err));
console.error("====>SUB_REQUEST_
CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016
throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录