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

!9350 完成元能力的delegator的跨平台测试套

Merge pull request !9350 from huyanqiang/aihua
{
"app": {
"bundleName": "com.example.delegatortest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"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_js_hap_suite("ActsCrossplatformAbilityTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformAbilityTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"shell-timeout": "60000",
"bundle-name": "com.example.delegatortest",
"module-name": "entry",
"testcase-timeout": 15000
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformAbilityTest.hap",
"ActsCrossplatformFeatureATest.hap",
"ActsCrossplatformFeatureBTest.hap",
"ActsCrossplatformFeatureCTest.hap",
"ActsCrossplatformFeatureDTest.hap",
"ActsCrossplatformAbilityTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class Main2Ability extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
globalThis.want = want;
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('testability/pages/Main2', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('testTag', '%{public}s', 'Ability onBackground');
}
}
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class Main3Ability extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
globalThis.want = want;
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('testability/pages/Main3', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('testTag', '%{public}s', 'Ability onBackground');
}
}
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class Main4Ability extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
globalThis.want = want;
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('testability/pages/Main4', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('testTag', '%{public}s', 'Ability onBackground');
}
}
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()
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
var 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
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
globalThis.want = want;
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('testability/pages/Index', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('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 {
describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it,
expect,
} from "@ohos/hypium";
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.
});
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("assertContain", 0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
console.log("testTag", "%{public}s", "it begin");
let a = "abc";
let b = "b";
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}
/*
* 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 AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
import { describe, expect, it } from "@ohos/hypium";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
export default function AbilityMonitorTest() {
const factoryWant = (
bundleName: string,
abilityName: string,
moduleName: string
) => {
return {
bundleName: bundleName,
abilityName: abilityName,
moduleName: moduleName,
};
};
describe("AbilityMonitorTest", function () {
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100
* @tc.name actsAddAbilityMonitorCallback0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100", 0, async function (done) {
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = null;
try {
abilityDelegator.addAbilityMonitor(monitor, (err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100" + err.code
);
expect().assertFail();
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100 message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100 pass"
);
done();
}
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0200
* @tc.name actsAddAbilityMonitorCallback0200
* @tc.desc Pass in a monitor
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
console.log("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0200 ");
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_CALLBACK_0200 pass"
);
data.context.terminateSelf();
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(monitor, (err: any) => {
console.log("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0200");
});
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0300
* @tc.name actsAddAbilityMonitorCallback0300
* @tc.desc Pass in a monitor that has already been added.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_CALLBACK_0300 pass "
);
data.context.terminateSelf();
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.addAbilityMonitor(monitor, (err: any) => {
console.log("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0300");
});
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0100
* @tc.name actsAddAbilityMonitorPromise0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0100", 0, async function (done) {
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = null;
try {
let result = await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_PROMISE_0100 error"
);
expect().assertFail();
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_PROMISE_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_PROMISE_0100 message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_PROMISE_0100 pass"
);
done();
}
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0200
* @tc.name actsAddAbilityMonitorPromise0200
* @tc.desc Pass in a monitor
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync('ACTS_ADD_ABILITY_MONITOR_PROMISE_0200 pass');
data.context.terminateSelf();
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
await abilityDelegator.addAbilityMonitor(monitor);
setTimeout(() => {
abilityDelegator.startAbility(want);
}, 2000);
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0300
* @tc.name actsAddAbilityMonitorPromise0300
* @tc.desc Pass in a monitor that has already been added.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
data.context.terminateSelf();
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_MONITOR_PROMISE_0300 pass"
);
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
await abilityDelegator.addAbilityMonitor(monitor);
await abilityDelegator.addAbilityMonitor(monitor);
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100
* @tc.name actsRemoveAbilityMonitorCallback0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100", 0, async function (done) {
let monitor = null;
try {
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => {
expect().assertFail();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100 error"
);
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100 error code:" + e.code
);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100 message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100 pass"
);
done();
}
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0200
* @tc.name actsRemoveAbilityMonitorCallback0200
* @tc.desc Pass in an Add monitor that has already been added.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let result = 0;
function onAbilityCreateCallback() {
result = 1;
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => { });
setTimeout(() => {
abilityDelegator.startAbility(want);
}, 2000);
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0200 pass"
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300
* @tc.name actsRemoveAbilityMonitorCallback0300
* @tc.desc Pass in an unadded monitor to monitor
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300", 0, async function (done) {
let result = 0;
function onAbilityCreateCallback() {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300 onAbilityCreateCallback"
);
result = 1;
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300 removeAbilityMonitor"
);
});
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0400
* @tc.name actsRemoveAbilityMonitorCallback0400
* @tc.desc remove a monitor that has already been wait.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0400", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let result = 0;
function onAbilityCreateCallback() {
result = 1;
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => { });
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0400 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0500
* @tc.name actsRemoveAbilityMonitorCallback0500
* @tc.desc Pass in an Add monitor that has already been added.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0500", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let result = 0;
function onAbilityCreateCallback() {
result = 1;
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => { });
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0500 pass"
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100
* @tc.name actsRemoveAbilityMonitorPromise0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100", 0, async function (done) {
let monitor = null;
try {
let result = await abilityDelegator.removeAbilityMonitor(monitor);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100 pass+result:" + result
);
expect().assertFail();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100 error"
);
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100 message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100 pass"
);
done();
}
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200
* @tc.name actsRemoveAbilityMonitorPromise0200
* @tc.desc Pass in an Add monitor that has already been added.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let result = 0;
function onAbilityCreateCallback(err) {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200 onAbilityCreateCallback "
);
result = 1;
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200 callback"
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200 error:" + error
);
});
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300
* @tc.name actsRemoveAbilityMonitorPromise0300
* @tc.desc Pass in an unadded monitor to monitor
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let result = 0;
function onAbilityCreateCallback() {
result = 1;
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300 onAbilityCreateCallback"
);
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300"
);
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300"
);
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300 error:" + error
);
expect().assertFail();
done();
});
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0400
* @tc.name actsRemoveAbilityMonitorPromise0400
* @tc.desc remove a monitor that has already been wait.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0400", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let result = 0;
function onAbilityCreateCallback() {
result = 1;
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0400"
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0400 error:" + error
);
expect().assertFail();
done();
});
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0400 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500
* @tc.name actsRemoveAbilityMonitorPromise0500
* @tc.desc Pass in an unadded monitor to monitor whether the monitor container size increases.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let result = 1;
function onAbilityCreateCallback() {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500 onAbilityCreateCallback"
);
result = 0;
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
await abilityDelegator.addAbilityMonitor(monitor);
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500 callback"
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500 error:" + error
);
expect().assertFail();
done();
});
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(1);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500 pass"
);
done();
}, 3000);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0100
* @tc.name actsWaitAbilityMonitorCallback0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0100", 0, async function (done) {
let monitor = null;
try {
abilityDelegator.waitAbilityMonitor(monitor, (err: any) => {
expect().assertFail();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0100 callback "
);
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0100 message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0100 monitor pass"
);
done();
}
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0300
* @tc.name actsWaitAbilityMonitorCallback0300
* @tc.desc Pass in an added monitor and start the monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0300", 0, async function (done) {
function onAbilityCreateCallback(data) {
expect(data.context.abilityInfo.name).assertEqual("Main2Ability");
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0300 pass"
);
data.context.terminateSelf();
done();
}
let want = {
bundleName: "com.example.delegatortest",
abilityName: "Main2Ability",
moduleName: "entry",
};
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(monitor, (err: any, data: any) => { });
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0400
* @tc.name actsWaitAbilityMonitorCallback0400
* @tc.desc Pass in an empty monitor, timeout=6000.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0400", 0, async function (done) {
let monitor = null;
try {
abilityDelegator.waitAbilityMonitor(monitor, 6000, (err: any) => {
expect().assertFail();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0400 error"
);
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0400 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0400 message:" + e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0400 pass "
);
done();
}
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0500
* @tc.name actsWaitAbilityMonitorCallback0500
* @tc.desc Pass in a monitor that has been added, timeout=10000.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0500", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0500 error"
);
expect(true).assertTrue();
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(
monitor,
6000,
(err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0500 : " + err.code
);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0500 : " + err.message
);
expect(err.code).assertEqual(16000100);
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0500 pass"
);
done();
}
);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0600
* @tc.name actsWaitAbilityMonitorCallback0600
* @tc.desc Pass in an already added monitor and start this monitor, timeout<5.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0600", 0, async function (done) {
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0600 pass"
);
data.context.terminateSelf();
done();
}
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(
monitor,
6000,
(err: any, data: any) => { }
);
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0700
* @tc.name actsWaitAbilityMonitorCallback0700
* @tc.desc Pass in an already added monitor and start this monitor, timeout=0.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0700", 0, async function (done) {
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0700 pass"
);
data.context.terminateSelf();
done();
}
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(
monitor,
0,
(err: any, data: any) => { }
);
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0800
* @tc.name actsWaitAbilityMonitorCallback0800
* @tc.desc Pass in an already added monitor and start this monitor, timeout<5.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0800", 0, async function (done) {
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0800 pass"
);
data.context.terminateSelf();
done();
}
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(
monitor,
4000,
(err: any, data: any) => { }
);
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0900
* @tc.name actsWaitAbilityMonitorCallback0900
* @tc.desc Pass in an already added monitor and start this monitor, timeout<0.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0900", 0, async function (done) {
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_0900 pass"
);
data.context.terminateSelf();
done();
}
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(
monitor,
-1,
(err: any, data: any) => { }
);
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_CALLBACK_1000
* @tc.name actsWaitAbilityMonitorCallback1000
* @tc.desc Pass in an added monitor and start this monitor to get the current bundleName.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_CALLBACK_1000", 0, async function (done) {
function onAbilityCreateCallback(data) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_1000 onAbilityCreateCallback"
);
}
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.waitAbilityMonitor(monitor);
abilityDelegator.startAbility(want);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, data: any) => {
try {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_1000 getCurrentTopAbility ability: " +
data.context.abilityInfo.name
);
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_1000 pass"
);
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_CALLBACK_1000 error"
);
expect(true).assertTrue();
done();
}
});
}, 2000);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_PROMISE_0100
* @tc.name actsWaitAbilityMonitorPromise0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_WAIT_ABILITY_MONITOR_PROMISE_0100", 0, async function (done) {
let monitor = null;
try {
let result = await abilityDelegator.waitAbilityMonitor(monitor);
expect(result).assertEqual(undefined);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0100 error"
);
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0100 message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0100 pass"
);
done();
}
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_PROMISE_0200
* @tc.name actsWaitAbilityMonitorPromise0200
* @tc.desc Pass in a Monitor that has already been added.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_PROMISE_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0200 onAbilityCreateCallback"
);
data.context.terminateSelf();
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator
.waitAbilityMonitor(monitor)
.then(() => {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0200 pass"
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0200 error:" + error
);
expect.assertFail();
done();
});
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_PROMISE_0300
* @tc.name actsWaitAbilityMonitorPromise0300
* @tc.desc Pass in an already added Monitor and start the Monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_PROMISE_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
data.context.terminateSelf();
abilityDelegator.printSync("ACTS_WAITABILITYMONTOR_PROMISE_0300 pass");
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.waitAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"actsWaitAbilityMonitorPromise0300 waitAbilityMonitor"
);
})
.catch((error) => {
abilityDelegator.printSync(
"actsWaitAbilityMonitorPromise0300 error:" + error
);
expect.assertFail();
done();
});
await abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_WAIT_ABILITY_MONITOR_PROMISE_0400
* @tc.name actsWaitAbilityMonitorPromise0400
* @tc.desc Pass in an already added StageMonitor and start this Monitor, passing in a timeout=0.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_WAIT_ABILITY_MONITOR_PROMISE_0400", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onAbilityCreateCallback(data) {
expect(true).assertTrue();
abilityDelegator.printSync("ACTS_WAITABILITYMONTOR_PROMISE_0400 pass");
data.context.terminateSelf();
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityCreate: onAbilityCreateCallback,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.waitAbilityMonitor(monitor, 0)
.then(() => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0400 waitAbilityMonitor"
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_MONITOR_PROMISE_0400 error:" + error
);
expect.assertFail();
done();
});
await abilityDelegator.startAbility(want);
});
});
}
/*
* 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.
*/
// @ts-nocheck
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
export default function AbilityMonitor2Test() {
const factoryWant = (
bundleName: string,
abilityName: string,
moduleName: string
) => {
return {
bundleName: bundleName,
abilityName: abilityName,
moduleName: moduleName,
};
};
describe("AbilityMonitor2Test", function () {
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100
* @tc.name ACTS_AddAbilityMonitor_Callback_0100
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the callback function (onAbilityForeground) CallBack when the ability status becomes foreground
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0100", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityForegroundCallback(data) {
expect(data!=null).assertTrue();
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Callback_0100 pass");
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0100 getCurrentTopAbility err:" +
ability1.context.abilityInfo.name
);
abilityDelegator.removeAbilityMonitor(monitor);
ability1.context.terminateSelf();
});
done();
}
let monitor = {
abilityName: "Main2Ability",
onAbilityForeground: onAbilityForegroundCallback,
};
abilityDelegator.addAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0100 addAbilityMonitor:" +
JSON.stringify(err)
);
});
abilityDelegator.startAbility(want, (err: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0100 startAbility:" +
JSON.stringify(err)
);
});
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0200
* @tc.name ACTS_AddAbilityMonitor_Callback_0200
* @tc.desc Verify that addAbilityMonitor enters the normal value of the monitor parameter and executes the callback function (onWindowStageCreate) CallBack when the window stage is created
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main3Ability",
"entry"
);
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onWindowStageCreateCallBack(data) {
expect(data!=null).assertTrue();
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Callback_0200 pass");
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0200 getCurrentTopAbility :" +
ability1.context.abilityInfo.name
);
abilityDelegator.removeAbilityMonitor(monitor);
ability1.context.terminateSelf();
});
done();
}
let monitor = {
abilityName: "Main3Ability",
onWindowStageCreate: onWindowStageCreateCallBack,
};
abilityDelegator.addAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0200 addAbilityMonitor:" +
JSON.stringify(err)
);
});
abilityDelegator.startAbility(want, (err) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0200 startAbility:" +
JSON.stringify(err)
);
});
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0300
* @tc.name ACTS_AddAbilityMonitor_Callback_0300
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the callback function (onWindowStageCreate) Promise when the window stage is created
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityBackgroundCallback(data) {
expect(data!=null).assertTrue();
console.info("ACTS_AddAbilityMonitor_Callback_0300 pass");
abilityDelegator.removeAbilityMonitor(monitor);
done();
}
let monitor = {
abilityName: "Main4Ability",
onAbilityBackground: onAbilityBackgroundCallback,
};
abilityDelegator.addAbilityMonitor(monitor, (err: any) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0300 err:" + JSON.stringify(err)
);
});
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0300 err:" + JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0300 getCurrentTopAbility err:" +
JSON.stringify(err)
);
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0300 getCurrentTopAbility err:" +
ability1.context.abilityInfo.name
);
abilityDelegator.doAbilityBackground(ability1, (err: any) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0300 doAbilityBackground err:" +
JSON.stringify(err)
);
});
});
}, 2000);
});
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0400
* @tc.name ACTS_AddAbilityMonitor_Callback_0400
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the onAbilityBackground Promise when the ability status becomes background
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0400", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"entry"
);
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onWindowStageDestroyCallBack(data) {
expect(data!=null).assertTrue();
console.info("ACTS_AddAbilityMonitor_Callback_0400 pass");
abilityDelegator.removeAbilityMonitor(monitor);
done();
}
let monitor = {
abilityName: "MainAbility",
onWindowStageDestroy: onWindowStageDestroyCallBack,
};
abilityDelegator.addAbilityMonitor(monitor, (err: any) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0400 err:" + JSON.stringify(err)
);
});
setTimeout(() => {
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0400 err:" + JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0400 getCurrentTopAbility err:" +
JSON.stringify(err)
);
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0400 getCurrentTopAbility err:" +
ability1.context.abilityInfo.name
);
ability1.context.terminateSelf();
});
}, 2000);
});
}, 2000);
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_CALLBACK_0500
* @tc.name ACTS_AddAbilityMonitor_Callback_0500
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the onAbilityDestroy callBack function before the ability is destroyed
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_CALLBACK_0500", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main3Ability",
"entry"
);
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityDestroyCallback(data) {
console.log(
"ACTS_AddAbilityMonitor_Callback_0500 data1: " +
JSON.stringify(data.context.abilityInfo)
);
expect(data!=null).assertTrue();
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Callback_0500 pass");
abilityDelegator.removeAbilityMonitor(monitor);
done();
}
let monitor = {
abilityName: "Main3Ability",
onAbilityDestroy: onAbilityDestroyCallback,
};
abilityDelegator.addAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0500 addAbilityMonitor:" +
JSON.stringify(err)
);
});
setTimeout(() => {
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0500 startAbility:" +
JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0500 getCurrentTopAbility:" +
JSON.stringify(err)
);
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Callback_0500 getCurrentTopAbility:" +
ability1.context.abilityInfo.name
);
ability1.context.terminateSelf();
});
}, 2000);
});
}, 2000);
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0100
* @tc.name ACTS_AddAbilityMonitor_Promise_0100
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the onAbilityForeground Promise when the ability status becomes foreground
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0100", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
function onAbilityForegroundPromise(data) {
expect(data!=null).assertTrue();
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Promise_0100 pass");
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0100 getCurrentTopAbility :" +
ability1.context.abilityInfo.name
);
abilityDelegator.removeAbilityMonitor(monitor);
ability1.context.terminateSelf();
});
done();
}
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = {
abilityName: "Main4Ability",
onAbilityForeground: onAbilityForegroundPromise,
};
abilityDelegator
.addAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Promise_0100 add");
abilityDelegator.startAbility(want);
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0100 error"
);
done();
});
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0200
* @tc.name ACTS_AddAbilityMonitor_Promise_0200
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the callback function (onWindowStageCreate) Promise when the window stage is created
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main2Ability",
"entry"
);
function onWindowStageCreatePromise(data) {
expect(data!=null).assertTrue();
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Promise_0200 pass");
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0200 getCurrentTopAbility :" +
ability1.context.abilityInfo.name
);
abilityDelegator.removeAbilityMonitor(monitor);
ability1.context.terminateSelf();
});
done();
}
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = {
abilityName: "Main2Ability",
onWindowStageCreate: onWindowStageCreatePromise,
};
abilityDelegator
.addAbilityMonitor(monitor)
.then(async () => {
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Promise_0200 add");
setTimeout(() => {
abilityDelegator.startAbility(want).then(async () => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0200 start"
);
});
}, 2000);
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0200 error"
);
done();
});
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0300
* @tc.name ACTS_AddAbilityMonitor_Promise_0300
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the onAbilityBackground Promise when the ability status becomes background * @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main3Ability",
"entry"
);
function onAbilityBackgroundPromise(data) {
expect(data!=null).assertTrue();
console.log("ACTS_AddAbilityMonitor_Promise_0300 pass");
abilityDelegator.removeAbilityMonitor(monitor);
data.context.terminateSelf();
done();
}
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = {
abilityName: "Main3Ability",
onAbilityBackground: onAbilityBackgroundPromise,
};
abilityDelegator
.addAbilityMonitor(monitor)
.then(async () => {
console.info("ACTS_AddAbilityMonitor_Promise_0300 add");
})
.catch((err) => {
console.info("ACTS_AddAbilityMonitor_Promise_0300 error");
done();
});
setTimeout(() => {
abilityDelegator
.startAbility(want)
.then(async () => {
console.info("ACTS_AddAbilityMonitor_Promise_0300 start");
setTimeout(() => {
abilityDelegator.getCurrentTopAbility().then((ability) => {
console.info(
"ACTS_AddAbilityMonitor_Promise_0300 ability" +
JSON.stringify(ability)
);
abilityDelegator.doAbilityBackground(ability).then(async () => {
console.info(
"ACTS_AddAbilityMonitor_Promise_0300 doAbilityBackground."
);
});
});
}, 2000);
})
.catch((err) => {
console.info(
"ACTS_AddAbilityMonitor_Promise_0300 startability error"
);
done();
});
}, 2000);
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0400
* @tc.name ACTS_AddAbilityMonitor_Promise_0400
* @tc.desc Verify that addAbilityMonitor enters the parameter monitor to pass in the normal value, and executes the callback function (onWindowStageDestroy) Promise before the window stage is destroyed
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0400", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
function onWindowStageDestroyPromise(data) {
expect(data!=null).assertTrue();
console.log("ACTS_AddAbilityMonitor_Promise_0400 pass");
abilityDelegator.removeAbilityMonitor(monitor);
done();
}
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = {
abilityName: "Main4Ability",
onWindowStageDestroy: onWindowStageDestroyPromise,
};
abilityDelegator
.addAbilityMonitor(monitor)
.then(async () => {
console.info("ACTS_AddAbilityMonitor_Promise_0400 add");
})
.catch((err) => {
console.info("ACTS_AddAbilityMonitor_Promise_0400 error");
expect().assertFail();
done();
});
setTimeout(() => {
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_AddAbilityMonitor_Promise_0400 err:" + JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0400 top err:" +
JSON.stringify(err)
);
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0400 getCurrentTopAbility :" +
ability1.context.abilityInfo.name
);
ability1.context.terminateSelf();
});
}, 2000);
});
}, 2000);
});
/**
* @tc.number ACTS_ADD_ABILITY_MONITOR_PROMISE_0500
* @tc.name ACTS_AddAbilityMonitor_Promise_0500
* @tc.desc Verify that the addAbilityMonitor parameter monitor passes in the normal value, and execute the onAbilityDestroy Promise before the ability is destroyed
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_ADD_ABILITY_MONITOR_PROMISE_0500", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main3Ability",
"entry"
);
function onAbilityDestroyPromise(data) {
expect(data!=null).assertTrue();
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Promise_0500 pass");
abilityDelegator.removeAbilityMonitor(monitor);
done();
}
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = {
abilityName: "Main3Ability",
onAbilityDestroy: onAbilityDestroyPromise,
};
abilityDelegator
.addAbilityMonitor(monitor)
.then(async () => {
abilityDelegator.printSync("ACTS_AddAbilityMonitor_Promise_0500 add");
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0500 error"
);
done();
});
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_AddAbilityMonitor_Promise_0500 err:" + JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0500 top err:" +
JSON.stringify(err)
);
abilityDelegator.printSync(
"ACTS_AddAbilityMonitor_Promise_0500 top ability:" +
ability1.context.abilityInfo.name
);
ability1.context.terminateSelf();
});
}, 2000);
});
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100
* @tc.name ACTS_RemoveABILITY_MONITOR_CALLBACK_0100
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to the onAbilityForeground callback CallBack
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0100", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 0;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityForegroundCallback() {
result = 1;
abilityDelegator.printSync(
"ACTS_RemoveABILITY_MONITOR_CALLBACK_0100 error"
);
done();
}
let monitor = {
abilityName: "Main4Ability",
onAbilityForeground: onAbilityForegroundCallback,
};
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync("ACTS_RemoveABILITY_MONITOR_CALLBACK_0100.");
});
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_RemoveABILITY_MONITOR_CALLBACK_0100 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0200
* @tc.name ACTS_RemoveABILITY_MONITOR_CALLBACK_0200
* @tc.desc After validating removeAbilityMonitor, you cannot listen to the onWindowStageCreate callback CallBack
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 0;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onWindowStageCreateCallBack() {
result = 1;
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0200 error"
);
done();
}
let monitor = {
abilityName: "Main4Ability",
onWindowStageCreate: onWindowStageCreateCallBack,
};
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0200 ."
);
});
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0200 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300
* @tc.name ACTS_RemoveABILITY_MONITOR_CALLBACK_0300
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to the onAbilityBackground callback callback
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 0;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityBackgroundCallBack() {
result = 1;
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0300 error"
);
done();
}
let monitor = {
abilityName: "Main4Ability",
onAbilityBackground: onAbilityBackgroundCallBack,
};
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0300 ."
);
});
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0300 err:" + JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0300 getCurrentTopAbility err:" +
JSON.stringify(err)
);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0300 top ability:" +
ability1.context.abilityInfo.name
);
abilityDelegator.doAbilityBackground(ability1, (err: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0300 doAbilityBackground err:" +
JSON.stringify(err)
);
});
});
}, 2000);
});
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0300 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0400
* @tc.name ACTS_RemoveABILITY_MONITOR_CALLBACK_0400
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to the onAbilityDestroy callback CallBack
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0400", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 0;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityDestroyCallBack() {
result = 1;
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0400 error"
);
done();
}
let monitor = {
abilityName: "Main4Ability",
onAbilityDestroy: onAbilityDestroyCallBack,
};
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0400. "
);
});
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_AddAbilityMonitor_Callback_0600 err:" + JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0400 getCurrentTopAbility err:" +
JSON.stringify(err)
);
ability1.context.terminateSelf();
});
}, 2000);
});
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0400 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0500
* @tc.name ACTS_RemoveABILITY_MONITOR_CALLBACK_0500
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to the onWindowStageDestroy callback CallBack
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_CALLBACK_0500", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 0;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onWindowStageDestroyCallBack() {
result = 1;
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0500 error"
);
done();
}
let monitor = {
abilityName: "Main4Ability",
onWindowStageDestroy: onWindowStageDestroyCallBack,
};
abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator.removeAbilityMonitor(monitor, (err: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0500 ."
);
});
abilityDelegator.startAbility(want, (err) => {
console.log(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0500 err:" + JSON.stringify(err)
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0500 getCurrentTopAbility err:" +
JSON.stringify(err)
);
ability1.context.terminateSelf();
});
}, 2000);
});
setTimeout(() => {
expect(result).assertEqual(0);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_CALLBACK_0500 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100
* @tc.name Acts_RemoveAbility_Monitor_Promise_0100
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to onAbilityForeground callback promises
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0100", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 1;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityForegroundPromise() {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0100 error "
);
result = 0;
}
let monitor = {
abilityName: "Main4Ability",
onAbilityForeground: onAbilityForegroundPromise,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0100 callback"
);
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0100 error"
);
expect().assertFail();
done();
});
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(1);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0100 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200
* @tc.name Acts_RemoveAbility_Monitor_Promise_0200
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to the onWindowStageCreate callback Promise
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 1;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onWindowStageCreatePromise() {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0200 error "
);
result = 0;
}
let monitor = {
abilityName: "Main4Ability",
onWindowStageCreate: onWindowStageCreatePromise,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0200 promise"
);
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0200 error"
);
expect().assertFail();
done();
});
await abilityDelegator.startAbility(want);
setTimeout(() => {
expect(result).assertEqual(1);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0200 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300
* @tc.name Acts_RemoveAbility_Monitor_Promise_0300
* @tc.desc After validating removeAbilityMonitor, you cannot listen to the onAbilityBackground callback Promise
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0300", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 1;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityBackgroundPromise() {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 error "
);
result = 0;
}
let monitor = {
abilityName: "Main4Ability",
onAbilityBackground: onAbilityBackgroundPromise,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 promise"
);
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 error"
);
expect().assertFail();
done();
});
abilityDelegator
.startAbility(want)
.then(async () => {
console.info("ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 start");
abilityDelegator.getCurrentTopAbility().then((ability) => {
console.info(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 ability" +
JSON.stringify(ability)
);
abilityDelegator.doAbilityBackground(ability).then(async () => {
console.info(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 doAbilityBackground succeed."
);
});
});
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 start error"
);
expect().assertFail();
done();
});
setTimeout(() => {
expect(result).assertEqual(1);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0300 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0400
* @tc.name Acts_RemoveAbility_Monitor_Promise_0400
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to onAbilityDestroy callback promises
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0400", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 1;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onAbilityDestroyPromise() {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0400 error "
);
result = 0;
}
let monitor = {
abilityName: "Main4Ability",
onAbilityDestroy: onAbilityDestroyPromise,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0400 promise"
);
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0400 error"
);
expect().assertFail();
done();
});
abilityDelegator
.startAbility(want)
.then(async () => {
console.info("ACTS_REMOVEABILITY_MONITOR_PROMISE_0400 start");
abilityDelegator.getCurrentTopAbility().then((ability) => {
console.info(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0400 ability" +
JSON.stringify(ability)
);
ability1.context.terminateSelf();
});
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0400 start error"
);
expect().assertFail();
done();
});
setTimeout(() => {
expect(result).assertEqual(1);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0400 pass "
);
done();
}, 3000);
});
/**
* @tc.number ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500
* @tc.name Acts_RemoveAbility_Monitor_Promise_0500
* @tc.desc After verifying removeAbilityMonitor, you cannot listen to the onWindowStageDestroy callback Promise
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_REMOVE_ABILITY_MONITOR_PROMISE_0500", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"Main4Ability",
"entry"
);
let result = 1;
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
function onWindowStageDestroyPromise() {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0500 error "
);
result = 0;
}
let monitor = {
abilityName: "Main4Ability",
onWindowStageDestroy: onWindowStageDestroyPromise,
};
await abilityDelegator.addAbilityMonitor(monitor);
abilityDelegator
.removeAbilityMonitor(monitor)
.then(() => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0500 promise"
);
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0500 error"
);
expect().assertFail();
done();
});
abilityDelegator
.startAbility(want)
.then(async () => {
console.info("ACTS_REMOVEABILITY_MONITOR_PROMISE_0500 start");
abilityDelegator.getCurrentTopAbility().then((ability) => {
console.info(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0500 ability" +
JSON.stringify(ability)
);
ability1.context.terminateSelf();
});
})
.catch((err) => {
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0500 start error"
);
expect().assertFail();
done();
});
setTimeout(() => {
expect(result).assertEqual(1);
abilityDelegator.printSync(
"ACTS_REMOVEABILITY_MONITOR_PROMISE_0500 pass "
);
done();
}, 3000);
});
});
}
/*
* 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 {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
export default function AbilityStageMonitorTest() {
const factoryWant = (
bundleName: string,
abilityName: string,
moduleName: string
) => {
return {
bundleName: bundleName,
abilityName: abilityName,
moduleName: moduleName,
};
};
describe("AbilityStageMonitorTest", function () {
/**
* @tc.number ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0100
* @tc.name actsAddAbilityStageMonitorCallback0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0100",
0,
async function (done) {
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = null;
try {
abilityDelegator.addAbilityStageMonitor(
monitor,
(err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0100" + err.code
);
expect().assertFail();
done();
}
);
} catch (e) {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0100 message:" + e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0100 pass"
);
done();
}
}
);
/**
* @tc.number ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0200
* @tc.name actsAddAbilityStageMonitorCallback0200
* @tc.desc Pass in a stagemonitor and perform add, wait, and remove operations respectively.(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0200",
0,
async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator.addAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0200 waitAbilityStageMonitor data: " +
data
);
});
abilityDelegator.waitAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0200 waitAbilityStageMonitor data: " +
data
);
});
abilityDelegator.removeAbilityStageMonitor(monitor, (err, data) => {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_CALLBACK_0200 removeAbilityStageMonitor pass"
);
done();
});
}
);
/**
* @tc.number ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0100
* @tc.name actsAddAbilityStageMonitorPromise0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it("ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0100", 0, async function (done) {
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let monitor = null;
try {
await abilityDelegator.addAbilityStageMonitor(monitor);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0100 error"
);
expect().assertFail();
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0100 message:" + e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0100 pass"
);
done();
}
});
/**
* @tc.number ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200
* @tc.name actsAddAbilityStageMonitorPromise0200
* @tc.desc Pass in a stagemonitor and perform add, wait, and remove operations respectively.(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200", 0, async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator
.addAbilityStageMonitor(monitor)
.then((data) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200 waitAbilityStageMonitor data: " +
data
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200 wait catch error" +
error
);
});
abilityDelegator
.waitAbilityStageMonitor(monitor)
.then((data) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200 waitAbilityStageMonitor data: " +
data
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200 wait catch error" +
error
);
});
abilityDelegator
.removeAbilityStageMonitor(monitor)
.then((data) => {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200 removeAbilityStageMonitor pass"
);
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_ADD_ABILITY_STAGE_MONITOR_PROMISE_0200 remove catch error" +
error
);
});
});
/**
* @tc.number ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0100
* @tc.name actsRemoveAbilityStageMonitorCallback0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0100",
0,
async function (done) {
let monitor = null;
try {
abilityDelegator.removeAbilityStageMonitor(monitor, (err: any) => {
expect().assertFail();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0100 error"
);
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0100 message:" +
e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0100 pass"
);
done();
}
setTimeout(() => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0100 timeout"
);
done();
}, 3000);
}
);
/**
* @tc.number ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0200
* @tc.name actsRemoveAbilityStageMonitorCallback0200
* @tc.desc Pass in a stagemonitor and perform wait and remove operations, respectively.(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0200",
0,
async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator.waitAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0200 waitAbilityStageMonitor data: " +
data
);
});
abilityDelegator.removeAbilityStageMonitor(monitor, (err, data) => {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0200 removeAbilityStageMonitor pass"
);
done();
});
}
);
/**
* @tc.number ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0300
* @tc.name actsRemoveAbilityStageMonitorCallback0300
* @tc.desc Pass in a stagemonitor and perform wait (6 seconds) and remove operations, respectively.(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0300",
0,
async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator.waitAbilityStageMonitor(monitor, 6000, (err, data) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0300 waitAbilityStageMonitor data: " +
data
);
});
abilityDelegator.removeAbilityStageMonitor(monitor, (err, data) => {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_CALLBACK_0300 removeAbilityStageMonitor pass"
);
done();
});
}
);
/**
* @tc.number ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0100
* @tc.name actsRemoveAbilityStageMonitorPromise0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0100",
0,
async function (done) {
let monitor = null;
try {
await abilityDelegator.removeAbilityStageMonitor(monitor);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0100"
);
expect().assertFail();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0100 error"
);
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0100 message:" +
e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0100 pass"
);
done();
}
}
);
/**
* @tc.number ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0200
* @tc.name actsRemoveAbilityStageMonitorPromise0200
* @tc.desc Pass in a stagemonitor and perform wait and remove operations, respectively.(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0200",
0,
async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator
.waitAbilityStageMonitor(monitor)
.then((data) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0200 waitAbilityStageMonitor data: " +
data
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0200 wait catch error" +
error
);
});
abilityDelegator
.removeAbilityStageMonitor(monitor)
.then((data) => {
expect(true).assertTrue();
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0200 removeAbilityStageMonitor pass"
);
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_REMOVE_ABILITY_STAGE_MONITOR_PROMISE_0200 remove catch error" +
error
);
});
}
);
/**
* @tc.number ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0100
* @tc.name actsWaitAbilityStageMonitorCallback0100
* @tc.desc Pass in a null stagemonitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0100",
0,
async function (done) {
let monitor = null;
try {
abilityDelegator.waitAbilityStageMonitor(monitor, (err: any) => {
expect().assertFail();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0100 callback "
);
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0100 message:" + e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0100 monitor pass"
);
done();
}
}
);
/**
* @tc.number ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0200
* @tc.name actsWaitAbilityStageMonitorCallback0200
* @tc.desc Pass in null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0200",
0,
async function (done) {
let monitor = null;
try {
abilityDelegator.waitAbilityStageMonitor(
monitor,
6000,
(err: any) => {
expect().assertFail();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0200 error"
);
done();
}
);
} catch (e) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0200 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0200 message:" + e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0200 pass "
);
done();
}
setTimeout(() => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0200 timeout"
);
done();
}, 3000);
}
);
/**
* @tc.number ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0300
* @tc.name actsWaitAbilityStageMonitorCallback0300
* @tc.desc Pass in a stage monitor and perform the wait operation.(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0300",
0,
async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator.waitAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0300 err code: " +
err.code
);
expect(err.code).assertEqual(16000100);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0300 pass"
);
done();
});
}
);
/**
* @tc.number ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0400
* @tc.name actsWaitAbilityStageMonitorCallback0400
* @tc.desc Pass in a stage monitor and perform the wait operation(6 seconds).(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0400",
0,
async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator.waitAbilityStageMonitor(monitor, 6000, (err, data) => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0400 err code: " +
err.code
);
expect(err.code).assertEqual(16000100);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_CALLBACK_0400 pass"
);
done();
});
}
);
/**
* @tc.number ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0100
* @tc.name actsWaitAbilityStageMonitorPromise0100
* @tc.desc pass in a null monitor.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 3
*/
it(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0100",
0,
async function (done) {
let monitor = null;
try {
await abilityDelegator.waitAbilityStageMonitor(monitor);
expect().assertFail();
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0100 error"
);
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0100 code:" + e.code
);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0100 message:" + e.message
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0100 pass"
);
done();
}
}
);
/**
* @tc.number ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0200
* @tc.name actsWaitAbilityStageMonitorPromise0200
* @tc.desc Pass in a stage monitor and perform the wait operation.(incomplete)
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0200",
0,
async function (done) {
const want = factoryWant(
"com.example.delegatortest",
"MainAbility",
"featureassist"
);
let monitor = {
moduleName: "featureassist",
srcEntrance: "./ets/Application/AbilityStage.ts",
};
abilityDelegator
.waitAbilityStageMonitor(monitor)
.then((data) => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0200 pass data: " + data
);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0200 error: " + error
);
expect(error.code).assertEqual(16000100);
abilityDelegator.printSync(
"ACTS_WAIT_ABILITY_STAGE_MONITOR_PROMISE_0200 pass"
);
done();
});
}
);
});
}
/*
* 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 { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
export default function AbilityStageMonitor2Test() {
const factoryWant = (bundleName: string, abilityName: string, moduleName: string) => {
return {
bundleName: bundleName,
abilityName: abilityName,
moduleName: moduleName
}
}
describe('AbilityStageMonitor2Test', function () {
beforeAll(function () {
let want = {
abilityName: 'Main4Ability',
bundleName: 'com.example.delegatortest',
moduleName: 'entry'
};
abilityDelegator.startAbility(want);
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0100
* @tc.name Phase2_AbilityStageMonitor_0100
* @tc.desc Verify that StageMonitor listens to the abilitystage CallBack after the abilitystage starts
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0100', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassista');
let monitor = {
moduleName: 'featureassista',
srcEntrance: './ets/Application/AbilityStage.ts'
};
abilityDelegator.waitAbilityStageMonitor(monitor, (err, data) => {
try {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0100 err code: ' + err.code);
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0100 data code: ' + JSON.stringify(data.context.currentHapModuleInfo.name));
let moduleName = data.context.currentHapModuleInfo.name;
expect(moduleName).assertEqual(monitor.moduleName)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0100 pass');
} catch (error) {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0100 catch error:' + error);
}
done();
});
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0100 startAbility ');
setTimeout(() => {
abilityDelegator.startAbility(want, (err: any) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0100 err: ' + err);
});
}, 3000);
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0200
* @tc.name Phase2_AbilityStageMonitor_0200
* @tc.desc Verify that StageMonitor listens to the abilitystage (wait plus timeout) CallBack after the abilitystage starts
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0200', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassistb');
let monitor = {
moduleName: 'featureassistb',
srcEntrance: './ets/Application/AbilityStage.ts'
};
abilityDelegator.waitAbilityStageMonitor(monitor, 6000, (err, data) => {
try {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0200 err code: ' + err.code);
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0200 data code: ' + JSON.stringify(data.context.currentHapModuleInfo.name));
let moduleName = data.context.currentHapModuleInfo.name;
expect(moduleName).assertEqual(monitor.moduleName)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0200 pass');
} catch (error) {
abilityDelegator.printSync('PHASE2_ABILITY_STAGE_MONITOR_0200 catch error:' + error);
}
done();
});
abilityDelegator.startAbility(want, (err: any) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0200 err: ' + err);
});
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0300
* @tc.name Phase2_AbilityStageMonitor_0300
* @tc.desc Verify that StageMonitor listens for the abilitystage Promise after the abilitystage starts
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0300', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassistc');
let monitor = {
moduleName: 'featureassistc',
srcEntrance: './ets/Application/AbilityStage.ts'
};
abilityDelegator.waitAbilityStageMonitor(monitor).then((data) => {
try {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0300 pass data: ' + JSON.stringify(data.context.currentHapModuleInfo.name));
let moduleName = data.context.currentHapModuleInfo.name;
expect(moduleName).assertEqual(monitor.moduleName)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0300 pass');
done();
} catch (error) {
abilityDelegator.printSync('PHASE2_ABILITY_STAGE_MONITOR_0200 catch error:' + error);
expect().assertFail();
done();
}
}).catch((err) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0300 catch err' + err);
expect(err != null).assertTrue();
done();
})
abilityDelegator.startAbility(want, (err: any) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0300 err: ' + err);
});
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0400
* @tc.name Phase2_AbilityStageMonitor_0400
* @tc.desc Verify that StageMonitor listens for the abilitystage(wait plus timeout) Promise after the abilitystage starts
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0400', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassistd');
let monitor = {
moduleName: 'featureassistd',
srcEntrance: './ets/Application/AbilityStage.ts'
};
abilityDelegator.waitAbilityStageMonitor(monitor, 6000).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0400 pass data: ' + JSON.stringify(data.context.currentHapModuleInfo.name));
let moduleName = data.context.currentHapModuleInfo.name;
expect(moduleName).assertEqual(monitor.moduleName)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0400 pass');
done();
}).catch((err) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0400 error');
expect(err != null).assertTrue();
done();
});
abilityDelegator.startAbility(want)
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0500
* @tc.name Phase2_AbilityStageMonitor_0500
* @tc.desc After verifying that the StageMonitor add is removed again, starting the abilitystage cannot listen to the abilitystage CallBack
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0500', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassista');
let monitor = {
moduleName: 'featureassista',
srcEntrance: './ets/Application/AbilityStage.ts'
};
abilityDelegator.addAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 addAbilityStageMonitor err: ' + JSON.stringify(err));
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 addAbilityStageMonitor data: ' + JSON.stringify(data));
})
abilityDelegator.waitAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 err code: ' + err.code);
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 waitAbilityStageMonitor data: ' + JSON.stringify(data));
expect(err.code).assertEqual(16000100)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 pass')
done();
});
abilityDelegator.removeAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 removeAbilityStageMonitor err: ' + JSON.stringify(err))
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 removeAbilityStageMonitor data: ' + JSON.stringify(data))
})
setTimeout(() => {
try {
abilityDelegator.startAbility(want);
} catch (error) {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 catch error: ' + error)
}
}, 3000);
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0600
* @tc.name Phase2_AbilityStageMonitor_0600
* @tc.desc After verifying that the StageMonitor add is removed again, starting the abilitystage cannot listen to the abilitystage promise
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0600', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassistb');
let monitor = {
moduleName: 'featureassistb',
srcEntrance: './ets/Application/AbilityStage.ts'
};
abilityDelegator.addAbilityStageMonitor(monitor).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0600 addAbilityStageMonitor data: ' + JSON.stringify(data))
})
await abilityDelegator.waitAbilityStageMonitor(monitor).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0600 waitAbilityStageMonitor data: ' + JSON.stringify(data))
}).catch((err) => {
abilityDelegator.printSync("Phase2_AbilityStageMonitor_0600 waitAbilityStageMonitor err: " + JSON.stringify(err));
expect(err.code).assertEqual(16000100)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0600 pass')
done();
}).catch((err) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0600 error')
expect().assertFail();
done();
})
abilityDelegator.removeAbilityStageMonitor(monitor).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0600 removeAbilityStageMonitor data: ' + JSON.stringify(data))
})
await abilityDelegator.startAbility(want);
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0700
* @tc.name Phase2_AbilityStageMonitor_0700
* @tc.desc After verifying that the StageMonitor wait is removed again, go to start the abilitystage and cannot listen to the abilitystage CallBack
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0700', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassistc');
let monitor = {
moduleName: 'featureassistc',
srcEntrance: './ets/Application/AbilityStage.ts'
};
abilityDelegator.waitAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0700 err code: ' + err.code);
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0700 waitAbilityStageMonitor data: ' + JSON.stringify(data));
expect(err.code).assertEqual(16000100)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0700 pass')
done();
});
abilityDelegator.removeAbilityStageMonitor(monitor, (err, data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0700 removeAbilityStageMonitor err: ' + JSON.stringify(err))
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0700 removeAbilityStageMonitor data: ' + JSON.stringify(data))
})
setTimeout(() => {
try {
abilityDelegator.startAbility(want);
} catch (error) {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0500 catch error: ' + error)
}
}, 3000);
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0800
* @tc.name Phase2_AbilityStageMonitor_0800
* @tc.desc After verifying that the StageMonitor wait is removed again, starting the abilitystage cannot listen to the abilitystage promise
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0800', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassistd');
let monitor = {
moduleName: 'featureassistd',
srcEntrance: './ets/Application/AbilityStage.ts'
};
await abilityDelegator.waitAbilityStageMonitor(monitor).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0800 waitAbilityStageMonitor data: ' + JSON.stringify(data))
}).catch((err) => {
abilityDelegator.printSync("Phase2_AbilityStageMonitor_0800 waitAbilityStageMonitor err: " + JSON.stringify(err));
expect(err.code).assertEqual(16000100)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0800 pass')
done();
}).catch((err) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0800 error')
expect().assertFail();
done();
})
abilityDelegator.removeAbilityStageMonitor(monitor).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0800 removeAbilityStageMonitor data: ' + JSON.stringify(data))
})
await abilityDelegator.startAbility(want);
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_0900
* @tc.name Phase2_AbilityStageMonitor_0900
* @tc.desc Verify that the moduleName of the StageMonitor wait incoming error cannot listen to the abilitystage promise
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it('PHASE2_ABILITY_STAGE_MONITOR_0900', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'feature_error');
let monitor = {
moduleName: 'feature_error',
srcEntrance: './ets/Application/AbilityStage.ts'
};
await abilityDelegator.waitAbilityStageMonitor(monitor).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0900 waitAbilityStageMonitor data: ' + JSON.stringify(data))
}).catch((err) => {
abilityDelegator.printSync("Phase2_AbilityStageMonitor_0900 waitAbilityStageMonitor err: " + JSON.stringify(err));
expect(err.code).assertEqual(16000100)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_0900 pass')
done();
})
await abilityDelegator.startAbility(want);
})
/**
* @tc.number PHASE2_ABILITY_STAGE_MONITOR_1000
* @tc.name Phase2_AbilityStageMonitor_1000
* @tc.desc srcEntrance that verifies that StageMonitor wait incoming errors cannot listen to abilitystage promises
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it('PHASE2_ABILITY_STAGE_MONITOR_1000', 0, async function (done) {
const want = factoryWant('com.example.delegatortest', 'MainAbility', 'featureassista');
let monitor = {
moduleName: 'featureassista',
srcEntrance: './ets/Application/AbilityStageerror.ts'
};
await abilityDelegator.waitAbilityStageMonitor(monitor).then((data) => {
abilityDelegator.printSync('Phase2_AbilityStageMonitor_1000 waitAbilityStageMonitor data: ' + JSON.stringify(data))
}).catch((err) => {
abilityDelegator.printSync("Phase2_AbilityStageMonitor_1000 waitAbilityStageMonitor err: " + JSON.stringify(err));
expect(err.code).assertEqual(16000100)
abilityDelegator.printSync('Phase2_AbilityStageMonitor_1000 pass')
done();
})
await abilityDelegator.startAbility(want);
})
})
}
/*
* 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 {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
export default function AbilityDelegatorTest() {
describe("AbilityDelegatorTest", function () {
/**
* @tc.number GET_ABILITY_DELEGATOR_0001
* @tc.name getAbilityDelegator0001
* @tc.desc test getAbilityDelegator
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("GET_ABILITY_DELEGATOR_0001", 0, async function (done) {
const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
expect(abilityDelegator != null).assertTrue();
abilityDelegator.printSync("GET_ABILITY_DELEGATOR_0001 pass");
done();
});
/**
* @tc.number GET_ARGUMENTS_0001
* @tc.name getArguments0001
* @tc.desc test getArguments
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("GET_ARGUMENTS_0001", 0, async function (done) {
const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
const abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
var bundleName = abilityDelegatorArguments.bundleName;
var testRunnerClassName = abilityDelegatorArguments.testRunnerClassName;
var parameters = abilityDelegatorArguments.parameters;
let moduleName = parameters["moduleName"];
let timeout = parameters["timeout"];
abilityDelegator.printSync(
"GET_ARGUMENTS_0001 bundleName: " + bundleName
);
abilityDelegator.printSync(
"GET_ARGUMENTS_0001 testRunnerClassName: " + testRunnerClassName
);
abilityDelegator.printSync(
"GET_ARGUMENTS_0001 moduleName: " + moduleName
);
abilityDelegator.printSync("GET_ARGUMENTS_0001 timeout: " + timeout);
expect(bundleName).assertEqual("com.example.delegatortest");
expect(testRunnerClassName).assertEqual("OpenHarmonyTestRunner");
expect(moduleName==null).assertFalse();
expect(timeout).assertEqual(undefined);
abilityDelegator.printSync("GET_ARGUMENTS_0001 pass");
done();
});
});
}
/*
* 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.
*/
//@ts-nocheck
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
const START_ABILITY_TIMEOUT_TWO_THOUSAND = 2000;
export default function BackgroundCallback() {
describe("BackgroundCallback", function () {
beforeEach(function () {
let want = {
abilityName: "MainAbility",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001
* @tc.name actsDoAbilityBackgroundCallback0001
* @tc.desc Test the api: doAbilityBackground, swith the ability to background.原有Second,再启动Main,使Main退到后台
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001", 0, async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001 start"
);
setTimeout(() => {
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator.doAbilityBackground(
ability2,
(err: any) => {
setTimeout(() => {
try {
var stateNum =
abilityDelegator.getAbilityState(ability2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001 getAbilityState stateNum :" +
stateNum
);
expect(stateNum).assertEqual(3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001 pass"
);
} catch (error) {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0001 error:" +
error
);
}
done();
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
}
);
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002
* @tc.name actsDoAbilityBackgroundCallbackError0002
* @tc.desc Test the api: doAbilityBackground, swith the wrong ability to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 start"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 startAbility"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
try {
abilityDelegator.doAbilityBackground(
ability2 + "error",
(err: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 fail"
);
expect().assertFail();
done();
}
);
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 doAbilityForeground meet an error: ability is wrong"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 Main3Ability : " +
ability2.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main3Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 pass."
);
done();
}
);
}
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
}
);
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003
* @tc.name actsDoAbilityBackgroundCallbackError0003
* @tc.desc Test the api: doAbilityBackground, swith the empty ability to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("actsDoAbilityBackgroundCallbackError0003", 0, async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 Main3Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain2, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 startAbility"
);
setTimeout(() => {
try {
abilityDelegator.doAbilityBackground("", (err: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 fail"
);
expect().assertFail();
done();
});
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 doAbilityForeground meet an error: ability is null"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 Main4Ability : " +
ability2.context.abilityInfo.name
);
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main4Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0003 pass."
);
done();
}
);
}
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
});
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004
* @tc.name actsDoAbilityBackgroundCallback0004
* @tc.desc Test the api: doAbilityBackground, swith the ability which is background to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004", 0, async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004 start"
);
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator.doAbilityBackground(
ability1,
(err: any) => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability3: any) => {
try {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004 Main3Ability: " +
ability3.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004 getAbilityState stateNum :" +
stateNum
);
expect(
ability3.context.abilityInfo.name
).assertEqual("Main3Ability");
expect(stateNum).assertEqual(2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004 pass"
);
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_0004 fail"
);
}
done();
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
}
);
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0005
* @tc.name actsDoAbilityBackgroundCallbackError0005
* @tc.desc Test the api: doAbilityBackground, swith the wrong ability to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0005",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_CALLBACK_ERROR_0002 startAbility"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
ability2.context.terminateSelf(() => {
setTimeout(() => {
try {
abilityDelegator.doAbilityBackground(
ability2,
(err: any) => {}
);
} catch (error) {
expect(error.message).assertEqual(
"Incorrect parameters."
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0005 doAbilityForeground meet an error: " +
error
);
}
done();
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
});
}
/*
* 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.
*/
//@ts-nocheck
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
const START_ABILITY_TIMEOUT_TWO_THOUSAND = 2000;
export default function BackgroundPromise() {
describe("BackgroundPromise", function () {
beforeEach(function () {
let want = {
abilityName: "MainAbility",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001
* @tc.name actsDoAbilityBackgroundPromise0001
* @tc.desc Test the api: doAbilityBackground, swith the ability to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001", 0, async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001 start"
);
setTimeout(() => {
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator
.doAbilityBackground(ability2)
.then(() => {
setTimeout(() => {
try {
var stateNum =
abilityDelegator.getAbilityState(ability2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001 getAbilityState stateNum :" +
stateNum
);
expect(stateNum).assertEqual(3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001 pass"
);
} catch (error) {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001 catch error:" +
error
);
}
done();
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0001 error error:" +
error
);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002
* @tc.name actsDoAbilityBackgroundPromise0002
* @tc.desc Test the api: doAbilityBackground, swith the wrong ability to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 start"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 startAbility"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
try {
abilityDelegator
.doAbilityBackground(ability2 + "error")
.then(() => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 fail"
);
expect().assertFail();
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 catch error:" +
error
);
});
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 doAbilityForeground meet an error: ability is wrong"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 Main3Ability : " +
ability2.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main3Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0002 pass."
);
done();
}
);
}
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
}
);
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003
* @tc.name actsDoAbilityBackgroundPromise0003
* @tc.desc Test the api: doAbilityBackground, swith the empty ability to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003",
0,
async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 Main3Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain2, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 startAbility"
);
setTimeout(() => {
try {
abilityDelegator
.doAbilityBackground("")
.then(() => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 fail"
);
expect().assertFail();
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 catch error:" +
error
);
});
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 doAbilityForeground meet an error: ability is null"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 Main4Ability : " +
ability2.context.abilityInfo.name
);
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main4Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0003 pass."
);
done();
}
);
}
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004
* @tc.name actsDoAbilityBackgroundPromise0004
* @tc.desc Test the api: doAbilityBackground, swith the ability which is background to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004", 0, async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 start"
);
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator
.doAbilityBackground(ability1)
.then(() => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability3: any) => {
try {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 Main3Ability: " +
ability3.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 getAbilityState stateNum :" +
stateNum
);
expect(
ability3.context.abilityInfo.name
).assertEqual("Main3Ability");
expect(stateNum).assertEqual(2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 pass"
);
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 fail"
);
}
done();
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_0004 catch error:" +
error
);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
/**
* @tc.number ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0005
* @tc.name actsDoAbilityBackgroundPromise0005
* @tc.desc Test the api: doAbilityBackground, swith the wrong ability to background.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0005",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0005 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0005 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0005 startAbility"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
ability2.context.terminateSelf(() => {
setTimeout(() => {
try {
abilityDelegator
.doAbilityBackground(ability2)
.then(() => {});
} catch (error) {
expect(error.message).assertEqual(
"Incorrect parameters."
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_BACKGROUND_PROMISE_ERROR_0005 doAbilityBackground meet an error: " +
error
);
}
done();
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
});
}
/*
* 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.
*/
//@ts-nocheck
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
const START_ABILITY_TIMEOUT_TWO_THOUSAND = 2000;
export default function ForegroundCallback() {
describe("ForegroundCallback", function () {
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001
* @tc.name actsDoAbilityForegroundCallback0001
* @tc.desc Test the api: doAbilityForeground, swith the ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001", 0, async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001 start"
);
setTimeout(() => {
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator.doAbilityForeground(
ability1,
(err: any) => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability3: any) => {
try {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001 Main4Ability: " +
ability3.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001 getAbilityState stateNum :" +
stateNum
);
expect(stateNum).assertEqual(2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001 pass"
);
} catch (error) {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0001 error:" +
error
);
}
done();
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
}
);
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002
* @tc.name actsDoAbilityForegroundCallbackError0002
* @tc.desc Test the api: doAbilityForeground, swith the wrong ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 startAbility"
);
setTimeout(() => {
try {
abilityDelegator.doAbilityForeground(
ability1 + "error",
(err: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 fail"
);
expect().assertFail();
done();
}
);
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 doAbilityForeground meet an error: ability is wrong"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 Main3Ability : " +
ability2.context.abilityInfo.name
);
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main3Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0002 pass."
);
done();
}
);
}
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003
* @tc.name actsDoAbilityForegroundCallbackError0003
* @tc.desc Test the api: doAbilityForeground, swith the empty ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003",
0,
async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 Main3Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain2, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 startAbility"
);
setTimeout(() => {
try {
abilityDelegator.doAbilityForeground("", (err: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 fail"
);
expect().assertFail();
done();
});
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 doAbilityForeground meet an error: ability is null"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 Main4Ability : " +
ability2.context.abilityInfo.name
);
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main4Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0003 pass."
);
done();
}
);
}
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004
* @tc.name actsDoAbilityForegroundCallback0004
* @tc.desc Test the api: doAbilityForeground, swith the ability which is foregrond to foreground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004", 0, async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004 start"
);
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator.doAbilityForeground(
ability2,
(err: any) => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability3: any) => {
try {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004 Main3Ability: " +
ability3.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004 getAbilityState stateNum :" +
stateNum
);
expect(
ability3.context.abilityInfo.name
).assertEqual("Main3Ability");
expect(stateNum).assertEqual(2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004 pass"
);
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_0004 fail"
);
}
done();
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
}
);
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0005
* @tc.name actsDoAbilityForegroundCallbackError0005
* @tc.desc Test the api: doAbilityForeground, swith the wrong ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0005",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0005 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0005 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0005 startAbility"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
ability2.context.terminateSelf(() => {
setTimeout(() => {
try {
abilityDelegator.doAbilityForeground(
ability2,
(err: any) => {}
);
} catch (error) {
expect(error.message).assertEqual(
"Incorrect parameters."
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_CALLBACK_ERROR_0005 doAbilityForeground meet an error: " +
error
);
}
done();
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
});
}
/*
* 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.
*/
//@ts-nocheck
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
const START_ABILITY_TIMEOUT_TWO_THOUSAND = 2000;
const START_ABILITY_TIMEOUT_THOUSAND = 1000;
export default function ForegroundPromise() {
describe("ForegroundPromise", function () {
beforeAll(function () {
let want = {
abilityName: "MainAbility",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want);
});
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001
* @tc.name actsDoAbilityForegroundPromise0001
* @tc.desc Test the api: doAbilityForeground, swith the ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001", 0, async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
setTimeout(() => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 start"
);
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator
.doAbilityForeground(ability1)
.then(() => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability3: any) => {
try {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 Main4Ability: " +
ability3.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 getAbilityState stateNum :" +
stateNum
);
expect(stateNum).assertEqual(2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 pass"
);
} catch (error) {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 error:" +
error
);
}
done();
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0001 catch error: " +
error
);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002
* @tc.name actsDoAbilityForegroundPromiseError0002
* @tc.desc Test the api: doAbilityForeground, swith the ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 startAbility"
);
setTimeout(() => {
try {
abilityDelegator
.doAbilityForeground(ability1 + "error")
.then(() => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 fail"
);
expect().assertFail();
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 catch error: " +
error
);
});
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 doAbilityForeground meet an error: ability is wrong"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 Main3Ability : " +
ability2.context.abilityInfo.name
);
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main3Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0002 pass."
);
done();
}
);
}
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003
* @tc.name actsDoAbilityForegroundPromiseError0003
* @tc.desc Test the api: doAbilityForeground, swith the ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003",
0,
async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 Main3Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain2, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 startAbility"
);
setTimeout(() => {
try {
abilityDelegator
.doAbilityForeground("")
.then(() => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 fail"
);
expect().assertFail();
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 catch error: " +
error
);
});
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 doAbilityForeground meet an error: ability is null"
);
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 Main4Ability : " +
ability2.context.abilityInfo.name
);
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 getAbilityState: " +
stateNum
);
expect(stateNum).assertEqual(3);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main4Ability"
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 pass."
);
done();
}
);
}
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004
* @tc.name actsDoAbilityForegroundPromise004
* @tc.desc Test the api: doAbilityForeground, swith the ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004", 0, async function (done) {
let wantMain2 = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004 start"
);
abilityDelegator.startAbility(wantMain2, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004 Main3Ability: " +
ability2.context.abilityInfo.name
);
abilityDelegator
.doAbilityForeground(ability2)
.then(() => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability3: any) => {
try {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004 Main3Ability: " +
ability3.context.abilityInfo.name
);
var stateNum =
abilityDelegator.getAbilityState(ability3);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004 getAbilityState stateNum :" +
stateNum
);
expect(
ability3.context.abilityInfo.name
).assertEqual("Main3Ability");
expect(stateNum).assertEqual(2);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004 pass"
);
} catch {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_0004 fail"
);
}
done();
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0003 catch error: " +
error
);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
/**
* @tc.number ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0005
* @tc.name actsDoAbilityForegroundPromiseError0005
* @tc.desc Test the api: doAbilityForeground, swith the ability forground.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0005",
0,
async function (done) {
let wantMain = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0005 start"
);
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0005 Main4Ability: " +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(wantMain, () => {
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0005 startAbility"
);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility(
(err: any, ability2: any) => {
ability2.context.terminateSelf(() => {
setTimeout(() => {
try {
abilityDelegator
.doAbilityForeground(ability2)
.then(() => {});
} catch (error) {
expect(error.message).assertEqual(
"Incorrect parameters."
);
abilityDelegator.printSync(
"ACTS_DO_ABILITY_FOREGROUND_PROMISE_ERROR_0005 doAbilityBackground meet an error: " +
error
);
}
done();
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}
);
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
);
});
}
/*
* 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 {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
const START_ABILITY_TIMEOUT_TWO_THOUSAND = 1000;
export default function GetAbilityStateTest() {
describe("GetAbilityStateTest", function () {
beforeAll(function () {
let want = {
abilityName: "MainAbility",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.startAbility(want);
});
/**
* @tc.number: ACTS_GET_ABILITY_STATE_0001
* @tc.name : actsGetAbilityState0001
* @tc.desc : Test the api "abilityDelegator.getAbilityState", return the uiAbility state result.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_GET_ABILITY_STATE_0001", 0, async function (done) {
let want = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
setTimeout(() => {
abilityDelegator.startAbility(want, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability2: any) => {
try {
var stateNum = abilityDelegator.getAbilityState(ability2);
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0001 getAbilityState: " + stateNum
);
expect(stateNum).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.FOREGROUND);
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0001 getAbilityState Pass. "
);
done();
} catch (error) {
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0001 error: " + error
);
expect().assertFail();
done();
}
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
/**
* @tc.number: ACTS_GET_ABILITY_STATE_0002
* @tc.name : actsGetAbilityState0002
* @tc.desc : Test the api "abilityDelegator.getAbilityState", return the uiAbility state result.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_GET_ABILITY_STATE_0002", 0, async function (done) {
let want = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability1: any) => {
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0002 getCurrentTopAbility start:" +
ability1.context.abilityInfo.name
);
abilityDelegator.startAbility(want, () => {
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0002 startAbility "
);
setTimeout(() => {
try {
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0002 getAbilityState: " + stateNum
);
expect(stateNum).assertEqual(AbilityDelegatorRegistry.AbilityLifecycleState.BACKGROUND);
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0002 getAbilityState Pass. "
);
done();
} catch (error) {
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0002 error: " + error
);
expect().assertFail();
done();
}
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
/**
* @tc.number: ACTS_GET_ABILITY_STATE_0003
* @tc.name : actsGetAbilityState0003
* @tc.desc : Test the api "abilityDelegator.getAbilityState", return the uiAbility state result.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_GET_ABILITY_STATE_0003", 0, async function (done) {
let ability1 = null;
var stateNum = abilityDelegator.getAbilityState(ability1);
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0003 getAbilityState of ability1: " + stateNum
);
expect(stateNum).assertEqual(undefined);
abilityDelegator.printSync(
"ACTS_GET_ABILITY_STATE_0003 getAbilityState Pass. "
);
done();
});
});
}
/*
* 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 {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
export default function GetAppContextTest() {
describe("GetAppContextTest", function () {
/**
* @tc.number: ACTS_GET_APP_CONTENT_0001
* @tc.name : actsGetAppContextCallback0001
* @tc.desc : Test the api "abilityDelegator.startAbility", return the result with callback function.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_GET_APP_CONTENT_0001", 0, async function (done) {
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
if (context != null) {
abilityDelegator.printSync(
"ACTS_GET_APP_CONTENT_0001 : " + JSON.stringify(context)
);
expect(context.applicationInfo.name).assertEqual(
"com.example.delegatortest"
);
expect(context.applicationInfo.description).assertEqual("");
expect(context.applicationInfo.label).assertEqual("$string:app_name");
expect(context.applicationInfo.labelId).assertEqual("16777216");
expect(context.applicationInfo.icon).assertEqual("$media:app_icon");
expect(context.applicationInfo.iconId).assertEqual("16777217");
expect(context.applicationInfo.codePath != null).assertTrue();
abilityDelegator.printSync("ACTS_GET_APP_CONTENT_0001 pass ");
done();
} else {
abilityDelegator.printSync(
"ACTS_GET_APP_CONTENT_0001 not found context"
);
expect().assertFail();
done();
}
});
});
}
/*
* 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 {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
const START_ABILITY_TIMEOUT_TWO_THOUSAND = 2000;
export default function GetCurrentTopAbilityTest() {
describe("GetCurrentTopAbilityTest", function () {
beforeAll(function () {
let want = {
abilityName: "MainAbility",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want);
});
/**
* @tc.number: ACTS_GET_CURRENT_TOP_ABILITY_CALL_BACK_0001
* @tc.name : actsGetCurrentTopAbilityCallback0001
* @tc.desc : Test the api "abilityDelegator.getCurrentTopAbility", return the uiAbility state result.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_GET_CURRENT_TOP_ABILITY_CALL_BACK_0001", 0, async function (done) {
let abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
abilityName: "Main4Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
setTimeout(() => {
abilityDelegator.startAbility(want, () => {
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability2: any) => {
if (ability2 != null) {
abilityDelegator.printSync(
"ACTS_GetCurrentTopAbility_CALLBACK_0001 getCurrentTopAbility2: " +
ability2.context.abilityInfo.name
);
expect(ability2.context.abilityInfo.name).assertEqual(
"Main4Ability"
);
done();
} else {
abilityDelegator.printSync(
"ACTS_GetCurrentTopAbility_CALLBACK_0001 getCurrentTopAbility2 not found."
);
expect().assertFail();
done();
}
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
/**
* @tc.number: ACTS_GET_CURRENT_TOP_ABILITY_PROMISE_0002
* @tc.name : actsGetCurrentTopAbilityCallback0002
* @tc.desc : Test the api "abilityDelegator.getCurrentTopAbility", return the uiAbility state result.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("ACTS_GET_CURRENT_TOP_ABILITY_PROMISE_0002", 0, async function (done) {
let abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
abilityName: "Main3Ability",
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.printSync(
"ACTS_GET_CURRENT_TOP_ABILITY_PROMISE_0002 getCurrentTopAbility start"
);
abilityDelegator.startAbility(want);
setTimeout(() => {
abilityDelegator
.getCurrentTopAbility()
.then((ability: any) => {
if (ability != null) {
abilityDelegator.printSync(
"ACTS_GET_CURRENT_TOP_ABILITY_PROMISE_0002 getCurrentTopAbility1: " +
ability.context.abilityInfo.name
);
expect(ability.context.abilityInfo.name).assertEqual(
"Main3Ability"
);
done();
} else {
abilityDelegator.printSync(
"ACTS_GET_CURRENT_TOP_ABILITY_PROMISE_0002 getCurrentTopAbility1 not found ability1."
);
expect().assertFail();
done();
}
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_GET_CURRENT_TOP_ABILITY_PROMISE_0002 catch error: " + error
);
});
}, START_ABILITY_TIMEOUT_TWO_THOUSAND);
});
});
}
/*
* 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";
import AbilityDelegatorTest from "./Abilitydelegator.test";
import AbilityStageMonitorTest from "./AbilityStageMonitor.test";
import PrintTest from "./Print.test";
import GetAbilityStateTest from "./GetAbilityState.test";
import GetAppContextTest from "./GetAppContext.test";
import AbilityMonitorTest from "./AbilityMonitor.test";
import GetCurrentTopAbilityTest from "./GetCurrentTopAbility.test";
import BackgroundCallbackTest from "./BackgroundCallback.test";
import BackgroundPromiseTest from "./BackgroundPromise.test";
import ForegroundCallbackTest from "./ForegroundCallback.test";
import ForegroundPromiseTest from "./ForegroundPromise.test";
import StartAbilityTest from "./StartAbility.test";
import AbilityMonitorTest2 from "./AbilityMonitor2.test";
import AbilityStageMonitorTest2 from "./AbilityStageMonitor2.test";
export default function testsuite() {
AbilityStageMonitorTest2();
abilityTest();
AbilityDelegatorTest();
AbilityMonitorTest();
AbilityMonitorTest2();
GetCurrentTopAbilityTest();
GetAbilityStateTest();
AbilityStageMonitorTest();
GetAppContextTest();
BackgroundCallbackTest();
BackgroundPromiseTest();
ForegroundCallbackTest();
ForegroundPromiseTest();
PrintTest();
StartAbilityTest();
}
/*
* 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.
*/
// @ts-nocheck
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
export default function PrintTest() {
describe("PrintTest", function () {
/**
* @tc.number ACTS_PRINT_CALLBACK_0001
* @tc.name actsPrintCallback0001
* @tc.desc Test the api "abilityDelegator.print", return the result with callback function.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_CALLBACK_0001", 0, async function (done) {
let msg = "print_Callback normal message: hello print callback.";
abilityDelegator.print(msg, (err: any) => {
abilityDelegator.printSync(
"ACTS_PRINT_CALLBACK_0001 print callback err" + err
);
done();
});
});
/**
* @tc.number ACTS_PRINT_CALLBACK_ERROR_0002
* @tc.name actsPrintCallbackError0002
* @tc.desc Test the api "abilityDelegator.print", return the result with callback function.
* The print information includes number(unsupport).
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_PRINT_CALLBACK_ERROR_0002", 0, async function (done) {
var msg = 123;
try {
abilityDelegator.print(msg, (err: any) => {
abilityDelegator.printSync(
"ACTS_PRINT_CALLBACK_ERROR_0002 print callback err" + err
);
abilityDelegator.printSync(
"ACTS_PRINT_CALLBACK_ERROR_0002 print callback err" + err.code
);
expect().assertFail();
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_PRINT_CALLBACK_ERROR_0002 print code:" + e.code
);
abilityDelegator.printSync(
"ACTS_PRINT_CALLBACK_ERROR_0002 print message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
abilityDelegator.printSync(
"ACTS_PRINT_CALLBACK_ERROR_0002 print callback meet an error: msg is int"
);
done();
}
});
/**
* @tc.number ACTS_PRINT_CALLBACK_0003
* @tc.name actsPrintCallback0003
* @tc.desc Test the api "abilityDelegator.print", return the result with callback function.
* The print information includes escape character.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_CALLBACK_0003", 0, async function (done) {
let msg = "print_Callback escape character: \n";
abilityDelegator.print(msg, (err: any) => {
abilityDelegator.printSync("ACTS_PRINT_CALLBACK_0003 print callback");
done();
});
});
/**
* @tc.number ACTS_PRINT_CALLBACK_0004
* @tc.name actsPrintCallback0004
* @tc.desc Test the api "abilityDelegator.print", return the result with callback function.
* The print information includes special characters, etc.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_CALLBACK_0004", 0, async function (done) {
let msg = "print_Callback special character: © ® ℃ ℉ ™ ↵";
abilityDelegator.print(msg, (err: any) => {
abilityDelegator.printSync("ACTS_PRINT_CALLBACK_0004 print callback");
done();
});
});
/**
* @tc.number ACTS_PRINT_CALLBACK_0005
* @tc.name actsPrintCallback0005
* @tc.desc Test the api "abilityDelegator.print", return the result with callback function.
* The print information includes Chinese etc.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_CALLBACK_0005", 0, async function (done) {
let msg = "print_Callback language: 中文 English  Русский язык Français";
abilityDelegator.print(msg, (err: any) => {
abilityDelegator.printSync("ACTS_PRINT_CALLBACK_0005 print callback");
done();
});
});
/**
* @tc.number ACTS_PRINT_CALLBACK_0006
* @tc.name actsPrintCallback0006
* @tc.desc Test the api "abilityDelegator.print", return the result with callback function.
* the length of the printSync message is greater than 1000 characters.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_CALLBACK_0006", 0, async function (done) {
var msg =
"0callbackaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"aaaaaaaaaa" +
"1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"4aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"5aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"7aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"8aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"9aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae" +
"fffffffffff";
abilityDelegator.print(msg, (err: any) => {
abilityDelegator.printSync(
"ACTS_PRINT_CALLBACK_0006 print callback err" + JSON.stringify(err)
);
abilityDelegator.printSync("ACTS_PRINT_CALLBACK_0006 print callback");
done();
});
});
/**
* @tc.number ACTS_PRINT_PROMISE_0001
* @tc.name actsPrintPromise0001
* @tc.desc Test the api "abilityDelegator.print", return the result with promise function.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_PROMISE_0001", 0, async function (done) {
let msg = "print_Promise normal message: hello print promise.";
abilityDelegator
.print(msg)
.then(() => {
abilityDelegator.printSync("ACTS_PRINT_PROMISE_0001 print promise");
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_0001 catch error: " + error
);
expect().assertFail();
done();
});
});
/**
* @tc.number ACTS_PRINT_PROMISE_ERROR_0002
* @tc.name actsPrintPromiseError0002
* @tc.desc Test the api "abilityDelegator.print", return the result with promise function.
* The print information includes number(unsupport).
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_PRINT_PROMISE_ERROR_0002", 0, async function (done) {
var msg = 123;
try {
abilityDelegator
.print(msg)
.then(() => {
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_ERROR_0002 print promise"
);
expect().assertFail();
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_ERROR_0002 catch error: " + error
);
expect().assertFail();
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_ERROR_0002 print callback code:" + e.code
);
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_ERROR_0002 print callback message:" + e.message
);
expect(e.code).assertEqual(401);
expect(e.message).assertEqual("Incorrect parameters.");
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_ERROR_0002 print promise meet an error: msg is int"
);
done();
}
});
/**
* @tc.number ACTS_PRINT_PROMISE_0003
* @tc.name actsPrintPromise0003
* @tc.desc Test the api "abilityDelegator.print", return the result with promise function.
* The print information includes escape character.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_PROMISE_0003", 0, async function (done) {
let msg = "print_Promise escape character: \n";
abilityDelegator
.print(msg)
.then(() => {
abilityDelegator.printSync("ACTS_PRINT_PROMISE_0003 print promise");
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_0003 catch error: " + error
);
expect().assertFail();
done();
});
});
/**
* @tc.number ACTS_PRINT_PROMISE_0004
* @tc.name actsPrintPromise0004
* @tc.desc Test the api "abilityDelegator.print", return the result with promise function.
* The print information includes special characters, etc.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_PROMISE_0004", 0, async function (done) {
let msg = "print_Promise special character: © ® ℃ ℉ ™ ↵";
abilityDelegator
.print(msg)
.then(() => {
abilityDelegator.printSync("ACTS_PRINT_PROMISE_0004 print promise");
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_0004 catch error: " + error
);
expect().assertFail();
done();
});
});
/**
* @tc.number ACTS_PRINT_PROMISE_0005
* @tc.name actsPrintPromise0005
* @tc.desc Test the api "abilityDelegator.print", return the result with promise function.
* The print information includes Chinese etc.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_PROMISE_0005", 0, async function (done) {
let msg = "print_Promise language: 中文 English  Русский язык Français";
abilityDelegator
.print(msg)
.then(() => {
abilityDelegator.printSync("ACTS_PRINT_PROMISE_0005 print promise");
done();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_PRINT_PROMISE_0005 catch error: " + error
);
expect().assertFail();
done();
});
});
/**
* @tc.number ACTS_PRINT_PROMISE_0006
* @tc.name actsPrintPromise0006
* @tc.desc Test the api "abilityDelegator.print", return the result with promise function.
* the length of the printSync message is greater than 1000 characters.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_PROMISE_0006", 0, async function (done) {
let msg =
"0callbackaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"aaaaaaaaaa" +
"1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"4aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"5aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"7aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"8aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"9aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae" +
"fffffffffff";
abilityDelegator
.print(msg)
.then(() => {
abilityDelegator.printSync("ACTS_PRINT_PROMISE_0006 print promise");
done();
})
.catch((error) => {
abilityDelegator.printSync("ACTS_PRINT_PROMISE_0006 error:" + error);
expect().assertFail();
done();
});
});
/**
* @tc.number ACTS_PRINT_SYNC_0001
* @tc.name actsPrintSync0001
* @tc.desc Test the api "abilityDelegator.printSync", return the result.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_SYNC_0001", 0, async function (done) {
let abilityDelegator;
let msg = "printSync msg";
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.printSync(msg);
abilityDelegator.printSync("ACTS_PRINTSYNC_0001 printSync");
done();
});
/**
* @tc.number ACTS_PRINT_SYNC_ERROR_0002
* @tc.name actsPrintSyncError0002
* @tc.desc Test the api "abilityDelegator.printSync", return the result with.
* The printSync information includes number(unsupport).
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_SYNC_ERROR_0002", 0, async function (done) {
var msg = 123;
try {
abilityDelegator.printSync(msg);
abilityDelegator.printSync("ACTS_PRINTSYNC_0002 printSync");
expect().assertFail();
done();
} catch (e) {
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_PRINT_SYNC_ERROR_0002 printSync meet an error: msg is int"
);
done();
}
});
/**
* @tc.number ACTS_PRINT_SYNC_0003
* @tc.name actsPrintSync0003
* @tc.desc Test the api "abilityDelegator.print", return the result.
* The printSync information includes escape character.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_SYNC_0003", 0, async function (done) {
let msg = "printSync escape character: \n";
abilityDelegator.printSync(msg);
abilityDelegator.printSync("ACTS_PRINT_SYNC_0003 printSync");
done();
});
/**
* @tc.number ACTS_PRINT_SYNC_0004
* @tc.name actsPrintSync0004
* @tc.desc Test the api "abilityDelegator.print", return the result.
* The printSync information includes special characters, etc.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_SYNC_0004", 0, async function (done) {
let msg = "printSync special character: © ® ℃ ℉ ™ ↵";
abilityDelegator.printSync(msg);
abilityDelegator.printSync("ACTS_PRINT_SYNC_0004 printSync");
done();
});
/**
* @tc.number ACTS_PRINT_SYNC_0005
* @tc.name actsPrintSync0005
* @tc.desc Test the api "abilityDelegator.print", return the result.
* The printSync information includes Chinese etc.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_SYNC_0005", 0, async function (done) {
let msg = "printSync language: 中文 English  Русский язык Français";
abilityDelegator.printSync(msg);
abilityDelegator.printSync("ACTS_PRINT_SYNC_0005 printSync");
done();
});
/**
* @tc.number ACTS_PRINT_SYNC_0006
* @tc.name actsPrintSync0006
* @tc.desc Test the api "abilityDelegator.print", return the result.
* the length of the printSync message is greater than 1000 characters.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_PRINT_SYNC_0006", 0, async function (done) {
let msg =
"0callbackaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"aaaaaaaaaa" +
"1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"4aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"5aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"7aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"8aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"9aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae" +
"fffffffffff";
abilityDelegator.printSync(msg);
abilityDelegator.printSync("ACTS_PRINT_SYNC_0006 printSync");
done();
});
});
}
/*
* 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 {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "@ohos/hypium";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
export default function StartAbilityTest() {
describe("StartAbilityTest", function () {
/**
* @tc.number ACTS_START_ABILITY_CALLBACK_0001
* @tc.name actsStartAbilityCallback0001
* @tc.desc Test the api "abilityDelegator.startAbility", return the result with callback function.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_START_ABILITY_CALLBACK_0001", 0, async function (done) {
const want = {
bundleName: "com.example.delegatortest",
moduleName: "entry",
abilityName: "Main4Ability",
};
setTimeout(() => {
abilityDelegator.startAbility(want, () => {
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_0001 startAbility callback"
);
setTimeout(() => {
try {
abilityDelegator.getCurrentTopAbility(
(err: any, ability: any) => {
if (ability != null) {
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_0001 getCurrentTopAbility ability: " +
ability.context.abilityInfo.name
);
expect(
ability.context.abilityInfo.name === "Main4Ability"
).assertTrue();
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_0001 pass."
);
done();
} else {
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_0001 getCurrentTopAbility callback meet an error: not found ability"
);
expect().assertFail();
done();
}
}
);
} catch {
expect().assertFail();
done();
}
}, 2000);
});
}, 2000);
});
/**
* @tc.number ACTS_START_ABILITY_CALLBACK_PARAMETER_0002
* @tc.name actsStartAbilityCallbackParameter0002
* @tc.desc Test the api: startAbility, want contain 'parameters'
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_CALLBACK_PARAMETER_0002", 0, async function (done) {
const want = {
moduleName: "entry",
bundleName: "com.example.delegatortest",
abilityName: "Main3Ability",
parameters: {
keyForString: "test start",
keyForInt: 100,
keyForDouble: 99.99,
keyForBoolean: true,
},
};
abilityDelegator.startAbility(want, () => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_PARAMETER_0002 startAbility callback"
);
setTimeout(() => {
try {
abilityDelegator.getCurrentTopAbility((err: any, ability: any) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_PARAMETER_0002 getCurrentTopAbility: " +
ability.context.abilityInfo.name
);
expect(ability.context.abilityInfo.name).assertEqual(
"Main3Ability"
);
expect(globalThis.want.parameters["keyForString"]).assertEqual(
"test start"
);
expect(globalThis.want.parameters["keyForInt"]).assertEqual(100);
expect(globalThis.want.parameters["keyForDouble"]).assertEqual(
99.99
);
expect(globalThis.want.parameters["keyForBoolean"]).assertEqual(
true
);
console.log("ACTS_START_ABILITY_CALLBACK_PARAMETER_0002 pass");
done();
});
} catch (error) {
console.log(
"ACTS_START_ABILITY_CALLBACK_PARAMETER_0002 fail :" + error
);
expect().assertFail();
done();
}
}, 3000);
});
});
/**
* @tc.number ACTS_START_ABILITY_CALLBACK_ERROR_0001
* @tc.name actsStartAbilityCallbackError0001
* @tc.desc Test the api: startAbility, start an ability which bundleName is the error value, AbilityName is the correct value, and ModuleName is the correct value named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_CALLBACK_ERROR_0001", 0, async function (done) {
const want = {
moduleName: "entry",
bundleName: "com.example.error",
abilityName: "Main4Ability",
};
abilityDelegator.startAbility(want, (err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0001 startAbility callback"
);
try {
if (err != null) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0001 meet an error: " +
err.code
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0001 meet an error: " +
err.message
);
expect(err.code != null).assertTrue();
expect(err.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0001 pass"
);
} else {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0001 error"
);
expect().assertFail();
}
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0001 meet an error: " + e
);
expect().assertFail();
done();
}
});
});
/**
* @tc.number ACTS_START_ABILITY_CALLBACK_ERROR_0002
* @tc.name actsStartAbilityCallbackError0002
* @tc.desc Test the api: startAbility, start an ability which bundlename is the error value, abilityname does not pass in the value, modulename is the correct value, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_CALLBACK_ERROR_0002", 0, async function (done) {
const want = {
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
abilityDelegator.startAbility(want, (err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0002 startAbility callback"
);
try {
if (err != null) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0002 meet an error: " +
err.code
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0002 meet an error: " +
err.message
);
expect(err.code != null).assertTrue();
expect(err.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0002 pass"
);
} else {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0002 error"
);
expect().assertFail();
}
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0002 meet an error: " + e
);
expect().assertFail();
done();
}
});
});
/**
* @tc.number ACTS_START_ABILITY_CALLBACK_ERROR_0003
* @tc.name actsStartAbilityCallbackError0003
* @tc.desc Test the api: startAbility, BundleName does not pass in a value, AbilityName is the correct value, and ModuleName is the correct value, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_CALLBACK_ERROR_0003", 0, async function (done) {
const want = {
moduleName: "entry",
abilityName: "Main4Ability",
};
abilityDelegator.startAbility(want, (err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_ERROR_0003 startAbility callback"
);
try {
if (err != null) {
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_ERROR_0003 meet an error: " + err.code
);
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_ERROR_0003 meet an error: " +
err.message
);
expect(err.code != null).assertTrue();
expect(err.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_ERROR_0003 pass"
);
} else {
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_ERROR_0003 error"
);
expect().assertFail();
}
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_STARTABILITY_CALLBACK_ERROR_0003 meet an error: " + e
);
expect().assertFail();
done();
}
});
});
/**
* @tc.number ACTS_START_ABILITY_CALLBACK_ERROR_0006
* @tc.name actsStartAbilityCallbackError0006
* @tc.desc Test the api: startAbility, want is empty, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_CALLBACK_ERROR_0006", 0, async function (done) {
const want = {};
abilityDelegator.startAbility(want, (err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0006 startAbility callback"
);
try {
if (err != null) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0006 meet an error: " +
err.code
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0006 meet an error: " +
err.message
);
expect(err.code != null).assertTrue();
expect(err.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0006 pass"
);
} else {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0006 error"
);
expect().assertFail();
}
done();
} catch (e) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0006 meet an error: " + e
);
expect().assertFail();
done();
}
});
});
/**
* @tc.number ACTS_START_ABILITY_CALLBACK_ERROR_0007
* @tc.name actsStartAbilityCallbackError0007
* @tc.desc Test the api: startAbility,want is undefined, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_CALLBACK_ERROR_0007", 0, async function (done) {
const want = undefined;
try {
abilityDelegator.startAbility(want, (err: any, data: any) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0007 startAbility callback"
);
expect().assertFail();
done();
});
} catch (e) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0007 meet an error: " + e
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0007 meet an error: " + e.code
);
expect(e.message).assertEqual("Incorrect parameters.");
expect(e.code).assertEqual(401);
abilityDelegator.printSync(
"ACTS_START_ABILITY_CALLBACK_ERROR_0007 pass"
);
done();
}
});
/**
* @tc.number ACTS_START_ABILITY_PROMISE_0001
* @tc.name actsStartAbilityPromise0001
* @tc.desc Test the api "abilityDelegator.startAbility", return the result with callback function.
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 2
*/
it("ACTS_START_ABILITY_PROMISE_0001", 0, async function (done) {
const want = {
moduleName: "entry",
bundleName: "com.example.delegatortest",
abilityName: "Main4Ability",
};
try {
await abilityDelegator.startAbility(want);
setTimeout(() => {
abilityDelegator.getCurrentTopAbility((err: any, ability: any) => {
expect(ability.context.abilityInfo.name).assertEqual(
"Main4Ability"
);
console.log("ACTS_STARTABILITY_PROMISE_0001 pass");
done();
});
}, 2000);
} catch (e) {
abilityDelegator.printSync(
"ACTS_STARTABILITY_PROMISE_0001 meet an error: " + e
);
expect().assertFail();
done();
}
});
/**
* @tc.number ACTS_START_ABILITY_PROMISE_PARAMETER_0002
* @tc.name actsStartAbilityPromiseParameter0002
* @tc.desc Test the api: startAbility, want contain 'parameters'
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_PROMISE_PARAMETER_0002", 0, async function (done) {
const want = {
moduleName: "entry",
bundleName: "com.example.delegatortest",
abilityName: "Main3Ability",
parameters: {
keyForString: "test start",
keyForInt: 100,
keyForDouble: 99.99,
keyForBoolean: true,
},
};
await abilityDelegator.startAbility(want).then((data) => {
setTimeout(() => {
try {
abilityDelegator.getCurrentTopAbility((err: any, ability: any) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_PARAMETER_0002 getCurrentTopAbility: " +
ability.context.abilityInfo.name
);
expect(ability.context.abilityInfo.name).assertEqual(
"Main3Ability"
);
expect(globalThis.want.parameters["keyForString"]).assertEqual(
"test start"
);
expect(globalThis.want.parameters["keyForInt"]).assertEqual(100);
expect(globalThis.want.parameters["keyForDouble"]).assertEqual(
99.99
);
expect(globalThis.want.parameters["keyForBoolean"]).assertEqual(
true
);
console.log("ACTS_START_ABILITY_PROMISE_PARAMETER_0002 pass");
done()
});
} catch (error) {
console.log(
"ACTS_START_ABILITY_PROMISE_PARAMETER_0002 fail :" + error
);
expect().assertFail();
done();
}
}, 3000);
});
});
/**
* @tc.number ACTS_START_ABILITY_PROMISE_ERROR_0001
* @tc.name actsStartAbilityPromiseError0001
* @tc.desc Test the api: startAbility, start an ability which bundle is not exist, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_PROMISE_ERROR_0001", 0, async function (done) {
const want = {
moduleName: "entry",
bundleName: "com.example.error",
abilityName: "Main4Ability",
};
try {
await abilityDelegator
.startAbility(want)
.then((data) => {
abilityDelegator.printSync(
"ACTS_STARTABILITY_PROMISE_ERROR_0001 data: " + data
);
expect().assertFail();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_STARTABILITY_PROMISE_ERROR_0001 meet an error: " + error
);
abilityDelegator.printSync(
"ACTS_STARTABILITY_PROMISE_ERROR_0001 meet an error code: " +
error.code
);
expect(error.code != null).assertTrue();
expect(error.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_STARTABILITY_PROMISE_ERROR_0001 pass"
);
done();
});
} catch (error) {
abilityDelegator.printSync(
"ACTS_STARTABILITY_PROMISE_ERROR_0001 fail error: " + error
);
expect().assertFail();
done();
}
});
/**
* @tc.number ACTS_START_ABILITY_PROMISE_ERROR_0002
* @tc.name actsStartAbilityPromiseError0002
* @tc.desc Test the api: startAbility, bundlename is the error value, abilityname does not pass in the value, modulename is the correct value, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_PROMISE_ERROR_0002", 0, async function (done) {
const want = {
bundleName: "com.example.delegatortest",
moduleName: "entry",
};
try {
await abilityDelegator
.startAbility(want)
.then((data) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0002 data: " + data
);
expect().assertFail();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0002 meet an error: " + error
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0002 meet an error code: " +
error.code
);
expect(error.code != null).assertTrue();
expect(error.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0002 pass"
);
done();
});
} catch (error) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0002 fail error: " + error
);
expect().assertFail();
done();
}
});
/**
* @tc.number ACTS_START_ABILITY_PROMISE_ERROR_0003
* @tc.name actsStartAbilityPromiseError0003
* @tc.desc Test the api: startAbility, start an ability which BundleName does not pass in a value, AbilityName is the correct value, and ModuleName is the correct value, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_PROMISE_ERROR_0003", 0, async function (done) {
const want = {
moduleName: "entry",
abilityName: "Main4Ability",
};
try {
await abilityDelegator
.startAbility(want)
.then((data) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0003 data: " + data
);
expect().assertFail();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0003 meet an error: " + error
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0003 meet an error code: " +
error.code
);
expect(error.code != null).assertTrue();
expect(error.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0003 pass"
);
done();
});
} catch (error) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0003 fail error: " + error
);
expect().assertFail();
done();
}
});
/**
* @tc.number ACTS_START_ABILITY_PROMISE_ERROR_0006
* @tc.name actsStartAbilityPromiseError0006
* @tc.desc Test the api: startAbility, want is empty, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_PROMISE_ERROR_0006", 0, async function (done) {
const want = {};
try {
await abilityDelegator
.startAbility(want)
.then((data) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0006 data: " + data
);
expect().assertFail();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0006 meet an error: " + error
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0006 meet an error code: " +
error.code
);
expect(error.code != null).assertTrue();
expect(error.message).assertEqual("startAbility failed.");
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0006 pass"
);
done();
});
} catch (error) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0006 fail error: " + error
);
expect().assertFail();
done();
}
});
/**
* @tc.number ACTS_START_ABILITY_PROMISE_ERROR_0007
* @tc.name actsStartAbilityPromiseError0007
* @tc.desc Test the api: startAbility, want is undefined, expect it return an error named "startAbility failed".
* @tc.size MediumTest
* @tc.type Function
* @tc.level Level 3
*/
it("ACTS_START_ABILITY_PROMISE_ERROR_0007", 0, async function (done) {
const want = undefined;
try {
await abilityDelegator
.startAbility(want)
.then((data) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0007 data: " + data
);
expect().assertFail();
})
.catch((error) => {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0007 meet an error: " + error
);
expect(error.message).assertEqual("Incorrect parameters.");
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0007 pass"
);
done();
});
} catch (error) {
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0007 fail error: " + error
);
abilityDelegator.printSync(
"ACTS_START_ABILITY_PROMISE_ERROR_0007 meet an error code: " +
error.code
);
expect(error.code).assertEqual(401);
done();
}
});
});
}
/*
* 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) ?? '');
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) ?? '');
});
globalThis.abilityContext = this.context;
}
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.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 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 Main2 {
@State message: string = 'EntryMain2'
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.
*/
@Entry
@Component
struct Main3 {
@State message: string = 'EntryMain3'
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.
*/
@Entry
@Component
struct Main4 {
@State message: string = 'EntryMain4'
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": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"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"
]
}
]
},
{
"name": "MainAbility",
"srcEntrance": "./ets/mainability/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"visible": true
},
{
"name": "Main2Ability",
"srcEntrance": "./ets/Main2Ability/Main2Ability.ts",
"description": "$string:Main2Ability_desc",
"icon": "$media:icon",
"label": "$string:Main2Ability_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"visible": true
},
{
"name": "Main3Ability",
"srcEntry": "./ets/Main3Ability/Main3Ability.ts",
"description": "$string:Main3Ability_desc",
"icon": "$media:icon",
"label": "$string:Main3Ability_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
},
{
"name": "Main4Ability",
"srcEntry": "./ets/Main4Ability/Main4Ability.ts",
"description": "$string:Main4Ability_desc",
"icon": "$media:icon",
"label": "$string:Main4Ability_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background"
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "TestAbility_desc",
"value": "entry ability test"
},
{
"name": "TestAbility_label",
"value": "entry ability test"
},
{
"name": "module_test_desc",
"value": "entry module test description"
},
{
"name": "module_desc",
"value": "entry module description"
},
{
"name": "MainAbility_desc",
"value": "entry description"
},
{
"name": "MainAbility_label",
"value": "entry label"
},
{
"name": "Main2Ability_desc",
"value": "description"
},
{
"name": "Main2Ability_label",
"value": "label"
},
{
"name": "Main3Ability_desc",
"value": "description"
},
{
"name": "Main3Ability_label",
"value": "label"
},
{
"name": "Main4Ability_desc",
"value": "description"
},
{
"name": "Main4Ability_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"src": [
"testability/pages/Index",
"testability/pages/Main2",
"testability/pages/Main3",
"testability/pages/Main4"
]
}
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "Main2Ability_desc",
"value": "description"
},
{
"name": "Main2Ability_label",
"value": "label"
},
{
"name": "Main3Ability_desc",
"value": "description"
},
{
"name": "Main3Ability_label",
"value": "label"
},
{
"name": "Main4Ability_desc",
"value": "description"
},
{
"name": "Main4Ability_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "Main2Ability_desc",
"value": "description"
},
{
"name": "Main2Ability_label",
"value": "label"
},
{
"name": "Main3Ability_desc",
"value": "description"
},
{
"name": "Main3Ability_label",
"value": "label"
},
{
"name": "Main4Ability_desc",
"value": "description"
},
{
"name": "Main4Ability_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.delegatortest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"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("ActsCrossplatformFeatureATest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformFeatureATest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "com.example.delegatortest",
"module-name": "featureassista"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformFeatureATest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('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.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "featureassista",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "MainAbility",
"srcEntry": "./ets/mainability/MainAbility.ts",
"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"
]
}
]
}
]
}
}
{
"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
{
"app": {
"bundleName": "com.example.delegatortest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"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("ActsCrossplatformFeatureBTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformFeatureBTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "com.example.delegatortest",
"module-name": "featureassistb"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformFeatureBTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('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.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "featureassistb",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "MainAbility",
"srcEntry": "./ets/mainability/MainAbility.ts",
"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"
]
}
]
}
]
}
}
{
"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
{
"app": {
"bundleName": "com.example.delegatortest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"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("ActsCrossplatformFeatureCTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformFeatureCTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "com.example.delegatortest",
"module-name": "featureassistc"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformFeatureCTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('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.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "featureassistc",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "MainAbility",
"srcEntry": "./ets/mainability/MainAbility.ts",
"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"
]
}
]
}
]
}
}
{
"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
{
"app": {
"bundleName": "com.example.delegatortest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"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("ActsCrossplatformFeatureDTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformFeatureDTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "com.example.delegatortest",
"module-name": "featureassistd"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformFeatureDTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('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.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "featureassistd",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "MainAbility",
"srcEntry": "./ets/mainability/MainAbility.ts",
"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"
]
}
]
}
]
}
}
{
"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
{
"app": {
"bundleName": "com.example.delegatortest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"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("ActsCrossplatformFeatureTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCrossplatformFeatureTest"
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "com.example.delegatortest",
"module-name": "featureassist"
},
"kits": [
{
"test-file-name": [
"ActsCrossplatformFeatureTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
console.log('testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
console.log('testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
console.log('testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
console.log('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log('testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
console.log('testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
console.log('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.
*/
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "featureassist",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "MainAbility",
"srcEntry": "./ets/mainability/MainAbility.ts",
"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"
]
}
]
}
]
}
}
{
"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
......@@ -17,6 +17,12 @@ group("ability_crossplatform_runtime") {
testonly = true
if (is_standard_system) {
deps = [
"ActsCrossplatformAbilityTest:ActsCrossplatformAbilityTest",
"ActsCrossplatformFeatureATest:ActsCrossplatformFeatureATest",
"ActsCrossplatformFeatureBTest:ActsCrossplatformFeatureBTest",
"ActsCrossplatformFeatureCTest:ActsCrossplatformFeatureCTest",
"ActsCrossplatformFeatureDTest:ActsCrossplatformFeatureDTest",
"ActsCrossplatformFeatureTest:ActsCrossplatformFeatureTest",
"ActsLifeCycleEtsFeatureTest:ActsLifeCycleEtsFeatureTest",
"ActsLifeCycleEtsTest:ActsLifeCycleEtsTest",
"ActsUiAbilityEtsTest:ActsUiAbilityEtsTest",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册