提交 91412330 编写于 作者: X xialiangwei

add xts napi testcase for uiextension

Signed-off-by: Nxialiangwei <xialiangwei1@huawei.com>
Change-Id: Id9a6adce878ad7e728c9ac2bdc8d8f9f1296a28c
上级 bbabf558
......@@ -19,6 +19,7 @@ group("actsuiextensiontest") {
deps = [
"uiextensionprovider:UIExtensionProvider",
"uiextensiontest:UIExtensionTest",
"actsabilityusertest:ActsAmsStartAbilityUser",
]
}
}
{
"app": {
"bundleName": "com.example.actsabilityusertest",
"vendor": "huawei",
"versionCode": 1000000,
"versionName": "1.0.0",
"debug": false,
"icon" : "$media:icon",
"label" : "$string:app_name",
"description" : "$string:description_application",
"distributedNotificationEnabled": true,
"keepAlive" : true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsAmsStartAbilityUser") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":actsamsstartabilityuser_js_assets",
":actsamsstartabilityuser_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsAmsStartAbilityUser"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("actsamsstartabilityuser_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("actsamsstartabilityuser_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("actsamsstartabilityuser_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":actsamsstartabilityuser_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for aceceshi Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.example.actsabilityusertest",
"module-name": "entry",
"shell-timeout": "600000"
},
"kits": [
{
"test-file-name": [
"ActsAmsStartAbilityUser.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
import AbilityStage from "@ohos.app.ability.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
import Ability from '@ohos.app.ability.UIAbility'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
console.log('MainAbility onCreate')
}
onDestroy() {
console.log('MainAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('MainAbility onWindowStageCreate')
windowStage.setUIContent(this.context, 'MainAbility/pages/index', null)
}
onWindowStageDestroy() {
console.log('MainAbility onWindowStageDestroy')
}
onForeground() {
console.log('MainAbility onForeground')
setTimeout(()=>{
this.context.terminateSelf().then((data) => {
console.info("com.example.actsabilityusertest MainAbility terminateSelf data = " + JSON.stringify(data));
}).catch((err) => {
console.info("com.example.actsabilityusertest MainAbility terminateSelf err = " + JSON.stringify(err));
});
}, 2000)
}
onBackground() {
console.log('MainAbility onBackground')
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@ohos.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('MainAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.app.ability.UIAbility'
import commonEventManager from '@ohos.commonEventManager'
function PublishCallBackOne() {
console.debug("====>Publish CallBack ACTS_StartAbility_0100_CommonEvent====>");
globalThis.ability2Context.terminateSelf().then(()=>{
console.debug("====>publish ACTS_TerminateSelf_CommonEvent finish====>")
});
console.debug("====>terminateSelf succese====>")
}
export default class MainAbility2 extends Ability {
onCreate(want, launchParam) {
console.log("MainAbility2 onCreate");
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("MainAbility2 onDestroy");
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("MainAbility2 onWindowStageCreate");
windowStage.setUIContent(this.context, "pages/index2", null);
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
globalThis.ability2Context = this.context;
commonEventManager.publish(onResultEvent, PublishCallBackOne);
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("MainAbility2 onWindowStageDestroy");
}
onForeground() {
// Ability has brought to foreground
console.log("MainAbility2 onForeground");
}
onBackground() {
// Ability has back to background
console.log("MainAbility2 onBackground");
}
};
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.app.ability.UIAbility'
export default class MainAbility3 extends Ability {
onCreate(want, launchParam) {
console.log("MainAbility3 onCreate");
}
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/index3", null);
globalThis.abilityContext3 = this.context;
globalThis.abilityContext3.terminateSelfWithResult(
{
resultCode:1,
want:{
action:'ACTION'
}
},()=>{
console.debug("====>terminateSelfWithResult succese====>")
});
console.debug("====>terminateSelf end====>")
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("MainAbility3 onWindowStageDestroy");
}
onForeground() {
// Ability has brought to foreground
console.log("MainAbility3 onForeground");
}
onBackground() {
// Ability has back to background
console.log("MainAbility3 onBackground");
}
};
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var MainAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: MainAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World3'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World3'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import commonEvent from '@ohos.commonEvent'
var subscriberInfo_MainAbility = {
events: ["ACTS_StartAbility_CommonEvent"]
};
const START_ABILITY_TIMEOUT = 4000;
export default function abilityTest() {
describe('ACTS_StartAbility_Test', function () {
/*
* @tc.number : ACTS_StartAbility_Callback_Successfully_0100
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability succeeded.(callback)
*/
it('ACTS_StartAbility_Callback_Successfully_0100', 0, async function (done) {
var Subscriber
var flag = true
var startresult = false
function SubscribeCallBack(err, data) {
expect(data.event == "ACTS_StartAbility_CommonEvent").assertTrue();
console.log("====>0100 Subscribe CallBack data:====>" + JSON.stringify(data));
if (data.event == "ACTS_StartAbility_CommonEvent") {
startresult = true
}
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
flag = false
expect(startresult).assertEqual(true);
done();
}
await commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2'
}, () => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
if (flag == true) {
expect().assertFail();
console.log('ACTS_StartAbility_Callback_Successfully_0100 - timeout')
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
/*
* @tc.number : ACTS_StartAbility_Callback_Error_0200
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability failed.(callback)
*/
it('ACTS_StartAbility_Callback_Error_0200', 0, async function (done) {
var AbilityDelegatorArgs = AbilityDelegatorRegistry.getArguments()
console.log("====>getArguments is====>" + JSON.stringify(AbilityDelegatorArgs));
var Subscriber
function SubscribeCallBack(err, data) {
expect().assertFail();
console.log("====>0200 Subscribe CallBack data:====>" + JSON.stringify(data));
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
done();
}
await commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
await globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.error',
abilityName: 'com.example.error.MainAbility2'
}, () => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
console.log('ACTS_StartAbility_Callback_Error_0200 - timeout');
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
/*
* @tc.number : ACTS_StartAbility_Promise_Successfully_0100
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability succeeded.(callback)
*/
it('ACTS_StartAbility_Promise_Successfully_0100', 0, async function (done) {
var Subscriber
var flag = true
var startresult = false
function SubscribeCallBack(err, data) {
expect(data.event == "ACTS_StartAbility_CommonEvent").assertTrue();
console.log("====>0100 Subscribe CallBack data:====>" + JSON.stringify(data));
if (data.event == "ACTS_StartAbility_CommonEvent") {
startresult = true
}
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
flag = false
expect(startresult).assertEqual(true);
done();
}
commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
await globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3'
}).then(() => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
if (flag == true) {
expect().assertFail();
console.log('ACTS_StartAbility_Promise_Successfully_0100 - timeout');
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
/*
* @tc.number : ACTS_StartAbility_Promise_Error_0200
* @tc.name : start new ability
* @tc.desc : Starting mainability2 with startability failed.(callback)
*/
it('ACTS_StartAbility_Promise_Error_0200', 0, async function (done) {
var AbilityDelegatorArgs = AbilityDelegatorRegistry.getArguments()
console.log("====>getArguments is====>" + JSON.stringify(AbilityDelegatorArgs));
var Subscriber
function SubscribeCallBack(err, data) {
expect().assertFail();
console.log("====>0200 Subscribe CallBack data:====>" + JSON.stringify(data));
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback);
}
function UnSubscribeCallback() {
console.log("====>UnSubscribeCallback====>");
done();
}
commonEvent.createSubscriber(subscriberInfo_MainAbility).then((data) => {
console.log("====>Create Subscriber====>");
data.getSubscribeInfo().then(async (SubscribeInfo) => {
console.log("====>SubscribeInfo is====>" + JSON.stringify(SubscribeInfo));
Subscriber = data;
commonEvent.subscribe(Subscriber, SubscribeCallBack);
console.log("====>start startAbility====>");
globalThis.abilityContext.startAbility(
{
bundleName: 'com.example.error',
abilityName: 'com.example.error.MainAbility2'
}).then(() => {
console.log("====>startAbility end====>");
})
})
})
function timeout() {
console.log('ACTS_StartAbility_Promise_Error_0200 - timeout');
commonEvent.unsubscribe(Subscriber, UnSubscribeCallback)
}
setTimeout(timeout, START_ABILITY_TIMEOUT);
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import abilityTest from './Ability.test'
export default function testsuite() {
abilityTest()
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
},
{
"name": "MainAbility2",
"srcEntrance": "./ets/MainAbility2/MainAbility2.ts",
"description": "$string:MainAbility2_desc",
"icon": "$media:icon",
"label": "$string:MainAbility2_label",
"visible": true
},
{
"name": "MainAbility3",
"srcEntrance": "./ets/MainAbility3/MainAbility3.ts",
"description": "$string:MainAbility3_desc",
"icon": "$media:icon",
"label": "$string:MainAbility3_label",
"visible": true
}
]
}
}
\ No newline at end of file
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "MainAbility2_desc",
"value": "description"
},
{
"name": "MainAbility2_label",
"value": "label"
},
{
"name": "MainAbility3_desc",
"value": "description"
},
{
"name": "MainAbility3_label",
"value": "label"
},
{
"name": "app_name",
"value": "actsabilityusertest"
},
{
"name": "description_application",
"value": "demo for test"
}
]
}
\ No newline at end of file
......@@ -18,6 +18,9 @@ import commonEventManager from '@ohos.commonEventManager'
import Logger from '../model/Logger'
import common from '@ohos.app.ability.common';
let context= getContext(this) as common.UIExtensionContext;
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
const TAG: string = '[UIExtAbility]'
const sleepTimeOne = 1000;
......@@ -50,10 +53,24 @@ struct Index {
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult';
let sendDataEvent = 'ACTS_UIExtension_SendData';
let startAbilityEvent = 'ACTS_UIExtension_StartAbility';
let startAbilityOpsEvent = 'ACTS_UIExtension_StartAbility_Options';
let startAbilityEventPromise = 'ACTS_UIExtension_StartAbility_Promise';
let startAbilityOpsEventPromise = 'ACTS_UIExtension_StartAbility_Options_Promise';
let startAbilityForResultEvent = 'ACTS_UIExtension_StartAbilityForResult';
let startAbilityForResultOpsEvent = 'ACTS_UIExtension_StartAbilityForResult_Options';
let startAbilityForResultEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Promise';
let startAbilityForResultOpsEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise';
var subscriber;
var startresult = false;
var subscribeInfo = {
events: [terminateSelfWithResultEvent, sendDataEvent]
events: [startAbilityEvent, startAbilityOpsEvent, startAbilityEventPromise,
startAbilityOpsEventPromise, startAbilityForResultEvent,
startAbilityForResultOpsEvent, startAbilityForResultEventPromise,
startAbilityForResultOpsEventPromise,
terminateSelfWithResultEvent, sendDataEvent]
}
commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
......@@ -100,7 +117,178 @@ struct Index {
}).catch((err)=>{
console.log(TAG + "setWindowPrivacyModeFalsePromise : " + JSON.stringify(err));
})
} else if(data.event == startAbilityEvent) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
}, () => {
console.log(TAG + "====>startAbilityEvent end====>" );
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityOpsEvent) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
},
{
windowMode: 0,
displayId: 15
}, () => {
console.log(TAG + "====>startAbilityOpsEvent end====>" );
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityEventPromise) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
}).then((data)=>{
console.log(TAG + "====>startAbilityEventPromise end====>");
console.log(TAG + "====>data is====>" + JSON.stringify(data));
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityOpsEventPromise) {
this.session.startAbility(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility2',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
},
{
windowMode: 0,
displayId: 15
}).then((data)=>{
console.log(TAG + "====>startAbilityOpsEventPromise end====>");
console.log(TAG + "====>data is====>" + JSON.stringify(data));
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultEvent) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
}, (err,data) => {
console.log(TAG + "====>startAbilityForResultEvent end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_OnResult failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_OnResult success');
}
});
}
})
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultOpsEvent) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
},
{
windowMode: 0,
displayId: 15
}, (err,data) => {
console.log(TAG + "====>startAbilityForResultOpsEvent end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_Options_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_OnResult failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_Options_OnResult success');
}
});
}
})
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultEventPromise) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
}).then((data) => {
console.log(TAG + "====>startAbilityForResultEventPromise end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_Promise_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Promise_OnResult failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_Promise_OnResult success');
}
});
}
})
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if(data.event == startAbilityForResultOpsEventPromise) {
var flag = true
this.session.startAbilityForResult(
{
bundleName: 'com.example.actsabilityusertest',
abilityName: 'MainAbility3',
parameters:{
"ability.params.backToOtherMissionStack":true,
},
},
{
windowMode: 0,
displayId: 15
}).then((data) => {
console.log(TAG + "====>startAbilityForResultOpsEventPromise end====>" + JSON.stringify(data));
if(data.resultCode == 1 && data.want.action=='ACTION') {
commonEventManager.publish('ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult', (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult success');
}
});
}
})
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber error : " + JSON.stringify(error));
......
......@@ -12,7 +12,8 @@
{
"test-file-name": [
"UIExtensionTest.hap",
"UIextensionProvider.hap"
"UIextensionProvider.hap",
"ActsAmsStartAbilityUser.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -144,5 +144,466 @@ export default function abilityTest() {
done();
})
})
it('ACTS_UIExtension_StartAbility_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityEvent = 'ACTS_UIExtension_StartAbility';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbility_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_001 success');
}
});
} else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
it('ACTS_UIExtension_StartAbility_Options_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_Options_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityOpsEvent = 'ACTS_UIExtension_StartAbility_Options';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility_Options - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityOpsEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbility_Options_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_Options_001 success');
}
});
} else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
it('ACTS_UIExtension_StartAbility_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_Promise_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityEventPromise = 'ACTS_UIExtension_StartAbility_Promise';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility_Promise - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbility_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_Promise_001 success');
}
});
} else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
it('ACTS_UIExtension_StartAbility_Options_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbility_Options_Promise_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult';
let startAbilityOpsEventPromise = 'ACTS_UIExtension_StartAbility_Options_Promise';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbility_Options_Promise - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityOpsEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbility_Options_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbility_Options_Promise_001 success');
}
});
} else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
it('ACTS_UIExtension_StartAbilityForResult_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_OnResult';
let startAbilityForResultEvent = 'ACTS_UIExtension_StartAbilityForResult';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResultEvent failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResultEvent success');
}
});
}
else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
it('ACTS_UIExtension_StartAbilityForResult_Options_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_Options_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_Options_OnResult';
let startAbilityForResultOpsEvent = 'ACTS_UIExtension_StartAbilityForResult_Options';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult_Options - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultOpsEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_Options_001 success');
}
});
}
else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
it('ACTS_UIExtension_StartAbilityForResult_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_Promise_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_Promise_OnResult';
let startAbilityForResultEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Promise';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult_Promise - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_Promise_001 success');
}
});
}
else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
it('ACTS_UIExtension_StartAbilityForResult_Options_Promise_001',0, async function (done) {
TAG = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise_OnResult';
let startAbilityForResultOpsEventPromise = 'ACTS_UIExtension_StartAbilityForResult_Options_Promise';
var flag = true
function UnSubscribeCallback() {
console.log(TAG + "UnSubscribeInfoCallback");
flag = false;
done();
}
function timeout() {
if(flag == true) {
expect().assertFail();
console.debug(TAG + 'StartAbilityForResult_Options_Promise - timeout');
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback)
}
}
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(startAbilityForResultOpsEventPromise, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_StartAbilityForResult_Options_Promise_001 failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_StartAbilityForResult_Options_Promise_001 success');
}
});
}
else if (data.event == onResultEvent) {
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, UnSubscribeCallback);
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
setTimeout(timeout, 10000);
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册