diff --git a/ability/ability_runtime/newwant/actsnewwantarelyhap/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/newwant/actsnewwantarelyhap/entry/src/main/ets/MainAbility/MainAbility.ts index 0389de11ea41bb4a341a79de6ee303906eb70669..950088fc292fc6cd326ff6121b47cf943ebbb19c 100644 --- a/ability/ability_runtime/newwant/actsnewwantarelyhap/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/newwant/actsnewwantarelyhap/entry/src/main/ets/MainAbility/MainAbility.ts @@ -89,11 +89,6 @@ export default class MainAbility extends Ability { console.log("ACTS_NewWant Publish CallBack onNewWantMain_To_Test_CommonEvent") }); switch (want.action) { - case 'restartHapB': - commonEvent.publish("onNewWantMain1_To_Test_CommonEvent", publishData, () => { - console.log("ACTS_NewWant Publish CallBack onNewWantMain1_To_Test_CommonEvent") - }); - break; case 'restartHapC': commonEvent.publish("onNewWantMain2_To_Test_CommonEvent", publishData, () => { console.log("ACTS_NewWant Publish CallBack onNewWantMain2_To_Test_CommonEvent") diff --git a/ability/ability_runtime/newwant/actsnewwantbrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/newwant/actsnewwantbrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts index 737b598be61dd0e14a5dc766682edb873ae47268..70dd29e22def32f76e65823d8a300886ce0899a8 100644 --- a/ability/ability_runtime/newwant/actsnewwantbrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/newwant/actsnewwantbrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts @@ -88,5 +88,12 @@ export default class MainAbility extends Ability { commonEvent.publish("onNewWantMain_To_Test_CommonEvent", publishData, () => { console.log("ACTS_NewWant Publish CallBack onNewWantMain_To_Test_CommonEvent") }); + switch (want.action) { + case 'restartHapB': + commonEvent.publish("onNewWantMain1_To_Test_CommonEvent", publishData, () => { + console.log("ACTS_NewWant Publish CallBack onNewWantMain1_To_Test_CommonEvent") + }); + break; + } } }; diff --git a/ability/ability_runtime/newwant/actsnewwantrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/newwant/actsnewwantrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts index 4ec9dbc6a38e08051fd0c4e7811c63f4c8578e01..8dbd22aa90fc244b2217842c1deaafb29e75d487 100644 --- a/ability/ability_runtime/newwant/actsnewwantrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/newwant/actsnewwantrelyhap/entry/src/main/ets/MainAbility/MainAbility.ts @@ -80,6 +80,16 @@ export default class MainAbility extends Ability { + JSON.stringify(error) + ", " + JSON.stringify(data)) }) } + if (globalThis.abilityWant.action == 'startMainAbility0800') { + globalThis.abilityContext.startAbility({ + bundleName: "com.example.newwanthap", + abilityName: "com.example.newwanthapa.SecondAbility", + action: "startSecondAbility0800" + }, (error, data) => { + console.log('ACTS_NewWant MainAbility onForeground - startAbility startServiceAbility: ' + + JSON.stringify(error) + ", " + JSON.stringify(data)) + }) + } commonEvent.publish("onForegroundMain_To_Test_CommonEvent", () => { console.log("ACTS_NewWant MainAbility Publish CallBack onForegroundMain_To_Test_CommonEvent") }); @@ -102,9 +112,23 @@ export default class MainAbility extends Ability { console.log("ACTS_NewWant MainAbility onNewWant type :" + want.type) console.log("ACTS_NewWant MainAbility onNewWant flags :" + want.flags) console.log("ACTS_NewWant MainAbility onNewWant action :" + want.action) - + var publishData = { + data: want.action + } commonEvent.publish("onNewWantMain_To_Test_CommonEvent", () => { console.log("ACTS_NewWant MainAbility Publish CallBack onNewWantMain_To_Test_CommonEvent") }); + switch (want.action) { + case 'restartHapB': + commonEvent.publish("onNewWantSecond1_To_Test_CommonEvent", publishData,() => { + console.log("ACTS_NewWant SecondAbility Publish CallBack onNewWantSecond1_To_Test_CommonEvent") + }); + break; + case 'restartSecondAbility0700': + commonEvent.publish("onNewWantSecond2_To_Test_CommonEvent", publishData,() => { + console.log("ACTS_NewWant SecondAbility Publish CallBack onNewWantSecond2_To_Test_CommonEvent") + }); + break; + } } }; diff --git a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets index 0887c61ed3507706a86f0bd5e0b6bd2cf0c8a31a..9c9d001cd26b5f06f0ab17323544529c3842114b 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets @@ -16,7 +16,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index" import commonEvent from '@ohos.commonEvent' -var subscriberInfo = { +let subscriberInfo = { events: ['onCreateMain_To_Test_CommonEvent', 'onWindowStageCreateMain_To_Test_CommonEvent', 'onForegroundMain_To_Test_CommonEvent', @@ -33,6 +33,8 @@ var subscriberInfo = { ], }; +let flagNewWant = false; + export default function abilityTest(abilityContext) { describe('ActsNewWantTest', function () { @@ -43,13 +45,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0100', 0, async function (done) { console.log("ACTS_NewWant_Test_0100 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0100====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -94,17 +96,14 @@ export default function abilityTest(abilityContext) { + flagOnNewWant) if (flagOnCreate == 1 && flagOnWindowStageCreate == 1 && flagOnForeground == 1 && flagOnNewWant == 0) { - expect(flagOnCreate).assertEqual(1); - expect(flagOnWindowStageCreate).assertEqual(1); - expect(flagOnForeground).assertEqual(1); - expect(flagOnNewWant).assertEqual(0); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } - done() } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0100====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } }) @@ -116,13 +115,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0200', 0, async function (done) { console.log("ACTS_NewWant_Test_0200 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0200====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -166,17 +165,14 @@ export default function abilityTest(abilityContext) { + flagOnNewWant) if (flagOnCreate == 1 && flagOnWindowStageCreate == 1 && flagOnForeground == 1 && flagOnNewWant == 0) { - expect(flagOnCreate).assertEqual(1); - expect(flagOnWindowStageCreate).assertEqual(1); - expect(flagOnForeground).assertEqual(1); - expect(flagOnNewWant).assertEqual(0); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } - done() } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0200====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } }) @@ -188,13 +184,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0300', 0, async function (done) { console.log("ACTS_NewWant_Test_0300 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0300====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -240,15 +236,13 @@ export default function abilityTest(abilityContext) { if (flagOnCreate == 2 && flagOnWindowStageCreate == 2 && flagOnForeground == 2 && flagOnNewWant == 0) { - expect(flagOnCreate).assertEqual(2); - expect(flagOnWindowStageCreate).assertEqual(2); - expect(flagOnForeground).assertEqual(2); - expect(flagOnNewWant).assertEqual(0); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0300====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } }) @@ -260,13 +254,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0400', 0, async function (done) { console.log("ACTS_NewWant_Test_0400 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0400====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -311,19 +305,16 @@ export default function abilityTest(abilityContext) { console.debug("ACTS_NewWant_Test_0400====>flagOnNewWant:====>" + flagOnNewWant) - if (flagOnCreate == 1 && flagOnWindowStageCreate == 1 + if (flagOnCreate == 0 && flagOnWindowStageCreate == 0 && flagOnForeground == 2 && flagOnNewWant == 1) { - expect(flagOnCreate).assertEqual(1); - expect(flagOnWindowStageCreate).assertEqual(1); - expect(flagOnForeground).assertEqual(2); - expect(flagOnNewWant).assertEqual(1); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } - done() } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0400====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } }) @@ -335,13 +326,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0500', 0, async function (done) { console.log("ACTS_NewWant_Test_0500 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0500====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -388,17 +379,14 @@ export default function abilityTest(abilityContext) { if (flagOnCreate == 1 && flagOnWindowStageCreate == 1 && flagOnForeground == 2 && flagOnNewWant == 1) { - expect(flagOnCreate).assertEqual(1); - expect(flagOnWindowStageCreate).assertEqual(1); - expect(flagOnForeground).assertEqual(2); - expect(flagOnNewWant).assertEqual(1); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } - done() } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0500====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } }) @@ -410,13 +398,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0600', 0, async function (done) { console.log("ACTS_NewWant_Test_0600 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0600====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -463,17 +451,14 @@ export default function abilityTest(abilityContext) { if (flagOnCreate == 1 && flagOnWindowStageCreate == 1 && flagOnForeground == 2 && flagOnNewWant == 1) { - expect(flagOnCreate).assertEqual(1); - expect(flagOnWindowStageCreate).assertEqual(1); - expect(flagOnForeground).assertEqual(2); - expect(flagOnNewWant).assertEqual(1); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } - done() } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0600====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } }) @@ -485,13 +470,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0700', 0, async function (done) { console.log("ACTS_NewWant_Test_0700 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0700====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -536,18 +521,15 @@ export default function abilityTest(abilityContext) { console.debug("ACTS_NewWant_Test_0700====>flagOnNewWant:====>" + flagOnNewWant) - if (flagOnCreate == 1 && flagOnWindowStageCreate == 1 + if (flagOnCreate == 0 && flagOnWindowStageCreate == 0 && flagOnForeground == 2 && flagOnNewWant == 1) { - expect(flagOnCreate).assertEqual(1); - expect(flagOnWindowStageCreate).assertEqual(1); - expect(flagOnForeground).assertEqual(2); - expect(flagOnNewWant).assertEqual(1); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } - done() } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0700====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } }) @@ -559,13 +541,13 @@ export default function abilityTest(abilityContext) { */ it('ACTS_NewWant_Test_0800', 0, async function (done) { console.log("ACTS_NewWant_Test_0800 --- start") - var Subscriber; - var flagOnCreate = 0; - var flagOnWindowStageCreate = 0; - var flagOnForeground = 0; - var flagOnNewWant = 0; + let Subscriber; + let flagOnCreate = 0; + let flagOnWindowStageCreate = 0; + let flagOnForeground = 0; + let flagOnNewWant = 0; - commonEvent.createSubscriber(subscriberInfo).then(async (data) => { + await commonEvent.createSubscriber(subscriberInfo).then(async (data) => { console.debug("ACTS_NewWant_Test_0800====>Create Subscriber====>"); Subscriber = data; await commonEvent.subscribe(Subscriber, SubscribeCallBack); @@ -573,8 +555,8 @@ export default function abilityTest(abilityContext) { abilityContext.startAbility({ bundleName: "com.example.newwanthap", - abilityName: "com.example.newwanthapa.SecondAbility", - action: "startSecondAbility0800" + abilityName: "com.example.newwanthapa.MainAbility", + action: "startMainAbility0800" }, (error, data) => { console.log('ACTS_NewWant_Test_0800 - startAbility start SecondAbility: ' + JSON.stringify(error) + ", " + JSON.stringify(data)) @@ -611,18 +593,15 @@ export default function abilityTest(abilityContext) { console.debug("ACTS_NewWant_Test_0800====>flagOnNewWant:====>" + flagOnNewWant) - if (flagOnCreate == 1 && flagOnWindowStageCreate == 1 + if (flagOnCreate == 0 && flagOnWindowStageCreate == 0 && flagOnForeground == 2 && flagOnNewWant == 1) { - expect(flagOnCreate).assertEqual(1); - expect(flagOnWindowStageCreate).assertEqual(1); - expect(flagOnForeground).assertEqual(2); - expect(flagOnNewWant).assertEqual(1); - commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + flagNewWant = true; + commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); } - done() } function UnSubscribeCallback() { console.debug("ACTS_NewWant_Test_0800====>UnSubscribe CallBack====>"); + expect(flagNewWant).assertTrue(); done(); } })