diff --git a/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets index 1ff8fa6ce67227af1fa30239138f13847fff4177..3b2c266ccdda1cbdae970a5c0d41033e05c8884e 100644 --- a/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets @@ -37,12 +37,35 @@ export default function abilityTest() { Subscriber.publish("ACTS_AddAbilityMonitor_0100", AddAbilityData, publishCallback); } console.debug("====>ACTS_AddAbilityMonitor_0100 start====>"); - var AddAbilityData + var AddAbilityData; var commonEventSubscribeInfo = { events: ["ACTS_AddAbilityMonitor_0100"] }; - var data = abilityDelegatorRegistry.getAbilityDelegator() - console.log("0100getAbilityDelegator data is" + JSON.stringify(data)) + var data = abilityDelegatorRegistry.getAbilityDelegator(); + console.log("0100getAbilityDelegator data is" + JSON.stringify(data)); + Subscriber.createSubscriber(commonEventSubscribeInfo, async (err, data) => { + console.info("===ACTS_AddAbilityMonitor_0100===createSubscriber" + JSON.stringify(data)); + var AddAbility = data; + await Subscriber.subscribe(AddAbility, (err, data) => { + console.log('===ACTS_AddAbilityMonitor_0100CallBack===' + + err.code + JSON.stringify(data)); + Subscriber.unsubscribe(AddAbility, (err, data) => { + console.log('===UnSubscribeCallBacka===' + err.code); + }); + if (data.code == 1) { + expect(data.code).assertEqual(1); + setTimeout(() => { + done(); + }, 2500); + } + else { + expect().assertFail(); + setTimeout(() => { + done(); + }, 2500); + } + }); + }); data.addAbilityMonitor( { abilityName: 'MainAbility2', @@ -55,31 +78,8 @@ export default function abilityTest() { abilityName: 'MainAbility2' }).then(async () => { console.debug("====>0100startAbility success====>"); - await Subscriber.createSubscriber(commonEventSubscribeInfo, async (err, data) => { - console.info("===ACTS_AddAbilityMonitor_0100===createSubscriber" + JSON.stringify(data)); - var AddAbility = data - await Subscriber.subscribe(AddAbility, (err, data) => { - console.log('===ACTS_AddAbilityMonitor_0100CallBack===' - + err.code + JSON.stringify(data)) - Subscriber.unsubscribe(AddAbility, (err, data) => { - console.log('===UnSubscribeCallBacka===' + err.code) - }) - if (data.code == 1) { - expect(data.code).assertEqual(1); - setTimeout(() => { - done(); - }, 2500) - } - else { - expect().assertFail(); - setTimeout(() => { - done(); - }, 2500) - } - }) - }) - }) - })) + }); + })); }) /** @@ -176,7 +176,7 @@ export default function abilityTest() { console.info("===ACTS_AddAbilityMonitor_0300===createSubscriber" + JSON.stringify(data)); var AddAbility = data Delegator.getCurrentTopAbility().then((ability) => { - console.info("===ACTS_AddAbilityMonitor_0300===ability" + JSON.stringify(ability)); + console.info("===ACTS_AddAbilityMonitor_0300===ability " + JSON.stringify(ability).length); Subscriber.subscribe(AddAbility, (err, data) => { console.log('===ACTS_AddAbilityMonitor_0300CallBack===' + err.code + JSON.stringify(data)) @@ -198,9 +198,12 @@ export default function abilityTest() { } }) Delegator.doAbilityBackground(ability).then(async (data) => { - console.info("===ACTS_AddAbilityMonitor_0300===data" + JSON.stringify(data)); - expect(data).assertEqual(true) - }) + console.info("===ACTS_AddAbilityMonitor_0300===data succeed."); + expect(true).assertTrue(); + }).catch((err: any) => { + console.info("===ACTS_AddAbilityMonitor_0300===data failed."); + expect(false).assertTrue(); + }); }) }) } @@ -655,10 +658,10 @@ export default function abilityTest() { console.info("===ACTS_AddAbilityMonitor_1000===createSubscriber" + JSON.stringify(data)); var AddAbility = data Delegator.getCurrentTopAbility().then((ability) => { - console.info("===ACTS_AddAbilityMonitor_1000===ability" + JSON.stringify(ability)); - Delegator.doAbilityBackground(ability).then(async (data) => { - console.info("===ACTS_AddAbilityMonitor_1000===data" + JSON.stringify(data)); - expect(data).assertEqual(true) + console.info("===ACTS_AddAbilityMonitor_1000===ability" + JSON.stringify(ability).length); + Delegator.doAbilityBackground(ability).then(async () => { + console.info("===ACTS_AddAbilityMonitor_1000===data succeed."); + expect(true).assertTrue(); await Subscriber.subscribe(AddAbility, (err, data) => { console.log('===ACTS_AddAbilityMonitor_1000CallBack===' + err.code + JSON.stringify(data)) @@ -679,7 +682,10 @@ export default function abilityTest() { }, 2500) } }) - }) + }).catch(() => { + console.info("===ACTS_AddAbilityMonitor_1000===data succeed."); + expect(false).assertTrue(); + }); }) }) } diff --git a/ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/test/Ability.test.ets index dac97ad3472130d12198aca872ee7613615b7d33..d3b071b019583962df1a9f86277bdd2e9b2f700f 100644 --- a/ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/test/Ability.test.ets @@ -35,9 +35,9 @@ export default function abilityTest() { abilityDelegator.getCurrentTopAbility((err, data)=>{ console.debug("====>getCurrentTopAbility_0200 err:" + JSON.stringify(err) + " data:" + JSON.stringify(data)); ability = data; - abilityDelegator.doAbilityBackground(ability, (err, isBackground)=>{ - console.debug("====>doAbilityBackground_0200 data:" + JSON.stringify(isBackground)); - expect(isBackground).assertTrue(); + abilityDelegator.doAbilityBackground(ability, (err)=>{ + console.debug("====>doAbilityBackground_0200 data:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); }) }) } @@ -98,9 +98,9 @@ export default function abilityTest() { expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.FOREGROUND); expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.CREATE).assertTrue() expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.DESTROY).assertTrue() - abilityDelegator.doAbilityBackground(ability, (err, isBackground)=>{ - console.debug("====>doAbilityBackground_0300 data:" + JSON.stringify(isBackground)); - expect(isBackground).assertTrue(); + abilityDelegator.doAbilityBackground(ability, (err)=>{ + console.debug("====>doAbilityBackground_0300 data:" + JSON.stringify(err)); + expect(err.code).assertEqual(0); console.debug("====>ACTS_GetAbilityState_0300 end===="); flag=false; done(); diff --git a/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets index 0c35f894b798b88adabdbc5146a8506c179a308e..eb0aea66ba796ced69d76dce81c8063530469505 100644 --- a/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets @@ -54,9 +54,9 @@ export default function abilityTest() { function SubscribeCallBack(err, data) { expect(data.event == "ACTS_DoAbility_Event").assertTrue(); console.log("====>0100 Subscribe CallBack data:====>" + JSON.stringify(data)); - globalThis.abilitydelegator.doAbilityForeground(ability, (err, data) => { - console.log("====>ACTS_DoAbilityForeground_0100 data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability, (err) => { + console.log("====>ACTS_DoAbilityForeground_0100 data:====>" + JSON.stringify(err)); + expect(err.code).assertEqual(0); setTimeout(() => { var num = globalThis.abilitydelegator.getAbilityState(ability) console.log("====>ACTS_DoAbilityForeground_0100 getAbilityState:====>" + JSON.stringify(num)); @@ -108,9 +108,9 @@ export default function abilityTest() { ability = data expect(JSON.stringify(data) == JSON.stringify(mainability)).assertTrue(); console.log("====>getCurrentTopAbility ability data:====>" + JSON.stringify(ability)); - globalThis.abilitydelegator.doAbilityForeground(ability, (err, data) => { - console.log("====>ACTS_DoAbilityForeground_0200 data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability, (err) => { + console.log("====>ACTS_DoAbilityForeground_0200 data:====>" + JSON.stringify(err)); + expect(err.code).assertEqual(0); setTimeout(() => { var num = globalThis.abilitydelegator.getAbilityState(ability) console.log("====>ACTS_DoAbilityForeground_0200 getAbilityState:====>" + JSON.stringify(num)); @@ -143,9 +143,9 @@ export default function abilityTest() { function SubscribeCallBack(err, data) { expect(data.event == "ACTS_DoAbility_Event").assertTrue(); console.log("====>0400 Subscribe CallBack data:====>" + JSON.stringify(data)); - globalThis.abilitydelegator.doAbilityForeground(ability).then((data) => { - console.log("====>ACTS_DoAbilityForeground_0400 data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability).then(() => { + console.log("====>ACTS_DoAbilityForeground_0400 data:====>"); + expect(true).assertTrue(); setTimeout(() => { var num = globalThis.abilitydelegator.getAbilityState(ability) console.log("====>ACTS_DoAbilityForeground_0400 getAbilityState:====>" + JSON.stringify(num)); @@ -198,9 +198,9 @@ export default function abilityTest() { console.log("====>getCurrentTopAbility mainability:====>" + JSON.stringify(mainability)); expect(JSON.stringify(data) == JSON.stringify(mainability)).assertTrue(); console.log("====>getCurrentTopAbility ability data:====>" + JSON.stringify(ability)); - globalThis.abilitydelegator.doAbilityForeground(ability).then((data) => { - console.log("====>ACTS_DoAbilityForeground_0500 data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability).then(() => { + console.log("====>ACTS_DoAbilityForeground_0500 data:====>"); + expect(true).assertTrue(); setTimeout(() => { var num = globalThis.abilitydelegator.getAbilityState(ability) console.log("====>ACTS_DoAbilityForeground_0500 getAbilityState:====>" + JSON.stringify(num)); @@ -235,9 +235,9 @@ export default function abilityTest() { console.log("====>0100 Subscribe CallBack data:====>" + JSON.stringify(data)); globalThis.abilitydelegator.getCurrentTopAbility().then((ability) => { console.log("====>getCurrentTopAbility ability data:====>" + JSON.stringify(ability)); - globalThis.abilitydelegator.doAbilityBackground(ability, (err, data1) => { - console.log("====>ACTS_DoAbilityBackground_0100 data:====>" + JSON.stringify(data1)); - expect(data1).assertEqual(true); + globalThis.abilitydelegator.doAbilityBackground(ability, (err) => { + console.log("====>ACTS_DoAbilityBackground_0100 data:====>"); + expect(err.code).assertEqual(0); setTimeout(() => { var num = globalThis.abilitydelegator.getAbilityState(ability) console.log("====>ACTS_DoAbilityBackground_0100 getAbilityState:====>" + JSON.stringify(num)); @@ -296,9 +296,9 @@ export default function abilityTest() { console.log("====>0500 Subscribe CallBack data:====>" + JSON.stringify(data)); globalThis.abilitydelegator.getCurrentTopAbility().then((ability2) => { console.log("====>getCurrentTopAbility ability2 data:====>" + JSON.stringify(ability2)); - globalThis.abilitydelegator.doAbilityBackground(ability2).then((data1) => { - console.log("====>ACTS_DoAbilityBackground_0500 data:====>" + JSON.stringify(data1)); - expect(data1).assertEqual(true); + globalThis.abilitydelegator.doAbilityBackground(ability2).then(() => { + console.log("====>ACTS_DoAbilityBackground_0500 data:====>"); + expect(true).assertTrue(); setTimeout(() => { var num = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0500 getAbilityState:====>" + JSON.stringify(num)); @@ -357,32 +357,32 @@ export default function abilityTest() { globalThis.abilitydelegator.getCurrentTopAbility().then((ability2) => { console.log("====>getCurrentTopAbility ability2 data:====>" + JSON.stringify(ability2)); console.log("====>0700newabilityname:====>" + JSON.stringify(ability2.context.abilityInfo.name)); - globalThis.abilitydelegator.doAbilityBackground(ability2).then((data1) => { - console.log("====>doAbilityBackground data1:====>" + JSON.stringify(data1)); - expect(data1).assertEqual(true); + globalThis.abilitydelegator.doAbilityBackground(ability2).then(() => { + console.log("====>doAbilityBackground data1:====>"); + expect(true).assertTrue(); setTimeout(() => { num1 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0700 getAbilityState1:====>" + " " + JSON.stringify(num1)); expect(num1).assertEqual(3); - globalThis.abilitydelegator.doAbilityForeground(ability2, (err, data) => { - console.log("====>doAbilityForeground data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability2, (err) => { + console.log("====>doAbilityForeground data:====>" + JSON.stringify(err)); + expect(err.code).assertEqual(0); setTimeout(() => { num2 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0700 getAbilityState2:====>" + " " + JSON.stringify(num2)); expect(num2).assertEqual(2); - globalThis.abilitydelegator.doAbilityBackground(ability2).then((data1) => { - console.log("====>doAbilityBackground data1:====>" + JSON.stringify(data1)); - expect(data1).assertEqual(true); + globalThis.abilitydelegator.doAbilityBackground(ability2).then(() => { + console.log("====>doAbilityBackground data1:====>"); + expect(true).assertTrue(); setTimeout(() => { num1 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0700 getAbilityState1:====>" + " " + JSON.stringify(num1)); expect(num1).assertEqual(3); - globalThis.abilitydelegator.doAbilityForeground(ability2, (err, data) => { - console.log("====>doAbilityForeground data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability2, (err) => { + console.log("====>doAbilityForeground data:====>"); + expect(err.code).assertEqual(0); setTimeout(() => { num2 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0700 getAbilityState2:====>" + @@ -448,32 +448,32 @@ export default function abilityTest() { globalThis.abilitydelegator.getCurrentTopAbility().then((ability2) => { console.log("====>getCurrentTopAbility ability2 data:====>" + JSON.stringify(ability2)); console.log("====>0800newabilityname:====>" + JSON.stringify(ability2.context.abilityInfo.name)); - globalThis.abilitydelegator.doAbilityBackground(ability2, (err, data1) => { - console.log("====>doAbilityBackground data1:====>" + JSON.stringify(data1)); - expect(data1).assertEqual(true); + globalThis.abilitydelegator.doAbilityBackground(ability2, (err) => { + console.log("====>doAbilityBackground data1:====>" + JSON.stringify(err)); + expect(err.code).assertEqual(0); setTimeout(() => { num1 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0800 getAbilityState1:====>" + " " + JSON.stringify(num1)); expect(num1).assertEqual(3); - globalThis.abilitydelegator.doAbilityForeground(ability2).then((data) => { - console.log("====>doAbilityForeground data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability2).then(() => { + console.log("====>doAbilityForeground data:====>"); + expect(true).assertTrue(); setTimeout(() => { num2 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0800 getAbilityState2:====>" + " " + JSON.stringify(num2)); expect(num2).assertEqual(2); - globalThis.abilitydelegator.doAbilityBackground(ability2, (err, data1) => { - console.log("====>doAbilityBackground data1:====>" + JSON.stringify(data1)); - expect(data1).assertEqual(true); + globalThis.abilitydelegator.doAbilityBackground(ability2, (err) => { + console.log("====>doAbilityBackground data1:====>" + JSON.stringify(err)); + expect(err.code).assertEqual(0); setTimeout(() => { num1 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0800 getAbilityState1:====>" + " " + JSON.stringify(num1)); expect(num1).assertEqual(3); - globalThis.abilitydelegator.doAbilityForeground(ability2).then((data) => { - console.log("====>doAbilityForeground data:====>" + JSON.stringify(data)); - expect(data).assertEqual(true); + globalThis.abilitydelegator.doAbilityForeground(ability2).then(() => { + console.log("====>doAbilityForeground data:====>"); + expect(true).assertTrue(); setTimeout(() => { num2 = globalThis.abilitydelegator.getAbilityState(ability2) console.log("====>ACTS_DoAbilityBackground_0800 getAbilityState2:====>" + @@ -538,9 +538,9 @@ export default function abilityTest() { console.log("====>0300 Subscribe CallBack globalThis.ability3:====>" + JSON.stringify(globalThis.ability3)); console.log("====>0300 ability3 name:====>" + JSON.stringify(globalThis.ability3.context.abilityInfo.name)); setTimeout(() => { - result = globalThis.abilitydelegator.doAbilityForeground(globalThis.ability3, (err, data) => { - console.log("====>ACTS_DoAbilityForeground_0300 data:====>" + JSON.stringify(data)); - expect().assertFail(); + result = globalThis.abilitydelegator.doAbilityForeground(globalThis.ability3, (err) => { + console.log("====>ACTS_DoAbilityForeground_0300 data:====>" + JSON.stringify(err)); + expect(err.code).assertEqual(0); }) console.log("====>0300 result:====>" + JSON.stringify(result)); expect(result).assertEqual(undefined); @@ -645,9 +645,9 @@ export default function abilityTest() { expect(data.event == "ACTS_DoAbility_Event").assertTrue(); console.log("====>0300 Subscribe CallBack data:====>" + JSON.stringify(data)); setTimeout(() => { - result = globalThis.abilitydelegator.doAbilityBackground(globalThis.ability3, (err, data) => { - console.log("====>ACTS_DoAbilityBackground_0300 data:====>" + JSON.stringify(data)); - expect().assertFail(); + result = globalThis.abilitydelegator.doAbilityBackground(globalThis.ability3, (err) => { + console.log("====>ACTS_DoAbilityBackground_0300 data:====>" + JSON.stringify(err)); + expect(err.code).assertEqual(0); }) console.log("====>DoAbilityBackground0300 result:====>" + JSON.stringify(result)); expect(result).assertEqual(undefined); diff --git a/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsfreeinstallstartabilitystagetest/entry/src/main/ets/test/StartAbilityTest.ets b/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsfreeinstallstartabilitystagetest/entry/src/main/ets/test/StartAbilityTest.ets index cbf143e20e9ca0be58ac8d424d86e992c4132e8c..36330f2b799f2fa06b9bf10300ecc060b701b7ef 100644 --- a/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsfreeinstallstartabilitystagetest/entry/src/main/ets/test/StartAbilityTest.ets +++ b/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsfreeinstallstartabilitystagetest/entry/src/main/ets/test/StartAbilityTest.ets @@ -132,14 +132,14 @@ export default function startAbilityTest(abilityContext) { }); async function abilityForeground(tag) { - globalThis.delegator.doAbilityForeground(globalThis.ability, (err: any, data: any) => { - console.info(tag + "doAbilityForeground err: " + JSON.stringify(err) + ", data: " + JSON.stringify(data)); + globalThis.delegator.doAbilityForeground(globalThis.ability, (err: any) => { + console.info(tag + "doAbilityForeground err: " + JSON.stringify(err)); }); } async function abilityBackground(tag) { - globalThis.delegator.doAbilityBackground(globalThis.ability, (err: any, data: any) => { - console.info(tag + "abilityBackground err: " + JSON.stringify(err) + ", data: " + JSON.stringify(data)); + globalThis.delegator.doAbilityBackground(globalThis.ability, (err: any) => { + console.info(tag + "abilityBackground err: " + JSON.stringify(err)); }); } diff --git a/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsstartabilitynotargetbundleliststagetest/entry/src/main/ets/test/StartAbilityTest.ets b/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsstartabilitynotargetbundleliststagetest/entry/src/main/ets/test/StartAbilityTest.ets index 1f0e8793d2fe0ae636b57e06a0115556d1a168cd..fb68ce96d77fcd72fd6da802cef20102e4421378 100644 --- a/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsstartabilitynotargetbundleliststagetest/entry/src/main/ets/test/StartAbilityTest.ets +++ b/ability/ability_runtime/freeinstalltest/startabilitystagetest/actsstartabilitynotargetbundleliststagetest/entry/src/main/ets/test/StartAbilityTest.ets @@ -87,8 +87,8 @@ export default function startAbilityTest(abilityContext) { }); async function abilityForeground(tag) { - globalThis.delegator.doAbilityForeground(globalThis.ability, (err: any, data: any) => { - console.info(tag + "doAbilityForeground err:" + JSON.stringify(err) + ", data:" + JSON.stringify(data)); + globalThis.delegator.doAbilityForeground(globalThis.ability, (err: any) => { + console.info(tag + "doAbilityForeground err:" + JSON.stringify(err)); }); }