Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
4015fba6
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4015fba6
编写于
3月 23, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 23, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8163 xts-getCurrentTopAbility问题修改1
Merge pull request !8163 from chengxingzhen/OpenHarmony-3.2-Release
上级
9a4bcfb4
8abd7ce9
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
146 addition
and
95 deletion
+146
-95
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/Test.json
...squeryfunctiontest/actsgetabilitystatestagetest/Test.json
+1
-1
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/MainAbility2/MainAbility2.ts
...stagetest/entry/src/main/ets/MainAbility2/MainAbility2.ts
+13
-3
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/MainAbility3/MainAbility3.ts
...stagetest/entry/src/main/ets/MainAbility3/MainAbility3.ts
+15
-4
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/MainAbility4/MainAbility4.ts
...stagetest/entry/src/main/ets/MainAbility4/MainAbility4.ts
+14
-5
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/test/Ability.test.ets
...tystatestagetest/entry/src/main/ets/test/Ability.test.ets
+103
-82
未找到文件。
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/Test.json
浏览文件 @
4015fba6
...
...
@@ -5,7 +5,7 @@
"test-timeout"
:
"600000"
,
"bundle-name"
:
"com.example.actsgetabilitystatestagetest"
,
"module-name"
:
"entry"
,
"shell-timeout"
:
"
60
0000"
"shell-timeout"
:
"
1
0000"
},
"kits"
:
[
{
...
...
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/MainAbility2/MainAbility2.ts
浏览文件 @
4015fba6
...
...
@@ -14,6 +14,10 @@
*/
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
{
onCreate
(
want
,
launchParam
)
{
...
...
@@ -27,9 +31,15 @@ export default class MainAbility extends Ability {
onWindowStageCreate
(
windowStage
)
{
// Main window is created, set main page for this ability
console
.
log
(
"
[Demo] MainAbility onWindowStageCreate
"
)
windowStage
.
setUIContent
(
this
.
context
,
"
pages/index
"
,
null
)
console
.
log
(
"
[Demo] MainAbility onWindowStageCreate
"
);
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
()
{
...
...
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/MainAbility3/MainAbility3.ts
浏览文件 @
4015fba6
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -15,22 +14,34 @@
*/
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
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
"
MainAbility3 onCreate
"
)
}
onDestroy
(
want
)
{
onDestroy
()
{
// Ability is destroying, release resources for this ability
console
.
log
(
"
MainAbility3 onDestroy
"
)
}
onWindowStageCreate
(
windowStage
)
{
// Main window is created, set main page for this ability
console
.
log
(
"
MainAbility3 onWindowStageCreate
"
)
windowStage
.
setUIContent
(
this
.
context
,
"
pages/index
"
,
null
)
console
.
log
(
"
MainAbility3 onWindowStageCreate
"
)
;
windowStage
.
setUIContent
(
this
.
context
,
"
pages/index
"
,
null
)
;
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
()
{
...
...
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/MainAbility4/MainAbility4.ts
浏览文件 @
4015fba6
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -14,24 +13,34 @@
* limitations under the License.
*/
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
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
"
MainAbility4 onCreate
"
)
}
onDestroy
(
want
)
{
onDestroy
()
{
// Ability is destroying, release resources for this ability
console
.
log
(
"
MainAbility4 onDestroy
"
)
}
onWindowStageCreate
(
windowStage
)
{
// Main window is created, set main page for this ability
console
.
log
(
"
MainAbility4 onWindowStageCreate
"
)
windowStage
.
setUIContent
(
this
.
context
,
"
pages/index
"
,
null
)
console
.
log
(
"
MainAbility4 onWindowStageCreate
"
)
;
windowStage
.
setUIContent
(
this
.
context
,
"
pages/index
"
,
null
)
;
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
()
{
...
...
ability/ability_runtime/actsqueryfunctiontest/actsgetabilitystatestagetest/entry/src/main/ets/test/Ability.test.ets
浏览文件 @
4015fba6
...
...
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-nocheck
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
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() {
describe('ActsGetAbilityStateStageTest', function () {
...
...
@@ -27,31 +29,44 @@ export default function abilityTest() {
* @tc.desc : Get the status of the Ability in the BACKGROUND state
*/
it('ACTS_GetAbilityState_0200', 0, async function (done) {
console.debug('====>start ACTS_GetAbilityState_0200====');
var flag = true;
var ability;
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
console.log('====>start ACTS_GetAbilityState_0200====');
let ability;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let count = 0;
let subscriber;
function onAbilityForegroundCallback2(){
console.debug("====>onAbilityForegroundCallback2====");
console.log("====>onAbilityForegroundCallback2====");
count ++;
if (count == 2) {
abilityDelegator.getCurrentTopAbility((err, data)=>{
console.
debu
g("====>getCurrentTopAbility_0200 err:" + JSON.stringify(err) + " data:" + JSON.stringify(data));
console.
lo
g("====>getCurrentTopAbility_0200 err:" + JSON.stringify(err) + " data:" + JSON.stringify(data));
ability = data;
abilityDelegator.doAbilityBackground(ability, (err)=>{
console.
debu
g("====>doAbilityBackground_0200 data:" + JSON.stringify(err));
console.
lo
g("====>doAbilityBackground_0200 data:" + JSON.stringify(err));
expect(err.code).assertEqual(0);
})
})
}
}
function onAbilityBackgroundCallback2(){
console.
debu
g("====>onAbilityBackgroundCallback2====");
var
state = abilityDelegator.getAbilityState(ability);
console.
debu
g("====>ACTS_GetAbilityState_0200 state:" + state);
console.
lo
g("====>onAbilityBackgroundCallback2====");
let
state = abilityDelegator.getAbilityState(ability);
console.
lo
g("====>ACTS_GetAbilityState_0200 state:" + state);
expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.BACKGROUND);
console.debug("====>ACTS_GetAbilityState_0200 end====");
flag=false;
done();
console.log("====>ACTS_GetAbilityState_0200 end====");
commonEvent.unsubscribe(subscriber, UnSubscribeCallback);
}
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(
{abilityName: 'MainAbility2',
...
...
@@ -59,24 +74,15 @@ export default function abilityTest() {
onAbilityBackground:onAbilityBackgroundCallback2
}
).then(()=>{
console.
debu
g("====>addAbilityMonitor_0200 finish====");
console.
lo
g("====>addAbilityMonitor_0200 finish====");
globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.actsgetabilitystatestagetest',
abilityName: 'MainAbility2',
}, (err)=>{
console.
debu
g("====>startAbility_0200 err:" + JSON.stringify(err));
console.
lo
g("====>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() {
* @tc.desc : Get the status of the Ability in the FOREGROUND state
*/
it('ACTS_GetAbilityState_0300', 0, async function (done) {
console.debug('====>start ACTS_GetAbilityState_0300====');
var flag = true;
var ability;
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
console.log('====>start ACTS_GetAbilityState_0300====');
let ability;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let count = 0;
let subscriber;
function onAbilityForegroundCallback3(){
console.debug("====>onAbilityForegroundCallback3====");
console.log("====>onAbilityForegroundCallback3====");
count++;
if (count == 2) {
abilityDelegator.getCurrentTopAbility((err, data)=>{
console.
debu
g("====>getCurrentTopAbility_0300 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data));
console.
lo
g("====>getCurrentTopAbility_0300 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data));
ability = data;
var
state = abilityDelegator.getAbilityState(ability);
console.
debu
g("====>ACTS_GetAbilityState_0300 state:" + state);
let
state = abilityDelegator.getAbilityState(ability);
console.
lo
g("====>ACTS_GetAbilityState_0300 state:" + state);
expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.FOREGROUND);
expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.CREATE).assertTrue()
expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.DESTROY).assertTrue()
expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.CREATE).assertTrue()
;
expect(state != AbilityDelegatorRegistry.AbilityLifecycleState.DESTROY).assertTrue()
;
abilityDelegator.doAbilityBackground(ability, (err)=>{
console.
debu
g("====>doAbilityBackground_0300 data:" + JSON.stringify(err));
console.
lo
g("====>doAbilityBackground_0300 data:" + JSON.stringify(err));
expect(err.code).assertEqual(0);
console.debug("====>ACTS_GetAbilityState_0300 end====");
flag=false;
done();
console.log("====>ACTS_GetAbilityState_0300 end====");
commonEvent.unsubscribe(subscriber, UnSubscribeCallback);
})
})
}
setTimeout(()=>{
if(flag==true){
console.debug("====>in timeout 0300====");
expect().assertFail();
}
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();
}
},START_ABILITY_TIMEOUT)
abilityDelegator.addAbilityMonitor(
{abilityName: 'MainAbility3',
onAbilityForeground:onAbilityForegroundCallback3}).then(()=>{
console.
debu
g("====>addAbilityMonitor_0300 finish====");
console.
lo
g("====>addAbilityMonitor_0300 finish====");
globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.actsgetabilitystatestagetest',
abilityName: 'MainAbility3',
}, (err)=>{
console.
debu
g("====>startAbility_0300 err:" + JSON.stringify(err));
console.
lo
g("====>startAbility_0300 err:" + JSON.stringify(err));
})
})
})
...
...
@@ -135,13 +149,13 @@ export default function abilityTest() {
* @tc.desc : Get the status of an inactive or nonexistent Ability
*/
it('ACTS_GetAbilityState_0500', 0, async function (done) {
console.
debu
g('====>start ACTS_GetAbilityState_0500====');
var
ability = Object.create(null);
var
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var
state = abilityDelegator.getAbilityState(ability);
console.
debu
g("====>ACTS_GetAppState_0500 state:" + state);
console.
lo
g('====>start ACTS_GetAbilityState_0500====');
let
ability = Object.create(null);
let
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let
state = abilityDelegator.getAbilityState(ability);
console.
lo
g("====>ACTS_GetAppState_0500 state:" + state);
expect(state).assertEqual(undefined);
console.
debu
g("====>ACTS_GetAbilityState_0500 end====");
console.
lo
g("====>ACTS_GetAbilityState_0500 end====");
done();
})
...
...
@@ -151,49 +165,56 @@ export default function abilityTest() {
* @tc.desc : Get the status of the Ability in the uninitialized state
*/
it('ACTS_GetAbilityState_0600', 0, async function (done) {
console.debug('====>start ACTS_GetAbilityState_0600====')
var flag = true;
var ability;
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
console.log('====>start ACTS_GetAbilityState_0600====');
let ability;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let count = 0;
let subscriber;
function onAbilityForegroundCallback6(){
console.debug("====>onAbilityForegroundCallback6====");
console.log("====>onAbilityForegroundCallback6====");
count++;
if (count == 2) {
abilityDelegator.getCurrentTopAbility((err, data)=>{
console.
debu
g("====>getCurrentTopAbility_0600 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data));
console.
lo
g("====>getCurrentTopAbility_0600 err:" + JSON.stringify(err) + "data:" + JSON.stringify(data));
ability = data;
globalThis.ability4Context.terminateSelf();
})
}
}
function onAbilityDestroyCallback6(){
console.
debu
g("====>onAbilityDestroyCallback6====");
var
state = abilityDelegator.getAbilityState(ability);
console.
debu
g("====>ACTS_GetAbilityState_0600 data:" + state);
console.
debu
g("====>UNINITIALIZED:"+ AbilityDelegatorRegistry.AbilityLifecycleState.UNINITIALIZED);
console.
lo
g("====>onAbilityDestroyCallback6====");
let
state = abilityDelegator.getAbilityState(ability);
console.
lo
g("====>ACTS_GetAbilityState_0600 data:" + state);
console.
lo
g("====>UNINITIALIZED:"+ AbilityDelegatorRegistry.AbilityLifecycleState.UNINITIALIZED);
expect(state).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.UNINITIALIZED);
console.debug("====>ACTS_GetAbilityState_0600 end====");
flag=false;
done();
console.log("====>ACTS_GetAbilityState_0600 end====");
commonEvent.unsubscribe(subscriber, UnSubscribeCallback);
}
setTimeout(()=>{
if(flag==true){
console.debug("====>in timeout 0600===");
expect().assertFail();
commonEvent.createSubscriber(subscriberInfo_MainAbility).then(async (data) => {
console.log("ACTS_GetAbilityState_0600====>Create Subscriber====>");
subscriber = data;
await commonEvent.subscribe(subscriber, onAbilityForegroundCallback6);
})
function UnSubscribeCallback() {
console.log("ACTS_GetAbilityState_0600====>UnSubscribe CallBack====>");
done();
}
},START_ABILITY_TIMEOUT)
abilityDelegator.addAbilityMonitor(
{abilityName: 'MainAbility4',
onAbilityForeground:onAbilityForegroundCallback6,
onAbilityDestroy:onAbilityDestroyCallback6}).then(()=>{
console.
debu
g("====>addAbilityMonitor_0600 finish====");
console.
lo
g("====>addAbilityMonitor_0600 finish====");
globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.actsgetabilitystatestagetest',
abilityName: 'MainAbility4',
}, (err)=>{
console.
debu
g("====>startAbility_0600 err:" + JSON.stringify(err));
console.
lo
g("====>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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录