未验证 提交 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 { 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.
*/
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 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.
*/
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册