diff --git a/ArkWeb/ProcessWebPageCont/.gitignore b/ArkWeb/ProcessWebPageCont/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/AppScope/app.json5 b/ArkWeb/ProcessWebPageCont/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4b1ce53f111420364c0803811493cd969dc80603 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.samples.processwebpagecont", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/ProcessWebPageCont/AppScope/resources/base/element/string.json b/ArkWeb/ProcessWebPageCont/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4779102effef55e6d1414c9166b60b0783cdc210 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ProcessWebPageCont" + } + ] +} diff --git a/ArkWeb/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png b/ArkWeb/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/ProcessWebPageCont/README.md b/ArkWeb/ProcessWebPageCont/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6b2dd9e180656b48df3158145018f040da9db4ee --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/README.md @@ -0,0 +1,135 @@ +## 使用Web组件打印前端页面 + +### 介绍 + +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-print.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### InitiatePrintW3CAPI + +#### 介绍 + +1. 本示例主要介绍使用Web组件打印前端页面,通过创建打印适配器,拉起打印应用,并对当前Web页面内容进行渲染,渲染后生成的PDF文件信息通过fd传递给打印框架。W3C标准协议接口window.print()方法用于打印当前页面或弹出打印对话框。该方法没有任何参数,只需要在JavaScript中调用即可。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击print按钮,触发window.print()操作,即可对页面内容进行打印。 + +### InitiatePrintAppAPI + +#### 介绍 + +1. 本示例主要介绍使用Web组件打印前端页面,应用侧通过调用createWebPrintDocumentAdapter创建打印适配器,通过将适配器传入打印的print接口调起打印。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击createWebPrintDocumentAdapter按钮应用侧会创建打印适配器,并将其传入打印接口,以触发打印操作。 + +## 使用Web组件的PDF文档预览能力 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-pdf-preview.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### PreviewPDF + +#### 介绍 + +1. 本示例主要介绍使用Web组件的PDF文档预览能力。Web组件提供了在网页中预览PDF的能力。应用可以通过Web组件的src参数和loadUrl()接口中传入PDF文件,来加载PDF文档。根据PDF文档来源不同,可以分为三种常用场景:加载网络PDF文档、加载本地PDF文档、加载应用内resource资源PDF文档。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------- | +| | + +使用说明 + +1. Web组件创建时指定默认加载的网络PDF文档example.com/test.pdf。 + +## 网页中安全区域计算和避让适配 + +### 介绍 + +### CalcAdjustSafeArea + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-safe-area-insets.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### 介绍 + +1. 本示例主要介绍网页中安全区域计算和避让适配。Web组件提供了利用W3C CSS进行安全区域计算并避让适配的能力,用来支持异形屏幕设备在沉浸式效果下页面的正常显示。此时,网页开发者想对重叠元素进行避让,就可以该能力。ArkWeb内核将持续监测Web组件及系统安全区域的位置与尺寸,依据两者的重叠部分,计算出当前Web组件的安全区域,以及在各个方向上所需避让的具体距离。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 通过expandSafeArea来开启沉浸式效果。Web组件根据实际情况对网页元素进行相应的避让,防止与系统的非安全区域发生重叠遮挡。 + +## 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---InitiatePrintAppAPI +|---|---|---InitiatePrintW3CAPI +|---|---|---PreviewPDF +|---|---|---CalcAdjustSafeArea +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +## 相关权限 + +[ohos.permission.PRINT](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionprint) + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/ProcessWebPageCont > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` + diff --git a/ArkWeb/ProcessWebPageCont/build-profile.json5 b/ArkWeb/ProcessWebPageCont/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/build-profile.json5 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/code-linter.json5 b/ArkWeb/ProcessWebPageCont/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/.gitignore b/ArkWeb/ProcessWebPageCont/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/build-profile.json5 b/ArkWeb/ProcessWebPageCont/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/hvigorfile.ts b/ArkWeb/ProcessWebPageCont/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2025 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. +*/ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ProcessWebPageCont/entry/obfuscation-rules.txt b/ArkWeb/ProcessWebPageCont/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/oh-package.json5 b/ArkWeb/ProcessWebPageCont/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..82e98bec44d83d2df03deb52508045cb06cc8604 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..29feaca7669174be5c2b0e2366529ee94ab7e726 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets new file mode 100644 index 0000000000000000000000000000000000000000..a357e5996f55843b6b23feb7dae4b176cba2b0e6 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ +// [Start use_expand_safe_area_to_enable_immersive_effect] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'www.example.com', controller: this.controller }) + .width('100%').height('100%') + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) + } + } +} +// [End use_expand_safe_area_to_enable_immersive_effect] diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1def271b5633e957e9dd40c3b9591542f5cae01f --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('InitiatePrintW3CAPI') + .onClick(() => { + router.pushUrl({ url: 'pages/InitiatePrintW3CAPI' }); + }) + Button('InitiatePrintAppAPI') + .onClick(() => { + router.pushUrl({ url: 'pages/InitiatePrintAppAPI' }); + }) + Button('PreviewPDF') + .onClick(() => { + router.pushUrl({ url: 'pages/PreviewPDF' }); + }) + Button('CalcAdjustSafeArea') + .onClick(() => { + router.pushUrl({ url: 'pages/CalcAdjustSafeArea' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets new file mode 100644 index 0000000000000000000000000000000000000000..30eecf7173f0c347787a368ec2b185ff925d4e3d --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start create_web_print_document] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { print } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('createWebPrintDocumentAdapter') + .onClick(() => { + try { + let webPrintDocadapter = this.controller.createWebPrintDocumentAdapter('example.pdf'); + print.print('example_jobid', webPrintDocadapter, null, getContext()); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }); + } + } +} +// [End create_web_print_document] diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d1281e593d6ba6c272dcd97a49da7cc006a16c2 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start w3c_print_html] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct Index { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Row() { + Column() { + Web({ src: $rawfile('print.html'), controller: this.controller }) + .javaScriptAccess(true) + } + .width('100%') + } + .height('100%') + } +} +// [End w3c_print_html] diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets new file mode 100644 index 0000000000000000000000000000000000000000..dad0b0ca9293ff918383646cded1535936ae35c1 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start web_module_create_load_pdf] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ + src: + $r('app.string.web_path'), // 方式一 加载网络PDF文档 + // getContext(this).filesDir + '/test.pdf', // 方式二 加载本地应用沙箱内PDF文档 + // 'resource://rawfile/test.pdf', // 方式三 应用内resource资源PDF文档 + // $rawfile('test.pdf'), // 方式四 应用内resource资源PDF文档 + controller: this.controller + }) + .domStorageAccess(true) + } + } +} +// [End web_module_create_load_pdf] diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 b/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70729d262d8e46da160838ad06ca01e2f48b6f46 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + // [Start web_module_print_html] + // [Start web_module_preview_pdf] + "requestPermissions":[ + // [StartExclude web_module_preview_pdf] + { + "name" : "ohos.permission.PRINT" + }, + // EndExclude web_module_preview_pdf] + // [StartExclude web_module_print_html] + { + "name" : "ohos.permission.INTERNET" + } + // [EndExclude web_module_print_html] + ], + // [End web_module_preview_pdf] + // [End web_module_print_html] + } +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/color.json b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/string.json b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1f758cd41cf67e4c769d7526ee83f962d0d865c6 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ProcessWebPageCont" + }, + { + "name": "web_path", + "value": "https://www.example.com/test.pdf" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/background.png b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..ead1e2c5ae06ebd7246b0a4028b9899b3de9574a --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/InitiatePrintW3CAPI", + "pages/InitiatePrintAppAPI", + "pages/PreviewPDF", + "pages/CalcAdjustSafeArea" + ] +} diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/en_US/element/string.json b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..448a2a5210af13626ae587985d80eb8c51800e4d --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ProcessWebPageCont" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html new file mode 100644 index 0000000000000000000000000000000000000000..7225f16ebc840f16091bc9e7c75380f4c1104470 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html @@ -0,0 +1,63 @@ + + + + + + + + printTest + + + + +
+

+
This is a test page for printing
+
+
+

+ +

content content content

+
+ + + + + + + + + + + + + + + + + +
ThingChairs
1blue
2green
+
+

content content content

+

content content content

