提交 b7ba703c 编写于 作者: J jsjzju

增加UIExtension相关xts

Signed-off-by: Njsjzju <jinsenjun@huawei.com>
Change-Id: I7a468ed3bd809b447d5ef99c5d7dafe707b85d57
上级 20f260d6
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2021-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
......@@ -40,6 +40,7 @@ group("ability_runtime") {
"actsstserviceabilityclientcase:ActsStServiceAbilityClientCaseTest",
"actssupportfunction:actssupportfunction",
"actssystemapitest:ActsSystemAPITest",
"actsuiextensiontest:actsuiextensiontest",
"actsusers:actsusers",
"amscontextualinforquery:amscontextualinforquery",
"amsdatauriutils:ActsAmsDataUriUtilsTest",
......
# 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("actsuiextensiontest") {
testonly = true
if (is_standard_system) {
deps = [
"uiextensionprovider:UIExtensionProvider",
"uiextensiontest:UIExtensionTest",
]
}
}
{
"app": {
"bundleName": "com.example.uiextensionprovider",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"minAPIVersion": 10,
"targetAPIVersion": 10
}
}
# 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("UIExtensionProvider") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":uiextensionprovider_js_assets",
":uiextensionprovider_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "UIExtensionProvider"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("uiextensionprovider_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("uiextensionprovider_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("uiextensionprovider_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":uiextensionprovider_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 hilog from '@ohos.hilog';
import AbilityStage from "@ohos.app.ability.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'AbilityStage onCreate');
}
}
\ 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 Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
}
onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
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.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'
import Logger from '../model/Logger'
const TAG: string = '[UIExtAbility]'
export default class UIExtAbility extends UIExtensionAbility {
onCreate() {
Logger.log(TAG, `UIExtAbility onCreate`)
}
onForeground() {
Logger.log(TAG, `UIExtAbility onForeground`)
}
onBackground() {
Logger.log(TAG, `UIExtAbility onBackground`)
}
onDestroy() {
Logger.log(TAG, `UIExtAbility onDestroy`)
}
onSessionCreate(want, session) {
Logger.log(TAG, `UIExtAbility onSessionCreate, want: ${JSON.stringify(want)}`)
let storage: LocalStorage = new LocalStorage({
'session': session
});
session.loadContent('pages/index', storage);
}
onSessionDestroy(session) {
Logger.log(TAG, `UIExtAbility onSessionDestroy`)
}
};
/*
* 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.
*/
const TAG: string = '=== Stage AMS ==='
export default class Logger {
public static log(tag, ...args: any[]) {
console.log(`${TAG}.${tag}: ${args.join('')}`)
}
public static info(tag, ...args: any[]) {
console.info(`${TAG}.${tag}: ${args.join('')}`)
}
public static debug(tag, ...args: any[]) {
console.debug(`${TAG}.${tag}: ${args.join('')}`)
}
public static warn(tag, ...args: any[]) {
console.warn(`${TAG}.${tag}: ${args.join('')}`)
}
public static error(tag, ...args: any[]) {
console.error(`${TAG}.${tag}: ${args.join('')}`)
}
}
\ 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'
import commonEventManager from '@ohos.commonEventManager'
import Logger from '../model/Logger'
const TAG: string = '[UIExtAbility]'
const sleepTimeOne = 1000;
let storage = LocalStorage.GetShared()
@Entry(storage)
@Component
struct Index {
@State message: string = 'UIExtension'
private session: UIExtensionContentSession = storage.get<UIExtensionContentSession>('session');
aboutToAppear() {
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult';
let sendDataEvent = 'ACTS_UIExtension_SendData';
var subscriber;
var subscribeInfo = {
events: [terminateSelfWithResultEvent, sendDataEvent]
}
commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == terminateSelfWithResultEvent) {
this.session.terminateSelfWithResult({
"resultCode": 0,
"want": {
"bundleName": "test"
}
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
} else if (data.event == sendDataEvent) {
this.session.sendData({
name: {
last: 'King'
}
});
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
});
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber error : " + JSON.stringify(error));
})
setTimeout(async () => {
commonEventManager.publish(appearEvent, (err) => {
if (err) {
Logger.log(TAG + `publish ACTS_UIExtension_AboutToAppear failed, code is ${err.code}, message is ${err.message}`);
} else {
Logger.log(TAG + 'publish ACTS_UIExtension_AboutToAppear success');
}
});
}, sleepTimeOne);
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"srcEntrance": "./ets/Application/MyAbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"extensionAbilities": [
{
"name": "UIExtAbility",
"icon": "$media:icon",
"description": "UIExtAbility",
"type": "ui",
"visible": true,
"srcEntrance": "./ets/UIExtensionAbility/UIExtAbility.ts",
"metadata": [
{
"name": "ohos.extension.servicetype",
"value": "share"
}
]
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.uiextensiontest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"minAPIVersion": 10,
"targetAPIVersion": 10
}
}
# 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("UIExtensionTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":uiextensiontest_js_assets",
":uiextensiontest_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "UIExtensionTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("uiextensiontest_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("uiextensiontest_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("uiextensiontest_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":uiextensiontest_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for aceceshi Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.example.uiextensiontest",
"module-name": "entry",
"shell-timeout": "600000",
"testcase-timeout":"30000"
},
"kits": [
{
"test-file-name": [
"UIExtensionTest.hap",
"UIextensionProvider.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
/*
* 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 AbilityStage from "@ohos.app.ability.UIAbility"
export default class TestAbilityStage extends AbilityStage {
onCreate() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbilityStage onCreate');
}
}
\ 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 Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
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) ?? '');
}
onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: Window.WindowStage) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/index', (err, data) => {
if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
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';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../test/List.test'
@Entry
@Component
struct Index {
@State message: string = 'Index'
aboutToAppear() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.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.
*/
import hilog from '@ohos.hilog';
import commonEventManager from '@ohos.commonEventManager'
const TAG: string = '[P1]'
@Entry
@Component
struct P1 {
aboutToAppear() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
build() {
Row() {
Column() {
UIExtensionComponent({
bundleName: 'com.example.uiextensionprovider',
abilityName: 'UIExtAbility'
}).width('100%').height('35%')
.onResult((data)=>{
let onResultEvent = 'ACTS_UIExtension_OnResult';
let options = {
parameters: {
'result': data
}
}
commonEventManager.publish(onResultEvent, options, (err) => {
console.log(TAG + 'ACTS_UIExtension_OnResult');
});
})
.onReceive((data)=>{
let onReceiveEvent = 'ACTS_UIExtension_OnReceive';
let options = {
parameters: {
'result': data
}
}
commonEventManager.publish(onReceiveEvent, options, (err) => {
console.log(TAG + 'ACTS_UIExtension_OnReceive');
});
})
}
.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 hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import commonEventManager from '@ohos.commonEventManager'
import router from '@ohos.router'
import Utils from './Utils'
export default function abilityTest() {
describe('ACTS_UIExtension', function () {
let TAG = "";
let sleepTimeOne = 1000;
// 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(async function (done) {
console.info("ACTS_UIExtension beforeEach start");
let options = {
url: 'TestAbility/pages/p1',
}
let result;
try {
result = await router.pushUrl(options);
await Utils.sleep(500);
console.info("ACTS_UIExtension push page result: " + JSON.stringify(result));
} catch (err) {
console.error("ACTS_UIExtension push page error: " + err);
}
done()
});
afterEach(async function (done) {
router.back()
await Utils.sleep(500);
done()
})
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_UIExtension_TerminateSelfWithResult_001',0, async function (done) {
TAG = 'ACTS_UIExtension_TerminateSelfWithResult_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onResultEvent = 'ACTS_UIExtension_OnResult';
let terminateSelfWithResultEvent = 'ACTS_UIExtension_TerminateSelfWithResult';
var subscriber;
var subscribeInfo = {
events: [appearEvent, onResultEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(terminateSelfWithResultEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_TerminateSelfWithResult failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_TerminateSelfWithResult success');
}
});
} else if (data.event == onResultEvent) {
let result = data.parameters.result;
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
expect(result.want.bundleName).assertEqual('test');
done();
});
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
})
it('ACTS_UIExtension_UIExtensionSendData_001',0, async function (done) {
TAG = 'ACTS_UIExtension_UIExtensionSendData_001 == ';
console.log(TAG + "begin");
let appearEvent = 'ACTS_UIExtension_AboutToAppear';
let onReceiveEvent = 'ACTS_UIExtension_OnReceive';
let sendDataEvent = 'ACTS_UIExtension_SendData';
var subscriber;
var subscribeInfo = {
events: [appearEvent, onReceiveEvent]
}
await commonEventManager.createSubscriber(subscribeInfo).then(async (data) => {
console.log(TAG + "createSubscriber data : " + JSON.stringify(data));
subscriber = data;
commonEventManager.subscribe(subscriber, async (err, data) => {
console.log(TAG + "SubscribeInfoCallback : " + JSON.stringify(data));
if (data.event == appearEvent) {
commonEventManager.publish(sendDataEvent, (err) => {
if (err) {
console.log(TAG + `publish ACTS_UIExtension_SendData failed, code is ${err.code}, message is ${err.message}`);
} else {
console.log(TAG + 'publish ACTS_UIExtension_SendData success');
}
});
} else if (data.event == onReceiveEvent) {
let result = data.parameters.result;
let resultCheck = {
name: {
last: 'King'
}
};
setTimeout(async () => {
commonEventManager.unsubscribe(subscriber, async (err, data) => {
console.log(TAG + "UnSubscribeInfoCallback : " + JSON.stringify(data));
expect(JSON.stringify(result)).assertEqual(JSON.stringify(resultCheck));
done();
});
}, sleepTimeOne);
}
});
}).catch((error) => {
console.log(TAG + "createSubscriber err : " + JSON.stringify(error));
expect().assertFail();
done();
})
})
})
}
\ 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.
*/
export default class Utils {
static sleep(time) {
return new Promise<void>((resolve, reject) => {
setTimeout(() => {
resolve()
}, time)
}).then(() => {
console.info(`sleep ${time} over...`)
})
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"srcEntrance": "./ets/Application/TestAbilityStage.ts",
"description": "$string:entry_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntrance": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"visible": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "entry_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.
先完成此消息的编辑!
想要评论请 注册