diff --git a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/MainAbility/MainAbility.ts index 97457d2797e717c9f43db5f1557a78ebf2fa929d..a1713c0c0788aa5456aaf5f5e787703f9c56a8bf 100644 --- a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -20,6 +20,7 @@ export default class MainAbility extends Ability { // Ability is creating, initialize resources for this ability console.log("MainAbility onCreate") globalThis.abilityWant = want; + globalThis.abilityContext = this.context } onDestroy() { @@ -30,7 +31,7 @@ export default class MainAbility extends Ability { onWindowStageCreate(windowStage) { // Main window is created, set main page for this ability console.log("MainAbility onWindowStageCreate") - globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) } diff --git a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts index 99f25c1ee223ff42cf8ea3b98978b3d4efb19f50..360b453d4ec06923b7f90be95b4ac500cc8385e6 100644 --- a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts +++ b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts @@ -97,8 +97,8 @@ export default class ServiceAbility extends ServiceExtension { if (want.action == "Seven") { extensionContext.connectAbility( { - bundleName: "com.example.manyusersabilitytest", - abilityName: "com.example.manyusersabilitytest.ServiceAbility2", + bundleName: "com.example.actsmanyusersabilitytest", + abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility2", }, { onConnect: onConnectCallback, onDisconnect: onDisconnectCallback, @@ -109,8 +109,8 @@ export default class ServiceAbility extends ServiceExtension { if (want.action == "Eight") { extensionContext.connectAbility( { - bundleName: "com.example.manyusersabilitytesta", - abilityName: "com.example.manyusersabilitytest.ServiceAbility3", + bundleName: "com.example.actsmanyusersabilitytesta", + abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility3", }, { onConnect: onConnectCallback, onDisconnect: onDisconnectCallback, @@ -122,8 +122,8 @@ export default class ServiceAbility extends ServiceExtension { console.log('connectAbility 111'); let num = this.context.connectAbility( { - bundleName: 'com.example.manyusersabilitytest', - abilityName: 'com.example.manyusersabilitytest.ServiceAbility2' + bundleName: 'com.example.actsmanyusersabilitytest', + abilityName: 'com.example.actsmanyusersabilitytest.ServiceAbility2' }, { onConnect: onConnectCallback, onDisconnect: onDisconnectCallback, @@ -140,8 +140,8 @@ export default class ServiceAbility extends ServiceExtension { console.log('connectAbility 222'); let num = this.context.connectAbility( { - bundleName: 'com.example.manyusersabilitytest', - abilityName: 'com.example.manyusersabilitytest.ServiceAbility2' + bundleName: 'com.example.actsmanyusersabilitytest', + abilityName: 'com.example.actsmanyusersabilitytest.ServiceAbility2' }, { onConnect: onConnectCallback, onDisconnect: onDisconnectCallback, @@ -158,8 +158,8 @@ export default class ServiceAbility extends ServiceExtension { console.log('connectAbility 333'); let num = this.context.connectAbility( { - bundleName: 'com.example.manyusersabilitytest', - abilityName: 'com.example.manyusersabilitytest.ServiceAbility2' + bundleName: 'com.example.actsmanyusersabilitytest', + abilityName: 'com.example.actsmanyusersabilitytest.ServiceAbility2' }, { onConnect: onConnectCallback, onDisconnect: onDisconnectCallback, @@ -176,8 +176,8 @@ export default class ServiceAbility extends ServiceExtension { console.log('connectAbility 444'); let num = this.context.connectAbility( { - bundleName: 'com.example.manyusersabilitytest', - abilityName: 'com.example.manyusersabilitytest.ServiceAbility2' + bundleName: 'com.example.actsmanyusersabilitytest', + abilityName: 'com.example.actsmanyusersabilitytest.ServiceAbility2' }, { onConnect: onConnectCallback, onDisconnect: onDisconnectCallback, diff --git a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/test/manyusersabilitytest.test.ets b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/test/manyusersabilitytest.test.ets index 2ad577c57b2da1a773fd1e5735e76f3c3539cbd4..1a8dc9b175ff9a334225f9dac64e7caccb337bc6 100644 --- a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/test/manyusersabilitytest.test.ets +++ b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/ets/test/manyusersabilitytest.test.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index" +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index" import commonEvent from '@ohos.commonEvent' @@ -67,6 +67,26 @@ var unsubscriberInfoStartAbility_0200 = { const START_ABILITY_TIMEOUT = 1000; globalThis.number = 0; +function onConnectCallback(element, remote) { + console.log(' ACTS_ConnectAbility onConnectCallback====> element=' + JSON.stringify(element)); + console.log(' ACTS_ConnectAbility onConnectCallback====> remote=' + JSON.stringify(remote)); + // setTimeout(()=> { + // console.log('====>in timeout'); + // console.debug("====>flag is====>" + JSON.stringify(flag)); + // if(flag == true) { + // console.debug('ACTS_ThirdPartyExtensionStartAbility_0600 - timeout'); + // commonEvent.unsubscribe(Subscriber, UnSubscribeCallback); + // } + // }, 1000); +} +function onDisconnectCallback(element) { + console.log('ACTS_ConnectAbility onDisconnectCallback====> element=' + JSON.stringify(element)); +} + +function onFailedCallback(code) { + console.log('ACTS_ConnectAbility onFailedCallback====> code=' + JSON.stringify(code)) +} + export default function abilityTest(abilityContext) { describe('manyuserability', function () { @@ -74,6 +94,11 @@ export default function abilityTest(abilityContext) { console.log('ACTS_ConnectAbility_0200 Connectability errcode:' + code); } + /* + * @tc.number : ACTS_ThirdPartyConnectAbility_0100 + * @tc.name : connect ability + * @tc.desc : Start an ability with the parameter startability with options failed.(callback) + */ it('ACTS_ThirdPartyConnectAbility_0100', 0, async function (done) { console.log('ACTS_ThirdPartyConnectAbility_0100====ACTS_ThirdPartyConnectAbility_0100 7 CallBack data:====>" + JSON.stringify(data)); clearTimeout(id); @@ -95,10 +119,8 @@ export default function abilityTest(abilityContext) { ); console.debug("====>ACTS_ThirdPartyConnectAbility_0100 6 "); commonEvent.unsubscribe(subscriber, unSubscribeCallback) - } - commonEvent.createSubscriber(subscriberInfoStartAbility_0100).then(async (data) => { console.debug("====>ACTS_ThirdPartyConnectAbility_0100 2 Subscriber1====>"); subscriber = data; @@ -128,11 +150,19 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "one", - }, + },{ + onConnect:onConnectCallback, + onDisconnect:onDisconnectCallback, + onFailed: onFailedCallback + } ); + console.debug("====>ACTS_ThirdPartyConnectAbility_0100 4 "); }) + + + it('ACTS_ThirdPartyConnectAbility_0200', 0, async function (done) { console.log('ACTS_ThirdPartyConnectAbility_0200====Subscribe CallBack data:====>" + JSON.stringify(data)); + console.debug("====>ACTS_ThirdPartyConnectAbility_0200 Subscribe CallBack data:====>" + JSON.stringify(data)); clearTimeout(id); expect(data.event).assertEqual("AMS_ConnectAbility_0200_commonEvent"); @@ -150,13 +180,13 @@ export default function abilityTest(abilityContext) { } commonEvent.createSubscriber(subscriberInfoStartAbility_0200).then(async (data) => { - console.debug("====>Create Subscriber====>"); + console.debug("====>ACTS_ThirdPartyConnectAbility_0200 Create Subscriber====>"); subscriber = data; await commonEvent.subscribe(subscriber, subscribeCallBack); }) function unSubscribeCallback() { - console.debug("====>UnSubscribe CallBack====>"); + console.debug("====>ACTS_ThirdPartyConnectAbility_0200 UnSubscribe CallBack====>"); done(); } @@ -176,8 +206,6 @@ export default function abilityTest(abilityContext) { { onFailed: onFailedCallBack, }, - - ); }) @@ -213,10 +241,10 @@ export default function abilityTest(abilityContext) { function unSubscribeCallback() { console.debug("====>UnSubscribe CallBack====>"); - setTimeout(()=> - { + setTimeout(() => { done() - }, 1000)}; + }, 1000) + }; function timeout() { expect().assertFail(); @@ -236,7 +264,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Three", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyDisconnectAbility_0100 4====>"); }) @@ -312,7 +344,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Four", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>connId is:====>" + JSON.stringify(connId)); console.debug("====>ACTS_ThirdPartyDisconnectAbility_0200 1010 Subscriber====>"); @@ -380,7 +416,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Five", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyDisconnectAbility_0300 4 "); }) @@ -455,7 +495,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Six", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>connId is:====>" + JSON.stringify(connId)); console.debug("====>ACTS_ThirdPartyDisconnectAbility_0400 1010 Subscriber====>"); @@ -524,7 +568,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Seven", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyExtensionConnectAbility_0100 4 "); @@ -585,7 +633,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Eight", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyExtensionConnectAbility_0200 4 "); @@ -646,7 +698,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Nine", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyExtensionDisconnectAbility_0100 4 "); @@ -708,7 +764,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Ten", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyExtensionDisconnectAbility_0200 4 "); @@ -769,7 +829,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Ten one", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyExtensionDisconnectAbility_0300 4 "); @@ -830,7 +894,11 @@ export default function abilityTest(abilityContext) { bundleName: "com.example.actsmanyusersabilitytest", abilityName: "com.example.actsmanyusersabilitytest.ServiceAbility", action: "Ten two", - }, + }, { + onConnect: onConnectCallback, + onDisconnect: onDisconnectCallback, + onFailed: onFailedCallback + } ); console.debug("====>ACTS_ThirdPartyExtensionDisconnectAbility_0400 4 "); diff --git a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/module.json b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/module.json index 3deb3e5d7010bab334ca863ca848ad8604654f49..081771c25885e6801e4b0e7c1b3056054363eb8e 100644 --- a/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/module.json +++ b/ability/ability_runtime/actsusers/actsmanyuserthirdabilitytest/entry/src/main/module.json @@ -36,7 +36,7 @@ "extensionAbilities": [ { "srcEntrance": "./ets/ServiceAbility/ServiceAbility.ts", - "name": "com.example.actsconnectabilitysystemabilitytest.ServiceAbility", + "name": "com.example.actsmanyusersabilitytest.ServiceAbility", "icon": "$media:icon", "srcLanguage": "ets", "description": "$string:phone_entry_main", @@ -45,7 +45,7 @@ }, { "srcEntrance": "./ets/ServiceAbility2/ServiceAbility2.ts", - "name": "com.example.actsconnectabilitysystemabilitytest.ServiceAbility2", + "name": "com.example.actsmanyusersabilitytest.ServiceAbility2", "icon": "$media:icon", "srcLanguage": "ets", "description": "$string:phone_entry_main",