+
+ diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f9dac5633ffc24eea33331035efbdbaffceb0031 Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf differ diff --git a/ArkWeb/ProcessWebPageCont/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..88de2d38c7e3b4d9017b102162dee18ed9bc4794 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ProcessWebPageCont" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/mock/mock-config.json5 b/ArkWeb/ProcessWebPageCont/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..328b7bb43ddfe2b41224a082e95263ec212bc34e --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 InitiatePrintW3CAPI 按钮 + * 触发 window.print 操作对页面内容进行打印 + */ + it('InitiatePrintW3CAPI', 0, async (done: Function) => { + console.info('uitest: InitiatePrintW3CAPI begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(3000); + + const button1 = await driver.findComponent(ON.text('InitiatePrintW3CAPI')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('button')); + await button2.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('print.html'); + + await driver.pressBack(); + console.info('uitest: InitiatePrintW3CAPI end'); + done(); + }); + + /* + * 点击 InitiatePrintAppAPI 按钮 + * 创建打印适配器,将适配器传入打印的print接口调起打印 + */ + it('InitiatePrintAppAPI', 0, async (done: Function) => { + console.info('uitest: InitiatePrintAppAPI begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('InitiatePrintAppAPI')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: InitiatePrintAppAPI end'); + done(); + }); + + /* + * 点击 PreviewPDF 按钮 + * 使用Web组件的PDF文档预览能力加载PDF文档 + */ + it('PreviewPDF', 0, async (done: Function) => { + console.info('uitest: PreviewPDF begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PreviewPDF')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com/test.pdf'); + + await driver.pressBack(); + console.info('uitest: PreviewPDF end'); + done(); + }); + + /* + * 点击 CalcAdjustSafeArea 按钮 + * 进行安全区域计算并避让适配支持异形屏幕设备在沉浸式效果下页面的正常显示 + */ + it('CalcAdjustSafeArea', 0, async (done: Function) => { + console.info('uitest: CalcAdjustSafeArea begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('CalcAdjustSafeArea')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: CalcAdjustSafeArea end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/module.json5 b/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/ProcessWebPageCont/entry/src/test/List.test.ets b/ArkWeb/ProcessWebPageCont/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/entry/src/test/LocalUnit.test.ets b/ArkWeb/ProcessWebPageCont/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/ProcessWebPageCont/hvigor/hvigor-config.json5 b/ArkWeb/ProcessWebPageCont/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/ProcessWebPageCont/hvigorfile.ts b/ArkWeb/ProcessWebPageCont/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2025 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. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/ProcessWebPageCont/oh-package.json5 b/ArkWeb/ProcessWebPageCont/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/ProcessWebPageCont/ohosTest.md b/ArkWeb/ProcessWebPageCont/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..a93a5b8216aaab3fa52497aba5b07499e2460066 --- /dev/null +++ b/ArkWeb/ProcessWebPageCont/ohosTest.md @@ -0,0 +1,24 @@ +#### InitiatePrintW3CAPI + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------- | ------------ | --------------------------- | ---------------------- | -------- | -------- | +| 使用Web组件打印前端页面 | 设备运转正常 | 应用启动成功,点击print按钮 | 触发window.print()操作 | Yes | Pass | + +#### InitiatePrintAppAPI + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------- | ------------ | --------------------------------------------------- | ------------ | -------- | -------- | +| 使用Web组件打印前端页面 | 设备运转正常 | 应用启动成功,点击createWebPrintDocumentAdapter按钮 | 触发打印操作 | Yes | Pass | + +#### PreviewPDF + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------- | ------------ | ------------ | -------------------------------------- | -------- | -------- | +| 使用Web组件的PDF文档预览能力 | 设备运转正常 | 应用启动成功 | Web组件创建时指定默认加载的网络PDF文档 | Yes | Pass | + +#### CalcAdjustSafeArea + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------- | ---------------------------- | ------------ | ------------------------------------------- | -------- | -------- | +| 网页中安全区域计算和避让适配 | 设备运转正常,开启沉浸式效果 | 应用启动成功 | Web组件根据实际情况对网页元素进行相应的避让 | Yes | Pass | + diff --git a/ArkWeb/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png b/ArkWeb/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png new file mode 100644 index 0000000000000000000000000000000000000000..bacf76e4cca730d6869a641b88c9ab43a1c654c6 Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png differ diff --git a/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png b/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png new file mode 100644 index 0000000000000000000000000000000000000000..f3e5eb8f67cca636ea0608cd5af117cc0e8f6542 Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png differ diff --git a/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png b/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png new file mode 100644 index 0000000000000000000000000000000000000000..6e8241f75e8b4701ee18405f97b5b9f7e65efa87 Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png differ diff --git a/ArkWeb/ProcessWebPageCont/screenshots/PreviewPDF.png b/ArkWeb/ProcessWebPageCont/screenshots/PreviewPDF.png new file mode 100644 index 0000000000000000000000000000000000000000..979eb15ac49c64537b600b4fe1e1e4c03b931c52 Binary files /dev/null and b/ArkWeb/ProcessWebPageCont/screenshots/PreviewPDF.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/.gitignore b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0f85c5557290b6c5fe654a0173b9db71c296633d --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.samples.setbasicattrsevtsone", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f3bc9e64fec3aceeac9b80739ca1dae60be59090 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SetBasicAttrsEvtsOne" + } + ] +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/README.md b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8d3025b20958141d60fe87b2fbecb9699b1ca92f --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/README.md @@ -0,0 +1,318 @@ +# 使用隐私模式 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-incognito-mode.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### AllowGeolocation + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过allowGeolocation设置隐私模式下的Web组件允许指定来源使用地理位置。 + +#### 效果预览 + +| 主页 | +| ----------------------------------------------------------- | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,来开启Web组件的隐私模式 +2. 点击按钮通过allowGeolocation设置隐私模式下的Web组件允许指定来源使用地理位置。 + +### ClearAllCookiesSync + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过clearAllCookiesSync清除隐私模式下所有cookie。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,来开启Web组件的隐私模式。 +1. 点击按钮通过clearAllCookiesSync清除隐私模式下所有cookie。 + +### ConfigCookieSync + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过configCookieSync设置隐私模式下指定url的单个cookie的值。 + +#### 效果预览 + +| 主页 | +| ----------------------------------------------------------- | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,来开启Web组件的隐私模式。 +2. 点击按钮通过configCookieSync设置隐私模式下指定url的单个cookie的值。 + +### DeleteAllData + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过deleteAllData清除隐私模式下Web SQL当前使用的所有存储。 + +#### 效果预览 + +| 主页 | +| -------------------------------------------------------- | +| | + +使用说明 + +1,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式。 + +2 , 点击按钮通过deleteAllData清除隐私模式下Web SQL当前使用的所有存储。 + +### DeleteGeolocation + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过deleteGeolocation清除隐私模式下指定来源的地理位置权限状态。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,来开启Web组件的隐私模式。 +2. 点击按钮通过deleteGeolocation清除隐私模式下指定来源的地理位置权限状态。 + +### ExistCookie + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过existCookie查询隐私模式下是否存在cookie。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------ | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,来开启Web组件的隐私模式。 +2. 点击按钮通过existCookie查询隐私模式下是否存在cookie。 + +### FetchCookieSync + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过fetchCookieSync获取隐私模式下指定url对应cookie的值。 + +#### 效果预览 + +| 主页 | +| ---------------------------------------------------------- | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,来开启Web组件的隐私模式。 +2. 点击按钮通过fetchCookieSync获取隐私模式下指定url对应cookie的值。 + +### GetAccessibleGeolocation + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,通过getAccessibleGeolocation以回调方式异步获取隐私模式下指定源的地理位置权限状态。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,来开启Web组件的隐私模式。 +2. 点击按钮通过getAccessibleGeolocation以回调方式异步获取隐私模式下指定源的地理位置权限状态。 + +### IncognitoMode_one + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,将可选参数incognitoMode设置为true,来开启Web组件的隐私模式,当使用隐私模式时,浏览网页时的Cookie、 Cache Data等数据不会保存在本地的持久化文件,当隐私模式的Web组件被销毁时,Cookie、 Cache Data等数据将不被记录下来。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 将可选参数incognitoMode设置为true,创建隐私模式的Web组件。 + +### IncognitoMode_two + +#### 介绍 + +1. 本示例主要介绍使用隐私模式,通过isIncogntoMode判断当前Web组件是否是隐私模式。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击按钮通过isIncogntoMode判断当前Web组件是否是隐私模式。 + +# 在新窗口中打开页面 + +### OpenPageNewWin + +#### 介绍 + +1. 本示例主要介绍在新窗口中打开页面,通过multiWindowAccess()接口来设置是否允许网页在新窗口打开。 +2. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-open-in-new-window.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### 效果预览 + +| 主页 | 新窗口页面 | +| ----------------------------------------------------------- | ----------------------------------------------------------- | +| | | + +使用说明 + +1. 通过multiWindowAccess()接口来设置是否允许网页在新窗口打开。 +1. 点击按钮在新窗口打开网页。 + +# 管理位置权限 + +### ManageLocPerms + +#### 介绍 + +1. 本示例主要介绍管理位置权限,可以通过onGeolocationShow()接口对某个网站进行位置权限管理。Web组件根据接口响应结果,决定是否赋予前端页面权限。 +2. 实现对以下指南文档中 https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/web/web-geolocation-permission.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### 效果预览 + +| 主页 | 提示框 | +| ----------------------------------------------------------- | ----------------------------------------------------------- | +| | | + +使用说明 + +1. 通过onGeolocationShow()接口对某个网站进行位置权限管理。 +1. 点击按钮,Web组件通过弹窗的形式通知应用侧位置权限请求消息。 + +# 设置深色模式 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-set-dark-mode.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### DarkMode_one + +#### 介绍 + +1. 本示例主要介绍对前端页面进行深色模式配置,使用darkMode()接口可以配置不同的深色模式。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------- | +| | + +使用说明 + +1. 使用darkMode()接口将页面深色模式配置为跟随系统。 + +### DarkMode_two + +#### 介绍 + +1. 本示例主要介绍对前端页面进行深色模式配置,通过forceDarkAccess()接口可将前端页面强制配置深色模式。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------- | +| | + +使用说明 + +1. 将深色模式配置成WebDarkMode.On,并通过forceDarkAccess()接口将页面强制配置为深色模式。 + +## 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---DarkMode_one.ets +|---|---|---DarkMode_two.ets +|---|---|---AllowGeolocation +|---|---|---ClearAllCookiesSync +|---|---|---ConfigCookieSync +|---|---|---DeleteAllData +|---|---|---DeleteGeolocation +|---|---|---ExistCookie +|---|---|---FetchCookieSync +|---|---|---GetAccessibleGeolocation +|---|---|---IncognitoMode_one +|---|---|---IncognitoMode_two +|---|---|---OpenPageNewWin.ets +|---|---|---ManageLocPerms.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + +## 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +[ohos.permission.LOCATION](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionlocation) + +[ohos.permission.APPROXIMATELY_LOCATION](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionapproximatelylocation) + +[ohos.permission.LOCATION_IN_BACKGROUND](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionlocationinbackground) + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/code-linter.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/.gitignore b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/hvigorfile.ts b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/obfuscation-rules.txt b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/AllowGeolocation.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/AllowGeolocation.ets new file mode 100644 index 0000000000000000000000000000000000000000..96167cf5d798feae39d86710b5ee195f507eaed6 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/AllowGeolocation.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start setting_the_web_component_in_privacy_mode_allows_specifying_the_geolocation_of_the_source_used] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + origin: string = 'file:///'; + + build() { + Column() { + Button('allowGeolocation') + .onClick(() => { + try { + // allowGeolocation第二个参数表示隐私模式(true)或非隐私模式(false)下,允许指定来源使用地理位置。 + webview.GeolocationPermissions.allowGeolocation(this.origin, true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End setting_the_web_component_in_privacy_mode_allows_specifying_the_geolocation_of_the_source_used] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ClearAllCookiesSync.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ClearAllCookiesSync.ets new file mode 100644 index 0000000000000000000000000000000000000000..dde1aa7d0bd4b8e9ab501690b47459063e6cdaf0 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ClearAllCookiesSync.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start clear_all_cookies_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('clearAllCookiesSync') + .onClick(() => { + // clearAllCookiesSync参数表示清除隐私模式(true)或非隐私模式(false)下,webview的所有内存cookies。 + webview.WebCookieManager.clearAllCookiesSync(true); + }) + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End clear_all_cookies_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ConfigCookieSync.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ConfigCookieSync.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c5e72cd0afd6e4dfc6d002d7e28532b1adb1b75 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ConfigCookieSync.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start set_the_value_of_a_single_cookie_for_a_specified_url_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('configCookieSync') + .onClick(() => { + try { + // configCookieSync第三个参数表示获取隐私模式(true)或非隐私模式(false)下,对应url的cookies。 + webview.WebCookieManager.configCookieSync('www.example.com', 'a=b', true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End set_the_value_of_a_single_cookie_for_a_specified_url_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_one.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fad13e49ed848122a37294eca902ba3b8b61ade --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_one.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start configure_page_dark_mode_to_follow_the_system] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + @State mode: WebDarkMode = WebDarkMode.Auto; + + build() { + Column() { + Web({ src: $rawfile('darkModePage.html'), controller: this.controller }) + .darkMode(this.mode) + } + } +} +// [End configure_page_dark_mode_to_follow_the_system] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_two.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd0dc35bcea348c0186915a71879e92829fbbeb6 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_two.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start force_the_page_to_be_configured_to_dark_mode] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + @State mode: WebDarkMode = WebDarkMode.On; + @State access: boolean = true; + + build() { + Column() { + Web({ src: $rawfile('darkModePage.html'), controller: this.controller }) + .darkMode(this.mode) + .forceDarkAccess(this.access) + } + } +} +// [End force_the_page_to_be_configured_to_dark_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteAllData.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteAllData.ets new file mode 100644 index 0000000000000000000000000000000000000000..eba8a6b93ec17492b001acb0d90fd90f7f8248d8 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteAllData.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start clear_all_storage_currently_used_by_web_sql_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('deleteAllData') + .onClick(() => { + try { + // deleteAllData参数表示删除所有隐私模式(true)或非隐私模式(false)下,内存中的web数据。 + webview.WebStorage.deleteAllData(true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index.html'), controller: this.controller, incognitoMode: true }) + .databaseAccess(true) + } + } +} +// [End clear_all_storage_currently_used_by_web_sql_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteGeolocation.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteGeolocation.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b38112ff6ea0c1a3c4b6d373614aa6f9fdede9a --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteGeolocation.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start clear_the_geolocation_permission_status_of_the_specified_source_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + origin: string = 'file:///'; + + build() { + Column() { + Button('deleteGeolocation') + .onClick(() => { + try { + // deleteGeolocation第二个参数表示隐私模式(true)或非隐私模式(false)下,清除指定来源的地理位置权限状态。 + webview.GeolocationPermissions.deleteGeolocation(this.origin, true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End clear_the_geolocation_permission_status_of_the_specified_source_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ExistCookie.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ExistCookie.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4f870530753c4ccb924457eb929bfb9d7e85411 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ExistCookie.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start check_whether_cookies_exist_in_mode] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('existCookie') + .onClick(() => { + // existCookie参数表示隐私模式(true)或非隐私模式(false)下,查询是否存在cookies。 + let result = webview.WebCookieManager.existCookie(true); + console.log('result: ' + result); + }) + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End check_whether_cookies_exist_in_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/FetchCookieSync.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/FetchCookieSync.ets new file mode 100644 index 0000000000000000000000000000000000000000..a17ed3b40343d58092b9156b79a9d82df1c5f549 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/FetchCookieSync.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start obtain_the_value_of_the_cookie_corresponding_to_the_specified_url_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('fetchCookieSync') + .onClick(() => { + try { + // fetchCookieSync第二个参数表示获取隐私模式(true)或非隐私模式(false)下,webview的内存cookies。 + let value = webview.WebCookieManager.fetchCookieSync('www.example.com', true); + console.log('fetchCookieSync cookie = ' + value); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End obtain_the_value_of_the_cookie_corresponding_to_the_specified_url_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/GetAccessibleGeolocation.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/GetAccessibleGeolocation.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e37fd79fcd073ea9a487421899fcec2ffdd42aa --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/GetAccessibleGeolocation.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start asynchronously_obtains_the_geolocation_permission_status_of_the_specified_source_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + origin: string = 'file:///'; + + build() { + Column() { + Button('getAccessibleGeolocation') + .onClick(() => { + try { + // getAccessibleGeolocation第三个参数表示隐私模式(true)或非隐私模式(false)下 + // 以回调方式异步获取指定源的地理位置权限状态。 + webview.GeolocationPermissions.getAccessibleGeolocation(this.origin, (error, result) => { + if (error) { + console.log('getAccessibleGeolocationAsync error: ' + JSON.stringify(error)); + return; + } + console.log('getAccessibleGeolocationAsync result: ' + result); + }, true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End asynchronously_obtains_the_geolocation_permission_status_of_the_specified_source_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_one.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..95d05d45a2a3d9ac1a635dc9f47c5dcdcc9b3080 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_one.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start create_a_web_component_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }); + } + } +} +// [End create_a_web_component_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_two.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..45893f00c020b4a179eae6575e9bed4dc899b280 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_two.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start determine_whether_the_current_web_component_is_in_privacy_mode] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('isIncognitoMode') + .onClick(() => { + try { + let result = this.controller.isIncognitoMode(); + console.log('isIncognitoMode' + result); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }); + } + } +} +// [End determine_whether_the_current_web_component_is_in_privacy_mode] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..420f733900a18591c4b182d382f7b6e6bede3d61 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('DarkMode_one') + .onClick(() => { + router.pushUrl({ url: 'pages/DarkMode_one' }); + }) + Button('DarkMode_two') + .onClick(() => { + router.pushUrl({ url: 'pages/DarkMode_two' }); + }) + Button('AllowGeolocation') + .onClick(() => { + router.pushUrl({ url: 'pages/AllowGeolocation' }); + }) + Button('ClearAllCookiesSync') + .onClick(() => { + router.pushUrl({ url: 'pages/ClearAllCookiesSync' }); + }) + Button('ConfigCookieSync') + .onClick(() => { + router.pushUrl({ url: 'pages/ConfigCookieSync' }); + }) + Button('DeleteAllData') + .onClick(() => { + router.pushUrl({ url: 'pages/DeleteAllData' }); + }) + Button('DeleteGeolocation') + .onClick(() => { + router.pushUrl({ url: 'pages/DeleteGeolocation' }); + }) + Button('ExistCookie') + .onClick(() => { + router.pushUrl({ url: 'pages/ExistCookie' }); + }) + Button('FetchCookieSync') + .onClick(() => { + router.pushUrl({ url: 'pages/FetchCookieSync' }); + }) + Button('GetAccessibleGeolocation') + .onClick(() => { + router.pushUrl({ url: 'pages/GetAccessibleGeolocation' }); + }) + Button('IncognitoMode_one') + .onClick(() => { + router.pushUrl({ url: 'pages/IncognitoMode_one' }); + }) + Button('IncognitoMode_two') + .onClick(() => { + router.pushUrl({ url: 'pages/IncognitoMode_two' }); + }) + Button('OpenPageNewWin') + .onClick(() => { + router.pushUrl({ url: 'pages/OpenPageNewWin' }); + }) + Button('ManageLocPerms') + .onClick(() => { + router.pushUrl({ url: 'pages/ManageLocPerms' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets new file mode 100644 index 0000000000000000000000000000000000000000..b39a2cf2be2b6dc0d11af46a87c698b4a7b20ac2 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start a_pop_up_window_is_used_to_notify_the_app_side_location_permission_request_message] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { abilityAccessCtrl, common } from '@kit.AbilityKit'; + +let context = getContext(this) as common.UIAbilityContext; +let atManager = abilityAccessCtrl.createAtManager(); + +// 向用户请求位置权限设置。 +atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION']).then((data) => { + console.info('data:' + JSON.stringify(data)); + console.info('data permissions:' + data.permissions); + console.info('data authResults:' + data.authResults); +}).catch((error: BusinessError) => { + console.error(`Failed to request permissions from user. Code is ${error.code}, message is ${error.message}`); +}) + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $rawfile('getLocation.html'), controller: this.controller }) + .geolocationAccess(true) + .onGeolocationShow((event) => { // 地理位置权限申请通知 + AlertDialog.show({ + title: 'Location permission requests', + message: 'Whether to allow access to location information', + primaryButton: { + value: 'cancel', + action: () => { + if (event) { + event.geolocation.invoke(event.origin, false, false); // 不允许此站点地理位置权限请求 + } + } + }, + secondaryButton: { + value: 'ok', + action: () => { + if (event) { + event.geolocation.invoke(event.origin, true, false); // 允许此站点地理位置权限请求 + } + } + }, + cancel: () => { + if (event) { + event.geolocation.invoke(event.origin, false, false); // 不允许此站点地理位置权限请求 + } + } + }) + }) + } + } +} +// [End a_pop_up_window_is_used_to_notify_the_app_side_location_permission_request_message] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets new file mode 100644 index 0000000000000000000000000000000000000000..af16dd1c6edf119f9f6da7d80d8d45517e3a7f0a --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start receive_a_web_component_new_window_event] +import { webview } from '@kit.ArkWeb'; + +// 在同一page页有两个Web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。 +@CustomDialog +struct NewWebViewComp { + controller?: CustomDialogController; + webviewController1: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: '', controller: this.webviewController1 }) + .javaScriptAccess(true) + .multiWindowAccess(false) + .onWindowExit(() => { + console.info('NewWebViewComp onWindowExit'); + if (this.controller) { + this.controller.close(); + } + }) + } + } +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + dialogController: CustomDialogController | null = null; + + build() { + Column() { + Web({ src: $rawfile('window.html'), controller: this.controller }) + .javaScriptAccess(true) + // 需要使能multiWindowAccess + .multiWindowAccess(true) + .allowWindowOpenMethod(true) + .onWindowNew((event) => { + if (this.dialogController) { + this.dialogController.close(); + } + let popController: webview.WebviewController = new webview.WebviewController(); + this.dialogController = new CustomDialogController({ + builder: NewWebViewComp({ webviewController1: popController }) + }); + this.dialogController.open(); + // 将新窗口对应WebviewController返回给Web内核。 + // 如果不需要打开新窗口请调用event.handler.setWebController接口设置成null。 + // 若不调用event.handler.setWebController接口,会造成render进程阻塞。 + event.handler.setWebController(popController); + }) + } + } +} +// [End receive_a_web_component_new_window_event] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..394d2a4703ff31b1662e4f09fba46876e701c984 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name" : "ohos.permission.LOCATION", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + } + }, + { + "name" : "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + } + }, + { + "name" : "ohos.permission.LOCATION_IN_BACKGROUND", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + } + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..18d4ec70763241b2e4e8ece71a5a37f56c0d74c8 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SetBasicAttrsEvtsOne" + }, + { + "name": "use_is_permitted", + "value": "本次使用允许" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..873e2af741f7145ca994ad97abad48f571d63589 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,19 @@ +{ + "src": [ + "pages/Index", + "pages/DarkMode_one", + "pages/DarkMode_two", + "pages/AllowGeolocation", + "pages/ClearAllCookiesSync", + "pages/ConfigCookieSync", + "pages/DeleteAllData", + "pages/DeleteGeolocation", + "pages/ExistCookie", + "pages/FetchCookieSync", + "pages/GetAccessibleGeolocation", + "pages/IncognitoMode_one", + "pages/IncognitoMode_two", + "pages/OpenPageNewWin", + "pages/ManageLocPerms" + ] +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/en_US/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..80f7dd956c3a63524e9bc87f25a1567069ce3176 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SetBasicAttrsEvtsOne" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html new file mode 100644 index 0000000000000000000000000000000000000000..43497f5df3fabd7205aa28942e6dc63e24892b4a --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html @@ -0,0 +1,35 @@ + + + + + + + + + +
+

Dark mode debug page

+
+ + \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html new file mode 100644 index 0000000000000000000000000000000000000000..4ae442f92a0e6145b5979fd8f571722c6ca83d10 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html @@ -0,0 +1,34 @@ + + + + + +

位置信息

+ + + + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..25c6d7f99692719d79c63898f8bb68a9e8e6d9cc --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,55 @@ + + + + + + + test + + + +
状态信息
+ + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html new file mode 100644 index 0000000000000000000000000000000000000000..e1a15e6a52b74bd26ba93ef26e4da665427aadec --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html @@ -0,0 +1,34 @@ + + + + + + + WindowEvent + + + + + + \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f276d4cc8d01d30a9337543e65032484ddbb6765 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SetBasicAttrsEvtsOne" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/mock/mock-config.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ddaa8f7e38d9a8406806eb3040768ec7fd07932 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,394 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +function resourceToString(resource: Resource): string { + return getContext().resourceManager.getStringSync(resource); +} + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 AllowGeolocation 按钮 + * 开启Web组件的隐私模式 + * 设置隐私模式下的Web组件允许指定来源使用地理位置 + */ + it('AllowGeolocation', 0, async (done: Function) => { + console.info('uitest: AllowGeolocation begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('AllowGeolocation')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: AllowGeolocation end'); + done(); + }); + + /* + * 点击 ClearAllCookiesSync 按钮 + * 开启Web组件的隐私模式 + * 通过 clearAllCookiesSync 清除隐私模式下所有cookie + */ + it('ClearAllCookiesSync', 0, async (done: Function) => { + console.info('uitest: ClearAllCookiesSync begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ClearAllCookiesSync')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: ClearAllCookiesSync end'); + done(); + }); + + /* + * 点击 ConfigCookieSync 按钮 + * 开启Web组件的隐私模式 + * 通过 configCookieSync 设置隐私模式下指定url的单个cookie的值 + */ + it('ConfigCookieSync', 0, async (done: Function) => { + console.info('uitest: ConfigCookieSync begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ConfigCookieSync')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: ConfigCookieSync end'); + done(); + }); + + /* + * 点击 DeleteAllData 按钮 + * 开启Web组件的隐私模式 + * 通过 deleteAllData 清除隐私模式下Web SQL当前使用的所有存储 + */ + it('DeleteAllData', 0, async (done: Function) => { + console.info('uitest: DeleteAllData begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('DeleteAllData')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + await driver.pressBack(); + console.info('uitest: DeleteAllData end'); + done(); + }); + + /* + * 点击 DeleteGeolocation 按钮 + * 开启Web组件的隐私模式 + * 通过 deleteGeolocation 清除隐私模式下指定来源的地理位置权限状态 + */ + it('DeleteGeolocation', 0, async (done: Function) => { + console.info('uitest: DeleteGeolocation begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('DeleteGeolocation')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: DeleteGeolocation end'); + done(); + }); + + /* + * 点击 ExistCookie 按钮 + * 开启Web组件的隐私模式 + * 通过 existCookie 查询隐私模式下是否存在cookie + */ + it('ExistCookie', 0, async (done: Function) => { + console.info('uitest: ExistCookie begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ExistCookie')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: ExistCookie end'); + done(); + }); + + /* + * 点击 FetchCookieSync 按钮 + * 开启Web组件的隐私模式 + * 通过 fetchCookieSync 获取隐私模式下指定url对应cookie的值 + */ + it('FetchCookieSync', 0, async (done: Function) => { + console.info('uitest: FetchCookieSync begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('FetchCookieSync')); + await button1.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: FetchCookieSync end'); + done(); + }); + + /* + * 点击 GetAccessibleGeolocation 按钮 + * 开启Web组件的隐私模式 + * 通过 getAccessibleGeolocation 以回调方式异步获取隐私模式下指定源的地理位置权限状态 + */ + it('GetAccessibleGeolocation', 0, async (done: Function) => { + console.info('uitest: GetAccessibleGeolocation begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('GetAccessibleGeolocation')); + await button1.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: GetAccessibleGeolocation end'); + done(); + }); + + /* + * 点击 IncognitoMode_one 按钮 + * 开启Web组件的隐私模式 + * 浏览网页时的Cookie、 Cache Data等数据不会保存在本地的持久化文件,数据将不被记录下来 + */ + it('IncognitoMode_one', 0, async (done: Function) => { + console.info('uitest: IncognitoMode_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('IncognitoMode_one')); + await button1.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: IncognitoMode_one end'); + done(); + }); + + /* + * 点击 IncognitoMode_two 按钮 + * 开启Web组件的隐私模式 + * 通过isIncogntoMode判断当前Web组件是否是隐私模式 + */ + it('IncognitoMode_two', 0, async (done: Function) => { + console.info('uitest: IncognitoMode_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('IncognitoMode_two')); + await button1.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: IncognitoMode_two end'); + done(); + }); + + /* + * 点击 OpenPageNewWin 按钮 + * 通过 multiWindowAccess 接口来设置是否允许网页在新窗口打开 + * + */ + it('OpenPageNewWin', 0, async (done: Function) => { + console.info('uitest: OpenPageNewWin begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('OpenPageNewWin')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('button')); + await button2.click(); + await driver.delayMs(2000); + + const dialog = JSON.stringify(getInspectorTree()); + expect(dialog).assertContain('Dialog'); + + await driver.pressBack(); + await driver.delayMs(1000); + await driver.pressBack(); + console.info('uitest: OpenPageNewWin end'); + done(); + }); + + /* + * 点击 ManageLocPerms 按钮 + * 通过 onGeolocationShow 接口对网站进行位置权限管理 + * Web组件根据接口响应结果,决定是否赋予前端页面权限 + */ + it('ManageLocPerms', 0, async (done: Function) => { + console.info('uitest: ManageLocPerms begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ManageLocPerms')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text(resourceToString($r('app.string.use_is_permitted')))); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.type('button')); + await button3.click(); + await driver.delayMs(1000); + + const dialog = JSON.stringify(getInspectorTree()); + expect(dialog).assertContain('Dialog'); + + const button4 = await driver.findComponent(ON.text('ok')); + await button4.click(); + await driver.delayMs(1000); + + await driver.pressBack(); + console.info('uitest: ManageLocPerms end'); + done(); + }); + + /* + * 点击 DarkMode_one 按钮 + * 开启Web组件的隐私模式 + * 使用 darkMode 接口将页面深色模式配置为跟随系统 + */ + it('DarkMode_one', 0, async (done: Function) => { + console.info('uitest: DarkMode_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('DarkMode_one')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let text1 = await web1.getText(); + expect(text1).assertContain('darkModePage.html'); + + await driver.pressBack(); + console.info('uitest: DarkMode_one end'); + done(); + }); + + /* + * 点击 DarkMode_two 按钮 + * 开启Web组件的隐私模式 + * 通过 forceDarkAccess 接口可将前端页面强制配置深色模式 + */ + it('DarkMode_two', 0, async (done: Function) => { + console.info('uitest: DarkMode_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('DarkMode_two')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let text1 = await web1.getText(); + expect(text1).assertContain('darkModePage.html'); + + console.info('uitest: DarkMode_two end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/List.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/LocalUnit.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigorfile.ts b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/ohosTest.md b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..1366ac94e7a9591c59e590bb7e2139b635c275b1 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/ohosTest.md @@ -0,0 +1,84 @@ +### DarkMode_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------ | -------------------------------------- | -------- | -------- | +| 设置深色模式 | 设备运转正常 | 应用启动成功 | 将页面深色模式配置为WebDarkMode.Auto。 | Yes | Pass | + +### DarkMode_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------ | ------------------ | -------- | -------- | +| 设置深色模式 | 设备运转正常 | 应用启动成功 | 前端页面为深色模式 | Yes | Pass | + +### AllowGeolocation + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | -------------------------------------- | ------------------------ | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击allowGeolocation按钮 | 允许指定来源使用地理位置 | Yes | Pass | + +### ClearAllCookiesSync + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ----------------------------------------- | ------------------------ | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击clearAllCookiesSync按钮 | 清除隐私模式下所有cookie | Yes | Pass | + +### ConfigCookieSync + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | -------------------------------------- | ------------------------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击configCookieSync按钮 | 设置隐私模式下指定url的单个cookie的值 | Yes | Pass | + +### DeleteAllData + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ----------------------------------- | --------------------------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击deleteAllData按钮 | 清除隐私模式下Web SQL当前使用的所有存储 | Yes | Pass | + +### DeleteGeolocation + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | --------------------------------------- | ---------------------------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击deleteGeolocation按钮 | 清除隐私模式下指定来源的地理位置权限状态 | Yes | Pass | + +### ExistCookie + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | --------------------------------- | ---------------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击existCookie按钮 | 查询隐私模式下是否存在cookie | Yes | Pass | + +### FetchCookieSync + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------------------------------- | ----------------------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击fetchCookieSync按钮 | 获取隐私模式下指定url对应cookie的值 | Yes | Pass | + +### GetAccessibleGeolocation + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ---------------------------------------------- | -------------------------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击getAccessibleGeolocation按钮 | 获取隐私模式下指定源的地理位置权限状态 | Yes | Pass | + +### IncognitoMode_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------ | ------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功 | 建隐私模式的Web组件 | Yes | Pass | + +### IncognitoMode_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------------------------------- | ----------------------------- | -------- | -------- | +| 使用隐私模式 | 设备运转正常 | 应用启动成功,点击isIncogntoMode 按钮 | 判断当前Web组件是否是隐私模式 | Yes | Pass | + +### OpenPageNewWin + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ---------------------------------------- | ------------------ | -------- | -------- | +| 在新窗口中打开页面 | 设备运转正常 | 应用启动成功,点击在新窗口中打开网页按钮 | 在新窗口中打开页面 | Yes | Pass | + +### ManageLocPerms + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | -------------------------------- | ------------------ | -------- | -------- | +| 管理位置权限 | 设备运转正常 | 应用启动成功,点击"获取位置"按钮 | 弹出权限请求提示框 | Yes | Pass | + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png new file mode 100644 index 0000000000000000000000000000000000000000..14db5e6cb7f913c2bb4bd4c1f650a6adc481ecc0 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png new file mode 100644 index 0000000000000000000000000000000000000000..a660a30cd30c0cc7dea9d91abbbde0f3e5cf0be0 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png new file mode 100644 index 0000000000000000000000000000000000000000..bcb0728a9ffb2dd02db07c591d54ba34f84cfae6 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png new file mode 100644 index 0000000000000000000000000000000000000000..070cc93979c4329965d0da492e7718a17b483421 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png new file mode 100644 index 0000000000000000000000000000000000000000..d988628107261e2a03abd319560d58eaba524095 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png new file mode 100644 index 0000000000000000000000000000000000000000..77b47aae22b5a81809ab869d8244e0d540ca84e9 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png new file mode 100644 index 0000000000000000000000000000000000000000..afff44065ba616b5bd56d6824f65aa662548dccf Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png new file mode 100644 index 0000000000000000000000000000000000000000..5e96f02cbf0d6d720444e28afaa27083e9b1ad32 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png new file mode 100644 index 0000000000000000000000000000000000000000..0581b3e297d890d2c7aeb1e2aa0a825357e075a3 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png new file mode 100644 index 0000000000000000000000000000000000000000..8d75318992f894e8af16cbf8c69aa3f5eaac115c Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png new file mode 100644 index 0000000000000000000000000000000000000000..58065bd9a8348befb7879279aa59443ffbb5761a Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png new file mode 100644 index 0000000000000000000000000000000000000000..237cb219e76eb1ccc6aa39fc03f3bd3a978a5254 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png new file mode 100644 index 0000000000000000000000000000000000000000..628a6e183aac531f9ebfa98b0059fec6a36f9a94 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png new file mode 100644 index 0000000000000000000000000000000000000000..c93cc7c400943c113530f451d724eab2af95ad8c Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png new file mode 100644 index 0000000000000000000000000000000000000000..0e70ae121a512da04e83988f817a5181d3accc52 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png new file mode 100644 index 0000000000000000000000000000000000000000..fc518f2b21fb6a82dd1c2afc21d1a6986e1d077f Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31ec642dd4cac388ed77191691e319de60e07db4 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.samples.setbasicsttrsrvtstwo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4f29f2384417aa862af49ba47c6479c7830b8573 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SetBasicAttrsEvtsTwo" + } + ] +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/README.md b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f161ca06e3da652f5eda926f300ded5d7dd9d14e --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/README.md @@ -0,0 +1,207 @@ +# 管理Cookie及数据存储 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-cookie-and-data-storage-mgmt.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### Cache_one + +#### 介绍 + +1. 本示例主要介绍管理Cookie及数据存储的缓存与存储管理。使用了cacheMode()接口配置页面资源的缓存模式。 + +#### 效果预览 + +| 主页 | +| ---------------------------------------------------- | +| | + +使用说明 + +1. 使用cacheMode()配置页面资源的缓存模式为None,加载资源使用cache,如果cache中无该资源则从网络中获取。 + +### Cache_two + +#### 介绍 + +1. 本示例主要介绍管理Cookie及数据存储的缓存与存储管理相关功能,通过removeCache()接口清除已经缓存的资源。 + +#### 效果预览 + +| 主页 | +| ---------------------------------------------------- | +| | + +使用说明 + +1. 点击按钮触发removeCache()接口清除已经缓存的资源。 + +### CookieManagement + +#### 介绍 + +1. 本示例主要介绍管理Cookie及数据存储。使用了configCookieSync()接口来设置单个Cookie的值。 + +#### 效果预览 + +| 主页 | +| ----------------------------------------------------------- | +| | + +使用说明 + +1. 点击按钮使用configCookieSync()接口为example.com设置单个Cookie的值。 + +### DomStorage + +#### 介绍 + +1. 本示例主要介绍管理Cookie及数据存储的缓存与存储管理相关部分Dom Storage。使用domStorageAccess()接口进行使能配置。 + +#### 效果预览 + +| 主页 | +| ----------------------------------------------------- | +| | + +使用说明 + +1. 通过Web组件的属性接口domStorageAccess()配置Dom Storage。 + +# UserAgent开发指导 + +### 介绍 + +1. UserAgent(简称UA)是一个特殊的字符串,它包含了设备类型、操作系统及版本等关键信息。如果页面无法正确识别UA,可能会导致一系列异常情况,例如页面布局错误、渲染问题以及逻辑错误等。 +2. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-default-userAgent.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### UserAgent_one + +#### 介绍 + +1. 通过getUserAgent()接口获取当前默认用户代理,支持开发者基于默认的UserAgent去定制UserAgent。 + +#### 效果预览 + +| 主页 | +| -------------------------------------------------------- | +| | + +使用说明 + +1. 在主界面,可以点击按钮获取当前默认用户代理。 + +### UserAgent_two + +#### 介绍 + +1. 本示例主要展示了设置UserAgent相关的功能,使用了getUserAgent(),setCustomUserAgent()接口实现了定制UserAgent。 + +#### 效果预览 + +| 主页 | +| ---------------------------------------------------------- | +| | + +使用说明 + +1. 通过this.controller.getUserAgent()获取当前的默认UserAgent字符串,并将其与自定义的字符串'xxx'进行拼接,得到定制后的UserAgent字符串,然后赋值给this.ua。 +2. 使用this.controller.setCustomUserAgent(this.ua);将定制后的UserAgent设置到Web组件中,在后续加载网页等操作时,就会使用定制后的UserAgent。 + +### UserAgent_three + +#### 介绍 + +1. 本示例主要介绍设置UserAgent相关的功能,通过getCustomUserAgent()接口获取自定义用户代理。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击按钮,通过getCustomUserAgent()接口获取自定义用户代理。 + +# 使用运动和方向传感器监测设备状态 + +### UseMotionDirSensor + +#### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-sensor.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### 效果预览 + +| 主页 | 弹窗 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击加速度按钮申请权限,获取请求权限的资源类型,弹出提示框。 +2. 点击onConfirm进行传感器授权处理。 + +## 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---Cache_one +|---|---|---Cache_two +|---|---|---CookieManagement +|---|---|---DomStorage +|---|---|---UserAgent_one.ets +|---|---|---UserAgent_three.ets +|---|---|---UserAgent_two.ets +|---|---|---UseMotionDirSensor.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + +## 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +[ohos.permission.ACCELEROMETER](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccelerometer) + +[ohos.permission.GYROSCOPE](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissiongyroscope) + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` + + + + + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/code-linter.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/.gitignore b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/hvigorfile.ts b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/obfuscation-rules.txt b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_one.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..1380c626b77a8925d9a21fee8cc5f8e99ce5b718 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_one.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start configure_the_caching_mode_for_page_resources] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + @State mode: CacheMode = CacheMode.None; + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'www.example.com', controller: this.controller }) + .cacheMode(this.mode) + } + } +} +// [End configure_the_caching_mode_for_page_resources] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_two.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e07970d273de44e1adddcb97a2efdeb46f29cad --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_two.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start clear_the_cached_resources_that_have_been_stored] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + @State mode: CacheMode = CacheMode.None; + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('removeCache') + .onClick(() => { + try { + // 设置为true时同时清除rom和ram中的缓存,设置为false时只清除ram中的缓存 + this.controller.removeCache(true); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }); + Web({ src: 'www.example.com', controller: this.controller }) + .cacheMode(this.mode) + } + } +} +// [End clear_the_cached_resources_that_have_been_stored] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/CookieManagement.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/CookieManagement.ets new file mode 100644 index 0000000000000000000000000000000000000000..632de154566c900d7e7b3fb1b626c7587c0f1a4f --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/CookieManagement.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start set_the_value_of_a_single_cookie] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('configCookieSync') + .onClick(() => { + try { + webview.WebCookieManager.configCookieSync('www.example.com', 'value=test'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }); + } + } +} +// [End set_the_value_of_a_single_cookie] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/DomStorage.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/DomStorage.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e26e61b26fcafccba1da6eb8041ef16e069ad84 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/DomStorage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start enable_configuration] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'www.example.com', controller: this.controller }) + .domStorageAccess(true) + } + } +} +// [End enable_configuration] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5fb4c112b7bb8fcac763cdee5dadeba13f4266b --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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. + */ + +import { router } from '@kit.ArkUI' + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('UserAgent_one') + .onClick(() => { + router.pushUrl({ url: 'pages/UserAgent_one' }); + }) + Button('UserAgent_two') + .onClick(() => { + router.pushUrl({ url: 'pages/UserAgent_two' }); + }) + Button('UserAgent_three') + .onClick(() => { + router.pushUrl({ url: 'pages/UserAgent_three' }); + }) + Button('CookieManagement') + .onClick(() => { + router.pushUrl({ url: 'pages/CookieManagement' }); + }) + Button('Cache_one') + .onClick(() => { + router.pushUrl({ url: 'pages/Cache_one' }); + }) + Button('Cache_two') + .onClick(() => { + router.pushUrl({ url: 'pages/Cache_two' }); + }) + Button('DomStorage') + .onClick(() => { + router.pushUrl({ url: 'pages/DomStorage' }); + }) + Button('UseMotionDirSensor') + .onClick(() => { + router.pushUrl({ url: 'pages/UseMotionDirSensor' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets new file mode 100644 index 0000000000000000000000000000000000000000..d823038993b07b7ac68ae1dcc566a1a38bc4a20d --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start the_type_of_resource_for_which_permission_is_requested] +import { webview } from '@kit.ArkWeb'; +import { abilityAccessCtrl, PermissionRequestResult } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + aboutToAppear() { + // 配置Web开启调试模式 + webview.WebviewController.setWebDebuggingAccess(true); + // 访问控制管理, 获取访问控制模块对象。 + let atManager = abilityAccessCtrl.createAtManager(); + try { + atManager.requestPermissionsFromUser(getContext(this) + , ['ohos.permission.ACCELEROMETER', 'ohos.permission.GYROSCOPE'] + , (err: BusinessError, data: PermissionRequestResult) => { + console.info('data:' + JSON.stringify(data)); + console.info('data permissions:' + data.permissions); + console.info('data authResults:' + data.authResults); + }) + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onPermissionRequest((event) => { + if (event) { + AlertDialog.show({ + title: 'title', + message: 'text', + primaryButton: { + value: 'deny', + action: () => { + event.request.deny(); + } + }, + secondaryButton: { + value: 'onConfirm', + action: () => { + event.request.grant(event.request.getAccessibleResource()); + } + }, + autoCancel: false, + cancel: () => { + event.request.deny(); + } + }) + } + }) + } + } +} +// [End the_type_of_resource_for_which_permission_is_requested] diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_one.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e21aa06e9a105cbe66544b0496e7e71d5046c19 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_one.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start get_the_current_default_user_agent] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('getUserAgent') + .onClick(() => { + try { + let userAgent = this.controller.getUserAgent(); + console.log('userAgent: ' + userAgent); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End get_the_current_default_user_agent] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_three.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_three.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e405be1a628098f73a7a511ca1a4911246455ea --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_three.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start get_a_custom_user_agent] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + @State userAgent: string = ''; + + build() { + Column() { + Button('getCustomUserAgent') + .onClick(() => { + try { + this.userAgent = this.controller.getCustomUserAgent(); + console.log('userAgent: ' + this.userAgent); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End get_a_custom_user_agent] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_two.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..4aff6c0e7d3f5d479a1119a6e384a823ec0c8825 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_two.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start set_up_a_custom_user_agent] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + // 三方应用相关信息标识 + @State customUserAgent: string = ' DemoApp'; + + build() { + Column() { + Web({ src: 'www.example.com', controller: this.controller }) + .onControllerAttached(() => { + console.log('onControllerAttached'); + try { + let userAgent = this.controller.getUserAgent() + this.customUserAgent; + this.controller.setCustomUserAgent(userAgent); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + } +} +// [End set_up_a_custom_user_agent] \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..94f3336a43093397f85ff0ce48b8f3fef9c9cac0 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + // [Start declare_the_appropriate_sensor_permissions] + "requestPermissions": [ + // [StartExclude declare_the_appropriate_sensor_permissions] + { + "name": "ohos.permission.INTERNET" + }, + // [EndExclude declare_the_appropriate_sensor_permissions] + { + "name" : "ohos.permission.ACCELEROMETER" // 加速度权限 + }, + { + "name" : "ohos.permission.GYROSCOPE" // 陀螺仪权限 + } + ] + // [End declare_the_appropriate_sensor_permissions] + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d52556ec36ab53d80e77fc16b8cac98cee07626d --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SetBasicAttrsEvtsTwo" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1555514763f2c22e49ed472c8840eb93bd9bad75 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,13 @@ +{ + "src": [ + "pages/Index", + "pages/CookieManagement", + "pages/Cache_two", + "pages/Cache_one", + "pages/DomStorage", + "pages/UserAgent_one", + "pages/UserAgent_two", + "pages/UserAgent_three", + "pages/UseMotionDirSensor" + ] +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/en_US/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d52556ec36ab53d80e77fc16b8cac98cee07626d --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SetBasicAttrsEvtsTwo" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..fea52d652492c9a1a9e650add17bc74d43b82e03 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,154 @@ + + + + + + + + + + + 运动和方向传感器 + + + + + +
+

