diff --git a/arkui/ace_ets_web_dev_webviewController/AppScope/app.json b/arkui/ace_ets_web_dev_webviewController/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..11be5a436922e50eedf1060fcfa630f7efaf5e5a --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.open.harmony.acewebtest", + "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_web_dev_webviewController/AppScope/resources/base/element/string.json b/arkui/ace_ets_web_dev_webviewController/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/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_webviewController/AppScope/resources/base/media/app_icon.png b/arkui/ace_ets_web_dev_webviewController/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_webviewController/AppScope/resources/base/media/app_icon.png differ diff --git a/arkui/ace_ets_web_dev_webviewController/BUILD.gn b/arkui/ace_ets_web_dev_webviewController/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..651e413f9fcd05e6305228e92874400027057f39 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/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("ActsAceWebDevWebViewControllerTest") { + 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 = "ActsAceWebDevWebViewControllerTest" +} + +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_webviewController/Test.json b/arkui/ace_ets_web_dev_webviewController/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..6be1473d80bb85b0541b6e5089162a1db776c761 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/Test.json @@ -0,0 +1,26 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.open.harmony.acewebtest", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [{ + "test-file-name": [ + "ActsAceWebDevWebViewControllerTest.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_web_dev_webviewController/entry/src/main/ets/Application/AbilityStage.ts b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0e0206ea9fb5ce94ef140d69510b6280969dd8e --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/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_web_dev_webviewController/entry/src/main/ets/MainAbility/MainAbility.ts b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..b05c3e7489c217a340e452a577694d6856159e81 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/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/webViewController", 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_webviewController/entry/src/main/ets/MainAbility/pages/webViewController.ets b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/MainAbility/pages/webViewController.ets new file mode 100644 index 0000000000000000000000000000000000000000..fcedf3faa568c7aa9e2f07f0f9d42fa5d605510a --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/MainAbility/pages/webViewController.ets @@ -0,0 +1,403 @@ +/** + * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 image from "@ohos.multimedia.image" +let loadedUrl; +@Entry +@Component +struct Index { + controller: web_webview.WebviewController = new web_webview.WebviewController(); + controllerTwo: web_webview.WebviewController = new web_webview.WebviewController(); + controllerThree: web_webview.WebviewController = new web_webview.WebviewController(); + @State str:string="emitGetWebId"; + @State webId:number=0; + @State webId2:number=0; + @State webId3:number=0; + @State webIdTol:number=0; + @State userAgent:string = "Mozilla/5.0 (Window NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)" + + " CHrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27"; + @State userAgent2:string = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)" + + " Chrome/86.0.4240.198 Safari/537.36"; + @State userAgentAll:string = ""; + @State userAgentCheck:string = ""; + @State pageResult:boolean=false; + @State pageResult2:boolean=false; + @State indexUrl:string = "//rawfile/indexCopy.html"; + @State indexUrlTwo:string = "//rawfile/indexTwo.html"; + @State indexUrlAll:string = "//rawfile/indexCopy.html"; + @State pixelmap: image.PixelMap = undefined; + @State javaScriptAccess:boolean=true; + @State fileAccess:boolean=true; + @State domStorageAccess:boolean=false; + @State imageAccess:boolean=true; + @State onlineImageAccess:boolean=true; + @State databaseAccess:boolean=true; + @State checkEleResult: Object = {}; + @State checkEleResultAgain: Object = {}; + @State checkEleResult1: Object = {}; + @State checkEleResult2: Object = {}; + @State checkEleResult3: Object = {}; + 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; + } + } + } + private jsObj={ + test:(res)=>{ + Utils.emitEvent(res,102); + }, + toString:(str)=>{ + console.info("ets toString:"+String(str)); + }, + register:(res)=>{ + Utils.emitEvent(res,86); + return "web222" + } + } + 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 "emitGetWebId": { + try { + this.webId = this.controller.getWebId(); + this.webId2 = this.controllerTwo.getWebId(); + this.webId3 = this.controllerThree.getWebId(); + console.log("id: " + this.webId + this.webId2 + this.webId); + this.webIdTol = this.webId + this.webId2 + this.webId3; + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.webIdTol, 100) + }) + break; + } + case "emitgetUserAgent": { + try { + this.userAgent = this.controller.getUserAgent(); + console.log("userAgent: " + this.userAgent); + this.userAgent2 = this.controllerTwo.getUserAgent(); + console.log("userAgent2: " + this.userAgent2); + this.userAgentAll = this.userAgent + this.userAgent2; + console.log("userAgentAll: " + this.userAgentAll); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.userAgentAll, 102) + }) + break; + } + case "emitgetUserAgentAgain": { + try { + this.userAgentCheck = this.controllerThree.getUserAgent(); + console.log("userAgentCheck: " + this.userAgentCheck); + this.controllerThree.runJavaScript("getUserAgent()",(error, result) => { + this.userAgentCheck = result + console.log(`The controllerThree.getUserAgent() return value is: ${result}`); + }) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.userAgentCheck, 104) + }) + break; + } + case "emitpageDown": { + try { + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResult = JSON.parse(result) + console.log(`The checkVIsible() return value is: ${result}`); + }) + this.controller.pageDown(false); + await Utils.sleep(1000) + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResultAgain = JSON.parse(result) + console.log(`The checkVIsible() again return value is: ${result}`); + if (this.checkEleResult[3] < JSON.parse(result)[3] && JSON.parse(result)[3] < + (JSON.parse(result)[1]/2)) { + this.pageResult = true; + console.log('emitpageDown result is :' + this.pageResult); + }else { + this.pageResult = false; + console.log('emitpageDown result is :' + this.pageResult); + } + }) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.pageResult = false; + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.pageResult, 106) + }) + break; + } + case "emitpageUp": { + try { + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResult = JSON.parse(result) + console.log(`The checkVIsible() return value is: ${result}`); + }) + this.controller.pageUp(false); + await Utils.sleep(1000) + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResultAgain = JSON.parse(result) + console.log(`The checkVIsible() again return value is: ${result}`); + if (JSON.parse(result)[3] == 0 && this.checkEleResult[3] > + (JSON.parse(result)[1]/4)) { + this.pageResult = true; + console.log('emitpageUp result is :' + this.pageResult); + }else { + this.pageResult = false; + console.log('emitpageUp result is :' + this.pageResult); + } + }) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.pageResult = false; + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.pageResult, 108) + }) + break; + } + case "emitpageDownAgain": { + try { + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResult = JSON.parse(result) + console.log(`The checkVIsible() return value is: ${result}`); + }) + this.controller.pageDown(true); + await Utils.sleep(1000) + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResultAgain = JSON.parse(result) + console.log(`The checkVIsible() again return value is: ${result}`); + if ((JSON.parse(result)[1]/2) < JSON.parse(result)[3] && JSON.parse(result)[3] < + JSON.parse(result)[1]) { + this.pageResult = true; + console.log('emitpageDownAgain result is :' + this.pageResult); + }else { + this.pageResult = false; + console.log('emitpageDownAgain result is :' + this.pageResult); + } + }) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.pageResult = false; + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.pageResult, 110) + }) + break; + } + case "emitpageUpAgain": { + try { + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResult = JSON.parse(result) + console.log(`The checkVIsible() return value is: ${result}`); + }) + this.controller.pageUp(true); + await Utils.sleep(1000) + this.controller.runJavaScript("checkVIsible()",(error, result) => { + this.checkEleResultAgain = JSON.parse(result) + console.log(`The checkVIsible() again return value is: ${result}`); + if (JSON.parse(result)[3] == 0 && this.checkEleResult[3] > (JSON.parse(result)[1]/2)) { + this.pageResult = true; + console.log('emitpageUpAgain result is :' + this.pageResult); + }else { + this.pageResult = false; + console.log('emitpageUpAgain result is :' + this.pageResult); + } + }) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.pageResult = false; + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.pageResult, 112) + }) + break; + } + case "emitGetFavicon": { + try { + this.controller.loadUrl($rawfile('indexCopy.html')) + this.pixelmap = this.controller.getFavicon(); + this.pixelmap.getImageInfo().then(imageInfo => { + if (imageInfo == undefined) { + console.error("Failed to obtain the image pixel map information."); + } + console.log("the result of pixelmap: " + JSON.stringify(imageInfo)); + Utils.emitEvent(Object.getOwnPropertyNames(imageInfo).length, 114) + }) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + Utils.emitEvent(this.pixelmap, 114) + } + break; + } + case "emitGetFaviconAgain": { + try { + this.controller.loadUrl($rawfile('secondCopy.html')) + await Utils.sleep(1000) + this.pixelmap = this.controller.getFavicon(); + this.pixelmap.getImageInfo().then(imageInfo => { + if (imageInfo == undefined) { + console.error("Failed to obtain the image pixel map information."); + } + console.log("the result of pixelmap: " + JSON.stringify(imageInfo)); + Utils.emitEvent(Object.getOwnPropertyNames(imageInfo).length, 116) + }) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitGetOriginalUrl": { + try { + this.controller.loadUrl($rawfile('secondCopy.html')) + let indexUrl = this.controller.getOriginalUrl(); + console.log("original url: " + this.indexUrl); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.indexUrl, 118) + }) + break; + } + case "emitGetOriginalUrlTwo": { + try { + this.controller.loadUrl($rawfile('secondCopy.html')) + let indexUrl = this.controller.getOriginalUrl(); + console.log("original url: " + this.indexUrl); + this.controllerTwo.loadUrl($rawfile('secondCopy.html')) + let indexUrlTwo = this.controller.getOriginalUrl(); + console.log("original urlTwo: " + this.indexUrlTwo); + this.indexUrlAll = this.indexUrl + this.indexUrlTwo; + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + this.controller.runJavaScript("test()",(res) => { + Utils.emitEvent(this.indexUrlAll, 120) + }) + break; + } + case "emitSetNetworkAvailable": { + try { + this.controller.loadUrl($rawfile('indexCopy.html')) + this.controller.setNetworkAvailable(false); + await Utils.sleep(3000) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + this.controller.runJavaScript("getNavigatorOnLine()",(error,result) => { + if (error) { + console.info(`run JavaScript error: ` + JSON.stringify(error)) + return; + } + if (result) { + console.log("result:"+result+JSON.stringify(result)) + let pageResult2 = result; + console.log("the status of navigator.onLine: " + this.pageResult2 + result); + } + Utils.emitEvent(this.pageResult2, 122) + }) + break; + } + case "emitSetNetworkAvailableAgain": { + try { + this.controller.loadUrl($rawfile('indexCopy.html')) + this.controller.setNetworkAvailable(true); + await Utils.sleep(3000) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + this.controller.runJavaScript("getNavigatorOnLine()",(error,result) => { + if (error) { + console.info(`run JavaScript error: ` + JSON.stringify(error)) + return; + } + if (result) { + console.log("result:"+result+JSON.stringify(result)) + let pageResult = result; + console.log("the status of navigator.onLine: " + this.pageResult + result); + } + Utils.emitEvent(this.pageResult, 124) + }) + break; + } + } + }) + } + Web({src:$rawfile('indexCopy.html'),controller:this.controller}) + .javaScriptAccess(this.javaScriptAccess) + .fileAccess(this.fileAccess) + .imageAccess(this.imageAccess) + .domStorageAccess(this.domStorageAccess) + .onlineImageAccess(this.onlineImageAccess) + .databaseAccess(this.databaseAccess) + .userAgent(this.userAgent) + + Web({src:$rawfile('indexTwo.html'),controller:this.controllerTwo}).id('2').key('web2') + .javaScriptAccess(this.javaScriptAccess) + .fileAccess(this.fileAccess) + .imageAccess(this.imageAccess) + .domStorageAccess(this.domStorageAccess) + .onlineImageAccess(this.onlineImageAccess) + .databaseAccess(this.databaseAccess) + .userAgent(this.userAgent2) + + Web({src:$rawfile('indexThree.html'),controller:this.controllerThree}).id('3').key('web3') + .javaScriptAccess(this.javaScriptAccess) + .fileAccess(this.fileAccess) + .imageAccess(this.imageAccess) + .domStorageAccess(this.domStorageAccess) + .onlineImageAccess(this.onlineImageAccess) + .databaseAccess(this.databaseAccess) + .userAgent(this.userAgentAll) + .userAgent(this.userAgent) + .userAgent(this.userAgent2) + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..a4ee2f1652b3d04ce83ece64ef70f8dfa62a2dc8 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/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_webviewController/entry/src/main/ets/test/List.test.ets b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3732f69597fd9b427131f1602f14ece7920c2a7f --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 webViewControllerJsunit from './webViewControllerJsunit.test' +export default function testsuite() { + webViewControllerJsunit() +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/test/Utils.ets b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..1188613cf2a664c4186c9fde8d0138c00ff48e69 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/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_web_dev_webviewController/entry/src/main/ets/test/webViewControllerJsunit.test.ets b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/test/webViewControllerJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..937d656fb81b440743116d1a761409bca3db95b7 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/entry/src/main/ets/test/webViewControllerJsunit.test.ets @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2023 iSoftStone Information Technology (Group) Co.,Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeEach, afterEach, it, expect } from "@ohos/hypium"; +import events_emitter from '@ohos.events.emitter'; +import Utils from './Utils.ets'; +let emitKey = "emitGetWebId"; +export default function webViewControllerJsunit() { + describe('ActsAceWebDevWebViewControllerTest', 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: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_0100 + *tc.name testGetWebId + *tc.desc Get the WebId + */ + it('testGetWebId',0,async function(done){ + emitKey="emitgetUserAgent"; + Utils.registerEvent("testGetWebId",6,100,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0200 + *tc.name testGetUserAgent + *tc.desc Get the UserAgent + */ + it('testGetUserAgent',0,async function(done){ + emitKey="emitgetUserAgentAgain"; + let userAgent= "Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.88 Mobile" + + " Safari/537.36Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.88 Mobile Safari/537.36"; + Utils.registerEvent("testGetUserAgent",userAgent,102,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0300 + *tc.name testGetUserAgentAgain + *tc.desc Get the UserAgent again + */ + it('testGetUserAgentAgain',0,async function(done){ + emitKey="emitpageDown"; + let userAgent= "\"Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.88" + + " Mobile Safari/537.36\""; + Utils.registerEvent("testGetUserAgentAgain",userAgent,104,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0400 + *tc.name testPageDown + *tc.desc Go pageDown + */ + it('testPageDown',0,async function(done){ + emitKey="emitpageUp"; + Utils.registerEvent("testPageDown",true,106,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0500 + *tc.name testPageUp + *tc.desc Go pageUp + */ + it('testPageUp',0,async function(done){ + emitKey="emitpageDownAgain"; + Utils.registerEvent("testPageUp",true,108,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0600 + *tc.name testPageDownAgain + *tc.desc Go PageDown Again + */ + it('testPageDownAgain',0,async function(done){ + emitKey="emitpageUpAgain"; + Utils.registerEvent("testPageDownAgain",true,110,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0700 + *tc.name testPageUpAgain + *tc.desc Go PageUp again + */ + it('testPageUpAgain',0,async function(done){ + emitKey="emitGetFavicon"; + Utils.registerEvent("testPageUpAgain",true,112,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0800 + *tc.name testGetFavicon + *tc.desc test for getFavicon + */ + it('testGetFavicon',0,async function(done){ + emitKey="emitGetFaviconAgain"; + Utils.registerEvent("testGetFavicon",undefined,114,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_0900 + *tc.name testGetFaviconAgain + *tc.desc test for getFavicon again + */ + it('testGetFaviconAgain',0,async function(done){ + emitKey="emitGetOriginalUrl"; + Utils.registerEvent("testGetFaviconAgain",5,116,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_1000 + *tc.name testGetOriginalUrl + *tc.desc test for getOriginalUrl + */ + it('testGetOriginalUrl',0,async function(done){ + emitKey="emitGetOriginalUrlTwo"; + let indexUrl = "//rawfile/indexCopy.html"; + Utils.registerEvent("testGetOriginalUrl",indexUrl,118,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_1100 + *tc.name testGetOriginalUrlTwo + *tc.desc test for getOriginalUrl again + */ + it('testGetOriginalUrlTwo',0,async function(done){ + emitKey="emitSetNetworkAvailable"; + let indexUrl = "//rawfile/indexCopy.html//rawfile/indexTwo.html"; + Utils.registerEvent("testGetOriginalUrlTwo",indexUrl,120,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_1100 + *tc.name testSetNetworkAvailable + *tc.desc test for setNetworkAvailable + */ + it('testSetNetworkAvailable',0,async function(done){ + emitKey="emitSetNetworkAvailableAgain"; + Utils.registerEvent("testSetNetworkAvailable",false,122,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_1200 + *tc.name testSetNetworkAvailableAgain + *tc.desc test for setNetworkAvailable again + */ + it('testSetNetworkAvailableAgain',0,async function(done){ + emitKey="emitSetNetworkAvailableAgain"; + Utils.registerEvent("testSetNetworkAvailableAgain",true,124,done); + sendEventByKey('webcomponent',10,''); + }) + }) +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewController/entry/src/main/module.json b/arkui/ace_ets_web_dev_webviewController/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..689268dcc71f30d259eb9eb6ce784b485dc94eb5 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/entry/src/main/module.json @@ -0,0 +1,52 @@ +{ + "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" + }, + { + "name": "ohos.permission.GET_NETWORK_INFO" + } + ] + } +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/base/element/string.json b/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2977b612ec4595b13eaaffe3e8fc578e83c42d48 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/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_webviewController/entry/src/main/resources/base/media/icon.png b/arkui/ace_ets_web_dev_webviewController/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_webviewController/entry/src/main/resources/base/media/icon.png differ diff --git a/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/base/profile/main_pages.json b/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b46de859d15b5cb292fcbf1758cbb4519ab9e29e --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/webViewController" + ] +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/rawfile/databaseAccess.html b/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/rawfile/databaseAccess.html new file mode 100644 index 0000000000000000000000000000000000000000..e63a1944656e6a826aed2e69840959bf7bc221dc --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewController/entry/src/main/resources/rawfile/databaseAccess.html @@ -0,0 +1,26 @@ + + +
+ + + +