Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
b2bb98f4
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看板
提交
b2bb98f4
编写于
2月 20, 2023
作者:
Z
zhangyushuai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
request用例优化 004
Signed-off-by:
N
zhangyushuai
<
zhangyushuai1@huawei.com
>
上级
6c59d190
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
513 addition
and
394 deletion
+513
-394
inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets
...est_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets
+11
-14
request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
...ge/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
+1
-1
request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets
...st_Stage/entry/src/main/ets/test/requestDownload.test.ets
+145
-99
request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets
...Test_Stage/entry/src/main/ets/test/requestUpload.test.ets
+8
-10
request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets
...Test_ets/entry/src/main/ets/test/requestDownload.test.ets
+336
-246
request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets
...stTest_ets/entry/src/main/ets/test/requestUpload.test.ets
+10
-22
theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets
...screenlock_ets/entry/src/main/ets/test/screenLockTest.ets
+2
-2
未找到文件。
inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets
浏览文件 @
b2bb98f4
...
...
@@ -24,13 +24,6 @@ export default function imeAbilityTest(abilityContext) {
id:'',
extra:{}
}
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
/**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
...
...
@@ -75,12 +68,14 @@ export default function imeAbilityTest(abilityContext) {
}
inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{
console.info('====>SUB_InputMethod_IMEAbility_000
4
switchInputMethod to IME :' + data);
console.info('====>SUB_InputMethod_IMEAbility_000
1
switchInputMethod to IME :' + data);
expect(data == true).assertTrue();
});
sleep(Date.now(), 3000);
console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------');
let t = setTimeout(() => {
console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------' + t);
clearTimeout(t);
done();
}, 500);
})
/**
...
...
@@ -105,9 +100,11 @@ export default function imeAbilityTest(abilityContext) {
console.info('====>SUB_InputMethod_IMEAbility_0002 switchInputMethod to IME :' + data);
expect(data == true).assertTrue();
});
sleep(Date.now(), 2500);
console.info('====>-----------SUB_InputMethod_IMEAbility_0002 end-------------');
let t = setTimeout(() => {
console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------' + t);
clearTimeout(t);
done();
}, 500);
})
})
}
request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
浏览文件 @
b2bb98f4
...
...
@@ -59,7 +59,7 @@ export default class OpenHarmonyTestRunner implements TestRunner {
}
hilog
.
isLoggable
(
0x0000
,
'
testTag
'
,
hilog
.
LogLevel
.
INFO
);
hilog
.
info
(
0x0000
,
'
testTag
'
,
'
cmd : %{public}s
'
,
cmd
);
abilityDelegator
.
executeShellCommand
(
"
echo
\"
123456
\"
> /data/app/el2/100/base/com.acts.request
test
.test/haps/entry_test/cache/test.txt
"
,
abilityDelegator
.
executeShellCommand
(
"
echo
\"
123456
\"
> /data/app/el2/100/base/com.acts.request.test/haps/entry_test/cache/test.txt
"
,
(
err
:
any
,
d
:
any
)
=>
{
console
.
info
(
'
executeShellCommand : err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
executeShellCommand : data :
'
+
d
.
stdResult
);
...
...
request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets
浏览文件 @
b2bb98f4
...
...
@@ -14,7 +14,7 @@
*/
import request from "@ohos.request";
import
AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry
';
import
fileio from '@ohos.fileio
';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function requestDownloadJSUnit() {
...
...
@@ -49,7 +49,6 @@ export default function requestDownloadJSUnit() {
console.info('====>afterAll: Test suite-level cleanup condition is executed');
});
let downloadTask;
/**
* @tc.number SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001
...
...
@@ -63,7 +62,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -75,15 +74,15 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, data)=>{
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask)=>{
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try{
expect(true).assertEqual(downloadTask != undefined);
await downloadTask.delete()
expect(downloadTask != undefined).assertEqual(true);
}catch(e){
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------");
done();
});
...
...
@@ -101,7 +100,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -114,21 +113,22 @@ export default function requestDownloadJSUnit() {
background: false
}
try{
request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(async (data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(async (downloadTask) => {
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
await downloadTask.delete()
expect(downloadTask != undefined).assertEqual(true);
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}).catch(err => {
console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err);
fileio.unlinkSync(downloadFilePath);
done();
})
}catch(err){
console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err);
fileio.unlinkSync(downloadFilePath);
done();
}
});
/**
...
...
@@ -143,7 +143,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -155,26 +155,30 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete((err, data) => {
downloadTask.delete(
async
(err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task.');
await downloadTask.delete();
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success.');
expect(typeof data == "boolean").assertTrue();
}catch(err){
await downloadTask.delete();
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete throw error' + err);
}
fileio.unlinkSync(downloadFilePath);
done();
});
} catch (error) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error' + error);
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
})
...
...
@@ -192,7 +196,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -204,23 +208,27 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete().then(data => {
downloadTask.delete().then(
async
data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Download task delete success.');
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 end-----------------------");
fileio.unlinkSync(downloadFilePath);
done();
}).catch((err) => {
}).catch(
async
(err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task.');
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
expect().assertFail();
done();
})
} catch (error) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 delete catch error');
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
})
...
...
@@ -238,7 +246,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -250,12 +258,11 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend((err, data) => {
downloadTask.suspend(
async
(err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task.');
...
...
@@ -266,14 +273,17 @@ export default function requestDownloadJSUnit() {
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err));
}
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error' + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
})
});
/**
...
...
@@ -288,7 +298,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -300,21 +310,23 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend().then(data =>
{
console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 Download task suspend success.'
);
try
{
let data = await downloadTask.suspend(
);
expect(data == true).assertTrue();
done();
}).catch((err) => {
}catch(err){
console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 throw_err:' + JSON.stringify(err));
}
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
})
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 suspend catch error' + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
})
...
...
@@ -332,7 +344,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -344,12 +356,11 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore((err, data) => {
downloadTask.restore(
async
(err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task.');
...
...
@@ -360,10 +371,14 @@ export default function requestDownloadJSUnit() {
}catch(err){
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 throw_err:' + JSON.stringify(err));
}
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error' + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
});
...
...
@@ -381,7 +396,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -393,21 +408,26 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore().then(data => {
downloadTask.restore().then(
async
data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore.');
expect(data == true).assertTrue();
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}).catch((err) => {
}).catch(
async
(err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task.');
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 restore catch error' +JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
});
...
...
@@ -425,7 +445,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -437,12 +457,11 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo((err, data) => {
downloadTask.getTaskInfo(
async
(err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.');
...
...
@@ -453,10 +472,14 @@ export default function requestDownloadJSUnit() {
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 throw_error' +JSON.stringify(err));
}
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error' + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
});
...
...
@@ -474,7 +497,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -486,21 +509,26 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo().then(data => {
downloadTask.getTaskInfo().then(
async
data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.');
expect(typeof data == "object").assertTrue();
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}).catch((err) => {
}).catch(
async
(err) => {
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.');
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 getTaskInfo catch error' + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
});
...
...
@@ -518,7 +546,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -530,18 +558,21 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
let flag = false;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('progress',(data1, data2) => {
downloadTask.on('progress',
async
(data1, data2) => {
try{
if (data1 > 0){
if (data1 > 0 && flag == false){
flag = true;
downloadTask.off('progress');
downloadTask.getTaskMimeType(async (err, data)=>{
try{
if(err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 err:'+ JSON.stringify(err));
fileio.unlinkSync(downloadFilePath);
expect().assertFail();
done();
}
...
...
@@ -555,18 +586,25 @@ export default function requestDownloadJSUnit() {
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 throw_error: " + JSON.stringify(err));
}
setTimeout(()=>{
let t = setTimeout(async ()=>{
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
clearTimeout(t);
done();
},1000)
});
}
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
})
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
})
...
...
@@ -584,7 +622,7 @@ export default function requestDownloadJSUnit() {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002.txt`)
let downloadFileConfig = {
url: 'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
url: 'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
',
header: {
headers: 'http'
},
...
...
@@ -596,28 +634,36 @@ export default function requestDownloadJSUnit() {
title: 'XTS download test!',
background: false
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, data) => {
downloadTask = data;
let flag = false;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('progress', async (data1, data2) => {
try{
if(data1 > 0){
if(data1 > 0 && flag == false){
flag = true;
downloadTask.off('progress');
let data = await downloadTask.getTaskMimeType()
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 data:' + JSON.stringify(data));
expect(typeof data == "string").assertTrue();
}
setTimeout(()=>{
let t = setTimeout(async ()=>{
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
clearTimeout(t);
done();
},1000)
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
fileio.unlinkSync(downloadFilePath);
done();
}
})
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 error: " + JSON.stringify(err));
await downloadTask.delete();
done();
}
})
...
...
request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets
浏览文件 @
b2bb98f4
...
...
@@ -89,8 +89,7 @@ export default function requestUploadJSUnit() {
it('SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data)=>{
uploadTask = data;
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask)=>{
console.info("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
...
...
@@ -101,8 +100,9 @@ export default function requestUploadJSUnit() {
} catch (err) {
console.error("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
};
setTimeout(()=>{
let t =
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------");
clearTimeout(t);
done();
}, 10000);
});
...
...
@@ -117,8 +117,7 @@ export default function requestUploadJSUnit() {
it('SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
try{
request.uploadFile(globalThis.abilityContext, uploadConfig).then(data => {
uploadTask = data;
request.uploadFile(globalThis.abilityContext, uploadConfig).then(uploadTask => {
console.info("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
...
...
@@ -132,8 +131,9 @@ export default function requestUploadJSUnit() {
}catch(err){
console.error("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err);
}
setTimeout(()=>{
let t =
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------");
clearTimeout(t);
done();
}, 10000);
});
...
...
@@ -147,9 +147,8 @@ export default function requestUploadJSUnit() {
*/
it('SUB_REQUEST_UPLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err,
data
) => {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err,
uploadTask
) => {
try{
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => {
...
...
@@ -184,8 +183,7 @@ export default function requestUploadJSUnit() {
*/
it('SUB_REQUEST_UPLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => {
uploadTask = data;
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
try{
expect(uploadTask != undefined).assertEqual(true);
...
...
request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets
浏览文件 @
b2bb98f4
...
...
@@ -15,7 +15,7 @@
import
request
from
"@ohos.request"
;
import
featureAbility
from
'@ohos.ability.featureAbility'
import
AbilityDelegatorRegistry
from
'@ohos.application.abilityDelegatorRegistry
'
;
import
fileio
from
'@ohos.fileio
'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
"hypium/index"
;
export
default
function
requestDownloadJSUnit
()
{
...
...
@@ -51,12 +51,11 @@ export default function requestDownloadJSUnit() {
console
.
info
(
'====>afterAll: Test suite-level cleanup condition is executed'
);
});
let
downloadTask
;
let
downloadConfig
async
function
setDownLoadConfig
(){
let
downloadFilePath
=
await
featureAbility
.
getContext
()
.
getFilesDir
()
downloadConfig
=
{
url
:
'https://
www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
'
,
url
:
'https://
gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk
'
,
header
:
{
headers
:
'http'
},
...
...
@@ -79,28 +78,39 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
try
{
downloadTask
=
data
;
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 downloadTask: "
+
JSON
.
stringify
(
downloadTask
)
);
expect
(
true
)
.
assertEqual
(
downloadTask
!=
undefined
);
downloadTask
.
on
(
'progress'
,
(
data1
,
data2
)
=>
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'progress'
,
async
(
data1
,
data2
)
=>
{
if
(
data1
==
data2
&&
flag
==
false
){
flag
=
true
;
try
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data1 ="
+
data1
);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data2 ="
+
data2
);
expect
(
true
)
.
assertEqual
(
data1
!=
undefined
);
expect
(
true
)
.
assertEqual
(
data2
!=
undefined
);
if
(
data1
==
data2
){
downloadTask
.
off
(
'progress'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 throw_error: "
+
err
);
downloadTask
.
off
(
'progress'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
}
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -115,24 +125,34 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
true
)
.
assertEqual
(
downloadTask
!=
undefined
);
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'complete'
,
async
()
=>
{
if
(
flag
==
false
){
flag
=
true
;
downloadTask
.
off
(
'complete'
);
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 task completed.'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 throw_error: "
+
err
);
}
await
downloadTask
.
remove
()
downloadTask
.
off
(
'complete'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 error: "
+
err
);
downloadTask
.
off
(
'complete'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -147,29 +167,36 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: "
+
downloadTask
);
try
{
expect
(
true
)
.
assertEqual
(
downloadTask
!=
undefined
);
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'pause'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task
completed
.'
)
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task
pause
.'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 throw_error: "
+
err
);
}
await
downloadTask
.
remove
()
downloadTask
.
off
(
'pause'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
});
downloadTask
.
on
(
'progress'
,
(
data1
,
data2
)
=>
{
if
(
data1
>
0
){
downloadTask
.
pause
()
downloadTask
.
on
(
'progress'
,
async
(
data1
,
data2
)
=>
{
if
(
flag
==
false
){
flag
=
true
await
downloadTask
.
pause
();
downloadTask
.
off
(
'progress'
);
}
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -184,28 +211,35 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'remove'
,
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 remove
completed
'
)
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 remove
remove
'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 throw_error: "
+
err
);
}
downloadTask
.
off
(
'remove'
);
fileio
.
unlinkSync
(
filePath
);
done
();
});
downloadTask
.
on
(
'progress'
,
(
data1
,
data2
)
=>
{
if
(
data1
>
0
){
downloadTask
.
remove
()
downloadTask
.
on
(
'progress'
,
async
(
data1
,
data2
)
=>
{
if
(
flag
==
false
){
flag
=
true
;
await
downloadTask
.
remove
();
downloadTask
.
off
(
'progress'
);
}
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -220,25 +254,30 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005.txt'
downloadConfig
.
url
+=
'xxxxxxxxxx'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005.txt'
;
downloadConfig
.
url
=
'https://www.baidu.com/xxxxxx.jpg'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'fail'
,
async
()
=>
{
downloadTask
.
on
(
'fail'
,
async
(
err
)
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 fail
completed'
)
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 fail
fail'
+
err
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 throw_error: "
+
err
);
}
await
downloadTask
.
remove
()
downloadTask
.
off
(
'fail'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -253,25 +292,29 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'complete'
,
async
()
=>
{
try
{
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
})
await
request
.
download
(
downloadConfig
);
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 second throw_error: "
+
err
);
expect
(
err
.
code
)
.
assertEqual
(
13400002
)
await
downloadTask
.
remove
()
expect
(
err
.
code
)
.
assertEqual
(
13400002
);
downloadTask
.
off
(
'complete'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -286,27 +329,36 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
try
{
downloadTask
=
data
;
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 downloadTask: "
+
downloadTask
);
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'progress'
,
(
data1
,
data2
)
=>
{});
downloadTask
.
on
(
'progress'
,
async
(
data1
,
data2
)
=>
{
downloadTask
.
off
(
'progress'
,
async
(
data1
,
data2
)
=>
{
if
(
flag
==
false
){
flag
=
true
;
try
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on
data1 ="
+
data1
);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on
data2 ="
+
data2
);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off
data1 ="
+
data1
);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off
data2 ="
+
data2
);
expect
(
data1
)
.
assertEqual
(
0
);
expect
(
data2
)
.
assertEqual
(
0
);
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off_err: "
+
err
);
}
await
downloadTask
.
remove
()
downloadTask
.
off
(
'progress'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -321,24 +373,29 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'complete'
,
()
=>
{});
downloadTask
.
off
(
'complete'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 task complete.'
)
expect
(
true
)
.
assertTrue
();
done
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 off_err: "
+
err
);
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -353,24 +410,29 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'pause'
,
()
=>
{});
downloadTask
.
off
(
'pause'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 task
complet
e.'
)
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 task
paus
e.'
)
expect
(
true
)
.
assertTrue
();
done
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: "
+
err
);
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -385,24 +447,28 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
off
(
'remove'
,
async
(
data
)
=>
{
downloadTask
.
on
(
'remove'
,
()
=>
{});
downloadTask
.
off
(
'remove'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 remove
data:'
+
JSON
.
stringify
(
data
)
)
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 remove
success'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: "
+
err
);
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -417,26 +483,29 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'fail'
,
(
data
)
=>
{});
downloadTask
.
off
(
'fail'
,
async
(
data
)
=>
{
downloadTask
.
off
(
'fail'
,
async
(
err
)
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_data:'
+
JSON
.
stringify
(
data
))
expect
(
data
)
.
assertEqual
(
0
)
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_data:'
+
JSON
.
stringify
(
err
))
expect
(
err
)
.
assertEqual
(
0
)
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 end-----------------------"
);
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_error: "
+
err
);
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
...
...
@@ -451,9 +520,9 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0001'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0001.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
...
...
@@ -473,10 +542,13 @@ export default function requestDownloadJSUnit() {
}
catch
(
err
){
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 remove_throw_err:'
+
JSON
.
stringify
(
err
))
}
fileio
.
unlinkSync
(
filePath
);
done
();
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
...
...
@@ -491,31 +563,24 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0002'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0002.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
remove
()
.
then
(
data
=>
{
if
(
data
)
{
let
data
=
await
downloadTask
.
remove
();
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 removed data:'
+
JSON
.
stringify
(
data
));
expect
(
data
==
true
)
.
assertTrue
();
}
else
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.'
);
expect
()
.
assertFail
();
}
done
();
})
.
catch
((
err
)
=>
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.'
);
fileio
.
unlinkSync
(
filePath
);
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
});
/**
...
...
@@ -527,9 +592,9 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0001'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0001.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 downloadTask: "
+
downloadTask
);
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
try
{
...
...
@@ -540,11 +605,14 @@ export default function requestDownloadJSUnit() {
}
catch
(
err
){
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 pause_throw_err:'
+
JSON
.
stringify
(
err
))
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
...
...
@@ -559,23 +627,20 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0002'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0002.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
pause
()
.
then
(
async
()
=>
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 Download task pause success.'
);
expect
(
true
)
.
assertTrue
();
await
downloadTask
.
pause
();
await
downloadTask
.
remove
()
fileio
.
unlinkSync
(
filePath
);
done
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 throw_error: "
+
JSON
.
stringify
(
err
));
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
()
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
...
...
@@ -590,9 +655,9 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0001'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0001.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 downloadTask: "
+
downloadTask
);
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
try
{
...
...
@@ -603,11 +668,14 @@ export default function requestDownloadJSUnit() {
}
catch
(
err
){
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 pause_throw_err:'
+
JSON
.
stringify
(
err
))
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
downloadConfig
.
filePath
);
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
downloadConfig
.
filePath
);
done
();
}
})
...
...
@@ -622,23 +690,20 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0002'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0002.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
resume
()
.
then
(
async
()
=>
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 Download task resume success.'
);
expect
(
true
)
.
assertTrue
();
await
downloadTask
.
remove
()
done
()
})
.
catch
((
err
)
=>
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 throw_error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
resume
();
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
...
...
@@ -653,9 +718,9 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_QUERY_0001'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0001 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERY_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERY_0001.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
...
...
@@ -681,11 +746,14 @@ export default function requestDownloadJSUnit() {
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 throw_error: "
+
JSON
.
stringify
(
err
));
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
...
...
@@ -700,9 +768,9 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_QUERY_0002'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0002 is starting-----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERY_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERY_0002.txt'
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
...
...
@@ -725,19 +793,26 @@ export default function requestDownloadJSUnit() {
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
downloadTotalBytes
);
expect
(
true
)
.
assertTrue
();
}
await
downloadTask
.
remove
()
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
.
catch
((
err
)
=>
{
})
.
catch
(
async
(
err
)
=>
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 catch_error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
expect
()
.
assertFail
();
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
downloadConfig
.
filePath
);
done
();
}
})
...
...
@@ -752,46 +827,55 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>---------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 is starting---------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'progress'
,
async
(
data1
,
data2
)
=>
{
try
{
if
(
data1
>
0
&&
downloadTask
!=
null
){
downloadTask
.
queryMimeType
((
err
,
data
)
=>
{
try
{
if
(
err
)
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 return_err:'
+
JSON
.
stringify
(
err
));
try
{
if
(
data1
>
0
&&
flag
==
false
)
{
flag
=
true
;
downloadTask
.
off
(
'progress'
);
downloadTask
.
queryMimeType
(
async
(
err
,
data
)
=>
{
try
{
if
(
err
)
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 return_err:'
+
JSON
.
stringify
(
err
));
fileio
.
unlinkSync
(
downloadConfig
.
filePath
);
expect
()
.
assertFail
();
done
();
}
if
(
data
)
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data:'
+
JSON
.
stringify
(
data
));
expect
(
typeof
data
==
"string"
)
.
assertTrue
();
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
else
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data_error: "
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 throw_error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
});
}
if
(
data1
==
data2
){
downloadTask
=
null
await
downloadTask
.
remove
()
done
();
}
}
catch
(
err
){
}
catch
(
err
)
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
...
...
@@ -806,31 +890,37 @@ export default function requestDownloadJSUnit() {
*/
it
(
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002'
,
0
,
async
function
(
done
)
{
console
.
info
(
"====>-------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 is starting----------------------"
);
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002.txt'
;
let
flag
=
false
;
let
filePath
=
downloadConfig
.
filePath
;
request
.
download
(
downloadConfig
,
async
(
err
,
downloadTask
)
=>
{
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'progress'
,
async
(
data1
,
data2
)
=>
{
try
{
if
(
data1
>
0
&&
downloadTask
!=
null
){
if
(
data1
>
0
&&
flag
==
false
){
flag
=
true
;
downloadTask
.
off
(
'progress'
);
let
data
=
await
downloadTask
.
queryMimeType
()
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.'
);
expect
(
typeof
data
==
"string"
)
.
assertTrue
();
}
if
(
data1
==
data2
){
downloadTask
=
null
await
downloadTask
.
remove
()
downloadTask
.
off
(
'progress'
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: "
+
JSON
.
stringify
(
err
));
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: "
+
err
);
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 error: "
+
JSON
.
stringify
(
err
));
await
downloadTask
.
remove
();
fileio
.
unlinkSync
(
filePath
);
done
();
}
})
...
...
request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets
浏览文件 @
b2bb98f4
...
...
@@ -49,13 +49,6 @@ export default function requestUploadJSUnit() {
console.info('====>afterAll: Test suite-level cleanup condition is executed');
});
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
let uploadTask;
let RequestData = {
name: 'name',
...
...
@@ -265,11 +258,9 @@ export default function requestUploadJSUnit() {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
request.upload(uploadConfig, (err, data) => {
uploadTask = data;
request.upload(uploadConfig, (err, uploadTask) => {
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on('progress', function (data1, data2) {
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data1 =" + data1);
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data2 =" + data2);
...
...
@@ -282,15 +273,15 @@ export default function requestUploadJSUnit() {
uploadTask.remove((err, data) => {
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 remove =" + data);
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------");
done();
});
});
} catch (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
sleep(Date.now(), 20000);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------");
done();
});
/**
...
...
@@ -305,33 +296,30 @@ export default function requestUploadJSUnit() {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
request.upload(uploadConfig).then((data) => {
uploadTask = data;
request.upload(uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {}));
expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('headerReceive', (header) => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}
));
expect(true).assertEqual((header != {} || header != undefined
));
});
uploadTask.off('headerReceive', (header) => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}
));
expect(true).assertEqual((header != {} || header != undefined
));
});
uploadTask.remove().then((result)=>{
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 remove result = " + result);
expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------");
done();
});
});
} catch (e) {
console.error("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(true).assertFail(true);
}
sleep(Date.now(), 20000);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------");
done();
});
})
}
theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets
浏览文件 @
b2bb98f4
...
...
@@ -170,7 +170,7 @@ export default function screenLockJSUnit() {
screenLock.isSecureMode((err, data) => {
try{
console.info("====>SUB_MISC_THEME_screenLock_API_0003 secureMode's result is " + data);
expect(data ==
result
).assertTrue();
expect(data ==
false
).assertTrue();
console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0003-------------------");
done();
}catch(err){
...
...
@@ -288,7 +288,7 @@ export default function screenLockJSUnit() {
try{
secured = screenLock.isSecure()
console.info('====>SUB_MISC_THEME_screenLock_API_0011 data : ' + JSON.stringify(secured));
if (
typeof secured == "boolean"
) {
if (
secured == false
) {
expect(true).assertTrue();
console.info('====>-------------SUB_MISC_THEME_screenLock_API_0011 end----------------------');
done()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录