未验证 提交 4015fba6 编写于 作者: O openharmony_ci 提交者: Gitee

!8163 xts-getCurrentTopAbility问题修改1

Merge pull request !8163 from chengxingzhen/OpenHarmony-3.2-Release
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"test-timeout": "600000", "test-timeout": "600000",
"bundle-name": "com.example.actsgetabilitystatestagetest", "bundle-name": "com.example.actsgetabilitystatestagetest",
"module-name": "entry", "module-name": "entry",
"shell-timeout": "600000" "shell-timeout": "10000"
}, },
"kits": [ "kits": [
{ {
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
*/ */
import Ability from '@ohos.app.ability.UIAbility' import Ability from '@ohos.app.ability.UIAbility'
import commonEvent from '@ohos.commonEvent'
function publishCallBackOne() {
console.log("====MainAbility2 Publish CallBack GetCurrentTopAbility");
}
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
...@@ -27,9 +31,15 @@ export default class MainAbility extends Ability { ...@@ -27,9 +31,15 @@ export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate") console.log("[Demo] MainAbility onWindowStageCreate");
windowStage.setUIContent(this.context, "pages/index", null);
windowStage.setUIContent(this.context, "pages/index", null) windowStage.on('windowStageEvent', (data) => {
console.log(`ActsGetAbilityStatestAgeTest onWindwoStageMainAbilty2 is : ${JSON.stringify(data)}`);
if (data == 2 ) {
console.log(`ActsGetAbilityStatestAgeTest getWindowStageActiveMainAbility2 is sucess`);
commonEvent.publish("GetCurrentTopAbility", publishCallBackOne);
}
})
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
// @ts-nocheck
/* /*
* Copyright (c) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -15,22 +14,34 @@ ...@@ -15,22 +14,34 @@
*/ */
import Ability from '@ohos.app.ability.UIAbility' import Ability from '@ohos.app.ability.UIAbility'
import commonEvent from '@ohos.commonEvent'
function publishCallBackOne() {
console.log("====MainAbility3 Publish CallBack GetCurrentTopAbility");
}
export default class MainAbility3 extends Ability { export default class MainAbility3 extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log("MainAbility3 onCreate") console.log("MainAbility3 onCreate")
} }
onDestroy(want) { onDestroy() {
// Ability is destroying, release resources for this ability // Ability is destroying, release resources for this ability
console.log("MainAbility3 onDestroy") console.log("MainAbility3 onDestroy")
} }
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
console.log("MainAbility3 onWindowStageCreate") console.log("MainAbility3 onWindowStageCreate");
windowStage.setUIContent(this.context, "pages/index", null) windowStage.setUIContent(this.context, "pages/index", null);
globalThis.ability3Context = this.context; globalThis.ability3Context = this.context;
windowStage.on('windowStageEvent', (data) => {
console.log(`ActsGetAbilityStatestAgeTest onWindwoStageMainAbilty3 is : ${JSON.stringify(data)}`);
if (data == 2 ) {
console.log(`ActsGetAbilityStatestAgeTest getWindowStageActiveMainAbility3 is sucess`);
commonEvent.publish("GetCurrentTopAbility", publishCallBackOne);
}
})
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
// @ts-nocheck
/* /*
* Copyright (c) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -14,24 +13,34 @@ ...@@ -14,24 +13,34 @@
* limitations under the License. * limitations under the License.
*/ */
import Ability from '@ohos.app.ability.UIAbility' import Ability from '@ohos.app.ability.UIAbility'
import commonEvent from '@ohos.commonEvent'
function publishCallBackOne() {
console.log("====MainAbility4 Publish CallBack GetCurrentTopAbility");
}
export default class MainAbility4 extends Ability { export default class MainAbility4 extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log("MainAbility4 onCreate") console.log("MainAbility4 onCreate")
} }
onDestroy(want) { onDestroy() {
// Ability is destroying, release resources for this ability // Ability is destroying, release resources for this ability
console.log("MainAbility4 onDestroy") console.log("MainAbility4 onDestroy")
} }
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
console.log("MainAbility4 onWindowStageCreate") console.log("MainAbility4 onWindowStageCreate");
windowStage.setUIContent(this.context, "pages/index", null) windowStage.setUIContent(this.context, "pages/index", null);
globalThis.ability4Context = this.context; globalThis.ability4Context = this.context;
//commonEvent.publish("ACTS_GetAppContext", PublishCallBackOne4); windowStage.on('windowStageEvent', (data) => {
console.log(`ActsGetAbilityStatestAgeTest onWindwoStageMainAbilty4 is : ${JSON.stringify(data)}`);
if (data == 2 ) {
console.log(`ActsGetAbilityStatestAgeTest getWindowStageActiveMainAbility4 is sucess`);
commonEvent.publish("GetCurrentTopAbility", publishCallBackOne);
}
})
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
// @ts-nocheck
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
const START_ABILITY_TIMEOUT = 4000; import commonEvent from "@ohos.commonEvent"
let subscriberInfo_MainAbility = {
events: ["GetCurrentTopAbility"],
};
export default function abilityTest() { export default function abilityTest() {
describe('ActsGetAbilityStateStageTest', function () { describe('ActsGetAbilityStateStageTest', function () {
...@@ -27,31 +29,44 @@ export default function abilityTest() { ...@@ -27,31 +29,44 @@ export default function abilityTest() {
* @tc.desc : Get the status of the Ability in the BACKGROUND state * @tc.desc : Get the status of the Ability in the BACKGROUND state
*/ */
it('ACTS_GetAbilityState_0200', 0, async function (done) { it('ACTS_GetAbilityState_0200', 0, async function (done) {
console.debug('====>start ACTS_GetAbilityState_0200===='); console.log('====>start ACTS_GetAbilityState_0200====');
var flag = true; let ability;
var ability; let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let count = 0;
let subscriber;
function onAbilityForegroundCallback2(){ function onAbilityForegroundCallback2(){
console.debug("====>onAbilityForegroundCallback2===="); console.log("====>onAbilityForegroundCallback2====");
abilityDelegator.getCurrentTopAbility((err, data)=>{ count ++;
console.debug("====>getCurrentTopAbility_0200 err:" + JSON.stringify(err) + " data:" + JSON.stringify(data)); if (count == 2) {
abilityDelegator.getCurrentTopAbility((err, data)=>{
console.log("====>getCurrentTopAbility_0200 err:" + JSON.stringify(err) + " data:" + JSON.stringify(data));
ability = data; ability = data;
abilityDelegator.doAbilityBackground(ability, (err)=>{ abilityDelegator.doAbilityBackground(ability, (err)=>{
console.debug("====>doAbilityBackground_0200 data:" + JSON.stringify(err)); console.log("====>doAbilityBackground_0200 data:" + JSON.stringify(err));
expect(err.code).assertEqual(0); expect(err.code).assertEqual(0);
}) })
}) })
}
} }
function onAbilityBackgroundCallback2(){ function onAbilityBackgroundCallback2(){
console.debug("====>onAbilityBackgroundCallback2===="); console.log("====>onAbilityBackgroundCallback2====");
var state = abilityDelegator.getAbilityState(ability); let state = abilityDelegator.getAbilityState(ability);
console.debug("====>ACTS_GetAbilityState_0200 state:" + state); console.log("====>ACTS_GetAbilityState_0200 state:" + state);
expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.BACKGROUND); expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.BACKGROUND);
console.debug("====>ACTS_GetAbilityState_0200 end===="); console.log("====>ACTS_GetAbilityState_0200 end====");
flag=false; commonEvent.unsubscribe(subscriber, UnSubscribeCallback);
done();
} }
commonEvent.createSubscriber(subscriberInfo_MainAbility).then(async (data) => {
console.log("ACTS_GetAbilityState_0200====>Create Subscriber====>");
subscriber = data;
await commonEvent.subscribe(subscriber, onAbilityForegroundCallback2);
})
function UnSubscribeCallback() {
console.log("ACTS_GetAbilityState_0200====>UnSubscribe CallBack====>");
done();
}
abilityDelegator.addAbilityMonitor( abilityDelegator.addAbilityMonitor(
{abilityName: 'MainAbility2', {abilityName: 'MainAbility2',
...@@ -59,24 +74,15 @@ export default function abilityTest() { ...@@ -59,24 +74,15 @@ export default function abilityTest() {
onAbilityBackground:onAbilityBackgroundCallback2 onAbilityBackground:onAbilityBackgroundCallback2
} }
).then(()=>{ ).then(()=>{
console.debug("====>addAbilityMonitor_0200 finish===="); console.log("====>addAbilityMonitor_0200 finish====");
globalThis.abilityContext.startAbility( globalThis.abilityContext.startAbility(
{ {
bundleName: 'com.example.actsgetabilitystatestagetest', bundleName: 'com.example.actsgetabilitystatestagetest',
abilityName: 'MainAbility2', abilityName: 'MainAbility2',
}, (err)=>{ }, (err)=>{
console.debug("====>startAbility_0200 err:" + JSON.stringify(err)); console.log("====>startAbility_0200 err:" + JSON.stringify(err));
}) })
}) })
setTimeout(()=>{
if(flag==true){
console.debug("====>in timeout 0200====");
expect().assertFail();
done();
}
},START_ABILITY_TIMEOUT)
}) })
/* /*
...@@ -85,46 +91,54 @@ export default function abilityTest() { ...@@ -85,46 +91,54 @@ export default function abilityTest() {
* @tc.desc : Get the status of the Ability in the FOREGROUND state * @tc.desc : Get the status of the Ability in the FOREGROUND state
*/ */
it('ACTS_GetAbilityState_0300', 0, async function (done) { it('ACTS_GetAbilityState_0300', 0, async function (done) {
console.debug('====>start ACTS_GetAbilityState_0300===='); console.log('====>start ACTS_GetAbilityState_0300====');
var flag = true; let ability;
var ability; let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let count = 0;
let subscriber;
function onAbilityForegroundCallback3(){ function onAbilityForegroundCallback3(){
console.debug("====>onAbilityForegroundCallback3===="); console.log("====>onAbilityForegroundCallback3====");
abilityDelegator.getCurrentTopAbility((err, data)=>{ count++;
console.debug("====>getCurrentTopAbility_0300 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data)); if (count == 2) {
abilityDelegator.getCurrentTopAbility((err, data)=>{
console.log("====>getCurrentTopAbility_0300 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data));
ability = data; ability = data;
var state = abilityDelegator.getAbilityState(ability); let state = abilityDelegator.getAbilityState(ability);
console.debug("====>ACTS_GetAbilityState_0300 state:" + state); console.log("====>ACTS_GetAbilityState_0300 state:" + state);
expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.FOREGROUND); expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.FOREGROUND);
expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.CREATE).assertTrue() expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.CREATE).assertTrue();
expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.DESTROY).assertTrue() expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.DESTROY).assertTrue();
abilityDelegator.doAbilityBackground(ability, (err)=>{ abilityDelegator.doAbilityBackground(ability, (err)=>{
console.debug("====>doAbilityBackground_0300 data:" + JSON.stringify(err)); console.log("====>doAbilityBackground_0300 data:" + JSON.stringify(err));
expect(err.code).assertEqual(0); expect(err.code).assertEqual(0);
console.debug("====>ACTS_GetAbilityState_0300 end===="); console.log("====>ACTS_GetAbilityState_0300 end====");
flag=false; commonEvent.unsubscribe(subscriber, UnSubscribeCallback);
done();
}) })
}) })
}
setTimeout(()=>{
if(flag==true){
console.debug("====>in timeout 0300====");
expect().assertFail();
done();
} }
},START_ABILITY_TIMEOUT) }
commonEvent.createSubscriber(subscriberInfo_MainAbility).then(async (data) => {
console.log("ACTS_GetAbilityState_0300====>Create Subscriber====>");
subscriber = data;
await commonEvent.subscribe(subscriber, onAbilityForegroundCallback3);
})
function UnSubscribeCallback() {
console.log("ACTS_GetAbilityState_0300====>UnSubscribe CallBack====>");
done();
}
abilityDelegator.addAbilityMonitor( abilityDelegator.addAbilityMonitor(
{abilityName: 'MainAbility3', {abilityName: 'MainAbility3',
onAbilityForeground:onAbilityForegroundCallback3}).then(()=>{ onAbilityForeground:onAbilityForegroundCallback3}).then(()=>{
console.debug("====>addAbilityMonitor_0300 finish===="); console.log("====>addAbilityMonitor_0300 finish====");
globalThis.abilityContext.startAbility( globalThis.abilityContext.startAbility(
{ {
bundleName: 'com.example.actsgetabilitystatestagetest', bundleName: 'com.example.actsgetabilitystatestagetest',
abilityName: 'MainAbility3', abilityName: 'MainAbility3',
}, (err)=>{ }, (err)=>{
console.debug("====>startAbility_0300 err:" + JSON.stringify(err)); console.log("====>startAbility_0300 err:" + JSON.stringify(err));
}) })
}) })
}) })
...@@ -135,13 +149,13 @@ export default function abilityTest() { ...@@ -135,13 +149,13 @@ export default function abilityTest() {
* @tc.desc : Get the status of an inactive or nonexistent Ability * @tc.desc : Get the status of an inactive or nonexistent Ability
*/ */
it('ACTS_GetAbilityState_0500', 0, async function (done) { it('ACTS_GetAbilityState_0500', 0, async function (done) {
console.debug('====>start ACTS_GetAbilityState_0500===='); console.log('====>start ACTS_GetAbilityState_0500====');
var ability = Object.create(null); let ability = Object.create(null);
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var state = abilityDelegator.getAbilityState(ability); let state = abilityDelegator.getAbilityState(ability);
console.debug("====>ACTS_GetAppState_0500 state:" + state); console.log("====>ACTS_GetAppState_0500 state:" + state);
expect(state).assertEqual(undefined); expect(state).assertEqual(undefined);
console.debug("====>ACTS_GetAbilityState_0500 end===="); console.log("====>ACTS_GetAbilityState_0500 end====");
done(); done();
}) })
...@@ -151,49 +165,56 @@ export default function abilityTest() { ...@@ -151,49 +165,56 @@ export default function abilityTest() {
* @tc.desc : Get the status of the Ability in the uninitialized state * @tc.desc : Get the status of the Ability in the uninitialized state
*/ */
it('ACTS_GetAbilityState_0600', 0, async function (done) { it('ACTS_GetAbilityState_0600', 0, async function (done) {
console.debug('====>start ACTS_GetAbilityState_0600====') console.log('====>start ACTS_GetAbilityState_0600====');
var flag = true; let ability;
var ability; let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let count = 0;
let subscriber;
function onAbilityForegroundCallback6(){ function onAbilityForegroundCallback6(){
console.debug("====>onAbilityForegroundCallback6===="); console.log("====>onAbilityForegroundCallback6====");
abilityDelegator.getCurrentTopAbility((err, data)=>{ count++;
console.debug("====>getCurrentTopAbility_0600 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data)); if (count == 2) {
abilityDelegator.getCurrentTopAbility((err, data)=>{
console.log("====>getCurrentTopAbility_0600 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data));
ability = data; ability = data;
globalThis.ability4Context.terminateSelf(); globalThis.ability4Context.terminateSelf();
}) })
}
} }
function onAbilityDestroyCallback6(){ function onAbilityDestroyCallback6(){
console.debug("====>onAbilityDestroyCallback6===="); console.log("====>onAbilityDestroyCallback6====");
var state = abilityDelegator.getAbilityState(ability); let state = abilityDelegator.getAbilityState(ability);
console.debug("====>ACTS_GetAbilityState_0600 data:" + state); console.log("====>ACTS_GetAbilityState_0600 data:" + state);
console.debug("====>UNINITIALIZED:"+ AbilityDelegatorRegistry.AbilityLifecycleState.UNINITIALIZED); console.log("====>UNINITIALIZED:"+ AbilityDelegatorRegistry.AbilityLifecycleState.UNINITIALIZED);
expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.UNINITIALIZED); expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.UNINITIALIZED);
console.debug("====>ACTS_GetAbilityState_0600 end===="); console.log("====>ACTS_GetAbilityState_0600 end====");
flag=false; commonEvent.unsubscribe(subscriber, UnSubscribeCallback);
done();
} }
setTimeout(()=>{
if(flag==true){ commonEvent.createSubscriber(subscriberInfo_MainAbility).then(async (data) => {
console.debug("====>in timeout 0600==="); console.log("ACTS_GetAbilityState_0600====>Create Subscriber====>");
expect().assertFail(); subscriber = data;
done(); await commonEvent.subscribe(subscriber, onAbilityForegroundCallback6);
} })
},START_ABILITY_TIMEOUT)
function UnSubscribeCallback() {
console.log("ACTS_GetAbilityState_0600====>UnSubscribe CallBack====>");
done();
}
abilityDelegator.addAbilityMonitor( abilityDelegator.addAbilityMonitor(
{abilityName: 'MainAbility4', {abilityName: 'MainAbility4',
onAbilityForeground:onAbilityForegroundCallback6, onAbilityForeground:onAbilityForegroundCallback6,
onAbilityDestroy:onAbilityDestroyCallback6}).then(()=>{ onAbilityDestroy:onAbilityDestroyCallback6}).then(()=>{
console.debug("====>addAbilityMonitor_0600 finish===="); console.log("====>addAbilityMonitor_0600 finish====");
globalThis.abilityContext.startAbility( globalThis.abilityContext.startAbility(
{ {
bundleName: 'com.example.actsgetabilitystatestagetest', bundleName: 'com.example.actsgetabilitystatestagetest',
abilityName: 'MainAbility4', abilityName: 'MainAbility4',
}, (err)=>{ }, (err)=>{
console.debug("====>startAbility_0600 err:" + JSON.stringify(err)); console.log("====>startAbility_0600 err:" + JSON.stringify(err));
}) })
}) })
}) })
}) })
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册