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

!6396 【上传下载】sleep modifed setTimeout

Merge pull request !6396 from 何海涛/r1105
......@@ -35,6 +35,8 @@ export default class MainAbility extends Ability {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
globalThis.abilityContext = this.context;
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
......
......@@ -19,34 +19,34 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
export default function requestDownloadJSUnit() {
describe('requestDownloadJSUnit', function () {
console.info('################################request download Test start');
console.info('====>################################request download Test start');
/**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
*/
beforeAll(function () {
console.info('beforeAll: Prerequisites are executed.');
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.');
console.info('====>beforeEach: Prerequisites is executed.');
});
/**
* afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
*/
afterEach(function () {
console.info('afterEach: Test case-level clearance conditions is executed.');
console.info('====>afterEach: Test case-level clearance conditions is executed.');
});
/**
* afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed.
*/
afterAll(function () {
console.info('afterAll: Test suite-level cleanup condition is executed');
console.info('====>afterAll: Test suite-level cleanup condition is executed');
});
let downloadTask;
......@@ -72,21 +72,24 @@ export default function requestDownloadJSUnit() {
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------");
console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------");
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
try {
request.download(context, downloadConfig, (data)=>{
request.download(context, downloadConfig, (err, data)=>{
downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
});
} catch (err) {
console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err);
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
done();
},5000)
});
/**
......@@ -97,19 +100,21 @@ export default function requestDownloadJSUnit() {
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 is starting-----------------------");
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 => {
downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
}).catch(err => {
console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err);
console.info("====>SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------");
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------");
done();
},5000)
});
});
}
\ No newline at end of file
......@@ -19,34 +19,34 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
export default function requestUploadJSUnit() {
describe('requestUploadJSUnit', function () {
console.info('################################request upload Test start');
console.info('====>################################request upload Test start');
/**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
*/
beforeAll(function () {
console.info('beforeAll: Prerequisites are executed.');
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.');
console.info('====>beforeEach: Prerequisites is executed.');
});
/**
* afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
*/
afterEach(function () {
console.info('afterEach: Test case-level clearance conditions is executed.');
console.info('====>afterEach: Test case-level clearance conditions is executed.');
});
/**
* afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed.
*/
afterAll(function () {
console.info('afterAll: Test suite-level cleanup condition is executed');
console.info('====>afterAll: Test suite-level cleanup condition is executed');
});
/**
......@@ -88,37 +88,38 @@ export default function requestUploadJSUnit() {
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------");
console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 context = " + appContext);
request.upload(appContext, uploadConfig, (data) => {
request.upload(globalThis.abilityContext, uploadConfig, (err, data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + uploadTask);
expect(true).assertEqual(uploadTask != undefined);
uploadTask.on('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data2 =" + data2);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data1 =" + data1);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data2 =" + data2);
});
uploadTask.off('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data2 =" + data2);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data1 =" + data1);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data2 =" + data2);
});
uploadTask.remove((err, data) => {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 remove =" + data);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 remove =" + data);
});
});
} catch (err) {
console.error("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 error: " + err);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
done();
}, 10000)
});
/*
......@@ -130,38 +131,142 @@ export default function requestUploadJSUnit() {
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 is starting-----------------------");
console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 context = " + appContext);
request.upload(appContext, uploadConfig).then((data) => {
request.upload(globalThis.abilityContext, uploadConfig).then((data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 uploadTask = " + uploadTask);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 uploadTask = " + uploadTask);
expect(true).assertEqual(uploadTask != undefined);
uploadTask.on('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.off('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.remove().then((result)=>{
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 remove result = " + result);
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 remove result = " + result);
expect(result).assertEqual(true);
});
});
} catch (e) {
console.error("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 error: " + JSON.stringify(e));
console.info("====>SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(e).assertFail();
}
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 end-----------------------");
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 end-----------------------");
done();
}, 10000)
});
/**
* @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0002
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Called when the current upload session complete or fail.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_PROMISE_0002', 0, async function (done) {
console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0002 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 UploadConfig = " + JSON.stringify(uploadConfig));
request.upload(globalThis.abilityContext, uploadConfig).then((data) => {
try{
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {}));
uploadTask.on('complete', (TaskState) => {
for(let i = 0; i < TaskState.length; i++){
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState = " + JSON.stringify(TaskState[i]))
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState.path = " + TaskState[i].path);
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState.responseCode = " + TaskState[i].responseCode);
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 complete TaskState.TaskState.message = " + TaskState[i].message);
expect(typeof(TaskState[i].path) == "string").assertEqual(true);
expect(typeof(TaskState[i].responseCode) == "number").assertEqual(true);
expect(typeof(TaskState[i].message) == "string").assertEqual(true);
}
done();
});
uploadTask.on('fail', (TaskState) => {
for(let i = 0; i < TaskState.length; i++){
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState = " + JSON.stringify(TaskState[i]))
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState.path = " + TaskState[i].path);
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState.responseCode = " + TaskState[i].responseCode);
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 fail TaskState.TaskState.message = " + TaskState[i].message);
expect(typeof(TaskState[i].path) == "string").assertEqual(true);
expect(typeof(TaskState[i].responseCode) == "number").assertEqual(true);
expect(typeof(TaskState[i].message) == "string").assertEqual(true);
}
expect(true).assertEqual(true);
});
}catch(err){
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(err));
expect(true).assertFail(true);
}
}).catch((err)=>{
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(err));
expect(true).assertFail(true);
})
} catch (e) {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0002 throw_error: " + JSON.stringify(e));
expect(true).assertFail(true);
}
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0002 end-----------------------");
done();
}, 10000)
});
/**
* @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0003
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Called when the current upload session complete or fail.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_PROMISE_0003', 0, async function (done) {
console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0003 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 UploadConfig = " + JSON.stringify(uploadConfig));
request.upload(globalThis.abilityContext, uploadConfig).then((data) => {
try{
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {}));
uploadTask.off('complete', () => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success");
expect(true).assertEqual(true);
});
uploadTask.off('fail', () => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 TaskState success");
expect(true).assertEqual(true);
});
}catch(err){
expect().assertFail();
done();
}
});
} catch (e) {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0003 error: " + JSON.stringify(e));
expect(true).assertFail(true);
}
setTimeout(()=>{
console.info("====>------------------SUB_REQUEST_UPLOAD_API_PROMISE_0003 end-----------------------");
done();
}, 10000)
});
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册