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 b3146dbf6dadda1114f8df34bd9f860d905f03e9..664b6b9ea43529dffe94328468de421aa822b470 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021~2023 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 @@ -19,12 +19,14 @@ import testsuite from '../../test/List.test'; import Utils from '../../test/Utils'; import web_webview from '@ohos.web.webview'; import fileio from '@ohos.fileio'; +import prompt from '@system.prompt'; let loadedUrl; @Entry @Component struct Index { controller: web_webview.WebviewController = new web_webview.WebviewController(); controllerTwo: web_webview.WebviewController = new web_webview.WebviewController(); + dialogController:CustomDialogController; scheme1: web_webview.WebCustomScheme = {schemeName: "name1", isSupportCORS: true, isSupportFetch: true} scheme2: web_webview.WebCustomScheme = {schemeName: "name2", isSupportCORS: true, isSupportFetch: true} scheme3: web_webview.WebCustomScheme = {schemeName: "name3", isSupportCORS: true, isSupportFetch: true} @@ -594,7 +596,6 @@ struct Index { console.log('onTouchIconUrlReceived:' + JSON.stringify(event)) }) .pinchSmooth(true) - } } } \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/webTwo.ets b/arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/webTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..e0a2a30420e01ba890bba137aab3428a06cde38c --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/webTwo.ets @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2023 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. + */ + +@Extend(Button) function bu(){ + .width('25%') + .type(ButtonType.Capsule) + .backgroundColor(Color.Orange) + .fontSize(8) +} +import router from '@ohos.router'; +import web_webview from '@ohos.web.webview' +import prompt from '@system.prompt' +import Utils from '../../test/Utils' +import events_emitter from '@ohos.events.emitter' + +const phoneUserAgent: string = "Mozilla/5.0 (Linux;Android 9; VRD-AL10; HMSCore 6.3.0.331) AppleWebKit/537.36 (KHTML, like Gecko) CHrome/92.0.4515.105 HuaweuBrowser/12.0.4.1 Mobile Safari/537.36" +const pcUserAgent: 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" + +@CustomDialog +export struct NewWebViewComp { + dialogController: CustomDialogController; + url: string; + @State text: string = '日志在这里显示' + @State javaScriptAccess: boolean = true; + @State multitAccess: boolean = true; + @State fileAccess: boolean = true; + @State onlineImageAccess: boolean = true; + @State domStorageAccess: boolean = true; + @State imageAccess: boolean = true; + @State zoomAccess: boolean = true; + @State geolocationAccess: boolean = true; + @State allowWindow: boolean = true; + private controller: web_webview.WebviewController = new web_webview.WebviewController(); + private dialog : any; + build() { + Column() { + Row({ space: 5 }) { + Web({ src: $rawfile('indexTwo.html'), controller: this.controller }) + .fileAccess(this.fileAccess) + .onlineImageAccess(this.onlineImageAccess) + .domStorageAccess(this.domStorageAccess) + .imageAccess(this.imageAccess) + .zoomAccess(this.zoomAccess) + .geolocationAccess(this.geolocationAccess) + .javaScriptAccess(true) + .databaseAccess(true) + .backgroundColor(Color.Orange) + .onWindowExit(() => { + this.dialogController.close(); + }) + } + } + } +} + +@Entry +@Component +struct indexTwo { + @State gameLeft: string = "console.info('webgame gameLeft'); _main.paddle.moveLeft();" + @State gameRight: string = "console.info('webgame gameRight'); _main.paddle.moveRight();" + @State gameStart: string = "console.info('webgame gameStart'); _main.game.start = _main.game.start_RUNNING; _main.ball.fired = true" + @State gameReset: string = "console.info('webgame gameReset'); if (_main.game.start === _main.game.start_GAMEOVER) { _main.game.start = _main.game.start_START; _main.start()}" + @State removeDesc: string = "console.info('webgame removeDesc'); y=document.getElementsBytagName('div')[0]; y.parentNode.removeChild(y)" + @State setJavaScriptOpenWindowFlagInZoom: boolean = true; + @State setMultiWindowFlag: boolean = true; + @State javaScriptAccess: boolean = true; + @State multitAccess: boolean = true; + controller: web_webview.WebviewController = new web_webview.WebviewController() + dialogController: CustomDialogController = null; + popController: web_webview.WebviewController = null; + @State allowWindow: boolean = true + + @State str:string="emitAllowWindowOpenMethod" + + + build() { + Column() { + Row() { + Button("web click").key('webcomponentTwo').onClick(async ()=>{ + console.info("key==>"+this.str) + switch(this.str){ + case "emitAllowWindowOpenMethod":{ + this.controller.loadUrl($rawfile("indexTwo.html")); + setTimeout(()=>{ + this.controller.runJavaScript('openwindowAll()') + .then(function (result) { + console.log('result: ' + result); + }) + },3000) + break; + } + default: + console.info("can not match case") + } + }) + } + Web({ src: $rawfile('indexTwo.html'), controller: this.controller }) + .javaScriptAccess(true) + .backgroundColor(Color.Orange) + .userAgent(pcUserAgent) + .domStorageAccess(true) + .fileAccess(true) + .onlineImageAccess(true) + .imageAccess(true) + .overviewModeAccess(true) + .zoomAccess(true) + .databaseAccess(true) + .multiWindowAccess(true) + .allowWindowOpenMethod(true) + .onWindowNew((event) => { + Utils.emitEvent("openwindow",110) + console.info("zfh window ts onWindowNew isAlert: " + event.isAlert + ", isUserTrigger: " + event.isUserTrigger + ", targetUrl: " + event.targetUrl); + if (this.dialogController != null) { + console.info("zfh window this.dialogController != null") + this.dialogController.close(); + } + var targetUrlNew: string = event.targetUrl; + + this.popController = new web_webview.WebviewController(); + console.info("zfh window onWindowNew start") + this.dialogController = new CustomDialogController({ + builder: NewWebViewComp({ url: targetUrlNew, controller: this.popController }), + autoCancel: false, + customStyle: true + }); + console.info("zfh window onWindowNew start2") + this.dialogController.open(); + + event.handler.setWebController(this.popController); + console.info("zfh window onWindowNew start3") + + }) + .onWindowExit(() => { + console.info("closewindow") + this.dialogController.close(); + }) + } + } +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/List.test.ets b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/List.test.ets index 079023dd24ba05f62f21dacf79f7077bb41b6e0d..bae210db91d571d0d991383c80ae2cc4ff79fe00 100644 --- a/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/List.test.ets +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/List.test.ets @@ -13,7 +13,8 @@ * limitations under the License. */ import webJsunit from './WebJsunit.test' - +import webTwoJsunit from './WebTwoJsunit.test' export default function testsuite() { webJsunit() + webTwoJsunit() } \ No newline at end of file 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 5ac307f70a38dc6c342502b93829fd58447725ef..8e2dedd1cab3b9fad4a2093bf68baf72f591fab2 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022~2023 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 diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebTwoJsunit.test.ets b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebTwoJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff6c59d9db07ac900fabae6bc55ddafd05cd2d74 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebTwoJsunit.test.ets @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 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. + */ +// @ts-nocheck +import { describe, beforeEach, afterEach, it, expect, beforeAll} from "@ohos/hypium"; +import events_emitter from '@ohos.events.emitter'; +import router from '@system.router'; +import Utils from './Utils.ets'; +let emitKey = "emitAllowWindowOpenMethod"; +export default function webTwoJsunit() { + describe('overviewTest', function () { + beforeAll(async function (done) { + let options = { + uri: 'MainAbility/pages/webTwo', + } + try { + router.clear(); + let pages = router.getState(); + console.info("get webTwo state success " + JSON.stringify(pages)); + if (!("webTwo" == pages.name)) { + console.info("get webTwo state success " + JSON.stringify(pages.name)); + let result = await router.push(options); + await Utils.sleep(2000); + console.info("push webTwo page success " + JSON.stringify(result)); + } + } catch (err) { + console.error("push webTwo page error: " + err); + } + done() + }); + 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_001 + *tc.name AllowWindowOpenMethod + *tc.desic Sets allow the Web access overview mode + */ + it('AllowWindowOpenMethod',0,async function(done){ + emitKey="emitAllowWindowOpenMethod"; + Utils.registerEvent("AllowWindowOpenMethod","openwindow",110,done); + sendEventByKey('webcomponentTwo',10,''); + }) + }) +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/profile/main_pages.json b/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/profile/main_pages.json index accbf272408dce05ff15f78a1adf077bafc62174..49a8c1b20998079991aa83c52a3e6ad576f694f1 100644 --- a/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/profile/main_pages.json +++ b/arkui/ace_ets_web_dev_three/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,6 @@ { "src": [ - "MainAbility/pages/web" + "MainAbility/pages/web", + "MainAbility/pages/webTwo" ] } \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/indexTwo.html b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/indexTwo.html new file mode 100644 index 0000000000000000000000000000000000000000..9cd7637c0983764276fd81d163d0b9fd341d5791 --- /dev/null +++ b/arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/indexTwo.html @@ -0,0 +1,33 @@ + + +
+ +