运动和方向:

+ +
+ + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..abeb0b892fc4650c62ed42d93dc6b31be93c8344 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SetBasicAttrsEvtsTwo" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/mock/mock-config.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3e0fa5673567c1c2a6fd86f0041ce8510237b262 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 Cache_one 按钮 + * 使用 cacheMode 接口配置页面资源的缓存模式 + */ + it('Cache_one', 0, async (done: Function) => { + console.info('uitest: Cache_one begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('Cache_one')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let text1 = await web1.getText(); + expect(text1).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: Cache_one end'); + done(); + }); + + /* + * 点击 Cache_two 按钮 + * 通过 removeCache 接口清除已经缓存的资源 + */ + it('Cache_two', 0, async (done: Function) => { + console.info('uitest: Cache_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('Cache_two')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let text1 = await web1.getText(); + expect(text1).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: Cache_two end'); + done(); + }); + + /* + * 点击 CookieManagement 按钮 + * 使用 configCookieSync 接口来设置单个Cookie的值 + */ + it('CookieManagement', 0, async (done: Function) => { + console.info('uitest: CookieManagement begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('CookieManagement')); + await button1.click(); + await driver.delayMs(1000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let text1 = await web1.getText(); + expect(text1).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: CookieManagement end'); + done(); + }); + + /* + * 点击 DomStorage 按钮 + * 使用 domStorageAccess 接口进行使能配置 + */ + it('DomStorage', 0, async (done: Function) => { + console.info('uitest: DomStorage begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('DomStorage')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let text1 = await web1.getText(); + expect(text1).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: DomStorage end'); + done(); + }); + + /* + * 点击 UserAgent_one 按钮 + * 通过 getUserAgent 接口获取当前默认用户代理 + */ + it('UserAgent_one', 0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UserAgent_one')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('getUserAgent')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: UserAgent_one end'); + done(); + }); + + /* + * 点击 UserAgent_two 按钮 + * 使用 setCustomUserAgent 接口定制UserAgent + */ + it('UserAgent_two', 0, async (done: Function) => { + console.info('uitest: UserAgent_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UserAgent_two')); + await button1.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: UserAgent_two end'); + done(); + }); + + /* + * 点击 UserAgent_three 按钮 + * 通过 getCustomUserAgent 接口获取自定义用户代理 + */ + it('UserAgent_three', 0, async (done: Function) => { + console.info('uitest: UserAgent_three begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UserAgent_three')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('getCustomUserAgent')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: UserAgent_three end'); + done(); + }); + + /* + * 点击 UseMotionDirSensor 按钮 + * 访问运动和方向传感器,使用运动和方向传感器监测设备状态 + */ + it('UseMotionDirSensor',0, async (done: Function) => { + console.info('uitest: UseMotionDirSensor begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UseMotionDirSensor')); + await button1.click(); + await driver.delayMs(2000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + const button2 = await driver.findComponent(ON.type('button')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('onConfirm')); + await button3.click(); + await driver.delayMs(1000); + + await driver.pressBack(); + console.info('uitest: UseMotionDirSensor end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/List.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/LocalUnit.test.ets b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigorfile.ts b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/ohosTest.md b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..515264d3e232a27e66b787f511f08ac7ad393f64 --- /dev/null +++ b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/ohosTest.md @@ -0,0 +1,49 @@ +### Cache_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | --------------------------------- | -------------------- | -------- | -------- | +| 管理Cookie及数据存储 | 设备运转正常 | 应用启动成功,点击removeCache按钮 | 清除rom和ram中的缓存 | Yes | Pass | + +### Cache_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | ------------ | ------------------------------------ | -------- | -------- | +| 管理Cookie及数据存储 | 设备运转正常 | 应用启动成功 | 成功配置页面资源的缓存模式为None模式 | Yes | Pass | + +### CookieManagement + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | -------------------------------------- | ---------------------------------- | -------- | -------- | +| 管理Cookie及数据存储 | 设备运转正常 | 应用启动成功,点击configCookieSync按钮 | 单个Cookie的值“value=test”设置成功 | Yes | Pass | + +### DomStorage + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | ------------ | --------------- | -------- | -------- | +| 管理Cookie及数据存储 | 设备运转正常 | 应用启动成功 | 使能Dom Storage | Yes | Pass | + +### UserAgent_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------- | ------------ | ---------------------------------- | -------------------- | -------- | -------- | +| 设置UserAgent | 设备运转正常 | 应用启动成功,点击getUserAgent按钮 | 获取当前默认用户代理 | Yes | Pass | + +### UserAgent_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------- | ------------ | ------------ | ------------------------------- | -------- | -------- | +| 设置UserAgent | 设备运转正常 | 应用启动成功 | 加载网页时使用定制后的UserAgent | Yes | Pass | + +### UserAgent_three + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------- | ------------ | ---------------------------------------- | ---------------------- | -------- | -------- | +| 设置UserAgent | 设备运转正常 | 应用启动成功,点击getCustomUserAgent按钮 | 获取当前自定义用户代理 | Yes | Pass | + +### UseMotionDirSensor + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------- | ------------------ | ---------------------------- | ------------------ | -------- | -------- | +| 使用运动和方向传感器监测设备状态 | 设备运转正常 | 应用启动成功,点击加速度按钮 | 弹出权限申请提示框 | Yes | Pass | +| 传感器授权处理 | 弹出权限申请提示框 | 点击onConfirm按钮 | 传感器授权成功 | Yes | Pass | + diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png new file mode 100644 index 0000000000000000000000000000000000000000..b519a6915fe29d4c35014427a740efef2f54f3be Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png new file mode 100644 index 0000000000000000000000000000000000000000..cc9751214bb8f1b626abbb07131f0bcb5a56b1de Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png new file mode 100644 index 0000000000000000000000000000000000000000..7226dba6e72950639ad4e07323b53fcd860521d0 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png new file mode 100644 index 0000000000000000000000000000000000000000..2737f7f92ba24dc12c23b527253054bec2961fea Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png new file mode 100644 index 0000000000000000000000000000000000000000..7ec9c6c64fa8862970cf471cf14600a6d7e39580 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1d6a51e23edec2e705a25284a638ebcb0852ac4b Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png new file mode 100644 index 0000000000000000000000000000000000000000..ee8c9c998321599f0d0381deac96e827fceac5ac Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png new file mode 100644 index 0000000000000000000000000000000000000000..4f00b024de82f2bb88b33471bd1440b798d56859 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png differ diff --git a/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png new file mode 100644 index 0000000000000000000000000000000000000000..5249dc4104448d82890889afdc1c61092980bac8 Binary files /dev/null and b/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png differ diff --git a/ArkWeb/UseFrontendJSApp/.gitignore b/ArkWeb/UseFrontendJSApp/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/AppScope/app.json5 b/ArkWeb/UseFrontendJSApp/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb2771a6d1ebbcd7b796d98179f3dddaac3c9efd --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.samples.usefrontendjsapp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/UseFrontendJSApp/AppScope/resources/base/element/string.json b/ArkWeb/UseFrontendJSApp/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d98b87fae58bdc64df1c8a60281d29644dff9f00 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UseFrontendJSApp" + } + ] +} diff --git a/ArkWeb/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png b/ArkWeb/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/UseFrontendJSApp/README.md b/ArkWeb/UseFrontendJSApp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5b411ba5ce5596df28bf38a34cfa4a5887dfe474 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/README.md @@ -0,0 +1,401 @@ +# Entry: + +## 应用侧调用前端页面函数 + +### 介绍 + +1. 本示例主要介绍应用侧调用前端页面函数,应用侧可以通过runJavaScript()和runJavaScriptExt()方法调用前端页面的JavaScript相关函数。 +2. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-in-app-frontend-page-function-invoking.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | 绿色字体 | 红色字体 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | | + +使用说明 + +1. 点击 runJavaScript 按钮,文本字体变绿,此操作调用前端 htmlTest() 方法实现。 +2. 点击 runJavaScriptCodePassed 按钮,通过向前端传递自定义JavaScript代码改变颜色。 +3. 点击 Click Me! 按钮触发前端 callArkTS() 函数,开启交互逻辑,文本字体变红。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +无。 + +# Entry2: + +## 前端页面调用应用侧函数 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-in-page-app-function-invoking.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### JavaScriptProxy + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数。在Web组件初始化使用javaScriptProxy()接口注册应用侧代码。 + +#### 效果预览 + +| 主页 | 触发callArkTS | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击deleteJavaScriptRegister按钮从 Web 端删除已注册对象。 +1. 点击Click Me!按钮,触发callArkTS函数。 + +### Promise_one + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,Promise使用场景,在应用侧new Promise。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------ | +| | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将testObj注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### Promise_two + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,Promise使用场景,在前端页面new Promise。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------ | +| | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将 testObj 注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### RegisterJavaScriptProxy + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,在Web组件初始化使用registerJavaScriptProxy()接口注册应用侧代码。 + +#### 效果预览 + +| 主页 | 触发callArkTS | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将 testObj 注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### UsageOfComplexTypes_one + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,在应用侧和前端页面之间传递Array。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将 testObj 注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### UsageOfComplexTypes_two + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,应用侧和前端页面之间传递基础类型,非Function等复杂类型。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将 testObj 注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### UsageOfComplexTypes_three + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,应用侧调用前端页面的Callback。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将 testObj 注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### UsageOfComplexTypes_four + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,应用侧调用前端页面Object里的Function。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将 testObj 注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### UsageOfComplexTypes_five + +#### 介绍 + +1. 本示例主要介绍前端页面调用应用侧函数,前端页面调用应用侧Object里的Function。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击refresh按钮刷新网页。 +2. 点击Register JavaScript To Window按钮将 testObj 注册到前端。 +3. 点击deleteJavaScriptRegister按钮删除Web端注册的testObjName对象。 +4. 点击Click Me!按钮,触发callArkTS函数。 + +### 工程目录 + +``` +entry2/src/main/ +|---ets +|---|---entry2ability +|---|---|---Entry2Ability.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---JavaScriptProxy +|---|---|---Promise_one +|---|---|---Promise_two +|---|---|---RegisterJavaScriptProxy +|---|---|---UsageOfComplexTypes_one +|---|---|---UsageOfComplexTypes_two +|---|---|---UsageOfComplexTypes_three +|---|---|---UsageOfComplexTypes_four +|---|---|---UsageOfComplexTypes_five +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +# Entry3: + +## 建立应用侧与前端页面数据通道 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-app-page-data-channel.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | 向 HTML 发送消息 | 向 ArkTS 发送消息 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | | + +使用说明 + +1. 点击postMessage按钮初始化消息端口。 +2. 点击SendDataToHTML按钮从 ArkTS 向 ETS 发送消息。 +3. 点击SendToEts按钮,从 ETS 向 ArkTS 发送消息。 + +### 工程目录 + +``` +entry3/src/main/ +|---ets +|---|---entry3ability +|---|---|---Entry3Ability.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +无。 + +# Entry4: + +## 应用侧与前端页面的相互调用(C/C++) + +### 介绍 + +1. 实现对以下文档中提供的 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/arkweb-ndk-jsbridge.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击 runJS hello按钮调用testNapi.runJavaScript。 +2. 点击test Native Development Kit method1 !按钮调用testNdkProxyObjMethod1。 +3. 点击test Native Development Kit method2 !按钮调用testNdkProxyObjMethod2。 + +### 工程目录 + +``` +entry4/src/main/ +|---cpp // cpp文件夹 +|---ets +|---|---entry4ability +|---|---|---Entry4Ability.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +无。 + +# Entry5: + +## 建立应用侧与前端页面数据通道(C/C++) + +### 介绍 + +1. 实现对以下文档中提供中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/arkweb-ndk-page-data-channel.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | 通信 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击createNoControllerTagPort按钮ETS侧调用testNapi.createWebMessagePorts("noTag")。 +2. 点击createPort按钮ETS侧调用 testNapi.createWebMessagePorts(this.webTaag)。 +3. 点击setHandler按钮ETS侧调用testNapi.setMessageEventHandler(this.webTag(3)。 +4. 点击setHandlerThread按钮ETS侧调用 testNapi.setMessageEventHandlerThread(this.webTag)。 +5. 点击SendString按钮ETS侧清空h5Log,调用 testNapi.postMessage(this.webTag),通过消息端口将内容发送到前端页面。 + +### 工程目录 + +``` +entry5/src/main/ +|---cpp // cpp文件夹 +|---ets +|---|---entry5ability +|---|---|---Entry5Ability.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + + +### 相关权限 + +无。 + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/UseFrontendJSApp > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/build-profile.json5 b/ArkWeb/UseFrontendJSApp/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e4e9cf69682c02dcb930dfce613e32ab91914790 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/build-profile.json5 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry3", + "srcPath": "./entry3", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry4", + "srcPath": "./entry4", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry5", + "srcPath": "./entry5", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/code-linter.json5 b/ArkWeb/UseFrontendJSApp/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/.gitignore b/ArkWeb/UseFrontendJSApp/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/build-profile.json5 b/ArkWeb/UseFrontendJSApp/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/hvigorfile.ts b/ArkWeb/UseFrontendJSApp/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/UseFrontendJSApp/entry/obfuscation-rules.txt b/ArkWeb/UseFrontendJSApp/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/oh-package.json5 b/ArkWeb/UseFrontendJSApp/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..82e98bec44d83d2df03deb52508045cb06cc8604 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..29feaca7669174be5c2b0e2366529ee94ab7e726 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/ets/pages/Index.ets b/ArkWeb/UseFrontendJSApp/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e1a33e76b4c5114d9f50733e010812c4dfaa9a55 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start interact_with_web_pages_through_button_click_events] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + aboutToAppear() { + // 配置Web开启调试模式 + webview.WebviewController.setWebDebuggingAccess(true); + } + + build() { + Column() { + Button('runJavaScript') + .onClick(() => { + // 前端页面函数无参时,将param删除。 + this.webviewController.runJavaScript('htmlTest(param)'); + }) + Button('runJavaScriptCodePassed') + .onClick(() => { + // 传递runJavaScript侧代码方法。 + this.webviewController.runJavaScript( + `function changeColor(){document.getElementById('text').style.color = 'red'}`); + }) + Web({ src: $rawfile('index.html'), controller: this.webviewController }) + } + } +} +// [End interact_with_web_pages_through_button_click_events] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/module.json5 b/ArkWeb/UseFrontendJSApp/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/color.json b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/string.json b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8f7df8d295e8046511f2835416c9eea959c99657 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "UseFrontendJSApp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/background.png b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/en_US/element/string.json b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8f7df8d295e8046511f2835416c9eea959c99657 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "UseFrontendJSApp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..3db83981023a1e30aa99b51b7c0ac4be7ebf2bda --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,39 @@ + + + + + + + +

