提交 1f143934 编写于 作者: Z zwx1016320

add request API

Signed-off-by: Nzwx1016320 <zhangyushuai1@huawei-partners.com>
上级 4c984031
......@@ -116,5 +116,92 @@ export default function requestDownloadJSUnit() {
done();
},5000)
});
/**
* @tc.number SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
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 downloadFileConfig = {
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: downloadFilePath,
title: 'XTS download test!',
background: true
}
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();
});
/**
* @tc.number SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
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 downloadFileConfig = {
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: downloadFilePath,
title: 'XTS download test!',
background: true
}
try{
request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(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);
}
}).catch(err => {
console.error("SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
}catch(err){
console.error("SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err);
}
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 end-----------------------");
done();
});
});
}
\ No newline at end of file
......@@ -268,5 +268,66 @@ export default function requestUploadJSUnit() {
done();
}, 10000)
});
/**
* @tc.number SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data)=>{
uploadTask = data;
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);
}
});
} catch (err) {
console.error("SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
};
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------");
done();
}, 10000);
});
/**
* @tc.number SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
try{
request.uploadFile(globalThis.abilityContext, uploadConfig).then(data => {
uploadTask = data;
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);
}
}).catch(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);
}
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------");
done();
}, 10000);
});
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册