diff --git a/arkui/ace_ets_web_dev/entry/src/main/ets/MainAbility/pages/web.ets b/arkui/ace_ets_web_dev/entry/src/main/ets/MainAbility/pages/web.ets index 2aaab4a36b71117b15abffc0e209840d4695325f..5e64c69c4f5a043c7afe4c3a4d85daa37b9739dc 100644 --- a/arkui/ace_ets_web_dev/entry/src/main/ets/MainAbility/pages/web.ets +++ b/arkui/ace_ets_web_dev/entry/src/main/ets/MainAbility/pages/web.ets @@ -27,6 +27,16 @@ struct Index { @State loadedResource:string="" @State progress:string="" @State newUrl:string="" + @State pageBegin:string="" + @State pageEnd:string="" + @State console:string="" + @State confirm:string="" + @State alert:string="" + @State errorReceive:string="" + @State httpErrorReceive:number=0 + @State titleReceive:string="" + @State downloadStart:string="" + @State javaScriptAccess:boolean=true onPageShow(){ let valueChangeEvent={ eventId:10, @@ -49,6 +59,10 @@ struct Index { }, toString:(str)=>{ console.info("ets toString:"+String(str)); + }, + register:(res)=>{ + Utils.emitEvent(res,86); + return "web222" } } aboutToAppear(){ @@ -62,6 +76,7 @@ struct Index { build(){ Column(){ Web({src:$rawfile('index.html'),controller:this.controller}) + .javaScriptAccess(this.javaScriptAccess) .userAgent("Mozila/5.0 (Linux; Andriod 9; VRD-AL10; HMSCore 6.3.0.331) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.105 HuaweiBrowser/12.0.4.1 MobileSafari/537.36") .javaScriptProxy({ object:this.jsObj, @@ -93,6 +108,36 @@ struct Index { .onFocus(()=>{ Utils.emitEvent("requestFocus",126) }) + .onPageBegin((event) => { + this.pageBegin = event.url + }) + .onPageEnd((event) => { + this.pageEnd = event.url + }) + .onConsole((event) => { + this.console = event.message.getMessage() + return false + }) + .onAlert((event) => { + this.alert = event.message + return false + }) + .onConfirm((event) => { + this.confirm = event.message + return false + }) + .onErrorReceive((event) => { + this.errorReceive = event.request.getRequestUrl() + }) + .onHttpErrorReceive((event) => { + this.httpErrorReceive = event.response.getResponseCode() + }) + .onTitleReceive((event) => { + this.titleReceive = event.title + }) + .onDownloadStart((event) => { + this.downloadStart = event.url + }) Row(){ Button("web click").key('webcomponent').onClick(()=>{ console.info("key==>"+this.str) @@ -229,6 +274,210 @@ struct Index { },3000) break; } + case "emitOnPageBegin":{ + Utils.emitEvent(this.pageBegin,59) + break; + } + case "emitOnPageEnd":{ + Utils.emitEvent(this.pageBegin,60) + break; + } + case "emitOnConsole":{ + this.controller.runJavaScript({script:"consoleTest()"}) + setTimeout(()=>{ + Utils.emitEvent(this.console,62) + },3000) + break; + } + case "emitOnAlert":{ + this.controller.runJavaScript({script:"alertTest()"}) + setTimeout(()=>{ + Utils.emitEvent(this.alert,63) + },3000) + break; + } + case "emitOnConfirm":{ + this.controller.runJavaScript({script:"confirmTest()"}) + setTimeout(()=>{ + Utils.emitEvent(this.confirm,64) + },3000) + break; + } + case "emitOnErrorReceive":{ + this.controller.loadUrl({url:'http://192.168.5.40:9006/sso_web/html/H5/doctor/aboutUs.html'}) + setTimeout(()=>{ + this.controller.loadUrl({url:'http://192.168.5.40:9006/sso_web/html/H5/doctor/aboutUs.html'}) + setTimeout(() => { + Utils.emitEvent(this.errorReceive,65) + },3000) + },3000) + break; + } + case "emitOnHttpErrorReceive":{ + this.controller.loadUrl({url:'http://example.com/path/does/not/exist/index.jsp'}) + setTimeout(()=>{ + Utils.emitEvent(this.httpErrorReceive,66) + },3000) + break; + } + case "emitOnTitleReceive":{ + this.controller.loadUrl({url:"file:///data/storage/el1/bundle/phone/resources/rawfile/index.html"}) + setTimeout(()=>{ + Utils.emitEvent(this.titleReceive,67) + },3000) + break; + } + case "emitOnDownloadStart":{ + this.controller.loadUrl({url:"https://consumer.huawei.com/content/dam/huawei-cbg-site/cn/mkt/mobileservices/2022/download/PC107f1b3947c942ffaa14334a879065d8.2107261020.exe"}) + setTimeout(()=>{ + Utils.emitEvent(this.downloadStart,68) + },5000) + break; + } + case "emitSetCookie":{ + this.controller.getCookieManager().setCookie('http://www.baidu.com','e=f') + setTimeout(()=>{ + let setCookieCalled = this.controller.getCookieManager().getCookie('http://www.baidu.com') + Utils.emitEvent(setCookieCalled,76) + },3000) + break; + } + case "emitGetCookie":{ + this.controller.getCookieManager().setCookie('https://www.bilibili.com/','e=f') + setTimeout(()=>{ + let getCookieCalled = this.controller.getCookieManager().getCookie('https://www.bilibili.com/') + Utils.emitEvent(getCookieCalled,69) + },3000) + break; + } + case "emitZoom":{ + this.controller.loadUrl({url:"file:///data/storage/el1/bundle/phone/resources/rawfile/index.html"}) + setTimeout(()=>{ + this.controller.zoom(2) + setTimeout(() => { + if(this.controller.getPageHeight() > 1400){ + var zoomCalled = true + } + Utils.emitEvent(zoomCalled,77) + },3000) + },5000) + break; + } + case "emitZoomOut":{ + this.controller.zoomOut() + setTimeout(()=>{ + if(this.controller.getPageHeight() < 1500){ + var zoomOutCalled = true + } + Utils.emitEvent(zoomOutCalled,78) + },3000) + break; + } + case "emitZoomIn":{ + this.controller.zoomIn() + setTimeout(()=>{ + var zoomInCalled = false + if(this.controller.getPageHeight() > 1400){ + zoomInCalled = true + } + Utils.emitEvent(zoomInCalled,79) + },3000) + break; + } + case "emitDeleteEntireCookie":{ + this.controller.getCookieManager().deleteEntireCookie() + setTimeout(()=>{ + let deleteEntireCookieCalled = this.controller.getCookieManager().getCookie('http://www.baidu.com') + Utils.emitEvent(deleteEntireCookieCalled,80) + },3000) + break; + } + case "emitSaveCookieSync":{ + let saveCookieSyncCalled = this.controller.getCookieManager().saveCookieSync() + Utils.emitEvent(saveCookieSyncCalled,81) + break; + } + case "emitClearHistory":{ + this.controller.loadUrl({url:"http://www.baidu.com/"}) + setTimeout(()=>{ + this.controller.clearHistory() + setTimeout(() => { + let clearHistoryCalled = this.controller.accessBackward() + Utils.emitEvent(clearHistoryCalled,82) + },5000) + },10000) + break; + } + case "emitStop":{ + this.controller.loadUrl({url:"http://appgallery.huawei.com/"}) + this.controller.stop() + setTimeout(()=>{ + var stopCalled = false + if(this.pageEnd !== 'http://appgallery.huawei.com/'){ + stopCalled = true + } + Utils.emitEvent(stopCalled,83) + },3000) + break; + } + case "emitOnInactive":{ + this.controller.onInactive() + this.controller.zoomOut() + setTimeout(()=>{ + var onInactiveCalled = false + if(this.controller.getPageHeight() < 2600){ + onInactiveCalled = true + } + Utils.emitEvent(onInactiveCalled,84) + },3000) + break; + } + case "emitOnActive":{ + this.controller.onActive() + this.controller.loadUrl({url:"file:///data/storage/el1/bundle/phone/resources/rawfile/index.html"}) + setTimeout(()=>{ + let onActiveCalled = this.pageBegin + Utils.emitEvent(onActiveCalled,85) + },5000) + break; + } + case "emitRegisterJavaScriptProxy":{ + this.controller.registerJavaScriptProxy({object:this.jsObj,name:"objName",methodList:["test","toString","register"]}) + this.controller.refresh() + setTimeout(()=>{ + this.controller.runJavaScript({script:"proxy()"}) + },3000) + break; + } + case "emitDeleteJavaScriptRegister":{ + this.controller.deleteJavaScriptRegister("objName") + this.controller.runJavaScript({script:"registerTest()"}) + setTimeout(()=>{ + if(this.console !== "web222"){ + let deleteEntireCookieCalled = true + Utils.emitEvent(deleteEntireCookieCalled,87) + } + },3000) + break; + } + case "emitJavaScriptAccess":{ + this.javaScriptAccess = false + setTimeout(() => { + this.controller.runJavaScript({script:"jsAccess()"}) + setTimeout(()=>{ + if(this.console !== "web111"){ + let javaScriptAccessCalled = true + Utils.emitEvent(javaScriptAccessCalled,88) + } + },3000) + },3000) + break; + } + case "emitGetCookieManager":{ + let getCookieManagerCalled = this.controller.getCookieManager().setCookie("https://weibo.com","a=b") + Utils.emitEvent(getCookieManagerCalled,89) + break; + } default: console.info("can not match case") } diff --git a/arkui/ace_ets_web_dev/entry/src/main/ets/test/WebJsunit.test.ets b/arkui/ace_ets_web_dev/entry/src/main/ets/test/WebJsunit.test.ets index 9aba47efef75a44e17f7f8cdc6a2850ef47bc821..4253ed8b13484da7dfdc8745bcff1c89459ba128 100644 --- a/arkui/ace_ets_web_dev/entry/src/main/ets/test/WebJsunit.test.ets +++ b/arkui/ace_ets_web_dev/entry/src/main/ets/test/WebJsunit.test.ets @@ -237,9 +237,249 @@ export default function webJsunit() { *tc.desic Goes forward or back backOrForward in the history of the web page */ it('backOrForward',0,async function(done){ - emitKey="emitBackOrForward"; + emitKey="emitOnPageBegin"; Utils.registerEvent("backOrForward","index",138,done); sendEventByKey('webcomponent',10,''); }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_021 + *tc.name onPageBegin + *tc.desic Triggered when the page loading progress changes + */ + it('onPageBegin',0,async function(done){ + emitKey="emitOnPageEnd"; + Utils.registerEvent("onPageBegin","file:///data/storage/el1/bundle/phone/resources/rawfile/index.html",59,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_022 + *tc.name onPageEnd + *tc.desic Triggered at the begin of web page loading + */ + it('onPageEnd',0,async function(done){ + emitKey="emitOnConsole"; + Utils.registerEvent("onPageEnd","file:///data/storage/el1/bundle/phone/resources/rawfile/index.html",60,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_023 + *tc.name onConsole + *tc.desic Triggered when the web page receives a JavaScript console message + */ + it('onConsole',0,async function(done){ + emitKey="emitOnAlert"; + Utils.registerEvent("onConsole","console test",62,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_024 + *tc.name onAlert + *tc.desic Triggered when the Web wants to display a JavaScript alert() dialog + */ + it('onAlert',0,async function(done){ + emitKey="emitOnConfirm"; + Utils.registerEvent("onAlert","alert test",63,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_025 + *tc.name onConfirm + *tc.desic Triggered when the web page wants to display a JavaScript confirm() dialog + */ + it('onConfirm',0,async function(done){ + emitKey="emitOnErrorReceive"; + Utils.registerEvent("onConfirm","confirm test",64,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_026 + *tc.name onErrorReceive + *tc.desic Triggered when the web page receives a web resource loading error + */ + it('onErrorReceive',0,async function(done){ + emitKey="emitOnHttpErrorReceive"; + Utils.registerEvent("onErrorReceive","http://192.168.5.40:9006/sso_web/html/H5/doctor/aboutUs.html",65,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_027 + *tc.name onHttpErrorReceive + *tc.desic Triggered when the web page receives a web resource loading HTTP error + */ + it('onHttpErrorReceive',0,async function(done){ + emitKey="emitOnTitleReceive"; + Utils.registerEvent("onHttpErrorReceive",404,66,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_028 + *tc.name onTitleReceive + *tc.desic Triggered when the title of the main application document changes + */ + it('onTitleReceive',0,async function(done){ + emitKey="emitOnDownloadStart"; + Utils.registerEvent("onTitleReceive","index",67,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_029 + *tc.name onDownloadStart + *tc.desic Triggered when starting to download + */ + it('onDownloadStart',0,async function(done){ + emitKey="emitSetCookie"; + Utils.registerEvent("onDownloadStart","https://consumer.huawei.com/content/dam/huawei-cbg-site/cn/mkt/mobileservices/2022/download/PC107f1b3947c942ffaa14334a879065d8.2107261020.exe",68,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_030 + *tc.name setCookie + *tc.desic Sets the cookie + */ + it('setCookie',0,async function(done){ + emitKey="emitGetCookie"; + Utils.registerEvent("setCookie","e=f",76,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_031 + *tc.name getCookie + *tc.desic Gets all cookies for the given URL + */ + it('getCookie',0,async function(done){ + emitKey="emitZoom"; + Utils.registerEvent("getCookie","e=f",69,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_032 + *tc.name zoom + *tc.desic Let the Web zoom by + */ + it('zoom',0,async function(done){ + emitKey="emitZoomOut"; + Utils.registerEvent("zoom",true,77,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_033 + *tc.name zoomOut + *tc.desic Let the Web zoom out + */ + it('zoomOut',0,async function(done){ + emitKey="emitZoomIn"; + Utils.registerEvent("zoomOut",true,78,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_034 + *tc.name zoomIn + *tc.desic Let the Web zoom in + */ + it('zoomIn',0,async function(done){ + emitKey="emitDeleteEntireCookie"; + Utils.registerEvent("zoomIn",true,79,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_035 + *tc.name deleteEntireCookie + *tc.desic Delete all cookies + */ + it('deleteEntireCookie',0,async function(done){ + emitKey="emitSaveCookieSync"; + Utils.registerEvent("deleteEntireCookie","",80,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_036 + *tc.name saveCookieSync + *tc.desic Saves the cookies + */ + it('saveCookieSync',0,async function(done){ + emitKey="emitClearHistory"; + Utils.registerEvent("saveCookieSync",true,81,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_037 + *tc.name clearHistory + *tc.desic Clears the history in the Web + */ + it('clearHistory',0,async function(done){ + emitKey="emitStop"; + Utils.registerEvent("clearHistory",false,82,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_038 + *tc.name stop + *tc.desic Stops the current load + */ + it('stop',0,async function(done){ + emitKey="emitOnInactive"; + Utils.registerEvent("stop",true,83,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_039 + *tc.name onInactive + *tc.desic Let the Web inactive. + */ + it('onInactive',0,async function(done){ + emitKey="emitOnActive"; + Utils.registerEvent("onInactive",true,84,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_040 + *tc.name onActive + *tc.desic Let the Web active + */ + it('onActive',0,async function(done){ + emitKey="emitRegisterJavaScriptProxy"; + Utils.registerEvent("onActive","file:///data/storage/el1/bundle/phone/resources/rawfile/index.html",85,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_041 + *tc.name registerJavaScriptProxy + *tc.desic Registers the JavaScript object and method list + */ + it('registerJavaScriptProxy',0,async function(done){ + emitKey="emitDeleteJavaScriptRegister"; + Utils.registerEvent("registerJavaScriptProxy","backToEts",86,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_042 + *tc.name deleteJavaScriptRegister + *tc.desic Deletes a registered JavaScript object with given name + */ + it('deleteJavaScriptRegister',0,async function(done){ + emitKey="emitJavaScriptAccess"; + Utils.registerEvent("deleteJavaScriptRegister",true,87,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_043 + *tc.name javaScriptAccess + *tc.desic Sets whether the Web allows JavaScript scripts to execute + */ + it('javaScriptAccess',0,async function(done){ + emitKey="emitGetCookieManager"; + Utils.registerEvent("javaScriptAccess",true,88,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_044 + *tc.name getCookieManager + *tc.desic Gets network cookie manager + */ + it('getCookieManager',0,async function(done){ + emitKey="emitGetCookieManager"; + Utils.registerEvent("getCookieManager",true,89,done); + sendEventByKey('webcomponent',10,''); + }) }) } diff --git a/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/index.html b/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/index.html index ff3ff3e0194aec48d5d2f234386ce882006b181c..9f24a59018e392b05c5146657f1739f19bbba041 100644 --- a/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/index.html +++ b/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/index.html @@ -29,5 +29,25 @@ let height=document.body.scrollHeight return height } + function proxy(){ + objName.register("backToEts") + } + function registerTest(){ + let str=objName.register(); + console.log(str); + return str + } + function jsAccess(){ + console.log("web111") + } + function consoleTest(){ + console.log("console test") + } + function alertTest(){ + alert('alert test') + } + function confirmTest(){ + confirm("confirm test") + } diff --git a/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/second.html b/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/second.html index 122ec205b7949306b8ad543e5f3cdea342b6e343..3017554b2ab0ca8725fd3acf1711c6d9b6aab02b 100644 --- a/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/second.html +++ b/arkui/ace_ets_web_dev/entry/src/main/resources/rawfile/second.html @@ -7,6 +7,6 @@ second -
second pages
+
second pages
\ No newline at end of file