diff --git a/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest.ets b/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest.ets index 60cc2ceb43ece30605e9067f41c61a6be3249e64..19e80d90ebcc37e4c3614ae866af998eafc65f82 100644 --- a/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest.ets +++ b/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest.ets @@ -23,9 +23,9 @@ import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry export default function ConnectAbilityTest() { - var TAG = ""; - var Tempassert = ""; - var abilityDelegator = undefined + let TAG = ""; + let Tempassert = ""; + let abilityDelegator = undefined function sleep(time) { return new Promise((resolve) => setTimeout(resolve, time)) @@ -35,19 +35,19 @@ export default function ConnectAbilityTest() { beforeAll(async function (done) { console.info("FreeInstall_FA_ConnectAbility before all called"); abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var cmd = "bm install -p data/test/MockService.hap"; + let cmd = "bm install -p data/test/MockService.hap"; console.info("cmd : " + cmd) console.info(TAG + " abilityDelegator : " + JSON.stringify(abilityDelegator)); abilityDelegator.executeShellCommand(cmd, (err: any, d: any) => { console.info("executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) await sleep(500); - var cmd1 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry"; + let cmd1 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry"; abilityDelegator.executeShellCommand(cmd1, (err: any, d: any) => { console.info("executeShellCommand1 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) await sleep(500); - var cmd2 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files"; + let cmd2 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files"; abilityDelegator.executeShellCommand(cmd2, (err: any, d: any) => { console.info("executeShellCommand2 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); done(); @@ -57,11 +57,12 @@ export default function ConnectAbilityTest() { afterEach(async (done) => { console.info("FreeInstall_FA_ConnectAbility after each called"); Tempassert = "" - if ("FreeInstall_FA_ConnectAbility_2000" === TAG) { - var cmd14 = "bm uninstall -n com.ohos.hag.famanager"; + if ("FreeInstall_FA_ConnectAbility_1300" === TAG) { + let cmd14 = "bm uninstall -n com.ohos.hag.famanager"; abilityDelegator.executeShellCommand(cmd14, (err: any, d: any) => { console.info("executeShellCommand14 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) + await sleep(2000) } done(); }); @@ -125,33 +126,32 @@ export default function ConnectAbilityTest() { it("FreeInstall_FA_ConnectAbility_0100", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_0100-------------"); TAG = "FreeInstall_FA_ConnectAbility_0100"; - var cmd4 = "cp data/test/ConnectFaMyApplication6.hap /data/app/el2/100/base/com.ohos.hag.famanager/haps" + + let cmd4 = "cp data/test/ConnectFaMyApplication6.hap /data/app/el2/100/base/com.ohos.hag.famanager/haps" + "/entry/files"; abilityDelegator.executeShellCommand(cmd4, (err: any, d: any) => { console.info(TAG + " executeShellCommand4 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - setTimeout(async () => { - var deviceid = "0"; - await abilityManager.getTopAbility((err, data) => { - console.log(TAG + 'getTopAbility result: ' + JSON.stringify(data) + " , err: " + JSON.stringify(err)); - console.log(TAG + 'getTopAbility result deviceid:' + JSON.stringify(data.deviceId)); - deviceid = data.deviceId; - }) - var request1 = { - "deviceId": deviceid, - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication6.ServiceAbility", - "moduleName": "myapplication6", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request1); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500) - }, 2000); + let deviceid = "0"; + abilityManager.getTopAbility((err, data) => { + console.log(TAG + 'getTopAbility result: ' + JSON.stringify(data) + " , err: " + JSON.stringify(err)); + console.log(TAG + 'getTopAbility result deviceid:' + JSON.stringify(data.deviceId)); + deviceid = data.deviceId; + }) + await sleep(500) + let request1 = { + "deviceId": deviceid, + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication6.ServiceAbility", + "moduleName": "myapplication6", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request1); + setTimeout(() => { + expect(Tempassert).assertEqual("onConnect"); + done(); + }, 2000) console.log("------------end FreeInstall_FA_ConnectAbility_0100-------------"); - done(); }); /* @@ -163,31 +163,32 @@ export default function ConnectAbilityTest() { it("FreeInstall_FA_ConnectAbility_0200", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_0200-------------"); TAG = "FreeInstall_FA_ConnectAbility_0200"; - var cmdapp10 = "bm install -p data/test/ConnectFaMyApplication10.hap"; + let cmdapp10 = "bm install -p data/test/ConnectFaMyApplication10.hap"; abilityDelegator.executeShellCommand(cmdapp10, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - setTimeout(async () => { - var deviceid = "0"; - await abilityManager.getTopAbility((err, data) => { - console.log(TAG + 'getTopAbility result: ' + JSON.stringify(data) + " , err: " + JSON.stringify(err)); - console.log(TAG + 'getTopAbility result deviceid:' + JSON.stringify(data.deviceId)); - deviceid = data.deviceId; - }) - var request2 = { - "deviceId": deviceid, - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication10.ServiceAbility", - "moduleName": "myapplication10", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request2); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500) - }, 2500); - console.log("------------end FreeInstall_FA_ConnectAbility_0200-------------"); - done(); + let deviceid = "0"; + await abilityManager.getTopAbility((err, data) => { + console.log(TAG + 'getTopAbility result: ' + JSON.stringify(data) + " , err: " + JSON.stringify(err)); + console.log(TAG + 'getTopAbility result deviceid:' + JSON.stringify(data.deviceId)); + deviceid = data.deviceId; + }) + await sleep(500) + let request2 = { + "deviceId": deviceid, + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication10.ServiceAbility", + "moduleName": "myapplication10", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request2); + + setTimeout(() => { + expect(Tempassert).assertEqual("onConnect"); + console.log("------------end FreeInstall_FA_ConnectAbility_0200-------------"); + done(); + }, 2000) + }); /* @@ -199,26 +200,24 @@ export default function ConnectAbilityTest() { it("FreeInstall_FA_ConnectAbility_0300", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_0300-------------"); TAG = "FreeInstall_FA_ConnectAbility_0300"; - var cmd3 = "cp data/test/ConnectFaMyApplication1.hap /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files"; + let cmd3 = "cp data/test/ConnectFaMyApplication1.hap /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files"; abilityDelegator.executeShellCommand(cmd3, (err: any, d: any) => { console.info("executeShellCommand3 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - setTimeout(async () => { - var request3 = { - "deviceId": "", - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication1.ServiceAbility_feature", - "moduleName": "myapplication1", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request3); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500) - }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_0300-------------"); - done(); + let request3 = { + "deviceId": "", + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication1.ServiceAbility_feature", + "moduleName": "myapplication1", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request3); + setTimeout(() => { + expect(Tempassert).assertEqual("onConnect"); + console.log("------------end FreeInstall_FA_ConnectAbility_0300-------------"); + done(); + }, 2000) }); /* @@ -230,25 +229,24 @@ export default function ConnectAbilityTest() { it("FreeInstall_FA_ConnectAbility_0400", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_0400-------------"); TAG = "FreeInstall_FA_ConnectAbility_0400"; - var cmdapp11 = "bm install -p data/test/ConnectFaMyApplication11.hap"; + let cmdapp11 = "bm install -p data/test/ConnectFaMyApplication11.hap"; abilityDelegator.executeShellCommand(cmdapp11, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - setTimeout(async () => { - var request4 = { - "deviceId": "", - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication11.ServiceAbility", - "moduleName": "myapplication11", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request4); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500) - }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_0400-------------"); - done(); + await sleep(2000) + let request4 = { + "deviceId": "", + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication11.ServiceAbility", + "moduleName": "myapplication11", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request4); + setTimeout(() => { + expect(Tempassert).assertEqual("onConnect"); + console.log("------------end FreeInstall_FA_ConnectAbility_0400-------------"); + done(); + }, 2000) }); /* @@ -261,20 +259,18 @@ export default function ConnectAbilityTest() { console.log("------------start FreeInstall_FA_ConnectAbility_0500-------------"); TAG = "FreeInstall_FA_ConnectAbility_0500"; - setTimeout(async () => { - var request5 = { - "bundleName": "com.example.different.hmservice", - "abilityName": "com.example.different.ServiceAbility", - "moduleName": "entry", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request5); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request5 = { + "bundleName": "com.example.different.hmservice", + "abilityName": "com.example.different.ServiceAbility", + "moduleName": "entry", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request5); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_0500-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_0500-------------"); - done(); }); /* @@ -287,20 +283,18 @@ export default function ConnectAbilityTest() { console.log("------------start FreeInstall_FA_ConnectAbility_0600-------------"); TAG = "FreeInstall_FA_ConnectAbility_0600"; - setTimeout(async () => { - var request6 = { - "bundleName": "", - "abilityName": "com.example.myapplication1.ServiceAbility_feature", - "moduleName": "myapplication1", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request6); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request6 = { + "bundleName": "", + "abilityName": "com.example.myapplication1.ServiceAbility_feature", + "moduleName": "myapplication1", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request6); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_0600-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_0600-------------"); - done(); }); /* @@ -313,20 +307,18 @@ export default function ConnectAbilityTest() { console.log("------------start FreeInstall_FA_ConnectAbility_0700-------------"); TAG = "FreeInstall_FA_ConnectAbility_0700"; - setTimeout(async () => { - var request7 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "", - "moduleName": "myapplication1", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request7); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request7 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "", + "moduleName": "myapplication1", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request7); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_0700-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_0700-------------"); - done(); }); /* @@ -339,21 +331,19 @@ export default function ConnectAbilityTest() { console.log("------------start FreeInstall_FA_ConnectAbility_0800-------------"); TAG = "FreeInstall_FA_ConnectAbility_0800"; - setTimeout(async () => { - var request8 = { - "deviceId": "xxxxxx", - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication2.ServiceAbility", - "moduleName": "myapplication2", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request8); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request8 = { + "deviceId": "xxxxxx", + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication2.ServiceAbility", + "moduleName": "myapplication2", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request8); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_0800-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_0800-------------"); - done(); }); /* @@ -366,20 +356,18 @@ export default function ConnectAbilityTest() { console.log("------------start FreeInstall_FA_ConnectAbility_0900-------------"); TAG = "FreeInstall_FA_ConnectAbility_0900"; - setTimeout(async () => { - var request9 = { - "bundleName": "com.example.xxx.hmservice", - "abilityName": "com.example.myapplication2.ServiceAbility", - "moduleName": "myapplication2", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request9); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request9 = { + "bundleName": "com.example.xxx.hmservice", + "abilityName": "com.example.myapplication2.ServiceAbility", + "moduleName": "myapplication2", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request9); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_0900-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_0900-------------"); - done(); }); /* @@ -392,20 +380,18 @@ export default function ConnectAbilityTest() { console.log("------------start FreeInstall_FA_ConnectAbility_1000-------------"); TAG = "FreeInstall_FA_ConnectAbility_1000"; - setTimeout(async () => { - var request10 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication2.ServiceAbility", - "moduleName": "myapplication2", - "flags": 1111111, - } - connectabillity(TAG, request10); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request10 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication2.ServiceAbility", + "moduleName": "myapplication2", + "flags": 1111111, + } + connectabillity(TAG, request10); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_1000-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1000-------------"); - done(); }); /* @@ -417,25 +403,23 @@ export default function ConnectAbilityTest() { it("FreeInstall_FA_ConnectAbility_1100", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1100-------------"); TAG = "FreeInstall_FA_ConnectAbility_1100"; - var cmdapp2 = "bm install -p data/test/ConnectFaMyApplication2.hap"; + let cmdapp2 = "bm install -p data/test/ConnectFaMyApplication2.hap"; abilityDelegator.executeShellCommand(cmdapp2, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - - setTimeout(async () => { - var request11 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication2.ServiceAbility", - "moduleName": "myapplication2", - "flags": "11", - } - connectabillity(TAG, request11); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500) + await sleep(2000) + let request11 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication2.ServiceAbility", + "moduleName": "myapplication2", + "flags": "11", + } + connectabillity(TAG, request11); + setTimeout(() => { + expect(Tempassert).assertEqual("onConnect"); + console.log("------------end FreeInstall_FA_ConnectAbility_1000-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1000-------------"); - done(); }); /* @@ -447,24 +431,22 @@ export default function ConnectAbilityTest() { it("FreeInstall_FA_ConnectAbility_1200", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1200-------------"); TAG = "FreeInstall_FA_ConnectAbility_1200"; - var cmdrm = "rm -r /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files/*"; + let cmdrm = "rm -r /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files/*"; abilityDelegator.executeShellCommand(cmdrm, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - setTimeout(async () => { - var request12 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication1.ServiceAbility_feature", - "moduleName": "myapplication3", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request12); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request12 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication1.ServiceAbility_feature", + "moduleName": "myapplication3", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request12); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_1200-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1200-------------"); - done(); }); /* @@ -476,7 +458,7 @@ export default function ConnectAbilityTest() { it("FreeInstall_FA_ConnectAbility_1300", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1300-------------"); TAG = "FreeInstall_FA_ConnectAbility_1300"; - var str = { + let str = { "want": { "bundleName": "com.example.myapplication.hmservice", "abilityName": "com.example.myapplication.MainAbility2", @@ -490,21 +472,18 @@ export default function ConnectAbilityTest() { console.error(TAG + " startmainability2 failed. Cause: " + JSON.stringify(error)); }) - setTimeout(async () => { - var request13 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication1.ServiceAbility_feature", - "moduleName": "myapplication3", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request13); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request13 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication1.ServiceAbility_feature", + "moduleName": "myapplication3", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request13); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_1300-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1300-------------"); - done(); }); - }) } \ No newline at end of file diff --git a/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest1.ets b/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest1.ets index 2adb8fc3b0e2b03f3822ea5cc6cb49a6ff88bee2..4a10735f4a9691333ac1d8c34a0849e1651cf00b 100644 --- a/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest1.ets +++ b/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/ConnectAbilityTest1.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" +import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium" import rpc from '@ohos.rpc'; import featureAbility from '@ohos.ability.featureAbility'; import wantConstant from '@ohos.ability.wantConstant' @@ -22,9 +22,9 @@ import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry export default function ConnectAbilityTest1() { - var TAG = ""; - var Tempassert = ""; - var abilityDelegator = undefined + let TAG = ""; + let Tempassert = ""; + let abilityDelegator = undefined function sleep(time) { return new Promise((resolve) => setTimeout(resolve, time)) @@ -34,17 +34,19 @@ export default function ConnectAbilityTest1() { beforeAll(async function (done) { console.info("FreeInstall_FA_ConnectAbility before all called"); abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var cmd = "bm install -p data/test/MockService.hap"; + let cmd = "bm install -p data/test/MockService.hap"; console.info("cmd : " + cmd) console.info(TAG + " abilityDelegator : " + JSON.stringify(abilityDelegator)); abilityDelegator.executeShellCommand(cmd, (err: any, d: any) => { console.info("executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - var cmd1 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry"; + await sleep(500); + let cmd1 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry"; abilityDelegator.executeShellCommand(cmd1, (err: any, d: any) => { console.info("executeShellCommand1 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - var cmd2 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files"; + await sleep(500); + let cmd2 = "mkdir /data/app/el2/100/base/com.ohos.hag.famanager/haps/entry/files"; abilityDelegator.executeShellCommand(cmd2, (err: any, d: any) => { console.info("executeShellCommand2 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); done(); @@ -54,11 +56,12 @@ export default function ConnectAbilityTest1() { afterEach(async function (done) { console.info("FreeInstall_FA_ConnectAbility after each called"); Tempassert = "" - if ("FreeInstall_FA_ConnectAbility_1600" === TAG) { - var cmd14 = "bm uninstall -n com.ohos.hag.famanager"; + if ("FreeInstall_FA_ConnectAbility_2000" === TAG) { + let cmd14 = "bm uninstall -n com.ohos.hag.famanager"; abilityDelegator.executeShellCommand(cmd14, (err: any, d: any) => { console.info("executeShellCommand14 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) + await sleep(2000) } done(); }); @@ -113,8 +116,6 @@ export default function ConnectAbilityTest1() { console.info(msg + "END"); } - - /* * @tc.number FreeInstall_FA_ConnectAbility_1500 * @tc.name The application is not in the foreground, @@ -125,11 +126,12 @@ export default function ConnectAbilityTest1() { it("FreeInstall_FA_ConnectAbility_1500", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1500-------------"); TAG = "FreeInstall_FA_ConnectAbility_1500"; - var cmddif = "bm install -p data/test/ConnectDifferentApplication.hap"; + let cmddif = "bm install -p data/test/ConnectDifferentApplication.hap"; abilityDelegator.executeShellCommand(cmddif, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - var str = { + await sleep(2000) + let str = { "want": { "bundleName": "com.example.different.hmservice", "abilityName": "MainAbility", @@ -141,20 +143,18 @@ export default function ConnectAbilityTest1() { }).catch((error) => { console.error(TAG + " startother failed. Cause: " + JSON.stringify(error)); }) - setTimeout(async () => { - var request15 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication5.ServiceAbility5", - "moduleName": "myapplication5", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request15); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request15 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication5.ServiceAbility5", + "moduleName": "myapplication5", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request15); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_1500-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1500-------------"); - done(); }); /* @@ -167,11 +167,12 @@ export default function ConnectAbilityTest1() { it("FreeInstall_FA_ConnectAbility_1600", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1600-------------"); TAG = "FreeInstall_FA_ConnectAbility_1600"; - var cmdmyapp4 = "bm install -p data/test/ConnectFaMyApplication4.hap"; + let cmdmyapp4 = "bm install -p data/test/ConnectFaMyApplication4.hap"; abilityDelegator.executeShellCommand(cmdmyapp4, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - var str = { + await sleep(2000) + let str = { "want": { "bundleName": "com.example.different.hmservice", "abilityName": "MainAbility", @@ -184,20 +185,18 @@ export default function ConnectAbilityTest1() { console.error(TAG + " startother failed. Cause: " + JSON.stringify(error)); }) - setTimeout(function () { - var request16 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication4.ServiceAbility4", - "moduleName": "myapplication4", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request16); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500) + let request16 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication4.ServiceAbility4", + "moduleName": "myapplication4", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request16); + setTimeout(() => { + expect(Tempassert).assertEqual("onConnect"); + console.log("------------end FreeInstall_FA_ConnectAbility_1600-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1600-------------"); - done(); }); /* @@ -209,7 +208,7 @@ export default function ConnectAbilityTest1() { it("FreeInstall_FA_ConnectAbility_1400", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1400-------------"); TAG = "FreeInstall_FA_ConnectAbility_1400"; - var str = { + let str = { "want": { "bundleName": "com.example.myapplication.hmservice", "abilityName": "com.example.myapplication2.MainAbility", @@ -222,20 +221,18 @@ export default function ConnectAbilityTest1() { }).catch((error) => { console.error(TAG + " startmyapp2 failed. Cause: " + JSON.stringify(error)); }) + let request14 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication1.ServiceAbility_feature", + "moduleName": "myapplication3", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request14); setTimeout(() => { - var request14 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication1.ServiceAbility_feature", - "moduleName": "myapplication3", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request14); - setTimeout(async () => { - expect(Tempassert).assertEqual("onFailed"); - }, 500); + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_1400-------------"); + done() }, 2000) - done(); - console.log("------------end FreeInstall_FA_ConnectAbility_1400-------------"); }); /* @@ -247,23 +244,22 @@ export default function ConnectAbilityTest1() { it("FreeInstall_FA_ConnectAbility_1700", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1700-------------"); TAG = "FreeInstall_FA_ConnectAbility_1700"; - var cmddif = "bm install -p data/test/ConnectDifferentApplication.hap"; + let cmddif = "bm install -p data/test/ConnectDifferentApplication.hap"; await abilityDelegator.executeShellCommand(cmddif, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) + await sleep(2000) + let request17 = { + "bundleName": "com.example.different.hmservice", + "abilityName": "com.example.different.ServiceAbility", + "moduleName": "entry", + } + connectabillity(TAG, request17); setTimeout(() => { - var request17 = { - "bundleName": "com.example.different.hmservice", - "abilityName": "com.example.different.ServiceAbility", - "moduleName": "entry", - } - connectabillity(TAG, request17); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500); + expect(Tempassert).assertEqual("onConnect"); + console.log("------------end FreeInstall_FA_ConnectAbility_1700-------------"); + done(); }, 2000) - console.log("------------end FreeInstall_FA_ConnectAbility_1700-------------"); - done(); }); /* @@ -275,21 +271,18 @@ export default function ConnectAbilityTest1() { it("FreeInstall_FA_ConnectAbility_1800", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1800-------------"); TAG = "FreeInstall_FA_ConnectAbility_1800"; - - setTimeout(async () => { - var request18 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication1.ServiceAbility_feature", - "moduleName": "xxxxx", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request18); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request18 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication1.ServiceAbility_feature", + "moduleName": "xxxxx", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request18); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_1800-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1800-------------"); - done(); }); /* @@ -301,25 +294,23 @@ export default function ConnectAbilityTest1() { it("FreeInstall_FA_ConnectAbility_1900", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_1900-------------"); TAG = "FreeInstall_FA_ConnectAbility_1900"; - var cmdmyapp5 = "cp data/test/ConnectFaMyApplication5.hap /data/app/el2/100/base/com.ohos.hag.famanager/" + + let cmdmyapp5 = "cp data/test/ConnectFaMyApplication5.hap /data/app/el2/100/base/com.ohos.hag.famanager/" + "haps/entry/files"; await abilityDelegator.executeShellCommand(cmdmyapp5, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - setTimeout(async () => { - var request19 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication1.ServiceAbility_feature", - "moduleName": "myapplication3", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - } - connectabillity(TAG, request19); - setTimeout(() => { - expect(Tempassert).assertEqual("onFailed"); - }, 500) + let request19 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication1.ServiceAbility_feature", + "moduleName": "myapplication3", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + } + connectabillity(TAG, request19); + setTimeout(() => { + expect(Tempassert).assertEqual("onFailed"); + console.log("------------end FreeInstall_FA_ConnectAbility_1900-------------"); + done(); }, 2000); - console.log("------------end FreeInstall_FA_ConnectAbility_1900-------------"); - done(); }); /* @@ -331,28 +322,27 @@ export default function ConnectAbilityTest1() { it("FreeInstall_FA_ConnectAbility_2000", 0, async function (done) { console.log("------------start FreeInstall_FA_ConnectAbility_2000-------------"); TAG = "FreeInstall_FA_ConnectAbility_2000"; - var cmdmyapp5 = "cp data/test/ConnectFaMyApplication5.hap /data/app/el2/100/base/com.ohos.hag.famanager/" + + let cmdmyapp5 = "cp data/test/ConnectFaMyApplication5.hap /data/app/el2/100/base/com.ohos.hag.famanager/" + "haps/entry/files"; abilityDelegator.executeShellCommand(cmdmyapp5, (err: any, d: any) => { console.info(TAG + " executeShellCommand : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) - setTimeout(async () => { - var request20 = { - "bundleName": "com.example.myapplication.hmservice", - "abilityName": "com.example.myapplication5.ServiceAbility5", - "moduleName": "myapplication5", - "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, - "parameters": { - "name": 1111, "key1": "value1", "site": "nice to meet you!" - }, - } - connectabillity(TAG, request20); - setTimeout(() => { - expect(Tempassert).assertEqual("onConnect"); - }, 500) + await sleep(1000) + let request20 = { + "bundleName": "com.example.myapplication.hmservice", + "abilityName": "com.example.myapplication5.ServiceAbility5", + "moduleName": "myapplication5", + "flags": wantConstant.Flags.FLAG_INSTALL_ON_DEMAND, + "parameters": { + "name": 1111, "key1": "value1", "site": "nice to meet you!" + }, + } + connectabillity(TAG, request20); + setTimeout(() => { + expect(Tempassert).assertEqual("onConnect"); + console.log("------------end FreeInstall_FA_ConnectAbility_2000-------------"); + done() }, 4000) - done(); - console.log("------------end FreeInstall_FA_ConnectAbility_2000-------------"); }); } ) diff --git a/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/connectAbilityTest_PA.ets b/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/connectAbilityTest_PA.ets index 03a25c2be1edc502a19dab77e92212c76b23e9d4..4b96cf84a75f83aeaa3b2ac342f3f5fb0a16e776 100644 --- a/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/connectAbilityTest_PA.ets +++ b/ability/ability_runtime/freeinstalltest/connectabilityfatest/actsfreeinstallconnectabilityfatest/entry/src/main/ets/MainAbility/test/connectAbilityTest_PA.ets @@ -146,8 +146,8 @@ abilityDelegator.executeShellCommand(cmd14, (err: any, d: any) => { console.info("executeShellCommand14 : err : " + JSON.stringify(err), " data : " + JSON.stringify(d)); }) + await sleep(2000) } - await sleep(1500); done(); });