未验证 提交 6ebc1469 编写于 作者: O openharmony_ci 提交者: Gitee

!9981 修复ActsOnAndOffScreenTest时序问题

Merge pull request !9981 from 于文泽/onOff
...@@ -441,7 +441,7 @@ export default function OnAndOffScreenTest() { ...@@ -441,7 +441,7 @@ export default function OnAndOffScreenTest() {
let flag = false; let flag = false;
let status1 = undefined; let status1 = undefined;
let lifeList = []; let lifeSet = new Set();
let listCheck = ["onCreate", "onWindowStageCreate", "onForeground", "onBackground"]; let listCheck = ["onCreate", "onWindowStageCreate", "onForeground", "onBackground"];
let onCreate = "StageOnAndOffScreen_MainAbility2_onCreate"; let onCreate = "StageOnAndOffScreen_MainAbility2_onCreate";
let onWindowStageCreate = "StageOnAndOffScreen_MainAbility2_onWindowStageCreate"; let onWindowStageCreate = "StageOnAndOffScreen_MainAbility2_onWindowStageCreate";
...@@ -465,27 +465,27 @@ export default function OnAndOffScreenTest() { ...@@ -465,27 +465,27 @@ export default function OnAndOffScreenTest() {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data)); console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == onCreate) { if (data.event == onCreate) {
lifeList.push("onCreate"); lifeSet.add("onCreate");
} }
if (data.event == onWindowStageCreate) { if (data.event == onWindowStageCreate) {
lifeList.push("onWindowStageCreate"); lifeSet.add("onWindowStageCreate");
} }
if (data.event == onForeground) { if (data.event == onForeground) {
lifeList.push("onForeground"); lifeSet.add("onForeground");
} }
if (data.event == onBackground) { if (data.event == onBackground) {
lifeList.push("onBackground"); lifeSet.add("onBackground");
} }
if (data.event == onWindowStageDestroy) { if (data.event == onWindowStageDestroy) {
lifeList.push("onWindowStageDestroy"); lifeSet.add("onWindowStageDestroy");
} }
if (data.event == onDestroy) { if (data.event == onDestroy) {
lifeList.push("onDestroy"); lifeSet.add("onDestroy");
} }
if (data.event == onForeground2 && !flag) { if (data.event == onForeground2 && !flag) {
...@@ -497,7 +497,9 @@ export default function OnAndOffScreenTest() { ...@@ -497,7 +497,9 @@ export default function OnAndOffScreenTest() {
setTimeout(async () => { setTimeout(async () => {
commonEvent.unsubscribe(subscriber, async (err, data) => { commonEvent.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data)); console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
expect(JSON.stringify(lifeList)).assertEqual(JSON.stringify(listCheck)); for (let i in listCheck) {
expect(lifeSet.has(listCheck[i])).assertTrue();
}
expect(status1).assertTrue(); expect(status1).assertTrue();
done(); done();
}); });
......
...@@ -496,32 +496,31 @@ export default function lifecycleTest() { ...@@ -496,32 +496,31 @@ export default function lifecycleTest() {
console.log(TAG + " listKey1 : " + JSON.stringify(globalThis.list1)); console.log(TAG + " listKey1 : " + JSON.stringify(globalThis.list1));
console.log(TAG + " callbackid1 : " + JSON.stringify(globalThis.callbackid1)); console.log(TAG + " callbackid1 : " + JSON.stringify(globalThis.callbackid1));
var strtemp = ""; var strtemp = "";
var listtemp = []; let settemp = new Set();
var listtemp2 = []; let settemp2 = new Set();
for (var i = 0; i < globalThis.list1.length; i++) { for (var i = 0; i < globalThis.list1.length; i++) {
strtemp = globalThis.list1[i].substring(0, 12); strtemp = globalThis.list1[i].substring(0, 12);
if (strtemp == "MainAbility2") { if (strtemp == "MainAbility2") {
listtemp.push(globalThis.list1[i]); settemp.add(globalThis.list1[i]);
console.log(TAG + " set1 is :" + JSON.stringify(globalThis.list1[i]));
} else if (strtemp == "MainAbility5") { } else if (strtemp == "MainAbility5") {
listtemp2.push(globalThis.list1[i]); settemp2.add(globalThis.list1[i]);
console.log(TAG + " set2 is :" + JSON.stringify(globalThis.list1[i]));
} }
} }
console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); expect(settemp.has("MainAbility2 onAbilityCreate")).assertTrue();
console.log(TAG + " listtemp2 is :" + JSON.stringify(listtemp2)); expect(settemp.has("MainAbility2 onWindowStageCreate")).assertTrue();
let exlist = listtemp; expect(settemp.has("MainAbility2 onAbilityForeground")).assertTrue();
let exlist2 = listtemp2; expect(settemp.has("MainAbility2 onAbilityBackground")).assertTrue();
expect(exlist[0]).assertEqual("MainAbility2 onAbilityCreate"); expect(settemp.has("MainAbility2 onWindowStageDestroy")).assertTrue();
expect(exlist[1]).assertEqual("MainAbility2 onWindowStageCreate"); expect(settemp.has("MainAbility2 onAbilityDestroy")).assertTrue();
expect(exlist[2]).assertEqual("MainAbility2 onAbilityForeground");
expect(exlist[3]).assertEqual("MainAbility2 onAbilityBackground"); expect(settemp2.has("MainAbility5 onAbilityCreate")).assertTrue();
expect(exlist[4]).assertEqual("MainAbility2 onWindowStageDestroy"); expect(settemp2.has("MainAbility5 onWindowStageCreate")).assertTrue();
expect(exlist[5]).assertEqual("MainAbility2 onAbilityDestroy"); expect(settemp2.has("MainAbility5 onAbilityForeground")).assertTrue();
expect(exlist2[0]).assertEqual("MainAbility5 onAbilityCreate"); expect(settemp2.has("MainAbility5 onAbilityBackground")).assertTrue();
expect(exlist2[1]).assertEqual("MainAbility5 onWindowStageCreate"); expect(settemp2.has("MainAbility5 onWindowStageDestroy")).assertTrue();
expect(exlist2[2]).assertEqual("MainAbility5 onAbilityForeground"); expect(settemp2.has("MainAbility5 onAbilityDestroy")).assertTrue();
expect(exlist2[3]).assertEqual("MainAbility5 onAbilityBackground");
expect(exlist2[4]).assertEqual("MainAbility5 onWindowStageDestroy");
expect(exlist2[5]).assertEqual("MainAbility5 onAbilityDestroy");
globalThis.applicationContext1 globalThis.applicationContext1
.unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => { .unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册