提交 b2bb98f4 编写于 作者: Z zhangyushuai

request用例优化 004

Signed-off-by: Nzhangyushuai <zhangyushuai1@huawei.com>
上级 6c59d190
...@@ -24,13 +24,6 @@ export default function imeAbilityTest(abilityContext) { ...@@ -24,13 +24,6 @@ export default function imeAbilityTest(abilityContext) {
id:'', id:'',
extra:{} extra:{}
} }
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
/** /**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
...@@ -75,12 +68,14 @@ export default function imeAbilityTest(abilityContext) { ...@@ -75,12 +68,14 @@ export default function imeAbilityTest(abilityContext) {
} }
inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{ inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{
console.info('====>SUB_InputMethod_IMEAbility_0004 switchInputMethod to IME :' + data); console.info('====>SUB_InputMethod_IMEAbility_0001 switchInputMethod to IME :' + data);
expect(data == true).assertTrue(); expect(data == true).assertTrue();
}); });
sleep(Date.now(), 3000); let t = setTimeout(() => {
console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------'); console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------' + t);
clearTimeout(t);
done(); done();
}, 500);
}) })
/** /**
...@@ -105,9 +100,11 @@ export default function imeAbilityTest(abilityContext) { ...@@ -105,9 +100,11 @@ export default function imeAbilityTest(abilityContext) {
console.info('====>SUB_InputMethod_IMEAbility_0002 switchInputMethod to IME :' + data); console.info('====>SUB_InputMethod_IMEAbility_0002 switchInputMethod to IME :' + data);
expect(data == true).assertTrue(); expect(data == true).assertTrue();
}); });
sleep(Date.now(), 2500); let t = setTimeout(() => {
console.info('====>-----------SUB_InputMethod_IMEAbility_0002 end-------------'); console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------' + t);
clearTimeout(t);
done(); done();
}, 500);
}) })
}) })
} }
...@@ -59,7 +59,7 @@ export default class OpenHarmonyTestRunner implements TestRunner { ...@@ -59,7 +59,7 @@ export default class OpenHarmonyTestRunner implements TestRunner {
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); 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", abilityDelegator.executeShellCommand("echo \"123456\" > /data/app/el2/100/base/com.acts.request.test/haps/entry_test/cache/test.txt",
(err: any, d: any) => { (err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err)); console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult); console.info('executeShellCommand : data : ' + d.stdResult);
......
...@@ -89,8 +89,7 @@ export default function requestUploadJSUnit() { ...@@ -89,8 +89,7 @@ export default function requestUploadJSUnit() {
it('SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) { it('SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------"); console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
try { try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data)=>{ request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask)=>{
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{ try{
expect(true).assertEqual(uploadTask != undefined); expect(true).assertEqual(uploadTask != undefined);
...@@ -101,8 +100,9 @@ export default function requestUploadJSUnit() { ...@@ -101,8 +100,9 @@ export default function requestUploadJSUnit() {
} catch (err) { } catch (err) {
console.error("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err); console.error("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
}; };
setTimeout(()=>{ let t = setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------"); console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------");
clearTimeout(t);
done(); done();
}, 10000); }, 10000);
}); });
...@@ -117,8 +117,7 @@ export default function requestUploadJSUnit() { ...@@ -117,8 +117,7 @@ export default function requestUploadJSUnit() {
it('SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) { it('SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------"); console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
try{ try{
request.uploadFile(globalThis.abilityContext, uploadConfig).then(data => { request.uploadFile(globalThis.abilityContext, uploadConfig).then(uploadTask => {
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{ try{
expect(true).assertEqual(uploadTask != undefined); expect(true).assertEqual(uploadTask != undefined);
...@@ -132,8 +131,9 @@ export default function requestUploadJSUnit() { ...@@ -132,8 +131,9 @@ export default function requestUploadJSUnit() {
}catch(err){ }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(()=>{ let t = setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------"); console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------");
clearTimeout(t);
done(); done();
}, 10000); }, 10000);
}); });
...@@ -147,9 +147,8 @@ export default function requestUploadJSUnit() { ...@@ -147,9 +147,8 @@ export default function requestUploadJSUnit() {
*/ */
it('SUB_REQUEST_UPLOAD_API_DELETE_0001', 0, async function (done) { it('SUB_REQUEST_UPLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------"); console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
try{ try{
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask); console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true); expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => { uploadTask.delete((err, data) => {
...@@ -184,8 +183,7 @@ export default function requestUploadJSUnit() { ...@@ -184,8 +183,7 @@ export default function requestUploadJSUnit() {
*/ */
it('SUB_REQUEST_UPLOAD_API_DELETE_0002', 0, async function (done) { it('SUB_REQUEST_UPLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------"); console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask); console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
try{ try{
expect(uploadTask != undefined).assertEqual(true); expect(uploadTask != undefined).assertEqual(true);
......
...@@ -49,13 +49,6 @@ export default function requestUploadJSUnit() { ...@@ -49,13 +49,6 @@ export default function requestUploadJSUnit() {
console.info('====>afterAll: Test suite-level cleanup condition is executed'); console.info('====>afterAll: Test suite-level cleanup condition is executed');
}); });
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
let uploadTask; let uploadTask;
let RequestData = { let RequestData = {
name: 'name', name: 'name',
...@@ -265,11 +258,9 @@ export default function requestUploadJSUnit() { ...@@ -265,11 +258,9 @@ export default function requestUploadJSUnit() {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 is starting-----------------------"); console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 is starting-----------------------");
try { try {
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig)); console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
request.upload(uploadConfig, (err, data) => { request.upload(uploadConfig, (err, uploadTask) => {
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask)); console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true); expect(uploadTask != undefined).assertEqual(true);
uploadTask.on('progress', function (data1, data2) { uploadTask.on('progress', function (data1, data2) {
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data1 =" + data1); console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data1 =" + data1);
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data2 =" + data2); console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data2 =" + data2);
...@@ -282,15 +273,15 @@ export default function requestUploadJSUnit() { ...@@ -282,15 +273,15 @@ export default function requestUploadJSUnit() {
uploadTask.remove((err, data) => { uploadTask.remove((err, data) => {
console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 remove =" + data); console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 remove =" + data);
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------");
done();
}); });
}); });
} catch (err) { } catch (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err); console.error("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err);
expect().assertFail(); expect().assertFail();
} }
sleep(Date.now(), 20000);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------");
done();
}); });
/** /**
...@@ -305,33 +296,30 @@ export default function requestUploadJSUnit() { ...@@ -305,33 +296,30 @@ export default function requestUploadJSUnit() {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------"); console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------");
try { try {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
request.upload(uploadConfig).then((data) => { request.upload(uploadConfig).then((uploadTask) => {
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask); console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {})); expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('headerReceive', (header) => { uploadTask.on('headerReceive', (header) => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header); console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); expect(true).assertEqual((header != {} || header != undefined));
}); });
uploadTask.off('headerReceive', (header) => { uploadTask.off('headerReceive', (header) => {
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header); console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); expect(true).assertEqual((header != {} || header != undefined));
}); });
uploadTask.remove().then((result)=>{ uploadTask.remove().then((result)=>{
console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 remove result = " + result); console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 remove result = " + result);
expect(result).assertEqual(true); expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------");
done();
}); });
}); });
} catch (e) { } 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); expect(true).assertFail(true);
} }
sleep(Date.now(), 20000);
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------");
done();
}); });
}) })
} }
...@@ -170,7 +170,7 @@ export default function screenLockJSUnit() { ...@@ -170,7 +170,7 @@ export default function screenLockJSUnit() {
screenLock.isSecureMode((err, data) => { screenLock.isSecureMode((err, data) => {
try{ try{
console.info("====>SUB_MISC_THEME_screenLock_API_0003 secureMode's result is " + data); console.info("====>SUB_MISC_THEME_screenLock_API_0003 secureMode's result is " + data);
expect(data == result).assertTrue(); expect(data == false).assertTrue();
console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0003-------------------"); console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0003-------------------");
done(); done();
}catch(err){ }catch(err){
...@@ -288,7 +288,7 @@ export default function screenLockJSUnit() { ...@@ -288,7 +288,7 @@ export default function screenLockJSUnit() {
try{ try{
secured = screenLock.isSecure() secured = screenLock.isSecure()
console.info('====>SUB_MISC_THEME_screenLock_API_0011 data : ' + JSON.stringify(secured)); console.info('====>SUB_MISC_THEME_screenLock_API_0011 data : ' + JSON.stringify(secured));
if (typeof secured == "boolean") { if (secured == false) {
expect(true).assertTrue(); expect(true).assertTrue();
console.info('====>-------------SUB_MISC_THEME_screenLock_API_0011 end----------------------'); console.info('====>-------------SUB_MISC_THEME_screenLock_API_0011 end----------------------');
done() done()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册