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

!9244 UIExtensionAbility支持拉起应用, 并可返回应用的操作结果xts测试

Merge pull request !9244 from xinking129/master
......@@ -29,6 +29,7 @@ group("ability_runtime") {
"actscalltest:actscalltest",
"actscrosscall:actscrosscall",
"actsdataabilityaccessdatasharetest:dataabilityaccessdatashare",
"actsforresult:actsforresult",
"actsfwkdataaccessortest:dataability",
"actsmultiplecall:actsmultiplecall",
"actsnfcselecttypes:actsnfcselecttypes",
......
# Copyright (c) 2023 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")
group("actsforresult") {
testonly = true
if (is_standard_system) {
deps = [
"forresulttest:forresulttest",
"forresulttestnopermission:forresulttestnopermission",
"main:main",
"maintest:maintest",
]
}
}
{
"app": {
"bundleName": "com.example.forresulttestsecond",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive" : true,
"singleUser": true,
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (c) 2023 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_hap_assist_suite("forresulttest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":forresulttest_js_assets",
":forresulttest_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "forresulttest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("forresulttest_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("forresulttest_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("forresulttest_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":forresulttest_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
/*
* Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
import wantConstant from '@ohos.app.ability.wantConstant';
import commonEvent from '@ohos.commonEventManager';
import hilog from '@ohos.hilog';
export default class UiExtAbility extends UIExtensionAbility {
onCreate() {
hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s');
console.info('=======>UIExtAbility onCreate======>');
}
onSessionCreate(want, session) {
console.log(`want: ${JSON.stringify(want)}}`);
let storage: LocalStorage = new LocalStorage({
'session': session
});
session.loadContent('pages/Page', storage);
console.info('=======>UIExtAbility onSessionCreate======>');
if (want.action === 'AsyncCallback_0200') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0200======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0200',
bundleName: 'com.example.mainhap',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0200 first from another error.code ======>' + error.code);
console.info('=======>Callback_0200 first from another data.resultCode ======>' + data.resultCode);
console.info('=======>Callback_0200 first from another data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
num: error.code,
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0200 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'AsyncCallback_0300') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0200======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0300',
bundleName: 'com.example.mainhap',
abilityName: 'OtherAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0300 first from another error.code ======>' + error.code);
console.info('=======>Callback_0300 first from another data.resultCode ======>' + data.resultCode);
console.info('=======>Callback_0300 first from another data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
num: error.code,
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT_ANOTHER', commonEventData, (err) => {
console.debug('====>AsyncCallback_0300 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Promise_0200') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0200======>');
this.context.startAbilityForResult({
action: 'Promise_0200',
bundleName: 'com.example.mainhap',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Promise_0200 first from another data.resultCode ======>' + data.resultCode);
console.info('=======>Promise_0200 first from another data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Promise_0200 first publish err:' + JSON.stringify(err));
});
}).catch((error) => {
console.info('=======>Promise_0200 first from another error.code ======>' + error.code);
});
}
if (want.action === 'Promise_0300') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0300======>');
this.context.startAbilityForResult({
action: 'Promise_0300',
bundleName: 'com.example.mainhap',
abilityName: 'OtherAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Promise_0300 first from another data.resultCode ======>' + data.resultCode);
console.info('=======>Promise_0300 first from another data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT_ANOTHER', commonEventData, (err) => {
console.debug('====>Promise_0300 first publish err:' + JSON.stringify(err));
});
}).catch((error) => {
console.info('=======>Promise_0300 first from another error.code ======>' + error.code);
});
}
}
onSessionDestroy(session) {
console.log('onSessionDestroy');
}
onDestroy() {
console.info('=======>UIExtensionAbility onDestroy ======>');
}
onForeground() {
// Ability has brought to foreground
console.log('=====> UIExtAbility onForeground =====> ');
}
};
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
export default class CalledAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onCreate');
console.log('=====> second app CalledAbility bas been created =====>');
if (want.action === 'AsyncCallback_0200') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> AsyncCallback_0200 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/PageTwo', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onBackground');
}
}
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
console.info('====>another EntryAbility');
if (want.action === 'AsyncCallback_0200') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0200':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0200',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'AsyncCallback_0300') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0300':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0300',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'Promise_0200') {
console.info("====>EntryAbility want.action == 'Promise_0200':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0200',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'Promise_0300') {
console.info("====>EntryAbility want.action == 'Promise_0300':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0300',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'UIExtAbility'
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
/*
* Copyright (c) 2023 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 Want from '@ohos.app.ability.Want';
@Entry
@Component
struct Index {
@State message: string = 'Second application'
@StorageLink('want') want: Want = {
action: "AsyncCallback_0200",
bundleName: 'com.example.forresulttestsecond',
abilityName: 'UIExtAbility'
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
UIExtensionComponent(this.want)
.size({width:'100%',height:'100'})
.backgroundColor(Color.Blue)
.border({width:5,color:Color.Red})
Button('StartAbilityForResult')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult()
})
.margin({
top: 5
})
Button('StartUI')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.startUIExtension()
})
.margin({
top: 5
})
Button('StartCalledAbilitybyUIExtension')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
console.info('=======>button======>');
globalThis.StartAbilityForResult_AsyncCallback_0100()
})
.margin({
top: 5
})
Button('terminal')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.terminal()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 Want from '@ohos.app.ability.Want';
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
let storage = LocalStorage.GetShared()
@Entry(storage)
@Component
struct Page {
@State message: string = 'UIExtAbility'
private session: UIExtensionContentSession = storage.get<UIExtensionContentSession>('session');
build() {
Row() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 PageTwo {
@State message: string = 'Second application'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button('TerminateCallback0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_CallBack()
})
.margin({
top: 5
})
Button('TerminatePromise0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_Promise()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
},
{
"name": "CalledAbility",
"srcEntry": "./ets/calledability/CalledAbility.ts",
"description": "$string:CalledAbility_desc",
"visible": true,
"icon": "$media:icon",
"label": "$string:CalledAbility_label",
"launchType": "standard",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
}
],
"extensionAbilities": [
{
"name": "UIExtAbility",
"icon": "$media:icon",
"description": "UIExtAbility",
"type": "ui",
"visible": true,
"srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts"
}
],
"requestPermissions": [
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
},
{
"name": "ohos.permission.START_INVISIBLE_ABILITY"
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.forresulttestthrid",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive" : true,
"singleUser": true,
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (c) 2023 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_hap_assist_suite("forresulttestnopermission") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":forresulttestnopermission_js_assets",
":forresulttestnopermission_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "forresulttestnopermission"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("forresulttestnopermission_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("forresulttestnopermission_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("forresulttestnopermission_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":forresulttestnopermission_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
/*
* Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
import wantConstant from '@ohos.app.ability.wantConstant';
import commonEvent from '@ohos.commonEventManager';
import hilog from '@ohos.hilog';
export default class UiExtAbility extends UIExtensionAbility {
onCreate() {
hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s');
console.info('=======>UIExtAbility onCreate======>');
}
onSessionCreate(want, session) {
console.log(`want: ${JSON.stringify(want)}}`);
let storage: LocalStorage = new LocalStorage({
'session': session
});
session.loadContent('pages/Page', storage);
console.info('=======>UIExtAbility onSessionCreate======>');
if (want.action === 'AsyncCallback_0600') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0600======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0600',
bundleName: 'com.example.mainhap',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0600 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0600 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'AsyncCallback_0700') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0700======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0700',
bundleName: 'com.example.mainhap',
abilityName: 'OtherAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0700 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0700 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Promise_0600') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0600======>');
this.context.startAbilityForResult({
action: 'Promise_0600',
bundleName: 'com.example.mainhap',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Promise_0600 startAbilityForResult ok ======>');
}).catch((error) => {
console.info('=======>Promise_0600 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Promise_0600 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Promise_0700') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0700======>');
this.context.startAbilityForResult({
action: 'Promise_0700',
bundleName: 'com.example.mainhap',
abilityName: 'OtherAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Promise_0700 startAbilityForResult ok ======>');
}).catch((error) => {
console.info('=======>Promise_0700 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0700 first publish err:' + JSON.stringify(err));
});
});
}
}
onSessionDestroy(session) {
console.log('onSessionDestroy');
}
onDestroy() {
console.info('=======>UIExtensionAbility onDestroy ======>');
}
onForeground() {
// Ability has brought to foreground
console.log('=====> UIExtAbility onForeground =====> ');
}
};
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
export default class CalledAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onCreate');
console.log('=====> second app CalledAbility bas been created =====>');
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/PageTwo', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onBackground');
}
}
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
console.info('====>another EntryAbility');
if (want.action === 'AsyncCallback_0600') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0600':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0600',
bundleName: 'com.example.forresulttestthrid',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'AsyncCallback_0700') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0700':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0700',
bundleName: 'com.example.forresulttestthrid',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'Promise_0600') {
console.info("====>EntryAbility want.action == 'Promise_0600':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0600',
bundleName: 'com.example.forresulttestthrid',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'Promise_0700') {
console.info("====>EntryAbility want.action == 'Promise_0700':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0700',
bundleName: 'com.example.forresulttestthrid',
abilityName: 'UIExtAbility'
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onNewWant(want, launchParams) {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
if (want.action === 'AsyncCallback_0200') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0200':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0200',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'AsyncCallback_0300') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0300':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0300',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'UIExtAbility'
});
}
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
/*
* Copyright (c) 2023 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 Want from '@ohos.app.ability.Want';
@Entry
@Component
struct Index {
@State message: string = 'Second application'
@StorageLink('want') want: Want = {
action: "AsyncCallback_0600",
bundleName: 'com.example.forresulttestthrid',
abilityName: 'UIExtAbility'
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
UIExtensionComponent(this.want)
.size({width:'100%',height:'100'})
.backgroundColor(Color.Blue)
.border({width:5,color:Color.Red})
Button('StartAbilityForResult')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult()
})
.margin({
top: 5
})
Button('StartUI')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.startUIExtension()
})
.margin({
top: 5
})
Button('StartCalledAbilitybyUIExtension')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
console.info('=======>button======>');
globalThis.StartAbilityForResult_AsyncCallback_0100()
})
.margin({
top: 5
})
Button('terminal')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.terminal()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 Want from '@ohos.app.ability.Want';
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
let storage = LocalStorage.GetShared()
@Entry(storage)
@Component
struct Page {
@State message: string = 'UIExtAbility'
private session: UIExtensionContentSession = storage.get<UIExtensionContentSession>('session');
build() {
Row() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 PageTwo {
@State message: string = 'Second application'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button('TerminateCallback0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_CallBack()
})
.margin({
top: 5
})
Button('TerminatePromise0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_Promise()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
},
{
"name": "CalledAbility",
"srcEntry": "./ets/calledability/CalledAbility.ts",
"description": "$string:CalledAbility_desc",
"visible": true,
"icon": "$media:icon",
"label": "$string:CalledAbility_label",
"launchType": "standard",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
}
],
"extensionAbilities": [
{
"name": "UIExtAbility",
"icon": "$media:icon",
"description": "UIExtAbility",
"type": "ui",
"visible": true,
"srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts"
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.mainhap",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive" : true,
"singleUser": true,
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
}
]
}
# Copyright (c) 2023 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_hap_assist_suite("main") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":main_js_assets",
":main_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "main"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("main_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("main_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("main_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":main_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
/*
* Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
import wantConstant from '@ohos.app.ability.wantConstant';
import commonEvent from '@ohos.commonEventManager';
// import Logger from '../model/Logger'
import hilog from '@ohos.hilog';
// const TAG: string = '[UIExtensionAbility]'
export default class UiExtAbility extends UIExtensionAbility {
onCreate() {
hilog.info(0x0000, 'testTag', 'UIExtAbility onCreate want: %{public}s');
console.info('=======>UIExtAbility onCreate======>');
}
onSessionCreate(want, session) {
console.log(`want: ${JSON.stringify(want)}}`);
let storage: LocalStorage = new LocalStorage({
'session': session
});
session.loadContent('pages/Page', storage);
console.info('=======>UIExtAbility onSessionCreate======>');
if (want.action === 'AsyncCallback_0100') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0100======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0100',
bundleName: 'com.example.mainhap',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0100 error.code ======>' + error.code);
console.info('=======>Callback_0100 data.resultCode ======>' + data.resultCode);
console.info('=======>Callback_0100 data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
num: error.code,
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0100 publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'AsyncCallback_0300') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0300======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0300',
bundleName: 'com.example.mainhap',
abilityName: 'OtherAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0300 first from own error.code ======>' + error.code);
console.info('=======>Callback_0300 first from own data.resultCode ======>' + data.resultCode);
console.info('=======>Callback_0300 first from own data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
num: error.code,
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0300 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'AsyncCallback_0400') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0400======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0400',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0400 first from own error.code ======>' + error.code);
console.info('=======>Callback_0400 first from own data.resultCode ======>' + data.resultCode);
console.info('=======>Callback_0400 first from own data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
num: error.code,
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0400 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'AsyncCallback_0500') {
console.info('=======>UIExtAbility onSessionCreate want.action == AsyncCallback_0500======>');
this.context.startAbilityForResult({
action: 'AsyncCallback_0500',
bundleName: 'xxx.xxxxxxx.xxx',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}, (error, data) => {
console.info('=======>Callback_0500 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0500 first publish err:' + JSON.stringify(err));
});
});
}
if (want.action === 'Promise_0100') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0100======>');
this.context.startAbilityForResult({
action: 'Promise_0100',
bundleName: 'com.example.mainhap',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Promise_0100 data.resultCode ======>' + data.resultCode);
console.info('=======>Promise_0100 data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Promise_0100 publish err:' + JSON.stringify(err));
});
}).catch((error) => {
console.info('=======>Promise_0100 error.code ======>' + error.code);
});
}
if (want.action === 'Promise_0300') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0300======>');
this.context.startAbilityForResult({
action: 'Promise_0300',
bundleName: 'com.example.mainhap',
abilityName: 'OtherAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Promise_0300 first from own data.resultCode ======>' + data.resultCode);
console.info('=======>Promise_0300 first from own data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Promise_0300 first publish err:' + JSON.stringify(err));
});
}).catch((error) => {
console.info('=======>Promise_0300 first from own error.code ======>' + error.code);
});
}
if (want.action === 'Promise_0400') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0400======>');
this.context.startAbilityForResult({
action: 'Promise_0400',
bundleName: 'com.example.forresulttestsecond',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Promise_0400 first from own data.resultCode ======>' + data.resultCode);
console.info('=======>Promise_0400 first from own data.action ======>' + data.want.parameters.action);
let commonEventData = {
parameters: {
str: data.want.parameters.action,
result: data.resultCode
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>Promise_0400 first publish err:' + JSON.stringify(err));
});
}).catch((error) => {
console.info('=======>Promise_0400 first from own error.code ======>' + error.code);
});
}
if (want.action === 'Promise_0500') {
console.info('=======>UIExtAbility onSessionCreate want.action == Promise_0500======>');
this.context.startAbilityForResult({
action: 'Promise_0500',
bundleName: 'xxx.xxxxxxx.xxx',
abilityName: 'CalledAbility',
parameters: {
[wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true
}
}).then((data) => {
console.info('=======>Callback_0500 first from own data.resultCode ======>' + data.resultCode);
console.info('=======>Callback_0500 first from own data.action ======>' + data.want.parameters.action);
}).catch((error) => {
console.info('=======>Callback_0500 first from own error.code ======>' + error.code);
let commonEventData = {
parameters: {
num: error.code
}
};
commonEvent.publish('ACTS_CALL_EVENT', commonEventData, (err) => {
console.debug('====>AsyncCallback_0500 first publish err:' + JSON.stringify(err));
});
});
}
}
onSessionDestroy(session) {
console.log('onSessionDestroy');
}
onDestroy() {
console.info('=======>UIExtensionAbility onDestroy ======>');
}
onForeground() {
// Ability has brought to foreground
console.log('=====> UIExtAbility onForeground =====> ');
}
};
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
export default class CalledAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onCreate');
console.log('=====> first app CalledAbility =====>');
if (want.action === 'AsyncCallback_0100') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> AsyncCallback_0100 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
if (want.action === 'Promise_0100') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> Promise_0100 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
if (want.action === 'AsyncCallback_0200') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> AsyncCallback_0200 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
if (want.action === 'Promise_0200') {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> Promise_0200 CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/PageTwo', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'CalledAbility onBackground');
}
}
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
const TIMEOUT = 50;
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
globalThis.terminate = (str) => {
setTimeout(() => {
this.context.terminateSelf().then(() => {
console.info('====>terminateSelf' + JSON.stringify(str) + ' end');
}).catch((err) => {
console.info('====>terminateSelf ' + JSON.stringify(str) + ' err:' + JSON.stringify(err));
});
}, TIMEOUT);
};
if (want.action === 'AsyncCallback_0100') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0100':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0100',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
} else if (want.action === 'AsyncCallback_0300') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0300':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0300',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
} else if (want.action === 'AsyncCallback_0400') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0400':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0400',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
} else if (want.action === 'AsyncCallback_0500') {
console.info("====>EntryAbility want.action == 'AsyncCallback_0500':");
AppStorage.SetOrCreate('want', {
action: 'AsyncCallback_0500',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
}
if (want.action === 'Promise_0100') {
console.info("====>EntryAbility want.action == 'Promise_0100':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0100',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
} else if (want.action === 'Promise_0300') {
console.info("====>EntryAbility want.action == 'Promise_0300':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0300',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
} else if (want.action === 'Promise_0400') {
console.info("====>EntryAbility want.action == 'Promise_0400':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0400',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
} else if (want.action === 'Promise_0500') {
console.info("====>EntryAbility want.action == 'Promise_0500':");
AppStorage.SetOrCreate('want', {
action: 'Promise_0500',
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
});
}
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
globalThis.StartAbilityForResult = () => {
this.context.startAbilityForResult({
bundleName: 'com.example.mainhap',
abilityName: 'CalledAbility',
//moduleName: 'entry'
}, (error, data) => {
console.log('=======>startAbilityForResult error.code ======>' + error.code);
console.log('=======>startAbilityForResult data.resultCode ======>' + data.resultCode);
console.log('=======>startAbilityForResult data.action ======>' + data.want.parameters.action);
});
};
globalThis.startUIExtension = () => {
this.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility',
}, (err) => {
console.info('====>startAbility err:' + JSON.stringify(err));
});
};
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import type window from '@ohos.window';
const CUMULATIVE = 2;
export default class OtherAbility extends UIAbility {
circulate: number = 0;
onCreate(want, launchParam) {
console.log('=====> OtherAbility onCreate =====>');
}
onDestroy() {
console.log('=====> OtherAbility onDestroy =====>');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('=====> OtherAbility onWindowStageCreate =====>');
windowStage.loadContent('pages/IndexTwo', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('=====> OtherAbility onWindowStageDestroy =====>');
}
onForeground() {
console.log('=====> OtherAbility onForeground =====>');
this.circulate++;
console.log(`=====> OtherAbility circulate count: ${this.circulate}`);
if (this.circulate === CUMULATIVE) {
this.context.terminateSelfWithResult({
resultCode: 0,
want: {
parameters: {
action: 'ACTION'
}
}
}, (err) => {
console.log('=====> OtherAbility CalledAbilityCallBack terminateSelfWithResult =====>' + err.code);
});
}
}
onBackground() {
// Ability has back to background
console.log('=====> OtherAbility onBackground =====>');
}
}
/*
* Copyright (c) 2023 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 Want from '@ohos.app.ability.Want';
@Entry
@Component
struct Index {
@State message: string = 'First application'
@StorageLink('want') want: Want = {
action: "AsyncCallback_0100",
bundleName: 'com.example.mainhap',
abilityName: 'UIExtAbility'
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
UIExtensionComponent(this.want)
.size({width:'100%',height:'100'})
.backgroundColor(Color.Blue)
.border({width:5,color:Color.Red})
Button('StartAbilityForResult')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult()
})
.margin({
top: 5
})
Button('StartUI')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.startUIExtension()
})
.margin({
top: 5
})
Button('StartCalledAbilitybyUIExtension')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
console.info('=======>button======>');
globalThis.StartAbilityForResult_AsyncCallback_0100()
})
.margin({
top: 5
})
Button('terminal')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.terminal()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 IndexTwo {
@State message: string = 'Other Ability!'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button('TerminateCallback0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_CallBack()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 Want from '@ohos.app.ability.Want';
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
let storage = LocalStorage.GetShared()
@Entry(storage)
@Component
struct Page {
@State message: string = 'UIExtAbility'
private session: UIExtensionContentSession = storage.get<UIExtensionContentSession>('session');
build() {
Row() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 PageTwo {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button('TerminateCallback0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_CallBack()
})
.margin({
top: 5
})
Button('TerminatePromise0100')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(() => {
globalThis.StartAbilityForResult_Promise()
})
.margin({
top: 5
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
},
{
"name": "OtherAbility",
"srcEntry": "./ets/otherability/OtherAbility.ts",
"description": "$string:OtherAbility_desc",
"visible": true,
"icon": "$media:icon",
"label": "$string:OtherAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
},
{
"name": "CalledAbility",
"srcEntry": "./ets/calledability/CalledAbility.ts",
"description": "$string:CalledAbility_desc",
"visible": true,
"icon": "$media:icon",
"label": "$string:CalledAbility_label",
"launchType": "standard",
"exported": false,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
}
],
"extensionAbilities": [
{
"name": "UIExtAbility",
"icon": "$media:icon",
"description": "UIExtAbility",
"type": "ui",
"visible": true,
"srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts"
}
],
"requestPermissions": [
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "OtherAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "OtherAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"src": [
"pages/Index",
"pages/Page",
"pages/PageTwo"
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "OtherAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "OtherAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
},
{
"name": "CalledAbility_desc",
"value": "description"
},
{
"name": "CalledAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.mainhap",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive" : true,
"singleUser": true,
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
}
]
}
# Copyright (c) 2023 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("maintest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":maintest_js_assets",
":maintest_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "maintest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("maintest_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("maintest_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("maintest_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":maintest_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for aceceshi Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.example.mainhap",
"module-name": "entry_test",
"shell-timeout": "600000",
"testcase-timeout": 25000
},
"kits": [
{
"test-file-name": [
"forresulttest.hap",
"forresulttestnopermission.hap",
"main.hap",
"maintest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
"param set persist.sys.suspend_manager_enabled false",
"reboot",
"power-shell wakeup",
"uinput -T -d 300 600 -m 300 600 300 100 -u 300 100",
"power-shell setmode 602"
],
"teardown-command": [
"param set persist.sys.suspend_manager_enabled true",
"power-shell setmode 601",
"reboot"
]
}
]
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility';
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName;
let debug = abilityDelegatorArguments.parameters['-D'];
if (debug == 'true') {
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 hilog from '@ohos.hilog';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import commonEvent from '@ohos.commonEventManager'
import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { Driver } from '@ohos.UiTest';
let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator()
var ACTS_CallFunction = {
events: ['ACTS_CALL_EVENT', 'ACTS_CALL_EVENT_ANOTHER']
};
export default function abilityTest() {
describe('ActsAbilityTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(function () {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
// setTimeout(() => {
// console.info(`====>beforeEach setTimeout'`)
// }, 2000)
})
afterEach(function () {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(function () {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0100',0, async function (done) {
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>AsyncCallback_0100 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0100'
},(err) => {
console.info('====>startAbility err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>AsyncCallback_0100 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.str).assertEqual('ACTION');
expect(data.parameters.result).assertEqual(0);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>AsyncCallback_0100 unSubscribeCallback 'ACTS_CALL_EVENT'`)
globalThis.terminate('AsyncCallback_0100')
done()
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0200',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>AsyncCallback_0200 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestsecond',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0200'
},(err) => {
console.info('====>startAbility err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>AsyncCallback_0200 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.str).assertEqual('ACTION');
expect(data.parameters.result).assertEqual(0);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>AsyncCallback_0200 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{
console.info('====>AsyncCallback_0200 unSubscribeCallback pkill ok' + JSON.stringify(result));
done()
}).catch(err => {
console.info('====>AsyncCallback_0200 unSubscribeCallback pkill ng' + JSON.stringify(err));
done()
})
}, 2000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0300',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>AsyncCallback_0300 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0300'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
setTimeout(() => {
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestsecond',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0300'
},(err) => {
console.info('====>start Another Ability err:' + JSON.stringify(err));
})
}, 2500);
})
function subscribeCallBack(err, data) {
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>AsyncCallback_0300 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.result).assertEqual(-1);
}
if(data.event == 'ACTS_CALL_EVENT_ANOTHER') {
console.info(`====>AsyncCallback_0300 subscribeCallBack 'ACTS_CALL_EVENT_ANOTHER' ${data}`)
expect(data.parameters.str).assertEqual('ACTION');
expect(data.parameters.result).assertEqual(0);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>AsyncCallback_0300 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
globalThis.terminate('AsyncCallback_0300')
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then((result) =>{
console.info('====>AsyncCallback_0300 unSubscribeCallback pkill ok' + JSON.stringify(result));
done()
}).catch((err) => {
console.info('====>AsyncCallback_0300 unSubscribeCallback pkill ng' + JSON.stringify(err));
done()
})
}, 1000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0400',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>AsyncCallback_0400 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0400'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
setTimeout(() => {
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{
console.info('====>AsyncCallback_0400 pkill ok' + JSON.stringify(result));
}).catch(err => {
console.info('====>AsyncCallback_0400 pkill ng' + JSON.stringify(err));
})
}, 2000)
})
function subscribeCallBack(err, data) {
console.info(`====>AsyncCallback_0400 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>AsyncCallback_0400 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.result).assertEqual(-1);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>AsyncCallback_0400 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
globalThis.terminate('AsyncCallback_0400')
done()
}, 1000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0500',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>AsyncCallback_0500 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0500'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
console.info(`====>AsyncCallback_0500 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>AsyncCallback_0500 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.num).assertEqual(16000001);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>AsyncCallback_0500 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
globalThis.terminate('AsyncCallback_0500')
done()
}, 2000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0600',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>AsyncCallback_0600 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestthrid',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0600'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
console.info(`====>AsyncCallback_0600 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>AsyncCallback_0600 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
console.info(`====>AsyncCallback_0600 subscribeCallBack ${data.parameters.num}`)
expect(data.parameters.num).assertEqual(16000004);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>AsyncCallback_0600 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{
console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ok' + JSON.stringify(result));
done()
}).catch(err => {
console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ng' + JSON.stringify(err));
done()
})
}, 1000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_AsyncCallback_0700',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>AsyncCallback_0700 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestthrid',
abilityName: 'EntryAbility',
action: 'AsyncCallback_0700'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
console.info(`====>AsyncCallback_0700 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>AsyncCallback_0700 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.num).assertEqual(201);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>AsyncCallback_0700 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{
console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ok' + JSON.stringify(result));
done()
}).catch(err => {
console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ng' + JSON.stringify(err));
done()
})
}, 2000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0100',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>Promise_0100 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'Promise_0100'
},(err) => {
console.info('====>startAbility err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>Promise_0100 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.str).assertEqual('ACTION');
expect(data.parameters.result).assertEqual(0);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>Promise_0100 unSubscribeCallback 'ACTS_CALL_EVENT'`)
globalThis.terminate('Promise_0100')
done()
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0200',0, async function (done) {
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>Promise_0200 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestsecond',
abilityName: 'EntryAbility',
action: 'Promise_0200'
},(err) => {
console.info('====>startAbility err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>Promise_0200 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.str).assertEqual('ACTION');
expect(data.parameters.result).assertEqual(0);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>Promise_0200 unSubscribeCallback 'ACTS_CALL_EVENT'`)
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{
console.info('====>Promise_0200 unSubscribeCallback pkill ok' + JSON.stringify(result));
done()
})
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0300',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
await commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>Promise_0300 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'Promise_0300'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
setTimeout(() => {
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestsecond',
abilityName: 'EntryAbility',
action: 'Promise_0300'
},(err) => {
console.info('====>start Another Ability err:' + JSON.stringify(err));
})
}, 2000);
})
function subscribeCallBack(err, data) {
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>Promise_0300 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.result).assertEqual(-1);
}
if(data.event == 'ACTS_CALL_EVENT_ANOTHER') {
console.info(`====>Promise_0300 subscribeCallBack 'ACTS_CALL_EVENT_ANOTHER' ${data}`)
expect(data.parameters.str).assertEqual('ACTION');
expect(data.parameters.result).assertEqual(0);
}
globalThis.terminate('Promise_0300')
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{
console.info('====>Promise_0300 unSubscribeCallback pkill ok' + JSON.stringify(result));
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}).catch(err => {
console.info('====>Promise_0300 unSubscribeCallback pkill ng' + JSON.stringify(err));
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
})
}
function unSubscribeCallback() {
console.info(`====>Promise_0300 unSubscribeCallback 'ACTS_CALL_EVENT'`)
done()
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0400',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>Promise_0400 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'Promise_0400'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
setTimeout(() => {
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestsecond').then(result =>{
console.info('====>Promise_0400 pkill ok' + JSON.stringify(result));
}).catch(err => {
console.info('====>Promise_0400 pkill ng' + JSON.stringify(err));
})
}, 2000)
})
function subscribeCallBack(err, data) {
console.info(`====>Promise_0400 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>Promise_0400 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.result).assertEqual(-1);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>Promise_0400 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
globalThis.terminate('Promise_0400')
done()
}, 1000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0500',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>Promise_0500 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.mainhap',
abilityName: 'EntryAbility',
action: 'Promise_0500'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
console.info(`====>Promise_0500 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>Promise_0500 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.num).assertEqual(16000001);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>Promise_0500 unSubscribeCallback 'ACTS_CALL_EVENT'`)
globalThis.terminate('Promise_0500')
setTimeout(() => {
done()
}, 1000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0600',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>Promise_0600 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestthrid',
abilityName: 'EntryAbility',
action: 'Promise_0600'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
console.info(`====>Promise_0600 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>Promise_0600 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
console.info(`====>Promise_0600 subscribeCallBack ${data.parameters.num}`)
expect(data.parameters.num).assertEqual(16000004);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>Promise_0600 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{
console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ok' + JSON.stringify(result));
done()
}).catch(err => {
console.info('====>AsyncCallback_0600 unSubscribeCallback pkill ng' + JSON.stringify(err));
done()
})
}, 2000)
}
})
it('ACTS_UIExtensionAbility_StartAbilityForResult_Promise_0700',0, async function (done) {
await Driver.create().delayMs(2000)
var subscriber
commonEvent.createSubscriber(ACTS_CallFunction).then(async (data) => {
console.info(`====>Promise_0700 createSubscriber ${data}`)
subscriber = data
commonEvent.subscribe(data, subscribeCallBack)
globalThis.context.startAbility({
bundleName: 'com.example.forresulttestthrid',
abilityName: 'EntryAbility',
action: 'Promise_0700'
},(err) => {
console.info('====>start Own Ability err:' + JSON.stringify(err));
})
})
function subscribeCallBack(err, data) {
console.info(`====>Promise_0700 subscribeCallBack all ${data.event}`)
if(data.event == 'ACTS_CALL_EVENT') {
console.info(`====>Promise_0700 subscribeCallBack 'ACTS_CALL_EVENT' ${data}`)
expect(data.parameters.num).assertEqual(201);
commonEvent.unsubscribe(subscriber, unSubscribeCallback)
}
}
function unSubscribeCallback() {
console.info(`====>Promise_0700 unSubscribeCallback 'ACTS_CALL_EVENT'`)
setTimeout(() => {
abilityDelegator.executeShellCommand('aa force-stop com.example.forresulttestthrid').then(result =>{
console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ok' + JSON.stringify(result));
done()
}).catch(err => {
console.info('====>AsyncCallback_0700 unSubscribeCallback pkill ng' + JSON.stringify(err));
done()
})
}, 2000)
}
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2023 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
/*
* Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
globalThis.context = this.context
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('testability/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility 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
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/testability/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册