From 6b494082f63e8b4eb0cda6bc3ded934530a44846 Mon Sep 17 00:00:00 2001 From: ywx1211260 Date: Mon, 16 Jan 2023 19:46:30 +0800 Subject: [PATCH] increase_file Signed-off-by: ywx1211260 --- .../main/ets/MainAbility/pages/webCovered.ets | 73 ++++++++++++++ .../test/WebViewCoveredJsunit.test.ets | 94 +++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 arkui/ace_ets_webView/entry/src/main/ets/MainAbility/pages/webCovered.ets create mode 100644 arkui/ace_ets_webView/entry/src/main/ets/MainAbility/test/WebViewCoveredJsunit.test.ets diff --git a/arkui/ace_ets_webView/entry/src/main/ets/MainAbility/pages/webCovered.ets b/arkui/ace_ets_webView/entry/src/main/ets/MainAbility/pages/webCovered.ets new file mode 100644 index 000000000..fa1fea184 --- /dev/null +++ b/arkui/ace_ets_webView/entry/src/main/ets/MainAbility/pages/webCovered.ets @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 web_webview from '@ohos.web.webview'; +import image from "@ohos.multimedia.image" + +@Entry +@Component +struct WebComponent { + controller: web_webview.WebviewController = new web_webview.WebviewController(); + @State icon: image.PixelMap = undefined; + @State family: string = "serif"; + @State fontSize: number = 13; + + build() { + Column() { + Button('getBackForwardEntries').key("webCovered01") + .onClick(() => { + try { + let list = this.controller.getBackForwardEntries(); + let historyItem = list.getItemAtIndex(list.currentIndex); + console.log("HistoryItem: " + JSON.stringify(historyItem)); + this.icon = historyItem.icon; + } catch (error) { + console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); + } + }) + try { + let backData = { + data: { + "ACTION": this.icon + } + } + let backEvent = { + eventId:01, + 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)); + } + } + Web({ src: 'www.example.com', controller: this.controller }).key("webCovered02") + .webSerifFont(this.family) + .webSansSerifFont(this.family) + .minLogicalFontSize(this.fontSize) + .onTouchIconUrlReceived((event) => { + console.log('onTouchIconUrlReceived:' + JSON.stringify(event)) + }) + + Divider().width("3%") + + Web({ src: 'www.example.com', controller: this.controller }).key("webCovered03") + .onDataResubmitted((event) => { + console.log('onDataResubmitted') + event.handler.resend(); + }) + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_webView/entry/src/main/ets/MainAbility/test/WebViewCoveredJsunit.test.ets b/arkui/ace_ets_webView/entry/src/main/ets/MainAbility/test/WebViewCoveredJsunit.test.ets new file mode 100644 index 000000000..82a93d4e3 --- /dev/null +++ b/arkui/ace_ets_webView/entry/src/main/ets/MainAbility/test/WebViewCoveredJsunit.test.ets @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets" +import router from '@system.router'; + +export default function webViewCoveredJsunit() { + function sleep(time) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, time * 1000) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + describe('WebViewCoveredTest', function () { + beforeEach(async function (done) { + console.info("WebViewCoveredTest beforeEach start"); + let options = { + uri: 'pages/webCovered', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get WebViewCovered state success " + JSON.stringify(pages)); + if (!("WebViewCovered" == pages.name)) { + console.info("get WebViewCovered state success " + JSON.stringify(pages.name)); + let result = await router.push(options) + console.info("push WebViewCovered page success " + JSON.stringify(result)); + } + } catch (err) { + console.error("push WebViewCovered page error " + JSON.stringify(result)); + } + await sleep(4) + done() + }); + + afterEach(async function () { + await sleep(1) + console.info("WebViewCovered after each called"); + }); + + + + it('WebViewCoveredJsunit_01', 0, async function (done) { + console.info('[WebViewCoveredJsunit01] START'); + try{ + let callBack=(backData)=>{ + console.info('WebViewCoveredJsunit01 get result is:'+JSON.stringify(backData)); + expect(backData.data.ACTION).assertEqual(historyItem.icon); + console.info('[WebViewCoveredJsunit01] END'); + done() + } + let innerEvent = { + eventId:01, + priority:events_emitter.EventPriority.LOW + } + events_emitter.on(innerEvent,callBack) + }catch(err){ + console.info('[WebViewCoveredJsunit01] err:'+JSON.stringify(err)); + } + } + sendEventByKey('webCovered01',10,''); + done(); + }); + + it('WebViewCoveredJsunit_02', 0, async function (done) { + console.info('[WebViewCoveredJsunit02] START'); + await Utils.sleep(1000); + let strJson = getInspectorByKey('webCovered02'); + let obj = JSON.parse(strJson); + console.info("[WebViewCoveredJsunit02] component obj is: " + JSON.stringify(obj)); + expect(obj.$attrs.webSerifFont).assertEqual("serif"); + expect(obj.$attrs.webSansSerifFont).assertEqual("serif"); + expect(obj.$attrs.minLogicalFontSize).assertEqual(13); + done(); + }); + }) +} + -- GitLab