diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/CreateFormAbility/pages/MainAbility_pages.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/CreateFormAbility/pages/MainAbility_pages.ets index bd1a181eafb32a9bc64d156d02d9f98bd27aff64..56d5f67e613ad670d5eaf335e5304b0bdbed6f35 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/CreateFormAbility/pages/MainAbility_pages.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/CreateFormAbility/pages/MainAbility_pages.ets @@ -28,7 +28,7 @@ struct Index { @State bundle: string = "com.example.apicoverhaptest"; @State ability: string = "FormAbility"; @State moduleName: string = "phone"; - @State name: string = "widget"; + @State name: string = "form1"; private dimension: FormDimension = FormDimension.Dimension_2_2; private temporary = false; diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/FormHostAbility/FormHostAbility.ts b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/FormHostAbility/FormHostAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..b87146f0022cc25140be23f512b2d30bd407cb49 --- /dev/null +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/FormHostAbility/FormHostAbility.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021 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.application.Ability' + +export default class MainAbility extends Ability { + + onCreate(want, launchParam) { + console.log("[Demo] FormHostAbility onCreate") + globalThis.abilityWant = want; + globalThis.applicationContext = this.context.getApplicationContext(); + } + + onDestroy() { + console.log("[Demo] FormHostAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] FormHostAbility onWindowStageCreate") + globalThis.abilityContext = this.context; + windowStage.setUIContent(this.context, "FormHostAbility/pages/MainAbility_pages", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] FormHostAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] FormHostAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] FormHostAbility onBackground") + } +}; diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/FormHostAbility/pages/MainAbility_pages.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/FormHostAbility/pages/MainAbility_pages.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d8586760af62b7b8de76f1d383acb97d319ae42 --- /dev/null +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/FormHostAbility/pages/MainAbility_pages.ets @@ -0,0 +1,62 @@ +// @ts-nocheck +/* + * Copyright (c) 2021 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 router from '@ohos.router'; + +@Entry +@Component +struct Index { + @State message: string = 'FormHostAbility' + @State isShowing: boolean = true; + + @State formId: number = 0; + @State bundle: string = "com.example.apicoverhaptest"; + @State ability: string = "FormAbility"; + @State moduleName: string = "phone"; + @State name: string = "widget"; + private dimension: FormDimension = FormDimension.Dimension_2_1; + private temporary = false; + + build() { + Row() { + Column() { + FormComponent({ + id: this.formId, + name: this.name, + bundle: this.bundle, + ability: this.ability, + module: this.moduleName, + dimension: this.dimension, + temporary: this.temporary, + }) + .allowUpdate(this.allowUpate) + .visibility(this.isShowing ? Visibility.Visible : Visibility.Hidden) + .onAcquired((form) => { + console.log("[FormComponent.FormHostAbility] get form, form id:" + form.id); + globalThis.formId21 = form.id + }) + .onError((error) => { + console.log("[FormComponent.FormHostAbility] error code:" + error.errcode); + console.log("[FormComponent.FormHostAbility] error msg:" + error.msg); + }) + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts index 9817979907de1adda9ef8802aba894e092a50367..21e5a3e438d15227342a49dcb2778470a2f518ee 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/ServiceAbility/ServiceAbility.ts @@ -20,6 +20,7 @@ import rpc from '@ohos.rpc'; export default class ServiceAbility extends ServiceExtension { onCreate(want:Want) { globalThis.abilityWant = want; + globalThis.serviceContext = this.context let direction = this.context.config.direction let pointerDervice = this.context.config.hasPointerDevice let AbilityInfo = this.context.extensionAbilityInfo.bundleName diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets index ba110ccd8ac98fb92688237eddf9565d5d43df6d..e64f4112694c88cfdc102df9b62bb72668a6c4e9 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets @@ -36,12 +36,6 @@ function sleep(time) { export default function ApiCoverTest() { describe('ApiCoverTestTest', function () { - afterEach(async (done) => { - setTimeout(function () { - done(); - }, 2000); - }) - /* * @tc.number SUB_AA_ABILITY_Extension_API_001 * @tc.name StartServiceExtensionAbility with incorrect abilityName. @@ -242,19 +236,21 @@ export default function ApiCoverTest() { expect("/data/storage/el1/bundle").assertEqual(globalThis.abilityContext.bundleCodeDir) expect("/data/storage/el2/distributedfiles").assertEqual(globalThis.abilityContext.distributedFilesDir) expect(1).assertEqual(globalThis.abilityContext.area) - let moduleContext = globalThis.abilityContext.createModuleContext("module1") + let moduleContext = globalThis.abilityContext.createModuleContext("module1") expect("/data/storage/el2/base/cache").assertEqual(moduleContext.cacheDir) - globalThis.abilityContext.resourceManager.getConfiguration((err, data) => { - if(err == undefined){ + globalThis.abilityContext.area = 0 + expect(0).assertEqual(globalThis.abilityContext.area) + globalThis.abilityContext.resourceManager.getConfiguration((err, data) => { + if(err == undefined){ console.log(`Ability: getConfiguration success: ${JSON.stringify(data)}`); - console.log(`Ability: getConfiguration success: JSON.stringify(data.direction)`); + console.log(`Ability: getConfiguration success: JSON.stringify(data.direction)`); expect(0).assertEqual(data.direction) done() - }else{ - expect().assertFail() + }else{ + expect().assertFail() done() - } - }) + } + }) }) /* @@ -338,6 +334,12 @@ export default function ApiCoverTest() { expect(-1).assertEqual(FormInfo.FormState.UNKNOWN) expect(0).assertEqual(FormInfo.ColorMode.MODE_DARK) expect(1).assertEqual(FormInfo.ColorMode.MODE_LIGHT) + console.info("SUB_AA_Form_provider_TestFormInfo_0100:" + FormInfo.FormDimension.Dimension_2_1); + expect(1).assertEqual(FormInfo.FormDimension.Dimension_1_2) + expect(2).assertEqual(FormInfo.FormDimension.Dimension_2_2) + expect(3).assertEqual(FormInfo.FormDimension.Dimension_2_4) + expect(4).assertEqual(FormInfo.FormDimension.Dimension_4_4) + expect(5).assertEqual(FormInfo.FormDimension.Dimension_2_1) done(); }); @@ -391,10 +393,13 @@ export default function ApiCoverTest() { * @tc.desc Function test * @tc.level 3 */ - it('SUB_AA_AbilityConstant_0200', 0, async function (done) { + it('SUB_AA_Test_AbilityConstant_0100', 0, async function (done) { expect(1).assertEqual(abilityConstant.LaunchReason.START_ABILITY) expect(1).assertEqual(abilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) expect(2).assertEqual(abilityConstant.LastExitReason.NORMAL) + expect(0).assertEqual(abilityConstant.MemoryLevel.MEMORY_LEVEL_MODERATE) + expect(1).assertEqual(abilityConstant.MemoryLevel.MEMORY_LEVEL_LOW) + expect(2).assertEqual(abilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) done() }); @@ -462,6 +467,9 @@ export default function ApiCoverTest() { * @tc.level 3 */ it('SUB_AA_FMS_AbilityStage_0100', 0, async function (done) { + console.info("SUB_AA_FMS_AbilityStage_0100===AbilityStage===" + JSON.stringify(globalThis.stageContext)) + console.info("SUB_AA_FMS_AbilityStage_0100===AbilityStage===" + JSON.stringify(globalThis.stageContext.config)) + let directions = globalThis.stageContext.config.direction let subscriber = null let subscribeInfo = { events: ["AbilityStage_StartAbility"] @@ -470,10 +478,12 @@ export default function ApiCoverTest() { console.info("SUB_AA_FMS_AbilityStage_0100===UnSubscribeInfoCallback===") done() } - function SubscribeInfoCallback(err, data) { + async function SubscribeInfoCallback(err, data) { console.info("SUB_AA_FMS_AbilityStage_0100===SubscribeInfoCallback===" + JSON.stringify(data)) expect(data.parameters["config"]).assertEqual(-1) + expect(data.parameters["config"]).assertEqual(directions) commonEvent.unsubscribe(subscriber, UnSubscribeInfoCallback) + await sleep(4000) done() } commonEvent.createSubscriber(subscribeInfo, (err, data) => { @@ -490,6 +500,7 @@ export default function ApiCoverTest() { if(err.code == 0){ console.info("SUB_AA_FMS_AbilityStage_0100===CreateSubscriberCallback===") }else{ + console.info("SUB_AA_FMS_AbilityStage_0100===failed===") expect().assertFail() done() } @@ -504,25 +515,34 @@ export default function ApiCoverTest() { */ it('SUB_AA_FMS_AbilityStage_0200', 0, async function (done) { let subscriber = null - let subscribeInfo = { - events: ["ExtensionConext_StartAbility"] - } - function UnSubscribeInfoCallback(err, data) { - console.info("SUB_AA_FMS_AbilityStage_0200===UnSubscribeInfoCallback===") - } - function SubscribeInfoCallback(err, data) { - console.info("SUB_AA_FMS_AbilityStage_0200===SubscribeInfoCallback===" + JSON.stringify(data)) - expect(data.parameters["config"]).assertLess(2) - expect(data.parameters["poniterDevices"]).assertFalse() - expect(data.parameters["AbilityInfo"]).assertEqual("com.example.apicoverhaptest") - commonEvent.unsubscribe(subscriber, UnSubscribeInfoCallback) - done() - } - commonEvent.createSubscriber(subscribeInfo, (err, data) => { - console.info("SUB_AA_FMS_AbilityStage_0200===CreateSubscriberCallback===") - subscriber = data - commonEvent.subscribe(subscriber, SubscribeInfoCallback) - }) + let subscribeInfo = { + events: ["ExtensionConext_StartAbility"] + } + function UnSubscribeInfoCallback(err, data) { + console.info("SUB_AA_FMS_AbilityStage_0200===UnSubscribeInfoCallback===") + } + async function SubscribeInfoCallback(err, data) { + console.info("SUB_AA_FMS_AbilityStage_0200===SubscribeInfoCallback===" + JSON.stringify(data)) + console.info("SUB_AA_FMS_AbilityStage_0200===serviceContext===" + JSON.stringify(globalThis.serviceContext)) + console.info("SUB_AA_FMS_AbilityStage_0200===config===" + JSON.stringify(globalThis.serviceContext.config)) + expect(data.parameters["config"]).assertLess(2) + expect(data.parameters["poniterDevices"]).assertFalse() + expect(data.parameters["AbilityInfo"]).assertEqual("com.example.apicoverhaptest") + let direction = globalThis.serviceContext.config.direction + let pointerDervice = globalThis.serviceContext.config.hasPointerDevice + let AbilityInfo = globalThis.serviceContext.extensionAbilityInfo.bundleName + expect(direction).assertLess(2) + expect(pointerDervice).assertFalse() + expect(AbilityInfo).assertEqual("com.example.apicoverhaptest") + commonEvent.unsubscribe(subscriber, UnSubscribeInfoCallback) + await sleep(4000) + done() + } + commonEvent.createSubscriber(subscribeInfo, (err, data) => { + console.info("SUB_AA_FMS_AbilityStage_0200===CreateSubscriberCallback===") + subscriber = data + commonEvent.subscribe(subscriber, SubscribeInfoCallback) + }) let formWant ={ deviceId:"", bundleName:"com.example.apicoverhaptest", @@ -582,5 +602,56 @@ export default function ApiCoverTest() { } }) }) + + /* + * @tc.number SUB_AA_FormDisplaySpecifications_0100 + * @tc.name Create a form and delete. + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_FormDisplaySpecifications_0100', 0, async function (done) { + let formWant ={ + deviceId:"", + bundleName:"com.example.apicoverhaptest", + abilityName:"FormHostAbility", + } + globalThis.abilityContext.startAbility(formWant, (err, data)=>{ + if(err.code == 0){ + console.info("SUB_AA_FormDisplaySpecifications_0100===abilityContext startAbility success===") + }else{ + expect().assertFail() + done() + } + }) + await sleep(2000) + console.info("SUB_AA_FormDisplaySpecifications_0100===globalThis.formId21 success===" + globalThis.formId21) + expect(globalThis.formId21 != undefined).assertTrue() + formHost.deleteForm(globalThis.formId21).then((data)=>{ + console.info("SUB_AA_FormDisplaySpecifications_0100===deleteForm success===") + done() + }).catch((err)=>{ + console.info("SUB_AA_FormDisplaySpecifications_0100===deleteForm failed===") + expect().assertFail() + done() + }) + }) + + /* + * @tc.number SUB_AA_FormDisplaySpecifications_0200 + * @tc.name get the form info. + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_FormDisplaySpecifications_0200', 0, async function (done) { + await formHost.getFormsInfo("com.example.apicoverhaptest", "phone").then((data)=>{ + console.info("SUB_AA_FormDisplaySpecifications_0200===deleteForm success===" + JSON.stringify(data)) + expect(5).assertEqual(data[0].defaultDimension) + done() + }).catch((err)=>{ + console.info("SUB_AA_FormDisplaySpecifications_0200===deleteForm failed===" + JSON.stringify(err)) + expect().assertFail() + done() + }) + }) }) } diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/module.json b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/module.json index bbe5d394a7dc9d9f3292ad160f002c1c4ce5d748..4332a92b1eea34dc525d768146dbe5d923d38066 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/module.json +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/module.json @@ -55,6 +55,17 @@ "startWindowBackground": "$color:white", "visible": true, "launchType": "singleton" + }, + { + "name": "FormHostAbility", + "srcEntrance": "./ets/FormHostAbility/FormHostAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "launchType": "singleton" } ], "extensionAbilities": [ @@ -76,7 +87,8 @@ "srcEntrance": "./ets/ServiceAbility/ServiceAbility.ts", "label": "$string:MainAbility_label", "description": "$string:MainAbility_desc", - "type": "service" + "type": "service", + "visible": true } ], "requestPermissions":[ diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/form_config.json b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/form_config.json index 146fbe1c6da88e46886838ba746afb29e69cc190..e2b5e0aaabb7f175f1f32532dd50a31bfc9ec2a4 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/form_config.json +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/form_config.json @@ -4,7 +4,7 @@ "isDefault": true, "src": "./js/widget/pages/index/index", "scheduledUpdateTime": "10:30", - "defaultDimension": "2*2", + "defaultDimension": "2*1", "name": "widget", "description": "This is a service widget.", "colorMode": "auto", @@ -13,6 +13,25 @@ "autoDesignWidth": true }, "formConfigAbility": "ability://xxxxx", + "supportDimensions": [ + "2*1" + ], + "updateEnabled": true, + "updateDuration": 1 + }, + { + "isDefault": false, + "src": "./js/widget/pages/index/index", + "scheduledUpdateTime": "10:30", + "defaultDimension": "2*2", + "name": "form1", + "description": "This is a service widget.", + "colorMode": "auto", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "formConfigAbility": "ability://xxxxx", "supportDimensions": [ "2*2" ], diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/main_pages.json index 0860163e778f59c82e03294795f974e91404456d..c8f90d45cd159400c5f4f8088715066225b9b91f 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/main_pages.json +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/resources/base/profile/main_pages.json @@ -2,6 +2,7 @@ "src": [ "MainAbility/pages/MainAbility_pages", "SecondAbility/pages/MainAbility_pages", - "CreateFormAbility/pages/MainAbility_pages" + "CreateFormAbility/pages/MainAbility_pages", + "FormHostAbility/pages/MainAbility_pages" ] } \ No newline at end of file diff --git a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets index e3a6d8b9279a3da0c22072032e3d9d1536e2cedb..3414d643f1771ee0f8fd1dbb358de90b986db7a0 100644 --- a/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets +++ b/ability/ability_runtime/faapicover/faapicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets @@ -16,6 +16,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from " import FormInfo from '@ohos.application.formInfo'; import formError from '@ohos.application.formError'; +import featureAbility from '@ohos.ability.featureAbility' export default function ApiCoverTest() { describe('ApiCoverTestTest', function () { @@ -75,5 +76,40 @@ export default function ApiCoverTest() { expect(1).assertEqual(FormInfo.FormState.READY) done(); }); + /* + * @tc.number SUB_AA_OpenHarmony_CoverApiContext_0100 + * @tc.name Test getExternalCacheDir by callback. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_AA_OpenHarmony_CoverApiContext_0100', 0, async function (done) { + console.log("------------start SUB_AA_OpenHarmony_CoverApi_0500-------------"); + let appContext = featureAbility.getContext() + appContext.getExternalCacheDir((err, data) => { + expect(data).assertEqual(undefined) + console.info('SUB_AA_OpenHarmony_CoverApiContext_0100 successful. data: ' + JSON.stringify(data)); + done() + }) + }) + + /* + * @tc.number SUB_AA_OpenHarmony_CoverApiContext_0200 + * @tc.name Test getExternalCacheDir by promise. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_AA_OpenHarmony_CoverApiContext_0200', 0, async function (done) { + console.log("------------start SUB_AA_OpenHarmony_CoverApi_0500-------------"); + let appContext = featureAbility.getContext() + appContext.getExternalCacheDir().then((data)=>{ + console.info('SUB_AA_OpenHarmony_CoverApiContext_0200 successful. data: ' + JSON.stringify(data)); + expect(data).assertEqual(undefined) + done() + }).catch((err)=>{ + expect().assertFalse(); + done() + }) + }) + }) } \ No newline at end of file