From 143791dd8920d0ca1bb1a9828f53a31b059fd26f Mon Sep 17 00:00:00 2001 From: bianxinbo Date: Tue, 9 May 2023 10:36:43 +0800 Subject: [PATCH] api setdns getAccessibleGeolocation Signed-off-by: bianxinbo --- .../src/main/ets/MainAbility/pages/web.ets | 42 +++++++++++++++++++ .../src/main/ets/test/WebJsunit.test.ets | 23 +++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) 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 index 664b6b9ea..9c9b2053b 100644 --- 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 @@ -21,6 +21,8 @@ import web_webview from '@ohos.web.webview'; import fileio from '@ohos.fileio'; import prompt from '@system.prompt'; let loadedUrl; + + @Entry @Component struct Index { @@ -37,6 +39,11 @@ struct Index { @State mode: WebDarkMode = WebDarkMode.Off @State mode1: WebDarkMode = WebDarkMode.On @State mode2: WebDarkMode = WebDarkMode.Auto + @State enterPageEnd: boolean = false + + + + ports: web_webview.WebMessagePort[]; testObj = { testOne: (data) => { @@ -551,6 +558,34 @@ struct Index { } break; } + case "emitSetHttpDnsSuccess":{ + try { + web_webview.WebviewController.setHttpDns(web_webview.SecureDnsMode.SecureOnly, "https://httpdns-browser.platform.dbankcloud.cn/dns-query{?dns}") + this.controller.loadUrl("https://www.example.com/"); + this.enterPageEnd=true + } catch(error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } + case "emitGetAccessibleGeolocation":{ + try { + web_webview.GeolocationPermissions.allowGeolocation("file:///") + web_webview.GeolocationPermissions.getAccessibleGeolocation("file:///",(error, result) => { + if (error) { + console.log('getAccessibleGeolocation error: ' + JSON.stringify(error)) + return; + } + if (result) { + console.log('getAccessibleGeolocationAsync result: ' + result); + Utils.emitEvent(result, 451); + } + }); + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + break; + } default: console.info("can not match case") } @@ -584,6 +619,13 @@ struct Index { .onHttpErrorReceive((event) => { event.response.setResponseIsReady(true) }) + .onPageEnd((event) => { + if(this.enterPageEnd){ + Utils.emitEvent(1,446) + this.enterPageEnd=false + } + console.log('url:' + event.url) + }) .darkMode(this.mode) .forceDarkAccess(false) .webSerifFont('serif') 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 index 8e2dedd1c..ff9d26843 100644 --- 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 @@ -406,9 +406,30 @@ export default function webJsunit() { *tc.desic Save current page */ it('GetStoredGeolocation',0,async function(done){ - emitKey="emitGetStoredGeolocation"; + emitKey="emitSetHttpDnsSuccess"; Utils.registerEvent("GetStoredGeolocation","file:///",120,done); sendEventByKey('webcomponent',10,''); }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_037 + *tc.name SetHttpDnsSuccess + *tc.desic Save current page + */ + it('SetHttpDnsSuccess',0,async function(done){ + emitKey="emitGetAccessibleGeolocation"; + Utils.registerEvent("SetHttpDnsSuccess",1,446,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_038 + *tc.name GetAccessibleGeolocation + *tc.desic Save current page + */ + it('GetAccessibleGeolocation',0,async function(done){ + emitKey="emitGetAccessibleGeolocation"; + Utils.registerEvent("GetAccessibleGeolocation",true,451,done); + sendEventByKey('webcomponent',10,''); + }) + }) } -- GitLab