Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
3ff02a42
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3ff02a42
编写于
11月 28, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 28, 2022
浏览文件
操作
浏览文件
下载
差异文件
!6729 【上传下载】订阅事件接口XTS优化
Merge pull request !6729 from 何海涛/request1128
上级
f306257c
de6363ce
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
1160 addition
and
799 deletion
+1160
-799
request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts
...st_Stage/entry/src/main/ets/Application/MyAbilityStage.ts
+1
-1
request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts
...tTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts
+1
-1
request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
...ge/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
+6
-0
request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets
...t/RequestTest_Stage/entry/src/main/ets/test/List.test.ets
+2
-2
request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets
...st_Stage/entry/src/main/ets/test/requestDownload.test.ets
+565
-72
request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets
...Test_Stage/entry/src/main/ets/test/requestUpload.test.ets
+88
-16
request/RequestTest_ets/Test.json
request/RequestTest_ets/Test.json
+0
-2
request/RequestTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
...ts/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
+9
-3
request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets
...Test_ets/entry/src/main/ets/test/requestDownload.test.ets
+479
-628
request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets
...stTest_ets/entry/src/main/ets/test/requestUpload.test.ets
+9
-74
未找到文件。
request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts
浏览文件 @
3ff02a42
import
hilog
from
'
@ohos.hilog
'
;
import
AbilityStage
from
"
@ohos.app
.ability
.AbilityStage
"
import
AbilityStage
from
"
@ohos.app
lication
.AbilityStage
"
export
default
class
MyAbilityStage
extends
AbilityStage
{
onCreate
()
{
...
...
request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts
浏览文件 @
3ff02a42
...
...
@@ -2,7 +2,7 @@ import hilog from '@ohos.hilog';
import
Window
from
'
@ohos.window
'
;
import
{
Hypium
}
from
'
@ohos/hypium
'
;
import
testsuite
from
'
../test/List.test
'
;
import
Ability
from
'
@ohos.app
.ability.UI
Ability
'
;
import
Ability
from
'
@ohos.app
lication.
Ability
'
;
import
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
;
export
default
class
MainAbility
extends
Ability
{
...
...
request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
浏览文件 @
3ff02a42
...
...
@@ -59,6 +59,12 @@ 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.requesttest.test/haps/entry_test/cache/test.txt
"
,
(
err
:
any
,
d
:
any
)
=>
{
console
.
info
(
'
executeShellCommand : err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
executeShellCommand : data :
'
+
d
.
stdResult
);
console
.
info
(
'
executeShellCommand : data :
'
+
d
.
exitCode
);
})
abilityDelegator
.
executeShellCommand
(
cmd
,
(
err
:
any
,
d
:
any
)
=>
{
hilog
.
isLoggable
(
0x0000
,
'
testTag
'
,
hilog
.
LogLevel
.
INFO
);
...
...
request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets
浏览文件 @
3ff02a42
...
...
@@ -16,7 +16,7 @@
import requestUploadJSUnit from './requestUpload.test';
import requestDownloadJSUnit from './requestDownload.test';
export default function testsuite() {
requestUploadJSUnit()
export default function testsuite() {
requestDownloadJSUnit()
requestUploadJSUnit()
}
\ No newline at end of file
request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets
浏览文件 @
3ff02a42
...
...
@@ -50,19 +50,6 @@ export default function requestDownloadJSUnit() {
});
let downloadTask;
let downloadConfig = {
url: 'http://download.ci.openharmony.cn/version/Daily_Version/',
header: {
headers: 'http'
},
enableMetered: false,
enableRoaming: false,
description: 'XTS download test!',
networkType: request.NETWORK_WIFI,
filePath: 'internal://cache/test.txt',
title: 'XTS download test!',
background: true
}
/**
* @tc.number SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001
...
...
@@ -73,22 +60,32 @@ export default function requestDownloadJSUnit() {
*/
it('SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------");
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
try {
request.download(context, downloadConfig, (err, data)=>{
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001.txt`)
let downloadConfig = {
url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png',
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, downloadConfig, async (err, data)=>{
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try {
expect(true).assertEqual(downloadTask != undefined);
});
} catch (err) {
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
await downloadTask.delete()
} catch (err) {
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err);
}
done();
}
,5000)
}
);
});
...
...
@@ -101,20 +98,31 @@ export default function requestDownloadJSUnit() {
*/
it('SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 is starting-----------------------");
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
request.download(context, downloadConfig).then(data => {
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001.txt`
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001.txt`)
let downloadConfig = {
url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png',
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, downloadConfig).then(async (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
expect(true).assertEqual(downloadTask != undefined);
await downloadTask.delete()
done();
}).catch(err => {
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------");
done();
}
,5000
)
})
});
/**
...
...
@@ -126,10 +134,10 @@ export default function requestDownloadJSUnit() {
*/
it('SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/
test
.txt`
console.debug("
downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/test
.txt`)
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: 'http
://download.ci.openharmony.cn/version/Daily_Version/
',
url: 'http
s://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
header: {
headers: 'http'
},
...
...
@@ -139,24 +147,20 @@ export default function requestDownloadJSUnit() {
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: 'XTS download test!',
background:
tru
e
background:
fals
e
}
try {
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data)=>{
downloadTask = data;
console.info("SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try{
expect(true).assertEqual(downloadTask != undefined);
}catch(e){
console.info("SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
});
} catch (err) {
console.error("SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------");
done();
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, data)=>{
downloadTask = data;
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try{
expect(true).assertEqual(downloadTask != undefined);
await downloadTask.delete()
}catch(e){
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------");
done();
});
});
/**
...
...
@@ -168,10 +172,10 @@ export default function requestDownloadJSUnit() {
*/
it('SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/
test
.txt`
console.debug("
downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/test
.txt`)
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: 'http
://download.ci.openharmony.cn/version/Daily_Version/
',
url: 'http
s://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
',
header: {
headers: 'http'
},
...
...
@@ -181,27 +185,516 @@ export default function requestDownloadJSUnit() {
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: 'XTS download test!',
background:
tru
e
background:
fals
e
}
try{
request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(
data
=> {
request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(
async (data)
=> {
downloadTask = data;
console.info("SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
try{
expect(true).assertEqual(downloadTask != undefined);
}catch(e){
console.info("SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 except error: " + e);
}
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
await downloadTask.delete()
done();
}).catch(err => {
console.error("SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail
();
console.error("
====>
SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err);
done
();
})
}catch(err){
console.error("SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err);
console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err);
done();
}
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_DELETE_0001
* @tc.desc Delete the download task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success.');
expect(typeof data == "boolean").assertTrue();
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete throw error' + err);
}
done();
});
} catch (error) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error' + error);
done();
}
})
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_DELETE_0002
* @tc.desc Delete the download task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete().then(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-----------------------");
done();
}).catch((err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task.');
expect().assertFail();
done();
})
} catch (error) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 delete catch error');
done();
}
})
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001
* @tc.desc Suspend the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 is starting-----------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Download task suspend success.');
expect(data == true).assertTrue();
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err));
}
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error' + JSON.stringify(err));
done();
}
})
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002
* @tc.desc Suspend the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 is starting-----------------------");
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',
header: {
headers: 'http'
},
enableMetered: false,
enableRoaming: false,
description: 'XTS download test!',
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: 'XTS download test!',
background: false
}
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 end-----------------------");
done();
request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => {
downloadTask = data;
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.');
expect(data == true).assertTrue();
done();
}).catch((err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 throw_err:' + JSON.stringify(err));
done();
})
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 suspend catch error' + JSON.stringify(err));
done();
}
})
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_RESTORE_0001
* @tc.desc Restore the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_RESTORE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 is starting-----------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Download restore success.');
expect(data == true).assertTrue();
}catch(err){
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 throw_err:' + JSON.stringify(err));
}
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error' + JSON.stringify(err));
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_RESTORE_0002
* @tc.desc Restore the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_RESTORE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 is starting-----------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore().then(data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore.');
expect(data == true).assertTrue();
done();
}).catch((err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task.');
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 restore catch error' +JSON.stringify(err));
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001
* @tc.desc Get the download task info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001', 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 is starting---------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Download getTaskInfo success.');
expect(typeof data == "object").assertTrue();
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 throw_error' +JSON.stringify(err));
}
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error' + JSON.stringify(err));
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002
* @tc.desc Get the download task info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002', 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 is starting----------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo().then(data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.');
expect(typeof data == "object").assertTrue();
done();
}).catch((err) => {
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.');
done();
});
}catch(err){
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 getTaskInfo catch error' + JSON.stringify(err));
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001
* @tc.desc Get mimetype of the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001', 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 is starting---------------------");
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',
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, (err, data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 downloadTask: " + downloadTask);
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('progress',(data1, data2) => {
try{
if (data1 > 0){
downloadTask.getTaskMimeType(async (err, data)=>{
try{
if(err) {
console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 err:'+ JSON.stringify(err));
expect().assertFail();
done();
}
if (data) {
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 data:' + JSON.stringify(data));
expect(typeof data == "string").assertTrue();
} else {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err));
expect().assertFail();
}
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 throw_error: " + JSON.stringify(err));
}
setTimeout(()=>{
done();
},1000)
});
}
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err));
done();
}
})
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err));
done();
}
})
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002
* @tc.desc Get mimetype of the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002', 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 is starting----------------------");
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',
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, data) => {
downloadTask = data;
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){
let data = await downloadTask.getTaskMimeType()
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 data:' + JSON.stringify(data));
expect(typeof data == "string").assertTrue();
}
setTimeout(()=>{
done();
},1000)
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 throw_error: " + JSON.stringify(err));
done();
}
})
}catch(err){
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 error: " + JSON.stringify(err));
done();
}
})
});
});
}
\ No newline at end of file
request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets
浏览文件 @
3ff02a42
...
...
@@ -114,7 +114,6 @@ export default function requestUploadJSUnit() {
});
} catch (err) {
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
...
...
@@ -157,7 +156,6 @@ export default function requestUploadJSUnit() {
});
} catch (e) {
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(e).assertFail();
}
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 end-----------------------");
...
...
@@ -245,19 +243,28 @@ export default function requestUploadJSUnit() {
expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {}));
uploadTask.off('complete', () => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success");
expect(true).assertEqual(true);
try{
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success");
expect(true).assertEqual(true);
}catch(err){
console.debug("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 complete err"+ JSON.stringify(err));
done();
}
});
uploadTask.off('fail', () => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success");
expect(true).assertEqual(true);
try{
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success");
expect(true).assertEqual(true);
}catch(err){
console.debug("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 fail err" + JSON.stringify(err));
done();
}
});
}catch(err){
expect().assertFail();
done();
}
}
});
} catch (e) {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 error: " + JSON.stringify(e));
...
...
@@ -281,16 +288,15 @@ export default function requestUploadJSUnit() {
try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data)=>{
uploadTask = data;
console.info("SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask);
console.info("
====>
SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 except error: " + e);
console.info("
====>
SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
});
} catch (err) {
console.error("SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
console.error("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
};
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------");
...
...
@@ -310,18 +316,18 @@ export default function requestUploadJSUnit() {
try{
request.uploadFile(globalThis.abilityContext, uploadConfig).then(data => {
uploadTask = data;
console.info("SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask);
console.info("
====>
SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 except error: " + e);
console.info("
====>
SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 except error: " + e);
}
}).catch(err => {
console.error("SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 error: " + err);
console.error("
====>
SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
}catch(err){
console.error("SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err);
console.error("
====>
SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err);
}
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------");
...
...
@@ -329,5 +335,71 @@ export default function requestUploadJSUnit() {
}, 10000);
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0001
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
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) => {
try{
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task.');
expect().assertFail();
done();
}
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask task delete success.');
expect(typeof data == "boolean").assertTrue();
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 end-----------------------");
done();
}catch(err){
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete error' + err);
done();
}
});
} catch (error) {
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete catch error' + error);
done();
}
})
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0002
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
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;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
try{
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete().then(data => {
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete data:' + JSON.stringify(data));
expect(data).assertEqual(true);
done();
}).catch((err) => {
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task.');
expect().assertFail();
done();
})
}catch(err){
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete catch err');
done();
}
})
});
})
}
request/RequestTest_ets/Test.json
浏览文件 @
3ff02a42
...
...
@@ -16,8 +16,6 @@
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"mkdir -p /data/app/el2/100/base/com.acts.requesttest/haps/entry/cache"
,
"echo
\"
123456
\"
> /data/app/el2/100/base/com.acts.requesttest/haps/entry/cache/test.txt"
]
}
]
...
...
request/RequestTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
浏览文件 @
3ff02a42
...
...
@@ -54,15 +54,21 @@ export default class OpenHarmonyTestRunner implements TestRunner {
console
.
log
(
'
OpenHarmonyTestRunner onRun run
'
)
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
let
lMonitor
=
{
abilityName
:
testAbilityName
,
onAbilityCreate
:
onAbilityCreateCallback
,
};
var
testAbilityName
=
abilityDelegatorArguments
.
parameters
[
'
-p
'
]
+
'
.MainAbility
'
abilityDelegator
.
addAbilityMonitor
(
lMonitor
,
addAbilityMonitorCallback
)
abilityDelegator
.
addAbilityMonitor
(
lMonitor
,
addAbilityMonitorCallback
)
abilityDelegator
.
executeShellCommand
(
"
echo 123456 > /data/app/el2/100/base/com.acts.requesttest/haps/entry/cache/test.txt
"
,
(
err
:
any
,
d
:
any
)
=>
{
console
.
info
(
'
executeShellCommand : err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
executeShellCommand : data :
'
+
d
.
stdResult
);
console
.
info
(
'
executeShellCommand : data :
'
+
d
.
exitCode
);
})
var
cmd
=
'
aa start -d 0 -a
'
+
testAbilityName
+
'
-b
'
+
abilityDelegatorArguments
.
bundleName
cmd
+=
'
'
+
translateParamsToString
(
abilityDelegatorArguments
.
parameters
)
cmd
+=
'
'
+
translateParamsToString
(
abilityDelegatorArguments
.
parameters
)
console
.
info
(
'
cmd :
'
+
cmd
)
abilityDelegator
.
executeShellCommand
(
cmd
,
(
err
:
any
,
d
:
any
)
=>
{
...
...
request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets
浏览文件 @
3ff02a42
...
...
@@ -14,6 +14,7 @@
*/
import
request
from
"@ohos.request"
;
import
featureAbility
from
'@ohos.ability.featureAbility'
import
AbilityDelegatorRegistry
from
'@ohos.application.abilityDelegatorRegistry'
;
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
"hypium/index"
;
...
...
@@ -24,15 +25,16 @@ export default function requestDownloadJSUnit() {
/**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
*/
beforeAll(function () {
beforeAll
(
async
function
()
{
console
.
info
(
'====>beforeAll: Prerequisites are executed.'
);
});
/**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
*/
beforeEach(function () {
console.info('====>beforeEach: Prerequisites is executed.');
beforeEach
(
async
function
()
{
console
.
info
(
'====>beforeEach: Prerequisites is executed.'
);
await
setDownLoadConfig
()
});
/**
...
...
@@ -50,63 +52,23 @@ export default function requestDownloadJSUnit() {
});
let
downloadTask
;
let downloadConfig = {
url: 'http://127.0.0.1',
header: {
headers: 'http'
},
enableMetered: false,
enableRoaming: false,
description: 'XTS download test!',
networkType: request.NETWORK_WIFI,
filePath: 'test.txt',
title: 'XTS download test!',
background: true
}
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_CALLBACK_0001
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_CALLBACK_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_CALLBACK_0001 is starting-----------------------");
try {
request.download(downloadConfig, (data)=>{
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_CALLBACK_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
});
} catch (err) {
console.error("SUB_REQUEST_DOWNLOAD_API_CALLBACK_0001 error: " + err);
expect().assertFail();
let
downloadConfig
async
function
setDownLoadConfig
(){
let
downloadFilePath
=
await
featureAbility
.
getContext
()
.
getFilesDir
()
downloadConfig
=
{
url
:
'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png'
,
header
:
{
headers
:
'http'
},
enableMetered
:
false
,
enableRoaming
:
false
,
description
:
'XTS download test!'
,
networkType
:
request
.
NETWORK_WIFI
,
filePath
:
`${downloadFilePath}/`
,
title
:
'XTS download test!'
,
background
:
false
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_CALLBACK_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_PROMISE_0001
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_PROMISE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 is starting-----------------------");
request.download(downloadConfig).then(data => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
}).catch(err => {
console.error("SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 end-----------------------");
done();
});
}
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001
...
...
@@ -117,20 +79,31 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
downloadTask.on('progress', (data1, data2) => {
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);
});
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 end-----------------------");
done();
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
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
)
=>
{
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
){
done
();
}
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 throw_error: "
+
err
);
done
();
}
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 error: "
+
err
);
done
();
}
});
});
/**
...
...
@@ -142,21 +115,27 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
true
)
.
assertEqual
(
downloadTask
!=
undefined
);
downloadTask.on('complete', () => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 task completed.')
downloadTask
.
on
(
'complete'
,
async
()
=>
{
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
()
done
();
});
}
catch
(
err
){
console.error("
SUB_REQUEST_DOWNLOAD_API_CALLBACK
_0002 error: " + err);
expect().assertFail
();
}
console
.
error
(
"
====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON
_0002 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 end-----------------------");
done();
});
/**
...
...
@@ -168,21 +147,32 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: "
+
downloadTask
);
try
{
expect
(
true
)
.
assertEqual
(
downloadTask
!=
undefined
);
downloadTask.on('pause', () => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task pause.')
downloadTask
.
on
(
'pause'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task completed.'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 throw_error: "
+
err
);
}
await
downloadTask
.
remove
()
done
();
});
downloadTask
.
on
(
'progress'
,
(
data1
,
data2
)
=>
{
if
(
data1
>
0
){
downloadTask
.
pause
()
}
});
}
catch
(
err
){
console.error("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 error: " + err);
expect().assertFail
();
console
.
error
(
"
====>
SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 end-----------------------");
done();
});
});
/**
...
...
@@ -194,22 +184,31 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 downloadTask: " + downloadTask);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'remove'
,
()
=>
{
console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 task remove.')
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 remove completed'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 throw_error: "
+
err
);
}
done
();
});
downloadTask
.
on
(
'progress'
,
(
data1
,
data2
)
=>
{
if
(
data1
>
0
){
downloadTask
.
remove
()
}
});
}
catch
(
err
){
console.error("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 error: " + err);
expect().assertFail
();
console
.
error
(
"
====>
SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 end-----------------------");
done();
});
});
/**
...
...
@@ -221,21 +220,61 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005.txt'
downloadConfig
.
url
+=
'xxxxxxxxxx'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 downloadTask: "
+
downloadTask
);
try
{
downloadTask.on('remove', () => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 task remove.')
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'fail'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 fail completed'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 throw_error: "
+
err
);
}
await
downloadTask
.
remove
()
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 error: "
+
err
);
done
();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006
* @tc.desc Called when the current download session fails.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
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
;
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
)
=>
{
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 second throw_error: "
+
err
);
expect
(
err
.
code
)
.
assertEqual
(
'13400002'
)
await
downloadTask
.
remove
()
done
();
}
});
}
catch
(
err
){
console.error("
SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005
error: " + err);
expect().assertFail
();
console
.
error
(
"
====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006
error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 end-----------------------");
done();
});
});
/**
...
...
@@ -247,19 +286,30 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.off('progress', (data1, data2) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on data1 =" + data1);
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on data2 =" + data2);
expect(data1 != undefined).assertEqual(true);
expect(data2 != undefined).assertEqual(true);
});
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
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
.
off
(
'progress'
,
async
(
data1
,
data2
)
=>
{
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
);
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
()
done
();
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 end-----------------------");
done();
});
/**
...
...
@@ -271,21 +321,27 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 downloadTask: "
+
downloadTask
);
try
{
downloadTask.off('complete', () => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 task complete.')
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
off
(
'complete'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 task complete.'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 off_err: "
+
err
);
}
await
downloadTask
.
remove
()
done
();
});
}
catch
(
err
){
console.error("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 error: " + err);
expect().assertFail
();
console
.
error
(
"
====>
SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 end-----------------------");
done();
});
});
/**
...
...
@@ -297,21 +353,27 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 downloadTask: "
+
downloadTask
);
try
{
downloadTask.off('pause', () => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 task pause.')
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
off
(
'pause'
,
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 task complete.'
)
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: "
+
err
);
}
await
downloadTask
.
remove
()
done
();
});
}
catch
(
err
){
console.error("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 error: " + err);
expect().assertFail
();
console
.
error
(
"
====>
SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 end-----------------------");
done();
});
/**
...
...
@@ -323,21 +385,27 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 downloadTask: "
+
downloadTask
);
try
{
downloadTask.off('remove', () => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 task remove.')
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
off
(
'remove'
,
async
(
data
)
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 remove data:'
+
JSON
.
stringify
(
data
))
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: "
+
err
);
}
await
downloadTask
.
remove
()
done
();
});
}
catch
(
err
){
console.error("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 error: " + err);
expect().assertFail
();
console
.
error
(
"
====>
SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 end-----------------------");
done();
});
/**
...
...
@@ -349,21 +417,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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: "
+
downloadTask
);
expect(downloadTask != undefined).assertEqual(true);
try
{
downloadTask.off('pause', () => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 task complete.')
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'fail'
,
(
data
)
=>
{});
downloadTask
.
off
(
'fail'
,
async
(
data
)
=>
{
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 end-----------------------"
);
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_error: "
+
err
);
}
await
downloadTask
.
remove
()
done
();
});
}
catch
(
err
){
console.error("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 error: " + err);
expect().assertFail
();
}
console
.
error
(
"
====>
SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 error: "
+
err
);
done
();
}
});
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 end-----------------------");
done();
});
/**
...
...
@@ -375,26 +451,35 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.remove((err, data)=>{
if(err) {
console.error('SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 Failed to remove the download task.');
expect().assertFail();
}
if (data) {
console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 Download task removed.');
expect(data == true).assertTrue();
} else {
console.error('SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 Failed to remove the download task.');
expect().assertFail();
}
});
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
remove
((
err
,
data
)
=>
{
try
{
if
(
err
)
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 Failed to remove the download task.'
);
expect
()
.
assertFail
();
}
if
(
data
)
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 removed data:'
+
JSON
.
stringify
(
data
));
expect
(
data
==
true
)
.
assertTrue
();
}
else
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 Failed to remove the download task.'
);
expect
()
.
assertFail
();
}
}
catch
(
err
){
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 remove_throw_err:'
+
JSON
.
stringify
(
err
))
}
done
();
});
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 error: "
+
err
);
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 end-----------------------");
done();
});
/**
...
...
@@ -406,25 +491,31 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMOVE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.remove().then(data => {
if (data) {
console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Download task removed.');
expect(data == true).assertTrue();
} else {
console.error('SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.');
expect().assertFail();
}
}).catch((err) => {
console.error('SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.');
expect().assertFail();
})
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
remove
()
.
then
(
data
=>
{
if
(
data
)
{
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.'
);
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 error: "
+
err
);
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 end-----------------------");
done();
});
/**
...
...
@@ -436,22 +527,27 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_
DOWNLOADTASK_OFF_0005
downloadTask: " + downloadTask);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_
PAUSE_0001
downloadTask: "
+
downloadTask
);
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
try
{
downloadTask.pause(()=>{
console.info('====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 Download task pause success.');
expect(true).assertTrue();
downloadTask
.
pause
(
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 Download task pause success.'
);
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 pause_throw_err:'
+
JSON
.
stringify
(
err
))
}
await
downloadTask
.
remove
()
done
();
})
}
catch
(
err
){
console.error(
'Failed to pause the download task pause. because: '
+ JSON.stringify(err));
expect().assertFail
();
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 end-----------------------");
done();
});
/**
...
...
@@ -463,20 +559,26 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_PAUSE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.pause().then(() => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 Download task pause success.');
expect(true).assertTrue();
}).catch((err) => {
console.error('Failed to pause the download task pause. because: ' + JSON.stringify(err));
expect().assertFail();
})
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
.
remove
()
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
));
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 end-----------------------");
done();
});
/**
...
...
@@ -488,22 +590,27 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_
DOWNLOADTASK_OFF_0005
downloadTask: " + downloadTask);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_
REMUSE_0001
downloadTask: "
+
downloadTask
);
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
try
{
downloadTask.resume(()=>{
console.info('====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 Download task resume success.');
expect(true).assertTrue();
downloadTask
.
resume
(
async
()
=>
{
try
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 Download task resume success.'
);
expect
(
true
)
.
assertTrue
();
}
catch
(
err
){
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 pause_throw_err:'
+
JSON
.
stringify
(
err
))
}
await
downloadTask
.
remove
()
done
();
})
}
catch
(
err
){
console.error(
'Failed to pause the download task resume. because: '
+ JSON.stringify(err));
expect().assertFail
();
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 end-----------------------");
done();
});
/**
...
...
@@ -515,20 +622,26 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_REMUSE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.resume().then(() => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 Download task resume success.');
expect(true).assertTrue();
}).catch((err) => {
console.error('Failed to pause the download task resume. because: ' + JSON.stringify(err));
expect().assertFail();
})
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
));
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 end-----------------------");
done();
});
/**
...
...
@@ -540,37 +653,42 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERY_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 downloadTask: "
+
downloadTask
);
try
{
downloadTask.query((err, downloadInfo)=>{
if(err) {
console.error('SUB_REQUEST_DOWNLOAD_API_QUERY_0001 Failed to query: ' + JSON.stringify(err));
expect().assertFail();
} else {
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.description);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadedBytes);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadId);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.failedReason);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.fileName);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.filePath);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.pausedReason);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.status);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.targetURI);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadTitle);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadTotalBytes);
expect(true).assertTrue();
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
query
(
async
(
err
,
downloadInfo
)
=>
{
try
{
if
(
err
)
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 Failed to query: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
}
else
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
description
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
downloadedBytes
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
downloadId
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
failedReason
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
fileName
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
filePath
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
pausedReason
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
status
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
targetURI
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
downloadTitle
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '
+
downloadInfo
.
downloadTotalBytes
);
expect
(
true
)
.
assertTrue
();
}
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 throw_error: "
+
JSON
.
stringify
(
err
));
}
await
downloadTask
.
remove
()
done
();
})
}
catch
(
err
){
console.error(
'Failed to pause the download task query. because: '
+ JSON.stringify(err));
expect().assertFail
();
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0001 end-----------------------");
done();
});
/**
...
...
@@ -582,35 +700,47 @@ 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-----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERY_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.query().then((err, downloadInfo)=>{
if(err) {
console.error('SUB_REQUEST_DOWNLOAD_API_QUERY_0002 Failed to query: ' + JSON.stringify(err));
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
query
()
.
then
(
async
(
downloadInfo
)
=>
{
try
{
if
(
err
)
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 Failed to query: '
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
}
else
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
description
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
downloadedBytes
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
downloadId
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
failedReason
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
fileName
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
filePath
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
pausedReason
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
status
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
targetURI
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
downloadTitle
);
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '
+
downloadInfo
.
downloadTotalBytes
);
expect
(
true
)
.
assertTrue
();
}
await
downloadTask
.
remove
()
done
();
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
.
catch
((
err
)
=>
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 catch_error: "
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
} else {
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.description);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadedBytes);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadId);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.failedReason);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.fileName);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.filePath);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.pausedReason);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.status);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.targetURI);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadTitle);
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadTotalBytes);
expect(true).assertTrue();
}
}).catch(err => {
console.error('Failed to pause the download task query. because: ' + JSON.stringify(err));
expect().assertFail();
})
done
();
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0002 end-----------------------");
done();
});
/**
...
...
@@ -622,26 +752,48 @@ 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---------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.queryMimeType((err, data)=>{
if(err) {
console.error('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 Failed to queryMimeType the download task.');
expect().assertFail();
}
if (data) {
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 Download task queryMimeType.');
expect(typeof data == "string").assertTrue();
} else {
console.error('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 Failed to queryMimeType the download task.');
expect().assertFail();
}
});
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask
.
on
(
'progress'
,
(
data1
,
data2
)
=>
{
try
{
if
(
data1
>
0
){
downloadTask
.
queryMimeType
((
err
,
data
)
=>
{
try
{
if
(
err
)
{
console
.
error
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 err:'
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
done
();
}
if
(
data
)
{
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data:'
+
JSON
.
stringify
(
data
));
expect
(
typeof
data
==
"string"
)
.
assertTrue
();
}
else
{
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: "
+
JSON
.
stringify
(
err
));
expect
()
.
assertFail
();
}
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 throw_error: "
+
JSON
.
stringify
(
err
));
}
setTimeout
(
async
()
=>
{
await
downloadTask
.
remove
()
done
();
},
1000
)
});
}
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 end-----------------------");
done();
});
/**
...
...
@@ -653,334 +805,33 @@ 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----------------------"
);
request.download( downloadConfig, (data)=>{
downloadConfig
.
filePath
+=
'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002.txt'
request
.
download
(
downloadConfig
,
(
err
,
data
)
=>
{
downloadTask
=
data
;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.queryMimeType().then(data => {
if (data) {
console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.');
expect(data == true).assertTrue();
} else {
console.error('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Failed to queryMimeType the download task.');
expect().assertFail();
}
}).catch((err) => {
console.error('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Failed to queryMimeType the download task.');
expect().assertFail();
})
})
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_DELETE_0001
* @tc.desc Delete the download task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------");
try {
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete((err, data) => {
if (err) {
console.error('SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success.');
expect(typeof data == "boolean").assertTrue();
});
})
} catch (error) {
console.error('SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_DELETE_0002
* @tc.desc Delete the download task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------");
try {
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete().then(data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Download task delete success.');
expect(data == true).assertTrue();
}).catch((err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task.');
expect().assertFail();
})
})
} catch (error) {
console.error('SUB_REQUEST_DOWNLOAD_API_DELETE_0002 delete catch error');
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001
* @tc.desc Suspend the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 is starting-----------------------");
try {
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend((err, data) => {
if (err) {
console.error('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Download task suspend success.');
expect(data == true).assertTrue();
});
})
}
catch(error) {
console.error('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002
* @tc.desc Suspend the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 is starting-----------------------");
try {
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend().then(data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Download task suspend success.');
expect(data == true).assertTrue();
}).catch((err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 Failed to suspend the download task.');
expect().assertFail();
})
})
}
catch(error){
console.error('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_RESTORE_0001
* @tc.desc Restore the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_RESTORE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 is starting-----------------------");
try{
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore((err, data) => {
if (err) {
console.error('SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Download restore success.');
expect(data == true).assertTrue();
});
});
}catch(error){
console.error('SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_RESTORE_0002
* @tc.desc Restore the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_RESTORE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 is starting-----------------------");
try{
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore().then(data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore.');
expect(data == true).assertTrue();
}).catch((err) => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task.');
expect().assertFail();
});
});
}catch(error){
console.error('SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001
* @tc.desc Get the download task info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001', 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 is starting---------------------");
try{
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo((err, data) => {
if (err) {
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Download getTaskInfo success.');
expect(typeof data == "object").assertTrue();
});
});
}catch(error){
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002
* @tc.desc Get the download task info
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002', 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 is starting----------------------");
try{
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo().then(data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.');
expect(typeof data == "object").assertTrue();
}).catch((err) => {
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.');
expect().assertFail();
});
});
}catch(error){
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001
* @tc.desc Get mimetype of the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001', 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 is starting---------------------");
try{
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskMimeType((err, data) => {
if (err) {
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 Failed to getTaskMimeType the download task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 Download task getTaskMimeType success.');
expect(typeof data == "string").assertTrue();
});
});
}catch(error){
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 getTaskMimeType catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002
* @tc.desc Get mimetype of the download task
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002', 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 is starting----------------------");
try{
request.download(downloadConfig, (data) => {
downloadTask = data;
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 downloadTask: " + downloadTask);
console
.
info
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 downloadTask: "
+
downloadTask
);
try
{
expect
(
downloadTask
!=
undefined
)
.
assertEqual
(
true
);
downloadTask.getTaskMimeType().then(data => {
console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 Download getTaskMimeType success.');
expect(typeof data == "string").assertTrue();
}).catch((err) => {
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 Failed to getTaskMimeType the download task.');
expect().assertFail();
});
});
}catch(error){
console.error('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 getTaskMimeType catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 end-----------------------");
done();
downloadTask
.
on
(
'progress'
,
async
(
data1
,
data2
)
=>
{
try
{
if
(
data1
>
0
){
let
data
=
await
downloadTask
.
queryMimeType
()
console
.
info
(
'====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.'
);
expect
(
typeof
data
==
"string"
)
.
assertTrue
();
setTimeout
(
async
()
=>
{
await
downloadTask
.
remove
()
done
();
},
1000
)
}
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
}
catch
(
err
){
console
.
error
(
"====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 error: "
+
JSON
.
stringify
(
err
));
done
();
}
})
});
})
}
request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets
浏览文件 @
3ff02a42
...
...
@@ -100,7 +100,7 @@ export default function requestUploadJSUnit() {
expect(request.ERROR_DEVICE_NOT_FOUND).assertEqual(1);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0001 error: " + err);
console.error("
====>
SUB_REQUEST_UPLOAD_API_0001 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0001 end-----------------------");
done();
...
...
@@ -127,7 +127,7 @@ export default function requestUploadJSUnit() {
expect(request.ERROR_INSUFFICIENT_SPACE).assertEqual(5);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0002 error: " + err);
console.error("
====>
SUB_REQUEST_UPLOAD_API_0002 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0002 end-----------------------");
done();
...
...
@@ -154,7 +154,7 @@ export default function requestUploadJSUnit() {
expect(request.PAUSED_QUEUED_FOR_WIFI).assertEqual(0);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0003 error: " + err);
console.error("
====>
SUB_REQUEST_UPLOAD_API_0003 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0003 end-----------------------");
done();
...
...
@@ -181,7 +181,7 @@ export default function requestUploadJSUnit() {
expect(request.SESSION_FAILED).assertEqual(4);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0004 error: " + err);
console.error("
====>
SUB_REQUEST_UPLOAD_API_0004 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0004 end-----------------------");
done();
...
...
@@ -208,7 +208,7 @@ export default function requestUploadJSUnit() {
expect(request.SESSION_SUCCESSFUL).assertEqual(0);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0005 error: " + err);
console.error("
====>
SUB_REQUEST_UPLOAD_API_0005 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0005 end-----------------------");
done();
...
...
@@ -245,7 +245,7 @@ export default function requestUploadJSUnit() {
expect(request.ERROR_UNSUPPORTED_NETWORK_TYPE).assertEqual(10);
} catch (err) {
expect(true).assertEqual(true);
console.error("SUB_REQUEST_UPLOAD_API_0006 error: " + err);
console.error("
====>
SUB_REQUEST_UPLOAD_API_0006 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0006 end-----------------------");
done();
...
...
@@ -263,7 +263,7 @@ 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, (data) => {
request.upload(uploadConfig, (
err,
data) => {
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true);
...
...
@@ -283,7 +283,7 @@ export default function requestUploadJSUnit() {
});
});
} catch (err) {
console.error("SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err);
console.error("
====>
SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
sleep(Date.now(), 20000);
...
...
@@ -324,77 +324,12 @@ export default function requestUploadJSUnit() {
});
});
} catch (e) {
console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(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();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0001
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_UPLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------");
try {
request.upload(uploadConfig, (data) => {
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => {
if (err) {
console.error('SUB_REQUEST_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task.');
expect().assertFail();
}
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask task delete success.');
expect(typeof data == "boolean").assertTrue();
});
})
} catch (error) {
console.error('SUB_REQUEST_UPLOAD_API_DELETE_0001 delete catch error' + error);
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0002
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_UPLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------");
try {
request.upload(uploadConfig, (data) => {
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete().then(data => {
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask task delete success.');
expect(data == true).assertTrue();
}).catch((err) => {
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task.');
expect().assertFail();
})
})
} catch (error) {
console.error('SUB_REQUEST_UPLOAD_API_DELETE_0002 delete catch error');
expect().assertFail();
}
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 end-----------------------");
done();
});
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录