这是一个测试信息,默认字体为黑色,调用runJavaScript方法后字体为绿色,调用runJavaScriptCodePassed方法后字体为红色

+ + + diff --git a/ArkWeb/UseFrontendJSApp/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b060b52e82b9cbdf9b4cf441b8ebc77053cda9f4 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "UseFrontendJSApp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/mock/mock-config.json5 b/ArkWeb/UseFrontendJSApp/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..529c502db25b8b7edfc5ea420457241b8d374b9f --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用 + * 通过 runJavaScript 和 runJavaScriptExt 方法调用前端页面的JavaScript相关函数 + */ + it('testUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('runJavaScript')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('runJavaScriptCodePassed')); + await button2.click(); + await driver.delayMs(1000); + + const webButton = await driver.findComponent(ON.type('button')); + await webButton.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/module.json5 b/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry/src/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry/src/test/LocalUnit.test.ets b/ArkWeb/UseFrontendJSApp/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/.gitignore b/ArkWeb/UseFrontendJSApp/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/build-profile.json5 b/ArkWeb/UseFrontendJSApp/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/hvigorfile.ts b/ArkWeb/UseFrontendJSApp/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/UseFrontendJSApp/entry2/obfuscation-rules.txt b/ArkWeb/UseFrontendJSApp/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/oh-package.json5 b/ArkWeb/UseFrontendJSApp/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..dab8f3ea7260551b9dc6606eb397e396d241e701 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class Entry2Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..213e60d6187ea841335f6263f3072b8e1c20e395 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class Entry2BackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..730f850ab03976dfd6e0c92ad1dffdeacf6cad03 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('JavaScriptProxy') + .onClick(() => { + router.pushUrl({ url: 'pages/JavaScriptProxy' }); + }) + Button('Promise_one') + .onClick(() => { + router.pushUrl({ url: 'pages/Promise_one' }); + }) + Button('Promise_two') + .onClick(() => { + router.pushUrl({ url: 'pages/Promise_two' }); + }) + Button('RegisterJavaScriptProxy') + .onClick(() => { + router.pushUrl({ url: 'pages/RegisterJavaScriptProxy' }); + }) + Button('UsageOfComplexTypes_one') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_one' }); + }) + Button('UsageOfComplexTypes_two') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_two' }); + }) + Button('UsageOfComplexTypes_three') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_three' }); + }) + Button('UsageOfComplexTypes_four') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_four' }); + }) + Button('UsageOfComplexTypes_five') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_five' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/JavaScriptProxy.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/JavaScriptProxy.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1cd4cc07f1b04d30dc9cf8918b25cf8da7746eb --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/JavaScriptProxy.ets @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start functions_that_trigger_a_run_on_the_front_end_page_are_registered_in_the_front_end_page] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class TestClass { + constructor() { + } + + test(): string { + return 'ArkTS Hello World!'; + } +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + // 声明需要注册的对象 + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // Web组件加载本地index.html页面 + Web({ src: $rawfile('index1.html'), controller: this.webviewController}) + // 将对象注入到web端 + .javaScriptProxy({ + object: this.testObj, + name: 'testObjName', + methodList: ['test'], + controller: this.webviewController, + // 可选参数 + asyncMethodList: [], + permission: '{"javascriptProxyPermission":{"urlPermissionList":' + + '[{"scheme":"resource","host":"rawfile","port":"","path":""},' + + '{"scheme":"e","host":"f","port":"g","path":"h"}],"methodList":' + + '[{"methodName":"test","urlPermissionList":' + + '[{"scheme":"https","host":"xxx.com","port":"","path":""},' + + '{"scheme":"resource","host":"rawfile","port":"","path":""}]},' + + '{"methodName":"test11","urlPermissionList":' + + '[{"scheme":"q","host":"r","port":"","path":"t"},' + + '{"scheme":"u","host":"v","port":"","path":""}]}]}}' + }) + } + } +} +// [End functions_that_trigger_a_run_on_the_front_end_page_are_registered_in_the_front_end_page] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_one.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..df576803c18cdb35e48140459f394c0ad41faf46 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_one.ets @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start on_the_application_side_of_new_promise] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class TestClass { + constructor() { + } + + test(): Promise { + let p: Promise = new Promise((resolve, reject) => { + setTimeout(() => { + console.log('Execute Finished'); + reject('fail'); + }, 10000); + }); + return p; + } + + toString(param: String): void { + console.log(' ' + param); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString']); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index2.html'), controller: this.webviewController }) + } + } +} +// [End on_the_application_side_of_new_promise] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_two.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..67fdec8c5f3d40c406ceeac6190168faad1119a7 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_two.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start on_the_front_end_page_new_promise] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class TestClass { + constructor() { + } + + test(param:Function): void { + setTimeout( () => { param('suc') }, 10000) + } + + toString(param:String): void { + console.log(' ' + param); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString']); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index3.html'), controller: this.webviewController }) + } + } +} +// [End on_the_front_end_page_new_promise] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/RegisterJavaScriptProxy.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/RegisterJavaScriptProxy.ets new file mode 100644 index 0000000000000000000000000000000000000000..e69d1c30cccae8cbb61c9ef8072d23481eca3030 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/RegisterJavaScriptProxy.ets @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start application_side_api_registration] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class TestClass { + constructor() { + } + + test(): string { + return 'ArkUI Web Component'; + } + + toString(): void { + console.log('Web Component toString'); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString'], + // 可选参数, asyncMethodList + [], + // 可选参数, permission + '{"javascriptProxyPermission":{"urlPermissionList":' + + '[{"scheme":"resource","host":"rawfile","port":"","path":""},' + + '{"scheme":"e","host":"f","port":"g","path":"h"}],"methodList":' + + '[{"methodName":"test","urlPermissionList":' + + '[{"scheme":"https","host":"xxx.com","port":"","path":""},' + + '{"scheme":"resource","host":"rawfile","port":"","path":""}]},' + + '{"methodName":"test11","urlPermissionList":[{"scheme":"q","host":"r","port":"","path":"t"},' + + '{"scheme":"u","host":"v","port":"","path":""}]}]}}' + ); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index4.html'), controller: this.webviewController }) + } + } +} +// [End application_side_api_registration] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_five.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_five.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d284f5ddc539a42864c2a7fe68bc10be95c4ad6 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_five.ets @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start the_front_end_page_calls_the_function_in_the_object_on_the_application_side] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class ObjOther { + public methodNameListForJsProxy: string[]; + + constructor(list: string[]) { + this.methodNameListForJsProxy = list; + } + + testOther(json: string): void { + console.info(json); + } +} + +class TestClass { +public objReturn: ObjOther + + constructor() { + this.objReturn = new ObjOther(['testOther']); + } + + test(): ESObject { + return this.objReturn + } + + toString(param: string): void { + console.log('Web Component toString' + param); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString']); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index5.html'), controller: this.webviewController }) + } + } +} +// [End the_front_end_page_calls_the_function_in_the_object_on_the_application_side] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_four.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_four.ets new file mode 100644 index 0000000000000000000000000000000000000000..046d6e1c60674e9d5ca76fb13044fccb9b6c3388 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_four.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start call_the_function_in_the_object_of_the_front_end_page_on_the_application_side] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class TestClass { + constructor() { + } + + test(param: ESObject): void { + param.hello('call obj func'); + } + + toString(param: String): void { + console.log('Web Component toString' + param); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString']); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index6.html'), controller: this.webviewController }) + } + } +} +// [End call_the_function_in_the_object_of_the_front_end_page_on_the_application_side] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_one.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f115540320bebd5d2a69fc9c90e89ef13f76e9b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_one.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start pass_an_array_between_the_application_side_and_the_front_end_page] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class TestClass { + constructor() { + } + + test(): Array { + return [1, 2, 3, 4]; + } + + toString(param: String): void { + console.log('Web Component toString' + param); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString']); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index7.html'), controller: this.webviewController }) + } + } +} +// [End pass_an_array_between_the_application_side_and_the_front_end_page] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_three.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_three.ets new file mode 100644 index 0000000000000000000000000000000000000000..32d9ef6c5bee7edbda4c4e2ee6326717eddfbe3c --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_three.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start the_application_side_calls_the_callback_of_the_front_end_page] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class TestClass { + constructor() { + } + + test(param: Function): void { + param('call callback'); + } + + toString(param: String): void { + console.log('Web Component toString' + param); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString']); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index8.html'), controller: this.webviewController }) + } + } +} +// [End the_application_side_calls_the_callback_of_the_front_end_page] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_two.ets b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee4d7cbb90d72f446f6787797845c48ac385242a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_two.ets @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start the_base_type_is_passed_between_the_app_side_and_front_end_pages] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +class Student { + public name: string = ''; + public age: string = ''; +} + +class TestClass { + constructor() { + } + + // 传递的基础类型name:'jeck', age:'12'。 + test(): Student { + let st: Student = { name: 'jeck', age: '12' }; + return st; + } + + toString(param: ESObject): void { + console.log('Web Component toString' + param['name']); + } +} + +@Entry +@Component +struct Index { + webviewController: webview.WebviewController = new webview.WebviewController(); + @State testObj: TestClass = new TestClass(); + + build() { + Column() { + Button('refresh') + .onClick(() => { + try { + this.webviewController.refresh(); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('Register JavaScript To Window') + .onClick(() => { + try { + this.webviewController.registerJavaScriptProxy(this.testObj, 'testObjName', ['test', 'toString']); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('deleteJavaScriptRegister') + .onClick(() => { + try { + this.webviewController.deleteJavaScriptRegister('testObjName'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index9.html'), controller: this.webviewController }) + } + } +} +// [End the_base_type_is_passed_between_the_app_side_and_front_end_pages] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/module.json5 b/ArkWeb/UseFrontendJSApp/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..90a4604809422135bc23f5a1d55f88ba15ad078d --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/module.json5 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry2", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry2BackupAbility", + "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/string.json b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7c88d8349f6a73dadf4933bc4f150cb016a226fe --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry2Ability_desc", + "value": "description" + }, + { + "name": "Entry2Ability_label", + "value": "UseFrontendJSApp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/layered_image.json b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/main_pages.json b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..85f81c85c48178478853558030d3f675380df813 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,14 @@ +{ + "src": [ + "pages/Index", + "pages/JavaScriptProxy", + "pages/RegisterJavaScriptProxy", + "pages/Promise_one", + "pages/Promise_two", + "pages/UsageOfComplexTypes_one", + "pages/UsageOfComplexTypes_two", + "pages/UsageOfComplexTypes_three", + "pages/UsageOfComplexTypes_four", + "pages/UsageOfComplexTypes_five" + ] +} diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html new file mode 100644 index 0000000000000000000000000000000000000000..f191e18ba4a95fff3e0c00a06b8efc58042bed0e --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html @@ -0,0 +1,29 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index2.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index2.html new file mode 100644 index 0000000000000000000000000000000000000000..7ce3b4e0f6e7224d2d374d758218d12762074285 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index2.html @@ -0,0 +1,27 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index3.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index3.html new file mode 100644 index 0000000000000000000000000000000000000000..e8d5f8a4bc6bb2a5e7c71dd1755b2163640762d4 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index3.html @@ -0,0 +1,30 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index4.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index4.html new file mode 100644 index 0000000000000000000000000000000000000000..f191e18ba4a95fff3e0c00a06b8efc58042bed0e --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index4.html @@ -0,0 +1,29 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index5.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index5.html new file mode 100644 index 0000000000000000000000000000000000000000..39411f1290bcb77735a74018e21440838badf590 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index5.html @@ -0,0 +1,27 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index6.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index6.html new file mode 100644 index 0000000000000000000000000000000000000000..139cccc5c8e66579033566092b69e28f256fc329 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index6.html @@ -0,0 +1,51 @@ + + + + + + +

+ + + diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index7.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index7.html new file mode 100644 index 0000000000000000000000000000000000000000..a40f4ca5f942a89dd8b4fc5867302f142e3c53dd --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index7.html @@ -0,0 +1,27 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index8.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index8.html new file mode 100644 index 0000000000000000000000000000000000000000..b7092a6123176ec10e701a02f16b038a80db4fc3 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index8.html @@ -0,0 +1,27 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index9.html b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index9.html new file mode 100644 index 0000000000000000000000000000000000000000..a40f4ca5f942a89dd8b4fc5867302f142e3c53dd --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index9.html @@ -0,0 +1,27 @@ + + + + + + +

+ + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/mock/mock-config.json5 b/ArkWeb/UseFrontendJSApp/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe6e745d6402255deda1eb8eaae4ead04782fd0c --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 JavaScriptProxy 按钮 + * 在Web组件初始化使用 javaScriptProxy 接口注册应用侧代码 + */ + it('JavaScriptProxy', 0, async (done: Function) => { + console.info('uitest: JavaScriptProxy begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry2Ability' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Entry2Ability'); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('JavaScriptProxy')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.type('button')); + await button3.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index1.html'); + + await driver.pressBack(); + console.info('uitest: JavaScriptProxy end'); + done(); + }); + + /* + * 点击 Promise_one 按钮 + * 使用Promise使用场景 + */ + it('Promise_one', 0, async (done: Function) => { + console.info('uitest: Promise_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('Promise_one')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + await driver.pressBack(); + console.info('uitest: Promise_one end'); + done(); + }); + + /* + * 点击 Promise_two 按钮 + * 使用Promise使用场景 + */ + it('Promise_two', 0, async (done: Function) => { + console.info('uitest: Promise_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('Promise_two')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + await driver.pressBack(); + console.info('uitest: Promise_two end'); + done(); + }); + + /* + * 点击 RegisterJavaScriptProxy 按钮 + * 使用 registerJavaScriptProxy 接口注册应用侧代码 + */ + it('RegisterJavaScriptProxy', 0, async (done: Function) => { + console.info('uitest: RegisterJavaScriptProxy begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('RegisterJavaScriptProxy')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index4.html'); + + await driver.pressBack(); + console.info('uitest: RegisterJavaScriptProxy end'); + done(); + }); + + /* + * 点击 UsageOfComplexTypes_one 按钮 + * 在应用侧和前端页面之间传递Array + */ + it('UsageOfComplexTypes_one', 0, async (done: Function) => { + console.info('uitest: UsageOfComplexTypes_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UsageOfComplexTypes_one')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index7.html'); + + await driver.pressBack(); + console.info('uitest: UsageOfComplexTypes_one end'); + done(); + }); + + /* + * 点击 UsageOfComplexTypes_two 按钮 + * 应用侧和前端页面之间传递基础类型,非Function等复杂类型 + */ + it('UsageOfComplexTypes_two', 0, async (done: Function) => { + console.info('uitest: UsageOfComplexTypes_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UsageOfComplexTypes_two')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index9.html'); + + await driver.pressBack(); + console.info('uitest: UsageOfComplexTypes_two end'); + done(); + }); + + /* + * 点击 UsageOfComplexTypes_three 按钮 + * 使用应用侧调用前端页面的Callback + */ + it('UsageOfComplexTypes_three', 0, async (done: Function) => { + console.info('uitest: UsageOfComplexTypes_three begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UsageOfComplexTypes_three')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index8.html'); + + await driver.pressBack(); + console.info('uitest: UsageOfComplexTypes_three end'); + done(); + }); + + /* + * 点击 UsageOfComplexTypes_four 按钮 + * 应用侧调用前端页面Object里的Function + */ + it('UsageOfComplexTypes_four', 0, async (done: Function) => { + console.info('uitest: UsageOfComplexTypes_four begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UsageOfComplexTypes_four')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index6.html'); + + await driver.pressBack(); + console.info('uitest: UsageOfComplexTypes_four end'); + done(); + }); + + /* + * 点击 UsageOfComplexTypes_five 按钮 + * 前端页面调用应用侧Object里的Function + */ + it('UsageOfComplexTypes_five', 0, async (done: Function) => { + console.info('uitest: UsageOfComplexTypes_five begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('UsageOfComplexTypes_five')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('refresh')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Register JavaScript To Window')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('deleteJavaScriptRegister')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.type('button')); + await button5.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index5.html'); + + console.info('uitest: UsageOfComplexTypes_five end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/module.json5 b/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17410acb16bcc114982071879ee6b1f000794e19 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry2/src/test/LocalUnit.test.ets b/ArkWeb/UseFrontendJSApp/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry2/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/.gitignore b/ArkWeb/UseFrontendJSApp/entry3/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/build-profile.json5 b/ArkWeb/UseFrontendJSApp/entry3/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/hvigorfile.ts b/ArkWeb/UseFrontendJSApp/entry3/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/UseFrontendJSApp/entry3/obfuscation-rules.txt b/ArkWeb/UseFrontendJSApp/entry3/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/oh-package.json5 b/ArkWeb/UseFrontendJSApp/entry3/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..655d244a4ec5c8e387d7ebfb66967132c8c952f6 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry3", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..e62e0723b2780a459f90447d95ff110ba058fc00 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class Entry3Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/pages/Index.ets b/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..fbd0bd1bab826fdc2c0ad69c882481ee047fe643 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/pages/Index.ets @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start create_a_message_port_to_implement_communication_between_the_two_ends] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + ports: webview.WebMessagePort[] = []; + @State sendFromEts: string = 'Send this message from ets to HTML'; + @State receivedFromHtml: string = 'Display received message send from HTML'; + + build() { + Column() { + // Display the content received from the HTML side. + Text(this.receivedFromHtml) + // Send the content in the text box to the HTML side. + TextInput({ placeholder: 'Send this message from ets to HTML' }) + .onChange((value: string) => { + this.sendFromEts = value; + }) + + // The following can be called in the onPageEnd lifecycle callback. + Button('postMessage') + .onClick(() => { + try { + // 1. Create two message ports. + this.ports = this.controller.createWebMessagePorts(); + // 2. Register a callback for the message port (for example, port 1) on the application. + this.ports[1].onMessageEvent((result: webview.WebMessage) => { + let msg = 'Got msg from HTML:'; + if (typeof (result) === 'string') { + console.info(`received string message from html5, string is: ${result}`); + msg = msg + result; + } else if (typeof (result) === 'object') { + if (result instanceof ArrayBuffer) { + console.info(`received arraybuffer from html5, length is: ${result.byteLength}`); + msg = msg + 'length is ' + result.byteLength; + } else { + console.info('not support'); + } + } else { + console.info('not support'); + } + this.receivedFromHtml = msg; + }) + // 3. Send the other message port (for example, port 0) to + // the HTML side, which then saves the message port. + this.controller.postMessage('__init_port__', [this.ports[0]], '*'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + + // 4. Use the message port on the application to send messages to + // the message port that has been sent to the HTML side. + Button('SendDataToHTML') + .onClick(() => { + try { + if (this.ports && this.ports[1]) { + this.ports[1].postMessageEvent(this.sendFromEts); + } else { + console.error(`ports is null, Please initialize first`); + } + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index.html'), controller: this.controller }) + } + } +} +// [End create_a_message_port_to_implement_communication_between_the_two_ends] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/module.json5 b/ArkWeb/UseFrontendJSApp/entry3/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a9345ab1e0f0dbf59e896cd74d2ced8094e7fb9b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry3", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry3Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry3Ability", + "srcEntry": "./ets/entry3ability/Entry3Ability.ets", + "description": "$string:Entry3Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry3Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/string.json b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1253ae78eed82312b6c4db8b1a11dc6baee5f27c --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry3Ability_desc", + "value": "description" + }, + { + "name": "Entry3Ability_label", + "value": "UseFrontendJSApp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/layered_image.json b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..7e67007432b4e000fab6254a4fd81bd071066193 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html @@ -0,0 +1,69 @@ + + + + + + + WebView Message Port Demo + + +

WebView Message Port Demo

+
+ +
+
+

display received message send from ets

+ + + diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/mock/mock-config.json5 b/ArkWeb/UseFrontendJSApp/entry3/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..909b4cebec67c5b9af51626c88043ac152a69906 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用 + * 建立应用侧与前端页面数据通道 + */ + it('testUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry3Ability' + } + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Entry3Ability'); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('postMessage')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('SendDataToHTML')); + await button2.click(); + await driver.delayMs(1000); + + const webButton = await driver.findComponent(ON.type('button')); + await webButton.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/module.json5 b/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..edaba8aaabfc3819914b5d624d6d0143e85b5b86 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry3_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry3/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry3/src/test/LocalUnit.test.ets b/ArkWeb/UseFrontendJSApp/entry3/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry3/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/.gitignore b/ArkWeb/UseFrontendJSApp/entry4/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/build-profile.json5 b/ArkWeb/UseFrontendJSApp/entry4/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fea31f4580540c7c560b62bf531292c471c410f1 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/build-profile.json5 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/hvigorfile.ts b/ArkWeb/UseFrontendJSApp/entry4/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/UseFrontendJSApp/entry4/obfuscation-rules.txt b/ArkWeb/UseFrontendJSApp/entry4/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/oh-package.json5 b/ArkWeb/UseFrontendJSApp/entry4/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..00f4289f03ded4fc5b05708a28cd06c44a0ad53e --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry4", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry4.so": "file:./src/main/cpp/types/libentry4" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..14607faba853fe717a19495cfc2364bc8be66216 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt @@ -0,0 +1,24 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(NDKJSBridg) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED hello.cpp jsbridge_object.cpp) + +find_library( + # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z +) + +target_link_libraries(entry PUBLIC libace_napi.z.so ${hilog-lib} libohweb.so) \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..096575c6a7109a5cb714c7a936f28dfc0019aebb --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start node_api_layer_code] +#include "napi/native_api.h" +#include +#include +#include +#include +#include + +#include "hilog/log.h" +#include "web/arkweb_interface.h" +#include "jsbridge_object.h" + +constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; +std::shared_ptr jsbridge_object_ptr = nullptr; +static ArkWeb_ControllerAPI *controller = nullptr; +static ArkWeb_ComponentAPI *component = nullptr; + +// 发送JS脚本到H5侧执行,该方法为执行结果的回调。 +static void RunJavaScriptCallback(const char *webTag, const char *result, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit RunJavaScriptCallback webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit RunJavaScriptCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->RunJavaScriptCallback(result); + } else { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit RunJavaScriptCallback jsb_weak_ptr lock failed"); + } +} + +// 示例代码 ,注册了1个对象,2个方法 +static void ProxyMethod1( + const char *webTag, const ArkWeb_JavaScriptBridgeData *dataArray, size_t arraySize, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod1 webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod1 userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->ProxyMethod1(dataArray, arraySize); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod1 jsb_weak_ptr lock failed"); + } +} + +static void ProxyMethod2( + const char *webTag, const ArkWeb_JavaScriptBridgeData *dataArray, size_t arraySize, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod2 webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod2 userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + + std::string jsCode = "runJSRetStr()"; + ArkWeb_JavaScriptObject object = { + (uint8_t *)jsCode.c_str(), jsCode.size(), + &JSBridgeObject::StaticRunJavaScriptCallback, + static_cast(jsbridge_object_ptr->GetWeakPtr()) + }; + controller->runJavaScript(webTag, &object); + + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->ProxyMethod2(dataArray, arraySize); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod2 JsWeakPtr lock failed"); + } +} + +void ValidCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ValidCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ValidCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("ValidCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ValidCallback jsb_weak_ptr lock failed"); + } + + // [Start the_front_end_page_calls_application_side_functions] + // 注册对象 + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit RegisterJavaScriptProxy begin"); + ArkWeb_ProxyMethod method1 = {"method1", ProxyMethod1, static_cast(jsbridge_object_ptr->GetWeakPtr())}; + ArkWeb_ProxyMethod method2 = {"method2", ProxyMethod2, static_cast(jsbridge_object_ptr->GetWeakPtr())}; + ArkWeb_ProxyMethod methodList[2] = {method1, method2}; + // 调用Native Development Kit接口注册对象 + // 如此注册的情况下,在H5页面就可以使用proxy.method1、proxy.method1调用此文件下的ProxyMethod1和ProxyMethod2方法了 + ArkWeb_ProxyObject proxyObject = {"ndkProxy", methodList, 2}; + controller->registerJavaScriptProxy(webTag, &proxyObject); + // [End the_front_end_page_calls_application_side_functions] + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit RegisterJavaScriptProxy end"); +} + +void LoadStartCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadStartCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadStartCallback userData is null"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("LoadStartCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, + "ArkWeb", "Native Development Kit LoadStartCallback jsb_weak_ptr lock failed"); + } +} + +void LoadEndCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadEndCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadEndCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("LoadEndCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadEndCallback jsb_weak_ptr lock failed"); + } +} + +void DestroyCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit DestoryCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit DestroyCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("DestroyCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit DestroyCallback jsb_weak_ptr lock failed"); + } +} + +void SetComponentCallback(ArkWeb_ComponentAPI * component, const char* webTagValue) +{ + // [Start the_native_side_registers_the_callback_of_the_component_lifecycle] + if (!ARKWEB_MEMBER_MISSING(component, onControllerAttached)) { + component->onControllerAttached( + webTagValue, ValidCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onControllerAttached func not exist"); + } + + if (!ARKWEB_MEMBER_MISSING(component, onPageBegin)) { + component->onPageBegin(webTagValue, LoadStartCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onPageBegin func not exist"); + } + + if (!ARKWEB_MEMBER_MISSING(component, onPageEnd)) { + component->onPageEnd(webTagValue, LoadEndCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onPageEnd func not exist"); + } + + if (!ARKWEB_MEMBER_MISSING(component, onDestroy)) { + component->onDestroy(webTagValue, DestroyCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onDestroy func not exist"); + } + // [End the_native_side_registers_the_callback_of_the_component_lifecycle] +} + +// [Start parse_and_store_webtags] +// 解析存储webTag +static napi_value NativeWebInit(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit NativeWebInit webTag:%{public}s", webTagValue); + + // 将webTag保存在实例对象中 + jsbridge_object_ptr = std::make_shared(webTagValue); + if (jsbridge_object_ptr) + jsbridge_object_ptr->Init(); +// [End parse_and_store_webtags] + + controller = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_CONTROLLER)); + component = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_COMPONENT)); + SetComponentCallback(component, webTagValue); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit end"); + return nullptr; +} + +// 发送JS脚本到H5侧执行 +static napi_value RunJavaScript(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit OH_NativeArkWeb_RunJavaScript webTag:%{public}s", webTagValue); + + // 获取第二个参数 jsCode + size_t bufferSize = 0; + napi_get_value_string_utf8(env, args[1], nullptr, 0, &bufferSize); + char *jsCode = new (std::nothrow) char[bufferSize + 1]; + size_t byteLength = 0; + napi_get_value_string_utf8(env, args[1], jsCode, bufferSize + 1, &byteLength); + + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit OH_NativeArkWeb_RunJavaScript jsCode len:%{public}zu", strlen(jsCode)); + + // 构造runJS执行的结构体 + ArkWeb_JavaScriptObject object = {(uint8_t *)jsCode, bufferSize, &JSBridgeObject::StaticRunJavaScriptCallback, + static_cast(jsbridge_object_ptr->GetWeakPtr())}; + controller->runJavaScript(webTagValue, &object); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"nativeWebInit", nullptr, NativeWebInit, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"runJavaScript", nullptr, RunJavaScript, nullptr, nullptr, nullptr, napi_default, nullptr}, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +// [End node_api_layer_code] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b35bebbf50225c26290f8e4bc93d2feffa358523 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start handles_javascript_calls_from_webview] +#include "jsbridge_object.h" + +#include "hilog/log.h" + +constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; + +JSBridgeObject::JSBridgeObject(const char *webTag) : webTag_(webTag) {} + +void JSBridgeObject::Init() { weak_ptr_ = shared_from_this(); } + +std::weak_ptr *JSBridgeObject::GetWeakPtr() { return &weak_ptr_; } + +void JSBridgeObject::StaticRunJavaScriptCallback( + const char *webTag, const ArkWeb_JavaScriptBridgeData *data, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject StaticRunJavaScriptCallback webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject StaticRunJavaScriptCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + std::string result((char *)data->buffer, data->size); + jsb_ptr->RunJavaScriptCallback(result.c_str()); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject StaticRunJavaScriptCallback jsb_weak_ptr lock failed"); + } +} + +void JSBridgeObject::RunJavaScriptCallback(const char *result) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject OH_NativeArkWeb_RunJavaScript result:%{public}s", result); +} + +void JSBridgeObject::ProxyMethod1(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "JSBridgeObject ProxyMethod1 argc:%{public}d", + arraySize); + for (int i = 0; i < arraySize; i++) { + std::string result((char *)dataArray[i].buffer, dataArray[i].size); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject ProxyMethod1 argv[%{public}d]:%{public}s, size:%{public}d", + i, result.c_str(), dataArray[i].size); + } +} + +void JSBridgeObject::ProxyMethod2(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject ProxyMethod2 argc:%{public}d", arraySize); + for (int i = 0; i < arraySize; i++) { + std::string result((char *)dataArray[i].buffer, dataArray[i].size); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject ProxyMethod2 argv[%{public}d]:%{public}s, size:%{public}d", + i, result.c_str(), dataArray[i].size); + } +} + +void JSBridgeObject::SaySomething(const char *say) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "JSBridgeObject SaySomething argc:%{public}s", say); +} +// [End handles_javascript_calls_from_webview] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h new file mode 100644 index 0000000000000000000000000000000000000000..68d1e15bdcdbce0885d887cba00ee53264ed9edb --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h @@ -0,0 +1,40 @@ +#ifndef HEADER_GUARD_H +#define HEADER_GUARD_H +/* + * Copyright (c) 2025 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. + */ + +// [Start the_service_code_on_the_native_side] +#include "web/arkweb_type.h" +#include + +class JSBridgeObject : public std::enable_shared_from_this { +public: + explicit JSBridgeObject(const char* webTag); + ~JSBridgeObject() = default; + void Init(); + std::weak_ptr* GetWeakPtr(); + static void StaticRunJavaScriptCallback(const char *webTag, const ArkWeb_JavaScriptBridgeData *data, + void *userData); + void RunJavaScriptCallback(const char *result); + void ProxyMethod1(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize); + void ProxyMethod2(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize); + void SaySomething(const char* say); + +private: + std::string webTag_; + std::weak_ptr weak_ptr_; +}; +// [End the_service_code_on_the_native_side] +#endif // HEADER_GUARD_H \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..820107b7d23aac8e97b4f6ce2d6517ea2eea824b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a12836b52e43cb6d1b8cff089e191a95b44f40a8 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start the_arkts_interface_is_exposed_on_the_node_api_side] +export const nativeWebInit: (webName: string) => void; +export const runJavaScript: (webName: string, jsCode: string) => void; +// [End the_arkts_interface_is_exposed_on_the_node_api_side] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1228596cfe7eb84f89b7125abb95de5246a5829c --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "libentry4.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets b/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..84e3ab74f2a987f3a4cf9c6e380c5901b3491478 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class Entry4Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets b/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a21a25554a682bc942ffee2a5b9a2beb088123a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start interact_with_the_webview_via_the_native_api] +// [Start use_the_native_interface_to_bind_arkweb] +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; + +class testObj { + constructor() { + } + + test(): string { + console.log('ArkUI Web Component'); + return 'ArkUI Web Component'; + } + + toString(): void { + console.log('Web Component toString'); + } +} + +@Entry +@Component +struct Index { + // [Start customize_a_webtag_and_send_it_to_the_native_side_of_the_application] + webTag: string = 'ArkWeb1'; + controller: webview.WebviewController = new webview.WebviewController(this.webTag); + @State testObjtest: testObj = new testObj(); + + aboutToAppear() { + console.info('aboutToAppear'); + //初始化web Native Development Kit + testNapi.nativeWebInit(this.webTag); + // [End customize_a_webtag_and_send_it_to_the_native_side_of_the_application] + } + // [End use_the_native_interface_to_bind_arkweb] + + build() { + Column() { + Row() { + Button('runJS hello') + .fontSize(12) + .onClick(() => { + testNapi.runJavaScript(this.webTag, 'runJSRetStr(\"" + "hello" + "\")'); + }) + }.height('20%') + + Row() { + Web({ src: $rawfile('runJS.html'), controller: this.controller }) + .javaScriptAccess(true) + .fileAccess(true) + .onControllerAttached(() => { + console.error('Native Development Kit onControllerAttached webId: ' + this.controller.getWebId()); + }) + }.height('80%') + } + } +} +// [End interact_with_the_webview_via_the_native_api] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/module.json5 b/ArkWeb/UseFrontendJSApp/entry4/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..afa13b4ebdc29a9cb812bfbb16d66e97039a14e5 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry4", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry4Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry4Ability", + "srcEntry": "./ets/entry4ability/Entry4Ability.ets", + "description": "$string:Entry4Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry4Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/string.json b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..12e68f45a4cdb0af57c32b313a820ea8d23af66b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry4Ability_desc", + "value": "description" + }, + { + "name": "Entry4Ability_label", + "value": "UseFrontendJSApp" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/layered_image.json b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html new file mode 100644 index 0000000000000000000000000000000000000000..a6ebe9e4665f309fd2ecbe9b256af033154bb055 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html @@ -0,0 +1,93 @@ + + + + + + + + + run javascript demo + + +

run JavaScript Ext demo

+

+
+ +
+
+ +
+ + + + \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/mock/Libentry4.mock.ets b/ArkWeb/UseFrontendJSApp/entry4/src/mock/Libentry4.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..37c4693badee0bced9f50f020403147ada0e8d44 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/mock/Libentry4.mock.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +const nativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default nativeMock; \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/mock/mock-config.json5 b/ArkWeb/UseFrontendJSApp/entry4/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cccc61410df447034f1a89e4dae104448202f02a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/mock/mock-config.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "libentry4.so": { + "source": "src/mock/Libentry4.mock.ets" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9be87be5508277dddc4e036c2c687d47c3f302a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用 + * 使用应用侧与前端页面的相互调用 + */ + it('testUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry4Ability' + } + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Entry4Ability'); + await driver.delayMs(5000); + + const indexButton = await driver.findComponent(ON.type('Button')); + const webButton = await driver.findComponent(ON.type('button')); + + await webButton.click(); + await driver.delayMs(1000); + + await indexButton.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('runJS.html'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/module.json5 b/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..12ba91e94655586fb5e48c90b290e66be7e85db2 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry4_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry4/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry4/src/test/LocalUnit.test.ets b/ArkWeb/UseFrontendJSApp/entry4/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry4/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/.gitignore b/ArkWeb/UseFrontendJSApp/entry5/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/build-profile.json5 b/ArkWeb/UseFrontendJSApp/entry5/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fea31f4580540c7c560b62bf531292c471c410f1 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/build-profile.json5 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/hvigorfile.ts b/ArkWeb/UseFrontendJSApp/entry5/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/UseFrontendJSApp/entry5/obfuscation-rules.txt b/ArkWeb/UseFrontendJSApp/entry5/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/oh-package.json5 b/ArkWeb/UseFrontendJSApp/entry5/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b58415e4585a7d2d30f02bba160d4401c9575b19 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry5", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry5.so": "file:./src/main/cpp/types/libentry5" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..46be202fc230d85a6eade7ed2cedec2ad189af17 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt @@ -0,0 +1,25 @@ +# entry/src/main/cpp/CMakeLists.txt +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(NDKPostMessage) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED hello.cpp) + +find_library( + # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z +) + +target_link_libraries(entry PUBLIC libace_napi.z.so ${hilog-lib} libohweb.so) diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cde6ffb2e4639d3818c096981f9a6a07ecb74453 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp @@ -0,0 +1,469 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start the_node_api_layer_code_for_the_data_channel_between_the_application_side_and_the_frontend_page] +#include "napi/native_api.h" +#include +#include +#include +#include +#include +#include +#include "hilog/log.h" +#include "web/arkweb_interface.h" +#include + +constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; +ArkWeb_ControllerAPI *controller = nullptr; + +ArkWeb_WebMessagePortAPI *webMessagePort = nullptr; +ArkWeb_WebMessageAPI *webMessage = nullptr; +size_t g_webMessagePortSize = 0; +ArkWeb_WebMessagePortPtr *g_web_message_port_arr = nullptr; + +static void WebMessagePortCallback( + const char *webTag, const ArkWeb_WebMessagePortPtr port, const ArkWeb_WebMessagePtr message, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit WebMesagePortCallback webTag:%{public}s,messageType:%{public}d", + webTag, webMessage->getType(message)); + size_t len = 0; + void *back = webMessage->getData(message, &len); + if (webMessage->getType(message) == ArkWeb_WebMessageType::ARKWEB_STRING) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit WebMesagePortCallback message:%{public}s,messageSize:%{public}d", back, len); + } else if (webMessage->getType(message) == ArkWeb_WebMessageType::ARKWEB_BUFFER) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit WebMesagePortCallback messageSize:%{public}d", len); + } +} + +static napi_value NativeWebInit(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit NativeWebInit webTag:%{public}s", webTagValue); + + controller = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_CONTROLLER)); + if (controller) + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_ControllerAPI success"); + + webMessagePort = + reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_WEB_MESSAGE_PORT)); + if (webMessagePort) + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_WebMessagePortAPI success"); + + webMessage = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_WEB_MESSAGE)); + if (webMessage) + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_WebMessageAPI success"); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit end"); + + return nullptr; +} + +static napi_value createWebMessagePorts(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 初始化端口 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit createWebMessagePorts begin"); + g_web_message_port_arr = controller->createWebMessagePorts(webTagValue, &g_webMessagePortSize); + // 把其中一个端口发送给HTML + ArkWeb_ErrorCode code = + controller->postWebMessage(webTagValue, "init_web_messageport", g_web_message_port_arr, 1, "*"); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postWebMessage ArkWeb_ErrorCode:%{public}d", code); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit createWebMessagePorts end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value postMessage(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 发送消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); + webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_STRING); + std::string str = "send string from native"; + webMessage->setData(message, (void *)str.c_str(), str.length() + 1); + ArkWeb_ErrorCode code = webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage ArkWeb_ErrorCode:%{public}d", code); + webMessage->destroyWebMessage(&message); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + + +// 在线程中发消息 +void sendMessage(const char *webTag, const ArkWeb_WebMessagePtr message) +{ + // 发送1000次 + for (int i = 0; i < 1000; i++) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "sendMessage in thread %{public}d", i); + if (g_web_message_port_arr && webTag && message) { + webMessagePort->postMessage(g_web_message_port_arr[1], webTag, message); + } + } +} +static napi_value postMessageThread(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 构造消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); + webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_STRING); + std::string str = "thread message"; + webMessage->setData(message, (void *)str.c_str(), str.length() + 1); + const int numThreads = 5; + std::thread threads[numThreads]; + + // 创建线程 + for (int i = 0; i < numThreads; ++i) { + threads[i] = std::thread(sendMessage, webTagValue, message); + } + + // 等待所有线程完成 + for (int i = 0; i < numThreads; ++i) { + threads[i].detach(); + } + return nullptr; +} + +// 在线程中注册回调 +void SetHandler(const char *webTag) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "setMessageEventHandler in thread"); + webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTag, WebMessagePortCallback, NULL); +} + +static napi_value setMessageEventHandlerThread(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 注册回调 + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + std::thread thread(SetHandler, webTagValue); + thread.detach(); + webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTagValue, WebMessagePortCallback, NULL); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} +static napi_value postNoneMessage(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, + "ArkWeb", "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 发送消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit 发消息开始"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); + webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_NONE); + std::string str = "send string from native"; + webMessage->setData(message, (void *)str.c_str(), str.length() + 1); + webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message); + webMessage->destroyWebMessage(&message); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value postBufferMessage(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 发送消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message1 = webMessage->createWebMessage(); + webMessage->setType(message1, ArkWeb_WebMessageType::ARKWEB_BUFFER); + std::string str1 = "send buffer from native"; + webMessage->setData(message1, (void *)str1.c_str(), str1.length()); + webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message1); + webMessage->destroyWebMessage(&message1); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value setMessageEventHandler(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 注册回调 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTagValue, WebMessagePortCallback, NULL); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value closeMessagePort(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 关闭端口,先调用close,再调用destroyWebMessagePorts + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + webMessagePort->close(g_web_message_port_arr[0], webTagValue); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + controller->refresh(webTagValue); + return nullptr; +} + +static napi_value destroyMessagePort(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 释放内存,先调用close,再调用destroyWebMessagePorts + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + controller->destroyWebMessagePorts(&g_web_message_port_arr, g_webMessagePortSize); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value destroyNullMessagePort(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 释放内存,先调用close,再调用destroyWebMessagePorts + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + + controller->destroyWebMessagePorts(&g_web_message_port_arr, g_webMessagePortSize); + + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"nativeWebInit", nullptr, NativeWebInit, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createWebMessagePorts", nullptr, createWebMessagePorts, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postMessage", nullptr, postMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postNoneMessage", nullptr, postNoneMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postBufferMessage", nullptr, postBufferMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setMessageEventHandler", nullptr, setMessageEventHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"closeMessagePort", nullptr, closeMessagePort, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"destroyMessagePort", nullptr, destroyMessagePort, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postMessageThread", nullptr, postMessageThread, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setMessageEventHandlerThread", nullptr, setMessageEventHandlerThread, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"destroyNullMessagePort", nullptr, destroyNullMessagePort, nullptr, nullptr, nullptr, napi_default, nullptr}, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +// [End the_node_api_layer_code_for_the_data_channel_between_the_application_side_and_the_frontend_page] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c11c8b57c075b5322df845f7fdc371f8b49caa0 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..85deb09b85692e2643ef2057b9011afe4882f293 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start the_arkts_interface_is_exposed_on_the_node_api_side] +export const nativeWebInit: (webName: string) => void; +export const createWebMessagePorts: (webName: string) => void; +export const postMessage: (webName: string) => void; +export const postNoneMessage: (webName: string) => void; +export const setMessageEventHandler: (webName: string) => void; +export const closeMessagePort: (webName: string) => void; +export const destroyMessagePort: (webName: string) => void; +export const postBufferMessage: (webName: string) => void; +export const destroyNullMessagePort: (webName: string) => void; +export const setMessageEventHandlerThread: (webName: string) => void; +export const postMessageThread: (webName: string) => void; +// [End the_arkts_interface_is_exposed_on_the_node_api_side] \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..98c81afabac4d3f9d57c741379ffcd83981d7741 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "libentry5.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets b/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0e606032c1d06947096a1714fd9401b639ac132 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class Entry5Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets b/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..95128ad57412a7dee67713db44efc8f717855f31 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets @@ -0,0 +1,274 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start webview_and_native_modules_are_used_to_implement_complex_message_interaction_between_applications_and_h5_pages] +import testNapi from 'libentry.so'; +import web_webview from '@ohos.web.webview'; +import { BusinessError } from '@ohos.base'; + +@Entry +@Component +struct Index { + @State webTag: string = 'postMessage'; + controller: web_webview.WebviewController = new web_webview.WebviewController(this.webTag); + @State h5Log: string = 'Display received message send from HTML'; + + aboutToAppear() { + web_webview.WebviewController.setWebDebuggingAccess(true); + // 初始化web Native Development Kit + testNapi.nativeWebInit(this.webTag); + } + + aboutToDisAppear() { + console.error('aboutToDisAppear'); + } + + build() { + Scroll() { + Column({ space: 10 }) { + // 展示H5接收到的内容 + Text($r('app.string.H5_Side_Message_Display_From_App')) + TextArea({text: this.h5Log}) + .id('log_area') + .width('100%') + .height(100) + .border({ width: 1 }) + Text($r('app.string.App_Side_Button')) + Row() { + Button('createNoControllerTagPort') + .id('create_no_tag_btn') + .onClick(() => { + try { + testNapi.createWebMessagePorts('noTag'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('createPort') + .id('create_port_btn') + .onClick(() => { + try { + testNapi.createWebMessagePorts(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + + Button('setHandler') + .id('set_handler_btn') + .onClick(() => { + try { + testNapi.setMessageEventHandler(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + + Button('setHandlerThread') + .id('set_handler_thread_btn') + .onClick(() => { + try { + testNapi.setMessageEventHandlerThread(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + Button('SendString') + .id('send_string_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postMessage(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('SendStringThread') + .id('send_string_thread_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postMessageThread(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + Button('SendBuffer') + .id('send_buffer_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postBufferMessage(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('SendNone') + .id('send_none_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postNoneMessage(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + + Button('closePort') + .id('close_port_btn') + .onClick(() => { + try { + testNapi.closeMessagePort(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('destroyNullPort') + .id('destroy_null_btn') + .onClick(() => { + try { + testNapi.destroyNullMessagePort(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('destroyPort') + .id('destroy_port_btn') + .onClick(() => { + try { + testNapi.destroyMessagePort(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + .width('100%') + .padding(10) + .border({ width: 1 }) + + Column({ space: 10 }) { + Text($r('app.string.H5_Side_Send_Button')) + Row({ space: 10 }) { + Button('H5String') + .id('h5_send_string_btn') + .onClick(() => { + try { + this.controller.runJavaScript('for(var i = 0; i < 2000; i++) postStringToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Buffer') + .id('h5_send_buffer_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postBufferToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Number') + .id('h5_send_number_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postNumberToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + Button('H5Json') + .id('h5_send_json_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postJsonToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Array') + .id('h5_send_array_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postArrayStringToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Object') + .id('h5_send_object_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postObjectToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + } + .width('100%') + .margin(10) + .padding(10) + .border({ width: 1 }) + + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onConsole((event) => { + if (event) { + let msg = event.message.getMessage(); + if (msg.startsWith('H5')) { + this.h5Log = event.message.getMessage() + '\n' + this.h5Log; + } + } + return false; + }) + } + }.height('100%') + .scrollable(ScrollDirection.Vertical) + .scrollBar(BarState.Off) + .edgeEffect(EdgeEffect.Spring) + } +} +// [End webview_and_native_modules_are_used_to_implement_complex_message_interaction_between_applications_and_h5_pages] diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/module.json5 b/ArkWeb/UseFrontendJSApp/entry5/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e5f83a19012c5aeed889f2500740ef21005ce465 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry5", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry5Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry5Ability", + "srcEntry": "./ets/entry5ability/Entry5Ability.ets", + "description": "$string:Entry5Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry5Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/string.json b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..06da3e1cdd155e5e4e35d5d768e9c71eb8ccdc6d --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/string.json @@ -0,0 +1,29 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry5Ability_desc", + "value": "description" + }, + { + "name": "Entry5Ability_label", + "value": "UseFrontendJSApp" + }, + { + "name": "H5_Side_Message_Display_From_App", + "value": "H5侧接收到应用侧发送消息展示" + }, + { + "name": "App_Side_Button", + "value": "应用侧按钮" + }, + { + "name": "H5_Side_Send_Button", + "value": "H5侧发送按钮" + } + + ] +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/layered_image.json b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..d2925296ddd927dee795dba32254d6e182c4e8f8 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html @@ -0,0 +1,138 @@ + + + + + +

etsRunJavaScriptExt测试demo

+

+

Receive string:

+

Receive arraybuffer:

+ + + + diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/mock/Libentry5.mock.ets b/ArkWeb/UseFrontendJSApp/entry5/src/mock/Libentry5.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..37c4693badee0bced9f50f020403147ada0e8d44 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/mock/Libentry5.mock.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +const nativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default nativeMock; \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/mock/mock-config.json5 b/ArkWeb/UseFrontendJSApp/entry5/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d67f40d452081e758a12bf1b6aca9e0097b23590 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/mock/mock-config.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "libentry5.so": { + "source": "src/mock/Libentry5.mock.ets" + } +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ffbfa958c98ebfd0a8bea5b321594420b0f7398 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 UploadFiles 按钮 + * 建立应用侧与前端页面数据通道 + */ + it('testUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry5Ability' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Entry5Ability'); + await driver.delayMs(3000); + + const button1 = await driver.findComponent(ON.text('createNoControllerTagPort')); + const button2 = await driver.findComponent(ON.text('createPort')); + const button3 = await driver.findComponent(ON.text('setHandler')); + const button4 = await driver.findComponent(ON.text('setHandlerThread')); + const button5 = await driver.findComponent(ON.text('SendString')); + const type1 = await driver.findComponent(ON.type('TextArea')); + await button1.click(); + await driver.delayMs(800); + await button2.click(); + await driver.delayMs(800); + await button3.click(); + await driver.delayMs(800); + await button4.click(); + await driver.delayMs(800); + await button5.click(); + await driver.delayMs(800); + + let text1: string = await type1.getText(); + expect(text1).assertContain('H5 recv type:'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/module.json5 b/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5ee7a310ffadc8ca0196f9fbc0b4a62ccc8c575d --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry5_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/test/List.test.ets b/ArkWeb/UseFrontendJSApp/entry5/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/entry5/src/test/LocalUnit.test.ets b/ArkWeb/UseFrontendJSApp/entry5/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/entry5/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/UseFrontendJSApp/hvigor/hvigor-config.json5 b/ArkWeb/UseFrontendJSApp/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/UseFrontendJSApp/hvigorfile.ts b/ArkWeb/UseFrontendJSApp/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/UseFrontendJSApp/oh-package.json5 b/ArkWeb/UseFrontendJSApp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/UseFrontendJSApp/ohosTest.md b/ArkWeb/UseFrontendJSApp/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..f983963664d05f87556fefa33664465a499169e4 --- /dev/null +++ b/ArkWeb/UseFrontendJSApp/ohosTest.md @@ -0,0 +1,114 @@ +### entry: + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------- | ------------ | ----------------------------------- | ------------------------------ | -------- | -------- | +| 应用侧调用前端页面函数 | 设备运转正常 | 应用启动成功,点击runJavaScript按钮 | 文本字体变绿 | Yes | Pass | +| runJavaScriptCodePassed | 设备运转正常 | 点击runJavaScriptCodePassed按钮 | 向前端传递自定义JavaScript代码 | Yes | Pass | +| callArkTS | 设备运转正常 | 点击 Click Me! 按钮 | 文本字体变红 | Yes | Pass | + +### entry2: + +#### JavaScriptProxy + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------ | ---------------------------------------------- | ------------------------- | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击deleteJavaScriptRegister按钮 | 从 Web 端删除已注册对象 | Yes | Pass | +| 触发callArkTS函数 | 设备运转正常 | 点击Click Me!按钮 | 界面显示ArkTS Hello world | Yes | Pass | + +#### RegisterJavaScriptProxy + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| callArkTS | testObj 注册到前端 | 点击Click Me!按钮 | 触发callArkTS函数 | Yes | Pass | + +#### UsageOfComplexTypes_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| callArkTS | testObj 注册到前端 | 点击Click Me!按钮 | 触发callArkTS函数 | Yes | Pass | + +#### UsageOfComplexTypes_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| callArkTS | testObj 注册到前端 | 点击Click Me!按钮 | 触发callArkTS函数 | Yes | Pass | + +#### UsageOfComplexTypes_three + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| callArkTS | testObj 注册到前端 | 点击Click Me!按钮 | 触发callArkTS函数 | Yes | Pass | + +#### UsageOfComplexTypes_four + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| callArkTS | testObj 注册到前端 | 点击Click Me!按钮 | 触发callArkTS函数 | Yes | Pass | + +#### UsageOfComplexTypes_five + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| callArkTS | testObj 注册到前端 | 点击Click Me!按钮 | 触发callArkTS函数 | Yes | Pass | + +#### Promise_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| 触发callArkTS函数 | testObj 注册到前端 | 点击Click Me!按钮 | 控制台在10s左右打印fail | Yes | Pass | + +#### Promise_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------------- | ------------------------------------- | ------------------------------ | -------- | -------- | +| 前端页面调用应用侧函数 | 设备运转正常 | 应用启动成功,点击refresh按钮 | 刷新网页 | Yes | Pass | +| 注册 testObj | 设备运转正常 | 点击Register JavaScript To Window按钮 | 将 testObj 注册到前端 | Yes | Pass | +| 删除testObjName | 注册testObjName对象 | 点击deleteJavaScriptRegister按钮 | 删除Web端注册的testObjName对象 | Yes | Pass | +| callArkTS | testObj 注册到前端 | 点击Click Me!按钮 | 触发callArkTS函数 | Yes | Pass | + +### entry3: + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------- | ------------------------------------------ | --------------------------------- | ----------------------- | -------- | -------- | +| 建立应用侧与前端页面数据通道 | 设备运转正常 | 应用启动成功,点击postMessage按钮 | 初始化消息端口 | Yes | Pass | +| SendDataToHTML | 设备运转正常,初始化消息端口 | 点击SendDataToHTML按钮 | 从 ETS 向 HTML 发送消息 | Yes | Pass | +| SendToEts | 设备运转正常,初始化消息端口,输入框有消息 | 点击SendToEts按钮 | 从 HTML 向 ETS 发送消息 | Yes | Pass | + +### entry4: + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------- | ------------ | ---------------------------------- | -------------------------- | -------- | -------- | +| 应用侧与前端页面的相互调用(C/C++) | 设备运转正常 | 应用启动成功,点击 runJS hello按钮 | 调用testNapi.runJavaScript | Yes | Pass | +| testNdkProxyObjMethod1 | 设备运转正常 | 点击test Native Development Kit method1!按钮 | 调用testNdkProxyObjMethod1 | Yes | Pass | + +### entry5: + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------- | ------------ | ------------------------------------------------- | ------------------------------------------------------- | -------- | -------- | +| 创建特殊端口 | 设备运转正常 | 应用启动成功,点击 createNoControllerTagPort 按钮 | 调用 testNapi.createWebMessagePorts | Yes | Pass | +| 建立通信通道 | 设备运转正常 | 点击createPort按钮 | 调用 testNapi.createWebMessagePorts | Yes | Pass | +| 注册消息处理的回调 | 成功创建端口 | 点击setHandler按钮 | 调用 testNapi.setMessageEventHandler | Yes | Pass | +| 注册消息处理的回调(多线程) | 设备运转正常 | 点击setHandlerThread按钮 | 调用 testNapi.setMessageEventHandlerThread | Yes | Pass | +| 发送消息 | 回调注册成功 | 点击SendString按钮 | TextArea 中显示 H5 recv result: send string from native | Yes | Pass | + diff --git a/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png b/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png new file mode 100644 index 0000000000000000000000000000000000000000..4ec6b9379b1f30cee90784020ba5d63f8658b44a Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png b/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png new file mode 100644 index 0000000000000000000000000000000000000000..9fca6ab851203269337857ad55bfb928d48eae5b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png b/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png new file mode 100644 index 0000000000000000000000000000000000000000..d751a1f32fbc6ce5d348f67eb909967f71108b51 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png new file mode 100644 index 0000000000000000000000000000000000000000..91588bab66d95f3331b83c5835ceda40101e2a08 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png new file mode 100644 index 0000000000000000000000000000000000000000..af089f319eb97ca164e582f693f35fa736d9eaf7 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_1.png b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ee086caba864c70bc90146e8ddb647b4799b64e7 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_1.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_2.png b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_2.png new file mode 100644 index 0000000000000000000000000000000000000000..14099796a5bb12268b079ca387c4edaf17650d60 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_2.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_3.png b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_3.png new file mode 100644 index 0000000000000000000000000000000000000000..0356c81695e355fcf377781230ba8a86487eda37 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_3.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png b/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png new file mode 100644 index 0000000000000000000000000000000000000000..3ee5136df51546e427c67e2b3bbb4c8509c936c8 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png b/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png new file mode 100644 index 0000000000000000000000000000000000000000..820750d20233f35ce6d79046ba5f18d79321c851 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png b/ArkWeb/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png new file mode 100644 index 0000000000000000000000000000000000000000..013b8df368cbc76d35adc30032d9772e1ac9da73 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/Promise_one.png b/ArkWeb/UseFrontendJSApp/screenshots/Promise_one.png new file mode 100644 index 0000000000000000000000000000000000000000..12bbbb0fd128b21bed1a4371f6b2e550dbbeca0e Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/Promise_one.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/Promise_two.png b/ArkWeb/UseFrontendJSApp/screenshots/Promise_two.png new file mode 100644 index 0000000000000000000000000000000000000000..8bee542e43da4707286062da6e464ac404ccfe78 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/Promise_two.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png b/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ebeee2e026791ac950624544d3c755aa9575a2d3 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png b/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png new file mode 100644 index 0000000000000000000000000000000000000000..6a12f71ee544aba84d8f84b942b2e9ce795ebde1 Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png differ diff --git a/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png differ diff --git a/ArkWeb/WebRenderLayout/.gitignore b/ArkWeb/WebRenderLayout/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkWeb/WebRenderLayout/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/AppScope/app.json5 b/ArkWeb/WebRenderLayout/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..05d4077ce4a7d7033ee498e91542b02a57098a33 --- /dev/null +++ b/ArkWeb/WebRenderLayout/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.samples.webrenderlayout", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkWeb/WebRenderLayout/AppScope/resources/base/element/string.json b/ArkWeb/WebRenderLayout/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d141695c97a80ba162c219dfd4c5afa0b1ae7772 --- /dev/null +++ b/ArkWeb/WebRenderLayout/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "WebRenderLayout" + } + ] +} diff --git a/ArkWeb/WebRenderLayout/AppScope/resources/base/media/app_icon.png b/ArkWeb/WebRenderLayout/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkWeb/WebRenderLayout/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkWeb/WebRenderLayout/README.md b/ArkWeb/WebRenderLayout/README.md new file mode 100644 index 0000000000000000000000000000000000000000..69835eb56adea44f9c251167b00e2447df1bd849 --- /dev/null +++ b/ArkWeb/WebRenderLayout/README.md @@ -0,0 +1,82 @@ +# Web组件渲染模式 + +## RenderMode + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-render-mode.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 使用renderMode设置渲染模式为 ASYNC_RENDER (同步渲染模式)。 +# Web组件大小自适应页面内容布局 + +## FitPageContent + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-fit-content.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | +| --------------------------------------------------------- | +| | + +使用说明 + +1. 使用Web组件大小自适应页面内容布局模式layoutMode(WebLayoutMode.FIT_CONTENT)时,能使Web组件的大小根据页面内容自适应变化。 + +## 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---FitPageContent.ets +|---|---|---RenderMode.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + +## 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo ArkWeb/WebRenderLayout > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/build-profile.json5 b/ArkWeb/WebRenderLayout/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ArkWeb/WebRenderLayout/build-profile.json5 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/code-linter.json5 b/ArkWeb/WebRenderLayout/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkWeb/WebRenderLayout/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/.gitignore b/ArkWeb/WebRenderLayout/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/build-profile.json5 b/ArkWeb/WebRenderLayout/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/hvigorfile.ts b/ArkWeb/WebRenderLayout/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2025 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. +*/ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/WebRenderLayout/entry/obfuscation-rules.txt b/ArkWeb/WebRenderLayout/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/oh-package.json5 b/ArkWeb/WebRenderLayout/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkWeb/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets b/ArkWeb/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ArkWeb/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkWeb/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets b/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets new file mode 100644 index 0000000000000000000000000000000000000000..540e3cb7c6c821ee0737b9c7131947102d04689b --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start a_page_that_contains_a_webview_and_text_in_the_comment_section] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebHeightPage { + private webviewController: WebviewController = new webview.WebviewController(); + private scroller: Scroller = new Scroller(); + + build() { + Navigation() { + Column() { + Scroll(this.scroller) { + Column() { + Web({ + src: $rawfile('fit_content.html'), + controller: this.webviewController, + renderMode: RenderMode.SYNC_RENDER // 设置为同步渲染模式 + }) + .layoutMode(WebLayoutMode.FIT_CONTENT)// 设置为Web组件大小自适应页面内容 + .overScrollMode(OverScrollMode.NEVER) // 设置过滚动模式为关闭状态 + Text($r('app.string.Comment_area')) + .fontSize(28) + .fontColor('#FF0F0F') + .height(100) + .width('100%') + .backgroundColor('#f89f0f') + } + } + } + } + .title($r('app.string.Title_bar')) + } +} +// [End a_page_that_contains_a_webview_and_text_in_the_comment_section] \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/Index.ets b/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..df919e917f89291db2860580991977a30666f74e --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +import { router } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('RenderMode') + .onClick(() => { + router.pushUrl({ url: 'pages/RenderMode' }); + }) + Button('FitPageContent') + .onClick(() => { + router.pushUrl({ url: 'pages/FitPageContent' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets b/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets new file mode 100644 index 0000000000000000000000000000000000000000..fa5b59c771ce7e9d4fab94562ec97740f72df354 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start web_component_rendering_mode] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebHeightPage { + private webviewController: WebviewController = new webview.WebviewController() + + build() { + Column() { + Web({ + src: 'www.example.com', + controller: this.webviewController, + renderMode: RenderMode.ASYNC_RENDER // 设置渲染模式 + }) + } + } +} +// [End web_component_rendering_mode] \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/module.json5 b/ArkWeb/WebRenderLayout/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/module.json5 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/color.json b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/string.json b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6e797f7e8ed5cd498631cffb6be41435d3a4c35f --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "WebRenderLayout" + }, + { + "name": "Title_bar", + "value": "标题栏" + }, + { + "name": "Comment_area", + "value": "评论区" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/background.png b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/background.png differ diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/foreground.png b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..a632b71f19e592ae7862ebda48f5b871bd93c7b9 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/FitPageContent", + "pages/RenderMode" + ] +} diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/en_US/element/string.json b/ArkWeb/WebRenderLayout/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f618771a19f0dffbca09170f416db1ff866c5972 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "WebRenderLayout" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html b/ArkWeb/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html new file mode 100644 index 0000000000000000000000000000000000000000..46c149ed86bd171a04921aed7d9c4dc5b927eccf --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html @@ -0,0 +1,63 @@ + + + + + + + + Fit-Content + + +
+

使用场景

+

ArkWeb(方舟Web)提供了Web组件,用于在应用程序中显示Web页面内容。常见使用场景包括:

+
    +
  • + 应用集成Web页面:应用可以在页面中使用Web组件,嵌入Web页面内容,以降低开发成本,提升开发、运营效率。

    +
  • +
  • + 浏览器网页浏览场景:浏览器类应用可以使用Web组件,打开三方网页,使用无痕模式浏览Web页面,设置广告拦截等。

    +
  • +
  • 小程序:小程序类宿主应用可以使用Web组件,渲染小程序的页面。

  • +
+
+

能力范围

+

Web组件为开发者提供了丰富的控制Web页面能力。包括:

+
    +
  • Web页面加载:声明式加载Web页面和离屏加载Web页面等。

  • +
  • 生命周期管理:组件生命周期状态变化,通知Web页面的加载状态变化等。

  • +
  • 常用属性与事件:UserAgent管理、Cookie与存储管理、字体与深色模式管理、权限管理等。

    +
  • +
  • + 与应用界面交互:自定义文本选择菜单、上下文菜单、文件上传界面等与应用界面交互能力。

    +
  • +
  • App通过JavaScriptProxy,与Web页面进行JavaScript交互。

  • +
  • 安全与隐私:无痕浏览模式、广告拦截、坚盾守护模式等。

  • +
  • 维测能力:DevTools工具调试能力,使用crashpad收集Web组件崩溃信息。 +

  • +
  • + 其他高阶能力:与原生组件同层渲染、Web组件的网络托管、Web组件的媒体播放托管、Web组件输入框拉起自定义输入法、等。

    +
  • +
+
+

约束与限制

+
    +
  • Web内核版本:ArkWeb基于谷歌Chromium内核开发,使用的Chromium版本为M114。
  • +
+
+
+ + diff --git a/ArkWeb/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json b/ArkWeb/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8b827c36ef821c56b3e6ef65fd4d64627a4a978b --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "WebRenderLayout" + } + ] +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/mock/mock-config.json5 b/ArkWeb/WebRenderLayout/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1375e7a47ea13527ce438c9327cb82226ebfed3e --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 RenderMode 按钮 + * 使用renderMode设置渲染模式为同步渲染模式 + */ + it('RenderMode',0, async (done: Function) => { + console.info('uitest: RenderMode begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('RenderMode')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: RenderMode end'); + done(); + }); + + /* + * 点击 FitPageContent 按钮 + * 使用Web组件大小自适应页面内容布局模式使Web组件的大小根据页面内容自适应变化 + */ + it('FitPageContent',0, async (done: Function) => { + console.info('uitest: FitPageContent begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('FitPageContent')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('fit_content.html'); + + await driver.pressBack(); + console.info('uitest: FitPageContent end'); + done(); + }); + }) +} diff --git a/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets b/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/ohosTest/module.json5 b/ArkWeb/WebRenderLayout/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkWeb/WebRenderLayout/entry/src/test/List.test.ets b/ArkWeb/WebRenderLayout/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/entry/src/test/LocalUnit.test.ets b/ArkWeb/WebRenderLayout/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkWeb/WebRenderLayout/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkWeb/WebRenderLayout/hvigor/hvigor-config.json5 b/ArkWeb/WebRenderLayout/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ArkWeb/WebRenderLayout/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkWeb/WebRenderLayout/hvigorfile.ts b/ArkWeb/WebRenderLayout/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ArkWeb/WebRenderLayout/hvigorfile.ts @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2025 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. +*/ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkWeb/WebRenderLayout/oh-package.json5 b/ArkWeb/WebRenderLayout/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ArkWeb/WebRenderLayout/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkWeb/WebRenderLayout/ohosTest.md b/ArkWeb/WebRenderLayout/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..adb0630d5903794a19ddf997a1149a45d5be34f3 --- /dev/null +++ b/ArkWeb/WebRenderLayout/ohosTest.md @@ -0,0 +1,12 @@ +#### renderMode + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------- | ------------ | ------------ | -------------------------- | -------- | -------- | +| Web组件渲染模式 | 设备运转正常 | 应用启动成功 | 设置渲染模式为同步渲染模式 | Yes | Pass | + +#### FitPageContent + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------- | ------------ | ------------ | ------------------------------------- | -------- | -------- | +| Web组件大小自适应页面内容布局 | 设备运转正常 | 应用启动成功 | 使Web组件的大小根据页面内容自适应变化 | Yes | Pass | + diff --git a/ArkWeb/WebRenderLayout/screenshots/FitPageContent.png b/ArkWeb/WebRenderLayout/screenshots/FitPageContent.png new file mode 100644 index 0000000000000000000000000000000000000000..9adcb9f829555ac56fb968df666af85a404fff83 Binary files /dev/null and b/ArkWeb/WebRenderLayout/screenshots/FitPageContent.png differ diff --git a/ArkWeb/WebRenderLayout/screenshots/RenderModeWebComp.png b/ArkWeb/WebRenderLayout/screenshots/RenderModeWebComp.png new file mode 100644 index 0000000000000000000000000000000000000000..aaad114cf5305f8c82ea1b1238330f61a3b7625d Binary files /dev/null and b/ArkWeb/WebRenderLayout/screenshots/RenderModeWebComp.png differ