diff --git a/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/web.ets b/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/web.ets index 11d6cd8c076898adbb980067442866e24007e233..dfc106410d30b8cbe4974bd5346067ef710047ee 100644 --- a/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/web.ets +++ b/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/web.ets @@ -28,6 +28,7 @@ struct Index { @State outputStr: string = '' @State playing: boolean = false @State str:string="emitOnLoadIntercept" + @State arrid:number = 0 onPageShow(){ let valueChangeEvent={ eventId:10, @@ -62,6 +63,10 @@ struct Index { this.controller.loadUrl("https://www.baidu.com/") break; } + case "emitOnControllerAttached":{ + Utils.emitEvent(this.arrid,7) + break; + } default: console.info("can not match case") @@ -82,6 +87,65 @@ struct Index { console.log('getErrorInfo:' + event.error.getErrorInfo()) Utils.emitEvent(event.error.getErrorInfo(),3) }) + + .onScreenCaptureRequest((event) => { + AlertDialog.show({ + title: 'title: ' + event.handler.getOrigin(), + message: 'text', + primaryButton: { + value: 'deny', + action: () => { + event.handler.deny() + } + }, + secondaryButton: { + value: 'onConfirm', + action: () => { + event.handler.grant({ captureMode: WebCaptureMode.HOME_SCREEN }) + } + }, + cancel: () => { + event.handler.deny() + } + }) + }) + + .onControllerAttached(() => { + try { + this.arrid = this.controller.getWebId(); + console.log("id++++++: " + this.arrid); + + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + }) + + .onOverScroll((event) => { + console.info("x = " + event.xOffset) + console.info("y = " + event.yOffset) + }) + + .onClientAuthenticationRequest((event) => { + AlertDialog.show({ + title: 'onClientAuthenticationRequest', + message: 'text', + primaryButton: { + value: 'confirm', + action: () => { + event.handler.confirm("/system/etc/user.pk8", "/system/etc/chain-user.pem") + } + }, + secondaryButton: { + value: 'cancel', + action: () => { + event.handler.cancel() + } + }, + cancel: () => { + event.handler.ignore() + } + }) + }) } } diff --git a/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/webTwo.ets b/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/webTwo.ets index fcaeebbb1085de929818d35734689d3e825b2bf4..53b233186b0d9cf8b9b1d439316906d000ace5f4 100644 --- a/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/webTwo.ets +++ b/arkui/ace_ets_web_dev_four/entry/src/main/ets/MainAbility/pages/webTwo.ets @@ -1,3 +1,4 @@ + /* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +16,7 @@ import events_emitter from '@ohos.events.emitter'; import Utils from '../../test/Utils'; import web_webview from '@ohos.web.webview'; +import UIAbility from '@ohos.app.ability.UIAbility'; function Uint8ArrayToString(dataArray) { var dataString = '' @@ -40,7 +42,9 @@ function ParseX509CertInfo(x509CertArray) { @Entry @Component struct Second { - @State outputStr: string = '' + @State outputStr: string = '' + @State firsttime:number = 0 + @State arr: Array = [0, 0] webviewCtl: web_webview.WebviewController = new web_webview.WebviewController(); @State str:string="emitGetCertificate" onPageShow(){ @@ -78,13 +82,61 @@ struct Second { } break; } - + + case "emitPrefetchPage": { + try { + this.webviewCtl.removeCache(true) + this.webviewCtl.loadUrl('https://www.huawei.com') + + if (this.arr.length > 2) { + this.webviewCtl.removeCache(true) + } + this.webviewCtl.prefetchPage('https://www.huawei.com'); + this.webviewCtl.loadUrl('https://www.huawei.com') + + setTimeout(()=>{ + if (this.arr.length > 3) { + if (this.arr[3]-this.arr[2] < 0) { + Utils.emitEvent("success",6) + } + } + },2000) + + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + + case "emitPrepareForPageLoad": { + try { + this.webviewCtl.removeCache(true) + this.webviewCtl.loadUrl('https://www.jd.com/') + if (this.arr.length > 4) { + this.webviewCtl.removeCache(true) + } + web_webview.WebviewController.prepareForPageLoad("https://www.jd.com/", true, 6); + this.webviewCtl.loadUrl('https://www.jd.com/') + setTimeout(()=>{ + if (this.arr.length > 5) { + if (this.arr[5]-this.arr[4] < 0) { + Utils.emitEvent("success",8) + } + } + },2000) + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + + default: console.info("can not match case"); } }) } - Web({ src: 'https://www.example.com', controller: this.webviewCtl }) + Web({ src: 'www.baidu.com', controller: this.webviewCtl }) .fileAccess(true) .javaScriptAccess(true) .domStorageAccess(true) @@ -92,6 +144,13 @@ struct Second { .onPageEnd((e) => { this.outputStr = 'onPageEnd : url = ' + e.url }) + .onFirstContentfulPaint(event => { + console.log("onFirstContentfulPaint:" + "[navigationStartTick]:" + + event.navigationStartTick + ", [firstContentfulPaintMs]:" + + event.firstContentfulPaintMs) + this.firsttime = event.firstContentfulPaintMs - event.navigationStartTick/1000 + this.arr.push(this.firsttime) + }) } } } \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebJsunit.test.ets b/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebJsunit.test.ets index e5d0ef216ee18fdae0729691cdece69159e25ec9..d10480975df3552211833c5da372873b9643682b 100644 --- a/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebJsunit.test.ets +++ b/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebJsunit.test.ets @@ -45,14 +45,22 @@ export default function webJsunit() { done(); }) /* - *tc.number SUB_ACE_BASIC_ETS_API_002 + *tc.number SUB_ACE_BASIC_ETS_API_001 *tc.name OnLoadIntercept *tc.desic Injects the JavaScript object into window and invoke the function in window */ it('OnLoadIntercept',0,async function(done){ - emitKey="emitOnLoadIntercept"; + emitKey="emitOnControllerAttached"; Utils.registerEvent("OnLoadIntercept","https://www.baidu.com/",2,done); sendEventByKey('webcomponent',10,''); }) - + /* + *tc.number SUB_ACE_BASIC_ETS_API_002 + *tc.name OnControllerAttached *tc.desic Injects the JavaScript object into window and invoke the function in window + */ + it('OnControllerAttached',0,async function(done){ + emitKey="emitOnControllerAttached"; + Utils.registerEvent("OnControllerAttached",1,7,done); + sendEventByKey('webcomponent',10,''); + }) }) } diff --git a/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebTwoJsunit.test.ets b/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebTwoJsunit.test.ets index de463b54b988766fee9c7c298ac752cc7793b531..a0e627616a61a15e08665999685c48864501457a 100644 --- a/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebTwoJsunit.test.ets +++ b/arkui/ace_ets_web_dev_four/entry/src/main/ets/test/WebTwoJsunit.test.ets @@ -70,9 +70,29 @@ export default function webTwoJsunit() { *tc.desic Sets allow the Web access overview mode */ it('GetCertificate',0,async function(done){ - emitKey="emitOverviewModeAccessFalse"; + emitKey="emitGetCertificate"; Utils.registerEvent("GetCertificate","getCertificate success: len = 0",4,done); sendEventByKey('webcomponenttwo',10,''); }) + ///* + // *tc.number SUB_ACE_BASIC_ETS_API_002 + // *tc.name PrefetchPage + // *tc.desic Sets allow the Web access overview mode + // */ + //it('PrefetchPage',0,async function(done){ + // emitKey="emitPrepareForPageLoad"; + // Utils.registerEvent("PrefetchPage","success",6,done); + // sendEventByKey('webcomponenttwo',10,''); + //}) + ///* + // *tc.number SUB_ACE_BASIC_ETS_API_003 + // *tc.name PrepareForPageLoad + // *tc.desic Sets allow the Web access overview mode + // */ + //it('PrepareForPageLoad',0,async function(done){ + // emitKey="emitPrepareForPageLoad"; + // Utils.registerEvent("PrepareForPageLoad","success",8,done); + // sendEventByKey('webcomponenttwo',10,''); + //}) }) } \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_four/entry/src/main/module.json b/arkui/ace_ets_web_dev_four/entry/src/main/module.json index 0cc1dc2bd069ef62d5e58d99ac603873200ef6f6..988c1bf8ec01db2c0d6e6b065039889cb768089f 100644 --- a/arkui/ace_ets_web_dev_four/entry/src/main/module.json +++ b/arkui/ace_ets_web_dev_four/entry/src/main/module.json @@ -8,42 +8,37 @@ "deviceTypes": [ "tablet", "default", - "phone", - "2in1" + "phone" ], "deliveryWithInstall": true, "installationFree": false, "uiSyntax": "ets", "pages": "$profile:main_pages", "metadata": [ - { - "name": "ArkTSPartialUpdate", - "value": "true" - } + { + "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" - ] - } + "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" }, { diff --git a/arkui/ace_ets_web_dev_four/entry/src/main/resources/rawfile/index.html b/arkui/ace_ets_web_dev_four/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..75a19dfba2dd04404c3abec92b9895407c72d287 --- /dev/null +++ b/arkui/ace_ets_web_dev_four/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,7 @@ + + + + +

Hello World

+ + \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContMessageError.ets b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContMessageError.ets index be205e0eaa60b19325ee8d3ab963ab6f367147dd..12364bcafce9d9d8d53778c690c24531106668fd 100644 --- a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContMessageError.ets +++ b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContMessageError.ets @@ -113,7 +113,6 @@ struct webViewContMessageError { this.ports[1].postMessageEvent("post message from ets to html5"); } catch (error) { console.error(`emitPostMessageEventUnPortErr ErrorCode: ${error.code}, Message: ${error.message}`); - this.errorCode = error.code this.errorMsg = error.message } this.controller.runJavaScript("test()",(res) => { @@ -122,6 +121,7 @@ struct webViewContMessageError { }) break; } + } }) } diff --git a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContPageAndprepareForPageLoadErrorOne.ets b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContPageAndprepareForPageLoadErrorOne.ets new file mode 100644 index 0000000000000000000000000000000000000000..51458637e6393f74d4f5dc3281da59f49d1c6fbd --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContPageAndprepareForPageLoadErrorOne.ets @@ -0,0 +1,92 @@ +/** + * 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 UIAbility from '@ohos.app.ability.UIAbility'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../../test/List.test'; +import Utils from '../../test/Utils'; +import web_webview from '@ohos.web.webview'; + +@Entry +@Component +struct webViewContPageAndprepareForPageLoadErrorOne { + controller20: web_webview.WebviewController = new web_webview.WebviewController(); + ports: web_webview.WebMessagePort[]; + msgPort: web_webview.WebMessagePort[] = null; + @State str:string="emitPrefetchPageErr"; + @State errorCode: string = '0'; + + onPageShow(){ + let valueChangeEvent={ + eventId:10, + priority:events_emitter.EventPriority.LOW + } + events_emitter.on(valueChangeEvent,this.valueChangeCallBack) + } + private valueChangeCallBack=(eventData)=>{ + console.info("webViewContPageAndprepareForPageLoadErrorOne 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("messageEventErrorTest").key('webViewContPageAndprepareForPageLoadErrorOne').onClick(() => { + console.info("key==>" + this.str) + switch (this.str) { + case "emitPrefetchPageErr": { + try { + this.controller20.prefetchPage('百度'); + console.info("---666---444---8888") + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.errorCode = error.code + console.info("789+++987"+this.errorCode) + Utils.emitEvent(this.errorCode, 900) + } + break; + } + } + }) + } + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContPageAndprepareForPageLoadErrorTwo.ets b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContPageAndprepareForPageLoadErrorTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..2bdbdbdcb610568586319abb24a6e12289ac8f0d --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/MainAbility/pages/webViewContPageAndprepareForPageLoadErrorTwo.ets @@ -0,0 +1,130 @@ +/** + * 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 UIAbility from '@ohos.app.ability.UIAbility'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../../test/List.test'; +import Utils from '../../test/Utils'; +import web_webview from '@ohos.web.webview'; + +@Entry +@Component +struct webViewContPageAndprepareForPageLoadErrorTwo { + controller: web_webview.WebviewController = new web_webview.WebviewController(); + ports: web_webview.WebMessagePort[]; + msgPort: web_webview.WebMessagePort[] = null; + @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 zoomAccess:boolean=false; + @State str:string="emitPostMessageInitErr"; + @State errorCode: string = '0'; + + onPageShow(){ + let valueChangeEvent={ + eventId:10, + priority:events_emitter.EventPriority.LOW + } + events_emitter.on(valueChangeEvent,this.valueChangeCallBack) + } + private valueChangeCallBack=(eventData)=>{ + console.info("webViewContPageAndprepareForPageLoadErrorTwo 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("messageEventErrorTest").key('webViewContPageAndprepareForPageLoadErrorTwo').onClick(() => { + console.info("key==>" + this.str) + switch (this.str) { + case "emitPrefetchPageErr": { + try { + this.controller.prefetchPage('华为'); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.errorCode = error.code + console.info("123+++321"+this.errorCode) + Utils.emitEvent(this.errorCode, 903) + } + break; + } + + case "emitPrepareForPageLoadErr": { + try { + web_webview.WebviewController.prepareForPageLoad("华为", true, 6); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.errorCode = error.code + console.info("456+++654"+this.errorCode) + Utils.emitEvent(this.errorCode, 904) + } + break; + } + + case "emitPrepareForPageLoadErrTwo": { + try { + web_webview.WebviewController.prepareForPageLoad("huawei", true, 7); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + this.errorCode = error.code + console.info("4566+++6546"+this.errorCode) + Utils.emitEvent(this.errorCode, 905) + } + break; + } + } + }) + } + Web({src:'www.example.com',controller:this.controller}) + .javaScriptAccess(this.javaScriptAccess) + .fileAccess(this.fileAccess) + .imageAccess(this.imageAccess) + .domStorageAccess(this.domStorageAccess) + .onlineImageAccess(this.onlineImageAccess) + .databaseAccess(this.databaseAccess) + .zoomAccess(this.zoomAccess) + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/List.test.ets b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/List.test.ets index 6ef340e2ead4ef00f4868a758ac2dc9b054c818c..1644672a1774da1e13622e4d2d026c3711f293c8 100644 --- a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/List.test.ets +++ b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/List.test.ets @@ -21,6 +21,8 @@ import webViewContGetUrlAndOthersError from './webViewContGetUrlAndOthersError.t import webViewContCookieToGeoLocationError from './webViewContCookieToGeoLocationError.test' import webViewContJsMessageExtReturnError from './webViewContJsMessageExtReturnError.test' import webViewContWebMessageExtReturnError from './webViewContWebMessageExtReturnError.test' +import webViewContPageAndprepareForPageLoadErrorOne from './webViewContPageAndprepareForPageLoadErrorOne.test' +import webViewContPageAndprepareForPageLoadErrorTwo from './webViewContPageAndprepareForPageLoadErrorTwo.test' export default function testsuite() { webViewContMessageError() @@ -32,4 +34,7 @@ export default function testsuite() { webViewContCookieToGeoLocationError() webViewContJsMessageExtReturnError() webViewContWebMessageExtReturnError() + //webViewContPageAndprepareForPageLoadErrorOne() + //webViewContPageAndprepareForPageLoadErrorTwo() + } \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/webViewContPageAndprepareForPageLoadErrorOne.test.ets b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/webViewContPageAndprepareForPageLoadErrorOne.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4453c4383a4dd085de38d4396cc1df526141c3d1 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/webViewContPageAndprepareForPageLoadErrorOne.test.ets @@ -0,0 +1,78 @@ +/** + * 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, beforeAll} from "@ohos/hypium"; +import events_emitter from '@ohos.events.emitter'; +import Utils from './Utils.ets'; +import router from '@system.router'; + +let emitKey = "emitPrefetchPageErr"; +export default function webViewContPageAndprepareForPageLoadErrorOne() { + describe('ActsAceWebDevWebViewContPageAndPrepareForPageLoadErrorOneTest', function () { + beforeAll(async function (done) { + let options = { + uri: 'MainAbility/pages/webViewContPageAndprepareForPageLoadErrorOne', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get webViewContPageAndprepareForPageLoadErrorOne state success " + JSON.stringify(pages)); + if (!("webViewContPageAndprepareForPageLoadErrorOne" == pages.name)) { + console.info("get webViewContPageAndprepareForPageLoadErrorOne state success " + JSON.stringify(pages.name)); + let result = await router.push(options); + await Utils.sleep(2000); + console.info("push webViewContPageAndprepareForPageLoadErrorOne page success " + JSON.stringify(result)); + } + } catch (err) { + console.error("push webViewContPageAndprepareForPageLoadErrorOne page error: " + err); + } + done() + }); + beforeEach(async function (done) { + await Utils.sleep(2000); + console.info("webViewContPageAndprepareForPageLoadErrorOne beforeEach start"); + done(); + }) + afterEach(async function (done) { + console.info("webViewContPageAndprepareForPageLoadErrorOne 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_WEBVIEWERROR_0100 + *tc.name testPostMessageInitErr + *tc.desc test interface of postMessage with not been associated with specific Web Components + */ + it('PrefetchPageErr',0,async function(done){ + emitKey="emitPrepareForPageLoadErr"; + Utils.registerEvent("PrefetchPageErr","17100001",900,done); + sendEventByKey('webViewContPageAndprepareForPageLoadErrorOne',10,''); + }) + }) +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/webViewContPageAndprepareForPageLoadErrorTwo.test.ets b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/webViewContPageAndprepareForPageLoadErrorTwo.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..235b7801dae160cc254e910cf808735e6423f1c8 --- /dev/null +++ b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/ets/test/webViewContPageAndprepareForPageLoadErrorTwo.test.ets @@ -0,0 +1,98 @@ +/** + * 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, beforeAll} from "@ohos/hypium"; +import events_emitter from '@ohos.events.emitter'; +import Utils from './Utils.ets'; +import router from '@system.router'; + +let emitKey = "emitPrefetchPageErr"; +export default function webViewContPageAndprepareForPageLoadErrorTwo() { + describe('ActsAceWebDevWebViewContPageAndPrepareForPageLoadErrorTwoTest', function () { + beforeAll(async function (done) { + let options = { + uri: 'MainAbility/pages/webViewContPageAndprepareForPageLoadErrorTwo', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get webViewContPageAndprepareForPageLoadErrorTwo state success " + JSON.stringify(pages)); + if (!("webViewContPageAndprepareForPageLoadErrorTwo" == pages.name)) { + console.info("get webViewContPageAndprepareForPageLoadErrorTwo state success " + JSON.stringify(pages.name)); + let result = await router.push(options); + await Utils.sleep(2000); + console.info("push webViewContPageAndprepareForPageLoadErrorTwo page success " + JSON.stringify(result)); + } + } catch (err) { + console.error("push webViewContPageAndprepareForPageLoadErrorTwo page error: " + err); + } + done() + }); + beforeEach(async function (done) { + await Utils.sleep(2000); + console.info("webViewContPageAndprepareForPageLoadErrorTwo beforeEach start"); + done(); + }) + afterEach(async function (done) { + console.info("webViewContPageAndprepareForPageLoadErrorTwo 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_WEBVIEWERROR_0100 + *tc.name testPostMessageInitErr + *tc.desc test interface of postMessage with not been associated with specific Web Components + */ + it('PrefetchPageErr',0,async function(done){ + emitKey="emitPrepareForPageLoadErr"; + Utils.registerEvent("PrefetchPageErr","17100002",903,done); + sendEventByKey('webViewContPageAndprepareForPageLoadErrorTwo',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_WEBVIEWERROR_0200 + *tc.name testPostMessageEventPortClose + *tc.desc test interface of postMessageEvent with WebMessagePort been closed by ets + */ + it('PrepareForPageLoadErr',0,async function(done){ + emitKey="emitPrepareForPageLoadErrTwo"; + Utils.registerEvent("PrepareForPageLoadErr","17100002",904,done); + sendEventByKey('webViewContPageAndprepareForPageLoadErrorTwo',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_WEBVIEWERROR_0200 + *tc.name testPostMessageEventPortClose + *tc.desc test interface of postMessageEvent with WebMessagePort been closed by ets + */ + it('PrepareForPageLoadErrTwo',0,async function(done){ + emitKey="emitPrepareForPageLoadErrTwo"; + Utils.registerEvent("PrepareForPageLoadErrTwo","171000013",905,done); + sendEventByKey('webViewContPageAndprepareForPageLoadErrorTwo',10,''); + }) + }) +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/module.json b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/module.json index 0cc1dc2bd069ef62d5e58d99ac603873200ef6f6..0729db882db60f8b8798a190efe02dbd546c03b4 100644 --- a/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/module.json +++ b/arkui/ace_ets_web_dev_webviewControllerError/entry/src/main/module.json @@ -8,8 +8,7 @@ "deviceTypes": [ "tablet", "default", - "phone", - "2in1" + "phone" ], "deliveryWithInstall": true, "installationFree": false, @@ -17,33 +16,29 @@ "pages": "$profile:main_pages", "metadata": [ { - "name": "ArkTSPartialUpdate", - "value": "true" + "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" - ] - } + ], + "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" }, {