diff --git a/ability/BUILD.gn b/ability/BUILD.gn index d0cd55395e5270d126378ae55e0369a20224a053..17d685cd0c87a45d0b07ac5b1ae4b183278efad7 100644 --- a/ability/BUILD.gn +++ b/ability/BUILD.gn @@ -17,6 +17,7 @@ group("ability") { testonly = true if (is_standard_system) { deps = [ + "crossplatform:ability_crossplatform", "ability_runtime:ability_runtime", "dmsfwk:dmsfwk", ] diff --git a/ability/crossplatform/BUILD.gn b/ability/crossplatform/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..91f03387ad228867a81b36411d82e09e06747f56 --- /dev/null +++ b/ability/crossplatform/BUILD.gn @@ -0,0 +1,23 @@ +# 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("//build/ohos_var.gni") + +group("ability_crossplatform") { + testonly = true + if (is_standard_system) { + deps = [ + "ability_runtime:ability_crossplatform_runtime", + ] + } +} diff --git a/ability/crossplatform/ability_runtime/BUILD.gn b/ability/crossplatform/ability_runtime/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bb6c6f0783f0c8cd84d6bed93f7578869f8914dc --- /dev/null +++ b/ability/crossplatform/ability_runtime/BUILD.gn @@ -0,0 +1,24 @@ +# 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("//build/ohos_var.gni") + +group("ability_crossplatform_runtime") { + testonly = true + if (is_standard_system) { + deps = [ + "actscontexttest:context_ets_normal_test", + "actscontexttestentry:context_entry_ets_normal_test" + ] + } +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/AppScope/app.json b/ability/crossplatform/ability_runtime/actscontexttest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..36066e67a2980327059f3538104f12196e7e4e2e --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "com.example.contexttest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/AppScope/resources/base/element/string.json b/ability/crossplatform/ability_runtime/actscontexttest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/AppScope/resources/base/media/app_icon.png b/ability/crossplatform/ability_runtime/actscontexttest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/actscontexttest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/crossplatform/ability_runtime/actscontexttest/BUILD.gn b/ability/crossplatform/ability_runtime/actscontexttest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..455cb6c4f5655cf22329261195071c9e2a5c16f9 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/BUILD.gn @@ -0,0 +1,39 @@ +# 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("context_ets_normal_test") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsAbilityContextTest" + 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" +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/Test.json b/ability/crossplatform/ability_runtime/actscontexttest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..464960a34995e564e4e8f455989ce6abef69eb00 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/Test.json @@ -0,0 +1,21 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "300000", + "shell-timeout": "300000", + "bundle-name": "com.example.contexttest", + "module-name": "entryTest", + "testcase-timeout": 5000 + }, + "kits": [ + { + "test-file-name": [ + "ActsAbilityContextTest.hap", + "ActsAbilityContextEntryTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/signature/openharmony_sx.p7b b/ability/crossplatform/ability_runtime/actscontexttest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..a35bb5d5d6412104d0eb2487299c1aa5f4c5bde2 Binary files /dev/null and b/ability/crossplatform/ability_runtime/actscontexttest/signature/openharmony_sx.p7b differ diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/Application/AbilityStage.ts b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..ccbd1395e8e1379e5d75c44c765cf668dacb8c55 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,8 @@ +import AbilityStage from '@ohos.app.ability.AbilityStage'; + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageContext = this.context; + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/MainAbility1/MainAbility1.ts b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/MainAbility1/MainAbility1.ts new file mode 100644 index 0000000000000000000000000000000000000000..dd9d083d276b8aa53ef7a533663476e51f7bf913 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/MainAbility1/MainAbility1.ts @@ -0,0 +1,66 @@ +/* + * 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 Ability from '@ohos.app.ability.UIAbility' + +let abilityName = null; +function recordLife(ownList, abilityName, lifeName) { + ownList.push(abilityName + ' ' + lifeName); +} + +export default class MainAbility1 extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility1 onCreate") + abilityName = want.abilityName; + globalThis.list1 = []; + globalThis.parameters = null; + recordLife(globalThis.list1, abilityName, 'onCreate'); + if (want.parameters) { + globalThis.parameters = want.parameters; + } + } + + onDestroy() { + console.log("[Demo] MainAbility1 onDestroy") + recordLife(globalThis.list1, abilityName, 'onDestroy'); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility1 onWindowStageCreate") + globalThis.ability1Context = this.context; + + windowStage.loadContent('TestAbility/pages/Index1', (err, data) => { + if (err.code) { + console.log('MainAbility1 loadContent error'); + return; + } + console.log('MainAbility1 loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility1 onWindowStageDestroy") + } + + onForeground() { + console.log("[Demo] MainAbility1 onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility1 onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/TestAbility.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..d6b95dd1528eee5972a11c670c53bcd4687ed786 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,67 @@ +/* + * 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; + globalThis.colorMode = this.context.config.colorMode; + globalThis.direction = this.context.config.direction; + } + + 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 diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/pages/Index.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..40f0a77aebde46e8c079bd9975134e37d373c1f7 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/pages/Index1.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/pages/Index1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4836054751d5cc391d5c6d7d249e23bd9e85ca6 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestAbility/pages/Index1.ets @@ -0,0 +1,27 @@ +/* + * 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 Index1 { + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World Mainability1') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +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 diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/List.test.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e32127048f6bfe83c56200a83a83427c4124e0f1 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/List.test.ets @@ -0,0 +1,28 @@ +/* + * 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 Common from './actsCommonTest/Common.test'; +import Configuration from './actsConfigurationTest/Configuration.test'; +import AbilityStageContext from './actsAbilityStageContextTest/AbilityStageContext.test'; +import ApplicationContext from './actsApplicationContextTest/ApplicationContext.test'; +import UIAbilityContext from './actsUIAbilityContextTest/UIAbilityContext.test'; + +export default function testsuite() { + Common(); + Configuration(); + AbilityStageContext(); + ApplicationContext(); + UIAbilityContext(); +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsAbilityStageContextTest/AbilityStageContext.test.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsAbilityStageContextTest/AbilityStageContext.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7df7b35855786574c55afad72c5f48e89b88a11 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsAbilityStageContextTest/AbilityStageContext.test.ets @@ -0,0 +1,473 @@ +/* + * 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 common from '@ohos.app.ability.common'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function AbilityStageContext() { + describe("AbilityStageContext", function () { + let bundleName: any; + + beforeAll(async function () { + console.info("beforeAll case"); + }); + + beforeEach(async function () { + console.info("beforeEach case"); + }); + + afterEach(async function () { + console.info('afterEach case'); + }); + + afterAll(async function () { + console.info("afterAll case"); + }); + + /** + * @tc.number : ABILITY_TEST_ABILITYSTAGECONTEXT_CURRENTHAPMODULEINFO_0100 + * @tc.name : testAbilityStageContextCurrentHapModuleInfo001 + * @tc.desc : test filed of currentHapModuleInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testAbilityStageContextCurrentHapModuleInfo001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + expect(context != null).assertTrue(); + let hapModuleInfo = context.currentHapModuleInfo; + expect(hapModuleInfo != null).assertTrue(); + + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.name: ` + hapModuleInfo.name); + expect(hapModuleInfo.name == "entryTest").assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.icon: ` + hapModuleInfo.icon); + expect(hapModuleInfo.icon == "$media:icon").assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.iconId: ` + hapModuleInfo.iconId); + expect(typeof (hapModuleInfo.iconId) == 'number').assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.label: ` + hapModuleInfo.label); + expect(hapModuleInfo.label == "$string:TestAbility_label").assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.labelId: ` + hapModuleInfo.labelId); + expect(typeof (hapModuleInfo.labelId) == 'number').assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.description: ` + hapModuleInfo.description); + expect(hapModuleInfo.description == "$string:module_test_desc").assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.descriptionId: ` + hapModuleInfo.descriptionId); + expect(typeof (hapModuleInfo.descriptionId) == 'number').assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.mainElementName: ` + hapModuleInfo.mainElementName); + expect(hapModuleInfo.mainElementName == "TestAbility").assertTrue(); + console.log(`testAbilityStageContextCurrentHapModuleInfo001 hapModuleInfo.metadata: ` + hapModuleInfo.metadata.length); + expect(hapModuleInfo.metadata.length >= 0).assertTrue(); + + console.log(`testAbilityStageContextCurrentHapModuleInfo001 success`); + done(); + } catch (err) { + console.log(`testAbilityStageContextCurrentHapModuleInfo001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_ABILITYSTAGECONTEXT_CONFIG_0100 + * @tc.name : testAbilityStageContextConfig001 + * @tc.desc : test filed of config + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testAbilityStageContextConfig001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + expect(context != null).assertTrue(); + let config = context.config; + expect(config != null).assertTrue(); + + console.log(`testAbilityStageContextConfig001 config.colorMode: ` + config.colorMode); + expect(typeof (config.colorMode) == 'number').assertTrue(); + console.log(`testAbilityStageContextConfig001 config.direction: ` + config.direction); + expect(typeof (config.direction) == 'number').assertTrue(); + + console.log(`testAbilityStageContextConfig001 success`); + done(); + } catch (err) { + console.log(`testAbilityStageContextConfig001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STAGEMODE_0100 + * @tc.name : testStageMode001 + * @tc.desc : test filed of stageMode + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testStageMode001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + expect(context.stageMode).assertTrue(); + console.log(`testStageMode001 success`); + done(); + } catch (err) { + console.log(`testStageMode001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_RESOURCEMANAGER_0100 + * @tc.name : testResourceManager001 + * @tc.desc : test filed of resourceManager + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testResourceManager001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + expect(context.resourceManager != null).assertTrue(); + console.log(`testResourceManager001 success`); + done(); + } catch (err) { + console.log(`testResourceManager001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_APPLICATIONINFO_0100 + * @tc.name : testApplicationInfo001 + * @tc.desc : test filed of applicationInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testApplicationInfo001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + expect(context != null).assertTrue(); + let applicationInfo = context.applicationInfo; + expect(applicationInfo != null).assertTrue(); + + console.log(`testApplicationInfo001 applicationInfo.name: ` + applicationInfo.name); + expect(applicationInfo.name == 'com.example.contexttest').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.description: ` + applicationInfo.description.length); + expect(applicationInfo.description.length >= 0).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.descriptionId: ` + applicationInfo.descriptionId); + expect(applicationInfo.descriptionId == 0).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.label: ` + applicationInfo.label); + expect(applicationInfo.label == '$string:app_name').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.labelId: ` + applicationInfo.labelId); + expect(applicationInfo.labelId != null).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.icon: ` + applicationInfo.icon); + expect(applicationInfo.icon == '$media:app_icon').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.iconId: ` + applicationInfo.iconId); + expect(applicationInfo.iconId != null).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.codePath: ` + applicationInfo.codePath); + expect(typeof (applicationInfo.codePath) == 'string').assertTrue(); + + console.log(`testApplicationInfo001 success`); + done(); + } catch (err) { + console.log(`testApplicationInfo001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CACHEDIR_0100 + * @tc.name : testCacheDir001 + * @tc.desc : test filed of cacheDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCacheDir001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + console.log(`testCacheDir001 cacheDir:` + context.cacheDir); + expect(typeof (context.cacheDir) == 'string').assertTrue(); + console.log(`testCacheDir001 success`); + done(); + } catch (err) { + console.log(`testCacheDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_TEMPDIR_0100 + * @tc.name : testTempDir001 + * @tc.desc : test filed of tempDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testTempDir001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + console.log(`testTempDir001 tempDir:` + context.tempDir); + expect(typeof (context.tempDir) == 'string').assertTrue(); + console.log(`testTempDir001 success`); + done(); + } catch (err) { + console.log(`testTempDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_FILESDIR_0100 + * @tc.name : testFilesDir001 + * @tc.desc : test filed of filesDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testFilesDir001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + console.log(`testFilesDir001 filesDir:` + context.filesDir); + expect(typeof (context.filesDir) == 'string').assertTrue(); + console.log(`testFilesDir001 success`); + done(); + } catch (err) { + console.log(`testFilesDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_DATABASEDIR_0100 + * @tc.name : testDatabaseDir001 + * @tc.desc : test filed of databaseDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testDatabaseDir001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + console.log(`testDatabaseDir001 databaseDir:` + context.databaseDir); + expect(typeof (context.databaseDir) == 'string').assertTrue(); + console.log(`testDatabaseDir001 success`); + done(); + } catch (err) { + console.log(`testDatabaseDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_PREFERENCESDIR_0100 + * @tc.name : testPreferencesDir001 + * @tc.desc : test filed of preferencesDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testPreferencesDir001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + console.log(`testPreferencesDir001 preferencesDir:` + context.preferencesDir); + expect(typeof (context.preferencesDir) == 'string').assertTrue(); + console.log(`testPreferencesDir001 success`); + done(); + } catch (err) { + console.log(`testPreferencesDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_BUNDLECODEDIR_0100 + * @tc.name : testBundleCodeDir001 + * @tc.desc : test filed of bundleCodeDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testBundleCodeDir001', 0, async function (done) { + try { + let context: common.AbilityStageContext = globalThis.stageContext; + console.log(`testBundleCodeDir001 bundleCodeDir:` + context.bundleCodeDir); + expect(typeof (context.bundleCodeDir) == 'string').assertTrue(); + console.log(`testBundleCodeDir001 success`); + done(); + } catch (err) { + console.log(`testBundleCodeDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0100 + * @tc.name : testCreateModuleContext001 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap1 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext001", 0, async function (done) { + try { + console.info("testCreateModuleContext001 begin"); + let context: common.AbilityStageContext = globalThis.stageContext; + expect(context != null).assertTrue(); + let moduleContext = context.createModuleContext("entry"); + expect(moduleContext != null).assertTrue(); + bundleName = moduleContext.applicationInfo.name; + console.info("testCreateModuleContext001 bundleName: " + bundleName); + expect(bundleName).assertEqual("com.example.contexttest"); + done(); + } catch (err) { + console.info("testCreateModuleContext001 err: " + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0200 + * @tc.name : testCreateModuleContext002 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap2 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext002", 0, async function (done) { + try { + console.log("testCreateModuleContext002 begin"); + let context: common.AbilityStageContext = globalThis.stageContext; + expect(context != null).assertTrue(); + let moduleContext = context.createModuleContext("entryTest"); + expect(moduleContext != null).assertTrue(); + bundleName = moduleContext.applicationInfo.name; + console.info("testCreateModuleContext002 bundleName: " + bundleName); + expect(bundleName).assertEqual("com.example.contexttest"); + done(); + } catch (err) { + console.info("testCreateModuleContext002 err: " + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0300 + * @tc.name : testCreateModuleContext003 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the cross-application hap1 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext003", 0, async function (done) { + try { + console.info("testCreateModuleContext003 begin"); + let context: common.AbilityStageContext = globalThis.stageContext; + let moduleContext = context.createModuleContext("entry_assist"); + expect(!moduleContext).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext003 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0400 + * @tc.name : testCreateModuleContext004 + * @tc.desc : Context calls createModuleContext, passing in a non-existing moduleName + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext004", 0, async function (done) { + try { + console.info("testCreateModuleContext004 begin"); + let context: common.AbilityStageContext = globalThis.stageContext; + let moduleContext = context.createModuleContext("abc"); + expect(!moduleContext).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext004 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0500 + * @tc.name : testCreateModuleContext005 + * @tc.desc : Context calls createModuleContext, and the incoming moduleName is undefined + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext005", 0, async function (done) { + try { + console.info("testCreateModuleContext005 begin"); + let context: common.AbilityStageContext = globalThis.stageContext; + let moduleContext = context.createModuleContext(undefined); + expect(moduleContext != null).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext005 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_GETAPPLICATIONCONTEXT_0100 + * @tc.name : testGetApplicationContext001 + * @tc.desc : test getApplicationContext return not empty + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetApplicationContext001", 0, async function (done) { + try { + console.info("testGetApplicationContext001 begin"); + let context: common.AbilityStageContext = globalThis.stageContext; + let applicationContext = context.getApplicationContext(); + expect(applicationContext != null).assertTrue(); + console.info("testGetApplicationContext001 success"); + done(); + } catch (err) { + console.log(`testGetApplicationContext001 fail: ` + err); + expect().assertFail(); + done(); + } + }); + }) +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsApplicationContextTest/ApplicationContext.test.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsApplicationContextTest/ApplicationContext.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e19e75bf64ae1fbefb3bab45a1b8d00b5734181 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsApplicationContextTest/ApplicationContext.test.ets @@ -0,0 +1,501 @@ +/* + * 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 common from '@ohos.app.ability.common'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function ApplicationContext() { + describe("ApplicationContext", function () { + let bundleName: any; + + beforeAll(async function () { + console.info("beforeAll case"); + }); + + beforeEach(async function () { + console.info("beforeEach case"); + }); + + afterEach(async function () { + console.info('afterEach case'); + }); + + afterAll(async function () { + console.info("afterAll case"); + }); + + /** + * @tc.number : ABILITY_TEST_GETRUNNINGPROCESSINFORMATION_PROMISE_0100 + * @tc.name : testGetRunningProcessInformationPromise001 + * @tc.desc : test getRunningProcessInformation(promise) + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testGetRunningProcessInformationPromise001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let appContext: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(appContext != null).assertTrue(); + + appContext.getRunningProcessInformation().then((data) => { + expect(data != undefined).assertTrue(); + console.log(`testGetRunningProcessInformationPromise001 pid:` + data[0].pid); + expect(data[0].pid > 0).assertTrue(); + console.log(`testGetRunningProcessInformationPromise001 processName:` + data[0].processName); + expect(data[0].processName == "com.example.contexttest").assertTrue(); + console.log(`testGetRunningProcessInformationPromise001 bundleNames:` + data[0].bundleNames); + expect(data[0].bundleNames[0] == "com.example.contexttest").assertTrue(); + console.log(`testGetRunningProcessInformationPromise001 success`); + done(); + }).catch((err) => { + console.log(`testGetRunningProcessInformationPromise001 fail ` + err); + expect().assertFail(); + done(); + }) + } catch (err) { + console.log(`testGetRunningProcessInformationPromise001 fail ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_GETRUNNINGPROCESSINFORMATION_CALLBACK_0100 + * @tc.name : testGetRunningProcessInformationCb001 + * @tc.desc : test getRunningProcessInformation(callback) + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testGetRunningProcessInformationCb001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let appContext: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(appContext != null).assertTrue(); + + appContext.getRunningProcessInformation((err, data) => { + expect(data != undefined).assertTrue(); + console.log(`testGetRunningProcessInformationCb001 pid:` + data[0].pid); + expect(data[0].pid > 0).assertTrue(); + console.log(`testGetRunningProcessInformationCb001 processName:` + data[0].processName); + expect(data[0].processName == "com.example.contexttest").assertTrue(); + console.log(`testGetRunningProcessInformationCb001 bundleNames:` + data[0].bundleNames); + expect(data[0].bundleNames[0] == "com.example.contexttest").assertTrue(); + console.log(`testGetRunningProcessInformationCb001 success`); + done(); + }) + } catch (err) { + console.log(`testGetRunningProcessInformationCb001 fail ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STAGEMODE_0100 + * @tc.name : testStageMode001 + * @tc.desc : test filed of stageMode + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testStageMode001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(context.stageMode).assertTrue(); + console.log(`testStageMode001 success`); + done(); + } catch (err) { + console.log(`testStageMode001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_RESOURCEMANAGER_0100 + * @tc.name : testResourceManager001 + * @tc.desc : test filed of resourceManager + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testResourceManager001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(context.resourceManager != null).assertTrue(); + console.log(`testResourceManager001 success`); + done(); + } catch (err) { + console.log(`testResourceManager001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_APPLICATIONINFO_0100 + * @tc.name : testApplicationInfo001 + * @tc.desc : test filed of applicationInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testApplicationInfo001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(context != null).assertTrue(); + let applicationInfo = context.applicationInfo; + expect(applicationInfo != null).assertTrue(); + + console.log(`testApplicationInfo001 applicationInfo.name: ` + applicationInfo.name); + expect(applicationInfo.name == 'com.example.contexttest').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.description: ` + applicationInfo.description.length); + expect(applicationInfo.description.length >= 0).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.descriptionId: ` + applicationInfo.descriptionId); + expect(applicationInfo.descriptionId == 0).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.label: ` + applicationInfo.label); + expect(applicationInfo.label == '$string:app_name').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.labelId: ` + applicationInfo.labelId); + expect(applicationInfo.labelId != null).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.icon: ` + applicationInfo.icon); + expect(applicationInfo.icon == '$media:app_icon').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.iconId: ` + applicationInfo.iconId); + expect(applicationInfo.iconId != null).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.codePath: ` + applicationInfo.codePath); + expect(typeof (applicationInfo.codePath) == 'string').assertTrue(); + + console.log(`testApplicationInfo001 success`); + done(); + } catch (err) { + console.log(`testApplicationInfo001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CACHEDIR_0100 + * @tc.name : testCacheDir001 + * @tc.desc : test filed of cacheDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCacheDir001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + console.log(`testCacheDir001 cacheDir:` + context.cacheDir); + expect(typeof (context.cacheDir) == 'string').assertTrue(); + console.log(`testCacheDir001 success`); + done(); + } catch (err) { + console.log(`testCacheDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_TEMPDIR_0100 + * @tc.name : testTempDir001 + * @tc.desc : test filed of tempDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testTempDir001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + console.log(`testTempDir001 tempDir:` + context.tempDir); + expect(typeof (context.tempDir) == 'string').assertTrue(); + console.log(`testTempDir001 success`); + done(); + } catch (err) { + console.log(`testTempDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_FILESDIR_0100 + * @tc.name : testFilesDir001 + * @tc.desc : test filed of filesDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testFilesDir001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + console.log(`testFilesDir001 filesDir:` + context.filesDir); + expect(typeof (context.filesDir) == 'string').assertTrue(); + console.log(`testFilesDir001 success`); + done(); + } catch (err) { + console.log(`testFilesDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_DATABASEDIR_0100 + * @tc.name : testDatabaseDir001 + * @tc.desc : test filed of databaseDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testDatabaseDir001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + console.log(`testDatabaseDir001 databaseDir:` + context.databaseDir); + expect(typeof (context.databaseDir) == 'string').assertTrue(); + console.log(`testDatabaseDir001 success`); + done(); + } catch (err) { + console.log(`testDatabaseDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_PREFERENCESDIR_0100 + * @tc.name : testPreferencesDir001 + * @tc.desc : test filed of preferencesDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testPreferencesDir001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + console.log(`testPreferencesDir001 preferencesDir:` + context.preferencesDir); + expect(typeof (context.preferencesDir) == 'string').assertTrue(); + console.log(`testPreferencesDir001 success`); + done(); + } catch (err) { + console.log(`testPreferencesDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_BUNDLECODEDIR_0100 + * @tc.name : testBundleCodeDir001 + * @tc.desc : test filed of bundleCodeDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testBundleCodeDir001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + console.log(`testBundleCodeDir001 bundleCodeDir:` + context.bundleCodeDir); + expect(typeof (context.bundleCodeDir) == 'string').assertTrue(); + console.log(`testBundleCodeDir001 success`); + done(); + } catch (err) { + console.log(`testBundleCodeDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0100 + * @tc.name : testCreateModuleContext001 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap1 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext001", 0, async function (done) { + try { + console.info("testCreateModuleContext001 begin"); + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(context != null).assertTrue(); + let moduleContext = context.createModuleContext("entry"); + expect(moduleContext != null).assertTrue(); + bundleName = moduleContext.applicationInfo.name; + console.info("testCreateModuleContext001 bundleName: " + bundleName); + expect(bundleName).assertEqual("com.example.contexttest"); + done(); + } catch (err) { + console.info("testCreateModuleContext001 err: " + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0200 + * @tc.name : testCreateModuleContext002 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap2 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext002", 0, async function (done) { + try { + console.log("testCreateModuleContext002 begin"); + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(context != null).assertTrue(); + let moduleContext = context.createModuleContext("entryTest"); + expect(moduleContext != null).assertTrue(); + bundleName = moduleContext.applicationInfo.name; + console.info("testCreateModuleContext002 bundleName: " + bundleName); + expect(bundleName).assertEqual("com.example.contexttest"); + done(); + } catch (err) { + console.info("testCreateModuleContext002 err: " + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0300 + * @tc.name : testCreateModuleContext003 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the cross-application hap1 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext003", 0, async function (done) { + try { + console.info("testCreateModuleContext003 begin"); + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + let moduleContext = context.createModuleContext("entry_assist"); + expect(!moduleContext).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext003 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0400 + * @tc.name : testCreateModuleContext004 + * @tc.desc : Context calls createModuleContext, passing in a non-existing moduleName + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext004", 0, async function (done) { + try { + console.info("testCreateModuleContext004 begin"); + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + let moduleContext = context.createModuleContext("abc"); + expect(!moduleContext).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext004 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0500 + * @tc.name : testCreateModuleContext005 + * @tc.desc : Context calls createModuleContext, and the incoming moduleName is undefined + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext005", 0, async function (done) { + try { + console.info("testCreateModuleContext005 begin"); + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + let moduleContext = context.createModuleContext(undefined); + expect(moduleContext != null).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext005 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_GETAPPLICATIONCONTEXT_0100 + * @tc.name : testGetApplicationContext001 + * @tc.desc : test getApplicationContext return not empty + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetApplicationContext001", 0, async function (done) { + try { + console.info("testGetApplicationContext001 begin"); + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let context: common.ApplicationContext = abilityContext.getApplicationContext(); + let applicationContext = context.getApplicationContext(); + expect(applicationContext != null).assertTrue(); + console.info("testGetApplicationContext001 success"); + done(); + } catch (err) { + console.log(`testGetApplicationContext001 fail: ` + err); + expect().assertFail(); + done(); + } + }); + }) +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsCommonTest/Common.test.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsCommonTest/Common.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f35d4029e92323bd21e85c10e48cce10186fbf9f --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsCommonTest/Common.test.ets @@ -0,0 +1,149 @@ +/* + * 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 common from '@ohos.app.ability.common'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function Common() { + describe("Common", function () { + + beforeAll(async function () { + console.info("beforeAll case"); + }); + + beforeEach(async function () { + console.info("beforeEach case"); + }); + + afterEach(async function () { + console.info('afterEach case'); + }); + + afterAll(async function () { + console.info("afterAll case"); + }); + + /** + * @tc.number : ABILITY_TEST_COMMON_0100 + * @tc.name : testCommon001 + * @tc.desc : test Common of UIAbilityContext + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCommon001', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + console.log(`testCommon001 success`); + done(); + } catch (err) { + console.log(`testCommon001 fail:` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_COMMON_0200 + * @tc.name : testCommon002 + * @tc.desc : test Common of AbilityStageContext + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCommon002', 0, async function (done) { + try { + let stageContext: common.AbilityStageContext = globalThis.stageContext; + expect(stageContext != null).assertTrue(); + console.log(`testCommon002 success`); + done(); + } catch (err) { + console.log(`testCommon002 fail:` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_COMMON_0300 + * @tc.name : testCommon003 + * @tc.desc : test Common of ApplicationContext + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCommon003', 0, async function (done) { + try { + let abilityContext: common.UIAbilityContext = globalThis.abilityContext; + expect(abilityContext != null).assertTrue(); + let appContext: common.ApplicationContext = abilityContext.getApplicationContext(); + expect(appContext != null).assertTrue(); + console.log(`testCommon003 success`); + done(); + } catch (err) { + console.log(`testCommon003 fail:` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_COMMON_0400 + * @tc.name : testCommon004 + * @tc.desc : test Common of BaseContext + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCommon004', 0, async function (done) { + try { + let stageContext: common.AbilityStageContext = globalThis.stageContext; + expect(stageContext != null).assertTrue(); + let baseContext: common.BaseContext = stageContext; + expect(baseContext != null).assertTrue(); + console.log(`testCommon004 success`); + done(); + } catch (err) { + console.log(`testCommon004 fail:` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_COMMON_0500 + * @tc.name : testCommon005 + * @tc.desc : test Common of Context + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCommon005', 0, async function (done) { + try { + let stageContext: common.AbilityStageContext = globalThis.stageContext; + expect(stageContext != null).assertTrue(); + let context: common.Context = stageContext; + expect(context != null).assertTrue(); + console.log(`testCommon005 success`); + done(); + } catch (err) { + console.log(`testCommon005 fail:` + err); + expect().assertFail(); + done(); + } + }) + }) +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsConfigurationTest/Configuration.test.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsConfigurationTest/Configuration.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..61bcf451bf46592284f3d2912051a40401bbacb2 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsConfigurationTest/Configuration.test.ets @@ -0,0 +1,105 @@ +/* + * 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 common from '@ohos.app.ability.common'; +import configurationConstant from '@ohos.app.ability.ConfigurationConstant'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function Configuration() { + describe("Configuration", function () { + + beforeAll(async function () { + console.info("beforeAll case"); + }); + + beforeEach(async function () { + console.info("beforeEach case"); + }); + + afterEach(async function () { + console.info('afterEach case'); + }); + + afterAll(async function () { + console.info("afterAll case"); + }); + + /** + * @tc.number : ABILITY_TEST_COLORMODE_0100 + * @tc.name : testColorMode001 + * @tc.desc : test filed of colorMode + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testColorMode001', 0, async function (done) { + try { + let colorMode = globalThis.colorMode; + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testColorMode001 colorMode:` + colorMode); + if (colorMode == configurationConstant.ColorMode.COLOR_MODE_NOT_SET) { + expect(context.config.colorMode).assertEqual(configurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } else if (colorMode == configurationConstant.ColorMode.COLOR_MODE_DARK) { + expect(context.config.colorMode).assertEqual(configurationConstant.ColorMode.COLOR_MODE_DARK); + expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_NOT_SET).assertTrue(); + expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_LIGHT).assertTrue(); + } else if (colorMode == configurationConstant.ColorMode.COLOR_MODE_LIGHT) { + expect(context.config.colorMode).assertEqual(configurationConstant.ColorMode.COLOR_MODE_LIGHT); + expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_NOT_SET).assertTrue(); + expect(context.config.colorMode != configurationConstant.ColorMode.COLOR_MODE_DARK).assertTrue(); + } + console.log(`testColorMode001 success`); + done(); + } catch (err) { + console.log(`testColorMode001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_DIRECTION_0100 + * @tc.name : testDirection001 + * @tc.desc : test filed of direction + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testDirection001', 0, async function (done) { + try { + let direction = globalThis.direction; + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testDirection001 direction:` + direction); + if (direction == configurationConstant.Direction.DIRECTION_NOT_SET) { + expect(context.config.direction).assertEqual(configurationConstant.Direction.DIRECTION_NOT_SET); + } else if (direction == configurationConstant.Direction.DIRECTION_VERTICAL) { + expect(context.config.direction).assertEqual(configurationConstant.Direction.DIRECTION_VERTICAL); + expect(context.config.direction != configurationConstant.Direction.DIRECTION_NOT_SET).assertTrue(); + expect(context.config.direction != configurationConstant.Direction.DIRECTION_HORIZONTAL).assertTrue(); + } else if (direction == configurationConstant.Direction.DIRECTION_HORIZONTAL) { + expect(context.config.direction).assertEqual(configurationConstant.Direction.DIRECTION_HORIZONTAL); + expect(context.config.direction != configurationConstant.Direction.DIRECTION_NOT_SET).assertTrue(); + expect(context.config.direction != configurationConstant.Direction.DIRECTION_VERTICAL).assertTrue(); + } + console.log(`testDirection001 success`); + done(); + } catch (err) { + console.log(`testDirection001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + }) +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsUIAbilityContextTest/UIAbilityContext.test.ets b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsUIAbilityContextTest/UIAbilityContext.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cf8d016ebed62a46e4f088128a30afb62fbe9eef --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/ets/test/actsUIAbilityContextTest/UIAbilityContext.test.ets @@ -0,0 +1,1513 @@ +/* + * 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 common from '@ohos.app.ability.common'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function UIAbilityContext() { + describe("UIAbilityContext", function () { + let bundleName: any; + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)) + } + + beforeAll(async function () { + console.info("beforeAll case"); + }); + + beforeEach(async function () { + console.info("beforeEach case"); + }); + + afterEach(async function () { + console.info('afterEach case'); + }); + + afterAll(async function () { + console.info("afterAll case"); + }); + + /** + * @tc.number : ABILITY_TEST_ABILITYINFO_0100 + * @tc.name : testAbilityInfo001 + * @tc.desc : test AbilityInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testAbilityInfo001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + let abilityInfo = context.abilityInfo; + expect(abilityInfo != null).assertTrue(); + + console.log(`testAbilityInfo001 abilityInfo.bundleName: ` + abilityInfo.bundleName); + expect(abilityInfo.bundleName == "com.example.contexttest").assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.moduleName: ` + abilityInfo.moduleName); + expect(abilityInfo.moduleName == "entryTest").assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.name: ` + abilityInfo.name); + expect(abilityInfo.name == "TestAbility").assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.label: ` + abilityInfo.label); + expect(abilityInfo.label == "$string:TestAbility_label").assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.labelId: ` + abilityInfo.labelId); + expect(typeof (abilityInfo.labelId) == 'number').assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.description: ` + abilityInfo.description); + expect(abilityInfo.description == "$string:TestAbility_desc").assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.descriptionId: ` + abilityInfo.descriptionId); + expect(typeof (abilityInfo.descriptionId) == 'number').assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.icon: ` + abilityInfo.icon); + expect(abilityInfo.icon == "$media:icon").assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.iconId: ` + abilityInfo.iconId); + expect(typeof (abilityInfo.iconId) == 'number').assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.applicationInfo: ` + abilityInfo.applicationInfo.name); + expect(abilityInfo.applicationInfo.name == "com.example.contexttest").assertTrue(); + console.log(`testAbilityInfo001 abilityInfo.metadata: ` + abilityInfo.metadata.length); + expect(abilityInfo.metadata.length >= 0).assertTrue(); + + console.log(`testAbilityInfo001 success`); + done(); + } catch (err) { + console.log(`testAbilityInfo001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_UIABILITYCONTEXT_CURRENTHAPMODULEINFO_0100 + * @tc.name : testUIAbilityContextCurrentHapModuleInfo001 + * @tc.desc : test filed of currentHapModuleInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testUIAbilityContextCurrentHapModuleInfo001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + let hapModuleInfo = context.currentHapModuleInfo; + expect(hapModuleInfo != null).assertTrue(); + + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.name: ` + hapModuleInfo.name); + expect(hapModuleInfo.name == "entryTest").assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.icon: ` + hapModuleInfo.icon); + expect(hapModuleInfo.icon == "$media:icon").assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.iconId: ` + hapModuleInfo.iconId); + expect(typeof (hapModuleInfo.iconId) == 'number').assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.label: ` + hapModuleInfo.label); + expect(hapModuleInfo.label == "$string:TestAbility_label").assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.labelId: ` + hapModuleInfo.labelId); + expect(typeof (hapModuleInfo.labelId) == 'number').assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.description: ` + hapModuleInfo.description); + expect(hapModuleInfo.description == "$string:module_test_desc").assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.descriptionId: ` + hapModuleInfo.descriptionId); + expect(typeof (hapModuleInfo.descriptionId) == 'number').assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.mainElementName: ` + hapModuleInfo.mainElementName); + expect(hapModuleInfo.mainElementName == "TestAbility").assertTrue(); + console.log(`testUIAbilityContextCurrentHapModuleInfo001 hapModuleInfo.metadata: ` + hapModuleInfo.metadata.length); + expect(hapModuleInfo.metadata.length >= 0).assertTrue(); + + console.log(`testUIAbilityContextCurrentHapModuleInfo001 success`); + done(); + } catch (err) { + console.log(`testUIAbilityContextCurrentHapModuleInfo001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_UIABILITYCONTEXT_CONFIG_0100 + * @tc.name : testUIAbilityContextConfig001 + * @tc.desc : test filed of config + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testUIAbilityContextConfig001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + let config = context.config; + expect(config != null).assertTrue(); + + console.log(`testUIAbilityContextConfig001 config.colorMode: ` + config.colorMode); + expect(typeof (config.colorMode) == 'number').assertTrue(); + console.log(`testUIAbilityContextConfig001 config.direction: ` + config.direction); + expect(typeof (config.direction) == 'number').assertTrue(); + + console.log(`testUIAbilityContextConfig001 success`); + done(); + } catch (err) { + console.log(`testUIAbilityContextConfig001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0100 + * @tc.name : testStartAbilityPromise001 + * @tc.desc : test startAbility right + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.info('testStartAbilityPromise001 start successful.'); + }).catch((error) => { + console.error('testStartAbilityPromise001 start failed. Cause: ' + JSON.stringify(error)); + }) + await sleep(1500); + const result = globalThis.list1; + console.info('result: ' + JSON.stringify(result)); + expect(result[0]).assertEqual('MainAbility1 onCreate'); + + let context1: common.UIAbilityContext = globalThis.ability1Context; + context1.terminateSelf(); + await sleep(1000); + + console.log(`testStartAbilityPromise001 success`); + done(); + } catch (err) { + console.log(`testStartAbilityPromise001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0200 + * @tc.name : testStartAbilityPromise002 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise002', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "bundleName": "com.example.abc", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise002 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise002 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise002 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0300 + * @tc.name : testStartAbilityPromise003 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise003', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "bundleName": " ", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise003 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise003 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise003 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0400 + * @tc.name : testStartAbilityPromise004 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise004', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise004 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise004 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise004 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0500 + * @tc.name : testStartAbilityPromise005 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise005', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "abc" + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise005 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise005 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise005 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0600 + * @tc.name : testStartAbilityPromise006 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise006', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": " " + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise006 fail `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise006 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise006 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0800 + * @tc.name : testStartAbilityPromise008 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise008', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "abc", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise008 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise008 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise008 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_0900 + * @tc.name : testStartAbilityPromise009 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise009', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "bundleName": "com.example.contexttest", + "abilityName": " ", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise009 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise009 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise009 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1000 + * @tc.name : testStartAbilityPromise010 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise010', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = { + "bundleName": "com.example.contexttest", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise010 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise010 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise010 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1100 + * @tc.name : testStartAbilityPromise011 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise011', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + var want = {} + context.startAbility(want).then(() => { + console.log(`testStartAbilityPromise011 fail: `); + expect().assertFail(); + done(); + }).catch((error) => { + console.log(`testStartAbilityPromise011 error.code: ` + error.code); + expect(true).assertTrue(); + done(); + }) + } catch (err) { + console.log(`testStartAbilityPromise011 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1200 + * @tc.name : testStartAbilityPromise012 + * @tc.desc : test startAbility right + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise012', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest", + "parameters": { + "key1": true, + "key2": 1, + "key3": "this is string" + } + } + context.startAbility(want).then(() => { + console.info('testStartAbilityPromise012 start successful.'); + }).catch((error) => { + console.error('testStartAbilityPromise012 start failed. Cause: ' + JSON.stringify(error)); + }) + await sleep(1500); + const result = globalThis.list1; + const parameters = globalThis.parameters; + console.info('result: ' + JSON.stringify(result)); + console.info('parameters: ' + JSON.stringify(parameters)); + expect(result[0]).assertEqual('MainAbility1 onCreate'); + expect(parameters.key1).assertEqual(true); + expect(parameters.key2).assertEqual(1); + expect(parameters.key3).assertEqual("this is string"); + let context1: common.UIAbilityContext = globalThis.ability1Context; + context1.terminateSelf(); + await sleep(1000); + + console.log(`testStartAbilityPromise012 success`); + done(); + } catch (err) { + console.log(`testStartAbilityPromise012 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_PROMISE_1300 + * @tc.name : testStartAbilityPromise013 + * @tc.desc : test startAbility right + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityPromise013', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + + context.startAbility(want).then(() => { + console.info('testStartAbilityPromise013 start1 successful.'); + }).catch((error) => { + console.error('testStartAbilityPromise013 start1 failed. Cause: ' + JSON.stringify(error)); + }) + await sleep(1000); + const result = globalThis.list1; + console.info('result: ' + JSON.stringify(result)); + expect(result[0]).assertEqual('MainAbility1 onCreate'); + let context1: common.UIAbilityContext = globalThis.ability1Context; + + context.startAbility(want).then(() => { + console.info('testStartAbilityPromise013 start2 successful.'); + }).catch((error) => { + console.error('testStartAbilityPromise013 start2 failed. Cause: ' + JSON.stringify(error)); + }) + await sleep(1000); + const result2 = globalThis.list1; + console.info('result2: ' + JSON.stringify(result2)); + expect(result2[0]).assertEqual('MainAbility1 onCreate'); + let context2: common.UIAbilityContext = globalThis.ability1Context; + + context1.terminateSelf(); + await sleep(1000); + context2.terminateSelf(); + await sleep(1000); + + console.log(`testStartAbilityPromise013 success`); + done(); + } catch (err) { + console.log(`testStartAbilityPromise013 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0100 + * @tc.name : testStartAbilityCallback001 + * @tc.desc : test startAbility right + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback001 fail: ` + err); + expect().assertFail(); + done(); + } + console.info('testStartAbilityCallback001 startAbility succeed'); + }) + await sleep(1500); + const result = globalThis.list1; + console.info('result: ' + JSON.stringify(result)); + expect(result[0]).assertEqual('MainAbility1 onCreate'); + + let context1: common.UIAbilityContext = globalThis.ability1Context; + context1.terminateSelf(); + await sleep(1000); + + console.log(`testStartAbilityCallback001 success`); + done(); + } catch (err) { + console.log(`testStartAbilityCallback001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0200 + * @tc.name : testStartAbilityCallback002 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback002', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.abc", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback002 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback002 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0300 + * @tc.name : testStartAbilityCallback003 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback003', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": " ", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback003 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback003 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0400 + * @tc.name : testStartAbilityCallback004 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback004', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback004 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback004 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0500 + * @tc.name : testStartAbilityCallback005 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback005', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "abc" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback005 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback005 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0600 + * @tc.name : testStartAbilityCallback006 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback006', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": " " + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback006 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback006 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0800 + * @tc.name : testStartAbilityCallback008 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback008', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "abc", + "moduleName": "entryTest" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback008 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback008 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_0900 + * @tc.name : testStartAbilityCallback009 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback009', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": " ", + "moduleName": "entryTest" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback009 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback009 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1000 + * @tc.name : testStartAbilityCallback010 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback010', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "moduleName": "entryTest" + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback010 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback010 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1100 + * @tc.name : testStartAbilityCallback011 + * @tc.desc : test startAbility wrong want + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback011', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = {} + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback011 err.code: ` + err.code); + expect(true).assertTrue(); + done(); + } else { + expect().assertFail(); + done(); + } + }) + } catch (err) { + console.log(`testStartAbilityCallback011 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1200 + * @tc.name : testStartAbilityCallback012 + * @tc.desc : test startAbility right + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback012', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest", + "parameters": { + "key1": true, + "key2": 1, + "key3": "this is string" + } + } + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback012 fail: ` + err); + expect().assertFail(); + done(); + return; + } + console.info('testStartAbilityCallback012 startAbility succeed'); + }) + await sleep(1500); + const result = globalThis.list1; + const parameters = globalThis.parameters; + console.info('result: ' + JSON.stringify(result)); + console.info('parameters: ' + JSON.stringify(parameters)); + expect(result[0]).assertEqual('MainAbility1 onCreate'); + expect(parameters.key1).assertEqual(true); + expect(parameters.key2).assertEqual(1); + expect(parameters.key3).assertEqual("this is string"); + + let context1: common.UIAbilityContext = globalThis.ability1Context; + context1.terminateSelf(); + await sleep(1000); + + console.log(`testStartAbilityCallback012 success`); + done(); + } catch (err) { + console.log(`testStartAbilityCallback012 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STARTABILITY_CALLBACK_1300 + * @tc.name : testStartAbilityCallback013 + * @tc.desc : test startAbility right + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('testStartAbilityCallback013', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback013 fail1: ` + err); + expect().assertFail(); + done(); + return; + } + console.info('testStartAbilityCallback013 startAbility1 succeed'); + }) + await sleep(1000); + const result = globalThis.list1; + console.info('result: ' + JSON.stringify(result)); + expect(result[0]).assertEqual('MainAbility1 onCreate'); + let context1: common.UIAbilityContext = globalThis.ability1Context; + + context.startAbility(want, (err) => { + if (err.code) { + console.log(`testStartAbilityCallback013 fail2: ` + err); + expect().assertFail(); + done(); + return; + } + console.info('testStartAbilityCallback013 startAbility2 succeed'); + }) + await sleep(1000); + const result2 = globalThis.list1; + console.info('result: ' + JSON.stringify(result2)); + expect(result2[0]).assertEqual('MainAbility1 onCreate'); + let context2: common.UIAbilityContext = globalThis.ability1Context; + + context1.terminateSelf(); + await sleep(1000); + context2.terminateSelf(); + await sleep(1000); + + console.log(`testStartAbilityCallback013 success`); + done(); + } catch (err) { + console.log(`testStartAbilityCallback013 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_APPLICATIONINFO_PROMISE_0100 + * @tc.name : testApplicationInfoPromise001 + * @tc.desc : test filed of applicationInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testTerminateSelfPromise001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.info('testTerminateSelfPromise001 start successful. '); + }).catch((error) => { + console.error('testTerminateSelfPromise001 start failed. Cause: ' + JSON.stringify(error)); + }) + await sleep(1500); + + let context1: common.UIAbilityContext = globalThis.ability1Context; + context1.terminateSelf(); + await sleep(1000); + + const result = globalThis.list1; + console.info('result: ' + JSON.stringify(result)); + expect(result[1]).assertEqual('MainAbility1 onDestroy'); + + console.log(`testTerminateSelfPromise001 success`); + done(); + } catch (err) { + console.log(`testTerminateSelfPromise001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_APPLICATIONINFO_CALLBACK_0100 + * @tc.name : testApplicationInfoCallback001 + * @tc.desc : test filed of applicationInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testApplicationInfoCallback001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + + var want = { + "bundleName": "com.example.contexttest", + "abilityName": "MainAbility1", + "moduleName": "entryTest" + } + context.startAbility(want).then(() => { + console.info('testApplicationInfoCallback001 start successful. '); + }).catch((error) => { + console.error('testApplicationInfoCallback001 start failed. Cause: ' + JSON.stringify(error)); + }) + await sleep(1500); + + let context1: common.UIAbilityContext = globalThis.ability1Context; + context1.terminateSelf((err) => { + if (err.code) { + console.log(`testApplicationInfoCallback001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + await sleep(1000); + + const result = globalThis.list1; + console.info('result: ' + JSON.stringify(result)); + expect(result[1]).assertEqual('MainAbility1 onDestroy'); + + console.log(`testApplicationInfoCallback001 success`); + done(); + } catch (err) { + console.log(`testApplicationInfoCallback001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_STAGEMODE_0100 + * @tc.name : testStageMode001 + * @tc.desc : test filed of stageMode + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testStageMode001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context.stageMode).assertTrue(); + console.log(`testStageMode001 success`); + done(); + } catch (err) { + console.log(`testStageMode001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_RESOURCEMANAGER_0100 + * @tc.name : testResourceManager001 + * @tc.desc : test filed of resourceManager + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testResourceManager001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context.resourceManager != null).assertTrue(); + console.log(`testResourceManager001 success`); + done(); + } catch (err) { + console.log(`testResourceManager001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_APPLICATIONINFO_0100 + * @tc.name : testApplicationInfo001 + * @tc.desc : test filed of applicationInfo + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testApplicationInfo001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + let applicationInfo = context.applicationInfo; + expect(applicationInfo != null).assertTrue(); + + console.log(`testApplicationInfo001 applicationInfo.name: ` + applicationInfo.name); + expect(applicationInfo.name == 'com.example.contexttest').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.description: ` + applicationInfo.description.length); + expect(applicationInfo.description.length >= 0).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.descriptionId: ` + applicationInfo.descriptionId); + expect(applicationInfo.descriptionId == 0).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.label: ` + applicationInfo.label); + expect(applicationInfo.label == '$string:app_name').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.labelId: ` + applicationInfo.labelId); + expect(applicationInfo.labelId != null).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.icon: ` + applicationInfo.icon); + expect(applicationInfo.icon == '$media:app_icon').assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.iconId: ` + applicationInfo.iconId); + expect(applicationInfo.iconId != null).assertTrue(); + console.log(`testApplicationInfo001 applicationInfo.codePath: ` + applicationInfo.codePath); + expect(typeof (applicationInfo.codePath) == 'string').assertTrue(); + + console.log(`testApplicationInfo001 success`); + done(); + } catch (err) { + console.log(`testApplicationInfo001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CACHEDIR_0100 + * @tc.name : testCacheDir001 + * @tc.desc : test filed of cacheDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testCacheDir001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testCacheDir001 cacheDir:` + context.cacheDir); + expect(typeof (context.cacheDir) == 'string').assertTrue(); + console.log(`testCacheDir001 success`); + done(); + } catch (err) { + console.log(`testCacheDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_TEMPDIR_0100 + * @tc.name : testTempDir001 + * @tc.desc : test filed of tempDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testTempDir001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testTempDir001 tempDir:` + context.tempDir); + expect(typeof (context.tempDir) == 'string').assertTrue(); + console.log(`testTempDir001 success`); + done(); + } catch (err) { + console.log(`testTempDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_FILESDIR_0100 + * @tc.name : testFilesDir001 + * @tc.desc : test filed of filesDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testFilesDir001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testFilesDir001 filesDir:` + context.filesDir); + expect(typeof (context.filesDir) == 'string').assertTrue(); + console.log(`testFilesDir001 success`); + done(); + } catch (err) { + console.log(`testFilesDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_DATABASEDIR_0100 + * @tc.name : testDatabaseDir001 + * @tc.desc : test filed of databaseDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testDatabaseDir001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testDatabaseDir001 databaseDir:` + context.databaseDir); + expect(typeof (context.databaseDir) == 'string').assertTrue(); + console.log(`testDatabaseDir001 success`); + done(); + } catch (err) { + console.log(`testDatabaseDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_PREFERENCESDIR_0100 + * @tc.name : testPreferencesDir001 + * @tc.desc : test filed of preferencesDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testPreferencesDir001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testPreferencesDir001 preferencesDir:` + context.preferencesDir); + expect(typeof (context.preferencesDir) == 'string').assertTrue(); + console.log(`testPreferencesDir001 success`); + done(); + } catch (err) { + console.log(`testPreferencesDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_BUNDLECODEDIR_0100 + * @tc.name : testBundleCodeDir001 + * @tc.desc : test filed of bundleCodeDir + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testBundleCodeDir001', 0, async function (done) { + try { + let context: common.UIAbilityContext = globalThis.abilityContext; + console.log(`testBundleCodeDir001 bundleCodeDir:` + context.bundleCodeDir); + expect(typeof (context.bundleCodeDir) == 'string').assertTrue(); + console.log(`testBundleCodeDir001 success`); + done(); + } catch (err) { + console.log(`testBundleCodeDir001 fail: ` + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_0100 + * @tc.name : testCreateModuleContext001 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap1 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext001", 0, async function (done) { + try { + console.info("testCreateModuleContext001 begin"); + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + let moduleContext = context.createModuleContext("entry"); + expect(moduleContext != null).assertTrue(); + bundleName = moduleContext.applicationInfo.name; + console.info("testCreateModuleContext001 bundleName: " + bundleName); + expect(bundleName).assertEqual("com.example.contexttest"); + done(); + } catch (err) { + console.info("testCreateModuleContext001 err: " + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_002 + * @tc.name : testCreateModuleContext002 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the current application hap2 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext002", 0, async function (done) { + try { + console.log("testCreateModuleContext002 begin"); + let context: common.UIAbilityContext = globalThis.abilityContext; + expect(context != null).assertTrue(); + let moduleContext = context.createModuleContext("entryTest"); + expect(moduleContext != null).assertTrue(); + bundleName = moduleContext.applicationInfo.name; + console.info("testCreateModuleContext002 bundleName: " + bundleName); + expect(bundleName).assertEqual("com.example.contexttest"); + done(); + } catch (err) { + console.info("testCreateModuleContext002 err: " + err); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_003 + * @tc.name : testCreateModuleContext003 + * @tc.desc : Context calls createModuleContext, passing in the moduleName of the cross-application hap1 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext003", 0, async function (done) { + try { + console.info("testCreateModuleContext003 begin"); + let context: common.UIAbilityContext = globalThis.abilityContext; + let moduleContext = context.createModuleContext("entry_assist"); + expect(!moduleContext).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext003 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_004 + * @tc.name : testCreateModuleContext004 + * @tc.desc : Context calls createModuleContext, passing in a non-existing moduleName + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext004", 0, async function (done) { + try { + console.info("testCreateModuleContext004 begin"); + let context: common.UIAbilityContext = globalThis.abilityContext; + let moduleContext = context.createModuleContext("abc"); + expect(!moduleContext).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext004 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_CREATEMODULECONTEXT_005 + * @tc.name : testCreateModuleContext005 + * @tc.desc : Context calls createModuleContext, and the incoming moduleName is undefined + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testCreateModuleContext005", 0, async function (done) { + try { + console.info("testCreateModuleContext005 begin"); + let context: common.UIAbilityContext = globalThis.abilityContext; + let moduleContext = context.createModuleContext(undefined); + expect(moduleContext != null).assertTrue(); + done(); + } catch (err) { + let e = err.toString(); + let errLog = "Invalid input parameter" + console.debug("testCreateModuleContext005 ====>e====>" + e); + expect(e.indexOf(errLog) >= 0).assertTrue(); + done(); + } + }) + + /** + * @tc.number : ABILITY_TEST_GETAPPLICATIONCONTEXT_0100 + * @tc.name : testGetApplicationContext001 + * @tc.desc : test getApplicationContext return not empty + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetApplicationContext001", 0, async function (done) { + try { + console.info("testGetApplicationContext001 begin"); + let context: common.UIAbilityContext = globalThis.abilityContext; + let applicationContext = context.getApplicationContext(); + expect(applicationContext != null).assertTrue(); + console.info("testGetApplicationContext001 success"); + done(); + } catch (err) { + console.log(`testGetApplicationContext001 fail: ` + err); + expect().assertFail(); + done(); + } + }); + }) +} diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/module.json b/ability/crossplatform/ability_runtime/actscontexttest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..384ab9e130691217cea4ab89dc8bf3c7c181ef96 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/module.json @@ -0,0 +1,47 @@ +{ + "module": { + "name": "entryTest", + "type": "feature", + "description": "$string:module_test_desc", + "srcEntry": "./ets/Application/AbilityStage.ts", + "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": "MainAbility1", + "srcEntry": "./ets/MainAbility1/MainAbility1.ts", + "description": "$string:MainAbility1_desc", + "icon": "$media:icon", + "label": "$string:MainAbility1_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "launchType": "multiton" + } + ] + } +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/element/color.json b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/element/string.json b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cfe4072fe5af70504ec752bfe2cb70ca255789b8 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "MainAbility1_desc", + "value": "description" + }, + { + "name": "MainAbility1_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/media/icon.png b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/media/icon.png differ diff --git a/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/profile/test_pages.json b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..27e58b1181b64282d22b1dcc4784b17bbf1fd16e --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "TestAbility/pages/Index", + "TestAbility/pages/Index1" + ] +} diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/app.json b/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..36066e67a2980327059f3538104f12196e7e4e2e --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "com.example.contexttest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/resources/base/element/string.json b/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/resources/base/media/app_icon.png b/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/actscontexttestentry/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/BUILD.gn b/ability/crossplatform/ability_runtime/actscontexttestentry/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..70b95497dc917f33e4cc873601473b49af57d2b5 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/BUILD.gn @@ -0,0 +1,39 @@ +# 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("context_entry_ets_normal_test") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsAbilityContextEntryTest" + 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" +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/signature/openharmony_sx.p7b b/ability/crossplatform/ability_runtime/actscontexttestentry/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..a35bb5d5d6412104d0eb2487299c1aa5f4c5bde2 Binary files /dev/null and b/ability/crossplatform/ability_runtime/actscontexttestentry/signature/openharmony_sx.p7b differ diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/Application/AbilityStage.ts b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..5f781eef66760e9268ec99f02a6d758a49983cfc --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,7 @@ +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 diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/mainability/MainAbility.ts b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/mainability/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..1816299bbc1f7e981520c2d995ed7453f02f160b --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/mainability/MainAbility.ts @@ -0,0 +1,136 @@ +/* + * 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 Ability from '@ohos.app.ability.UIAbility' +const abilityname = 'FeatureMainAbility'; + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant1 = want; + console.log("[Demo] MainAbility context: " + JSON.stringify(this.context)); + var listKey1 = []; + let AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityCreate"); + listKey1.push(abilityname + " onAbilityCreate"); + console.log("[Demo] 1listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageCreate(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageCreate abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onWindowStageCreate"); + listKey1.push(abilityname + " onWindowStageCreate"); + console.log("[Demo] 2listKey1:" + JSON.stringify(listKey1)); + }, + onWindowStageActive(ability, windowStage) { + console.log(abilityname + " onWindowStageActive") + }, + onWindowStageInactive(ability, windowStage) { + console.log(abilityname + " onWindowStageInactive") + }, + onWindowStageDestroy(ability, windowStage) { + console.log("[Demo] AbilityLifecycleCallback1 onWindowStageDestroy ability:" + + JSON.stringify(ability)); + listKey1.push(abilityname + " onWindowStageDestroy"); + console.log("[Demo] 3listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityDestroy(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityDestroy abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityDestroy"); + listKey1.push(abilityname + " onAbilityDestroy"); + console.log("[Demo] 4listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityForeground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityForeground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityForeground"); + listKey1.push(abilityname + " onAbilityForeground"); + console.log("[Demo] 5listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityBackground(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityBackground abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityBackground"); + listKey1.push(abilityname + " onAbilityBackground"); + console.log("[Demo] 6listKey1:" + JSON.stringify(listKey1)); + }, + onAbilityContinue(ability) { + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue ability:" + + JSON.stringify(ability)); + console.log("[Demo] AbilityLifecycleCallback1 onAbilityContinue abilityname:" + + JSON.stringify(abilityname)); + console.log("[Demo] " + abilityname + " onAbilityContinue"); + listKey1.push(abilityname + " onAbilityContinue"); + console.log("[Demo] 7listKey1:" + JSON.stringify(listKey1)); + } + } + globalThis.applicationContext1 = this.context.getApplicationContext(); + // let lifecycleid = globalThis.applicationContext1.registerAbilityLifecycleCallback(AbilityLifecycleCallback); + let lifecycleid = globalThis.applicationContext1.on('abilityLifecycle', AbilityLifecycleCallback); + console.log("[Demo] registerAbilityLifecycleCallback1 number: " + JSON.stringify(lifecycleid)); + setTimeout(function () { + console.log("[Demo] registerAbilityLifecycleCallback1 listKey: " + JSON.stringify(listKey1)); + globalThis.featureList1 = listKey1; + globalThis.featureCallbackid1 = lifecycleid; + }, 1500); + } + + onDestroy() { + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.featureAbilityContext = this.context; + // windowStage.setUIContent(this.context, "testability/pages/index1", null) + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + console.log('MainAbility loadContent error'); + return; + } + console.log('MainAbility loadContent success'); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/pages/Index.ets b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..326276b9ddb3dd8a930d0bbc8677d5aaad64834b --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * 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 diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/module.json b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..19bc237c6fb9935efc940fa7821041b042bf76fb --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/module.json @@ -0,0 +1,36 @@ +{ + "module": { + "name": "entry", + "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" + ] + } + ] + } + ] + } +} diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/element/color.json b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/element/string.json b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "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 diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/media/icon.png b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/media/icon.png differ diff --git a/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/profile/test_pages.json b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ability/crossplatform/ability_runtime/actscontexttestentry/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +}