diff --git a/arkui/ace_ets_state_test/AppScope/app.json b/arkui/ace_ets_state_test/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..445137e48be2a8ecc63d2898cb823f184a17d670 --- /dev/null +++ b/arkui/ace_ets_state_test/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.open.harmony.acestatetest", + "vendor": "huawei", + "versionCode": 1000000, + "versionName": "1.0.0", + "debug": false, + "icon": "$media:icon", + "label": "$string:app_name", + "description": "$string:description_application", + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/AppScope/resources/base/element/string.json b/arkui/ace_ets_state_test/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/arkui/ace_ets_state_test/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"ohosProject" + } + ] +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/AppScope/resources/base/media/app_icon.png b/arkui/ace_ets_state_test/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/arkui/ace_ets_state_test/AppScope/resources/base/media/app_icon.png differ diff --git a/arkui/ace_ets_state_test/BUILD.gn b/arkui/ace_ets_state_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f85e438829e0da79e90a298ba9ecaaa0b5503643 --- /dev/null +++ b/arkui/ace_ets_state_test/BUILD.gn @@ -0,0 +1,41 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsAceStateTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":ace_ets_state_test_js_assets", + ":ace_ets_state_test_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsAceStateTest" +} + +ohos_app_scope("ace_ets_state_test_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("ace_ets_state_test_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("ace_ets_state_test_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":ace_ets_state_test_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/arkui/ace_ets_state_test/Test.json b/arkui/ace_ets_state_test/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..e5f28f93c9a9c9f4c732d32a6db90be1fefc8fdc --- /dev/null +++ b/arkui/ace_ets_state_test/Test.json @@ -0,0 +1,26 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.open.harmony.acestatetest", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [{ + "test-file-name": [ + "ActsAceStateTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "power-shell wakeup", + "power-shell setmode 602" + ] + } + ] +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/Application/AbilityStage.ts b/arkui/ace_ets_state_test/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0e0206ea9fb5ce94ef140d69510b6280969dd8e --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.app.ability.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/MainAbility.ts b/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..2ea1bb20c2500b2f9a2ca61f4cf59b2b482fb153 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,37 @@ +import Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate windowStage="+ windowStage) + globalThis.windowStage = windowStage + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "MainAbility/pages/state", null) + } + + 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/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/pages/state.ets b/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/pages/state.ets new file mode 100644 index 0000000000000000000000000000000000000000..aaf329f7fb3dd7e3dd5b29e55f553456de80d201 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/pages/state.ets @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2021~2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 events_emitter from '@ohos.events.emitter'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../../test/List.test'; +import Utils from '../../test/Utils'; +import web_webview from '@ohos.web.webview'; +import fileio from '@ohos.fileio'; +import prompt from '@system.prompt'; +let loadedUrl; + +let storage: LocalStorage = new LocalStorage({ 'PropA': 47 }); + +@Entry +@Component + +struct Index { + controller: web_webview.WebviewController = new web_webview.WebviewController(); + @State outputStr: string = '' + @State playing: boolean = false + @State str:string="emitOnLoadIntercept" + + + + + + + + + onPageShow(){ + let valueChangeEvent={ + eventId:10, + priority:events_emitter.EventPriority.LOW + }; + events_emitter.on(valueChangeEvent,this.valueChangeCallBack); + } + private valueChangeCallBack=(eventData)=>{ + console.info("web page valueChangeCallBack"); + if(eventData != null){ + console.info("valueChangeCallBack:"+ JSON.stringify(eventData)); + if(eventData.data.ACTION != null){ + this.str = eventData.data.ACTION; + } + } + } + aboutToAppear(){ + let abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + build(){ + Column(){ + Row(){ + Button("web click").key('webcomponent').onClick(async ()=>{ + console.info("key==>"+this.str) + switch(this.str){ + case "emitOnLoadIntercept":{ + this.controller.loadUrl("https://www.baidu.com/") + break; + } + case "emitClear":{ + AppStorage.SetOrCreate('PropA', 47); + let res: boolean = AppStorage.Clear(); + console.log("emitClear====>"+res) + Utils.emitEvent(res,6) + break; + } + case "emitKeys":{ + AppStorage.SetOrCreate('PropA', 48); + let keys: IterableIterator = AppStorage.Keys(); + Utils.emitEvent(JSON.stringify(Array.from(keys)),8) + break; + } + case "emitSize":{ + AppStorage.SetOrCreate('PropA', 48); + let res: number = AppStorage.Size(); + console.log("emitSize====>"+res) + Utils.emitEvent(res,10) + await Utils.sleep(3000) + console.log("emitSize"+AppStorage.Delete('emitSize')) + break; + } + case "emitLocalStorageSize":{ + Utils.emitEvent(storage.size(),12) + break; + } + case "emitLink":{ + AppStorage.SetOrCreate('Link', 47); + let linkToPropA1 = AppStorage.Link('Link'); + let linkToPropA2 = AppStorage.Link('Link'); + linkToPropA1.set(48); + Utils.emitEvent(linkToPropA2.get(),14) + break; + } + case "emitLinkUndefined":{ + AppStorage.SetOrCreate('LinkUndefined', 47); + Utils.emitEvent(AppStorage.Link('PropB'),16) + break; + } + case "emitSetAndLinkCreate":{ + let link:SubscribedAbstractProperty = AppStorage.SetAndLink('LinkCreate', 49); + Utils.emitEvent(link.get(),18) + break; + } + case "emitProp":{ + AppStorage.SetOrCreate('Prop', 47); + let prop1 = AppStorage.Prop('Prop'); + let prop2 = AppStorage.Prop('Prop'); + prop1.set(1); + console.log("emitProp====>"+prop2.get()) + Utils.emitEvent(prop2.get(),20) + break; + } + case "emitPropUndefined":{ + Utils.emitEvent(AppStorage.Prop('xxxxxx'),22) + break; + } + case "emitSetAndLink":{ + AppStorage.SetOrCreate('SetAndLink', 47); + let link: SubscribedAbstractProperty = AppStorage.SetAndLink('SetAndLink', 50); + console.log("emitSetAndLink====>"+link.get()) + Utils.emitEvent(link.get(),24) + break; + } + + case "emitSetAndPropNull":{ + AppStorage.SetOrCreate('SetAndPropNull', 47); + let prop: SubscribedAbstractProperty = AppStorage.SetAndProp('SetAndPropNull1', 49); + console.log("emitSetAndPropNull====>"+prop.get()) + Utils.emitEvent(prop.get(),26) + break; + } + case "emitSetAndProp":{ + AppStorage.SetOrCreate('SetAndProp', 47); + let prop: SubscribedAbstractProperty = AppStorage.SetAndProp('SetAndProp', 49); + console.log("emitSetAndProp====>"+prop.get()) + Utils.emitEvent(prop.get(),28) + break; + } + case "emitDelete":{ + AppStorage.SetOrCreate('Delete', 48); + let res: boolean = AppStorage.Delete('Delete'); + console.log("emitDelete====>"+res) + Utils.emitEvent(res,30) + break; + } + + + + + + + default: + console.info("can not match case") + } + }) + } + Web({src:"www.example.com",controller:this.controller}) + .onLoadIntercept((event) => { + console.log('url:' + event.data.getRequestUrl()) + Utils.emitEvent(event.data.getRequestUrl(),2) + console.log('isMainFrame:' + event.data.isMainFrame()) + console.log('isRedirect:' + event.data.isRedirect()) + console.log('isRequestGesture:' + event.data.isRequestGesture()) + return false + }) + + .onErrorReceive((event) => { + console.log('getErrorInfo:' + event.error.getErrorInfo()) + Utils.emitEvent(event.error.getErrorInfo(),3) + }) + + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/pages/stateTwo.ets b/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/pages/stateTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1d05c91604ed50cc0b21d7c173cb05c1001b12c --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/MainAbility/pages/stateTwo.ets @@ -0,0 +1,403 @@ +/* + * 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 events_emitter from '@ohos.events.emitter'; +import Utils from '../../test/Utils'; +import web_webview from '@ohos.web.webview'; + +function Uint8ArrayToString(dataArray) { + var dataString = '' + for (var i = 0; i < dataArray.length; i++) { + dataString += String.fromCharCode(dataArray[i]) + } + return dataString +} + +function ParseX509CertInfo(x509CertArray) { + let res: string = 'getCertificate success: len = ' + x509CertArray.length; + for (let i = 0; i < x509CertArray.length; i++) { + res += ', index = ' + i + ', issuer name = ' + + Uint8ArrayToString(x509CertArray[i].getIssuerName().data) + ', subject name = ' + + Uint8ArrayToString(x509CertArray[i].getSubjectName().data) + ', valid start = ' + + x509CertArray[i].getNotBeforeTime() + + ', valid end = ' + x509CertArray[i].getNotAfterTime() + } + return res +} + +class Test2{ + value : number + constructor(value : number){ + this.value =value + } +} + +let storage: LocalStorage = new LocalStorage({ 'PropA': 47 }); +enum KFC{A = 1 ,B,C} + + + +@Entry(storage) +@Component +struct Second { + @State outputStr: string = '' + webviewCtl: web_webview.WebviewController = new web_webview.WebviewController(); + @State str:string="emitGetCertificate" + + @LocalStorageLink('Test2') storLink2: Test2 = {value :999}; + @LocalStorageLink('LinkType') storLink3: Array = [3,"enen",true,KFC.A]; + @LocalStorageProp('Bind') storProp1: number = 1; + @LocalStorageProp('') storProp2: number = 1; + @LocalStorageLink('LinkBind') storLinkBind: number = 1; + @LocalStorageProp('CaseNull') storProp3: number = 1; + @LocalStorageProp('PropBind') storProp4: Array = [3,"enen",true,KFC.A]; + @LocalStorageProp('PropTest2') storProp5: Test2 = {value :999}; + + onPageShow(){ + let valueChangeEvent={ + eventId:10, + priority:events_emitter.EventPriority.LOW + }; + events_emitter.on(valueChangeEvent,this.valueChangeCallBack); + } + private valueChangeCallBack=(eventData)=>{ + console.info("web page valueChangeCallBack"); + if(eventData != null){ + console.info("valueChangeCallBack:"+ JSON.stringify(eventData)); + if(eventData.data.ACTION != null){ + this.str = eventData.data.ACTION; + } + } + } + build(){ + Column(){ + Row(){ + Button("web click").key('webcomponenttwo').onClick(async ()=>{ + console.info("key==>"+this.str); + switch(this.str){ + case "emitGetCertificate":{ + this.webviewCtl.loadUrl('https://www.baidu.com') + try { + this.webviewCtl.getCertificate().then(x509CertArray => { + this.outputStr = ParseX509CertInfo(x509CertArray); + console.info('11111111111111'+this.outputStr) + Utils.emitEvent(this.outputStr,4) + }) + } catch (error) { + this.outputStr = 'getCertificate failed: ' + error.code + ", errMsg: " + error.message; + } + break; + } + case "emitGet":{ + AppStorage.SetOrCreate('emitGet', 47); + let value: number = AppStorage.Get('emitGet'); + console.log("emitGet====>"+value) + Utils.emitEvent(value,32) + break; + } + case "emitHas":{ + AppStorage.SetOrCreate('PropA', 47); + console.log("emitHas====>"+AppStorage.Has('PropA')) + Utils.emitEvent(AppStorage.Has('PropA'),5) + break; + } + case "emitSet":{ + AppStorage.SetOrCreate('Set', 48); + console.log("emitSet====>"+AppStorage.Set('Set', 47)) + Utils.emitEvent(AppStorage.Set('Set', 47),6) + break; + } + case "emitSetFalse":{ + console.log("emitSet====>"+AppStorage.Set('emitSetFalse', 47)) + Utils.emitEvent(AppStorage.Set('emitSetFalse', 47),40) + break; + } + + + + + + + case "emitGetUndefined":{ + AppStorage.SetOrCreate('emitGetUndefined', 47); + let value: number = AppStorage.Get('emitGetUndefined1'); + console.log("emitGetUndefined====>"+value) + Utils.emitEvent(value,34) + await Utils.sleep(3000) + break; + } + case "emitIsMutable":{ + AppStorage.SetOrCreate('emitIsMutable', 47); + let res: boolean = AppStorage.IsMutable('emitIsMutable'); + console.log("emitIsMutable====>"+res) + Utils.emitEvent(res,36) + break; + } + case "emitHasFalse":{ + AppStorage.SetOrCreate('emitHasFalse', 47); + console.log("emitHasFalse====>"+AppStorage.Has('emitHasFalse11')) + Utils.emitEvent(AppStorage.Has('emitHasFalse11'),38) + break; + } + case "emitSetOrCreate":{ + AppStorage.SetOrCreate('emitSetOrCreate', 121); + Utils.emitEvent(AppStorage.Get('emitSetOrCreate'),42) + break; + } + case "emitSetOrCreateTwo":{ + AppStorage.SetOrCreate('emitSetOrCreateTwo', 47); + AppStorage.SetOrCreate('emitSetOrCreateTwo', 121); + Utils.emitEvent(AppStorage.Get('emitSetOrCreateTwo'),44) + break; + } + + + case "emitLocalStorageClear":{ + let storage1: LocalStorage = new LocalStorage({ 'PropA': 47 }); + Utils.emitEvent(storage1.clear(),64) + break; + } + case "emitLocalStorageClearFalse":{ + let storage2: LocalStorage = new LocalStorage({ 'PropA': 47 }); + storage2.link('PropA'); + Utils.emitEvent(storage2.delete('PropA'),66) + break; + } + + case "emitLocalStorageHas":{ + Utils.emitEvent(storage.has('PropA'),46) + break; + } + case "emitLocalStorageHasNull":{ + Utils.emitEvent(storage.has('PropAA'),48) + break; + } + case "emitLocalStorageSet":{ + Utils.emitEvent(storage.set('PropA',47),50) + break; + } + case "emitLocalStorageSetNull":{ + Utils.emitEvent(storage.set('PropAA',47),52) + break; + } + case "emitLocalStoragesetOrCreate":{ + Utils.emitEvent(storage.setOrCreate('PropA', 48),54) + break; + } + case "emitLocalStoragesetOrCreateNull":{ + Utils.emitEvent(storage.setOrCreate('PropB', 48),56) + break; + } + case "emitLocalStorageLink":{ + let linkToPropA1: SubscribedAbstractProperty = storage.link('PropA'); + let linkToPropA2: SubscribedAbstractProperty = storage.link('PropA'); + linkToPropA1.set(48); + Utils.emitEvent(linkToPropA2.get(),58) + break; + } + case "emitLocalStorageLinkNull":{ + Utils.emitEvent(storage.link('PropAA'),60) + break; + } + case "emitLocalStoragesetsetAndLink":{ + let link1: SubscribedAbstractProperty = storage.setAndLink('PropBb', 49) + Utils.emitEvent(link1.get(),68) + break; + } + case "emitLocalStoragesetsetAndLinkTwo":{ + let link2: SubscribedAbstractProperty = storage.setAndLink('PropA', 121) + Utils.emitEvent(link2.get(),70) + break; + } + case "emitLocalStorageProp":{ + let prop1: SubscribedAbstractProperty = storage.prop('PropA'); + let prop2: SubscribedAbstractProperty = storage.prop('PropA'); + prop1.set(1); + Utils.emitEvent(prop2.get(),72) + break; + } + case "emitLocalStoragePropNull":{ + Utils.emitEvent(storage.prop('PropAaA'),74) + break; + } + case "emitLocalStorageSetAndProp":{ + let prop: SubscribedAbstractProperty = storage.setAndProp('PropBbB', 49); + Utils.emitEvent(prop.get(),76) + break; + } + case "emitLocalStorageSetAndPropTwo":{ + let prop1: SubscribedAbstractProperty = storage.setAndProp('PropA', 121); + Utils.emitEvent(prop1.get(),78) + break; + } + case "emitLocalStorageDelete":{ + let storage3: LocalStorage = new LocalStorage({ 'PropA': 47 }); + Utils.emitEvent(storage3.delete('PropA'),80) + break; + } + case "emitLocalStorageDeleteFalse":{ + let storage4: LocalStorage = new LocalStorage({ 'PropA': 47 }); + storage4.link('PropA'); + Utils.emitEvent(storage4.delete('PropA'),82) + break; + } + case "emitLocalStorageGet":{ + Utils.emitEvent(storage.get('PropA'),84) + break; + } + case "emitLocalStorageGetFalse":{ + Utils.emitEvent(storage.get('PropAaA'),86) + break; + } + case "emitLocalStorageKeys":{ + let storage5: LocalStorage = new LocalStorage({ 'PropA': 47 }); + let keys: IterableIterator = storage5.keys(); + + Utils.emitEvent(JSON.stringify(Array.from(keys)),88) + break; + } + case "emitPersistPropCover":{ + PersistentStorage.PersistProp('highScore', '0'); + AppStorage.SetOrCreate('highScore', 666); + Utils.emitEvent(AppStorage.Get('highScore'),90) + break; + } + case "emitPersistKeys":{ + let keys: Array = PersistentStorage.Keys(); + console.log("emitPersistKeys====>"+keys) + Utils.emitEvent(JSON.stringify(keys),96) + break; + } + case "emitPersistPropLasting":{ + PersistentStorage.PersistProp('Lasting', '0'); + Utils.emitEvent(AppStorage.Delete('Lasting'),92) + break; + } + case "emitDeleteProp":{ + + PersistentStorage.PersistProp('soon', '0'); + PersistentStorage.DeleteProp('soon'); + let keys: Array = PersistentStorage.Keys(); + Utils.emitEvent(JSON.stringify(keys),94) + break; + } + case "emitPersistProps":{ + PersistentStorage.PersistProps([{ key: 'lowScore', defaultValue: '1' }, { key: 'wightScore', defaultValue: '1' }]); + Utils.emitEvent(AppStorage.Get('lowScore'),98) + break; + } + case "emitEnvironmentKeys":{ + Environment.EnvProps([{ key: 'aa', defaultValue: 'default' }, + {key: 'bb',defaultValue: 'en'}, + { key: 'cc', defaultValue: 'hhhh' }]); + let keys: Array = Environment.Keys(); + Utils.emitEvent(JSON.stringify(keys),100) + break; + } + case "emitGetShared":{ + let storage: LocalStorage = LocalStorage.GetShared(); + console.log("emitGetShared"+storage) + Utils.emitEvent(storage,102) + break; + } + case "emitLocalStoragePropBind":{ + let storage = new LocalStorage({ 'Bind': 88 }); + this.storProp1 += 1 + console.log("emitLocalStorageProp1"+storage) + console.log("emitLocalStorageProp1"+this.storProp1) + Utils.emitEvent(storage.get('Bind'),104) + break; + } + case "emitLocalStoragePropBindTwo":{ + let storage = new LocalStorage({ 'Bind': 88 }); + this.storProp1 = 100 + console.log("emitLocalStorageProp1"+storage) + console.log("emitLocalStorageProp1"+this.storProp1) + Utils.emitEvent(this.storProp1,106) + break; + } + case "emitLocalStoragePropBindNull":{ + let storage = new LocalStorage({ 'Null': 88 }); + this.storProp2 = 1 + Utils.emitEvent(this.storProp2,108) + break; + } + case "emitLocalStorageLinkBind":{ + this.storLinkBind = 1000 + Utils.emitEvent(storage.get('LinkBind'),110) + break; + } + case "emitLocalStoragePropCaseNull":{ + Utils.emitEvent(storage.get('CaseNull'),112) + break; + } + case "emitEnvironmentTypeString":{ + Environment.EnvProp('one', "en"); + Environment.EnvProp('two', 2); + Environment.EnvProps([{ key: 'three', defaultValue: true }, { + key: 'four', + defaultValue: KFC.A + }]); + Utils.emitEvent(AppStorage.Has('one'),114) + break; + } + case "emitEnvironmentTypeNum":{ + Utils.emitEvent(AppStorage.Has('two'),116) + break; + } + case "emitEnvironmentTypeBoo":{ + Utils.emitEvent(AppStorage.Has('three'),118) + break; + } + case "emitEnvironmentTypeEnum":{ + Utils.emitEvent(AppStorage.Has('four'),120) + break; + } + case "emitLocalStorageLinkType":{ + Utils.emitEvent(storage.has('Test2'),122) + break; + } + case "emitLocalStorageLinkTypeTwo":{ + console.log("emitLocalStorageLinkTypeTwo"+storage.get('LinkType')) + Utils.emitEvent(storage.has('LinkType'),124) + + break; + } + case "emitLocalStoragePropTypeTwo":{ + console.log("emitLocalStoragePropTwo"+storage.get('PropBind')) + Utils.emitEvent(JSON.stringify(this.storProp4),126) + break; + } + case "emitLocalStoragePropType":{ + console.log("emitLocalStoragePropTwo"+this.storProp5) + Utils.emitEvent(storage.has('PropTest2'),128) + break; + } + + default: + console.info("can not match case"); + } + }) + } + Web({ src: 'https://www.example.com', controller: this.webviewCtl }) + .fileAccess(true) + .javaScriptAccess(true) + .domStorageAccess(true) + .onlineImageAccess(true) + .onPageEnd((e) => { + this.outputStr = 'onPageEnd : url = ' + e.url + }) + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/arkui/ace_ets_state_test/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..a4ee2f1652b3d04ce83ece64ef70f8dfa62a2dc8 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a com.example.myapplication.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/test/List.test.ets b/arkui/ace_ets_state_test/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6006ceb7c8b50b1a032522821e1933e35df9074 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,25 @@ +/* + * 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 stateJsunit from './StateJsunit.test' +import stateTwoJsunit from './StateTwoJsunit.test' +export default function testsuite() { + + stateJsunit() + stateTwoJsunit() + + + + +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/test/StateJsunit.test.ets b/arkui/ace_ets_state_test/entry/src/main/ets/test/StateJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..15219905272575378d31cbaaf346cb340d5e187c --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/test/StateJsunit.test.ets @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// @ts-nocheck +import { describe, beforeEach, afterEach, it, expect } from "@ohos/hypium"; +import events_emitter from '@ohos.events.emitter'; +import Utils from './Utils.ets'; +let emitKey = "emitOnLoadIntercept"; +export default function stateJsunit() { + describe('ActsAceStateTest', function () { + beforeEach(async function (done) { + await Utils.sleep(2000); + console.info("state beforeEach start"); + done(); + }) + + afterEach(async function (done) { + console.info("state afterEach start:"+emitKey); + try { + let backData = { + data: { + "ACTION": emitKey + } + } + let backEvent = { + eventId:10, + priority:events_emitter.EventPriority.LOW + } + console.info("start send emitKey"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("emit emitKey err: " + JSON.stringify(err)); + } + await Utils.sleep(2000); + done(); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_002 + *tc.name OnLoadIntercept *tc.desic Injects the JavaScript object into window and invoke the function in window + */ + it('OnLoadIntercept',0,async function(done){ + emitKey="emitClear"; + Utils.registerEvent("OnLoadIntercept","https://www.baidu.com/",2,done); + sendEventByKey('webcomponent',10,''); + }) + it('Clear',0,async function(done){ + emitKey="emitKeys"; + Utils.registerEvent("Clear",true,6,done); + sendEventByKey('webcomponent',10,''); + }) + it('Keys',0,async function(done){ + emitKey="emitSize"; + let value =["PropA"] + Utils.registerEvent("Keys",JSON.stringify(value),8,done); + sendEventByKey('webcomponent',10,''); + }) + it('Size',0,async function(done){ + emitKey="emitLocalStorageSize"; + Utils.registerEvent("Size",1,10,done); + sendEventByKey('webcomponent',10,''); + }) + it('LocalStorageSize',0,async function(done){ + emitKey="emitLink"; + Utils.registerEvent("LocalStorageSize",1,12,done); + sendEventByKey('webcomponent',10,''); + }) + it('Link',0,async function(done){ + emitKey="emitLinkUndefined"; + Utils.registerEvent("Link",48,14,done); + sendEventByKey('webcomponent',10,''); + }) + it('LinkUndefined',0,async function(done){ + emitKey="emitSetAndLinkCreate"; + Utils.registerEvent("LinkUndefined",undefined,16,done); + sendEventByKey('webcomponent',10,''); + }) + it('SetAndLinkCreate',0,async function(done){ + emitKey="emitProp"; + Utils.registerEvent("SetAndLinkCreate",49,18,done); + sendEventByKey('webcomponent',10,''); + }) + it('Prop',0,async function(done){ + emitKey="emitPropUndefined"; + Utils.registerEvent("Prop",47,20,done); + sendEventByKey('webcomponent',10,''); + }) + it('PropUndefined',0,async function(done){ + emitKey="emitSetAndLink"; + Utils.registerEvent("PropUndefined",undefined,22,done); + sendEventByKey('webcomponent',10,''); + }) + it('SetAndLink',0,async function(done){ + emitKey="emitSetAndPropNull"; + Utils.registerEvent("SetAndLink",47,24,done); + sendEventByKey('webcomponent',10,''); + }) + it('SetAndPropNull',0,async function(done){ + emitKey="emitSetAndProp"; + Utils.registerEvent("SetAndPropNull",49,26,done); + sendEventByKey('webcomponent',10,''); + }) + it('SetAndProp',0,async function(done){ + emitKey="emitDelete"; + Utils.registerEvent("SetAndProp",47,28,done); + sendEventByKey('webcomponent',10,''); + }) + it('Delete',0,async function(done){ + emitKey="emitDelete"; + Utils.registerEvent("Delete",true,30,done); + sendEventByKey('webcomponent',10,''); + }) + + }) +} diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/test/StateTwoJsunit.test.ets b/arkui/ace_ets_state_test/entry/src/main/ets/test/StateTwoJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a6067cc68b8764ac4df9ad8abddf3cd97082a9e1 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/test/StateTwoJsunit.test.ets @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// @ts-nocheck +import { describe, beforeEach, afterEach, it, expect, beforeAll} from "@ohos/hypium"; +import events_emitter from '@ohos.events.emitter'; +import router from '@system.router'; +import Utils from './Utils.ets'; +let emitKey = "emitGetCertificate"; +export default function stateTwoJsunit() { + describe('ActsAceStateTwoTest', function () { + + beforeAll(async function (done) { + let options = { + uri: 'MainAbility/pages/stateTwo', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get stateTwo state success " + JSON.stringify(pages)); + if (!("stateTwo" == pages.name)) { + console.info("get stateTwo state success " + JSON.stringify(pages.name)); + let result = await router.push(options); + await Utils.sleep(2000); + console.info("push stateTwo page success " + JSON.stringify(result)); + } + } catch (err) { + console.error("push stateTwo page error: " + err); + } + done() + }); + + beforeEach(async function (done) { + await Utils.sleep(2000); + console.info("stateTwo beforeEach start"); + done(); + }) + afterEach(async function (done) { + console.info("stateTwo afterEach start:"+emitKey); + try { + let backData = { + data: { + "ACTION": emitKey + } + } + let backEvent = { + eventId:10, + priority:events_emitter.EventPriority.LOW + } + console.info("start send emitKey"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("emit emitKey err: " + JSON.stringify(err)); + } + await Utils.sleep(2000); + done(); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_001 + *tc.name GetCertificate + *tc.desic Sets allow the Web access overview mode + */ + it('GetCertificate',0,async function(done){ + emitKey="emitGet"; + Utils.registerEvent("GetCertificate","getCertificate success: len = 0",4,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('Get',0,async function(done){ + emitKey="emitHas"; + Utils.registerEvent("Get",47,32,done); + sendEventByKey('webcomponenttwo',10,''); + }) + + + it('Has',0,async function(done){ + emitKey="emitSet"; + Utils.registerEvent("Has",true,5,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('Set',0,async function(done){ + emitKey="emitSetFalse"; + Utils.registerEvent("Set",true,6,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('SetFalse',0,async function(done){ + emitKey="emitGetUndefined"; + Utils.registerEvent("SetFalse",false,40,done); + sendEventByKey('webcomponenttwo',10,''); + }) + + + + it('GetUndefined',0,async function(done){ + emitKey="emitIsMutable"; + Utils.registerEvent("GetUndefined",undefined,34,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('IsMutable',0,async function(done){ + emitKey="emitHasFalse"; + Utils.registerEvent("IsMutable",true,36,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('HasFalse',0,async function(done){ + emitKey="emitSetOrCreate"; + Utils.registerEvent("HasFalse",false,38,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('SetOrCreate',0,async function(done){ + emitKey="emitSetOrCreateTwo"; + Utils.registerEvent("SetOrCreate",121,42,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('SetOrCreateTwo',0,async function(done){ + emitKey="emitLocalStorageClear"; + Utils.registerEvent("SetOrCreateTwo",121,44,done); + sendEventByKey('webcomponenttwo',10,''); + }) + + + it('LocalStorageClear',0,async function(done){ + emitKey="emitLocalStorageClearFalse"; + Utils.registerEvent("LocalStorageClear",true,64,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageClearFalse',0,async function(done){ + emitKey="emitLocalStorageHas"; + Utils.registerEvent("LocalStorageClearFalse",false,66,done); + sendEventByKey('webcomponenttwo',10,''); + }) + + it('LocalStorageHas',0,async function(done){ + emitKey="emitLocalStorageHasNull"; + Utils.registerEvent("LocalStorageHas",true,46,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageHasNull',0,async function(done){ + emitKey="emitLocalStorageSet"; + Utils.registerEvent("LocalStorageHasNull",false,48,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageSet',0,async function(done){ + emitKey="emitLocalStorageSetNull"; + Utils.registerEvent("LocalStorageSet",true,50,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageSetNull',0,async function(done){ + emitKey="emitLocalStoragesetOrCreate"; + Utils.registerEvent("LocalStorageSetNull",false,52,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragesetOrCreate',0,async function(done){ + emitKey="emitLocalStoragesetOrCreateNull"; + Utils.registerEvent("LocalStoragesetOrCreate",true,54,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragesetOrCreateNull',0,async function(done){ + emitKey="emitLocalStorageLink"; + Utils.registerEvent("LocalStoragesetOrCreateNull",true,56,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageLink',0,async function(done){ + emitKey="emitLocalStorageLinkNull"; + Utils.registerEvent("LocalStorageLink",48,58,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageLinkNull',0,async function(done){ + emitKey="emitLocalStoragesetsetAndLink"; + Utils.registerEvent("LocalStorageLinkNull",undefined,60,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragesetsetAndLink',0,async function(done){ + emitKey="emitLocalStoragesetsetAndLinkTwo"; + Utils.registerEvent("LocalStoragesetsetAndLink",49,68,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragesetsetAndLinkTwo',0,async function(done){ + emitKey="emitLocalStorageProp"; + Utils.registerEvent("LocalStoragesetsetAndLinkTwo",48,70,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageProp',0,async function(done){ + emitKey="emitLocalStoragePropNull"; + Utils.registerEvent("LocalStorageProp",48,72,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragePropNull',0,async function(done){ + emitKey="emitLocalStorageSetAndProp"; + Utils.registerEvent("LocalStoragePropNull",undefined,74,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageSetAndProp',0,async function(done){ + emitKey="emitLocalStorageSetAndPropTwo"; + Utils.registerEvent("LocalStorageSetAndProp",49,76,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageSetAndPropTwo',0,async function(done){ + emitKey="emitLocalStorageDelete"; + Utils.registerEvent("LocalStorageSetAndPropTwo",48,78,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageDelete',0,async function(done){ + emitKey="emitLocalStorageDeleteFalse"; + Utils.registerEvent("LocalStorageDelete",true,80,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageDeleteFalse',0,async function(done){ + emitKey="emitLocalStorageGet"; + Utils.registerEvent("LocalStorageDeleteFalse",false,82,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageGet',0,async function(done){ + emitKey="emitLocalStorageGetFalse"; + Utils.registerEvent("LocalStorageGet",48,84,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageGetFalse',0,async function(done){ + emitKey="emitLocalStorageKeys"; + Utils.registerEvent("LocalStorageGetFalse",undefined,86,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageKeys',0,async function(done){ + emitKey="emitPersistPropCover"; + let result = ["PropA"] + Utils.registerEvent("LocalStorageKeys",JSON.stringify(result),88,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('PersistPropCover',0,async function(done){ + emitKey="emitPersistKeys"; + Utils.registerEvent("PersistPropCover",666,90,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('PersistKeys',0,async function(done){ + emitKey="emitPersistPropLasting"; + let persistKeys=["highScore"] + Utils.registerEvent("PersistKeys",JSON.stringify(persistKeys),96,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('PersistPropLasting',0,async function(done){ + emitKey="emitDeleteProp"; + Utils.registerEvent("PersistPropLasting",false,92,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('DeleteProp',0,async function(done){ + emitKey="emitPersistProps"; + let deleteProp=["highScore","Lasting"] + Utils.registerEvent("DeleteProp",JSON.stringify(deleteProp),94,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('PersistProps',0,async function(done){ + emitKey="emitEnvironmentKeys"; + Utils.registerEvent("PersistProps","1",98,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('EnvironmentKeys',0,async function(done){ + emitKey="emitGetShared"; + let environmentKeys = ["aa","bb","cc"] + Utils.registerEvent("EnvironmentKeys",JSON.stringify(environmentKeys),100,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('GetShared',0,async function(done){ + emitKey="emitLocalStoragePropBind"; + Utils.registerEvent("GetShared",undefined,102,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragePropBind',0,async function(done){ + emitKey="emitLocalStoragePropBindTwo"; + Utils.registerEvent("LocalStoragePropBind",88,104,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragePropBindTwo',0,async function(done){ + emitKey="emitLocalStoragePropBindNull"; + Utils.registerEvent("LocalStoragePropBindTwo",100,106,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragePropBindNull',0,async function(done){ + emitKey="emitLocalStorageLinkBind"; + Utils.registerEvent("LocalStoragePropBindNull",1,108,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageLinkBind',0,async function(done){ + emitKey="emitLocalStoragePropCaseNull"; + Utils.registerEvent("LocalStorageLinkBind",1000,110,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragePropCaseNull',0,async function(done){ + emitKey="emitEnvironmentTypeString"; + Utils.registerEvent("LocalStoragePropCaseNull",1,112,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('EnvironmentTypeString',0,async function(done){ + emitKey="emitEnvironmentTypeNum"; + Utils.registerEvent("EnvironmentTypeString",true,114,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('EnvironmentTypeNum',0,async function(done){ + emitKey="emitEnvironmentTypeBoo"; + Utils.registerEvent("EnvironmentTypeNum",true,116,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('EnvironmentTypeBoo',0,async function(done){ + emitKey="emitEnvironmentTypeEnum"; + Utils.registerEvent("EnvironmentTypeBoo",true,118,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('EnvironmentTypeEnum',0,async function(done){ + emitKey="emitLocalStorageLinkType"; + Utils.registerEvent("EnvironmentTypeEnum",true,120,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageLinkType',0,async function(done){ + emitKey="emitLocalStorageLinkTypeTwo"; + Utils.registerEvent("LocalStorageLinkType",true,122,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageLinkTypeTwo',0,async function(done){ + emitKey="emitLocalStoragePropTypeTwo"; + Utils.registerEvent("LocalStorageLinkTypeTwo",true,124,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStoragePropTwo',0,async function(done){ + emitKey="emitLocalStoragePropType"; + let LocalStoragePropTwo=[3,"enen",true,1] + Utils.registerEvent("LocalStoragePropTwo",JSON.stringify(LocalStoragePropTwo),126,done); + sendEventByKey('webcomponenttwo',10,''); + }) + it('LocalStorageLinkTypeTwo',0,async function(done){ + emitKey="emitLocalStoragePropType"; + Utils.registerEvent("LocalStorageLinkTypeTwo",true,128,done); + sendEventByKey('webcomponenttwo',10,''); + }) + + }) +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/ets/test/Utils.ets b/arkui/ace_ets_state_test/entry/src/main/ets/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..1188613cf2a664c4186c9fde8d0138c00ff48e69 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/ets/test/Utils.ets @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2022 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 events_emitter from '@ohos.events.emitter'; +import { expect } from "@ohos/hypium"; +export default class Utils { + static sleep(time){ + return new Promise((resolve,reject)=>{ + setTimeout(()=>{ + resolve("ok") + },time) + }).then(()=>{ + console.info(`sleep ${time} over...`) + }) + } + static registerEvent(testCaseName,expectedValue,eventId,done){ + console.info(`[${testCaseName}] START`); + try{ + let callBack=(backData)=>{ + try{ + console.info(`${testCaseName} get result is:`+JSON.stringify(backData)); + expect(backData.data.ACTION).assertEqual(expectedValue); + console.info(`[${testCaseName}] END`); + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + done() + } + let innerEvent = { + eventId:eventId, + priority:events_emitter.EventPriority.LOW + } + events_emitter.on(innerEvent,callBack) + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + } + static emitEvent(actualValue,eventId){ + try { + let backData = { + data: { + "ACTION": actualValue + } + } + let backEvent = { + eventId:eventId, + priority:events_emitter.EventPriority.LOW + } + console.info("webFlag start to emit action state"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("webFlag emit action state err: " + JSON.stringify(err)); + } + } + static registerEventTwo(testCaseName,eventId,done){ + console.info(`[${testCaseName}] START`); + try{ + let callBack=(backData)=>{ + try{ + console.info(`${testCaseName} get result is:`+JSON.stringify(backData)); + expect(backData.data.actualValue).assertLarger(backData.data.expectedValue-100); + expect(backData.data.actualValue).assertLess(backData.data.expectedValue-(-100)); + console.info(`[${testCaseName}] END`); + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + done() + } + let innerEvent = { + eventId:eventId, + priority:events_emitter.EventPriority.LOW + } + events_emitter.on(innerEvent,callBack) + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + } + static emitEventTwo(expectedValue,actualValue,eventId){ + try { + let backData = { + data: { + "expectedValue":expectedValue, + "actualValue":actualValue + } + } + let backEvent = { + eventId:eventId, + priority:events_emitter.EventPriority.LOW + } + console.info("webFlag start to emit action state"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("webFlag emit action state err: " + JSON.stringify(err)); + } + } + static registerContainEvent(testCaseName,expectedValue,eventId,done){ + console.info(`[${testCaseName}] START`); + try{ + let callBack=(backData)=>{ + try{ + console.info(`${testCaseName} get result is:`+JSON.stringify(backData)); + expect(backData.data.ACTION).assertContain(expectedValue); + console.info(`[${testCaseName}] END`); + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + done() + } + let innerEvent = { + eventId:eventId, + priority:events_emitter.EventPriority.LOW + } + events_emitter.on(innerEvent,callBack) + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + } + static commitKey(emitKey){ + try { + let backData = { + data: { + "ACTION": emitKey + } + } + let backEvent = { + eventId:10, + priority:events_emitter.EventPriority.LOW + } + console.info("start send emitKey"); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info("emit emitKey err: " + JSON.stringify(err)); + } + } + static registerLargerEvent(testCaseName,eventId,done){ + console.info(`[${testCaseName}] START`); + try{ + let callBack=(backData)=>{ + try{ + console.info(`${testCaseName} get result is:`+JSON.stringify(backData)); + expect(backData.data.actualValue).assertLarger(backData.data.expectedValue); + console.info(`[${testCaseName}] END`); + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + done() + } + let innerEvent = { + eventId:eventId, + priority:events_emitter.EventPriority.LOW + } + events_emitter.on(innerEvent,callBack) + }catch(err){ + console.info(`[${testCaseName}] err:`+JSON.stringify(err)); + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/module.json b/arkui/ace_ets_state_test/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..988c1bf8ec01db2c0d6e6b065039889cb768089f --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/module.json @@ -0,0 +1,49 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default", + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "metadata": [ + { + "name": "ArkTSPartialUpdate", + "value": "true" + } + ], + "abilities": [{ + "name": "com.example.myapplication.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + "orientation": "portrait", + "skills": [{ + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + }] + }], + "requestPermissions": [ + { + "name": "ohos.permission.LOCATION" + }, + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/resources/base/element/string.json b/arkui/ace_ets_state_test/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2977b612ec4595b13eaaffe3e8fc578e83c42d48 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsContextTest" + }, + { + "name": "form_description", + "value": "my form" + }, + { + "name": "serviceability_description", + "value": "my whether" + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "app_name", + "value": "Demo" + } + ] +} diff --git a/arkui/ace_ets_state_test/entry/src/main/resources/base/media/icon.png b/arkui/ace_ets_state_test/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/arkui/ace_ets_state_test/entry/src/main/resources/base/media/icon.png differ diff --git a/arkui/ace_ets_state_test/entry/src/main/resources/base/profile/main_pages.json b/arkui/ace_ets_state_test/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..cec91e5a7e8aaf0ebee78f0bcd3f67edc3034c3b --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "MainAbility/pages/state", + "MainAbility/pages/stateTwo" + ] +} \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/1.html b/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/1.html new file mode 100644 index 0000000000000000000000000000000000000000..3e5c3acedcfbe7e8270d28d8c0d05a278cd3edfa --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/1.html @@ -0,0 +1,15 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/icon.png b/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/icon.png differ diff --git a/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/music.html b/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/music.html new file mode 100644 index 0000000000000000000000000000000000000000..205e18ab105423b6af0e6e150f7e1d67ea7f3d03 --- /dev/null +++ b/arkui/ace_ets_state_test/entry/src/main/resources/rawfile/music.html @@ -0,0 +1,10 @@ + + + + + music + + + + + diff --git a/arkui/ace_ets_state_test/signature/openharmony_sx.p7b b/arkui/ace_ets_state_test/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..614195aa50b1370aa8719425a5a6030feee5373c Binary files /dev/null and b/arkui/ace_ets_state_test/signature/openharmony_sx.p7b differ