未验证 提交 aa830d9b 编写于 作者: O openharmony_ci 提交者: Gitee

!9518 【杂散】【上传下载】用例新增和off用例优化

Merge pull request !9518 from 张育帅/master
......@@ -337,7 +337,7 @@ export default function requestDownloadJSUnit() {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('progress', async (data1, data2) => {
downloadTask.off('progress', async (data1, data2) => {});
downloadTask.off('progress');
await downloadTask.remove();
fileio.unlinkSync(filePath);
done();
......@@ -368,7 +368,7 @@ export default function requestDownloadJSUnit() {
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('complete', () => {});
downloadTask.off('complete',async () => {});
downloadTask.off('complete');
await downloadTask.remove();
fileio.unlinkSync(filePath);
done();
......@@ -397,7 +397,7 @@ export default function requestDownloadJSUnit() {
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('pause', () => {});
downloadTask.off('pause', async () => {});
downloadTask.off('pause');
await downloadTask.remove();
fileio.unlinkSync(filePath);
done();
......@@ -426,7 +426,7 @@ export default function requestDownloadJSUnit() {
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('remove', () => {});
downloadTask.off('remove', async () => {});
downloadTask.off('remove');
await downloadTask.remove();
fileio.unlinkSync(filePath);
done();
......@@ -455,7 +455,7 @@ export default function requestDownloadJSUnit() {
try{
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('fail', (data) => {});
downloadTask.off('fail', async (err) => {});
downloadTask.off('fail');
await downloadTask.remove();
fileio.unlinkSync(filePath);
done();
......
......@@ -1038,6 +1038,159 @@ export default function requestDownloadOneJSUnitTest() {
}
})
/**
* @tc.number SUB_Misc_REQUEST_Create_Callback_0070
* @tc.desc remove a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_Misc_REQUEST_Create_Callback_0070", 0, async function (done) {
let urls = 'x';
for (let i = 0; i < 2030; i++){
urls += 'x';
}
let config = {
action: request.agent.Action.DOWNLOAD,
url: 'https://' + urls + '/test.apk',
title: 'createTest',
description: "XTS download test!",
mode: request.agent.Mode.BACKGROUND,
overwrite: true,
saveas: "./SUB_Misc_REQUEST_Create_Callback_0070.txt",
network: request.agent.Network.WIFI,
};
console.info("====>-------------------SUB_Misc_REQUEST_Create_Callback_0070 is start ---------------------");
request.agent.create(globalThis.abilityContext, config, async (err, task) => {
try {
if(err){
console.info(`====>SUB_Misc_REQUEST_Create_Callback_0070 task creat fail: ` + JSON.stringify(err));
expect().assertFail();
}
console.info(`====>SUB_Misc_REQUEST_Create_Callback_0070 Succeeded download task length: ` + task.config.url.length);
await request.agent.remove(task.tid);
done();
} catch (err) {
console.info(`====>SUB_Misc_REQUEST_Create_Callback_0070 Succeeded in starting a download task.` + JSON.stringify(err));
done();
}
});
})
/**
* @tc.number SUB_Misc_REQUEST_Create_Promise_0070
* @tc.desc remove a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_Misc_REQUEST_Create_Promise_0070", 0, async function (done) {
let urls = 'x';
for (let i = 0; i < 2030; i++){
urls += 'x';
}
let config = {
action: request.agent.Action.DOWNLOAD,
url: 'https://' + urls + '/test.apk',
title: 'createTest',
description: "XTS download test!",
mode: request.agent.Mode.BACKGROUND,
overwrite: true,
saveas: "./SUB_Misc_REQUEST_Create_Promise_0070.txt",
network: request.agent.Network.WIFI,
};
console.info("====>-------------SUB_Misc_REQUEST_Create_Promise_0070 is starting----------------");
try{
let task = await request.agent.create(globalThis.abilityContext, config);
console.info(`====>SUB_Misc_REQUEST_Create_Promise_0070 Succeeded download task length: ` + task.config.url.length);
await request.agent.remove(task.tid);
expect(true).assertTrue();
done();
}catch(err){
console.info("====>SUB_Misc_REQUEST_Create_Promise_0070 create err: " + JSON.stringify(err));
expect().assertFail();
console.info("-----------------------SUB_Misc_REQUEST_Create_Promise_0070 is end-----------------------");
done();
}
})
/**
* @tc.number SUB_Misc_REQUEST_Create_Callback_0080
* @tc.desc remove a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_Misc_REQUEST_Create_Callback_0080", 0, async function (done) {
let urls = 'x';
for (let i = 0; i < 2031; i++){
urls += 'x';
}
let config = {
action: request.agent.Action.DOWNLOAD,
url: 'https://' + urls + '/test.apk',
title: 'createTest',
description: "XTS download test!",
mode: request.agent.Mode.BACKGROUND,
overwrite: true,
saveas: "./SUB_Misc_REQUEST_Create_Callback_0080.txt",
network: request.agent.Network.WIFI,
};
console.info("====>-------------------SUB_Misc_REQUEST_Create_Callback_0080 is start ---------------------");
try{
request.agent.create(globalThis.abilityContext, config, (err, task) => {
try {
console.info(`====>SUB_Misc_REQUEST_Create_Callback_0080 Succeeded in starting a download task.`);
expect().assertFail();
} catch (err) {
console.info(`====>SUB_Misc_REQUEST_Create_Callback_0080 Succeeded in starting a download task.` + JSON.stringify(err));
request.agent.remove(task.tid);
done();
}
});
}catch(err){
console.info("====>SUB_Misc_REQUEST_Create_Callback_0080 create err: " + JSON.stringify(err));
console.info("-----------------------SUB_Misc_REQUEST_Create_Callback_0080 is end-----------------------");
expect(err.code).assertEqual(401);
done();
}
})
/**
* @tc.number SUB_Misc_REQUEST_Create_Promise_0080
* @tc.desc remove a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_Misc_REQUEST_Create_Promise_0080", 0, async function (done) {
let urls = 'x';
for (let i = 0; i < 2031; i++){
urls += 'x';
}
let config = {
action: request.agent.Action.DOWNLOAD,
url: 'https://' + urls + '/test.apk',
title: 'createTest',
description: "XTS download test!",
mode: request.agent.Mode.BACKGROUND,
overwrite: true,
saveas: "./SUB_Misc_REQUEST_Create_Promise_0080.txt",
network: request.agent.Network.WIFI,
};
console.info("====>-------------SUB_Misc_REQUEST_Create_Promise_0080 is starting----------------");
try{
await request.agent.create(globalThis.abilityContext, config);
console.info(`====>SUB_Misc_REQUEST_Create_Promise_0080 Succeeded in starting a download task.`);
expect().assertFail();
}catch(err){
console.info("====>SUB_Misc_REQUEST_Create_Promise_0080 create err: " + JSON.stringify(err));
expect(err.code).assertEqual(401);
console.info("-----------------------SUB_Misc_REQUEST_Create_Promise_0080 is end-----------------------");
done();
}
})
/**
* @tc.number SUB_Misc_REQUEST_Create_Promise_0110
* @tc.desc remove a download session.
......
......@@ -237,6 +237,7 @@ export default function requestDownloadTwoUnitTest() {
console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 on_progressCallback flag: " + flag);
}
let on_progressCallback1 = (pro) => {
task.off('progress');
flag1 = false;
console.info("====>SUB_Misc_REQUEST_Off_Download_Progress_0020 on_progressCallback1 flag1: " + flag1);
expect(true).assertTrue();
......@@ -537,6 +538,7 @@ export default function requestDownloadTwoUnitTest() {
console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 on_progressCallback flag: " + flag);
}
let on_progressCallback1 = (pro) => {
task.off('completed');
flag1 = false;
console.info("====>SUB_Misc_REQUEST_Off_Download_Completed_0020 on_progressCallback1 flag1: " + flag1);
expect(true).assertTrue();
......@@ -837,6 +839,7 @@ export default function requestDownloadTwoUnitTest() {
console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 on_progressCallback flag: " + flag);
}
let on_progressCallback1 = (pro) => {
task.off('failed');
flag1 = false;
console.info("====>SUB_Misc_REQUEST_Off_Download_Failed_0020 on_progressCallback1 flag1: " + flag1);
expect(true).assertTrue();
......@@ -1881,32 +1884,33 @@ export default function requestDownloadTwoUnitTest() {
let task:request.agent.Task
function onCompletedCallback(progress){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 onCompletedCallback start')
task.off('completed');
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 onCompletedCallback start');
request.agent.touch(task.tid, config.token,(err, taskInfo)=>{
try{
if(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 err:' + JSON.stringify(err));
expect().assertFail();
done();
}
expect(taskInfo.url).assertEqual(config.url)
expect(taskInfo.data).assertEqual("")
expect(taskInfo.title).assertEqual(config.title)
expect(taskInfo.url).assertEqual(config.url);
expect(taskInfo.data).assertEqual("");
expect(taskInfo.title).assertEqual(config.title);
done();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 touch throw_err:' + JSON.stringify(err))
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 touch throw_err:' + JSON.stringify(err));
done();
}
})
}
try {
task = await request.agent.create(globalThis.abilityContext, config)
task.on('completed', onCompletedCallback)
await task.start()
task = await request.agent.create(globalThis.abilityContext, config);
task.on('completed', onCompletedCallback);
await task.start();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 create throw_err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0010 create throw_err:' + JSON.stringify(err));
expect().assertFail();
done();
}
......@@ -1934,25 +1938,26 @@ export default function requestDownloadTwoUnitTest() {
let task:request.agent.Task
async function onCompletedCallback(progress){
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 onCompletedCallback start')
task.off('completed');
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 onCompletedCallback start');
try{
let taskInfo = await request.agent.touch(task.tid, config.token)
expect(taskInfo.title).assertEqual(config.title)
let taskInfo = await request.agent.touch(task.tid, config.token);
expect(taskInfo.title).assertEqual(config.title);
done();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 touch throw_err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 touch throw_err:' + JSON.stringify(err));
expect().assertFail();
done();
}
}
try {
task = await request.agent.create(globalThis.abilityContext, config)
task.on('completed', onCompletedCallback)
await task.start()
task = await request.agent.create(globalThis.abilityContext, config);
task.on('completed', onCompletedCallback);
await task.start();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 create throw_err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0010 create throw_err:' + JSON.stringify(err));
expect().assertFail();
done();
}
......@@ -1980,27 +1985,28 @@ export default function requestDownloadTwoUnitTest() {
let task:request.agent.Task
function onCompletedCallback(progress){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 onCompletedCallback start')
task.off('completed');
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 onCompletedCallback start');
try{
// @ts-ignore
request.agent.touch({}, config.token,(err, taskInfo)=>{
expect().assertFail()
expect().assertFail();
done();
})
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 touch throw_err:' + JSON.stringify(err))
expect(err.code).assertEqual(401)
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 touch throw_err:' + JSON.stringify(err));
expect(err.code).assertEqual(401);
done();
}
}
try {
task = await request.agent.create(globalThis.abilityContext, config)
task.on('completed', onCompletedCallback)
await task.start()
task = await request.agent.create(globalThis.abilityContext, config);
task.on('completed', onCompletedCallback);
await task.start();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 create throw_err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0020 create throw_err:' + JSON.stringify(err));
expect().assertFail();
done();
}
......@@ -2028,26 +2034,27 @@ export default function requestDownloadTwoUnitTest() {
let task:request.agent.Task
async function onCompletedCallback(progress){
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 onCompletedCallback start')
task.off('completed');
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 onCompletedCallback start');
try{
// @ts-ignore
let taskInfo = await request.agent.touch(task.tid, {})
expect().assertFail()
let taskInfo = await request.agent.touch(task.tid, {});
expect().assertFail();
done();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 touch throw_err:' + JSON.stringify(err))
expect(err.code).assertEqual(401)
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 touch throw_err:' + JSON.stringify(err));
expect(err.code).assertEqual(401);
done();
}
}
try {
task = await request.agent.create(globalThis.abilityContext, config)
task.on('completed', onCompletedCallback)
await task.start()
task = await request.agent.create(globalThis.abilityContext, config);
task.on('completed', onCompletedCallback);
await task.start();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 create throw_err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Promise_0030 create throw_err:' + JSON.stringify(err));
expect().assertFail();
done();
}
......@@ -2075,27 +2082,28 @@ export default function requestDownloadTwoUnitTest() {
let task:request.agent.Task
function onCompletedCallback(progress){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 onCompletedCallback start')
task.off('completed');
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 onCompletedCallback start');
try{
request.agent.touch(task.tid, config.token+'1',(err, taskInfo)=>{
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch err:' + JSON.stringify(err))
expect(err.code).assertEqual(21900006)
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch err:' + JSON.stringify(err));
expect(err.code).assertEqual(21900006);
done();
})
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch throw_err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 touch throw_err:' + JSON.stringify(err));
expect().assertFail();
done();
}
}
try {
task = await request.agent.create(globalThis.abilityContext, config)
task.on('completed', onCompletedCallback)
await task.start()
task = await request.agent.create(globalThis.abilityContext, config);
task.on('completed', onCompletedCallback);
await task.start();
}catch(err){
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 create throw_err:' + JSON.stringify(err))
expect().assertFail()
console.debug('====>SUB_Misc_REQUEST_Touch_Callback_0040 create throw_err:' + JSON.stringify(err));
expect().assertFail();
done();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册