diff --git a/arkui/BUILD.gn b/arkui/BUILD.gn index 32f916b04e97c443ba6ea74cbc61265143fd71bf..989171313812e09307342b203cbc66788a2fdec2 100644 --- a/arkui/BUILD.gn +++ b/arkui/BUILD.gn @@ -28,6 +28,7 @@ group("arkui") { "ace_ets_third_test:ActsAceEtsThirdTest", "ace_ets_web_dev:ActsAceWebDevTest", "ace_ets_web_dev_two:ActsAceWebDevTwoTest", + "ace_ets_web_dev_three:ActsAceWebDevThreeTest", "ace_ets_xcomponent:ActsAceXComponentEtsTest", "ace_js_attribute_api:ActsAceJsApiTest", "ace_napi_test:ActsAceNapiEtsTest", diff --git a/arkui/ace_ets_web_dev_three/AppScope/app.json b/arkui/ace_ets_web_dev_three/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..52fd9651408ad407e3020e35e240170115e1977e --- /dev/null +++ b/arkui/ace_ets_web_dev_three/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.open.harmony.acewebthreetest", + "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": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/AppScope/resources/base/element/string.json b/arkui/ace_ets_web_dev_three/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/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_web_dev_three/AppScope/resources/base/media/app_icon.png b/arkui/ace_ets_web_dev_three/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/arkui/ace_ets_web_dev_three/AppScope/resources/base/media/app_icon.png differ diff --git a/arkui/ace_ets_web_dev_three/BUILD.gn b/arkui/ace_ets_web_dev_three/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..23be4f01df0c3ed1ca3ecd396251f4257ef8ce60 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/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("ActsAceWebDevThreeTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":ace_ets_web_dev_js_assets", + ":ace_ets_web_dev_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsAceWebDevThreeTest" +} + +ohos_app_scope("ace_ets_web_dev_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("ace_ets_web_dev_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("ace_ets_web_dev_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":ace_ets_web_dev_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/arkui/ace_ets_web_dev_three/Test.json b/arkui/ace_ets_web_dev_three/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..bd2f19203a23a4bdc76acf6b1b5135c861e3568b --- /dev/null +++ b/arkui/ace_ets_web_dev_three/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.open.harmony.acewebthreetest", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [{ + "test-file-name": [ + "ActsAceWebDevThreeTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/ets/Application/AbilityStage.ts b/arkui/ace_ets_web_dev_three/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3fdadfebeeeb676df2ce8f78f4b59e26fae9cf0 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,9 @@ +import AbilityStage from "@ohos.application.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_web_dev_three/entry/src/main/ets/MainAbility/MainAbility.ts b/arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..59523bc6f264d3bd1e38c03be90358e12f7f5c28 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,37 @@ +import Ability from '@ohos.application.Ability' + +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/web", 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_web_dev_three/entry/src/main/ets/MainAbility/pages/web.ets b/arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/web.ets new file mode 100644 index 0000000000000000000000000000000000000000..e41915a0b99432f2221babd96c56dca8be415743 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/web.ets @@ -0,0 +1,430 @@ +/* + * 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 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'; + +let loadedUrl; +@Entry +@Component +struct Index { + controller: web_webview.WebviewController = new web_webview.WebviewController(); + controllerTwo: web_webview.WebviewController = new web_webview.WebviewController(); + responseweb: WebResourceResponse = new WebResourceResponse() + @State str:string="emitLoadUrl" + @State text:boolean=false + @State num:number=0 + testObj = { + testOne: (data) => { + Utils.emitEvent(data,13) + return data + }, + toString: () => { + console.log('Web Component toString'); + } + } + + onPageShow(){ + let valueChangeEvent={ + eventId:100, + 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 "emitLoadUrl":{ + try { + setTimeout(()=>{ + this.controller.loadUrl('www.baidu.com'); + setTimeout(()=>{ + let title = this.controller.getTitle(); + Utils.emitEvent(title,1) + },5000) + },3000) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitLoadData":{ + try { + this.controller.loadData( + "
source", + "text/html", + "UTF-8" + ); + setTimeout(()=>{ + let title1 = this.controller.getTitle(); + Utils.emitEvent(title1,2) + },3000) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitBackward":{ + try { + this.controller.backward(); + setTimeout(()=>{ + let title2 = this.controller.getTitle(); + Utils.emitEvent(title2,3) + },3000) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitForward":{ + try { + this.controller.forward(); + setTimeout(()=>{ + let title3 = this.controller.getTitle(); + Utils.emitEvent(title3,4) + },3000) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitAccessBackward":{ + try { + let result0 = this.controller.accessBackward(); + setTimeout(()=>{ + Utils.emitEvent(result0,5) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitAccessForward":{ + try { + let result1 = this.controller.accessForward(); + setTimeout(()=>{ + Utils.emitEvent(result1,6) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitonInactive":{ + try { + this.controller.onInactive(); + setTimeout(()=>{ + setTimeout(()=>{ + this.controller.loadUrl("file:///data/storage/el1/bundle/phone/resources/rawfile/index.html") + },3000) + var title4 = this.controller.getTitle(); + Utils.emitEvent(title4,7) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitonActive":{ + try { + this.controller.onInactive(); + setTimeout(()=>{ + var title5 = this.controller.getTitle(); + Utils.emitEvent(title5,8) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitRefresh":{ + try { + this.controller.refresh(); + setTimeout(()=>{ + var title6 = this.controller.getTitle(); + Utils.emitEvent(title6,9) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitAccessStep":{ + try { + let result2 = this.controller.accessStep(-2); + setTimeout(()=>{ + Utils.emitEvent(result2,10) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitClearHistory":{ + try { + this.controller.clearHistory() + setTimeout(()=>{ + let result3 = this.controller.accessStep(-2); + setTimeout(()=>{ + Utils.emitEvent(result3,11) + },3000) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitGetHitTestValue":{ + try { + let hitValue = this.controller.getHitTestValue(); + console.log("hitType: " + hitValue.type); + console.log("extra: " + hitValue.extra); + Utils.emitEvent("hitValue",12) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitRegisterJavaScriptProxy":{ + try { + this.controller.registerJavaScriptProxy(this.testObj, "objName", ["testOne", "toString"]); + setTimeout(()=>{ + this.controller.refresh() + setTimeout(()=>{ + this.controller.runJavaScript('htmlTest()',(error,result4)=>{ + if (error) { + console.info(`run JavaScript error: ` + JSON.stringify(error)) + return; + } + if (result4) { + console.info('result:' + result4) + } + }) + },3000) + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitDeleteJavaScriptRegister":{ + try { + this.controller.deleteJavaScriptRegister("objName"); + this.controller.deleteJavaScriptRegister("objName"); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,14) + } + break; + } + case "emitZoom":{ + try { + this.controller.zoom(1); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,15) + } + break; + } + case "emitSearchAllAsync":{ + try { + this.controller.loadUrl("file:///data/storage/el1/bundle/phone/resources/rawfile/index.html") + setTimeout(()=>{ + this.controller.searchAllAsync("首页"); + },3000) + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitClearMatches":{ + try { + this.controllerTwo.clearMatches(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,17) + } + break; + } + case "emitSearchNext":{ + try { + this.controllerTwo.searchNext(true); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,18) + } + break; + } + case "emitClearSslCache":{ + try { + this.controllerTwo.clearSslCache(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,19) + } + break; + } + case "emitClearClientAuthenticationCache":{ + try { + this.controllerTwo.clearClientAuthenticationCache(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,20) + } + break; + } + case "emitStop":{ + try { + this.controllerTwo.stop(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,21) + } + break; + } + case "emitRequestFocus":{ + try { + this.controllerTwo.requestFocus(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,22) + } + break; + } + case "emitZoomIn":{ + try { + this.controllerTwo.zoomIn(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,23) + } + break; + } + case "emitZoomOut":{ + try { + this.controllerTwo.zoomOut(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,24) + } + break; + } + case "emitGetWebId":{ + try { + this.controllerTwo.requestFocus(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,25) + } + break; + } + case "emitGetUserAgent":{ + try { + this.controllerTwo.requestFocus(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,26) + } + break; + } + case "emitGetPageHeigth":{ + try { + this.controllerTwo.getPageHeight(); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,27) + } + break; + } + case "emitBackOrForward":{ + try { + this.controllerTwo.backOrForward(-2); + } catch (error) { + console.error(`Errorcode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,28) + } + break; + } + case "emitStoreWebArchive":{ + try { + this.controller.storeWebArchive("/data/storage/el2/base/", true, (error, filename) => { + if (error) { + console.info(`save web archive error: ` + JSON.stringify(error)) + return; + } + if (filename != null) { + Utils.emitEvent(filename,29) + } + }); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitGetUrl":{ + try { + let url = this.controllerTwo.getUrl(); + console.log("url: " + url); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(`${error.code}`,30) + } + break; + } + default: + console.info("can not match case") + } + }) + } + Web({src:"www.example.com",controller:this.controller}) + .webDebuggingAccess(true) + .mediaPlayGestureAccess(true) + .javaScriptAccess(true) + .zoomAccess(this.text) + .onSearchResultReceive(ret=>{ + var searchResult = ret.activeMatchOrdinal.toString() + + ret.numberOfMatches.toString() + console.log("searchResult" + searchResult) + setTimeout(()=>{ + Utils.emitEvent(searchResult,16) + },3000) + }) + + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/arkui/ace_ets_web_dev_three/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..a4ee2f1652b3d04ce83ece64ef70f8dfa62a2dc8 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/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_web_dev_three/entry/src/main/ets/test/List.test.ets b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..079023dd24ba05f62f21dacf79f7077bb41b6e0d --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 webJsunit from './WebJsunit.test' + +export default function testsuite() { + webJsunit() +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/Utils.ets b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..1a90ba6aedd9cd4c5662f10bd0f033f6136cb61a --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/Utils.ets @@ -0,0 +1,135 @@ +/* + * 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)=>{ + console.info(`${testCaseName} get result is:`+JSON.stringify(backData)); + expect(backData.data.ACTION).assertEqual(expectedValue); + console.info(`[${testCaseName}] END`); + 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)=>{ + 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`); + 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)=>{ + console.info(`${testCaseName} get result is:`+JSON.stringify(backData)); + expect(backData.data.ACTION).assertContain(expectedValue); + console.info(`[${testCaseName}] END`); + 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)); + } + } +} diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebJsunit.test.ets b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..84590803c90186935de4d466783720487fe5a37f --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebJsunit.test.ets @@ -0,0 +1,348 @@ +/* + * 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 = "emitLoadUrl"; +export default function webJsunit() { + describe('ActsAceWebDevTest', function () { + beforeEach(async function (done) { + await Utils.sleep(2000); + console.info("web beforeEach start"); + done(); + }) + afterEach(async function (done) { + console.info("web afterEach start:"+emitKey); + try { + let backData = { + data: { + "ACTION": emitKey + } + } + let backEvent = { + eventId:100, + 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 LoadUrl + *tc.desic load contents from url + */ + it('LoadUrl',0,async function(done){ + emitKey="emitLoadData"; + Utils.registerContainEvent("LoadUrl","百度一下,你就知道",1,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_002 + *tc.name LoadData + *tc.desic load contents from data + */ + it('LoadData',0,async function(done){ + emitKey="emitBackward"; + Utils.registerEvent("LoadData","baidu",2,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_003 + *tc.name Backward + *tc.desic back to the old page + */ + it('Backward',0,async function(done){ + emitKey="emitForward"; + Utils.registerEvent("Backward","百度一下,你就知道",3,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_004 + *tc.name Forward + *tc.desic go to the new page + */ + it('Forward',0,async function(done){ + emitKey="emitAccessBackward"; + Utils.registerEvent("Forward","baidu",4,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_005 + *tc.name AccessBackward + *tc.desic return whether there is a old page + */ + it('AccessBackward',0,async function(done){ + emitKey="emitAccessForward"; + Utils.registerEvent("AccessBackward",true,5,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_006 + *tc.name AccessForward + *tc.desic return whether there is a new page + */ + it('AccessForward',0,async function(done){ + emitKey="emitonInactive"; + Utils.registerEvent("AccessForward",false,6,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_007 + *tc.name onInactive + *tc.desic make web component inactive + */ + it('onInactive',0,async function(done){ + emitKey="emitonActive"; + Utils.registerEvent("onInactive","baidu",7,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_008 + *tc.name make web component active + *tc.desic return whether the third party cookie is allowed + */ + it('onActive',0,async function(done){ + emitKey="emitRefresh"; + Utils.registerEvent("onActive","index",8,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_009 + *tc.name Refresh + *tc.desic refresh current page + */ + it('Refresh',0,async function(done){ + emitKey="emitAccessStep"; + Utils.registerEvent("Refresh","index",9,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_010 + *tc.name AccessStep + *tc.desic return whether steps can be operated + */ + it('AccessStep',0,async function(done){ + emitKey="emitClearHistory"; + Utils.registerEvent("AccessStep",true,10,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_011 + *tc.name ClearHistory + *tc.desic clear the browsing history + */ + it('ClearHistory',0,async function(done){ + emitKey="emitGetHitTestValue"; + Utils.registerEvent("ClearHistory",false,11,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_012 + *tc.name GetHitTestValue + *tc.desic get the type of th clicked component + */ + it('GetHitTestValue',0,async function(done){ + emitKey="emitRegisterJavaScriptProxy"; + Utils.registerEvent("GetHitTestValue","hitValue",12,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_013 + *tc.name RegisterJavaScriptProxy + *tc.desic register proxy with a specific name + */ + it('RegisterJavaScriptProxy',0,async function(done){ + emitKey="emitDeleteJavaScriptRegister"; + Utils.registerEvent("RegisterJavaScriptProxy",'Web',13,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_014 + *tc.name DeleteJavaScriptRegister + *tc.desic delet specific proxy + */ + it('DeleteJavaScriptRegister',0,async function(done){ + emitKey="emitZoom"; + Utils.registerEvent("DeleteJavaScriptRegister","17100008",14,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_015 + *tc.name Zoom + *tc.desic zoom the current page + */ + it('Zoom',0,async function(done){ + emitKey="emitSearchAllAsync"; + Utils.registerEvent("Zoom","17100004",15,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_016 + *tc.name SearchAllAsync + *tc.desic zoom the current page + */ + it('SearchAllAsync',0,async function(done){ + emitKey="emitClearMatches"; + Utils.registerEvent("SearchAllAsync","01",16,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_017 + *tc.name ClearMatches + *tc.desic zoom the current page + */ + it('ClearMatches',0,async function(done){ + emitKey="emitSearchNext"; + Utils.registerEvent("ClearMatches","17100001",17,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_018 + *tc.name SearchNext + *tc.desic zoom the current page + */ + it('SearchNext',0,async function(done){ + emitKey="emitClearSslCache"; + Utils.registerEvent("SearchNext","17100001",18,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_019 + *tc.name ClearSslCache + *tc.desic zoom the current page + */ + it('ClearSslCache',0,async function(done){ + emitKey="emitClearClientAuthenticationCache"; + Utils.registerEvent("ClearSslCache","17100001",19,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_020 + *tc.name ClearClientAuthenticationCache + *tc.desic zoom the current page + */ + it('ClearClientAuthenticationCache',0,async function(done){ + emitKey="emitStop"; + Utils.registerEvent("ClearClientAuthenticationCache","17100001",20,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_021 + *tc.name Stop + *tc.desic zoom the current page + */ + it('Stop',0,async function(done){ + emitKey="emitRequestFocus"; + Utils.registerEvent("Stop","17100001",21,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_022 + *tc.name RequestFocus + *tc.desic zoom the current page + */ + it('RequestFocus',0,async function(done){ + emitKey="emitZoomIn"; + Utils.registerEvent("RequestFocus","17100001",22,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_023 + *tc.name ZoomIn + *tc.desic zoom the current page + */ + it('ZoomIn',0,async function(done){ + emitKey="emitZoomOut"; + Utils.registerEvent("ZoomIn","17100001",23,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_024 + *tc.name ZoomOut + *tc.desic zoom the current page + */ + it('ZoomOut',0,async function(done){ + emitKey="emitGetWebId"; + Utils.registerEvent("ZoomOut","17100001",24,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_025 + *tc.name GetWebId + *tc.desic zoom the current page + */ + it('GetWebId',0,async function(done){ + emitKey="emitGetUserAgent"; + Utils.registerEvent("GetWebId","17100001",25,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_026 + *tc.name GetUserAgent + *tc.desic zoom the current page + */ + it('GetUserAgent',0,async function(done){ + emitKey="emitGetPageHeigth"; + Utils.registerEvent("GetUserAgent","17100001",26,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_027 + *tc.name GetPageHeigth + *tc.desic zoom the current page + */ + it('GetPageHeigth',0,async function(done){ + emitKey="emitBackOrForward"; + Utils.registerEvent("GetPageHeigth","17100001",27,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_028 + *tc.name BackOrForward + *tc.desic zoom the current page + */ + it('BackOrForward',0,async function(done){ + emitKey="emitStoreWebArchive"; + Utils.registerEvent("BackOrForward","17100001",28,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_029 + *tc.name StoreWebArchive + *tc.desic Save current page + */ + it('StoreWebArchive',0,async function(done){ + emitKey="emitGetUrl"; + Utils.registerContainEvent("StoreWebArchive","/data/storage/el2/base/",29,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_030 + *tc.name GetUrl + *tc.desic Save current page + */ + it('GetUrl',0,async function(done){ + emitKey="emitGetUrl"; + Utils.registerContainEvent("GetUrl","17100001",30,done); + sendEventByKey('webcomponent',10,''); + }) + }) +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/module.json b/arkui/ace_ets_web_dev_three/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..1caeca096d756373af7eff5cea74a02a2c054cd0 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/module.json @@ -0,0 +1,41 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "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" + } + ] + } +} diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/element/string.json b/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2977b612ec4595b13eaaffe3e8fc578e83c42d48 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/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_web_dev_three/entry/src/main/resources/base/media/icon.png b/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/media/icon.png differ diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/profile/main_pages.json b/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..accbf272408dce05ff15f78a1adf077bafc62174 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/web" + ] +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/extra.html b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/extra.html new file mode 100644 index 0000000000000000000000000000000000000000..cefc3262907470c309ab76c57114eaf91ff95a9f --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/extra.html @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/icon.png b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..474a55588fd7216113dd42073aadf254d4dba023 Binary files /dev/null and b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/icon.png differ diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/index.html b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..b32d947f498f4bdbda9dab7f68edeea052600af6 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,74 @@ + + + + + + +