diff --git a/LifecycleWebComp/.gitignore b/LifecycleWebComp/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/LifecycleWebComp/.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/LifecycleWebComp/AppScope/app.json5 b/LifecycleWebComp/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c280ad8998ec933a13d5f497a6d439143c5eb8c2 --- /dev/null +++ b/LifecycleWebComp/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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.lifecyclewebcomp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/LifecycleWebComp/AppScope/resources/base/element/string.json b/LifecycleWebComp/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..db726d0837ef849bc208a86e9467181653f73010 --- /dev/null +++ b/LifecycleWebComp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "LifecycleWebComp" + } + ] +} diff --git a/LifecycleWebComp/AppScope/resources/base/media/app_icon.png b/LifecycleWebComp/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/LifecycleWebComp/AppScope/resources/base/media/app_icon.png differ diff --git a/LifecycleWebComp/README.md b/LifecycleWebComp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9575c892f64700b8c5aea8953289ca269ec81276 --- /dev/null +++ b/LifecycleWebComp/README.md @@ -0,0 +1,62 @@ +# Web组件的生命周期 + +### 介绍 + +本工程主要实现了对以下指南文档中 https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/web/web-event-sequence.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### 效果预览 + +| 日志效果 | +| --------------------------------------- | +| ![](./screenshots/LifecycleWebComp.png) | + +使用说明 + +1. 此 Web 组件无页面展示,运行时通过系统日志输出相关信息。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.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 code/DocsSample/ArkWeb/LifecycleWebComp > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/LifecycleWebComp/build-profile.json5 b/LifecycleWebComp/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d8f458efb875310bfaca49b33a5a8fc651e1ebd7 --- /dev/null +++ b/LifecycleWebComp/build-profile.json5 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/code-linter.json5 b/LifecycleWebComp/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eff2dbc9b8a447e5a99b0aab08ca2b766d786bf6 --- /dev/null +++ b/LifecycleWebComp/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/.gitignore b/LifecycleWebComp/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/LifecycleWebComp/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/LifecycleWebComp/entry/build-profile.json5 b/LifecycleWebComp/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31bf2f4c4df15f0403582b255ebdff1354312357 --- /dev/null +++ b/LifecycleWebComp/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/hvigorfile.ts b/LifecycleWebComp/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/LifecycleWebComp/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +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/LifecycleWebComp/entry/obfuscation-rules.txt b/LifecycleWebComp/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/LifecycleWebComp/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/LifecycleWebComp/entry/oh-package.json5 b/LifecycleWebComp/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4e54d14e1b444a338b2c922f94a4fe4deed5be45 --- /dev/null +++ b/LifecycleWebComp/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets b/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..217744d8eb6d893e1138cd660209ce4d0441ac4f --- /dev/null +++ b/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b744d7eaa66e51e79fc4e0896e251292ee767c5 --- /dev/null +++ b/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/main/ets/pages/Index.ets b/LifecycleWebComp/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e904676c4acbaa978d796dc71ce3ca78d084010 --- /dev/null +++ b/LifecycleWebComp/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2024 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_status_of_web_component_web_page_loading] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + responseWeb: WebResourceResponse = new WebResourceResponse(); + heads: Header[] = new Array(); + @State webData: string = '\n' + + '\n' + + '\n' + + 'intercept test\n' + + '\n' + + '\n' + + '

intercept test

\n' + + '\n' + + ''; + + aboutToAppear(): void { + try { + webview.WebviewController.setWebDebuggingAccess(true); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onControllerAttached(() => { + // 推荐在此loadUrl、设置自定义用户代理、注入JS对象等 + console.log('onControllerAttached execute'); + }) + .onLoadIntercept((event) => { + if (event) { + console.log('onLoadIntercept url:' + event.data.getRequestUrl()); + console.log('url:' + event.data.getRequestUrl()); + console.log('isMainFrame:' + event.data.isMainFrame()); + console.log('isRedirect:' + event.data.isRedirect()); + console.log('isRequestGesture:' + event.data.isRequestGesture()); + } + // 返回true表示阻止此次加载,否则允许此次加载 + return true; + }) + .onOverrideUrlLoading((webResourceRequest: WebResourceRequest) => { + if (webResourceRequest && webResourceRequest.getRequestUrl() == 'about:blank') { + return true; + } + return false; + }) + .onInterceptRequest((event) => { + if (event) { + console.log('url:' + event.request.getRequestUrl()); + } + let head1: Header = { + headerKey: 'Connection', + headerValue: 'keep-alive' + } + let head2: Header = { + headerKey: 'Cache-Control', + headerValue: 'no-cache' + } + let length = this.heads.push(head1); + length = this.heads.push(head2); + this.responseWeb.setResponseHeader(this.heads); + this.responseWeb.setResponseData(this.webData); + this.responseWeb.setResponseEncoding('utf-8'); + this.responseWeb.setResponseMimeType('text/html'); + this.responseWeb.setResponseCode(200); + this.responseWeb.setReasonMessage('OK'); + // 返回响应数据则按照响应数据加载,无响应数据则返回null表示按照原来的方式加载 + return this.responseWeb; + }) + .onPageBegin((event) => { + if (event) { + console.log('onPageBegin url:' + event.url); + } + }) + .onFirstContentfulPaint(event => { + if (event) { + console.log('onFirstContentfulPaint:' + '[navigationStartTick]:' + + event.navigationStartTick + ', [firstContentfulPaintMs]:' + + event.firstContentfulPaintMs); + } + }) + .onProgressChange((event) => { + if (event) { + console.log('newProgress:' + event.newProgress); + } + }) + .onPageEnd((event) => { + // 推荐在此事件中执行JavaScript脚本 + if (event) { + console.log('onPageEnd url:' + event.url); + } + }) + .onPageVisible((event) => { + console.log('onPageVisible url:' + event.url); + }) + .onRenderExited((event) => { + if (event) { + console.log('onRenderExited reason:' + event.renderExitReason); + } + }) + .onDisAppear(() => { + promptAction.showToast({ + message: 'The web is hidden', + duration: 2000 + }); + }) + } + } +} +// [End the_status_of_web_component_web_page_loading] \ No newline at end of file diff --git a/LifecycleWebComp/entry/src/main/module.json5 b/LifecycleWebComp/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cb5df2316a385286bf09b1aab230f0bf56d8b993 --- /dev/null +++ b/LifecycleWebComp/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/main/resources/base/element/color.json b/LifecycleWebComp/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/LifecycleWebComp/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/LifecycleWebComp/entry/src/main/resources/base/element/string.json b/LifecycleWebComp/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..38f261172dc69d5f1652c4a07e5197966e5d449f --- /dev/null +++ b/LifecycleWebComp/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": "LifecycleWebComp" + } + ] +} \ No newline at end of file diff --git a/LifecycleWebComp/entry/src/main/resources/base/media/background.png b/LifecycleWebComp/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/LifecycleWebComp/entry/src/main/resources/base/media/background.png differ diff --git a/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png b/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png differ diff --git a/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json b/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/LifecycleWebComp/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/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png b/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png differ diff --git a/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json b/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json b/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json b/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..38f261172dc69d5f1652c4a07e5197966e5d449f --- /dev/null +++ b/LifecycleWebComp/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": "LifecycleWebComp" + } + ] +} \ No newline at end of file diff --git a/LifecycleWebComp/entry/src/main/resources/rawfile/index.html b/LifecycleWebComp/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..844921321627bd854c9219a879ff5c656da188e9 --- /dev/null +++ b/LifecycleWebComp/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,9 @@ + + + + + + +

Hello, ArkWeb

+ + diff --git a/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json b/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..00df20570eb1892ed5e7d19b125c9f65988634c4 --- /dev/null +++ b/LifecycleWebComp/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": "LifecycleWebComp" + } + ] +} \ No newline at end of file diff --git a/LifecycleWebComp/entry/src/mock/mock-config.json5 b/LifecycleWebComp/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26ed9f53bc46192a07ad5ab16ea24e7ce9a79328 --- /dev/null +++ b/LifecycleWebComp/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets b/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..72a538fe044d7e7dbbac4010a47249c3eeabeeb7 --- /dev/null +++ b/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 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: '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 type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('index.html'); + + done(); + }) + }) +} \ No newline at end of file diff --git a/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets b/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e909c66ab67746c53f694cc12a0a604748a8b661 --- /dev/null +++ b/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/ohosTest/module.json5 b/LifecycleWebComp/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5f63462032245655b8df990c83c5d7312015c089 --- /dev/null +++ b/LifecycleWebComp/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/test/List.test.ets b/LifecycleWebComp/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab6445db05608a5b7f851a85add24f32b890b0f8 --- /dev/null +++ b/LifecycleWebComp/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/entry/src/test/LocalUnit.test.ets b/LifecycleWebComp/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b7b4eb2ff9627c7184e386fe88c2ba1b507f905 --- /dev/null +++ b/LifecycleWebComp/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/hvigor/hvigor-config.json5 b/LifecycleWebComp/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..76e3231223076011f7f4400f54fa73a5ab0141d4 --- /dev/null +++ b/LifecycleWebComp/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/hvigorfile.ts b/LifecycleWebComp/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/LifecycleWebComp/hvigorfile.ts @@ -0,0 +1,6 @@ +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/LifecycleWebComp/oh-package.json5 b/LifecycleWebComp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d7622199b7ba60be5983122081f71ae9ebef0c4b --- /dev/null +++ b/LifecycleWebComp/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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/LifecycleWebComp/ohosTest.md b/LifecycleWebComp/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..cbf90fb29998b1baec6a0ea45fdd2c6ff8633012 --- /dev/null +++ b/LifecycleWebComp/ohosTest.md @@ -0,0 +1,4 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ------------ | ---------------- | -------- | -------- | +| Web组件的生命周期 | 设备运转正常 | 应用启动成功 | 日志输出相关信息 | Yes | Pass | + diff --git a/LifecycleWebComp/screenshots/LifecycleWebComp.png b/LifecycleWebComp/screenshots/LifecycleWebComp.png new file mode 100644 index 0000000000000000000000000000000000000000..879273b457515acee4cc9752e74440204b7ac63c Binary files /dev/null and b/LifecycleWebComp/screenshots/LifecycleWebComp.png differ diff --git a/ManageWebCompSecPriv/.gitignore b/ManageWebCompSecPriv/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ManageWebCompSecPriv/.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/ManageWebCompSecPriv/AppScope/app.json5 b/ManageWebCompSecPriv/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f3bfcf54902f2bda4cd2cee4b827b89e2ba7ee37 --- /dev/null +++ b/ManageWebCompSecPriv/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.managewebcompsecpriv", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ManageWebCompSecPriv/AppScope/resources/base/element/string.json b/ManageWebCompSecPriv/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8e172ff2061de12c25e977effcf18d7629db4cd7 --- /dev/null +++ b/ManageWebCompSecPriv/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebCompSecPriv" + } + ] +} diff --git a/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png b/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png differ diff --git a/ManageWebCompSecPriv/README.md b/ManageWebCompSecPriv/README.md new file mode 100644 index 0000000000000000000000000000000000000000..58fe7b5dfe2faef450e0f689d957b17962f8a5a8 --- /dev/null +++ b/ManageWebCompSecPriv/README.md @@ -0,0 +1,270 @@ +## 解决Web组件本地资源跨域问题 + +### 介绍 + +1. 本示例主要介绍解决Web组件本地资源跨域问题,利用Web组件的onInterceptRequest方法,对本地资源进行拦截和相应的替换。 +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-cross-origin.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### LocCrossOriginResAccSol_one + +##### 介绍 + +1. 本示例主要介绍解决Web组件本地资源跨域问题,利用Web组件的onInterceptRequest方法,对本地资源进行拦截和相应的替换。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 针对本地index.html,使用http或者https协议代替file协议或者resource协议,构造一个属于自己的域名。 + +#### LocCrossOriginResAccSol_two + +##### 介绍 + +1. 本示例主要介绍解决Web组件本地资源跨域问题,通过setPathAllowingUniversalAccess设置一个路径列表。当使用file协议访问该列表中的资源时,允许进行跨域访问本地文件。 + +##### 效果预览 + +| 主页 | 跨域访问 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 通过setPathAllowingUniversalAccess设置一个路径列表。当使用file协议访问该列表中的资源时,允许进行跨域访问本地文件。 +1. index.html页面加载完成后,页面上显示一个按钮stealFile,点击stealFile按钮触发getFile函数跨域访问本地resfile/js/script.js文件。 + +## 使用智能防跟踪功能 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-intelligent-tracking-prevention.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### AddIntTrackPreventByPassList + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,调用addIntelligentTrackingPreventionBypassingList接口设置需要绕过智能防跟踪功能的域名列表。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击addIntelligentTrackingPreventionBypassingList按钮设置需要绕过智能防跟踪功能的域名。 + +#### ClearIntTrackPreventByPassList + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用clearIntelligentTrackingPreventionBypassingList接口清除通过addIntelligentTrackingPreventionBypassingList接口设置的所有域名。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击clearIntelligentTrackingPreventionBypassingList按钮清除通过addIntelligentTrackingPreventionBypassingList接口设置的所有域名。 + +#### EnableIntTrackPrevent + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,调用enableIntelligentTrackingPrevention接口使能或者关闭相应Web组件的智能防跟踪功能。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击enableIntelligentTrackingPrevention按钮使能相应Web组件的智能防跟踪功能。 + +#### IsIntTrackPreventEnabled + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用isIntelligentTrackingPreventionEnabled接口判断当前Web组件是否开启了智能防跟踪功能。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击isIntelligentTrackingPreventionEnabled按钮判断当前Web组件是否开启了智能防跟踪功能。 + +#### OnIntTrackPreventResult + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用onIntelligentTrackingPreventionResult接口,以回调的方式异步获取拦截的跟踪型网站的域名和访问的网站域名信息。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击onIntelligentTrackingPreventionResult按钮,获取拦截的跟踪型网站的域名和访问的网站域名信息。 + +#### RemoveIntTrackPreventByPassList + +##### 介绍 + +1. 本示例主要介绍使用智能防跟踪功能,通过调用removeIntelligentTrackingPreventionBypassingList接口移除通过addIntelligentTrackingPreventionBypassingList接口设置的部分域名列表。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击removeIntelligentTrackingPreventionBypassingList按钮,移除通过addIntelligentTrackingPreventionBypassingList接口设置的部分域名列表。 + +## 使用Web组件的广告过滤功能 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-adsblock.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### EnablingAdsBlocking + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,应用可以通过AdsBlockManager提供的setAdsBlockRules()接口设置自定义的easylist过滤规则,并通过Web组件的enableAdsBlock()接口使能广告过滤特性。 + +##### 效果预览 + +| 主页 | 文件选择器 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| /> | | + +使用说明 + +1. 点击setAdsBlockRules按钮,通过文件选择器设置自定义的easylist过滤规则。 + +#### DisAdsBlockSpecDomPages_one + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,在Web组件的广告过滤开关开启后,应用有时候会期望关闭一些特定页面的广告过滤功能,AdsBlockManager提供了addAdsBlockDisallowedList()接口完成此功能。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击addAdsBlockDisallowedList按钮关闭特定域名页面的广告过滤。 + +#### DisAdsBlockSpecDomPages_two + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,使用addAdsBlockDisallowedList()接口添加域名。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击addAdsBlockDisallowedList按钮添加域名。 + +#### CollectingAdsBlockingInformation + +##### 介绍 + +1. 本示例主要介绍使用Web组件的广告过滤功能,在Web组件的广告过滤开关开启后,访问的网页如果发生了广告过滤,会通过Web组件的onAdsBlocked()回调接口通知到应用,应用可根据需要进行过滤信息的收集和统计。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 使用onAdsBlocked接口收集广告过滤的信息。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---CollectingAdsBlockingInformation +|---|---|---DisAdsBlockSpecDomPages_one +|---|---|---DisAdsBlockSpecDomPages_two +|---|---|---LocCrossOriginResAccSol_one +|---|---|---LocCrossOriginResAccSol_two +|---|---|---AddIntTrackPreventByPassList +|---|---|---ClearIntTrackPreventByPassList +|---|---|---EnableIntTrackPrevent +|---|---|---IsIntTrackPreventEnabled +|---|---|---OnIntTrackPreventResult +|---|---|---RemoveIntTrackPreventByPassList +|---|---|---EnablingAdsBlocking +|---|---|---Index.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 code/DocsSample/ArkWeb/ManageWebCompSecPriv > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/ManageWebCompSecPriv/build-profile.json5 b/ManageWebCompSecPriv/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..edcfa0a0b72fb77e6fa0828177e088eec84f61eb --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/code-linter.json5 b/ManageWebCompSecPriv/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/.gitignore b/ManageWebCompSecPriv/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebCompSecPriv/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/build-profile.json5 b/ManageWebCompSecPriv/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/hvigorfile.ts b/ManageWebCompSecPriv/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/obfuscation-rules.txt b/ManageWebCompSecPriv/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/oh-package.json5 b/ManageWebCompSecPriv/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets b/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa1655f7bbde61df1c1a081b565110487297ab79 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.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_domains_to_bypass_intelligent_tracking] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('addIntelligentTrackingPreventionBypassingList') + .onClick(() => { + try { + let hostList = ['www.test1.com', 'www.test2.com', 'www.test3.com']; + webview.WebviewController.addIntelligentTrackingPreventionBypassingList(hostList); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } +} +// [End set_domains_to_bypass_intelligent_tracking] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets new file mode 100644 index 0000000000000000000000000000000000000000..49754ae2a245269f8aaec2dbcd2934e959e8bcb4 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets @@ -0,0 +1,33 @@ +/* + * 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_intelligent_tracking_prevention_bypasses] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('clearIntelligentTrackingPreventionBypassingList') + .onClick(() => { + webview.WebviewController.clearIntelligentTrackingPreventionBypassingList(); + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }) + } + } +} +// [End clear_all_intelligent_tracking_prevention_bypasses] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d271fae7990654324db8a7e4aeb8b3b363caec9 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.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 collect_information_about_ad_filtering] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + @State totalAdsBlockCounts: number = 0; + // [StartExclude collect_information_about_ad_filtering] + @State myString: string = 'onAdsBlocked'; + // [EndExclude collect_information_about_ad_filtering] + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.controller }) + .onAdsBlocked((details: AdsBlockedDetails) => { + if (details) { + console.log(' Blocked ' + details.adsBlocked.length + ' in ' + details.url); + let adList: string[] = Array.from(new Set(details.adsBlocked)); + this.totalAdsBlockCounts += adList.length; + console.log('Total blocked counts :' + this.totalAdsBlockCounts); + } + }) + } + } +} +// [End collect_information_about_ad_filtering] diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7649e9937a547b1fc4a4034afce0a877e524fc5 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets @@ -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. + */ +// [Start turn_off_ad_filtering_for_specific_domain_pages] +import { webview } from '@kit.ArkWeb'; + +// [StartExclude turn_off_ad_filtering_for_specific_domain_pages] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude turn_off_ad_filtering_for_specific_domain_pages] +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + textInputController: TextInputController = new TextInputController(); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) + .id('input_url') + .height(40) + .margin(5) + .borderColor(Color.Blue) + .onChange((value: string) => { + this.inputText = value; + }) + + Button({type: ButtonType.Capsule}) { Text('Go') } + .onClick(() => { + this.controller.loadUrl(this.inputText); + }) + + Button({type: ButtonType.Capsule}) { Text('addAdsBlockDisallowedList') } + .onClick(() => { + let arrDomainSuffixes: string[] = []; + arrDomainSuffixes.push('example.com'); + arrDomainSuffixes.push('abcdefg.cn'); + webview.AdsBlockManager.addAdsBlockDisallowedList(arrDomainSuffixes); + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} +// [End turn_off_ad_filtering_for_specific_domain_pages] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..c407061e161f5f86af1b1272e265f1d59262e821 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets @@ -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. + */ +// [Start set_up_page_level_ad_filtering_switch] +import { webview } from '@kit.ArkWeb'; + +// [StartExclude set_up_page_level_ad_filtering_switch] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude set_up_page_level_ad_filtering_switch] +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + textInputController: TextInputController = new TextInputController(); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) + .id('input_url') + .height(40) + .margin(5) + .borderColor(Color.Blue) + .onChange((value: string) => { + this.inputText = value; + }) + + Button({type: ButtonType.Capsule}) { Text('Go'); } + .onClick(() => { + this.controller.loadUrl(this.inputText); + }) + + Button({type: ButtonType.Capsule}) { Text('addAdsBlockAllowedList'); } + .onClick(() => { + let arrDisallowDomainSuffixes = ['example.com']; + webview.AdsBlockManager.addAdsBlockDisallowedList(arrDisallowDomainSuffixes); + + let arrAllowedDomainSuffixes = ['news.example.com', 'sport.example.com']; + webview.AdsBlockManager.addAdsBlockAllowedList(arrAllowedDomainSuffixes); + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} +// [End set_up_page_level_ad_filtering_switch] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab7767a6c6bb65d34e0c320e9d6b126039a8e77d --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.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 enable_or_disable_web_component_anti_tracking] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('enableIntelligentTrackingPrevention') + .onClick(() => { + try { + this.controller.enableIntelligentTrackingPrevention(true); + console.log('enableIntelligentTrackingPrevention: true'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } +} +// [End enable_or_disable_web_component_anti_tracking] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets new file mode 100644 index 0000000000000000000000000000000000000000..8eb4a81e2d203fc04af163a09aaf5601ef77c7c7 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets @@ -0,0 +1,64 @@ +/* + * 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 app_select_list_rule_file_for_ad_filter] +import { webview } from '@kit.ArkWeb'; +import { picker, fileUri } from '@kit.CoreFileKit'; + +// [StartExclude app_select_list_rule_file_for_ad_filter] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude app_select_list_rule_file_for_ad_filter] +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + Button({type: ButtonType.Capsule}) { + Text('setAdsBlockRules'); + } + .onClick(() => { + try { + let documentSelectionOptions: picker.DocumentSelectOptions = new picker.DocumentSelectOptions(); + let documentPicker: picker.DocumentViewPicker = new picker.DocumentViewPicker(); + documentPicker.select(documentSelectionOptions).then((documentSelectResult: string[]) => { + if (documentSelectResult && documentSelectResult.length > 0) { + let fileRealPath = new fileUri.FileUri(documentSelectResult[0]); + console.info('DocumentViewPicker.select successfully, uri: ' + fileRealPath); + webview.AdsBlockManager.setAdsBlockRules(fileRealPath.path, true); + } + }) + } catch (err) { + console.error('DocumentViewPicker.select failed with err:' + err); + } + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} +// [End app_select_list_rule_file_for_ad_filter] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb5f033b5edc90ee98d926d2590e6c02294df4b6 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('LocCrossOriginResAccSol_one') + .onClick(() => { + router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_one' }); + }) + Button('LocCrossOriginResAccSol_two') + .onClick(() => { + router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_two' }); + }) + Button('AddIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/AddIntTrackPreventByPassList' }); + }) + Button('ClearIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/ClearIntTrackPreventByPassList' }); + }) + Button('EnableIntTrackPrevent') + .onClick(() => { + router.pushUrl({ url: 'pages/EnableIntTrackPrevent' }); + }) + Button('IsIntTrackPreventEnabled') + .onClick(() => { + router.pushUrl({ url: 'pages/IsIntTrackPreventEnabled' }); + }) + Button('OnIntTrackPreventResult') + .onClick(() => { + router.pushUrl({ url: 'pages/OnIntTrackPreventResult' }); + }) + Button('RemoveIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/RemoveIntTrackPreventByPassList' }); + }) + Button('EnablingAdsBlocking') + .onClick(() => { + router.pushUrl({ url: 'pages/EnablingAdsBlocking' }); + }) + Button('DisAdsBlockSpecDomPages_one') + .onClick(() => { + router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_one' }); + }) + Button('DisAdsBlockSpecDomPages_two') + .onClick(() => { + router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_two' }); + }) + Button('CollectingAdsBlockingInformation') + .onClick(() => { + router.pushUrl({ url: 'pages/CollectingAdsBlockingInformation' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets new file mode 100644 index 0000000000000000000000000000000000000000..b33603d2c083d817a71949d8e8c4ac533582e4fc --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.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 check_if_web_component_anti_tracking_on] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('isIntelligentTrackingPreventionEnabled') + .onClick(() => { + try { + let result = this.controller.isIntelligentTrackingPreventionEnabled(); + console.log('result: ' + result); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } +} +// [End check_if_web_component_anti_tracking_on] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..89333b69cb353cc31ca718d0175cae53d6bd1de7 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.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 cors_loccross_one] +import { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + webviewController: webview.WebviewController = new webview.WebviewController(); + // 构造域名和本地文件的映射表 + schemeMap = new Map([ + [resourceToString($r('app.string.web_path')) + '/index.html', 'index.html'], + [resourceToString($r('app.string.web_path')) + '/js/script.js', 'js/script.js'], + ]); + // 构造本地文件和构造返回的格式mimeType + mimeTypeMap = new Map([ + ['index.html', 'text/html'], + ['js/script.js', 'text/javascript'] + ]); + + build() { + Row() { + Column() { + // 针对本地index1.html,使用http或者https协议代替file协议或者resource协议,并且构造一个属于自己的域名。 + // 本例中构造www.example.com为例。 + Web({ src: resourceToString($r('app.string.web_path')) + '/index.html', controller: this.webviewController }) + .javaScriptAccess(true) + .fileAccess(true) + .domStorageAccess(true) + .geolocationAccess(true) + .width('100%') + .height('100%') + .onInterceptRequest((event) => { + if (!event) { + return; + } + // 此处匹配自己想要加载的本地离线资源,进行资源拦截替换,绕过跨域 + if (this.schemeMap.has(event.request.getRequestUrl())) { + let rawfileName: string = this.schemeMap.get(event.request.getRequestUrl())!; + let mimeType = this.mimeTypeMap.get(rawfileName); + if (typeof mimeType === 'string') { + let response = new WebResourceResponse(); + // 构造响应数据,如果本地文件在rawfile下,可以通过如下方式设置 + response.setResponseData($rawfile(rawfileName)); + response.setResponseEncoding('utf-8'); + response.setResponseMimeType(mimeType); + response.setResponseCode(200); + response.setReasonMessage('OK'); + response.setResponseIsReady(true); + return response; + } + } + return null; + }) + } + .width('100%') + } + .height('100%') + } +} +// [End cors_loccross_one] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..aae56aaced7fd6f3c2611a7080e2c823b87ea13d --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets @@ -0,0 +1,47 @@ +/* + * 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 cors_loccross_two] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: WebviewController = new webview.WebviewController(); + + build() { + Row() { + Web({ src: '', controller: this.controller }) + .onControllerAttached(() => { + try { + // 设置允许可以跨域访问的路径列表 + this.controller.setPathAllowingUniversalAccess([ + getContext().resourceDir, + getContext().filesDir + '/example' + ]); + this.controller.loadUrl('file://' + getContext().resourceDir + '/index.html'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + .javaScriptAccess(true) + .fileAccess(true) + .domStorageAccess(true) + } + } +} +// [End cors_loccross_two] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets new file mode 100644 index 0000000000000000000000000000000000000000..23fdec43f07cb906691e0505bdc65cd5306e1e36 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets @@ -0,0 +1,45 @@ +/* + * 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 retrieve_blocked_and_visited_domain_names] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + // 需要打开智能防跟踪功能,才会触发onIntelligentTrackingPreventionResult回调 + Button('enableIntelligentTrackingPrevention') + .onClick(() => { + try { + this.controller.enableIntelligentTrackingPrevention(true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }) + .onIntelligentTrackingPreventionResult((details) => { + console.log('onIntelligentTrackingPreventionResult: [websiteHost]= ' + details.host + + ', [trackerHost]=' + details.trackerHost); + }) + } + } +} +// [End retrieve_blocked_and_visited_domain_names] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets b/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets new file mode 100644 index 0000000000000000000000000000000000000000..ed8c741879f229405e43b14fbc72650b4df53ec9 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.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 partial_domain_name_list] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('removeIntelligentTrackingPreventionBypassingList') + .onClick(() => { + try { + let hostList = [ 'www.test1.com', 'www.test2.com' ]; + webview.WebviewController.removeIntelligentTrackingPreventionBypassingList(hostList); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End partial_domain_name_list] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/module.json5 b/ManageWebCompSecPriv/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json b/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/main/resources/base/element/string.json b/ManageWebCompSecPriv/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..68f2a3f7cd4e6b25d5f6224c60837ba99c25ec76 --- /dev/null +++ b/ManageWebCompSecPriv/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": "ManageWebCompSecPriv" + }, + { + "name": "web_path", + "value": "https://www.example.com" + } + ] +} \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png b/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png differ diff --git a/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png b/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebCompSecPriv/entry/src/main/resources/base/media/layered_image.json b/ManageWebCompSecPriv/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png b/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json b/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json b/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..8a72c3b7803a5e5cd787f8239bc1a60b9f60391c --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,17 @@ +{ + "src": [ + "pages/Index", + "pages/LocCrossOriginResAccSol_one", + "pages/LocCrossOriginResAccSol_two", + "pages/AddIntTrackPreventByPassList", + "pages/ClearIntTrackPreventByPassList", + "pages/EnableIntTrackPrevent", + "pages/IsIntTrackPreventEnabled", + "pages/OnIntTrackPreventResult", + "pages/RemoveIntTrackPreventByPassList", + "pages/EnablingAdsBlocking", + "pages/DisAdsBlockSpecDomPages_one", + "pages/DisAdsBlockSpecDomPages_two", + "pages/CollectingAdsBlockingInformation" + ] +} \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/resources/en_US/element/string.json b/ManageWebCompSecPriv/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6aba54ea1bb3ac12f412cb39a46e76081f6fcc31 --- /dev/null +++ b/ManageWebCompSecPriv/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": "ManageWebCompSecPriv" + } + ] +} \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html b/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..01ba29a16a4306f3ed6bd10c2c7a9cdb84e5285e --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js b/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js new file mode 100644 index 0000000000000000000000000000000000000000..dfd1c0b8cb035c61be2f521a59d66908d4b4c023 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js @@ -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. + */ + +// [Start cors_script_raw] +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'success'; +body.appendChild(element); +// [End cors_script_raw] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html b/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..e8aa15081537f3f522e4ed361345524ca955f8f3 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html @@ -0,0 +1,56 @@ + + + + + + + + Demo + + + + + +
+ +
+
+ + + diff --git a/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js b/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js new file mode 100644 index 0000000000000000000000000000000000000000..9853f099a5d5f45d51460a9c53fd067ed68eb240 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js @@ -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. + */ + +// [Start cors_script] +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'success'; +body.appendChild(element); +// [End cors_script] \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/main/resources/zh_CN/element/string.json b/ManageWebCompSecPriv/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fa45cf3851f9f2519e27031ca337ffd4bd784ce5 --- /dev/null +++ b/ManageWebCompSecPriv/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": "ManageWebCompSecPriv" + } + ] +} \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/mock/mock-config.json5 b/ManageWebCompSecPriv/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f1d36678d8f270241ce6d2f73e6654664986586 --- /dev/null +++ b/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,369 @@ +/* + * 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. + }) + + /** + * 打开应用,点击 LocCrossOriginResAccSol_one 按钮 + * 对本地资源进行拦截和相应的替换 + */ + it('LocCrossOriginResAccSol_one', 0, async (done: Function) => { + console.info('uitest: LocCrossOriginResAccSol_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('LocCrossOriginResAccSol_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('index.html'); + + await driver.pressBack(); + console.info('uitest: LocCrossOriginResAccSol_one end'); + done(); + }); + + /** + * 点击 LocCrossOriginResAccSol_two 按钮,跨域访问本地文件 + */ + it('LocCrossOriginResAccSol_two', 0, async (done: Function) => { + console.info('uitest: LocCrossOriginResAccSol_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LocCrossOriginResAccSol_two')); + 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(); + + const web1 = await driver.findComponent(ON.type('Web')); + let src = await web1.getText(); + expect(src).assertContain(''); + + await driver.pressBack(); + console.info('uitest: LocCrossOriginResAccSol_two end'); + done(); + }); + + /** + * 点击 AddIntTrackPreventByPassList 按钮 + * 设置需要绕过智能防跟踪功能的域名列表 + */ + it('AddIntTrackPreventByPassList',0, async (done: Function) => { + console.info('uitest: AddIntTrackPreventByPassList begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('AddIntTrackPreventByPassList')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + 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: AddIntTrackPreventByPassList end'); + done(); + }); + + /** + * 点击 ClearIntTrackPreventByPassList 按钮 + * 清除通过 addIntelligentTrackingPreventionBypassingList 接口设置的所有域名 + */ + it('ClearIntTrackPreventByPassList',0, async (done: Function) => { + console.info('uitest: ClearIntTrackPreventByPassList begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ClearIntTrackPreventByPassList')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + 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: ClearIntTrackPreventByPassList end'); + done(); + }); + + /** + * 点击 EnableIntTrackPrevent 按钮 + * 使能或者关闭相应Web组件的智能防跟踪功能 + */ + it('EnableIntTrackPrevent',0, async (done: Function) => { + console.info('uitest: EnableIntTrackPrevent begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('EnableIntTrackPrevent')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + 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: EnableIntTrackPrevent end'); + done(); + }); + + /** + * 点击 IsIntTrackPreventEnabled 按钮 + * 判断当前Web组件是否开启了智能防跟踪功能 + */ + it('IsIntTrackPreventEnabled',0, async (done: Function) => { + console.info('uitest: IsIntTrackPreventEnabled begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('IsIntTrackPreventEnabled')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + 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: IsIntTrackPreventEnabled end'); + done(); + }); + + /** + * 点击 OnIntTrackPreventResult 按钮 + * 异步获取拦截的跟踪型网站的域名和访问的网站域名信息 + */ + it('OnIntTrackPreventResult',0, async (done: Function) => { + console.info('uitest: OnIntTrackPreventResult begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('OnIntTrackPreventResult')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + 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: OnIntTrackPreventResult end'); + done(); + }); + + /** + * 点击 RemoveIntTrackPreventByPassList 按钮 + * 移除通过 addIntelligentTrackingPreventionBypassingList 接口设置的部分域名列表 + */ + it('RemoveIntTrackPreventByPassList',0, async (done: Function) => { + console.info('uitest: RemoveIntTrackPreventByPassList begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('RemoveIntTrackPreventByPassList')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + 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: RemoveIntTrackPreventByPassList end'); + done(); + }); + + /** + * 点击 EnablingAdsBlocking 按钮 + * 设置自定义的easylist过滤规则并使能广告过滤特性 + */ + it('EnablingAdsBlocking',0, async (done: Function) => { + console.info('uitest: EnablingAdsBlocking begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('EnablingAdsBlocking')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + await driver.pressBack(); + 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: EnablingAdsBlocking end'); + done(); + }); + + /** + * 点击 DisAdsBlockSpecDomPages_one 按钮 + * 关闭一些特定页面的广告过滤功能 + */ + it('DisAdsBlockSpecDomPages_one',0, async (done: Function) => { + console.info('uitest: DisAdsBlockSpecDomPages_one begin'); + const driver = Driver.create(); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('DisAdsBlockSpecDomPages_one')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('Go')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('addAdsBlockDisallowedList')); + await button3.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: DisAdsBlockSpecDomPages_one end'); + done(); + }); + + /** + * 点击 DisAdsBlockSpecDomPages_two 按钮 + * 使用 addAdsBlockDisallowedList 接口添加域名 + */ + it('DisAdsBlockSpecDomPages_two',0, async (done: Function) => { + console.info('uitest: DisAdsBlockSpecDomPages_two begin'); + const driver = Driver.create(); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('DisAdsBlockSpecDomPages_two')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('Go')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('addAdsBlockAllowedList')); + await button3.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: DisAdsBlockSpecDomPages_two end'); + done(); + }); + + /** + * 点击 CollectingAdsBlockingInformation 按钮 + * 触发发生了广告过滤后过滤信息的收集和统计 + */ + it('CollectingAdsBlockingInformation',0, async (done: Function) => { + console.info('uitest: CollectingAdsBlockingInformation begin'); + const driver = Driver.create(); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('CollectingAdsBlockingInformation')); + await button1.click(); + await driver.delayMs(1000); + + const type1 = await driver.findComponent(ON.type('Web')); + let text: string = await type1.getText(); + expect(text).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: CollectingAdsBlockingInformation end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 b/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/test/List.test.ets b/ManageWebCompSecPriv/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/entry/src/test/LocalUnit.test.ets b/ManageWebCompSecPriv/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/hvigor/hvigor-config.json5 b/ManageWebCompSecPriv/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/hvigorfile.ts b/ManageWebCompSecPriv/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/oh-package.json5 b/ManageWebCompSecPriv/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ManageWebCompSecPriv/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/ManageWebCompSecPriv/ohosTest.md b/ManageWebCompSecPriv/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..a63576a348152f48f2d0a0658a723c18c0b87e15 --- /dev/null +++ b/ManageWebCompSecPriv/ohosTest.md @@ -0,0 +1,71 @@ +### LocCrossOriginResAccSol_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------- | ------------ | ------------ | ------------------ | -------- | -------- | +| 解决Web组件本地资源跨域问题 | 设备运转正常 | 应用启动成功 | 加载index.html页面 | Yes | Pass | + +### LocCrossOriginResAccSol_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------- | ------------------------------------ | ------------------------------- | ------------------------------------ | -------- | -------- | +| 解决Web组件本地资源跨域问题 | 设备运转正常,index.html页面加载完成 | 应用启动成功,点击stealFile按钮 | 跨域访问本地resfile/js/script.js文件 | Yes | Pass | + +### AddIntTrackPreventByPassList + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | -------------------------------- | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击addIntelligentTrackingPreventionBypassingList按钮 | 设置需要绕过智能防跟踪功能的域名 | Yes | Pass | + +### ClearIntTrackPreventByPassList + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击clearIntelligentTrackingPreventionBypassingList按钮 | 清除通过addIntelligentTrackingPreventionBypassingList接口设置的所有域名 | Yes | Pass | + +### EnableIntTrackPrevent + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | --------------------------------------------------------- | ------------------------------- | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击enableIntelligentTrackingPrevention按钮 | 使能相应Web组件的智能防跟踪功能 | Yes | Pass | + +### IsIntTrackPreventEnabled + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | --------------------------------------- | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击isIntelligentTrackingPreventionEnabled按钮 | 判断当前Web组件是否开启了智能防跟踪功能 | Yes | Pass | + +### OnIntTrackPreventResult + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ----------------------------------------------------------- | ------------------------------------------------ | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击onIntelligentTrackingPreventionResult按钮 | 获取拦截的跟踪型网站的域名和访问的网站域名信息。 | Yes | Pass | + +### RemoveIntTrackPreventByPassList + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -------- | +| 使用智能防跟踪功能 | 设备运转正常 | 应用启动成功,点击removeIntelligentTrackingPreventionBypassingList按钮 | 移除通过addIntelligentTrackingPreventionBypassingList接口设置的部分域名列表 | Yes | Pass | + +### EnablingAdsBlocking + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | -------------------------------------- | -------------- | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功,点击setAdsBlockRules按钮 | 打开文件选择器 | Yes | Pass | + +### DisAdsBlockSpecDomPages_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ----------------------------------------------- | -------------------------- | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功,点击addAdsBlockDisallowedList按钮 | 关闭特定域名页面的广告过滤 | Yes | Pass | + +### DisAdsBlockSpecDomPages_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ----------------------------------------------- | -------- | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功,点击addAdsBlockDisallowedList按钮 | 添加域名 | Yes | Pass | + +### CollectingAdsBlockingInformation + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ------------ | ------------------ | -------- | -------- | +| 使用Web组件的广告过滤功能 | 设备运转正常 | 应用启动成功 | 收集广告过滤的信息 | Yes | Pass | diff --git a/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png b/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png new file mode 100644 index 0000000000000000000000000000000000000000..ccbe69798a139432a565a9c74bef18fe5bc6f1e1 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png differ diff --git a/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png b/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png new file mode 100644 index 0000000000000000000000000000000000000000..c0438ba8b3ce0f30d8a340873cb43aef719de170 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png differ diff --git a/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png b/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png new file mode 100644 index 0000000000000000000000000000000000000000..5e3d62abefcb00d148eeaf9cfa91c255b8344a1c Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png differ diff --git a/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png b/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png new file mode 100644 index 0000000000000000000000000000000000000000..7e75e856cddf583d86e17f86a68f0c689836f298 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png differ diff --git a/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png b/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png new file mode 100644 index 0000000000000000000000000000000000000000..5f334f78a76bedca13310e917768027abaa16789 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png differ diff --git a/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png b/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png new file mode 100644 index 0000000000000000000000000000000000000000..3b2c90131beb736c785746ec54c922640cc906da Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png differ diff --git a/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png b/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png new file mode 100644 index 0000000000000000000000000000000000000000..6d6d41b49abab13406bdf04923b905d00081d7b6 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png differ diff --git a/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png b/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png new file mode 100644 index 0000000000000000000000000000000000000000..e327def8ac32a67e40b0f1319fc5ea6359dc5fe2 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png differ diff --git a/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png b/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png new file mode 100644 index 0000000000000000000000000000000000000000..31f7613ec78b6a724259d2b80cd3f7d41170241a Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png differ diff --git a/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png b/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png new file mode 100644 index 0000000000000000000000000000000000000000..a7cfbd1b813c8eacd6962fdc9552954f5b19f2a5 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png differ diff --git a/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png b/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png new file mode 100644 index 0000000000000000000000000000000000000000..816ee5693ab636c82957c6c524f5e7f10bea78a3 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png differ diff --git a/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png b/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8eb796240d9933f65ff4681d59075b93479d0809 Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png differ diff --git a/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png b/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png new file mode 100644 index 0000000000000000000000000000000000000000..bc6f50d9eaeaedf1a0fe0f907f00e6ad44f369df Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png differ diff --git a/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png b/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png new file mode 100644 index 0000000000000000000000000000000000000000..47389d196eca6812e5ed0fd941798d677785836a Binary files /dev/null and b/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png differ diff --git a/ManageWebPageFileIO/.gitignore b/ManageWebPageFileIO/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ManageWebPageFileIO/.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/ManageWebPageFileIO/AppScope/app.json5 b/ManageWebPageFileIO/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c81be320936ad21787cdb02b4d04f1015bfae2ea --- /dev/null +++ b/ManageWebPageFileIO/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.managewebpagefileio", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ManageWebPageFileIO/AppScope/resources/base/element/string.json b/ManageWebPageFileIO/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..651c9e36903ecf6afe4187bce123a1a3ab00c38d --- /dev/null +++ b/ManageWebPageFileIO/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebPageFileIO" + } + ] +} diff --git a/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png b/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png differ diff --git a/ManageWebPageFileIO/README.md b/ManageWebPageFileIO/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9b0609d97d25ba3b6935cef98bae7dd621c30369 --- /dev/null +++ b/ManageWebPageFileIO/README.md @@ -0,0 +1,133 @@ +## 上传文件 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-file-upload.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### UploadFiles + +#### 介绍 + +1. 本示例主要介绍Web组件上传文件功能,Web组件支持前端页面选择文件上传功能,应用开发者可以使用onShowvfileSelector)接口来处理前端页面文件上传的请求,如果应用开发者不做任何处理,Web会提供默认行为来处理前端页面文件上传的请求。 + +#### 效果预览 + +| 主页 | | +| ---------------------------------------------------------- | ---------------------------------------------------------- | +| | | + +使用方法 + +1. 在主页点击选择文件按钮触发onShowFileSelector事件创建DocumentSelectOptions和DocumentViewPicker,用于打开文件选择器,弹出文件选择器,用户可选择一个文件。 + +## 使用Web组件的下载能力 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-download.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### ListenForPageDown + +#### 介绍 + +1. 本示例主要介绍使用Web组件监听页面触发的下载功能,通过setDownloadDelegate()向Web组件注册一个DownloadDelegate来监听页面触发的下载任务。资源由Web组件来下载,Web组件会通过DownloadDelegate将下载的进度通知给应用。 + +#### 效果预览 + +| 主页 | 下载 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击setDownloadDelegate按钮,定义下载委托回调。 +2. 点击下载download.html链接,触发下载任务。 + +### InitiatingADownloadTask + +#### 介绍 + +1. 本示例主要介绍使用Web组件的下载能力。在Web组件启动时,可通过resumeDownload()接口恢复未完成的下载任务。 + + +#### 效果预览 + +| 主页 | 下载 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击setDownloadDelegate按钮,定义下载委托回调。 +1. 使用startDownload()接口发起一个下载。 + +### ResumeDownload + +#### 介绍 + +1. 本示例主要介绍使用Web组件的下载能力。使用startDownload()接口发起一个下载,Web组件发起的下载会根据当前显示的url以及Web组件默认的Referrer Policy来计算referrer。 + + +#### 效果预览 + +| 主页 | +| ----------------------------------------------------------- | +| | + +使用说明 + +1. 点击setDownloadDelegate按钮,定义下载委托回调。 +1. 使用startDownload()接口发起一个下载。 +1. 通过record按钮将当前下载任务保存至持久化文件中,记录下载任务信息。 +1. 点击recovery按钮恢复下载任务。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---UploadFiles.ets +|---|---|---downloadUtil.ets +|---|---|---Index.ets // 首页 +|---|---|---InitiatingADownloadTask.ets +|---|---|---ListenForPageDown.ets +|---|---|---ResumeDownload.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 code/DocsSample/ArkWeb/ManageWebPageFileIO > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ManageWebPageFileIO/build-profile.json5 b/ManageWebPageFileIO/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/code-linter.json5 b/ManageWebPageFileIO/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/.gitignore b/ManageWebPageFileIO/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageFileIO/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/build-profile.json5 b/ManageWebPageFileIO/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/hvigorfile.ts b/ManageWebPageFileIO/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/obfuscation-rules.txt b/ManageWebPageFileIO/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/oh-package.json5 b/ManageWebPageFileIO/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets b/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets b/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..80e8214f747914b9b3b64331d9eb37fd1619a007 --- /dev/null +++ b/ManageWebPageFileIO/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('UploadFiles') + .onClick(() => { + router.pushUrl({ url: 'pages/UploadFiles' }); + }) + Button('ListenForPageDown') + .onClick(() => { + router.pushUrl({ url: 'pages/ListenForPageDown' }); + }) + Button('InitiatingADownloadTask') + .onClick(() => { + router.pushUrl({ url: 'pages/InitiatingADownloadTask' }); + }) + Button('ResumeDownload') + .onClick(() => { + router.pushUrl({ url: 'pages/ResumeDownload' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets b/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b876e5f292321bcd2a884cd16a2f360516b7f02 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets @@ -0,0 +1,73 @@ +/* + * 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 init_download_task] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + @State myText: string = 'download'; + + build() { + Column() { + Text(this.myText) + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // 传入一个下载路径,并开始下载。 + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + console.log('download update guid: ' + webDownloadItem.getGuid()); + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + this.myText = 'download finish'; + }) + this.controller.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('startDownload') + .onClick(() => { + try { + // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 + // 开发者需要替换为自己想要下载的内容的地址。 + this.controller.startDownload(resourceToString($r('app.string.web_path'))); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End init_download_task] diff --git a/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets b/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets new file mode 100644 index 0000000000000000000000000000000000000000..733a26d4b9600db7f50a41cc0b338561f1584951 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets @@ -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. + */ + +// [Start download_delegate] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + @State myText: string = 'download'; + + build() { + Column() { + Text(this.myText) + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // Pass in a download path and start the download. + // If the path is invalid, the file will be downloaded to the + // default directory at /data/storage/el2/base/cache/web/. + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + // Unique ID of a download task. + console.log('download update guid: ' + webDownloadItem.getGuid()); + // Download progress. + console.log('download update guid: ' + webDownloadItem.getPercentComplete()); + // Current download speed. + console.log('download update speed: ' + webDownloadItem.getCurrentSpeed()); + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + // Error code of a download task failure. + console.log('download failed guid: ' + webDownloadItem.getLastErrorCode()); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + this.myText = 'download finish'; + }) + this.controller.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $rawfile('index.html'), controller: this.controller }) + } + } +} +// [End download_delegate] diff --git a/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets b/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets new file mode 100644 index 0000000000000000000000000000000000000000..c0d230cdc7916565a9760fad159c3f84b950243c --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets @@ -0,0 +1,106 @@ +/* + * 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 recovery_download_task] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { DownloadUtil, fileName, filePath } from './downloadUtil'; // downloadUtil.ets 见下文 + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + download: webview.WebDownloadItem = new webview.WebDownloadItem(); + // 用于记录失败的下载任务。 + failedData: Uint8Array = new Uint8Array(); + + build() { + Column() { + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // 传入一个下载路径,并开始下载。 + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + console.log('download update percent complete: ' + webDownloadItem.getPercentComplete()); + this.download = webDownloadItem; + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + // 序列化失败的下载任务到一个字节数组。 + this.failedData = webDownloadItem.serialize(); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + }) + this.controller.setDownloadDelegate(this.delegate); + webview.WebDownloadManager.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('startDownload') + .onClick(() => { + try { + // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 + // 开发者需要替换为自己想要下载的内容的地址。 + this.controller.startDownload(resourceToString($r('app.string.web_path'))); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 将当前的下载任务信息序列化保存,用于后续恢复下载任务。 + // 当前用例仅展示下载一个任务的场景,多任务场景请按需扩展。 + Button('record') + .onClick(() => { + try { + // 保存当前下载数据到持久化文档中。 + DownloadUtil.saveDownloadInfo(DownloadUtil.uint8ArrayToStr(this.download.serialize())); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 从序列化的下载任务信息中,恢复下载任务。 + // 按钮触发时必须保证WebDownloadManager.setDownloadDelegate设置完成。 + Button('recovery') + .onClick(() => { + try { + // 当前默认持久化文件存在,用户根据实际情况增加判断。 + let webDownloadItem = + webview.WebDownloadItem.deserialize( + DownloadUtil.strToUint8Array(DownloadUtil.readFileSync(filePath, fileName))); + webview.WebDownloadManager.resumeDownload(webDownloadItem); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End recovery_download_task] \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets b/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5e26614ec7193c00bd97c8ca7aca9b5d14d66b1 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.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. + */ + +// [Start web_file_upload] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { picker } from '@kit.CoreFileKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $rawfile('local.html'), controller: this.controller }) + .onShowFileSelector((event) => { + console.log('MyFileUploader onShowFileSelector invoked'); + const documentSelectOptions = new picker.DocumentSelectOptions(); + let uri: string | null = null; + const documentViewPicker = new picker.DocumentViewPicker(); + documentViewPicker.select(documentSelectOptions).then((documentSelectResult) => { + uri = documentSelectResult[0]; + console.info('documentViewPicker.select to file succeed and uri is:' + uri); + if (event) { + event.result.handleFileList([uri]); + } + }).catch((err: BusinessError) => { + console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`); + }) + return true; + }) + } + } +} +// [End web_file_upload] diff --git a/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets b/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..be9907e29f5341089f5e24a75fbefb6b08917e44 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets @@ -0,0 +1,68 @@ +/* + * 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 task_info_persistence_util] +import { util } from '@kit.ArkTS'; +import fileStream from '@ohos.file.fs'; + +const helper = new util.Base64Helper(); + +export const filePath = getContext().filesDir; +export const fileName = 'demoFile.txt'; +export namespace DownloadUtil { + + export function uint8ArrayToStr(uint8Array: Uint8Array): string { + return helper.encodeToStringSync(uint8Array); + } + + export function strToUint8Array(str: string): Uint8Array { + return helper.decodeSync(str); + } + + export function saveDownloadInfo(downloadInfo: string): void { + if (!fileExists(filePath)) { + mkDirectorySync(filePath); + } + + writeToFileSync(filePath, fileName, downloadInfo); + } + + export function fileExists(filePath: string): boolean { + try { + return fileStream.accessSync(filePath); + } catch (error) { + return false; + } + } + + export function mkDirectorySync(directoryPath: string, recursion?: boolean): void { + try { + fileStream.mkdirSync(directoryPath, recursion ?? false); + } catch (error) { + console.error(`mk dir error. err message: ${error.message}, err code: ${error.code}`); + } + } + + export function writeToFileSync(dir: string, fileName: string, msg: string): void { + let file = fileStream.openSync(dir + '/' + fileName, fileStream.OpenMode.WRITE_ONLY | fileStream.OpenMode.CREATE); + fileStream.writeSync(file.fd, msg); + } + + export function readFileSync(dir: string, fileName: string): string { + return fileStream.readTextSync(dir + '/' + fileName); + } + +} +// [End task_info_persistence_util] \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/main/module.json5 b/ManageWebPageFileIO/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json b/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/main/resources/base/element/string.json b/ManageWebPageFileIO/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..883cf5800d2f788f5b396cc9fbe250677c524829 --- /dev/null +++ b/ManageWebPageFileIO/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": "ManageWebPageFileIO" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png b/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png b/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageFileIO/entry/src/main/resources/base/media/layered_image.json b/ManageWebPageFileIO/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png b/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json b/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json b/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c163d886b69f969ad6975c6ac9fc06556384d468 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/UploadFiles", + "pages/ListenForPageDown", + "pages/InitiatingADownloadTask", + "pages/ResumeDownload" + ] +} diff --git a/ManageWebPageFileIO/entry/src/main/resources/en_US/element/string.json b/ManageWebPageFileIO/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b22824ad2f373eba1f5d72ee7ae6cddd9f82a8f --- /dev/null +++ b/ManageWebPageFileIO/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": "ManageWebPageFileIO" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html b/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html new file mode 100644 index 0000000000000000000000000000000000000000..79e8cc88be2c00e1a49303cd9ddffeb2e55b6c25 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html @@ -0,0 +1,21 @@ + + + + + +

download test

+ + \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html b/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..3dab642cbf493c630cec7194e2ea9c24d9dfadc8 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,21 @@ + + + + + +Download + + diff --git a/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html b/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html new file mode 100644 index 0000000000000000000000000000000000000000..a02fa4eb2b9854bcea11238cd13e25bafc9e9156 --- /dev/null +++ b/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html @@ -0,0 +1,28 @@ + + + + + + + Document + + + + +
+ + + diff --git a/ManageWebPageFileIO/entry/src/main/resources/zh_CN/element/string.json b/ManageWebPageFileIO/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..24c323f82206183076757243cbd869c488fd30f1 --- /dev/null +++ b/ManageWebPageFileIO/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": "ManageWebPageFileIO" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/mock/mock-config.json5 b/ManageWebPageFileIO/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb7966dc1b673cb46d7ead5c41419c25af4522ae --- /dev/null +++ b/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,184 @@ +/* + * 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('UploadFiles', 0, async (done: Function) => { + console.info('uitest: UploadFiles 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('UploadFiles')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.clickable(true).enabled(true)); + await button2.click(); + await driver.delayMs(3000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('local.html'); + + await driver.pressBack(); + await driver.delayMs(1000); + await driver.pressBack(); + await driver.delayMs(1000); + console.info('uitest: UploadFiles end'); + done(); + }); + + /* + * 点击 ListenForPageDown 按钮 + * 使用Web组件监听页面触发的下载 + */ + it('ListenForPageDown', 0, async (done: Function) => { + console.info('uitest: ListenForPageDown begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ListenForPageDown')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('setDownloadDelegate')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('Download')); + await button3.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('index.html'); + + const type1 = await driver.findComponent(ON.type('Text')); + let text1: string = await type1.getText(); + expect(text1).assertEqual('download finish'); + + await driver.pressBack(); + console.info('uitest: ListenForPageDown end'); + done(); + }); + + /* + * 点击 InitiatingADownloadTask 按钮 + * 使用Web组件的下载能力 + */ + it('InitiatingADownloadTask',0, async (done: Function) => { + console.info('uitest: InitiatingADownloadTask begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('InitiatingADownloadTask')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('setDownloadDelegate')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('startDownload')); + await button3.click(); + await driver.delayMs(4000); + + const type1 = await driver.findComponent(ON.type('Text')); + let text1: string = await type1.getText(); + expect(text1).assertEqual('download finish'); + + await driver.pressBack(); + console.info('uitest: InitiatingADownloadTask end'); + done(); + }); + + /* + * 点击 ResumeDownload 按钮 + * 发起一个下载,Web组件发起的下载会根据当前显示的url以及Web组件默认的Referrer Policy来计算referrer + */ + it('ResumeDownload',0, async (done: Function) => { + console.info('uitest: ResumeDownload begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ResumeDownload')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('setDownloadDelegate')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.text('startDownload')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('record')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.text('recovery')); + await button5.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: ResumeDownload end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ManageWebPageFileIO/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebPageFileIO/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/ohosTest/module.json5 b/ManageWebPageFileIO/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/test/List.test.ets b/ManageWebPageFileIO/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/entry/src/test/LocalUnit.test.ets b/ManageWebPageFileIO/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/hvigor/hvigor-config.json5 b/ManageWebPageFileIO/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/hvigorfile.ts b/ManageWebPageFileIO/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/oh-package.json5 b/ManageWebPageFileIO/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ManageWebPageFileIO/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/ManageWebPageFileIO/ohosTest.md b/ManageWebPageFileIO/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..09391f96fdc12e8ac2491af0cc7af217d206c44b --- /dev/null +++ b/ManageWebPageFileIO/ohosTest.md @@ -0,0 +1,28 @@ +#### UploadFiles + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ------------------------------------ | -------------- | -------- | -------- | +| 上传文件 | 设备运转正常 | 应用启动成功,在主页点击选择文件按钮 | 弹出文件选择器 | Yes | Pass | + +#### ListenForPageDown + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ---------------- | ----------------------------------------- | ---------------------------- | -------- | -------- | +| 使用Web组件的下载能力 | 设备运转正常 | 应用启动成功,点击setDownloadDelegate按钮 | 定义下载委托回调 | Yes | Pass | +| download | 定义下载委托回调 | 点击下载download.html链接 | 触发下载任务,为Text组件更名 | Yes | Pass | + +#### InitiatingADownloadTask + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ---------------- | ----------------------------------------- | ---------------------------- | -------- | -------- | +| 使用Web组件的下载能力 | 设备运转正常 | 应用启动成功,点击setDownloadDelegate按钮 | 定义下载委托回调 | Yes | Pass | +| startDownload() | 定义下载委托回调 | 使用startDownload按钮 | 发起一个下载,为Text组件更名 | Yes | Pass | + +#### ResumeDownload + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ---------------- | ----------------------------------------- | -------------------------------- | -------- | -------- | +| 使用Web组件的下载能力 | 设备运转正常 | 应用启动成功,点击setDownloadDelegate按钮 | 定义下载委托回调 | Yes | Pass | +| startDownload() | 定义下载委托回调 | 使用startDownload按钮 | 发起一个下载,为Text组件更名 | Yes | Pass | +| 记录下载任务信息 | 发起一个下载 | 点击record按钮 | 将当前下载任务保存至持久化文件中 | Yes | Pass | +| 恢复下载任务 | 记录下载任务信息 | 点击recovery按钮 | 恢复下载任务 | Yes | Pass | diff --git a/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png b/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png new file mode 100644 index 0000000000000000000000000000000000000000..638d816041eeaa5df04c9ea8d9faed0a43c074a5 Binary files /dev/null and b/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png differ diff --git a/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png b/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1126c64170901e237ae6a5c3189b61577afea4bc Binary files /dev/null and b/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png differ diff --git a/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png b/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png new file mode 100644 index 0000000000000000000000000000000000000000..da6c2b942cf47810384d06a6e68975a7e32c4ccf Binary files /dev/null and b/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png differ diff --git a/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png b/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png new file mode 100644 index 0000000000000000000000000000000000000000..474253d8840f12efe2c581698a4a34878d3e5e03 Binary files /dev/null and b/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png differ diff --git a/ManageWebPageFileIO/screenshots/ResumeDownload.png b/ManageWebPageFileIO/screenshots/ResumeDownload.png new file mode 100644 index 0000000000000000000000000000000000000000..84aa81093ac4cbd3c800d30633ae81f8e96587aa Binary files /dev/null and b/ManageWebPageFileIO/screenshots/ResumeDownload.png differ diff --git a/ManageWebPageFileIO/screenshots/UploadFiles_1.png b/ManageWebPageFileIO/screenshots/UploadFiles_1.png new file mode 100644 index 0000000000000000000000000000000000000000..83e3761eb2482a0bd2822c7624d49ed19e090809 Binary files /dev/null and b/ManageWebPageFileIO/screenshots/UploadFiles_1.png differ diff --git a/ManageWebPageFileIO/screenshots/UploadFiles_2.png b/ManageWebPageFileIO/screenshots/UploadFiles_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1fa35a07316427ee7d43b791e721d0b634d985e9 Binary files /dev/null and b/ManageWebPageFileIO/screenshots/UploadFiles_2.png differ diff --git a/ManageWebPageInteracts/.gitignore b/ManageWebPageInteracts/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ManageWebPageInteracts/.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/ManageWebPageInteracts/AppScope/app.json5 b/ManageWebPageInteracts/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce3d05eda7baad507acf0e8de81df905cdf32d67 --- /dev/null +++ b/ManageWebPageInteracts/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.managewebpageinteracts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ManageWebPageInteracts/AppScope/resources/base/element/string.json b/ManageWebPageInteracts/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..be8d935f6276f0e2833fde78d0f8320e6447b4f7 --- /dev/null +++ b/ManageWebPageInteracts/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebPageInteracts" + } + ] +} diff --git a/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png b/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png differ diff --git a/ManageWebPageInteracts/README.md b/ManageWebPageInteracts/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0802ff52bb78c2892693bfb7fd56a773022fbc23 --- /dev/null +++ b/ManageWebPageInteracts/README.md @@ -0,0 +1,151 @@ +# entry: + +## Web组件嵌套滚动 + +### 介绍 + +#### ImpNestedScroll + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-nested-scrolling.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +##### 效果预览 + +| 主页 | +| ---------------------------------------------------------- | +| | + +##### 使用说明 + +1. 设置滚动模式(前) + - 在 切换前滚动模式 区域,点击 SELF_ONLY、SELF_FIRST、PARENT_FIRST、PARALLEL 按钮,可分别将 NestedScrollModeF 设置为相应的滚动模式,此模式用于控制 Web 视图向前滚动(scrollForward)时与父组件的交互方式。 +2. 设置滚动模式(后) + - 在 切换后滚动模式 区域,同样点击上述按钮,可设置NestedScrollModeB,用于控制 Web 视图向后滚动(scrollBackward)时的交互模式。 + +## Web组件对接软键盘 + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-docking-softkeyboard.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +#### SetSKBMode_one + +##### 介绍 + +1. 本示例主要介绍Web组件对接软键盘,在UIContext的键盘避让模式为Offset模式情况下,通过WebKeyboardAvoidMode()设置ArkWeb组件的键盘避让模式。 + +##### 效果预览 + +| 主页 | 软键盘 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击输入框拉起软键盘。 + +#### OnIntKbdAttachSysCustIn + +##### 介绍 + +1. 本示例主要介绍拦截系统软键盘与自定义软键盘输入,调用onInterceptKeyboardAttach来拦截系统软键盘的弹出。 + + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 点击未设置特殊属性的输入框,将默认使用系统默认键盘。 +2. 点击设置了keyboard-return属性的输入框,根据属性值获取对应的enterKeyType,以改变系统键盘回车键的行为。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---OnIntKbdAttachSysCustIn.ets +|---|---|---SetSKBMode_one.ets +|---|---|---ImpNestedScroll.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) + +## entry2: + +### SetSKBMode_two + +#### 介绍 + +1. 本示例主要介绍Web组件对接软键盘,设置UIContext的软键盘避让模式setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE),应用窗口高度可缩小避开软键盘,ArkWeb组件跟随ArkUI重新布局。 + +#### 效果预览 + +| 主页 | 软键盘 | +| ----------------------------------------------------------- | ----------------------------------------------------------- | +| | | + +使用说明 + +1. 点击输入框拉起软键盘。 + +### 工程目录 + +``` +entry2/src/main/ +|---ets +|---|---entry2ability +|---|---|---Entry2Ability.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 code/DocsSample/ArkWeb/ManageWebPageInteracts > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ManageWebPageInteracts/build-profile.json5 b/ManageWebPageInteracts/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c00db5abef42d324e414e34ba929de407db76b8a --- /dev/null +++ b/ManageWebPageInteracts/build-profile.json5 @@ -0,0 +1,63 @@ +/* +* 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" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ManageWebPageInteracts/code-linter.json5 b/ManageWebPageInteracts/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/.gitignore b/ManageWebPageInteracts/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageInteracts/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/build-profile.json5 b/ManageWebPageInteracts/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/hvigorfile.ts b/ManageWebPageInteracts/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/obfuscation-rules.txt b/ManageWebPageInteracts/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/oh-package.json5 b/ManageWebPageInteracts/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets b/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets b/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets new file mode 100644 index 0000000000000000000000000000000000000000..502a4cc8780ad87d5ceff274637b369f27c1af63 --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets @@ -0,0 +1,139 @@ +/* + * 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 nested_scrolling] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct NestedScroll { + private scrollerForScroll: Scroller = new Scroller(); + controller: webview.WebviewController = new webview.WebviewController(); + controller2: webview.WebviewController = new webview.WebviewController(); + // NestedScrollMode设置成SELF_ONLY时,Web网页滚动到页面边缘后,不与父组件联动,父组件仍无法滚动。 + @State nestedScrollMode0: NestedScrollMode = NestedScrollMode.SELF_ONLY; + // NestedScrollMode设置成SELF_FIRST时,Web网页滚动到页面边缘后,父组件继续滚动。 + @State nestedScrollMode1: NestedScrollMode = NestedScrollMode.SELF_FIRST; + // NestedScrollMode设置为PARENT_FIRST时,父组件先滚动,滚动至边缘后通知Web继续滚动。 + @State nestedScrollMode2: NestedScrollMode = NestedScrollMode.PARENT_FIRST; + // NestedScrollMode设置为PARALLEL时,父组件与Web同时滚动。 + @State nestedScrollMode3: NestedScrollMode = NestedScrollMode.PARALLEL; + @State nestedScrollModeF: NestedScrollMode = NestedScrollMode.SELF_FIRST; + @State nestedScrollModeB: NestedScrollMode = NestedScrollMode.SELF_FIRST; + // scroll竖向的滚动 + @State scrollDirection: ScrollDirection = ScrollDirection.Vertical; + + build() { + Flex() { + Scroll(this.scrollerForScroll) { + Column({ space: 5 }) { + Row({}) { + Text('切换前滚动模式').fontSize(5) + Button('SELF_ONLY').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode0 + }).fontSize(5) + Button('SELF_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode1 + }).fontSize(5) + Button('PARENT_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode2 + }).fontSize(5) + Button('PARALLEL').onClick((event: ClickEvent) => { + this.nestedScrollModeF = this.nestedScrollMode3 + }).fontSize(5) + } + + Row({}) { + Text('切换后滚动模式').fontSize(5) + Button('SELF_ONLY').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode0 + }).fontSize(5) + Button('SELF_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode1 + }).fontSize(5) + Button('PARENT_FIRST').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode2 + }).fontSize(5) + Button('PARALLEL').onClick((event: ClickEvent) => { + this.nestedScrollModeB = this.nestedScrollMode3 + }).fontSize(5) + } + + Text('当前内嵌前滚动模式 scrollForward ---' + `${this.nestedScrollModeF}`).fontSize(10) + Text('当前内嵌后滚动模式 scrollBackward ---' + `${this.nestedScrollModeB}`).fontSize(10) + + Text('Scroll Area') + .width('100%') + .height('10%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + Text('Scroll Area') + .width('100%') + .height('10%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + Text('Scroll Area') + .width('100%') + .height('10%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + Web({ src: 'www.example.com', controller: this.controller }) + .nestedScroll({ + scrollForward: this.nestedScrollModeF, + scrollBackward: this.nestedScrollModeB, + }) + .height('40%') + .width('100%') + + Text('Scroll Area') + .width('100%') + .height('20%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + Text('Scroll Area') + .width('100%') + .height('20%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + Web({ src: 'www.example.com', controller: this.controller2 }) + .nestedScroll({ + scrollForward: this.nestedScrollModeF, + scrollBackward: this.nestedScrollModeB, + }) + .height('40%') + .width('90%') + + Text('Scroll Area') + .width('100%') + .height('20%') + .backgroundColor(0X330000FF) + .fontSize(16) + .textAlign(TextAlign.Center) + + }.width('95%').border({ width: 5 }) + } + .width('100%').height('120%').border({ width: 5 }).scrollable(this.scrollDirection) + }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20) + } +} +// [End nested_scrolling] \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets b/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9b6f41e802970502c50ee0ea64b70bc455da97a --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/ets/pages/Index.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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('ImpNestedScroll') + .onClick(() => { + router.pushUrl({ url: 'pages/ImpNestedScroll' }); + }) + Button('OnIntKbdAttachSysCustIn') + .onClick(() => { + router.pushUrl({ url: 'pages/OnIntKbdAttachSysCustIn' }); + }) + Button('SetSKBMode_one') + .onClick(() => { + router.pushUrl({ url: 'pages/SetSKBMode_one' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets b/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets new file mode 100644 index 0000000000000000000000000000000000000000..ed6dd8f9d0e1e447a3f91400877713906f6e9d57 --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets @@ -0,0 +1,122 @@ +/* + * 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 soft_keyboard_web] +import { webview } from '@kit.ArkWeb'; +import { inputMethodEngine } from '@kit.IMEKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + webKeyboardController: WebKeyboardController = new WebKeyboardController(); + inputAttributeMap: Map = new Map([ + ['UNSPECIFIED', inputMethodEngine.ENTER_KEY_TYPE_UNSPECIFIED], + ['GO', inputMethodEngine.ENTER_KEY_TYPE_GO], + ['SEARCH', inputMethodEngine.ENTER_KEY_TYPE_SEARCH], + ['SEND', inputMethodEngine.ENTER_KEY_TYPE_SEND], + ['NEXT', inputMethodEngine.ENTER_KEY_TYPE_NEXT], + ['DONE', inputMethodEngine.ENTER_KEY_TYPE_DONE], + ['PREVIOUS', inputMethodEngine.ENTER_KEY_TYPE_PREVIOUS] + ]); + + /** + * 自定义键盘组件Builder + */ + @Builder + customKeyboardBuilder() { + // 这里实现自定义键盘组件,对接WebKeyboardController实现输入、删除、关闭等操作。 + Row() { + Text('finish') + .fontSize(20) + .fontColor(Color.Blue) + .onClick(() => { + this.webKeyboardController.close(); + }) + // 插入字符。 + Button('insertText').onClick(() => { + this.webKeyboardController.insertText('insert '); + }).margin({ + bottom: 200, + }); + // 从后往前删除length参数指定长度的字符。 + Button('deleteForward').onClick(() => { + this.webKeyboardController.deleteForward(1); + }).margin({ + bottom: 200, + }); + // 从前往后删除length参数指定长度的字符。 + Button('deleteBackward').onClick(() => { + this.webKeyboardController.deleteBackward(1); + }).margin({ + left: -220, + }); + // 插入功能按键。 + Button('sendFunctionKey').onClick(() => { + this.webKeyboardController.sendFunctionKey(6); + }) + } + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onInterceptKeyboardAttach((keyBoardCallBackInfo) => { + // option初始化,默认使用系统默认键盘 + let option: WebKeyboardOptions = { + useSystemKeyboard: true, + }; + if (!keyBoardCallBackInfo) { + return option; + } + + // 保存WebKeyboardController,使用自定义键盘时候,需要使用该handler控制输入、删除、软键盘关闭等行为 + this.webKeyboardController = keyBoardCallBackInfo.controller; + let attributes: Record = keyBoardCallBackInfo.attributes; + // 遍历attributes + let attributeKeys = Object.keys(attributes); + for (let i = 0; i < attributeKeys.length; i++) { + console.log('WebCustomKeyboard key = ' + attributeKeys[i] + ', value = ' + attributes[attributeKeys[i]]); + } + + if (attributes) { + if (attributes['data-keyboard'] == 'customKeyboard') { + // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有data-keyboard,且值为customKeyboard,则使用自定义键盘 + console.log('WebCustomKeyboard use custom keyboard'); + option.useSystemKeyboard = false; + // 设置自定义键盘builder + option.customKeyboard = () => { + this.customKeyboardBuilder(); + } + return option; + } + + if (attributes['keyboard-return'] != undefined) { + // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有keyboard-return,使用系统键盘,并且指定系统软键盘enterKey类型 + option.useSystemKeyboard = true; + let enterKeyType: number | undefined = this.inputAttributeMap.get(attributes['keyboard-return']); + if (enterKeyType != undefined) { + option.enterKeyType = enterKeyType; + } + return option; + } + } + + return option; + }) + } + } +} +// [End soft_keyboard_web] \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets b/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d04e9146f1c3eaa821bebc51a94f07561961b2c --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets @@ -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. + */ + +// [Start soft_keyboard_setmode] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct KeyboardAvoidExample { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Row().height('50%').width('100%').backgroundColor(Color.Gray) + Web({ src: $rawfile('SetSKBModeIndex.html'), controller: this.controller }) + .keyboardAvoidMode(WebKeyboardAvoidMode.OVERLAYS_CONTENT) //此时ArkWeb组件不会调整任何视口的大小大小 + Text('I can see the bottom of the page') + .width('100%') + .textAlign(TextAlign.Center) + .backgroundColor(Color.Pink) + .layoutWeight(1) + }.width('100%').height('100%') + } +} +// [End soft_keyboard_setmode] \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/main/module.json5 b/ManageWebPageInteracts/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json b/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/main/resources/base/element/string.json b/ManageWebPageInteracts/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a660c237c2319d4f72e68f5c1caafb9fb065b72c --- /dev/null +++ b/ManageWebPageInteracts/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": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png b/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png b/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageInteracts/entry/src/main/resources/base/media/layered_image.json b/ManageWebPageInteracts/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png b/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json b/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json b/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..08d6cd1a732e2be0fea3683042318567db9eb26f --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/ImpNestedScroll", + "pages/OnIntKbdAttachSysCustIn", + "pages/SetSKBMode_one" + ] +} diff --git a/ManageWebPageInteracts/entry/src/main/resources/en_US/element/string.json b/ManageWebPageInteracts/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a660c237c2319d4f72e68f5c1caafb9fb065b72c --- /dev/null +++ b/ManageWebPageInteracts/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": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html b/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html new file mode 100644 index 0000000000000000000000000000000000000000..61538c5f011d7b79e613fa0ff14c35ff008e246a --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html @@ -0,0 +1,25 @@ + + + + + + 测试网页 + + +

DEMO

+ + + diff --git a/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html b/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..126ebbb351a2ec7d26f2c3024eb907935eb13a11 --- /dev/null +++ b/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,63 @@ + + + + + + + + + + + + +

input标签,原有默认行为:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key UNSPECIFIED:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key GO:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key SEARCH:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key SEND:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key NEXT:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key DONE:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key PREVIOUS:

+
+
+ +

input标签,应用自定义键盘:

+
+ + + + diff --git a/ManageWebPageInteracts/entry/src/main/resources/zh_CN/element/string.json b/ManageWebPageInteracts/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dce1868b4c1a653b60d10f637996503b2b90d241 --- /dev/null +++ b/ManageWebPageInteracts/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": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/mock/mock-config.json5 b/ManageWebPageInteracts/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..89cfee09caf5b351f7709a00a4b92931e68ed55d --- /dev/null +++ b/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,144 @@ +/* + * 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. + }) + + /* + * 打开应用,点击 ImpNestedScroll 按钮 + * 设置滚动模式 + */ + it('ImpNestedScroll', 0, async (done: Function) => { + console.info('uitest: ImpNestedScroll 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('ImpNestedScroll')); + await button1.click(); + await driver.delayMs(500); + + const button2 = await driver.findComponent(ON.text('SELF_ONLY')); + await button2.click(); + await driver.delayMs(500); + + const button3 = await driver.findComponent(ON.text('SELF_FIRST')); + await button3.click(); + await driver.delayMs(500); + + const button4 = await driver.findComponent(ON.text('PARENT_FIRST')); + await button4.click(); + await driver.delayMs(500); + + const button5 = await driver.findComponent(ON.text('PARALLEL')); + await button5.click(); + await driver.delayMs(500); + + 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: ImpNestedScroll end'); + done(); + }); + + /* + * 打开应用,点击 OnIntKbdAttachSysCustIn 按钮 + * 调用onInterceptKeyboardAttach来拦截系统软键盘的弹出 + */ + it('OnIntKbdAttachSysCustIn', 0, async (done: Function) => { + console.info('uitest: OnIntKbdAttachSysCustIn begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('OnIntKbdAttachSysCustIn')); + await button1.click(); + await driver.delayMs(1000); + + const input1 = await driver.findComponent(ON.clickable(true).enabled(true)); + await input1.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(); + await driver.pressBack(); + console.info('uitest: OnIntKbdAttachSysCustIn end'); + done(); + }); + + /* + * 打开应用,点击 SetSKBMode_one 按钮 + * 设置ArkWeb组件的键盘避让模式 + */ + it('SetSKBMode_one', 0, async (done: Function) => { + console.info('uitest: SetSKBMode_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('SetSKBMode_one')); + await button1.click(); + await driver.delayMs(2000); + + const input1 = await driver.findComponent(ON.clickable(true).enabled(true)); + await input1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('SetSKBModeIndex.html'); + + await driver.pressBack(); + console.info('uitest: SetSKBMode_one end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebPageInteracts/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/ohosTest/module.json5 b/ManageWebPageInteracts/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/test/List.test.ets b/ManageWebPageInteracts/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry/src/test/LocalUnit.test.ets b/ManageWebPageInteracts/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/.gitignore b/ManageWebPageInteracts/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageInteracts/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/build-profile.json5 b/ManageWebPageInteracts/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9edfdf8c4a72db3313433e7366df25b6beb1c3a7 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/hvigorfile.ts b/ManageWebPageInteracts/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/obfuscation-rules.txt b/ManageWebPageInteracts/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/oh-package.json5 b/ManageWebPageInteracts/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2944307304532e967f4956384cc91447f2c9bf8c --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7cf84b7a4732e1e1512ce7602c303c116cd4fc6 --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -0,0 +1,61 @@ +/* + * 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, KeyboardAvoidMode } 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'); + } + + // [Start soft_keyboard_entryability] + 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) => { + let keyboardAvoidMode = windowStage.getMainWindowSync().getUIContext().getKeyboardAvoidMode(); + // 设置虚拟键盘抬起时压缩页面大小为减去键盘的高度 + windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE); + 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.'); + }); + } + + // [End soft_keyboard_entryability] + 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'); + } +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9a6b459004e1f1d0aefe9350f2c2ee907f66ff3 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.ets b/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ac257ec08718a4fe4c8f383f07aa413a1bb8e6c3 --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.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 soft_keyboard_index] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct KeyboardAvoidExample { + controller: webview.WebviewController = new webview.WebviewController(); + build() { + Column() { + Row().height('50%').width('100%').backgroundColor(Color.Gray) + Web({ src: $rawfile('index.html'),controller: this.controller}) + Text('I can see the bottom of the page').width('100%').textAlign(TextAlign.Center).backgroundColor(Color.Pink).layoutWeight(1) + }.width('100%').height('100%') + } +} +// [End soft_keyboard_index] \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/src/main/module.json5 b/ManageWebPageInteracts/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7ef3d746a37c973a35599267383dee3b96d7eddb --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/main/module.json5 @@ -0,0 +1,65 @@ +/* +* 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" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json b/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/src/main/resources/base/element/string.json b/ManageWebPageInteracts/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2098765bde8417c3acfa9fd16eecdbdf37cba011 --- /dev/null +++ b/ManageWebPageInteracts/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": "ManageWebPageInteracts" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png b/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png b/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageInteracts/entry2/src/main/resources/base/media/layered_image.json b/ManageWebPageInteracts/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png b/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json b/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json b/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html b/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..4699c0c00f733ad2b5675eaf7e9898c61d3e0700 --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html @@ -0,0 +1,25 @@ + + + + + + 测试网页 + + +

DEMO

+ + + \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/src/mock/mock-config.json5 b/ManageWebPageInteracts/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2417dae33e86618dcf41b9c0c0f2835b30e47b34 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2fe0b328f2c2ffec62bdd561344aa5ef4911dae0 --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.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. + */ + +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 按钮 + * 设置UIContext的软键盘避让模式 + */ + it('TestUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample 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(5000); + + const input1 = await driver.findComponent(ON.clickable(true).enabled(true)); + await input1.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/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/List.test.ets b/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 b/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..def0d923e01bc24b31568e4855ae4f6989f5f017 --- /dev/null +++ b/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 @@ -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. +*/ + +{ + "module": { + "name": "entry2_test", + "type": "feature", + "deviceTypes": [ + "phone", + "2in1", + "car" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/ManageWebPageInteracts/entry2/src/test/List.test.ets b/ManageWebPageInteracts/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/entry2/src/test/LocalUnit.test.ets b/ManageWebPageInteracts/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/hvigor/hvigor-config.json5 b/ManageWebPageInteracts/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/hvigorfile.ts b/ManageWebPageInteracts/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/oh-package.json5 b/ManageWebPageInteracts/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ManageWebPageInteracts/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/ManageWebPageInteracts/ohosTest.md b/ManageWebPageInteracts/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..5e7e391d23ad1648fb318f86edf186312263fb1b --- /dev/null +++ b/ManageWebPageInteracts/ohosTest.md @@ -0,0 +1,31 @@ +## entry: + +### ImpNestedScroll + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ---------------------------------------- | ------------------------------- | ------------------------------------------------------------ | -------- | -------- | +| Web组件嵌套滚动 | 设备运转正常,example.com 页面可正常访问 | 应用启动成功,点击SELF_ONLY按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.SELF_ONLY | Yes | Pass | +| 设置滚动模式(前) | 设备运转正常,example.com 页面可正常访问 | 点击SELF_FIRST按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.SELF_FIRST | Yes | Pass | +| 设置滚动模式(前) | 设备运转正常,example.com 页面可正常访问 | 点击PARENT_FIRST按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.PARENT_FIRST | Yes | Pass | +| 设置滚动模式(前) | 设备运转正常,example.com 页面可正常访问 | 点击PARALLEL 按钮 | 当前内嵌前滚动模式 scrollForward ---NestedScrollMode.PARALLEL | Yes | Pass | + +### OnIntKbdAttachSysCustIn + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------- | ------------ | ------------------------ | -------- | -------- | -------- | +| 拦截系统软键盘与自定义软键盘输入 | 设备运转正常 | 应用启动成功,点击输入框 | 弹出键盘 | Yes | Pass | + +### SetSKBMode_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ---------------------------------- | -------------------------- | -------- | -------- | +| Web组件对接软键盘 | 设备运转正常 | 应用启动成功,点击输入框拉起软键盘 | 应用窗口高度缩小避开软键盘 | Yes | Pass | + +## entry2: + +### SetSKBMode_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ---------------------------------- | -------------------------- | -------- | -------- | +| Web组件对接软键盘 | 设备运转正常 | 应用启动成功,点击输入框拉起软键盘 | 应用窗口高度缩小避开软键盘 | Yes | Pass | + diff --git a/ManageWebPageInteracts/screenshots/ImpNestedScroll.png b/ManageWebPageInteracts/screenshots/ImpNestedScroll.png new file mode 100644 index 0000000000000000000000000000000000000000..bfb841ff5c9ef3f4b33df5f9bf8c2fef6c20dd60 Binary files /dev/null and b/ManageWebPageInteracts/screenshots/ImpNestedScroll.png differ diff --git a/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png b/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png new file mode 100644 index 0000000000000000000000000000000000000000..0bdd2dc4c67bcee1b60eb0f6d98c2ab19c74bcdb Binary files /dev/null and b/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png differ diff --git a/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png b/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png new file mode 100644 index 0000000000000000000000000000000000000000..435149dcebea920a056e829852f1c9906f142aa0 Binary files /dev/null and b/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png differ diff --git a/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png b/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png new file mode 100644 index 0000000000000000000000000000000000000000..a4056bf1dc11cc4b1fc8972ad486b0b770d2334a Binary files /dev/null and b/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png differ diff --git a/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png b/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png new file mode 100644 index 0000000000000000000000000000000000000000..7e7edaa392c118a336f7ecc67550a9071a640000 Binary files /dev/null and b/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png differ diff --git a/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png b/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png new file mode 100644 index 0000000000000000000000000000000000000000..78452f56bd471af2e1b138629e31f3f82156287a Binary files /dev/null and b/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/.gitignore b/ManageWebPageLoadBrowse/AcceleratePageAccess/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/.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/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b0c7bc7d9468973a02c86fae0a80050c9598dcc2 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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.acceleratepageaccess", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..09408da82ddf7aa37250665e2742bc8e2069dc22 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AcceleratePageAccess" + } + ] +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md b/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md new file mode 100644 index 0000000000000000000000000000000000000000..283f29112585c46d279ff5b6b832616162c71833 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md @@ -0,0 +1,253 @@ +# 加速Web页面的访问 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-predictor.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### Entry: + +#### PrepareForPageLoad_one + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,可以通过prepareForPageLoad()来预解析或者预连接将要加载的页面。 + +##### 效果预览 + +| 主页 | loadDate | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 在Web组件的onAppear中对要加载的页面进行预连接。 +1. 点击超链接跳转下一界面。 +1. 点击loadData按钮返回上个界面。 + +### Entry1: + +#### PrepareForPageLoad_two + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,可以通过initializeBrowserEngine()来提前初始化内核,然后在初始化内核后调用 prepareForPageLoad()对即将要加载的页面进行预解析、预连接。 +##### 效果预览 + +| 主页 | loadDate | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. Ability的onCreate中提前初始化Web内核并对首页进行预连接。 + +### Entry2: + +#### Prefetching + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,如果能够预测到Web组件将要加载的页面或者即将要跳转的页面,可以通过prefetchPage()来预加载即将要加载页面。 + +##### 效果预览 + +| 主页 | +| -------------------------------------------------------- | +| | + +使用说明 + +1. 在onPageEnd的时候触发下一个要访问的页面的预加载。 + +#### PrefetchingAPOSTRequest_one + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,通过prefetchResource()预获取将要加载页面中的post请求。在页面加载结束时,可以通过clearPrefetchedResource()清除后续不再使用的预获取资源缓存。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 对要加载页面中的post请求进行预获取。在onPageEnd中,可以清除预获取的post请求缓存。 + +#### PrefetchingAPOSTRequest_two + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,如果能够预测到Web组件将要加载页面或者即将要跳转页面中的post请求。可以通过prefetchResource()预获取即将要加载页面的post请求。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 在onPageEnd中,触发预获取一个要访问页面的post请求。 + +#### PrefetchingAPOSTRequest_three + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,通过initializeBrowserEngine()提前初始化内核,然后在初始化内核后调用prefetchResource()预获取将要加载页面中的post请求。这种方式适合提前预获取首页的post请求。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 在Ability的onCreate中,提前初始化Web内核并预获取首页的post请求。 + +### Entry3: + +#### PrecompForCompCache + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,通过precompileJavaScript()在页面加载前提前生成脚本文件的编译缓存。 + +##### 效果预览 + +| 主页 | 加载页面 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 应用启动时EntryAbility将UIContext存到localstorage,初始化预编译Web组件生成编译缓存。 +2. 点击加载页面按钮,创建businessNode,加载业务用Web组件展示business.html页面,此时会使用之前生成的编译缓存。 + +### Entry4: + +#### InjOffResNoInt + +##### 介绍 + +1. 本示例主要介绍加速Web页面的访问,可以通过injectOfflineResources()在页面加载前提前将图片、样式表或脚本资源注入到应用的内存缓存中。 + +##### 效果预览 + +| 主页 | 加载页面 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 进入Index.ets页面自动触发aboutToAppear方法。 +2. 点击加载页面按钮创建businessNode,加载业务用Web组件,展示business.html页面。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry1/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry2/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---Prefetching.ets +|---|---|---PrefetchingAPOSTRequest_one.ets +|---|---|---PrefetchingAPOSTRequest_three.ets +|---|---|---PrefetchingAPOSTRequest_two.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry3/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---BusinessWebview.ets +|---|---|---DynamicComponent.ets +|---|---|---Index.ets // 首页 +|---|---|---PrecompileConfig.ets +|---|---|---Precompile Webview.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry4/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---BusinessWebview.ets +|---|---|---DynamicComponent.ets +|---|---|---Index.ets // 首页 +|---|---|---Inject Webview.ets +|---|---|---Resource.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 code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..91a9926d9991ebd0faf86984be0a7f95893101df --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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": "entry1", + "srcPath": "./entry1", + "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" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/code-linter.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/hvigorfile.ts b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/obfuscation-rules.txt b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..82e98bec44d83d2df03deb52508045cb06cc8604 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..29feaca7669174be5c2b0e2366529ee94ab7e726 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6bf0e4fed027a57256e805bbbeb305052bb0b4be --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.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. + */ + +import { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + if (this.webviewController.accessBackward()) { + this.webviewController.backward(); + } + }) + Web({ src: resourceToString($r('app.string.web_path_one')), controller: this.webviewController }) + .onAppear(() => { + // 指定第二个参数为true,代表要进行预连接,如果为false该接口只会对网址进行dns预解析 + // 第三个参数为要预连接socket的个数。最多允许6个。 + webview.WebviewController.prepareForPageLoad(resourceToString($r('app.string.web_path_one')), true, 2); + }) + } + } +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65e6e287e05d404b31a376c49615635f654367cf --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + }, + { + "name": "web_path_one", + "value": "https://www.example.com" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/en_US/element/string.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0838a23893a22a87feea786664077715b79cf52e --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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": "AcceleratePageAccess" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/zh_CN/element/string.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5fd56f1eb0b9b271fbe3be4dc307c05d954eee7b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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": "AcceleratePageAccess" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4387b1d1e8e1e4e55c8e53794278b34203de2801 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.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. + */ + +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: '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 clickText = await driver.findComponent(ON.type('link')); + await clickText.click(); + await driver.delayMs(3000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/hvigorfile.ts b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/obfuscation-rules.txt b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c4e8768835e5e869bbd19dfb80d2e323afaa6f2d --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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": "entry1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..3377c9ffaec9f544b5a916055d599c55761194c0 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets @@ -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. + */ +// [Start initialize_kernel_in_onCreate_and_pre_connect_to_homepage] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +export default class Entry1Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + console.log('EntryAbility onCreate'); + webview.WebviewController.initializeWebEngine(); + // 预连接时,需要將'https://www.example.com'替换成真实要访问的网站地址。 + + webview.WebviewController.prepareForPageLoad(this.context.resourceManager.getStringSync($r('app.string.web_path_one')), true, 2); + AppStorage.setOrCreate('abilityWant', want); + console.log('EntryAbility onCreate done'); + } + + // [StartExclude initialize_kernel_in_onCreate_and_pre_connect_to_homepage] + 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'); + } + // [EndExclude initialize_kernel_in_onCreate_and_pre_connect_to_homepage] +} +// [End initialize_kernel_in_onCreate_and_pre_connect_to_homepage] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1a2fe4d9484543336d2e6c7bfce18192eb7278aa --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.ets @@ -0,0 +1,45 @@ +/* + * 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 previously_connect_in_onAppear_to_pages_being_loaded] +import { webview } from '@kit.ArkWeb'; +// [StartExclude previously_connect_in_onAppear_to_pages_being_loaded] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude previously_connect_in_onAppear_to_pages_being_loaded] + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + if (this.webviewController.accessBackward()) { + this.webviewController.backward(); + } + }) + Web({ src: $r('app.string.web_path_one'), controller: this.webviewController }) + .onAppear(() => { + // 指定第二个参数为true,代表要进行预连接,如果为false该接口只会对网址进行dns预解析 + // 第三个参数为要预连接socket的个数。最多允许6个。 + webview.WebviewController.prepareForPageLoad(resourceToString($r('app.string.web_path_one')), true, 2); + }) + } + } +} +//[End previously_connect_in_onAppear_to_pages_being_loaded] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5303c59d21b19cfd2c0a4299ec6ea72fede11eba --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 @@ -0,0 +1,47 @@ +/* + * 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": "entry1", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry1Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry1Ability", + "srcEntry": "./ets/entry1ability/Entry1Ability.ets", + "description": "$string:Entry1Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry1Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..76a37f8e3d89782b8d1c1215279ecf96c008d58e --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry1Ability_desc", + "value": "description" + }, + { + "name": "Entry1Ability_label", + "value": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + }, + { + "name": "web_path_one", + "value": "https://www.example.com" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..92f3212a1bf7d5c1936e398fec3c79bdf642d910 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.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. + */ + +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: 'Entry1Ability' + } + 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('Entry1Ability'); + await driver.delayMs(3000); + + const clickText = await driver.findComponent(ON.type('link')); + await clickText.click(); + await driver.delayMs(5000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a8392c11cf0dbecb4cdc78dc93d456a3a8e6ff41 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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": "entry1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/hvigorfile.ts b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/obfuscation-rules.txt b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..dab8f3ea7260551b9dc6606eb397e396d241e701 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e330ef4623eab184383297cf399532844448f58c --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/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('Prefetching') + .onClick(() => { + router.pushUrl({ url: 'pages/Prefetching' }); + }) + Button('PrefetchingAPOSTRequest_one') + .onClick(() => { + router.pushUrl({ url: 'pages/PrefetchingAPOSTRequest_one' }); + }) + Button('PrefetchingAPOSTRequest_two') + .onClick(() => { + router.pushUrl({ url: 'pages/PrefetchingAPOSTRequest_two' }); + }) + Button('PrefetchingAPOSTRequest_three') + .onClick(() => { + router.pushUrl({ url: 'pages/PrefetchingAPOSTRequest_three' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.ets new file mode 100644 index 0000000000000000000000000000000000000000..57d3b8e6e3b826c4740f5812e69e7138d2f89cd5 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.ets @@ -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. + */ +// [Start on_page_end_triggers_preload_of_next_page] +import { webview } from '@kit.ArkWeb'; +// [StartExclude on_page_end_triggers_preload_of_next_page] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude on_page_end_triggers_preload_of_next_page] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'www.example.com', controller: this.webviewController }) + .onPageEnd(() => { + // 预加载https://www.iana.org/help/example-domains。 + this.webviewController.prefetchPage(resourceToString($r('app.string.domains_path'))); + }) + } + } +} +// [End on_page_end_triggers_preload_of_next_page] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..7440060a2fd78d48fb53e4ed48817f9a21855879 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets @@ -0,0 +1,47 @@ +/* + * 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 prefetch_post_request_on_page_end_clear_cache] +import { webview } from '@kit.ArkWeb'; +// [StartExclude prefetch_post_request_on_page_end_clear_cache] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude prefetch_post_request_on_page_end_clear_cache] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.webviewController}) + .onAppear(() => { + // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + {url:resourceToString($r('app.string.post_path')), + method:'POST', + formData:'a=x&b=y',}, + [{headerKey:'c', + headerValue:'z',},], + 'KeyX', 500); + }) + .onPageEnd(() => { + // 清除后续不再使用的预获取资源缓存。 + webview.WebviewController.clearPrefetchedResource(['KeyX',]); + }) + } + } +} +//[End prefetch_post_request_on_page_end_clear_cache] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5b280f4b561f8638c51c5247704d1e179a6193f --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.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 on_page_end_trigger_prefetch_post_request_access_page] +import { webview } from '@kit.ArkWeb'; +// [StartExclude on_page_end_trigger_prefetch_post_request_access_page] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude on_page_end_trigger_prefetch_post_request_access_page] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.webviewController}) + .onPageEnd(() => { + // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + {url:resourceToString($r('app.string.web_path')) + '/post?e=f&g=h', + method:'POST', + formData:'a=x&b=y',}, + [{headerKey:'c', + headerValue:'z',},], + 'KeyX', 500); + }) + } + } +} +//[End on_page_end_trigger_prefetch_post_request_access_page] diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf09aea7ff25030baf584fd14c09ade89265977c --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets @@ -0,0 +1,44 @@ +/* + * 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 initialize_kernel_in_onCreate_and_pre_fetch_post_request] +import { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.webviewController}) + .onPageEnd(() => { + // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + {url:resourceToString($r('app.string.post_path')), + method:'POST', + formData:'a=x&b=y',}, + [{headerKey:'c', + headerValue:'z',},], + 'KeyX', 500); + }) + } + } +} +// [End initialize_kernel_in_onCreate_and_pre_fetch_post_request] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7c87a975ff65dac27497e22e35d2efa530f8064f --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 @@ -0,0 +1,47 @@ +/* + * 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": "feature", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "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 + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b363550515903b8badcdcbf12d372a6791349190 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry2Ability_desc", + "value": "description" + }, + { + "name": "Entry2Ability_label", + "value": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/" + }, + { + "name": "domains_path", + "value": "https://www.iana.org/help/example-domains" + }, + { + "name": "post_path", + "value": "https://www.example1.com/post?e=f&g=h" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1c4e7fcde829651559470084dc4c22f2f3c88b58 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/Prefetching", + "pages/PrefetchingAPOSTRequest_one", + "pages/PrefetchingAPOSTRequest_two", + "pages/PrefetchingAPOSTRequest_three" + ] +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ad971c822e74f7fa1ac058671ad091bc5bf2497 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,141 @@ +/* + * 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. + }) + + /* + * 打开应用,点击 Prefetching 按钮 + * 通过 prefetchPage 来预加载即将要加载页面 + */ + it('Prefetching', 0, async (done: Function) => { + console.info('uitest: Prefetching 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(3000); + + const button1 = await driver.findComponent(ON.text('Prefetching')); + 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: Prefetching end'); + done(); + }); + + /* + * 点击 PrefetchingAPOSTRequest_one 按钮 + * 预获取将要加载页面中的post请求 + * 在页面加载结束时,清除后续不再使用的预获取资源缓存 + */ + it('PrefetchingAPOSTRequest_one', 0, async (done: Function) => { + console.info('uitest: PrefetchingAPOSTRequest_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PrefetchingAPOSTRequest_one')); + 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: PrefetchingAPOSTRequest_one end'); + done(); + }); + + /* + * 点击 PrefetchingAPOSTRequest_two 按钮 + * 通过 prefetchResource 预获取即将要加载页面的post请求 + */ + it('PrefetchingAPOSTRequest_two', 0, async (done: Function) => { + console.info('uitest: PrefetchingAPOSTRequest_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PrefetchingAPOSTRequest_two')); + 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: PrefetchingAPOSTRequest_two end'); + done(); + }); + + /* + * 点击 PrefetchingAPOSTRequest_three 按钮 + * 在初始化内核后调用 prefetchResource 预获取将要加载页面中的post请求 + */ + it('PrefetchingAPOSTRequest_three', 0, async (done: Function) => { + console.info('uitest: PrefetchingAPOSTRequest_three begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PrefetchingAPOSTRequest_three')); + 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'); + + console.info('uitest: PrefetchingAPOSTRequest_three end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..031b54bde39f1b8ca1884b863026dbc91fd5a75a --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/hvigorfile.ts b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/obfuscation-rules.txt b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..655d244a4ec5c8e387d7ebfb66967132c8c952f6 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..407cf0869b146854e930d446181307ab937540b9 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -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. + */ + +// [Start save_the_uiContext_to_localstorage_in_entry_ability] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +// [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] +import { hilog } from '@kit.PerformanceAnalysisKit'; +// [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + +const localStorage: LocalStorage = new LocalStorage('uiContext'); + +export default class Entry3Ability extends UIAbility { + public storage: LocalStorage = localStorage; + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', this.storage, (err, data) => { + if (err.code) { + return; + } + + this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_the_uiContext_to_localstorage_in_entry_ability] + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } + // [EndExclude save_the_uiContext_to_localstorage_in_entry_ability] +} +// [End save_the_uiContext_to_localstorage_in_entry_ability] diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets new file mode 100644 index 0000000000000000000000000000000000000000..510e5960466050eb2ef8f19cb9f7b22a3addf5b5 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.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. + */ + +// [Start write_code_for_business_components] +import { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + // 此处组件可根据业务需要自行扩展 + Web({ src: data.url, controller: data.controller }) + .cacheMode(CacheMode.Default) +} + +export const businessWebview = wrapBuilder(webBuilder); +// [End write_code_for_business_components] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0fc29ad852969d54cf5a1db9efafdd369dd7c60 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets @@ -0,0 +1,60 @@ +/* + * 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 underlying_code_required_for_dynamic_components] +import { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; + +export interface BuilderData { + url: string; + controller: WebviewController; +} + +const storage = LocalStorage.getShared(); + +export class NodeControllerImpl extends NodeController { + private rootNode: BuilderNode | null = null; + private wrappedBuilder: WrappedBuilder | null = null; + + constructor(wrappedBuilder: WrappedBuilder) { + super(); + this.wrappedBuilder = wrappedBuilder; + } + + makeNode(): FrameNode | null { + if (this.rootNode != null) { + return this.rootNode.getFrameNode(); + } + return null; + } + + initWeb(url: string, controller: WebviewController) { + if(this.rootNode != null) { + return; + } + + const uiContext: UIContext = storage.get('uiContext') as UIContext; + if (!uiContext) { + return; + } + this.rootNode = new BuilderNode(uiContext); + this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); + } +} + +export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { + const baseNode = new NodeControllerImpl(wrappedBuilder); + baseNode.initWeb(data.url, data.controller); + return baseNode; +} +// [End underlying_code_required_for_dynamic_components] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..434a2ccf53015a2a93e547b040e2a60058c0afb8 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets @@ -0,0 +1,57 @@ +/* + * 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 dynamic_webview_component_loading] +import { webview } from '@kit.ArkWeb'; +import { NodeController } from '@kit.ArkUI'; +import { createNode } from "./DynamicComponent"; +import { precompileWebview } from "./PrecompileWebview"; +import { businessWebview } from "./BusinessWebview"; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct Index { + @State precompileNode: NodeController | undefined = undefined; + precompileController: webview.WebviewController = new webview.WebviewController(); + + @State businessNode: NodeController | undefined = undefined; + businessController: webview.WebviewController = new webview.WebviewController(); + + aboutToAppear(): void { + // 初始化用于注入本地资源的Web组件 + this.precompileNode = createNode(precompileWebview, + { url: resourceToString($r('app.string.web_path_one')) + 'empty.html', controller: this.precompileController}); + } + + build() { + Column() { + // 在适当的时机加载业务用Web组件,本例以Button点击触发为例 + Button('加载页面') + .onClick(() => { + this.businessNode = createNode(businessWebview, { + url: resourceToString($r('app.string.web_path_one')) + 'business.html', + controller: this.businessController + }); + }) + // 用于业务的Web组件 + NodeContainer(this.businessNode); + } + } +} +// [End dynamic_webview_component_loading] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets new file mode 100644 index 0000000000000000000000000000000000000000..75d2750e83bb4114e32dd9ca2339ef17b9ee0e0d --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.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 compile_resource_allocation_information] +import { webview } from '@kit.ArkWeb' + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +export interface Config { + url: string, + localPath: string, // 本地资源路径 + options: webview.CacheOptions +} + +export let configs: Config[] = [ + { + url: resourceToString($r('app.string.web_path')), + localPath: 'example.js', + options: { + responseHeaders: [ + { headerKey: 'E-Tag', headerValue: 'aWO42N9P9dG/5xqYQCxsx+vDOoU='}, + { headerKey: 'Last-Modified', headerValue: 'Wed, 21 Mar 2025 10:38:41 GMT'} + ] + } + } +] +// [End compile_resource_allocation_information] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets new file mode 100644 index 0000000000000000000000000000000000000000..6be26765077a847037648081f343b359a30ad7a7 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets @@ -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. + */ + +// [Start read_local_js_resource_from_rawfile_dir_via_file_api] +import { BuilderData } from './DynamicComponent'; +import { Config, configs } from './PrecompileConfig'; + +@Builder +function webBuilder(data: BuilderData) { + Web({ src: data.url, controller: data.controller }) + .onControllerAttached(() => { + precompile(data.controller, configs); + }) + .fileAccess(true) +} + +export const precompileWebview = wrapBuilder(webBuilder); + +export const precompile = async (controller: WebviewController, configs: Array) => { + for (const config of configs) { + let content = await readRawFile(config.localPath); + + try { + controller.precompileJavaScript(config.url, content, config.options) + .then(errCode => { + console.error('precompile successfully! ' + errCode); + }).catch((errCode: number) => { + console.error('precompile failed. ' + errCode); + }); + } catch (err) { + console.error('precompile failed. ' + err.code + ' ' + err.message); + } + } +} + +async function readRawFile(path: string) { + try { + return await getContext().resourceManager.getRawFileContent(path);; + } catch (err) { + return new Uint8Array(0); + } +} +// [End read_local_js_resource_from_rawfile_dir_via_file_api] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5566c38cae3156d6470062ff659b9f0a54160541 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 @@ -0,0 +1,47 @@ +/* + * 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 + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6894c74192e3a04b77939f14374213985e80eedb --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry3Ability_desc", + "value": "description" + }, + { + "name": "Entry3Ability_label", + "value": "AcceleratePageAccess" + }, + { + "name": "web_path", + "value": "https://www.example.com/example.js" + }, + { + "name": "web_path_one", + "value": "https://www.example.com/" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7216209578b1a72626a3341d0f398fcd2b454688 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/Ability.test.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. + */ + +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. + }) + + /* + * 打开应用 + * 通过 precompileJavaScript 在页面加载前提前生成脚本文件的编译缓存 + */ + 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(3000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..edaba8aaabfc3819914b5d624d6d0143e85b5b86 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/List.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/hvigorfile.ts b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/obfuscation-rules.txt b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/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/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ac50b7be8601621317e98fd352affe020e0897c7 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/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": "entry4", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ab5d17a3c7efdffe8b5fa34e9aec4f7ce9237c0 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets @@ -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. + */ + +// [Start save_uiContext_to_localstorage_in_entry_ability] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +// [StartExclude save_uiContext_to_localstorage_in_entry_ability] +import { hilog } from '@kit.PerformanceAnalysisKit'; +// [EndExclude save_uiContext_to_localstorage_in_entry_ability] + +const localStorage: LocalStorage = new LocalStorage('uiContext'); + +export default class Entry4Ability extends UIAbility { + public storage: LocalStorage = localStorage; + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', this.storage, (err, data) => { + if (err.code) { + return; + } + + this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] + // [StartExclude save_uiContext_to_localstorage_in_entry_ability] + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } + // [EndExclude save_uiContext_to_localstorage_in_entry_ability] +} +// [End save_uiContext_to_localstorage_in_entry_ability] diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f37c63bfdff0f3f42dee6da7e069016bbae7dd2 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets @@ -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. + */ +// [Start write_code_for_business_components] +import { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + // 此处组件可根据业务需要自行扩展 + Web({ src: data.url, controller: data.controller }) + .cacheMode(CacheMode.Default) +} + +export const businessWebview = wrapBuilder(webBuilder); +// [End write_code_for_business_components] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0fc29ad852969d54cf5a1db9efafdd369dd7c60 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets @@ -0,0 +1,60 @@ +/* + * 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 underlying_code_required_for_dynamic_components] +import { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; + +export interface BuilderData { + url: string; + controller: WebviewController; +} + +const storage = LocalStorage.getShared(); + +export class NodeControllerImpl extends NodeController { + private rootNode: BuilderNode | null = null; + private wrappedBuilder: WrappedBuilder | null = null; + + constructor(wrappedBuilder: WrappedBuilder) { + super(); + this.wrappedBuilder = wrappedBuilder; + } + + makeNode(): FrameNode | null { + if (this.rootNode != null) { + return this.rootNode.getFrameNode(); + } + return null; + } + + initWeb(url: string, controller: WebviewController) { + if(this.rootNode != null) { + return; + } + + const uiContext: UIContext = storage.get('uiContext') as UIContext; + if (!uiContext) { + return; + } + this.rootNode = new BuilderNode(uiContext); + this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); + } +} + +export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { + const baseNode = new NodeControllerImpl(wrappedBuilder); + baseNode.initWeb(data.url, data.controller); + return baseNode; +} +// [End underlying_code_required_for_dynamic_components] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..42fb5389701472c2a44fbc56eccfc531217e5c4e --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets @@ -0,0 +1,57 @@ +/* + * 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 dynamic_webview_component_loading] +import { webview } from '@kit.ArkWeb'; +import { NodeController } from '@kit.ArkUI'; +import { createNode } from "./DynamicComponent"; +import { injectWebview } from "./InjectWebview"; +import { businessWebview } from "./BusinessWebview"; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct Index { + @State injectNode: NodeController | undefined = undefined; + injectController: webview.WebviewController = new webview.WebviewController(); + + @State businessNode: NodeController | undefined = undefined; + businessController: webview.WebviewController = new webview.WebviewController(); + + aboutToAppear(): void { + // 初始化用于注入本地资源的Web组件, 提供一个空的html页面作为url即可 + this.injectNode = createNode(injectWebview, + { url: resourceToString($r('app.string.web_path_two')), controller: this.injectController}); + } + + build() { + Column() { + // 在适当的时机加载业务用Web组件,本例以Button点击触发为例 + Button("加载页面") + .onClick(() => { + this.businessNode = createNode(businessWebview, { + url: resourceToString($r('app.string.web_path_three')), + controller: this.businessController + }); + }) + // 用于业务的Web组件 + NodeContainer(this.businessNode); + } + } +} +// [End dynamic_webview_component_loading] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ccca1250e3ea1d0b6f0b400555fe142b35979ed --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets @@ -0,0 +1,64 @@ +/* + * 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 local_resources_content_read_from_rawfile_directory_by_file_operation] +import { webview } from '@kit.ArkWeb'; +import { resourceConfigs } from './Resource'; +import { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + Web({ src: data.url, controller: data.controller }) + .onControllerAttached(async () => { + try { + data.controller.injectOfflineResources(await getData ()); + } catch (err) { + console.error('error: ' + err.code + ' ' + err.message); + } + }) + .fileAccess(true) +} + +export const injectWebview = wrapBuilder(webBuilder); + +export async function getData() { + const resourceMapArr: webview.OfflineResourceMap[] = []; + + // 读取配置,从rawfile目录中读取文件内容 + for (let config of resourceConfigs) { + let buf: Uint8Array = new Uint8Array(0); + if (config.localPath) { + buf = await readRawFile(config.localPath); + } + + resourceMapArr.push({ + urlList: config.urlList, + resource: buf, + responseHeaders: config.responseHeaders, + type: config.type, + }) + } + + return resourceMapArr; +} + +export async function readRawFile(url: string) { + try { + return await getContext().resourceManager.getRawFileContent(url); + } catch (err) { + return new Uint8Array(0); + } +} +// [End local_resources_content_read_from_rawfile_directory_by_file_operation] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c7ab57171147e3cd14c9d8b4ab18a3d3aff6ec1 --- /dev/null +++ b/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.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. + */ + +// [Start compile_resource_allocation_information] +import { webview } from '@kit.ArkWeb'; +// [StartExclude compile_resource_allocation_information] +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} +// [EndExclude compile_resource_allocation_information] +export interface ResourceConfig { + urlList: Array, + type: webview.OfflineResourceType, + responseHeaders: Array
, + localPath: string, // 本地资源存放在rawfile目录下的路径 +} + +export const resourceConfigs: ResourceConfig[] = [ + { + localPath: 'example.png', + urlList: [ + resourceToString($r('app.string.web_path')), + resourceToString($r('app.string.web_path')) + 'path1/example.png', + resourceToString($r('app.string.web_path')) + 'path2/example.png', + ], + type: webview.OfflineResourceType.IMAGE, + responseHeaders: [ + { headerKey: 'Cache-Control', headerValue: 'max-age=1000' }, + { headerKey: 'Content-Type', headerValue: 'image/png' }, + ] + }, + { + localPath: 'example.js', + urlList: [ // 仅提供一个url,这个url既作为资源的源,也作为资源的网络请求地址 + resourceToString($r('app.string.web_path_one')), + ], + type: webview.OfflineResourceType.CLASSIC_JS, + responseHeaders: [ + // 以 + + \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/main/resources/zh_CN/element/string.json b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d4c9e1478d869b1ac4894955c2600173e5fa04d3 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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": "CustomizePageResp" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..43afd1c79414996342a92b8e6eb3ea00ae27ffa0 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,106 @@ +/* + * 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. + }) + + /* + * 打开应用,点击 OnInterceptRequest_one 按钮 + * 应用层构造本地资源响应消息发送给Web内核 + * Web内核解析应用层响应信息,根据此响应信息进行页面资源加载 + */ + it('OnInterceptRequest_one',0, async (done: Function) => { + console.info('uitest: OnInterceptRequest_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(3000); + + const button1 = await driver.findComponent(ON.text('OnInterceptRequest_one')); + await button1.click(); + await driver.delayMs(1000); + + const clickText = await driver.findComponent(ON.clickable(true).enabled(true)); + await clickText.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('index1.html'); + + await driver.pressBack(); + console.info('uitest: OnInterceptRequest_one end'); + done(); + }); + + /* + * 点击 OnInterceptRequest_two 按钮 + * Web组件通过拦截页面请求,应用侧代码构建响应资源 + * 在响应头中添加“ResponseDataID”字段,开启生成CodeCache的功能 + */ + it('OnInterceptRequest_two',0, async (done: Function) => { + console.info('uitest: OnInterceptRequest_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('OnInterceptRequest_two')); + await button1.click(); + await driver.delayMs(1000); + + const clickText = await driver.findComponent(ON.clickable(true).enabled(true)); + await clickText.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('index2.html'); + + console.info('uitest: OnInterceptRequest_two end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/List.test.ets b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/hvigor/hvigor-config.json5 b/ManageWebPageLoadBrowse/CustomizePageResp/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/hvigorfile.ts b/ManageWebPageLoadBrowse/CustomizePageResp/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/oh-package.json5 b/ManageWebPageLoadBrowse/CustomizePageResp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/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/ManageWebPageLoadBrowse/CustomizePageResp/ohosTest.md b/ManageWebPageLoadBrowse/CustomizePageResp/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..4231c946ba5e54812a5735db3aec93a85e465c81 --- /dev/null +++ b/ManageWebPageLoadBrowse/CustomizePageResp/ohosTest.md @@ -0,0 +1,11 @@ +#### OnInterceptRequest_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------ | ------------------------------ | -------- | -------- | +| 自定义页面请求响应 | 设备运转正常 | 应用启动成功 | 拦截页面请求自定义页面响应场景 | Yes | Pass | + +#### OnInterceptRequest_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------ | ------------ | ------------------------------------ | -------- | -------- | +| 自定义页面请求响应 | 设备运转正常 | 应用启动成功 | 拦截页面请求,应用侧代码构建响应资源 | Yes | Pass | diff --git a/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_1.png b/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_1.png new file mode 100644 index 0000000000000000000000000000000000000000..5921aacb8fb3bd418ea2ab998e4b3909d96bf104 Binary files /dev/null and b/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_1.png differ diff --git a/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_2.png b/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_2.png new file mode 100644 index 0000000000000000000000000000000000000000..3cccbb3464cb4c53486a27c8f01210550c916f52 Binary files /dev/null and b/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_2.png differ diff --git a/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_two.png b/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_two.png new file mode 100644 index 0000000000000000000000000000000000000000..348f6eac4920aed40cc1e2523a0756f8dee2efc7 Binary files /dev/null and b/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_two.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/.gitignore b/ManageWebPageLoadBrowse/LoadPages/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/.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/ManageWebPageLoadBrowse/LoadPages/AppScope/app.json5 b/ManageWebPageLoadBrowse/LoadPages/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a0839764e9f5191469c5b58f2a8ec6114aa3bdcd --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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.loadpages", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/element/string.json b/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..20d3fed609c211fb436f66442a2576b24d1a59ac --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "LoadPages" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/media/app_icon.png b/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/media/app_icon.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/README.md b/ManageWebPageLoadBrowse/LoadPages/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9b59e60742046073fb91f237485f502c119f680c --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/README.md @@ -0,0 +1,138 @@ +# 使用Web组件加载页面 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-page-loading-with-web-components.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### LoadingWebPages + +#### 介绍 + +1. 本示例主要介绍使用Web组件加载页面,开发者可以在Web组件创建时,指定默认加载的网络页面。在默认页面加载完成后,如果开发者需要变更此Web组件显示的网络页面,可以通过调用loadUrl()接口加载指定的网页。 + +#### 效果预览 + +| 主页 | loadUrl | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击loadUrl按钮加载指定的网页来变更此Web组件显示的网络页面。 + +### LoadingLocalPages + +#### 介绍 + +1. 本示例主要介绍使用Web组件加载页面,将本地页面文件放在应用的rawfile目录下,开发者可以在Web组件创建的时候指定默认加载的本地页面 ,并且加载完成后可通过调用loadUrl()接口变更当前Web组件的页面。 + +#### 效果预览 + +| 主页 | loadUrl | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击loadUrl按钮来变更当前Web组件的页面。 + +### LoadingHTMLRichTextData + +#### 介绍 + +1. 本示例主要介绍使用Web组件加载页面,Web组件可以通过loadData()接口实现加载HTML格式的文本数据。 + +#### 效果预览 + +| 主页 | loadData | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击loadUrl按钮加载HTML格式的文本数据。 + +### LoadLocalPageFileInSandboxPath_one + +#### 介绍 + +1. 本示例主要介绍使用Web组件加载页面,通过构造的单例对象GlobalContext获取沙箱路径,加载沙箱路径下的本地页面文件,需要开启应用中文件系统的访问fileAccess权限。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 通过构造的单例对象GlobalContext获取沙箱路径,加载沙箱路径下的本地页面文件。 + +### LoadLocalPageFileInSandboxPath_two + +#### 介绍 + +1. 本示例主要介绍使用Web组件加载页面,Web组件可以通过data url方式直接加载HTML字符串。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 通过data url方式直接加载HTML字符串。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---GlobalContext.ets +|---|---|---Index.ets // 首页 +|---|---|---LoadingHTMLRichTextData.ets +|---|---|---Loading LocalPages.ets +|---|---|---Loading WebPages.ets +|---|---|---Load LocalPageFileInSandboxPath_one.ets +|---|---|---Load LocalPageFileInSandboxPath_two.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 code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/build-profile.json5 b/ManageWebPageLoadBrowse/LoadPages/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/code-linter.json5 b/ManageWebPageLoadBrowse/LoadPages/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/.gitignore b/ManageWebPageLoadBrowse/LoadPages/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/build-profile.json5 b/ManageWebPageLoadBrowse/LoadPages/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/hvigorfile.ts b/ManageWebPageLoadBrowse/LoadPages/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/obfuscation-rules.txt b/ManageWebPageLoadBrowse/LoadPages/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/oh-package.json5 b/ManageWebPageLoadBrowse/LoadPages/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entryability/EntryAbility.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..82e98bec44d83d2df03deb52508045cb06cc8604 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..29feaca7669174be5c2b0e2366529ee94ab7e726 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/GlobalContext.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/GlobalContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e388d7c0789a2fde9a1dbc86eb58c8c77b8b856 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/GlobalContext.ets @@ -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. + */ + +// [Start after_load_complete_call_to_change_page] +export class GlobalContext { + private constructor() {} + private static instance: GlobalContext; + private _objects = new Map(); + + public static getContext(): GlobalContext { + if (!GlobalContext.instance) { + GlobalContext.instance = new GlobalContext(); + } + return GlobalContext.instance; + } + + getObject(value: string): Object | undefined { + return this._objects.get(value); + } + + setObject(key: string, objectClass: Object): void { + this._objects.set(key, objectClass); + } +} +// [End after_load_complete_call_to_change_page] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8414f37f6e33158c3cb833f41062d18b735051df --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('LoadingWebPages') + .onClick(() => { + router.pushUrl({ url: 'pages/LoadingWebPages' }); + }) + Button('LoadingLocalPages') + .onClick(() => { + router.pushUrl({ url: 'pages/LoadingLocalPages' }); + }) + Button('LoadingHTMLRichTextData') + .onClick(() => { + router.pushUrl({ url: 'pages/LoadingHTMLRichTextData' }); + }) + Button('LoadLocalPageFileInSandboxPath_one') + .onClick(() => { + router.pushUrl({ url: 'pages/LoadLocalPageFileInSandboxPath_one' }); + }) + Button('LoadLocalPageFileInSandboxPath_two') + .onClick(() => { + router.pushUrl({ url: 'pages/LoadLocalPageFileInSandboxPath_two' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_one.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..7265103ddffb308500e88278d43868f1ac9f5271 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_one.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 load_local_page_file_in_sandbox_path] +import { webview } from '@kit.ArkWeb'; +import { GlobalContext } from './GlobalContext'; + +let url = 'file://' + GlobalContext.getContext().getObject('filesDir') + '/index.html'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Text('loading success'); + // 加载沙箱路径文件。 + Web({ src: url, controller: this.controller }); + } + } +} +// [End load_local_page_file_in_sandbox_path] diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_two.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..208359c5f04520d90de51e7eb805f0f0a7a66264 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_two.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 web_components_load_html_strings_by_data_url] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + htmlStr: string = 'data:text/html, Source:
source
'; + + build() { + Column() { + // 组件创建时,加载htmlStr + Web({ src: this.htmlStr, controller: this.controller }); + } + } +} +// [End web_components_load_html_strings_by_data_url] diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingHTMLRichTextData.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingHTMLRichTextData.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc56f8160ac8640379d79cd3752462ccd690cc69 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingHTMLRichTextData.ets @@ -0,0 +1,44 @@ +/* + * 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 devs_load_page_fragments_for_quick_loading] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + try { + // 点击按钮时,通过loadData,加载HTML格式的文本数据 + this.controller.loadData( + 'Source:
source
', + 'text/html', + 'UTF-8' + ); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 组件创建时,加载www.example.com + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} +// [End devs_load_page_fragments_for_quick_loading] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingLocalPages.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingLocalPages.ets new file mode 100644 index 0000000000000000000000000000000000000000..781bbe446f028de2b05bfcac1510cac7dea85ad5 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingLocalPages.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 after_load_complete_call_to_change_page] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadUrl') + .onClick(() => { + try { + // 点击按钮时,通过loadUrl,跳转到local1.html + this.controller.loadUrl($rawfile('local1.html')); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 组件创建时,通过$rawfile加载本地文件local.html + Web({ src: $rawfile('local.html'), controller: this.controller }); + } + } +} +// [End after_load_complete_call_to_change_page] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingWebPages.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingWebPages.ets new file mode 100644 index 0000000000000000000000000000000000000000..e1bb08055573f295a89c60d8119d3fc2df4bd2a2 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingWebPages.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 use_load_interface_to_show_web_changes] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadUrl') + .onClick(() => { + try { + // 点击按钮时,通过loadUrl,跳转到www.example1.com + this.controller.loadUrl('www.example1.com'); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 组件创建时,加载www.example.com + Web({ src: 'www.example.com', controller: this.controller }); + } + } +} +// [End use_load_interface_to_show_web_changes] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/module.json5 b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ee18f9ce4fbbaa1861e1de23ff3e4846c93efc87 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..13ba44d53db0cce9e6b90d39a451fb166108470b --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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": "LoadPages" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/backup_config.json b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..55043dfca0e13cb4390abc45b022b0aa9ec038c9 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,10 @@ +{ + "src": [ + "pages/Index", + "pages/LoadingWebPages", + "pages/LoadingLocalPages", + "pages/LoadingHTMLRichTextData", + "pages/LoadLocalPageFileInSandboxPath_one", + "pages/LoadLocalPageFileInSandboxPath_two" + ] +} diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/en_US/element/string.json b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..13ba44d53db0cce9e6b90d39a451fb166108470b --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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": "LoadPages" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local.html b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local.html new file mode 100644 index 0000000000000000000000000000000000000000..4e7956396344e0db753afb9431de6cfa7b0a1e07 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local.html @@ -0,0 +1,21 @@ + + + + + +

Hello World

+ + diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local1.html b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local1.html new file mode 100644 index 0000000000000000000000000000000000000000..5b3b0b03bbf5da5ac6fc1287737a776b2a9e3d4d --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local1.html @@ -0,0 +1,21 @@ + + + + + +

This is local1 page

+ + diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/zh_CN/element/string.json b/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..becedf26056eeec62877304965a627eece9f3da3 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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": "LoadPages" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/LoadPages/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4843837034de0f1083ef3ff7cb78ca3d120146b0 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,175 @@ +/* + * 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. + }) + + /* + * 打开应用,点击 LoadingWebPages 按钮 + * 在默认页面加载完成后,调用 loadUrl 接口加载指定的网页 + */ + it('LoadingWebPages', 0, async (done: Function) => { + console.info('uitest: LoadingWebPages 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(4000); + + const button1 = await driver.findComponent(ON.text('LoadingWebPages')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('example.com'); + + await driver.pressBack(); + console.info('uitest: LoadingWebPages end'); + done(); + }); + + /* + * 打开应用,点击 LoadingLocalPages 按钮 + * 默认页面加载完成后可通过调用 loadUrl 接口变更当前Web组件的页面 + */ + it('LoadingLocalPages', 0, async (done: Function) => { + console.info('uitest: LoadingLocalPages begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LoadingLocalPages')); + await button1.click(); + await driver.delayMs(1000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + let src: string = await type.getText(); + expect(src).assertContain('local.html'); + + await driver.pressBack(); + console.info('uitest: LoadingLocalPages end'); + done(); + }); + + /* + * 打开应用,点击 LoadingHTMLRichTextData 按钮 + * 通过 loadData 接口实现加载HTML格式的文本数据 + */ + it('LoadingHTMLRichTextData', 0, async (done: Function) => { + console.info('uitest: LoadingHTMLRichTextData begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LoadingHTMLRichTextData')); + await button1.click(); + await driver.delayMs(1000); + + const button = await driver.findComponent(ON.type('Button')); + await button.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: LoadingHTMLRichTextData end'); + done(); + }); + + /* + * 打开应用,点击 LoadLocalPageFileInSandboxPath_one 按钮 + * 加载沙箱路径下的本地页面文件,需要开启应用中文件系统的访问fileAccess权限 + */ + it('LoadLocalPageFileInSandboxPath_one', 0, async (done: Function) => { + console.info('uitest: LoadLocalPageFileInSandboxPath_one begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LoadLocalPageFileInSandboxPath_one')); + await button1.click(); + await driver.delayMs(1000); + + const type1 = await driver.findComponent(ON.type('Text')); + let text1: string = await type1.getText(); + expect(text1).assertContain('loading success'); + + await driver.pressBack(); + console.info('uitest: LoadLocalPageFileInSandboxPath_one end'); + done(); + }); + + /* + * 打开应用,点击 LoadLocalPageFileInSandboxPath_two 按钮 + * 通过data url方式直接加载HTML字符串 + */ + it('LoadLocalPageFileInSandboxPath_two', 0, async (done: Function) => { + console.info('uitest: LoadLocalPageFileInSandboxPath_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LoadLocalPageFileInSandboxPath_two')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('Source:'); + + await driver.pressBack(); + console.info('uitest: LoadLocalPageFileInSandboxPath_two end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/test/List.test.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/entry/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/LoadPages/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/hvigor/hvigor-config.json5 b/ManageWebPageLoadBrowse/LoadPages/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/hvigorfile.ts b/ManageWebPageLoadBrowse/LoadPages/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/oh-package.json5 b/ManageWebPageLoadBrowse/LoadPages/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/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/ManageWebPageLoadBrowse/LoadPages/ohosTest.md b/ManageWebPageLoadBrowse/LoadPages/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..af2960f92e5798733ea4e4ba0974f6c1d3238b11 --- /dev/null +++ b/ManageWebPageLoadBrowse/LoadPages/ohosTest.md @@ -0,0 +1,30 @@ +#### LoadingWebPages + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | ------------ | ----------------------------- | -------------- | -------- | -------- | +| 使用Web组件加载页面 | 设备运转正常 | 应用启动成功,点击loadUrl按钮 | 加载指定的网页 | Yes | Pass | + +#### LoadingLocalPages + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | ------------ | ----------------------------- | --------------------- | -------- | -------- | +| 使用Web组件加载页面 | 设备运转正常 | 应用启动成功,点击loadUrl按钮 | 变更当前Web组件的页面 | Yes | Pass | + +#### LoadingHTMLRichTextData + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | ------------ | ----------------------------- | ---------------------- | -------- | -------- | +| 使用Web组件加载页面 | 设备运转正常 | 应用启动成功,点击loadUrl按钮 | 加载HTML格式的文本数据 | Yes | Pass | + +#### LoadLocalPageFileInSandboxPath_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | ------------ | ------------ | ---------------------------------------- | -------- | -------- | +| 使用Web组件加载页面 | 设备运转正常 | 应用启动成功 | 获取沙箱路径加载沙箱路径下的本地页面文件 | Yes | Pass | + +#### LoadLocalPageFileInSandboxPath_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | ------------ | ------------ | ---------------------------------- | -------- | -------- | +| 使用Web组件加载页面 | 设备运转正常 | 应用启动成功 | 通过data url方式直接加载HTML字符串 | Yes | Pass | + diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_one.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_one.png new file mode 100644 index 0000000000000000000000000000000000000000..a7c815eb6349f7cf7eb93464d57f666fb7d21fc7 Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_one.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_two.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_two.png new file mode 100644 index 0000000000000000000000000000000000000000..03d9599d1612eb550fa3edb973024838fd7f63f9 Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_two.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_1.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_1.png new file mode 100644 index 0000000000000000000000000000000000000000..dfc5745ac65d84f78a68c07b30a69fc42ef6200f Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_1.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_2.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_2.png new file mode 100644 index 0000000000000000000000000000000000000000..89b1161c6af2b78263d8d73d873b003671c4662c Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_2.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_1.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_1.png new file mode 100644 index 0000000000000000000000000000000000000000..385ef0d06d87a17b50786e29cee0465b25a882e3 Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_1.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_2.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_2.png new file mode 100644 index 0000000000000000000000000000000000000000..b7ec203d712bd013a4bccbb66b5a62916a70b147 Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_2.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_1.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_1.png new file mode 100644 index 0000000000000000000000000000000000000000..eb39d90e0f1758ba3640bd6021f031f7d99c885c Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_1.png differ diff --git a/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_2.png b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8794cba878eb7e77ac5fcb6757ba2383fae77e5d Binary files /dev/null and b/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_2.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/.gitignore b/ManageWebPageLoadBrowse/ManagePageRedirectNav/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/.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/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/app.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..829e8ba122dafa9aad9d543ebd9a3a6e1fb0dd10 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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.managepageredirectnav", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/element/string.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f2843105d1f0874209a5c4a51a1d2c67d51e296c --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManagePageRedirectNav" + } + ] +} diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/media/app_icon.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/media/app_icon.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/README.md b/ManageWebPageLoadBrowse/ManagePageRedirectNav/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f8b5cd6550c4b89f300311133bb8db8c65ea62ea --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/README.md @@ -0,0 +1,104 @@ +# 管理页面跳转及浏览记录导航 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-redirection-and-browsing-history-mgmt.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### HistoryNavigati + +#### 介绍 + +1. 本示例主要介绍管理页面跳转及浏览记录导航,如果存在历史记录,accessBackward()接口会返回true。同样可以使用accessForward()接口检查是否存在前进的历史记录。 + +#### 效果预览 + +| 主页 | More information... | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击More information...链接到达下一界面,来生成历史记录。 +1. 点击loadData按钮来触发前端页面的后退操作。 + +### PageRedirection + +#### 介绍 + +1. 本示例主要介绍页面跳转管理和浏览记录导航。当用户点击网页链接需要跳转到应用内其它页面时,可以通过使用Web组件的onLoadIntercept()接口来实现。 + +#### 效果预览 + +| 主页 | 跳转 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 在前端route.html页面点击超链接,可跳转到应用的ProfilePage.ets页面。 + +### CrossApplicationRedirection + +#### 介绍 + +本示例主要介绍页面管理及浏览记录导航功能,Web组件支持通过点击前端的超链接实现跨应用跳转。 + +#### 效果预览 + +| | | +| ------------------------------------------------------------ | ------------------------------------------------------------ | + +使用说明 + +1. 点击超链接导航至其它应用。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---CrossApplication Redirection.ets +|---|---|---HistoryNavigati.ets +|---|---|---Index.ets // 首页 +|---|---|---PageRedirection.ets +|---|---|---ProfilePage.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 code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/build-profile.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/code-linter.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/.gitignore b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/build-profile.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/hvigorfile.ts b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/obfuscation-rules.txt b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/oh-package.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entryability/EntryAbility.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..23a5f218909827e91bf6f66ce3d472c99df7c7c2 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entryability/EntryAbility.ets @@ -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. + */ +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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/CrossApplicationRedirection.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/CrossApplicationRedirection.ets new file mode 100644 index 0000000000000000000000000000000000000000..a449c95a90bfa7742231fc94c65d08cc41e49e20 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/CrossApplicationRedirection.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 { webview } from '@kit.ArkWeb'; +import { call } from '@kit.TelephonyKit'; +// [Start click_link_call_html_to_reach_phone_dialing_screen] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $rawfile('call.html'), controller: this.webviewController }) + .onLoadIntercept((event) => { + if (event) { + let url: string = event.data.getRequestUrl(); + // 判断链接是否为拨号链接 + if (url.indexOf('tel://') === 0) { + // 跳转拨号界面 + call.makeCall(url.substring(6), (err) => { + if (!err) { + console.info('make call succeeded.'); + } else { + console.info('make call fail, err is:' + JSON.stringify(err)); + } + }); + return true; + } + } + return false; + }) + } + } +} +//[End click_link_call_html_to_reach_phone_dialing_screen] diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/HistoryNavigati.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/HistoryNavigati.ets new file mode 100644 index 0000000000000000000000000000000000000000..cf577c6cbf0c81e5995f9f18c2560fc73a455733 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/HistoryNavigati.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. + */ + +import { webview } from '@kit.ArkWeb'; + +// [Start button_click_trigger_back] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + if (this.webviewController.accessBackward()) { + this.webviewController.backward(); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.webviewController }); + } + } +} +// [End button_click_trigger_back] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4914a5f5df429036d7259d9a47334c52f77beb4a --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/Index.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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('HistoryNavigati') + .onClick(() => { + router.pushUrl({ url: 'pages/HistoryNavigati' }); + }) + Button('PageRedirection') + .onClick(() => { + router.pushUrl({ url: 'pages/PageRedirection' }); + }) + Button('CrossApplicationRedirection') + .onClick(() => { + router.pushUrl({ url: 'pages/CrossApplicationRedirection' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/PageRedirection.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/PageRedirection.ets new file mode 100644 index 0000000000000000000000000000000000000000..d57537f43fd67eb4d8e08905dfbdfd87dcf66fec --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/PageRedirection.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. + */ + +import { webview } from '@kit.ArkWeb'; +import { router } from '@kit.ArkUI'; + +// [Start index_load_route_link_to_profile] +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + // 资源文件route.html存放路径src/main/resources/rawfile + Web({ src: $rawfile('route.html'), controller: this.webviewController }) + .onLoadIntercept((event) => { + if (event) { + let url: string = event.data.getRequestUrl(); + if (url.indexOf('native://') === 0) { + // 跳转其他界面 + router.pushUrl({ url: url.substring(9) }); + return true; + } + } + return false; + }) + } + } +} +// [End index_load_route_link_to_profile] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/ProfilePage.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/ProfilePage.ets new file mode 100644 index 0000000000000000000000000000000000000000..fa930b9d9c7dfc80242309d1e9da19825de225b8 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/ProfilePage.ets @@ -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 navigate_to_profile_page] +@Entry +@Component +struct ProfilePage { + @State message: string = 'Hello World'; + + build() { + Column() { + Text(this.message) + .fontSize(20) + } + } +} +// [End navigate_to_profile_page] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/module.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..51119df58d8798ee0c2863b48d2a3ce7e940555b --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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": "ManagePageRedirectNav" + }, + { + "name": "web_path", + "value": "https://www.example.com/cn/" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/backup_config.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..52f59acd8b0887f9a2cd26f9588d76ca542cb6d5 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/HistoryNavigati", + "pages/PageRedirection", + "pages/CrossApplicationRedirection", + "pages/ProfilePage" + ] +} diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/en_US/element/string.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c25ce9fcda427231c8f659e42517bef4b4325c41 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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": "ManagePageRedirectNav" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/call.html b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/call.html new file mode 100644 index 0000000000000000000000000000000000000000..ea7fea2546ac643d56202049eedb0da4cf3345ab --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/call.html @@ -0,0 +1,24 @@ +/* +* 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. +*/ + + + + + + + + diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/route.html b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/route.html new file mode 100644 index 0000000000000000000000000000000000000000..ecc87a41688d026c9cda4f9294ea208679a7c728 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/route.html @@ -0,0 +1,24 @@ +/* +* 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. +*/ + + + + + + + + diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/zh_CN/element/string.json b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..166ab4c2891df93540a9f2407b2436874fd85e19 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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": "ManagePageRedirectNav" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e979df586c8784a60472e053f76dbced15a916c --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,137 @@ +/* + * 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. + }) + + /* + * 打开应用,点击 HistoryNavigati 按钮 + * 点击 loadData 按钮来触发前端页面的后退操作 + */ + it('HistoryNavigati',0, async (done: Function) => { + console.info('uitest: HistoryNavigati 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(4000); + + const button1 = await driver.findComponent(ON.text('HistoryNavigati')); + await button1.click(); + await driver.delayMs(3000); + + const clickText = await driver.findComponent(ON.type('link')); + await clickText.click(); + await driver.delayMs(3000); + + const button2 = await driver.findComponent(ON.type('Button')); + await button2.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: HistoryNavigati end'); + done(); + }); + + /* + * 点击 PageRedirection 按钮 + * 点击网页中的链接跳转到应用内其他页面 + */ + it('PageRedirection',0, async (done: Function) => { + console.info('uitest: PageRedirection begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('PageRedirection')); + await button1.click(); + await driver.delayMs(3000); + + const clickText = await driver.findComponent(ON.clickable(true).enabled(true)); + await clickText.click(); + await driver.delayMs(1000); + + const text = await driver.findComponent(ON.text('Hello World')); + let type: string = await text.getType(); + expect(type).assertEqual('Text'); + await driver.delayMs(1000); + + await driver.pressBack(); + await driver.delayMs(1000); + await driver.pressBack(); + console.info('uitest: PageRedirection end'); + done(); + }); + + /* + * 点击 CrossApplicationRedirection 按钮 + * 击前端页面超链接跳转到其他应用 + */ + it('CrossApplicationRedirection',0, async (done: Function) => { + console.info('uitest: CrossApplicationRedirection begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('CrossApplicationRedirection')); + await button1.click(); + await driver.delayMs(3000); + + const clickText = await driver.findComponent(ON.clickable(true).enabled(true)); + await clickText.click(); + await driver.delayMs(1000); + + const type = await driver.findComponent(ON.type('Web')); + expect(type).assertEqual(null); + + await driver.pressBack(); + console.info('uitest: CrossApplicationRedirection end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/List.test.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigor/hvigor-config.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigorfile.ts b/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/oh-package.json5 b/ManageWebPageLoadBrowse/ManagePageRedirectNav/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/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/ManageWebPageLoadBrowse/ManagePageRedirectNav/ohosTest.md b/ManageWebPageLoadBrowse/ManagePageRedirectNav/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..2715364d3358506aeeaec98c1746d511a2fa447d --- /dev/null +++ b/ManageWebPageLoadBrowse/ManagePageRedirectNav/ohosTest.md @@ -0,0 +1,18 @@ +#### HistoryNavigati + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------- | ------------------------------------------------------------ | -------------------------------------------------------- | ------------ | -------- | -------- | +| 管理页面跳转及浏览记录导航 | 设备运行正常,点击More information...链接到达下一界面,来生成历史记录 | 应用启动成功,点击loadData按钮来触发前端页面的后退操作。 | 回到初始页面 | Yes | Pass | + +#### PageRedirection + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------- | ------------ | -------------------------------------------- | ------------------------------- | -------- | -------- | +| 管理页面跳转及浏览记录导航 | 设备运行正常 | 应用启动成功,在前端route.html页面点击超链接 | 跳转到应用的ProfilePage.ets页面 | Yes | Pass | + +#### CrossApplicationRedirection + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ------------ | ---------------------------- | -------- | -------- | -------- | +| 管理页面跳转及浏览记录 | 设备运行正常 | 应用启动成功,点击超链接跳转 | 跳转成功 | Yes | Pass | + diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_1.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_1.png new file mode 100644 index 0000000000000000000000000000000000000000..4c3276769353a7d3da5af26b6d6961353df34fc5 Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_1.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_2.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_2.png new file mode 100644 index 0000000000000000000000000000000000000000..fc4e7fd04c1e2d0cb4a42462515928bbb1f5104b Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_2.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_1.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_1.png new file mode 100644 index 0000000000000000000000000000000000000000..2de3e6fa56de1cbf0b0813ee2209922d4c04d900 Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_1.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_2.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_2.png new file mode 100644 index 0000000000000000000000000000000000000000..5f6bd0efb6f23713a1b5bad0b17f57f7917ecd52 Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_2.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_1.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_1.png new file mode 100644 index 0000000000000000000000000000000000000000..4cf9dd40a3961a799edbca39b9ffc888f4f3c8ac Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_1.png differ diff --git a/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_2.png b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_2.png new file mode 100644 index 0000000000000000000000000000000000000000..66705fe72f9b1a329413c5ef85d31a64d983cafe Binary files /dev/null and b/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_2.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/.gitignore b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/.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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/app.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e5c664911c57e8483759f0ead8b22ff2e2af1005 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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.netreqinterceptcachewinops", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/element/string.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ac0ab70b4d42157f3ba34fcf9e9a4608fcb1a4c0 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NetReqInterceptCacheWinOps" + } + ] +} diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/media/app_icon.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/media/app_icon.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/README.md b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/README.md new file mode 100644 index 0000000000000000000000000000000000000000..fe0d75e5db78c0071605b42f4c8409e959575473 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/README.md @@ -0,0 +1,172 @@ + + + + + + +## entry: + +### 拦截Web组件发起的网络请求 + +#### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-scheme-handler.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### InterceptNetRequest + +##### 介绍 + +1. 本示例主要实现拦截Web组件发起的网络请求,为Web组件设置网络拦截器, 设置自定义scheme需要遵循的规则,获取被拦截请求的请求信息并为被拦截的请求提供自定义的响应体。 + +##### 效果预览 + +| 主页 | 本地MP4文件 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 通过网络拦截接口对Web组件发出的请求进行拦截,并可以为被拦截的请求提供自定义的响应头以及响应体。 +1. 点击link链接请求视频资源,读取本地mp4文件。 + +##### 工程目录 + +``` +entry/src/main/ +|---cpp // cpp文件夹 +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.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) + +## entry2: + +### Web组件前进后退缓存 + +#### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-set-back-forward-cache.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### SetBackForwardCache + +##### 介绍 + +1. 本示例主要设置Web组件前进后退缓存,Web组件为开发者提供了启用和配置前进后退缓存(以下简称BFCache)的功能。启用此功能后,能够显著提升用户返回至先前浏览网页的速度,开发者需要在调用initializeWebEngine()初始化ArkWeb内核之前调用enableBackForwardCache()来开启BFCache,启用BFCache后仅能存储一个页面,Web组件默认进入BFCache的页面可保持存活状态600秒。开发者可通过调用setBackForwardCacheOptions()设置每个Web实例的前进后退缓存策略,使BFCache能够容纳更多页面,从而在用户连续进行前进后退操作时,提供更快的加载速度。同时,开发者还能修改每个页面在缓存中的停留时间,延长页面在BFCache中的驻留期限,进而优化用户的浏览体验。 + +##### 效果预览 + +| 主页 | 超链接 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击Add options按钮设置Web组件可以缓存的数量上限为10,每个页面在缓存中停留300s。 +2. 点击Backward按钮会触发WebviewController的backward方法,使Web视图后退到上一个浏览页面(如果存在上一页面且在后退缓存范围内),实现类似以于浏览器后退按钮的功能。 +3. 点击Forward按钮调用WebviewController的forward方法,使Web视图前进到下一个浏览页面(如果存在下一页且在前进缓存范围内),与Backward按钮相对应。 + +##### 工程目录 + +``` +entry2/src/main/ +|---ets +|---|---entry2ability +|---|---|---Entry2Ability.ets +|---|---pages +|---|---|---Index.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) + +## entry3: + +### Web组件在不同的窗口间迁移 + +#### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-component-migrate.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### MigrateWebCompWin + +##### 介绍 + +1. 本示例主要介绍Web组件在不同的窗口间迁移,Web组件在不同窗口间迁移是基于自定义节点能力实现的。通过BuilderNode,开发者可创建Web组件的离线节点,并结合自定义占位节点控制Web节点的挂载与移除。当从一个窗口上移除Web节点并挂载到另一个窗口中,即完成Web组件在窗口间的迁移。 + +##### 效果预览 + +| 主页 | 挂载 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击 Attach Webview 按钮,挂载 Web 视图,刷新NodeContainer使 Web 视图显示在页面上。 +1. 点击 Detach Webview 按钮,卸载 Web 视图,刷新NodeContainer使 Web 视图将从页面上移除。 + +##### 工程目录 + +``` +entry3/src/main/ +|---ets +|---|---entry3ability +|---|---|---Entry3Ability.ets +|---|---pages +|---|---|---common.ets // 提供动态挂载Web组件能力 +|---|---|---Index.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 code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/build-profile.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..638ae10f4bf8fc8c16156b4fdb6d62535fb58b28 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/build-profile.json5 @@ -0,0 +1,75 @@ +/* + * 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" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/code-linter.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/.gitignore b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/build-profile.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f24addba76d1c74999c890245fdc45a1c681db97 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/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": { + "abiFilters": ["arm64-v8a", "x86_64"], + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/hvigorfile.ts b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/obfuscation-rules.txt b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/oh-package.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/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": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/CMakeLists.txt b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1686eb5df713cd6fd4c5da0dd7aeeb5d580861a9 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(schemehandler) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_INFO_FILE) + include(${PACKAGE_INFO_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED rawfile_request.cpp hello.cpp) +target_link_libraries(entry PUBLIC librawfile.z.so libace_napi.z.so libohweb.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ece7e82f1eeb0ab691c41323648fe0d9a630881 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp @@ -0,0 +1,165 @@ +/* + * 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_intercept_web_module_request_example] +#include "hilog/log.h" +#include "napi/native_api.h" +#include "rawfile_request.h" +#include "rawfile/raw_file_manager.h" +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + +// [Start set_intercept_web_module_request] +ArkWeb_SchemeHandler *g_schemeHandler; +// [StartExclude set_intercept_web_module_request] +ArkWeb_SchemeHandler *g_schemeHandlerForSW; +NativeResourceManager *g_resourceManager; + +// 注册三方协议的配置,需要在Web内核初始化之前调用,否则会注册失败。 +static napi_value RegisterCustomSchemes(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "register custom schemes"); + // [Start register_set_custom_schemes] + OH_ArkWeb_RegisterCustomSchemes("custom", ARKWEB_SCHEME_OPTION_STANDARD | ARKWEB_SCHEME_OPTION_CORS_ENABLED); + OH_ArkWeb_RegisterCustomSchemes("custom-local", ARKWEB_SCHEME_OPTION_LOCAL); + OH_ArkWeb_RegisterCustomSchemes( + "custom-csp-bypassing", ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD); + OH_ArkWeb_RegisterCustomSchemes("custom-isolated", ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED); + // [End register_set_custom_schemes] + return nullptr; +} + +// 请求开始的回调,在该函数中我们创建一个RawfileRequest来实现对Web内核请求的拦截。 +void OnURLRequestStart(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +// 请求结束的回调,在该函数中我们需要标记RawfileRequest已经结束了,内部不应该再使用ResourceHandler。 +void OnURLRequestStop(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +void OnURLRequestStartForSW(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +void OnURLRequestStopForSW(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +// 设置SchemeHandler。 +static napi_value SetSchemeHandler(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "set scheme handler"); + // [EndExclude set_intercept_web_module_request] + // [Start set_intercept_web_module_request_custom] + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandler); + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandlerForSW); + + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandler, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandler, OnURLRequestStop); + + // [StartExclude set_intercept_web_module_request_custom] + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandlerForSW, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandlerForSW, OnURLRequestStop); + // [EndExclude set_intercept_web_module_request_custom] + + OH_ArkWeb_SetSchemeHandler("custom", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-csp-bypassing", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-isolated", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-local", "scheme-handler", g_schemeHandler); + // [End set_intercept_web_module_request_custom] + OH_ArkWeb_SetSchemeHandler("https", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("http", "scheme-handler", g_schemeHandler); + // [End set_intercept_web_module_request] + + OH_ArkWebServiceWorker_SetSchemeHandler("https", g_schemeHandlerForSW); + return nullptr; +} + +static napi_value InitResourceManager(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + g_resourceManager = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"setSchemeHandler", nullptr, SetSchemeHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"initResourceManager", nullptr, InitResourceManager, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"registerCustomSchemes", nullptr, RegisterCustomSchemes, 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 set_intercept_web_module_request_example] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/napi_init.cpp b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c11c8b57c075b5322df845f7fdc371f8b49caa0 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3ce2921a733d274ed070f46475e2d5edac50ece --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp @@ -0,0 +1,289 @@ +/* + * 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 intercepted_request_processing_cpp] +#include "rawfile_request.h" +#include "threads.h" + +#include "hilog/log.h" +#include "rawfile/raw_file.h" +#include "rawfile/raw_file_manager.h" + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + +namespace { + +uint8_t g_buffer[1024]; +cnd_t g_httpBodyCnd; +mtx_t g_httpBodyMtx; +const int HTTP_OK = 200; +const int HTTP_NOT_FOUND = 404; +const int BUFFER_SIZE = 1000; + +// HttpBodyStream的读回调。 +void ReadCallback(const ArkWeb_HttpBodyStream *httpBodyStream, uint8_t* buffer, int bytesRead) +{ + OH_LOG_INFO(LOG_APP, "read http body back."); + bool isEof = OH_ArkWebHttpBodyStream_IsEof(httpBodyStream); + if (!isEof && bytesRead != 0) { + memset(buffer, 0, BUFFER_SIZE); + OH_ArkWebHttpBodyStream_Read(httpBodyStream, buffer, BUFFER_SIZE); + } else { + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebHttpBodyStream_GetUserData(httpBodyStream); + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + cnd_signal(&g_httpBodyCnd); + } + } +} + +int ReadHttpBodyOnWorkerThread(void* userData) +{ + memset(g_buffer, 0, BUFFER_SIZE); + ArkWeb_HttpBodyStream *httpBodyStream = (ArkWeb_HttpBodyStream *)userData; + OH_ArkWebHttpBodyStream_Read(httpBodyStream, g_buffer, BUFFER_SIZE); + int initResult = cnd_init(&g_httpBodyCnd); + if (initResult == 0) { + OH_LOG_INFO(LOG_APP, "cnd_init success."); + } else { + OH_LOG_INFO(LOG_APP, "cnd_init fail."); + } + int mtxResult = mtx_init(&g_httpBodyMtx, mtx_plain); + if (mtxResult == 0) { + OH_LOG_INFO(LOG_APP, "mtx_init success."); + } else { + OH_LOG_INFO(LOG_APP, "mtx_init fail."); + } + int waitResult = cnd_wait(&g_httpBodyCnd, &g_httpBodyMtx); + if (waitResult == 0) { + OH_LOG_INFO(LOG_APP, "cnd_wait success."); + } else { + OH_LOG_INFO(LOG_APP, "cnd_wait fail."); + } + return 0; +} + +int ReadRawfileOnWorkerThread(void* userData) +{ + RawfileRequest* rawfileRequest = (RawfileRequest*)userData; + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + } + return 0; +} + +// ArkWeb_HttpBodyStream的初始化回调。 +void InitCallback(const ArkWeb_HttpBodyStream *httpBodyStream, ArkWeb_NetError result) +{ + OH_LOG_INFO(LOG_APP, "init http body stream done %{public}d.", result); + bool isChunked = OH_ArkWebHttpBodyStream_IsChunked(httpBodyStream); + OH_LOG_INFO(LOG_APP, "http body stream is chunked %{public}d.", isChunked); + thrd_t th; + if (thrd_create(&th, ReadHttpBodyOnWorkerThread, (void *)httpBodyStream) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } +} + +const int BLOCK_SIZE = 1024 * 8; +const int MAXWHILE = 100; + +} // namespace + +RawfileRequest::RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager) + : resourceRequest_(resourceRequest), + resourceHandler_(resourceHandler), + resourceManager_(resourceManager) {} + +RawfileRequest::~RawfileRequest() {} + +void RawfileRequest::Start() +{ + OH_LOG_INFO(LOG_APP, "start a rawfile request."); + // [Start get_intercepted_request_info] + char* url; + OH_ArkWebResourceRequest_GetUrl(resourceRequest_, &url); + std::string urlStr(url); + std::size_t position = urlStr.rfind('/'); + if (position != std::string::npos) { + rawfilePath_ = urlStr.substr(position + 1); + } + OH_ArkWeb_ReleaseString(url); + // [End get_intercepted_request_info] + + // [Start set_intercepted_request_response] + // [StartExclude set_intercepted_request_response] + OH_ArkWeb_CreateResponse(&response_); + // [EndExclude set_intercepted_request_response] + OH_ArkWebResourceRequest_GetHttpBodyStream(resourceRequest(), &stream_); + if (stream_) { + OH_LOG_ERROR(LOG_APP, "have http body stream"); + // [Start get_put_post_request_data] + OH_ArkWebHttpBodyStream_SetUserData(stream_, this); + OH_ArkWebHttpBodyStream_SetReadCallback(stream_, ReadCallback); + OH_ArkWebHttpBodyStream_Init(stream_, InitCallback); + // [End get_put_post_request_data] + } else { + thrd_t th; + if (thrd_create(&th, ReadRawfileOnWorkerThread, static_cast(this)) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } + } +} + +// 在worker线程中读取rawfile,并通过ResourceHandler返回给Web内核。 +void RawfileRequest::ReadRawfileDataOnWorkerThread() +{ + OH_LOG_INFO(LOG_APP, "read rawfile in worker thread."); + const struct UrlInfo { + std::string resource; + std::string mimeType; + } urlInfos[] = { + {"test.html", "text/html"}, + {"video.html", "text/html"}, + {"isolated.html", "text/html"}, + {"csp_bypassing.html", "text/html"}, + {"post_data.html", "text/html"}, + {"chunked_post_stream.html", "text/html"}, + {"local.html", "text/html"}, + {"service_worker.html", "text/html"}, + {"csp_script.js", "text/javascript"}, + {"sw.js", "text/javascript"}, + {"isolated_script.js", "text/javascript"}, + {"local_script.js", "text/javascript"}, + {"test.mp4", "video/mp4"}, + {"xhr", "application/json"} + }; + + if (!resourceManager()) { + OH_LOG_ERROR(LOG_APP, "read rawfile error, resource manager is nullptr."); + return; + } + + RawFile *rawfile = OH_ResourceManager_OpenRawFile(resourceManager(), RawfilePath().c_str()); + // [StartExclude set_intercepted_request_response] + if (!rawfile) { + OH_ArkWebResponse_SetStatus(response(), HTTP_NOT_FOUND); + } else { + OH_ArkWebResponse_SetStatus(response(), HTTP_OK); + } + // [EndExclude set_intercepted_request_response] + + for (auto &urlInfo : urlInfos) { + if (urlInfo.resource == RawfilePath()) { + OH_ArkWebResponse_SetMimeType(response(), urlInfo.mimeType.c_str()); + break; + } + } + // [StartExclude set_intercepted_request_response] + OH_ArkWebResponse_SetCharset(response(), "UTF-8"); + // [EndExclude set_intercepted_request_response] + + long len = OH_ResourceManager_GetRawFileSize(rawfile); + // [StartExclude set_intercepted_request_response] + OH_ArkWebResponse_SetHeaderByName(response(), "content-length", std::to_string(len).c_str(), false); + // EndExclude set_intercepted_request_response] + DidReceiveResponse(); + + long consumed = 0; + uint8_t buffer[BLOCK_SIZE]; + int i = 0; + while (++i < MAXWHILE) { + int ret = OH_ResourceManager_ReadRawFile(rawfile, buffer, BLOCK_SIZE); + if (ret > 0) { + OH_LOG_INFO(LOG_APP, "read rawfile %{public}d bytes.", ret); + } else if (ret == 0) { + OH_LOG_INFO(LOG_APP, "read rawfile Reached end of file, %{public}d bytes read.", ret); + break; + } else { + OH_LOG_ERROR(LOG_APP, "read rawfile Error, %{public}d bytes read.", ret); + break; + } + consumed += ret; + OH_ResourceManager_SeekRawFile(rawfile, consumed, 0); + DidReceiveData(buffer, ret); + memset(buffer, 0, BLOCK_SIZE); + } + + OH_ResourceManager_CloseRawFile(rawfile); + DidFinish(); +} + +void RawfileRequest::Stop() +{ + OH_LOG_INFO(LOG_APP, "stop the rawfile request."); + std::lock_guard guard(mutex_); + stopped_ = true; + if (response_) { + OH_ArkWeb_DestroyResponse(response_); + } + OH_ArkWebResourceRequest_Destroy(resourceRequest_); + OH_ArkWebResourceHandler_Destroy(resourceHandler_); +} + +void RawfileRequest::DidReceiveResponse() +{ + OH_LOG_INFO(LOG_APP, "did receive response."); + std::lock_guard guard(mutex_); + if (!stopped_) { + // [StartExclude set_intercepted_request_response] + OH_ArkWebResourceHandler_DidReceiveResponse(resourceHandler_, response_); + // [EndExclude set_intercepted_request_response] + } +} + +void RawfileRequest::DidReceiveData(const uint8_t *buffer, int64_t bufLen) +{ + OH_LOG_INFO(LOG_APP, "did receive data."); + std::lock_guard guard(mutex_); + if (!stopped_) { + // [StartExclude set_intercepted_request_response] + OH_ArkWebResourceHandler_DidReceiveData(resourceHandler_, buffer, bufLen); + // [EndExclude set_intercepted_request_response] + } +} + +void RawfileRequest::DidFinish() +{ + OH_LOG_INFO(LOG_APP, "did finish."); + std::lock_guard guard(mutex_); + if (!stopped_) { + // [StartExclude set_intercepted_request_response] + OH_ArkWebResourceHandler_DidFinish(resourceHandler_); + // [EndExclude set_intercepted_request_response] + // [End set_intercepted_request_response] + } +} + +void RawfileRequest::DidFailWithError(ArkWeb_NetError errorCode) +{ + OH_LOG_INFO(LOG_APP, "did finish with error %{public}d.", errorCode); + if (!stopped_) { + OH_ArkWebResourceHandler_DidFailWithError(resourceHandler_, errorCode); + } +} +// [End intercepted_request_processing_cpp] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h new file mode 100644 index 0000000000000000000000000000000000000000..09f6814761da59b2a5d3becf46da90aa2242fb10 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h @@ -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. + */ + +// [Start rawfile_request_head] +#ifndef RAWFILE_REQUEST_H +#define RAWFILE_REQUEST_H + +#include +#include + +#include +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + +class RawfileRequest { +public: + RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager); + ~RawfileRequest(); + + void Start(); + void Stop(); + void ReadRawfileDataOnWorkerThread(); + + const ArkWeb_ResourceHandler *resourceHandler() { return resourceHandler_; } + const ArkWeb_ResourceRequest *resourceRequest() { return resourceRequest_; } + const NativeResourceManager *resourceManager() { return resourceManager_; } + ArkWeb_Response *response() { return response_; } + ArkWeb_HttpBodyStream *stream() { return stream_; } + const std::string RawfilePath() { return rawfilePath_; } + + void DidReceiveResponse(); + void DidReceiveData(const uint8_t *buffer, int64_t bufLen); + void DidFinish(); + void DidFailWithError(ArkWeb_NetError errorCode); + +private: + const ArkWeb_ResourceRequest *resourceRequest_{nullptr}; + const ArkWeb_ResourceHandler *resourceHandler_{nullptr}; + const NativeResourceManager *resourceManager_{nullptr}; + ArkWeb_Response *response_; + bool stopped_{false}; + std::string rawfilePath_; + ArkWeb_HttpBodyStream *stream_{nullptr}; + std::mutex mutex_; +}; + +#endif // RAWFILE_REQUEST_H +// [End rawfile_request_head] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..97cceb187e4be3d5dd3eabe9644ec47805207ac7 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts @@ -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. + */ + +import { resourceManager } from "@kit.LocalizationKit"; + +// [Start export_register_set_init_schemes] +export const registerCustomSchemes: () => void; +export const setSchemeHandler: () => void; +export const initResourceManager: (resmgr: resourceManager.ResourceManager) => void; +// [End export_register_set_init_schemes] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/oh-package.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/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": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ddc53ccb115af8a04b0e6818d575dcfdf1f6769 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,61 @@ +/* + * 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 register_init_scheme_example] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; + +// [Start register_init_scheme] +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 注册三方协议的配置。 + testNapi.registerCustomSchemes(); + // 初始化Web组件内核,该操作会初始化Browser进程以及创建BrowserContext。 + webview.WebviewController.initializeWebEngine(); + // 设置SchemeHandler。 + testNapi.setSchemeHandler(); + } + + // [StartExclude register_init_scheme] + onDestroy(): void { + + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } + + onWindowStageDestroy(): void { + + } + + onForeground(): void { + + } + + onBackground(): void { + + } + // [EndExclude register_init_scheme] +}; +// [End register_init_scheme] +// [End register_init_scheme_example] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5420d2ebfb72569a014a35e174aa9edc7248582b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.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 set_test_html] +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; +import { resourceManager } from '@kit.LocalizationKit'; + +@Entry +@Component +struct Index { + mycontroller: webview.WebviewController = new webview.WebviewController('scheme-handler'); + + build() { + Row() { + Column() { + Button('goback').onClick( event => { + this.mycontroller.backward(); + }) + + Web({ src: $rawfile('test.html'), controller: this.mycontroller}) + .javaScriptAccess(true) + .width('100%') + .height('100%') + .databaseAccess(true) + .fileAccess(false) + .domStorageAccess(true) + .cacheMode(CacheMode.Default) + .onPageBegin( event => { + testNapi.initResourceManager(getContext().resourceManager); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End set_test_html] \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/module.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2889111cbccda2943046e3a1421d6576262e402e --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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": "NetReqInterceptCacheWinOps" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/backup_config.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/en_US/element/string.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2889111cbccda2943046e3a1421d6576262e402e --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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": "NetReqInterceptCacheWinOps" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/chunked_post_stream.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/chunked_post_stream.html new file mode 100644 index 0000000000000000000000000000000000000000..645cd7833b21a64e904b8747e2824e7f9ef6dcb7 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/chunked_post_stream.html @@ -0,0 +1,46 @@ + + + + + + + + +
test post chunked http body.
+ + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_bypassing.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_bypassing.html new file mode 100644 index 0000000000000000000000000000000000000000..c80c78270a1b8ad62a0b46b5085789b1d4c3673f --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_bypassing.html @@ -0,0 +1,26 @@ + + + + + + + + +

scheme: custom-csp-bypassing

+

options: ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD

+ + + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js new file mode 100644 index 0000000000000000000000000000000000000000..8621810e79f5f987fbc16a20cd72200d33fe140a --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js @@ -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. +*/ + +// [Start csp_rules_java_script] +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'csp_script.js bypass the csp rules'; +body.appendChild(element); +// [End csp_rules_java_script] diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated.html new file mode 100644 index 0000000000000000000000000000000000000000..bc04b313506d81f61fb720c4df39f99f9138d500 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated.html @@ -0,0 +1,26 @@ + + + + + + + +

scheme: custom-isolated

+

options: ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED

+
isolated_script.js 被拦截
+ + + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js new file mode 100644 index 0000000000000000000000000000000000000000..5ad02d6e0384ff6ab826ab4d25028c54e5afcd74 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js @@ -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 isolated_script_java_script] +const element = document.getElementById('isolated_test'); +element.textContent = 'isolated_script.js not blocked'; +// [End isolated_script_java_script] diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local.html new file mode 100644 index 0000000000000000000000000000000000000000..48ae7287bb6eb547f3e6af93822a6a2395554b28 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local.html @@ -0,0 +1,26 @@ + + + + + + + +

scheme: custom-local

+

options: ARKWEB_SCHEME_OPTION_LOCAL

+
local_script.js 被拦截
+ + + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js new file mode 100644 index 0000000000000000000000000000000000000000..b09eb3740e6f590481b9cc9f6832e15b6e9dd3de --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js @@ -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 local_script_java_script] +const element = document.getElementById('local_test'); +element.textContent = 'local_script.js not blocked.'; +// [End local_script_java_script] diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/post_data.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/post_data.html new file mode 100644 index 0000000000000000000000000000000000000000..cbb19dd30b4670af0cd983c6b86e91ffd283bc1f --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/post_data.html @@ -0,0 +1,48 @@ + + + + + + + + +
test xhr post
+
test xhr put
+ + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/service_worker.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/service_worker.html new file mode 100644 index 0000000000000000000000000000000000000000..e971e1c41387fc0a6e34e39d7a5ec6477419a3e2 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/service_worker.html @@ -0,0 +1,34 @@ + + + + + + + + + + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc5590284c2fb3fb66db687cdffc22f33782338 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js @@ -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. +*/ + +// [Start add_event_listener_java_script] +self.addEventListener('install', event => { + console.log('v1 installing'); + event.waitUntil( + caches.open('static-v1').then(cache => cache.add('/cat.svg')) + ); +}); + +self.addEventListener('activate', event => { + console.log('v1 now redy to handle fetches.'); +}); +// [End add_event_listener_java_script] diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.html new file mode 100644 index 0000000000000000000000000000000000000000..957e0b9cc9468930d06bade7bf15c6ea0ebbc90e --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.html @@ -0,0 +1,31 @@ + + + + + + + + +

网络拦截测试demo

+拦截视频资源请求,读取本地mp4文件
+测试三方协议忽略csp检查,并成功拦截
+测试拦截设置ISOLATED属性的三方协议
+测试拦截设置LOCAL属性的三方协议
+测试拦截service worker触发的请求
+测试读取blob类型http body stream
+测试读取chunked类型http body stream + + \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.mp4 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ea7b6c492bd757159d6fd62dd848a376bf918740 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.mp4 differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/video.html b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/video.html new file mode 100644 index 0000000000000000000000000000000000000000..87ccf17357ff0339a98a46c4f4f2077bac25699b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/video.html @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/xhr b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/xhr new file mode 100644 index 0000000000000000000000000000000000000000..42d4264b05a9fa4c2a5bf7e90c6f003e17588137 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/xhr @@ -0,0 +1,16 @@ +/* +* 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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/zh_CN/element/string.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9096f0eec925f8fad0a201dd68e989ac2137ed90 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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": "NetReqInterceptCacheWinOps" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/Libentry.mock.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..133fac9027ff6bbdcccfe98838fdbb2dc34639ab --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/Libentry.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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c7d2ba82b796a2850ced0a277d261d7d7355416 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/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. + */ + +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..be2af5338287767cc4f8e7a9c828728053e40ca8 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,77 @@ +/* + * 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. + }) + + /** + * 打开应用,拦截Web组件发起的网络请求 + */ + 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(3000); + + const button = await driver.findComponent(ON.text('goback')); + const clickText = await driver.findComponent(ON.type('link')); + await clickText.click(); + await driver.delayMs(2000); + + await button.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('test.html'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/List.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/.gitignore b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/build-profile.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/hvigorfile.ts b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/obfuscation-rules.txt b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/oh-package.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..0686a465f4e01e6afec667246536c3770fda73f9 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -0,0 +1,64 @@ +/* + * 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_open_bf_cache] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +export default class Entry2Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + let features = new webview.BackForwardCacheSupportedFeatures(); + features.nativeEmbed = true; + features.mediaTakeOver = true; + webview.WebviewController.enableBackForwardCache(features); + webview.WebviewController.initializeWebEngine(); + AppStorage.setOrCreate('abilityWant', want); + } + // [End web_module_open_bf_cache] + + 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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9a6b459004e1f1d0aefe9350f2c2ee907f66ff3 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..446ba7f8d6e676fb4293c037059eeee221396316 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/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 web_module_page_set] +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct Index { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Row() { + Button('Add options').onClick((event: ClickEvent) => { + let options = new webview.BackForwardCacheOptions(); + options.size = 10; + options.timeToLive = 300; + this.controller.setBackForwardCacheOptions(options); + }) + Button('Backward').onClick((event: ClickEvent) => { + this.controller.backward(); + }) + Button('Forward').onClick((event: ClickEvent) => { + this.controller.forward(); + }) + } + Web({ src: 'https://www.example.com', controller: this.controller }) + } + .height('100%') + .width('100%') + } +} +// [End Web_module_page_set] diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/module.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..90a4604809422135bc23f5a1d55f88ba15ad078d --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..548e6b522b6158085c11a1e61c7ce27152a67f30 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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": "NetReqInterceptCacheWinOps" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/backup_config.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfe20be2b7aebdfd54b3025e5c5a3af35b814ca1 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/Ability.test.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. + */ + +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. + }) + + /** + * 打开应用,使用Web组件前进后退缓存 + */ + it('testUiExample',0, async (done: Function) => { + console.info('uitest: TestUiExample 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(4000); + const button1 = await driver.findComponent(ON.text('Add options')); + const button2 = await driver.findComponent(ON.text('Backward')); + const button3 = await driver.findComponent(ON.text('Forward')); + await button1.click(); + await driver.delayMs(1000); + + const clickText = await driver.findComponent(ON.type('link')); + await clickText.click(); + await driver.delayMs(1000); + + await button2.click(); + await driver.delayMs(1000); + + await button3.click(); + await driver.delayMs(1000); + + const web = await driver.findComponent(ON.type('Web')); + let src: string = await web.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17410acb16bcc114982071879ee6b1f000794e19 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/List.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/.gitignore b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/build-profile.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/hvigorfile.ts b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/obfuscation-rules.txt b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/oh-package.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..655d244a4ec5c8e387d7ebfb66967132c8c952f6 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..069b292b0af70b3d468200c78ee1a6322194daf7 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -0,0 +1,63 @@ +/* + * 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'; +// [Start create_main_window] +import { createNWeb, defaultUrl } from '../pages/common'; + +// [StartExclude create_main_window] +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'); + } + // [EndExclude create_main_window] + + 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; + } + // 创建Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建,应用仅创建一个Web组件 + createNWeb(defaultUrl, windowStage.getMainWindowSync().getUIContext()); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + // [End create_main_window] + + 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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..2aa69cc19dbf5dde17260f3b99bc5d5683d0303c --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets @@ -0,0 +1,52 @@ +/* + * 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_dynamic_attach_detach] +// 使用NodeController的Page页 +import { getBuilderNode, MyNodeController, defaultUrl, getWebviewController } from './common'; + +@Entry +@Component +struct Index { + private nodeController : MyNodeController = + new MyNodeController(getBuilderNode(defaultUrl), getWebviewController(defaultUrl)); + + build() { + Row() { + Column() { + Button('Attach Webview') + .onClick(() => { + // 注意不要将同一个节点同时挂载在不同的页面上! + this.nodeController.attachWeb(); + this.nodeController.rebuild(); + }) + Button('Detach Webview') + .onClick(() => { + this.nodeController.detachWeb(); + this.nodeController.rebuild(); + }) + // NodeContainer用于与NodeController节点绑定,rebuild会触发makeNode + // Page页通过NodeContainer接口绑定NodeController,实现动态组件页面显示 + NodeContainer(this.nodeController) + .height('80%') + .width('80%') + } + .width('100%') + } + .height('100%') + } +} +// [End web_module_dynamic_attach_detach] + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5fa3e58a33fb108813444bf3ed4b64e92145af5 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets @@ -0,0 +1,118 @@ +/* + * 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 dynamic_web_module_manage] +// 提供动态挂载Web组件能力 +import { UIContext, NodeController, BuilderNode, FrameNode } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export const defaultUrl : string = 'www.example.com'; + +// Data为入参封装类 +class Data{ + public url: string = ''; + public webController: webview.WebviewController | null = null; + + constructor(url: string, webController: webview.WebviewController) { + this.url = url; + this.webController = webController; + } +} + +// @Builder中为动态组件的具体组件内容 +@Builder +function webBuilder(data:Data) { + Web({ src: data.url, controller: data.webController }) + .width('100%') + .height('100%') + .borderStyle(BorderStyle.Dashed) + .borderWidth(2) +} + +let wrap = wrapBuilder<[Data]>(webBuilder); + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private builderNode: BuilderNode<[Data]> | null | undefined = null; + private webController : webview.WebviewController | null | undefined = null; + private rootNode : FrameNode | null = null; + + constructor(builderNode : BuilderNode<[Data]> | undefined, webController : webview.WebviewController | undefined) { + super(); + this.builderNode = builderNode; + this.webController = webController; + } + + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 + // 在对应NodeContainer创建的时候调用或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + // 该节点会被挂载在NodeContainer的父节点下 + return this.rootNode; + } + + // 挂载Webview + attachWeb() : void { + if (this.builderNode) { + let frameNode : FrameNode | null = this.builderNode.getFrameNode(); + if (frameNode?.getParent() != null) { + // 挂载自定义节点前判断该节点是否已经被挂载 + hilog.error(0x0000, 'testTag', '%{public}s', 'The frameNode is already attached'); + return; + } + this.rootNode = this.builderNode.getFrameNode(); + } + } + + // 卸载Webview + detachWeb() : void { + this.rootNode = null; + } + + getWebController() : webview.WebviewController | null | undefined { + return this.webController; + } +} + +// 创建Map保存所需要的BuilderNode +let builderNodeMap : Map | undefined> = new Map(); +// 创建Map保存所需要的webview.WebviewController +let webControllerMap : Map = new Map(); + +// 初始化需要UIContext对象,UIContext对象可通过窗口或自定义组件的getUIContext方法获取 +export const createNWeb = (url: string, uiContext: UIContext) => { + // 创建WebviewController + let webController = new webview.WebviewController() ; + // 创建BuilderNode + let builderNode : BuilderNode<[Data]> = new BuilderNode(uiContext); + // 创建动态Web组件 + builderNode.build(wrap, new Data(url, webController)); + + // 保存BuilderNode + builderNodeMap.set(url, builderNode); + // 保存WebviewController + webControllerMap.set(url, webController); +} + +// 自定义获取BuilderNode的接口 +export const getBuilderNode = (url : string) : BuilderNode<[Data]> | undefined => { + return builderNodeMap.get(url); +} +// 自定义获取WebviewController的接口 +export const getWebviewController = (url : string) : webview.WebviewController | undefined => { + return webControllerMap.get(url); +} +// [End dynamic_web_module_manage] + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/module.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5566c38cae3156d6470062ff659b9f0a54160541 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/module.json5 @@ -0,0 +1,47 @@ +/* + * 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 + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/color.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/string.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0149cd890e824afa27522e2c2619eb1af870b7e6 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + } + ,{ + "name": "Entry3Ability_desc", + "value": "description" + }, + { + "name": "Entry3Ability_label", + "value": "NetReqInterceptCacheWinOps" + }, + { + "name": "web_path", + "value": "https://www.example.com" + } + ] +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/background.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/background.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/foreground.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/foreground.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/layered_image.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/startIcon.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/startIcon.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/profile/main_pages.json b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/mock/mock-config.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/Ability.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f76790cc9bbcaeff8e4261f449a25498dbcfc14d --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,80 @@ +/* + * 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. + }) + + /** + * 打开应用,使Web组件在不同的窗口间迁移 + */ + 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(3000); + + const button1 = await driver.findComponent(ON.text('Attach Webview')); + const button2 = await driver.findComponent(ON.text('Detach Webview')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src1: string = await web1.getText(); + expect(src1).assertContain('www.example.com'); + + await button2.click(); + await driver.delayMs(1000); + + const web2 = await driver.findComponent(ON.type('Web')); + expect(web2).assertEqual(null); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/List.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/module.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..edaba8aaabfc3819914b5d624d6d0143e85b5b86 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/List.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/LocalUnit.test.ets b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigor/hvigor-config.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigorfile.ts b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/oh-package.json5 b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/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/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/ohosTest.md b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..748fe87614e0f8e3e00968aa66845118a81eb916 --- /dev/null +++ b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/ohosTest.md @@ -0,0 +1,5 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | -------------------------------------- | ------------------------------- | -------- | -------- | +| 拦截Web组件发起的网络请求 | 设备运转正常 | 应用启动成功,点击link链接请求视频资源 | 跳转视频资源页,读取本地mp4文件 | Yes | Pass | +| 资源页按钮点击 | 位于资源页 | 点击按钮 | 跳转主页 | Yes | Pass | + diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_1.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_1.png new file mode 100644 index 0000000000000000000000000000000000000000..e8e9e6c44c1150016138cf6d544b6f19f48f3e23 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_1.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_2.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_2.png new file mode 100644 index 0000000000000000000000000000000000000000..4071262951432b162f41bc7872458d9a806d4a95 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_2.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_1.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_1.png new file mode 100644 index 0000000000000000000000000000000000000000..68483b6904f2089e5de4eab60995b07c743f0280 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_1.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_2.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_2.png new file mode 100644 index 0000000000000000000000000000000000000000..389930d3b0933c9420e2be528c3f0386d7269eda Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_2.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_1.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_1.png new file mode 100644 index 0000000000000000000000000000000000000000..1dcad318644d71c56792ec76d711762e9b697228 Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_1.png differ diff --git a/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_2.png b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_2.png new file mode 100644 index 0000000000000000000000000000000000000000..b32bfa47c6bb1dec72022ce376f7e69579ac621a Binary files /dev/null and b/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_2.png differ diff --git a/ProcessWebPageCont/.gitignore b/ProcessWebPageCont/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/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/ProcessWebPageCont/AppScope/app.json5 b/ProcessWebPageCont/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4b1ce53f111420364c0803811493cd969dc80603 --- /dev/null +++ b/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/ProcessWebPageCont/AppScope/resources/base/element/string.json b/ProcessWebPageCont/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4779102effef55e6d1414c9166b60b0783cdc210 --- /dev/null +++ b/ProcessWebPageCont/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ProcessWebPageCont" + } + ] +} diff --git a/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png b/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png differ diff --git a/ProcessWebPageCont/README.md b/ProcessWebPageCont/README.md new file mode 100644 index 0000000000000000000000000000000000000000..33ca5a3f5ed5dacf7ba2dfe6bb1b0ea5a1237864 --- /dev/null +++ b/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 code/DocsSample/ArkWeb/ProcessWebPageCont > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` + diff --git a/ProcessWebPageCont/build-profile.json5 b/ProcessWebPageCont/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/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/ProcessWebPageCont/code-linter.json5 b/ProcessWebPageCont/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/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/ProcessWebPageCont/entry/.gitignore b/ProcessWebPageCont/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ProcessWebPageCont/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ProcessWebPageCont/entry/build-profile.json5 b/ProcessWebPageCont/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/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/ProcessWebPageCont/entry/hvigorfile.ts b/ProcessWebPageCont/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/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/ProcessWebPageCont/entry/obfuscation-rules.txt b/ProcessWebPageCont/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/ProcessWebPageCont/entry/oh-package.json5 b/ProcessWebPageCont/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets b/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..82e98bec44d83d2df03deb52508045cb06cc8604 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..29feaca7669174be5c2b0e2366529ee94ab7e726 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets b/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets new file mode 100644 index 0000000000000000000000000000000000000000..a357e5996f55843b6b23feb7dae4b176cba2b0e6 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets b/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1def271b5633e957e9dd40c3b9591542f5cae01f --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets b/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets new file mode 100644 index 0000000000000000000000000000000000000000..30eecf7173f0c347787a368ec2b185ff925d4e3d --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets b/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d1281e593d6ba6c272dcd97a49da7cc006a16c2 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets b/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets new file mode 100644 index 0000000000000000000000000000000000000000..dad0b0ca9293ff918383646cded1535936ae35c1 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/module.json5 b/ProcessWebPageCont/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70729d262d8e46da160838ad06ca01e2f48b6f46 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/base/element/color.json b/ProcessWebPageCont/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/base/element/string.json b/ProcessWebPageCont/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1f758cd41cf67e4c769d7526ee83f962d0d865c6 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/base/media/background.png b/ProcessWebPageCont/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ProcessWebPageCont/entry/src/main/resources/base/media/background.png differ diff --git a/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png b/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png differ diff --git a/ProcessWebPageCont/entry/src/main/resources/base/media/layered_image.json b/ProcessWebPageCont/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png b/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json b/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/base/profile/main_pages.json b/ProcessWebPageCont/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..ead1e2c5ae06ebd7246b0a4028b9899b3de9574a --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/en_US/element/string.json b/ProcessWebPageCont/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..448a2a5210af13626ae587985d80eb8c51800e4d --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html b/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html new file mode 100644 index 0000000000000000000000000000000000000000..7225f16ebc840f16091bc9e7c75380f4c1104470 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf b/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f9dac5633ffc24eea33331035efbdbaffceb0031 Binary files /dev/null and b/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf differ diff --git a/ProcessWebPageCont/entry/src/main/resources/zh_CN/element/string.json b/ProcessWebPageCont/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..88de2d38c7e3b4d9017b102162dee18ed9bc4794 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/mock/mock-config.json5 b/ProcessWebPageCont/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/ohosTest/ets/test/Ability.test.ets b/ProcessWebPageCont/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..328b7bb43ddfe2b41224a082e95263ec212bc34e --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/ohosTest/ets/test/List.test.ets b/ProcessWebPageCont/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/ohosTest/module.json5 b/ProcessWebPageCont/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/test/List.test.ets b/ProcessWebPageCont/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/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/ProcessWebPageCont/entry/src/test/LocalUnit.test.ets b/ProcessWebPageCont/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/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/ProcessWebPageCont/hvigor/hvigor-config.json5 b/ProcessWebPageCont/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/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/ProcessWebPageCont/hvigorfile.ts b/ProcessWebPageCont/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/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/ProcessWebPageCont/oh-package.json5 b/ProcessWebPageCont/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/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/ProcessWebPageCont/ohosTest.md b/ProcessWebPageCont/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..a93a5b8216aaab3fa52497aba5b07499e2460066 --- /dev/null +++ b/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/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png b/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png new file mode 100644 index 0000000000000000000000000000000000000000..bacf76e4cca730d6869a641b88c9ab43a1c654c6 Binary files /dev/null and b/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png differ diff --git a/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png b/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png new file mode 100644 index 0000000000000000000000000000000000000000..f3e5eb8f67cca636ea0608cd5af117cc0e8f6542 Binary files /dev/null and b/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png differ diff --git a/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png b/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png new file mode 100644 index 0000000000000000000000000000000000000000..6e8241f75e8b4701ee18405f97b5b9f7e65efa87 Binary files /dev/null and b/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png differ diff --git a/ProcessWebPageCont/screenshots/PreviewPDF.png b/ProcessWebPageCont/screenshots/PreviewPDF.png new file mode 100644 index 0000000000000000000000000000000000000000..979eb15ac49c64537b600b4fe1e1e4c03b931c52 Binary files /dev/null and b/ProcessWebPageCont/screenshots/PreviewPDF.png differ diff --git a/README.md b/README.md index 98edb9ddb70ba5567278a771dee8be1f843275d1..0cb263c5bbc17552a32b216fdc97ad0894bde094 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,42 @@ * [ArkWebSchemeHandler: 拦截Web组件发起的网络请求](ArkWebSchemeHandler) +* [LifecycleWebComp:Web组件的生命周期](LifecycleWebComp) + +* [ManageWebCompSecPriv:解决Web组件本地资源跨域问题](ManageWebCompSecPriv) + +* [ManageWebPageFileIO:上传文件](ManageWebPageFileIO) + +* [ManageWebPageInteracts:管理网页交互](ManageWebPageInteracts) + +* [ManageWebPageLoadBrowse:管理网页加载与浏览记录](ManageWebPageLoadBrowse) + + - [AcceleratePageAccess:加速Web页面的访问](ManageWebPageLoadBrowse/AcceleratePageAccess) + - [CustomizePageResp:自定义页面请求响应](ManageWebPageLoadBrowse/CustomizePageResp) + + - [LoadPages:使用Web组件加载页面](ManageWebPageLoadBrowse/LoadPages) + - [ManagePageRedirectNav:管理页面跳转及浏览记录导航](ManageWebPageLoadBrowse/ManagePageRedirectNav) + - [NetReqInterceptCacheWinOps:拦截Web组件发起的网络请求](ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry) + - [NetReqInterceptCacheWinOps:Web组件前进后退缓存](ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2) + - [NetReqInterceptCacheWinOps:Web组件在不同的窗口间迁移](ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3) + +* [ProcessWebPageCont:使用Web组件打印前端页面](ProcessWebPageCont) + +* [SetBasicAttrsEvts:设置基本属性和事件](SetBasicAttrsEvts) + + - [SetBasicAttrsEvtsOne:使用隐私模式](SetBasicAttrsEvts/SetBasicAttrsEvtsOne) + - [SetBasicAttrsEvtsTwo:管理Cookie及数据存储](SetBasicAttrsEvts/SetBasicAttrsEvtsTwo) + +* [UseFrontendJSApp:在应用中使用前端页面JavaScript](UseFrontendJSApp) + +* [UseOfflineWebComp:使用离线Web组件](UseOfflineWebComp) + +* [UseSameLayerRender:同层渲染](UseSameLayerRender) + +* [UsingWebMultimedia:使用网页多媒体](UsingWebMultimedia) + +* [WebRenderLayout:Web渲染和布局](WebRenderLayout) + ## 使用说明 1. 将独立的应用示例工程导入DevEco Studio进行编译构建及运行调试。 diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/.gitignore b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0f85c5557290b6c5fe654a0173b9db71c296633d --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f3bc9e64fec3aceeac9b80739ca1dae60be59090 --- /dev/null +++ b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SetBasicAttrsEvtsOne" + } + ] +} diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/README.md b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d2c0dbcbdf13fc8040b6a72ea8793fd16b944248 --- /dev/null +++ b/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 code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/code-linter.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/.gitignore b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/hvigorfile.ts b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/obfuscation-rules.txt b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/AllowGeolocation.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/AllowGeolocation.ets new file mode 100644 index 0000000000000000000000000000000000000000..96167cf5d798feae39d86710b5ee195f507eaed6 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ClearAllCookiesSync.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ClearAllCookiesSync.ets new file mode 100644 index 0000000000000000000000000000000000000000..dde1aa7d0bd4b8e9ab501690b47459063e6cdaf0 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ConfigCookieSync.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ConfigCookieSync.ets new file mode 100644 index 0000000000000000000000000000000000000000..3c5e72cd0afd6e4dfc6d002d7e28532b1adb1b75 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_one.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fad13e49ed848122a37294eca902ba3b8b61ade --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_two.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd0dc35bcea348c0186915a71879e92829fbbeb6 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteAllData.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteAllData.ets new file mode 100644 index 0000000000000000000000000000000000000000..eba8a6b93ec17492b001acb0d90fd90f7f8248d8 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteGeolocation.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteGeolocation.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b38112ff6ea0c1a3c4b6d373614aa6f9fdede9a --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ExistCookie.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ExistCookie.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4f870530753c4ccb924457eb929bfb9d7e85411 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/FetchCookieSync.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/FetchCookieSync.ets new file mode 100644 index 0000000000000000000000000000000000000000..a17ed3b40343d58092b9156b79a9d82df1c5f549 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/GetAccessibleGeolocation.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/GetAccessibleGeolocation.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e37fd79fcd073ea9a487421899fcec2ffdd42aa --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_one.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..95d05d45a2a3d9ac1a635dc9f47c5dcdcc9b3080 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_two.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..45893f00c020b4a179eae6575e9bed4dc899b280 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..420f733900a18591c4b182d382f7b6e6bede3d61 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets new file mode 100644 index 0000000000000000000000000000000000000000..b39a2cf2be2b6dc0d11af46a87c698b4a7b20ac2 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets new file mode 100644 index 0000000000000000000000000000000000000000..af16dd1c6edf119f9f6da7d80d8d45517e3a7f0a --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..394d2a4703ff31b1662e4f09fba46876e701c984 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..18d4ec70763241b2e4e8ece71a5a37f56c0d74c8 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/layered_image.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/main_pages.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..873e2af741f7145ca994ad97abad48f571d63589 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/en_US/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..80f7dd956c3a63524e9bc87f25a1567069ce3176 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html new file mode 100644 index 0000000000000000000000000000000000000000..43497f5df3fabd7205aa28942e6dc63e24892b4a --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html new file mode 100644 index 0000000000000000000000000000000000000000..4ae442f92a0e6145b5979fd8f571722c6ca83d10 --- /dev/null +++ b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html @@ -0,0 +1,34 @@ + + + + + +

位置信息

+ + + + diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..25c6d7f99692719d79c63898f8bb68a9e8e6d9cc --- /dev/null +++ b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,55 @@ + + + + + + + test + + + +
状态信息
+ + diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html new file mode 100644 index 0000000000000000000000000000000000000000..e1a15e6a52b74bd26ba93ef26e4da665427aadec --- /dev/null +++ b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html @@ -0,0 +1,34 @@ + + + + + + + WindowEvent + + + + + + \ No newline at end of file diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/zh_CN/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f276d4cc8d01d30a9337543e65032484ddbb6765 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/mock/mock-config.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/Ability.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ddaa8f7e38d9a8406806eb3040768ec7fd07932 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/List.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/List.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/LocalUnit.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigorfile.ts b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/ohosTest.md b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..1366ac94e7a9591c59e590bb7e2139b635c275b1 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png new file mode 100644 index 0000000000000000000000000000000000000000..14db5e6cb7f913c2bb4bd4c1f650a6adc481ecc0 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png new file mode 100644 index 0000000000000000000000000000000000000000..a660a30cd30c0cc7dea9d91abbbde0f3e5cf0be0 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png new file mode 100644 index 0000000000000000000000000000000000000000..bcb0728a9ffb2dd02db07c591d54ba34f84cfae6 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png new file mode 100644 index 0000000000000000000000000000000000000000..070cc93979c4329965d0da492e7718a17b483421 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png new file mode 100644 index 0000000000000000000000000000000000000000..d988628107261e2a03abd319560d58eaba524095 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png new file mode 100644 index 0000000000000000000000000000000000000000..77b47aae22b5a81809ab869d8244e0d540ca84e9 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png new file mode 100644 index 0000000000000000000000000000000000000000..afff44065ba616b5bd56d6824f65aa662548dccf Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png new file mode 100644 index 0000000000000000000000000000000000000000..5e96f02cbf0d6d720444e28afaa27083e9b1ad32 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png new file mode 100644 index 0000000000000000000000000000000000000000..0581b3e297d890d2c7aeb1e2aa0a825357e075a3 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png new file mode 100644 index 0000000000000000000000000000000000000000..8d75318992f894e8af16cbf8c69aa3f5eaac115c Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png new file mode 100644 index 0000000000000000000000000000000000000000..58065bd9a8348befb7879279aa59443ffbb5761a Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png new file mode 100644 index 0000000000000000000000000000000000000000..237cb219e76eb1ccc6aa39fc03f3bd3a978a5254 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png new file mode 100644 index 0000000000000000000000000000000000000000..628a6e183aac531f9ebfa98b0059fec6a36f9a94 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png new file mode 100644 index 0000000000000000000000000000000000000000..c93cc7c400943c113530f451d724eab2af95ad8c Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png new file mode 100644 index 0000000000000000000000000000000000000000..0e70ae121a512da04e83988f817a5181d3accc52 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png new file mode 100644 index 0000000000000000000000000000000000000000..fc518f2b21fb6a82dd1c2afc21d1a6986e1d077f Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31ec642dd4cac388ed77191691e319de60e07db4 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4f29f2384417aa862af49ba47c6479c7830b8573 --- /dev/null +++ b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SetBasicAttrsEvtsTwo" + } + ] +} diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/README.md b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..858074d5053ce6c6ad496b087e5ac1f19a6d8859 --- /dev/null +++ b/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 code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` + + + + + diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/code-linter.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/.gitignore b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/hvigorfile.ts b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/obfuscation-rules.txt b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_one.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..1380c626b77a8925d9a21fee8cc5f8e99ce5b718 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_two.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e07970d273de44e1adddcb97a2efdeb46f29cad --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/CookieManagement.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/CookieManagement.ets new file mode 100644 index 0000000000000000000000000000000000000000..632de154566c900d7e7b3fb1b626c7587c0f1a4f --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/DomStorage.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/DomStorage.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e26e61b26fcafccba1da6eb8041ef16e069ad84 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5fb4c112b7bb8fcac763cdee5dadeba13f4266b --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets new file mode 100644 index 0000000000000000000000000000000000000000..d823038993b07b7ac68ae1dcc566a1a38bc4a20d --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_one.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e21aa06e9a105cbe66544b0496e7e71d5046c19 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_three.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_three.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e405be1a628098f73a7a511ca1a4911246455ea --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_two.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..4aff6c0e7d3f5d479a1119a6e384a823ec0c8825 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..94f3336a43093397f85ff0ce48b8f3fef9c9cac0 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d52556ec36ab53d80e77fc16b8cac98cee07626d --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/layered_image.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/main_pages.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1555514763f2c22e49ed472c8840eb93bd9bad75 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/en_US/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d52556ec36ab53d80e77fc16b8cac98cee07626d --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..fea52d652492c9a1a9e650add17bc74d43b82e03 --- /dev/null +++ b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,154 @@ + + + + + + + + + + + 运动和方向传感器 + + + + + +
+

运动和方向:

+
    +
  • +
  • +
  • +
  • +
  • +
  • +
+
+ + diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/zh_CN/element/string.json b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..abeb0b892fc4650c62ed42d93dc6b31be93c8344 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/mock/mock-config.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/Ability.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3e0fa5673567c1c2a6fd86f0041ce8510237b262 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/List.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/List.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/LocalUnit.test.ets b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigorfile.ts b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/ohosTest.md b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..515264d3e232a27e66b787f511f08ac7ad393f64 --- /dev/null +++ b/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/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png new file mode 100644 index 0000000000000000000000000000000000000000..b519a6915fe29d4c35014427a740efef2f54f3be Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png new file mode 100644 index 0000000000000000000000000000000000000000..cc9751214bb8f1b626abbb07131f0bcb5a56b1de Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png new file mode 100644 index 0000000000000000000000000000000000000000..7226dba6e72950639ad4e07323b53fcd860521d0 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png new file mode 100644 index 0000000000000000000000000000000000000000..2737f7f92ba24dc12c23b527253054bec2961fea Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png new file mode 100644 index 0000000000000000000000000000000000000000..7ec9c6c64fa8862970cf471cf14600a6d7e39580 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png new file mode 100644 index 0000000000000000000000000000000000000000..1d6a51e23edec2e705a25284a638ebcb0852ac4b Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png new file mode 100644 index 0000000000000000000000000000000000000000..ee8c9c998321599f0d0381deac96e827fceac5ac Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png new file mode 100644 index 0000000000000000000000000000000000000000..4f00b024de82f2bb88b33471bd1440b798d56859 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png differ diff --git a/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png new file mode 100644 index 0000000000000000000000000000000000000000..5249dc4104448d82890889afdc1c61092980bac8 Binary files /dev/null and b/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png differ diff --git a/UseFrontendJSApp/.gitignore b/UseFrontendJSApp/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/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/UseFrontendJSApp/AppScope/app.json5 b/UseFrontendJSApp/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb2771a6d1ebbcd7b796d98179f3dddaac3c9efd --- /dev/null +++ b/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/UseFrontendJSApp/AppScope/resources/base/element/string.json b/UseFrontendJSApp/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d98b87fae58bdc64df1c8a60281d29644dff9f00 --- /dev/null +++ b/UseFrontendJSApp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UseFrontendJSApp" + } + ] +} diff --git a/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png b/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png differ diff --git a/UseFrontendJSApp/README.md b/UseFrontendJSApp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..eac8fc419de119a1e89d00cf60103aa676c4c623 --- /dev/null +++ b/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 code/DocsSample/ArkWeb/UseFrontendJSApp > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/UseFrontendJSApp/build-profile.json5 b/UseFrontendJSApp/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e4e9cf69682c02dcb930dfce613e32ab91914790 --- /dev/null +++ b/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/UseFrontendJSApp/code-linter.json5 b/UseFrontendJSApp/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/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/UseFrontendJSApp/entry/.gitignore b/UseFrontendJSApp/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseFrontendJSApp/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseFrontendJSApp/entry/build-profile.json5 b/UseFrontendJSApp/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/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/UseFrontendJSApp/entry/hvigorfile.ts b/UseFrontendJSApp/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/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/UseFrontendJSApp/entry/obfuscation-rules.txt b/UseFrontendJSApp/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/UseFrontendJSApp/entry/oh-package.json5 b/UseFrontendJSApp/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets b/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..82e98bec44d83d2df03deb52508045cb06cc8604 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..29feaca7669174be5c2b0e2366529ee94ab7e726 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/ets/pages/Index.ets b/UseFrontendJSApp/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e1a33e76b4c5114d9f50733e010812c4dfaa9a55 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/module.json5 b/UseFrontendJSApp/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/resources/base/element/color.json b/UseFrontendJSApp/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/resources/base/element/string.json b/UseFrontendJSApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8f7df8d295e8046511f2835416c9eea959c99657 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/resources/base/media/background.png b/UseFrontendJSApp/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseFrontendJSApp/entry/src/main/resources/base/media/background.png differ diff --git a/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png b/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png differ diff --git a/UseFrontendJSApp/entry/src/main/resources/base/media/layered_image.json b/UseFrontendJSApp/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png b/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png differ diff --git a/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json b/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json b/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UseFrontendJSApp/entry/src/main/resources/en_US/element/string.json b/UseFrontendJSApp/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8f7df8d295e8046511f2835416c9eea959c99657 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html b/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..3db83981023a1e30aa99b51b7c0ac4be7ebf2bda --- /dev/null +++ b/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,39 @@ + + + + + + + +

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

+ + + diff --git a/UseFrontendJSApp/entry/src/main/resources/zh_CN/element/string.json b/UseFrontendJSApp/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b060b52e82b9cbdf9b4cf441b8ebc77053cda9f4 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/mock/mock-config.json5 b/UseFrontendJSApp/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/ohosTest/ets/test/Ability.test.ets b/UseFrontendJSApp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..529c502db25b8b7edfc5ea420457241b8d374b9f --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/ohosTest/ets/test/List.test.ets b/UseFrontendJSApp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/ohosTest/module.json5 b/UseFrontendJSApp/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/test/List.test.ets b/UseFrontendJSApp/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/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/UseFrontendJSApp/entry/src/test/LocalUnit.test.ets b/UseFrontendJSApp/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/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/UseFrontendJSApp/entry2/.gitignore b/UseFrontendJSApp/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseFrontendJSApp/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseFrontendJSApp/entry2/build-profile.json5 b/UseFrontendJSApp/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/hvigorfile.ts b/UseFrontendJSApp/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/obfuscation-rules.txt b/UseFrontendJSApp/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/UseFrontendJSApp/entry2/oh-package.json5 b/UseFrontendJSApp/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..dab8f3ea7260551b9dc6606eb397e396d241e701 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..213e60d6187ea841335f6263f3072b8e1c20e395 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..730f850ab03976dfd6e0c92ad1dffdeacf6cad03 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/JavaScriptProxy.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/JavaScriptProxy.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1cd4cc07f1b04d30dc9cf8918b25cf8da7746eb --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_one.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..df576803c18cdb35e48140459f394c0ad41faf46 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_two.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..67fdec8c5f3d40c406ceeac6190168faad1119a7 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/RegisterJavaScriptProxy.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/RegisterJavaScriptProxy.ets new file mode 100644 index 0000000000000000000000000000000000000000..e69d1c30cccae8cbb61c9ef8072d23481eca3030 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_five.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_five.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d284f5ddc539a42864c2a7fe68bc10be95c4ad6 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_four.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_four.ets new file mode 100644 index 0000000000000000000000000000000000000000..046d6e1c60674e9d5ca76fb13044fccb9b6c3388 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_one.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f115540320bebd5d2a69fc9c90e89ef13f76e9b --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_three.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_three.ets new file mode 100644 index 0000000000000000000000000000000000000000..32d9ef6c5bee7edbda4c4e2ee6326717eddfbe3c --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_two.ets b/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee4d7cbb90d72f446f6787797845c48ac385242a --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/module.json5 b/UseFrontendJSApp/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..90a4604809422135bc23f5a1d55f88ba15ad078d --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json b/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/resources/base/element/string.json b/UseFrontendJSApp/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7c88d8349f6a73dadf4933bc4f150cb016a226fe --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png b/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png differ diff --git a/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png b/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png differ diff --git a/UseFrontendJSApp/entry2/src/main/resources/base/media/layered_image.json b/UseFrontendJSApp/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png b/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json b/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/resources/base/profile/main_pages.json b/UseFrontendJSApp/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..85f81c85c48178478853558030d3f675380df813 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html b/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html new file mode 100644 index 0000000000000000000000000000000000000000..f191e18ba4a95fff3e0c00a06b8efc58042bed0e --- /dev/null +++ b/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html @@ -0,0 +1,29 @@ + + + + + + +

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

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

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

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

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

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

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

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

+ + + \ No newline at end of file diff --git a/UseFrontendJSApp/entry2/src/mock/mock-config.json5 b/UseFrontendJSApp/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/ohosTest/ets/test/Ability.test.ets b/UseFrontendJSApp/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe6e745d6402255deda1eb8eaae4ead04782fd0c --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/ohosTest/ets/test/List.test.ets b/UseFrontendJSApp/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/ohosTest/module.json5 b/UseFrontendJSApp/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17410acb16bcc114982071879ee6b1f000794e19 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/test/List.test.ets b/UseFrontendJSApp/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/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/UseFrontendJSApp/entry2/src/test/LocalUnit.test.ets b/UseFrontendJSApp/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/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/UseFrontendJSApp/entry3/.gitignore b/UseFrontendJSApp/entry3/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseFrontendJSApp/entry3/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseFrontendJSApp/entry3/build-profile.json5 b/UseFrontendJSApp/entry3/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/hvigorfile.ts b/UseFrontendJSApp/entry3/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/obfuscation-rules.txt b/UseFrontendJSApp/entry3/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/UseFrontendJSApp/entry3/oh-package.json5 b/UseFrontendJSApp/entry3/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..655d244a4ec5c8e387d7ebfb66967132c8c952f6 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..e62e0723b2780a459f90447d95ff110ba058fc00 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/main/ets/pages/Index.ets b/UseFrontendJSApp/entry3/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..fbd0bd1bab826fdc2c0ad69c882481ee047fe643 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/main/module.json5 b/UseFrontendJSApp/entry3/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a9345ab1e0f0dbf59e896cd74d2ced8094e7fb9b --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json b/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/main/resources/base/element/string.json b/UseFrontendJSApp/entry3/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1253ae78eed82312b6c4db8b1a11dc6baee5f27c --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png b/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png differ diff --git a/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png b/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png differ diff --git a/UseFrontendJSApp/entry3/src/main/resources/base/media/layered_image.json b/UseFrontendJSApp/entry3/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png b/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png differ diff --git a/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json b/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html b/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..7e67007432b4e000fab6254a4fd81bd071066193 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/mock/mock-config.json5 b/UseFrontendJSApp/entry3/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/ohosTest/ets/test/Ability.test.ets b/UseFrontendJSApp/entry3/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..909b4cebec67c5b9af51626c88043ac152a69906 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/ohosTest/ets/test/List.test.ets b/UseFrontendJSApp/entry3/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/ohosTest/module.json5 b/UseFrontendJSApp/entry3/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..edaba8aaabfc3819914b5d624d6d0143e85b5b86 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/test/List.test.ets b/UseFrontendJSApp/entry3/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/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/UseFrontendJSApp/entry3/src/test/LocalUnit.test.ets b/UseFrontendJSApp/entry3/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/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/UseFrontendJSApp/entry4/.gitignore b/UseFrontendJSApp/entry4/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseFrontendJSApp/entry4/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseFrontendJSApp/entry4/build-profile.json5 b/UseFrontendJSApp/entry4/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fea31f4580540c7c560b62bf531292c471c410f1 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/hvigorfile.ts b/UseFrontendJSApp/entry4/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/obfuscation-rules.txt b/UseFrontendJSApp/entry4/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/UseFrontendJSApp/entry4/oh-package.json5 b/UseFrontendJSApp/entry4/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..00f4289f03ded4fc5b05708a28cd06c44a0ad53e --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt b/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..14607faba853fe717a19495cfc2364bc8be66216 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp b/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..096575c6a7109a5cb714c7a936f28dfc0019aebb --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp b/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b35bebbf50225c26290f8e4bc93d2feffa358523 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h b/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h new file mode 100644 index 0000000000000000000000000000000000000000..68d1e15bdcdbce0885d887cba00ee53264ed9edb --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp b/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..820107b7d23aac8e97b4f6ce2d6517ea2eea824b --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts b/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a12836b52e43cb6d1b8cff089e191a95b44f40a8 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 b/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1228596cfe7eb84f89b7125abb95de5246a5829c --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets b/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..84e3ab74f2a987f3a4cf9c6e380c5901b3491478 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets b/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a21a25554a682bc942ffee2a5b9a2beb088123a --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/module.json5 b/UseFrontendJSApp/entry4/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..afa13b4ebdc29a9cb812bfbb16d66e97039a14e5 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json b/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/resources/base/element/string.json b/UseFrontendJSApp/entry4/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..12e68f45a4cdb0af57c32b313a820ea8d23af66b --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png b/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png differ diff --git a/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png b/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png differ diff --git a/UseFrontendJSApp/entry4/src/main/resources/base/media/layered_image.json b/UseFrontendJSApp/entry4/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png b/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png differ diff --git a/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json b/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html b/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html new file mode 100644 index 0000000000000000000000000000000000000000..a6ebe9e4665f309fd2ecbe9b256af033154bb055 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/mock/Libentry4.mock.ets b/UseFrontendJSApp/entry4/src/mock/Libentry4.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..37c4693badee0bced9f50f020403147ada0e8d44 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/mock/mock-config.json5 b/UseFrontendJSApp/entry4/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cccc61410df447034f1a89e4dae104448202f02a --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/ohosTest/ets/test/Ability.test.ets b/UseFrontendJSApp/entry4/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9be87be5508277dddc4e036c2c687d47c3f302a --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/ohosTest/ets/test/List.test.ets b/UseFrontendJSApp/entry4/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/ohosTest/module.json5 b/UseFrontendJSApp/entry4/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..12ba91e94655586fb5e48c90b290e66be7e85db2 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/test/List.test.ets b/UseFrontendJSApp/entry4/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/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/UseFrontendJSApp/entry4/src/test/LocalUnit.test.ets b/UseFrontendJSApp/entry4/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/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/UseFrontendJSApp/entry5/.gitignore b/UseFrontendJSApp/entry5/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseFrontendJSApp/entry5/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseFrontendJSApp/entry5/build-profile.json5 b/UseFrontendJSApp/entry5/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fea31f4580540c7c560b62bf531292c471c410f1 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/hvigorfile.ts b/UseFrontendJSApp/entry5/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/obfuscation-rules.txt b/UseFrontendJSApp/entry5/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/UseFrontendJSApp/entry5/oh-package.json5 b/UseFrontendJSApp/entry5/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b58415e4585a7d2d30f02bba160d4401c9575b19 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt b/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..46be202fc230d85a6eade7ed2cedec2ad189af17 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp b/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cde6ffb2e4639d3818c096981f9a6a07ecb74453 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp b/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c11c8b57c075b5322df845f7fdc371f8b49caa0 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts b/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..85deb09b85692e2643ef2057b9011afe4882f293 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 b/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..98c81afabac4d3f9d57c741379ffcd83981d7741 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets b/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0e606032c1d06947096a1714fd9401b639ac132 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets b/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..95128ad57412a7dee67713db44efc8f717855f31 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/module.json5 b/UseFrontendJSApp/entry5/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e5f83a19012c5aeed889f2500740ef21005ce465 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json b/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/resources/base/element/string.json b/UseFrontendJSApp/entry5/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..06da3e1cdd155e5e4e35d5d768e9c71eb8ccdc6d --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png b/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png differ diff --git a/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png b/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png differ diff --git a/UseFrontendJSApp/entry5/src/main/resources/base/media/layered_image.json b/UseFrontendJSApp/entry5/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png b/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png differ diff --git a/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json b/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html b/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..d2925296ddd927dee795dba32254d6e182c4e8f8 --- /dev/null +++ b/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html @@ -0,0 +1,138 @@ + + + + + +

etsRunJavaScriptExt测试demo

+

+

Receive string:

+

Receive arraybuffer:

+ + + + diff --git a/UseFrontendJSApp/entry5/src/mock/Libentry5.mock.ets b/UseFrontendJSApp/entry5/src/mock/Libentry5.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..37c4693badee0bced9f50f020403147ada0e8d44 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/mock/mock-config.json5 b/UseFrontendJSApp/entry5/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d67f40d452081e758a12bf1b6aca9e0097b23590 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/ohosTest/ets/test/Ability.test.ets b/UseFrontendJSApp/entry5/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ffbfa958c98ebfd0a8bea5b321594420b0f7398 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/ohosTest/ets/test/List.test.ets b/UseFrontendJSApp/entry5/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f40533d1374f4046f8af1e7df6aa90157cb361d8 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/ohosTest/module.json5 b/UseFrontendJSApp/entry5/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5ee7a310ffadc8ca0196f9fbc0b4a62ccc8c575d --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/test/List.test.ets b/UseFrontendJSApp/entry5/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ce5a4e436790deecb880ddf871876bd2a7f7b07 --- /dev/null +++ b/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/UseFrontendJSApp/entry5/src/test/LocalUnit.test.ets b/UseFrontendJSApp/entry5/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7b035e9b66997b8cac57382753074ff60c3f5ee --- /dev/null +++ b/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/UseFrontendJSApp/hvigor/hvigor-config.json5 b/UseFrontendJSApp/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/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/UseFrontendJSApp/hvigorfile.ts b/UseFrontendJSApp/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/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/UseFrontendJSApp/oh-package.json5 b/UseFrontendJSApp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/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/UseFrontendJSApp/ohosTest.md b/UseFrontendJSApp/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..f983963664d05f87556fefa33664465a499169e4 --- /dev/null +++ b/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/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png b/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png new file mode 100644 index 0000000000000000000000000000000000000000..4ec6b9379b1f30cee90784020ba5d63f8658b44a Binary files /dev/null and b/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png differ diff --git a/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png b/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png new file mode 100644 index 0000000000000000000000000000000000000000..9fca6ab851203269337857ad55bfb928d48eae5b Binary files /dev/null and b/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png differ diff --git a/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png b/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png new file mode 100644 index 0000000000000000000000000000000000000000..d751a1f32fbc6ce5d348f67eb909967f71108b51 Binary files /dev/null and b/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png differ diff --git a/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png b/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png new file mode 100644 index 0000000000000000000000000000000000000000..91588bab66d95f3331b83c5835ceda40101e2a08 Binary files /dev/null and b/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png differ diff --git a/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png b/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png new file mode 100644 index 0000000000000000000000000000000000000000..af089f319eb97ca164e582f693f35fa736d9eaf7 Binary files /dev/null and b/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png differ diff --git a/UseFrontendJSApp/screenshots/EstabDataChannel_1.png b/UseFrontendJSApp/screenshots/EstabDataChannel_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ee086caba864c70bc90146e8ddb647b4799b64e7 Binary files /dev/null and b/UseFrontendJSApp/screenshots/EstabDataChannel_1.png differ diff --git a/UseFrontendJSApp/screenshots/EstabDataChannel_2.png b/UseFrontendJSApp/screenshots/EstabDataChannel_2.png new file mode 100644 index 0000000000000000000000000000000000000000..14099796a5bb12268b079ca387c4edaf17650d60 Binary files /dev/null and b/UseFrontendJSApp/screenshots/EstabDataChannel_2.png differ diff --git a/UseFrontendJSApp/screenshots/EstabDataChannel_3.png b/UseFrontendJSApp/screenshots/EstabDataChannel_3.png new file mode 100644 index 0000000000000000000000000000000000000000..0356c81695e355fcf377781230ba8a86487eda37 Binary files /dev/null and b/UseFrontendJSApp/screenshots/EstabDataChannel_3.png differ diff --git a/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png b/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png new file mode 100644 index 0000000000000000000000000000000000000000..3ee5136df51546e427c67e2b3bbb4c8509c936c8 Binary files /dev/null and b/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png differ diff --git a/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png b/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png new file mode 100644 index 0000000000000000000000000000000000000000..820750d20233f35ce6d79046ba5f18d79321c851 Binary files /dev/null and b/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png differ diff --git a/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png b/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png new file mode 100644 index 0000000000000000000000000000000000000000..013b8df368cbc76d35adc30032d9772e1ac9da73 Binary files /dev/null and b/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png differ diff --git a/UseFrontendJSApp/screenshots/Promise_one.png b/UseFrontendJSApp/screenshots/Promise_one.png new file mode 100644 index 0000000000000000000000000000000000000000..12bbbb0fd128b21bed1a4371f6b2e550dbbeca0e Binary files /dev/null and b/UseFrontendJSApp/screenshots/Promise_one.png differ diff --git a/UseFrontendJSApp/screenshots/Promise_two.png b/UseFrontendJSApp/screenshots/Promise_two.png new file mode 100644 index 0000000000000000000000000000000000000000..8bee542e43da4707286062da6e464ac404ccfe78 Binary files /dev/null and b/UseFrontendJSApp/screenshots/Promise_two.png differ diff --git a/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png b/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ebeee2e026791ac950624544d3c755aa9575a2d3 Binary files /dev/null and b/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png differ diff --git a/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png b/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png new file mode 100644 index 0000000000000000000000000000000000000000..6a12f71ee544aba84d8f84b942b2e9ce795ebde1 Binary files /dev/null and b/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png differ diff --git a/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png differ diff --git a/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png differ diff --git a/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png differ diff --git a/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png differ diff --git a/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1060bef8cbda6cd2bd9d11983eea8075b5f87b Binary files /dev/null and b/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png differ diff --git a/UseOfflineWebComp/.gitignore b/UseOfflineWebComp/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/UseOfflineWebComp/.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/UseOfflineWebComp/AppScope/app.json5 b/UseOfflineWebComp/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5f862a961c7301f8f3f7a1639e5b59099e70e83c --- /dev/null +++ b/UseOfflineWebComp/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.useofflinewebcomp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/UseOfflineWebComp/AppScope/resources/base/element/string.json b/UseOfflineWebComp/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..16490fd4d57af415efa5b69d512c3cce31db1e47 --- /dev/null +++ b/UseOfflineWebComp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UseOfflineWebComp" + } + ] +} diff --git a/UseOfflineWebComp/AppScope/resources/base/media/app_icon.png b/UseOfflineWebComp/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/UseOfflineWebComp/AppScope/resources/base/media/app_icon.png differ diff --git a/UseOfflineWebComp/README.md b/UseOfflineWebComp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8ebe4d1e697a08732bb46cd13c964c744251fbc4 --- /dev/null +++ b/UseOfflineWebComp/README.md @@ -0,0 +1,136 @@ +# 使用离线Web组件 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-offline-mode.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### Entry: + +#### CreatingOfflineWebComponents + +##### 介绍 + +1. 本示例主要介绍使用离线Web组件加载显示页面。在需要离屏创建Web组件时,定义一个自定义组件以封装Web组件,此Web组件在离线状态下被创建,封装于无状态的NodeContainer节点中,并与相应的NodeController组件绑定。Web组件在后台预渲染完毕后,当需要展示时,通过NodeController将其挂载到ViewTree的NodeContainer中,即与对应的NodeContainer组件绑定,即可挂载上树并显示。 + +##### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. Index.ets通过getNWeb从NodeMap获取myNodeController,将其传入NodeContainer,实现动态组件在页面的显示。 + +### Entry1: + +#### PreLaunchingRenderingProcess_one + +##### 介绍 + +1. 本示例主要介绍预启动ArkWeb渲染进程。在后台预先创建一个Web组件,以启动用于渲染的Web渲染进程,这样可以节省后续Web组件加载时启动Web渲染进程所需的时间。 + +##### 效果预览 + +| 主页 | 跳转页 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 在onWindowStageCreate时期预创建了一个Web组件加载blank页面,从而提前启动了Render进程,从index跳转到index2时,优化了Web的Render进程启动和初始化的耗时。 +1. 点击跳转到web页面按钮跳转到Web页面。 + +### Entry2: + +#### PreLaunchingRenderingProcess_two + +##### 介绍 + +1. 本示例主要介绍使用预渲染Web页面。预预渲染Web页面优化方案适用于Web页面启动和跳转场景,例如,进入首页后,跳转到子页。建议在高命中率的页面使用该方案。渲染Web页面的实现方案是提前创建离线Web组件,并设置Web为Active状态来开启渲染引擎,进行后台渲染。 + +##### 效果预览 + +| 主页 | 跳转页面 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击跳转到web页面按钮跳转到Web页面。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---common.ets +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry1/src/main/ +|---ets +|---|---entry1ability +|---|---|---Entry1Ability.ets +|---|---pages +|---|---|---common.ets +|---|---|---Index.ets // 首页 +|---|---|---index2.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 + +entry2/src/main/ +|---ets +|---|---entry2ability +|---|---|---Entry2Ability.ets +|---|---pages +|---|---|---common.ets +|---|---|---Index.ets // 首页 +|---|---|---index2.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 code/DocsSample/ArkWeb/UseOfflineWebComp > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/UseOfflineWebComp/build-profile.json5 b/UseOfflineWebComp/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5d6ce573886808e297e2c5b7e699c9c6aaad0329 --- /dev/null +++ b/UseOfflineWebComp/build-profile.json5 @@ -0,0 +1,75 @@ +/* + * 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": "entry1", + "srcPath": "./entry1", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UseOfflineWebComp/code-linter.json5 b/UseOfflineWebComp/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/.gitignore b/UseOfflineWebComp/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseOfflineWebComp/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseOfflineWebComp/entry/build-profile.json5 b/UseOfflineWebComp/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/hvigorfile.ts b/UseOfflineWebComp/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/obfuscation-rules.txt b/UseOfflineWebComp/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/oh-package.json5 b/UseOfflineWebComp/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/main/ets/entryability/EntryAbility.ets b/UseOfflineWebComp/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..afdc22155db92eda85280be3c8b2099022c52392 --- /dev/null +++ b/UseOfflineWebComp/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * 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 { createNWeb } from "../pages/common"; +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'); + } + // [Start entry_ability_window_stage_created_after_specified_page_loaded] + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + // 创建Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建 + createNWeb('www.example.com', windowStage.getMainWindowSync().getUIContext()); + if (err.code) { + return; + } + }); + } + // [End entry_ability_window_stage_created_after_specified_page_loaded] + + 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/UseOfflineWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/UseOfflineWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/main/ets/pages/Index.ets b/UseOfflineWebComp/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..05172de125ec81709abfc50f85fa99c9d6b794bf --- /dev/null +++ b/UseOfflineWebComp/entry/src/main/ets/pages/Index.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. + */ + +// 使用NodeController的Page页 +// Index.ets +// [Start nodeContainer_bind_controller_to_show_dynamic_pages] +import { getNWeb } from './common' +@Entry +@Component +struct Index { + build() { + Row() { + Column() { + // NodeContainer用于与NodeController节点绑定,rebuild会触发makeNode + // Page页通过NodeContainer接口绑定NodeController,实现动态组件页面显示 + NodeContainer(getNWeb('www.example.com')) + .height('90%') + .width('100%') + } + .width('100%') + } + .height('100%') + } +} +// [End nodeContainer_bind_controller_to_show_dynamic_pages] + diff --git a/UseOfflineWebComp/entry/src/main/ets/pages/common.ets b/UseOfflineWebComp/entry/src/main/ets/pages/common.ets new file mode 100644 index 0000000000000000000000000000000000000000..12f79f4c56008d1ca83a76d674f08bbafb71874f --- /dev/null +++ b/UseOfflineWebComp/entry/src/main/ets/pages/common.ets @@ -0,0 +1,101 @@ +/* + * 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 manage_dynamic_webview_components_in_harmonyos_app] +// 创建NodeController +// common.ets +import { UIContext, NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +// @Builder中为动态组件的具体组件内容 +// Data为入参封装类 +class Data{ + public url: ResourceStr = 'www.example.com'; + public controller: WebviewController = new webview.WebviewController(); +} + +@Builder +function webBuilder(data:Data) { + Column() { + Web({ src: data.url, controller: data.controller }) + .width('100%') + .height('100%') + } +} + +let wrap = wrapBuilder(webBuilder); + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private rootnode: BuilderNode | null = null; + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + console.log(' uicontext is undefined : '+ (uiContext === undefined)); + if (this.rootnode != null) { + // 返回FrameNode节点 + return this.rootnode.getFrameNode(); + } + // 返回null控制动态组件脱离绑定节点 + return null; + } + // 当布局大小发生变化时进行回调 + aboutToResize(size: Size) { + console.log('aboutToResize width : ' + size.width + ' height : ' + size.height ); + } + + // 当controller对应的NodeContainer在Appear的时候进行回调 + aboutToAppear() { + console.log('aboutToAppear'); + } + + // 当controller对应的NodeContainer在Disappear的时候进行回调 + aboutToDisappear() { + console.log('aboutToDisappear'); + } + + // 此函数为自定义函数,可作为初始化函数使用 + // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 + initWeb(url:ResourceStr, uiContext:UIContext, control:WebviewController) { + if (this.rootnode != null) { + return; + } + // 创建节点,需要uiContext + this.rootnode = new BuilderNode(uiContext); + // 创建动态Web组件 + this.rootnode.build(wrap, { url:url, controller:control }); + } +} +// 创建Map保存所需要的NodeController +let nodeMap:Map = new Map(); +// 创建Map保存所需要的WebViewController +let controllerMap:Map = new Map(); + +// 初始化需要UIContext 需在Ability获取 +export const createNWeb = (url: ResourceStr, uiContext: UIContext) => { + // 创建NodeController + let baseNode = new MyNodeController(); + let controller = new webview.WebviewController() ; + // 初始化自定义Web组件 + baseNode.initWeb(url, uiContext, controller); + controllerMap.set(url, controller); + nodeMap.set(url, baseNode); +} +// 自定义获取NodeController接口 +export const getNWeb = (url: ResourceStr) : MyNodeController | undefined => { + return nodeMap.get(url); +} +// [End manage_dynamic_webview_components_in_harmonyos_app] \ No newline at end of file diff --git a/UseOfflineWebComp/entry/src/main/module.json5 b/UseOfflineWebComp/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/main/resources/base/element/color.json b/UseOfflineWebComp/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/main/resources/base/element/string.json b/UseOfflineWebComp/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..325d863aa7f8a3c7d5a94d68779702003bd7242e --- /dev/null +++ b/UseOfflineWebComp/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": "UseOfflineWebComp" + } + ] +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry/src/main/resources/base/media/background.png b/UseOfflineWebComp/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseOfflineWebComp/entry/src/main/resources/base/media/background.png differ diff --git a/UseOfflineWebComp/entry/src/main/resources/base/media/foreground.png b/UseOfflineWebComp/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseOfflineWebComp/entry/src/main/resources/base/media/foreground.png differ diff --git a/UseOfflineWebComp/entry/src/main/resources/base/media/layered_image.json b/UseOfflineWebComp/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/main/resources/base/media/startIcon.png b/UseOfflineWebComp/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseOfflineWebComp/entry/src/main/resources/base/media/startIcon.png differ diff --git a/UseOfflineWebComp/entry/src/main/resources/base/profile/backup_config.json b/UseOfflineWebComp/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/UseOfflineWebComp/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry/src/main/resources/base/profile/main_pages.json b/UseOfflineWebComp/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UseOfflineWebComp/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UseOfflineWebComp/entry/src/main/resources/en_US/element/string.json b/UseOfflineWebComp/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..325d863aa7f8a3c7d5a94d68779702003bd7242e --- /dev/null +++ b/UseOfflineWebComp/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": "UseOfflineWebComp" + } + ] +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry/src/main/resources/zh_CN/element/string.json b/UseOfflineWebComp/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..96f5c74c69f70c8ae6a004ea7f9ec4ddf80c90fa --- /dev/null +++ b/UseOfflineWebComp/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": "UseOfflineWebComp" + } + ] +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry/src/mock/mock-config.json5 b/UseOfflineWebComp/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/ohosTest/ets/test/Ability.test.ets b/UseOfflineWebComp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a45a1a8b939bf11a63fba92c8574ed59cba7f4f3 --- /dev/null +++ b/UseOfflineWebComp/entry/src/ohosTest/ets/test/Ability.test.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. + */ + +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. + }) + + /* + * 打开应用 + * 使用离线Web组件加载显示页面 + */ + 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(3000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry/src/ohosTest/ets/test/List.test.ets b/UseOfflineWebComp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/ohosTest/module.json5 b/UseOfflineWebComp/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/test/List.test.ets b/UseOfflineWebComp/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry/src/test/LocalUnit.test.ets b/UseOfflineWebComp/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry1/.gitignore b/UseOfflineWebComp/entry1/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseOfflineWebComp/entry1/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseOfflineWebComp/entry1/build-profile.json5 b/UseOfflineWebComp/entry1/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/hvigorfile.ts b/UseOfflineWebComp/entry1/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/obfuscation-rules.txt b/UseOfflineWebComp/entry1/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/oh-package.json5 b/UseOfflineWebComp/entry1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c4e8768835e5e869bbd19dfb80d2e323afaa6f2d --- /dev/null +++ b/UseOfflineWebComp/entry1/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": "entry1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/UseOfflineWebComp/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/UseOfflineWebComp/entry1/src/main/ets/entry1ability/Entry1Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..399559a50dd766258b4aac826c8ec6b81103b84b --- /dev/null +++ b/UseOfflineWebComp/entry1/src/main/ets/entry1ability/Entry1Ability.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'; +import { createNWeb } from '../pages/common'; + +export default class Entry1Ability 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'); + } + + // [Start entry_ability_window_stage_created_after_page_loaded] + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + // 创建空的Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建 + createNWeb('about:blank', windowStage.getMainWindowSync().getUIContext()); + if (err.code) { + return; + } + }); + } + // [End entry_ability_window_stage_created_after_page_loaded] + + 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/UseOfflineWebComp/entry1/src/main/ets/pages/Index.ets b/UseOfflineWebComp/entry1/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ef124adf169069c2e98e8ddd3ca4de8efca7ad0e --- /dev/null +++ b/UseOfflineWebComp/entry1/src/main/ets/pages/Index.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 navigate_to_web_page_pre_start_webview_load] +import router from '@ohos.router'; +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct Index1 { + WebviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + //已经预启动Render进程 + Button($r('app.string.Jump_to_Web_Page')).onClick(()=>{ + router.pushUrl({url: 'pages/index2'}); + }) + .width('100%') + .height('100%') + } + } +} +// [End navigate_to_web_page_pre_start_webview_load] diff --git a/UseOfflineWebComp/entry1/src/main/ets/pages/common.ets b/UseOfflineWebComp/entry1/src/main/ets/pages/common.ets new file mode 100644 index 0000000000000000000000000000000000000000..8558a5a6e8c6864caa62c6bceea81adc405a18c5 --- /dev/null +++ b/UseOfflineWebComp/entry1/src/main/ets/pages/common.ets @@ -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. + */ +// [Start manage_dynamic_webview_components_in_harmonyos] +// 创建NodeController +import { UIContext, NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +// @Builder中为动态组件的具体组件内容 +// Data为入参封装类 +class Data{ + public url: ResourceStr = 'www.example.com'; + public controller: WebviewController = new webview.WebviewController(); +} + +@Builder +function webBuilder(data:Data) { + Column() { + Web({ src: data.url, controller: data.controller }) + .width('100%') + .height('100%') + } +} + +let wrap = wrapBuilder(webBuilder); + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private rootnode: BuilderNode | null = null; + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + console.log(' uicontext is undefined : '+ (uiContext === undefined)); + if (this.rootnode != null) { + // 返回FrameNode节点 + return this.rootnode.getFrameNode(); + } + // 返回null控制动态组件脱离绑定节点 + return null; + } + // 当布局大小发生变化时进行回调 + aboutToResize(size: Size) { + console.log('aboutToResize width : ' + size.width + ' height : ' + size.height ); + } + + // 当controller对应的NodeContainer在Appear的时候进行回调 + aboutToAppear() { + console.log('aboutToAppear'); + } + + // 当controller对应的NodeContainer在Disappear的时候进行回调 + aboutToDisappear() { + console.log('aboutToDisappear'); + } + + // 此函数为自定义函数,可作为初始化函数使用 + // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 + initWeb(url:ResourceStr, uiContext:UIContext, control:WebviewController) { + if (this.rootnode != null) { + return; + } + // 创建节点,需要uiContext + this.rootnode = new BuilderNode(uiContext); + // 创建动态Web组件 + this.rootnode.build(wrap, { url:url, controller:control }); + } +} +// 创建Map保存所需要的NodeController +let nodeMap:Map = new Map(); +// 创建Map保存所需要的WebViewController +let controllerMap:Map = new Map(); + +// 初始化需要UIContext 需在Ability获取 +export const createNWeb = (url: ResourceStr, uiContext: UIContext) => { + // 创建NodeController + let baseNode = new MyNodeController(); + let controller = new webview.WebviewController() ; + // 初始化自定义Web组件 + baseNode.initWeb(url, uiContext, controller); + controllerMap.set(url, controller); + nodeMap.set(url, baseNode); +} +// 自定义获取NodeController接口 +export const getNWeb = (url: ResourceStr) : MyNodeController | undefined => { + return nodeMap.get(url); +} +// [End manage_dynamic_webview_components_in_harmonyos] \ No newline at end of file diff --git a/UseOfflineWebComp/entry1/src/main/ets/pages/index2.ets b/UseOfflineWebComp/entry1/src/main/ets/pages/index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c80dbf9c00f8b7a9c70d1193941217aba28f9ce --- /dev/null +++ b/UseOfflineWebComp/entry1/src/main/ets/pages/index2.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 nodeContainer_bind_controller_show_dynamic_pages] +import web_webview from '@ohos.web.webview'; + +@Entry +@Component +struct index2 { + webviewController: web_webview.WebviewController = new web_webview.WebviewController(); + + build() { + Row() { + Column() { + Web({src: 'www.example.com', controller: this.webviewController}) + .width('100%') + .height('100%') + } + .width('100%') + } + .height('100%') + } +} +// [End nodeContainer_bind_controller_show_dynamic_pages] \ No newline at end of file diff --git a/UseOfflineWebComp/entry1/src/main/module.json5 b/UseOfflineWebComp/entry1/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5303c59d21b19cfd2c0a4299ec6ea72fede11eba --- /dev/null +++ b/UseOfflineWebComp/entry1/src/main/module.json5 @@ -0,0 +1,47 @@ +/* + * 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": "entry1", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry1Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry1Ability", + "srcEntry": "./ets/entry1ability/Entry1Ability.ets", + "description": "$string:Entry1Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry1Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry1/src/main/resources/base/element/color.json b/UseOfflineWebComp/entry1/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/src/main/resources/base/element/string.json b/UseOfflineWebComp/entry1/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..960a808fc630cd034b21abb768d02f81d14c73ef --- /dev/null +++ b/UseOfflineWebComp/entry1/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry1Ability_desc", + "value": "description" + }, + { + "name": "Entry1Ability_label", + "value": "UseOfflineWebComp" + }, + { + "name": "Jump_to_Web_Page", + "value": "跳转到Web页面" + } + ] +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry1/src/main/resources/base/media/background.png b/UseOfflineWebComp/entry1/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseOfflineWebComp/entry1/src/main/resources/base/media/background.png differ diff --git a/UseOfflineWebComp/entry1/src/main/resources/base/media/foreground.png b/UseOfflineWebComp/entry1/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseOfflineWebComp/entry1/src/main/resources/base/media/foreground.png differ diff --git a/UseOfflineWebComp/entry1/src/main/resources/base/media/layered_image.json b/UseOfflineWebComp/entry1/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/src/main/resources/base/media/startIcon.png b/UseOfflineWebComp/entry1/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseOfflineWebComp/entry1/src/main/resources/base/media/startIcon.png differ diff --git a/UseOfflineWebComp/entry1/src/main/resources/base/profile/main_pages.json b/UseOfflineWebComp/entry1/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..63fa709f03d48768274fa57cdbf8104fe61bd5f9 --- /dev/null +++ b/UseOfflineWebComp/entry1/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/Index", + "pages/index2" + ] +} diff --git a/UseOfflineWebComp/entry1/src/mock/mock-config.json5 b/UseOfflineWebComp/entry1/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/src/ohosTest/ets/test/Ability.test.ets b/UseOfflineWebComp/entry1/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d3cd767bfe6f45f85db6086893aaa58aaeae063 --- /dev/null +++ b/UseOfflineWebComp/entry1/src/ohosTest/ets/test/Ability.test.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. + */ + +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. + }) + + /* + * 打开应用 + * 预启动ArkWeb渲染进程 + */ + it('assertContain', 0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'Entry1Ability' + }; + 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('Entry1Ability'); + await driver.delayMs(3000); + + const button = await driver.findComponent(ON.type('Button')); + await button.click(); + await driver.delayMs(2000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('example.com'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry1/src/ohosTest/ets/test/List.test.ets b/UseOfflineWebComp/entry1/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/src/ohosTest/module.json5 b/UseOfflineWebComp/entry1/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a8392c11cf0dbecb4cdc78dc93d456a3a8e6ff41 --- /dev/null +++ b/UseOfflineWebComp/entry1/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": "entry1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/UseOfflineWebComp/entry1/src/test/List.test.ets b/UseOfflineWebComp/entry1/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry1/src/test/LocalUnit.test.ets b/UseOfflineWebComp/entry1/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/UseOfflineWebComp/entry1/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/UseOfflineWebComp/entry2/.gitignore b/UseOfflineWebComp/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseOfflineWebComp/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseOfflineWebComp/entry2/build-profile.json5 b/UseOfflineWebComp/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/hvigorfile.ts b/UseOfflineWebComp/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/obfuscation-rules.txt b/UseOfflineWebComp/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/oh-package.json5 b/UseOfflineWebComp/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/UseOfflineWebComp/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..1270a900ce0da82cfabf25a43b7ae5087891d0d1 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/src/main/ets/pages/Index.ets b/UseOfflineWebComp/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a532a9232bb28c1f37a3249fb941b8104bd0d0f --- /dev/null +++ b/UseOfflineWebComp/entry2/src/main/ets/pages/Index.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. + */ + +import router from '@ohos.router'; +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct Index1 { + WebviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + //已经预启动Render进程 + Button($r('app.string.Jump_to_Web_Page')).onClick(()=>{ + router.pushUrl({url: 'pages/index2'}) + }) + .width('100%') + .height('100%') + } + } +} diff --git a/UseOfflineWebComp/entry2/src/main/ets/pages/common.ets b/UseOfflineWebComp/entry2/src/main/ets/pages/common.ets new file mode 100644 index 0000000000000000000000000000000000000000..b29faae9562ed751fb690c70ece2bc2b3ae3db20 --- /dev/null +++ b/UseOfflineWebComp/entry2/src/main/ets/pages/common.ets @@ -0,0 +1,111 @@ +/* + * 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. + */ + +// 创建NodeController +// common.ets +import { UIContext } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; +import { NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; +// @Builder中为动态组件的具体组件内容 +// Data为入参封装类 +class Data{ + public url: string = 'www.example.com'; + public controller: WebviewController = new webview.WebviewController(); +} +// 通过布尔变量shouldInactive控制网页在后台完成预渲染后停止渲染 +let shouldInactive: boolean = true; +// [Start call_onActive_method_to_pre_render_offline_web_component] +@Builder +function webBuilder(data:Data) { + Column() { + Web({ src: data.url, controller: data.controller }) + .onPageBegin(() => { + // 调用onActive,开启渲染 + data.controller.onActive(); + }) + // [StartExclude call_onActive_method_to_pre_render_offline_web_component] + .onFirstMeaningfulPaint(() =>{ + if (!shouldInactive) { + return; + } + // 在预渲染完成时触发,停止渲染 + data.controller.onInactive(); + shouldInactive = false; + }) + // [EndExclude call_onActive_method_to_pre_render_offline_web_component] + .width('100%') + .height('100%') + } +} +// [End call_onActive_method_to_pre_render_offline_web_component] +let wrap = wrapBuilder(webBuilder); +// 用于控制和反馈对应的NodeContianer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private rootnode: BuilderNode | null = null; + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContianer中 + // 在对应NodeContianer创建的时候调用、或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + console.info(' uicontext is undifined : '+ (uiContext === undefined)); + if (this.rootnode != null) { + // 返回FrameNode节点 + return this.rootnode.getFrameNode(); + } + // 返回null控制动态组件脱离绑定节点 + return null; + } + // 当布局大小发生变化时进行回调 + aboutToResize(size: Size) { + console.info('aboutToResize width : ' + size.width + ' height : ' + size.height ); + } + // 当controller对应的NodeContainer在Appear的时候进行回调 + aboutToAppear() { + console.info('aboutToAppear'); + // 切换到前台后,不需要停止渲染 + shouldInactive = false; + } + // 当controller对应的NodeContainer在Disappear的时候进行回调 + aboutToDisappear() { + console.info('aboutToDisappear'); + } + // 此函数为自定义函数,可作为初始化函数使用 + // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 + initWeb(url:string, uiContext:UIContext, control:WebviewController) { + if (this.rootnode != null) { + return; + } + // 创建节点,需要uiContext + this.rootnode = new BuilderNode(uiContext); + // 创建动态Web组件 + this.rootnode.build(wrap, { url:url, controller:control }); + } +} +// 创建Map保存所需要的NodeController +let nodeMap:Map = new Map(); +// 创建Map保存所需要的WebViewController +let controllerMap:Map = new Map(); +// 初始化需要UIContext 需在Ability获取 +export const createNWeb = (url: string, uiContext: UIContext) => { + // 创建NodeController + let baseNode = new MyNodeController(); + let controller = new webview.WebviewController(); + // 初始化自定义Web组件 + baseNode.initWeb(url, uiContext, controller); + controllerMap.set(url, controller) + nodeMap.set(url, baseNode); +} +// 自定义获取NodeController接口 +export const getNWeb = (url : string) : MyNodeController | undefined => { + return nodeMap.get(url); +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry2/src/main/ets/pages/index2.ets b/UseOfflineWebComp/entry2/src/main/ets/pages/index2.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5f9d665b315b188741381099e468752bab5ba1c --- /dev/null +++ b/UseOfflineWebComp/entry2/src/main/ets/pages/index2.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 web_webview from '@ohos.web.webview'; + +@Entry +@Component +struct index2 { + webviewController: web_webview.WebviewController = new web_webview.WebviewController(); + + build() { + Row() { + Column() { + Web({src: 'www.example.com', controller: this.webviewController}) + .width('100%') + .height('100%') + } + .width('100%') + } + .height('100%') + } +} + diff --git a/UseOfflineWebComp/entry2/src/main/module.json5 b/UseOfflineWebComp/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1f8c3599ec920c0e4b97730586c364874d5cc009 --- /dev/null +++ b/UseOfflineWebComp/entry2/src/main/module.json5 @@ -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. + */ + +{ + "module": { + "name": "entry2", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "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 + } + ], + // [Start add_network_permission] + "requestPermissions":[ + { + "name" : "ohos.permission.INTERNET" + } + ], + // [End add_network_permission] + } +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry2/src/main/resources/base/element/color.json b/UseOfflineWebComp/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/src/main/resources/base/element/string.json b/UseOfflineWebComp/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..72a527550ed4128c0fbb2a2c8153a0866ba7d0bd --- /dev/null +++ b/UseOfflineWebComp/entry2/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Entry2Ability_desc", + "value": "description" + }, + { + "name": "Entry2Ability_label", + "value": "UseOfflineWebComp" + }, + { + "name": "Jump_to_Web_Page", + "value": "跳转到Web页面" + } + ] +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry2/src/main/resources/base/media/background.png b/UseOfflineWebComp/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseOfflineWebComp/entry2/src/main/resources/base/media/background.png differ diff --git a/UseOfflineWebComp/entry2/src/main/resources/base/media/foreground.png b/UseOfflineWebComp/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseOfflineWebComp/entry2/src/main/resources/base/media/foreground.png differ diff --git a/UseOfflineWebComp/entry2/src/main/resources/base/media/layered_image.json b/UseOfflineWebComp/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/src/main/resources/base/media/startIcon.png b/UseOfflineWebComp/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseOfflineWebComp/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/UseOfflineWebComp/entry2/src/main/resources/base/profile/main_pages.json b/UseOfflineWebComp/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..63fa709f03d48768274fa57cdbf8104fe61bd5f9 --- /dev/null +++ b/UseOfflineWebComp/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/Index", + "pages/index2" + ] +} diff --git a/UseOfflineWebComp/entry2/src/mock/mock-config.json5 b/UseOfflineWebComp/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/src/ohosTest/ets/test/Ability.test.ets b/UseOfflineWebComp/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c589f702da7464ab5afaa22b447d6aff089f6c96 --- /dev/null +++ b/UseOfflineWebComp/entry2/src/ohosTest/ets/test/Ability.test.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. + */ + +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. + }) + + /* + * 打开应用 + * 使用预渲染Web页面 + */ + it('TestUiExample', 0, async (done: Function) => { + console.info('uitest: TestUiExample 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(3000); + + const button1 = await driver.findComponent(ON.type('Button')); + 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: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/UseOfflineWebComp/entry2/src/ohosTest/ets/test/List.test.ets b/UseOfflineWebComp/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/src/ohosTest/module.json5 b/UseOfflineWebComp/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..031b54bde39f1b8ca1884b863026dbc91fd5a75a --- /dev/null +++ b/UseOfflineWebComp/entry2/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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/UseOfflineWebComp/entry2/src/test/List.test.ets b/UseOfflineWebComp/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/entry2/src/test/LocalUnit.test.ets b/UseOfflineWebComp/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/hvigor/hvigor-config.json5 b/UseOfflineWebComp/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/hvigorfile.ts b/UseOfflineWebComp/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/oh-package.json5 b/UseOfflineWebComp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/UseOfflineWebComp/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/UseOfflineWebComp/ohosTest.md b/UseOfflineWebComp/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..72c41bb53d749fbfb0eeaca36778383160483598 --- /dev/null +++ b/UseOfflineWebComp/ohosTest.md @@ -0,0 +1,18 @@ +#### Entry: CreatingOfflineWebComponents + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------- | ------------ | ------------ | ------------------------------------------------------- | -------- | -------- | +| 使用离线Web组件 | 设备运转正常 | 应用启动成功 | 页面能正常加载并显示,所显示的内容为离线 Web 组件的内容 | Yes | Pass | + +#### Entry1: PreLaunchingRenderingProcess_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | ----------------------------------- | ------------- | -------- | -------- | +| 预启动ArkWeb渲染进程 | 设备运转正常 | 应用启动成功,点击跳转到web页面按钮 | 跳转到Web页面 | Yes | Pass | + +#### Entry2: PreLaunchingRenderingProcess_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | ----------------------------------- | ------------- | -------- | -------- | +| 预启动ArkWeb渲染进程 | 设备运转正常 | 应用启动成功,点击跳转到web页面按钮 | 跳转到Web页面 | Yes | Pass | + diff --git a/UseOfflineWebComp/screenshots/CreatingOfflineWebComponents.png b/UseOfflineWebComp/screenshots/CreatingOfflineWebComponents.png new file mode 100644 index 0000000000000000000000000000000000000000..6e4d1cc737f0cbc14296825fc11ed29c15df8ffb Binary files /dev/null and b/UseOfflineWebComp/screenshots/CreatingOfflineWebComponents.png differ diff --git a/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_1.png b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_1.png new file mode 100644 index 0000000000000000000000000000000000000000..a47ecbbe2a4ec508900c94c85f89c3364a09a31d Binary files /dev/null and b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_1.png differ diff --git a/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_2.png b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_2.png new file mode 100644 index 0000000000000000000000000000000000000000..439cfa0e73fb2ec1a327bf7749fd97fca378f62d Binary files /dev/null and b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_2.png differ diff --git a/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_1.png b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_1.png new file mode 100644 index 0000000000000000000000000000000000000000..a47ecbbe2a4ec508900c94c85f89c3364a09a31d Binary files /dev/null and b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_1.png differ diff --git a/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_2.png b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_2.png new file mode 100644 index 0000000000000000000000000000000000000000..439cfa0e73fb2ec1a327bf7749fd97fca378f62d Binary files /dev/null and b/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_2.png differ diff --git a/UseSameLayerRender/.gitignore b/UseSameLayerRender/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/UseSameLayerRender/.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/UseSameLayerRender/AppScope/app.json5 b/UseSameLayerRender/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5b18054bf88655b05cb4d3f97880b8a465aaa700 --- /dev/null +++ b/UseSameLayerRender/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.usesamelayerrender", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/UseSameLayerRender/AppScope/resources/base/element/string.json b/UseSameLayerRender/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..030dffd09fc244d49ff44a13c13f61872c724578 --- /dev/null +++ b/UseSameLayerRender/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UseSameLayerRender" + } + ] +} diff --git a/UseSameLayerRender/AppScope/resources/base/media/app_icon.png b/UseSameLayerRender/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/UseSameLayerRender/AppScope/resources/base/media/app_icon.png differ diff --git a/UseSameLayerRender/README.md b/UseSameLayerRender/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c43c1814af513f528833175354c107f839072d11 --- /dev/null +++ b/UseSameLayerRender/README.md @@ -0,0 +1,108 @@ +# 同层渲染 + +### 介绍 + +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-same-layer.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +### RenderTxtBoxSameLayer_one + +#### 介绍 + +1. 本示例主要介绍Web页面中同层渲染输入框,在Web页面中,可以使用ArkUI原生的TextInput组件进行同层渲染。同层渲染支持/两种标签。type类型可任意指定,两个字符串参数均不区分大小写,ArkWeb内核将会统一转换为小写。其中,tag字符串使用全字符串匹配,type使用字符串前缀匹配。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 在应用侧通过enableNativeEmbedMode来开启同层渲染功能,展示在对应区域的原生组件。 +1. 调用onNativeEmbedLifecycleChange来监听同层渲染的生命周期变化。 +1. 调用onNativeEmbedGestureEvent来监听同层渲染同层渲染区域的手势事件。 + +### RenderTxtBoxSameLayer_two + +#### 介绍 + +1. 本示例主要介绍Web页面中同层渲染输入框,在Web页面中,可以使用ArkUI原生的TextInput组件进行同层渲染。同层渲染支持/两种标签。type类型可任意指定,两个字符串参数均不区分大小写,ArkWeb内核将会统一转换为小写。其中,tag字符串使用全字符串匹配,type使用字符串前缀匹配。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 在应用侧通过enableNativeEmbedMode来开启同层渲染功能,展示在对应区域的原生组件。 +1. 调用onNativeEmbedLifecycleChange来监听同层渲染的生命周期变化。 +1. 调用onNativeEmbedGestureEvent来监听同层渲染同层渲染区域的手势事件。 + +### DrawXCompAVPBtn + +#### 介绍 + +1. 本示例主要介绍同层渲染。通过enableNativeEmbedMode()控制同层渲染开关。Html文件中需要显式使用embed标签,并且embed标签内type必须以“native/”开头。同层标签对应的元素区域的背景为透明。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 绘制 XComponent、AVPlayer 和 Button 组件。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---DrawXCompAVPBtn.ets +|---|---|---Index.ets // 首页 +|---|---|---PlayerDemo.ets +|---|---|---RenderTxtBoxSameLayer_one.ets +|---|---|---RenderTxtBoxSameLayer_two.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 code/DocsSample/ArkWeb/UseSameLayerRender > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/UseSameLayerRender/build-profile.json5 b/UseSameLayerRender/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/code-linter.json5 b/UseSameLayerRender/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/.gitignore b/UseSameLayerRender/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UseSameLayerRender/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UseSameLayerRender/entry/build-profile.json5 b/UseSameLayerRender/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/hvigorfile.ts b/UseSameLayerRender/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/obfuscation-rules.txt b/UseSameLayerRender/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/oh-package.json5 b/UseSameLayerRender/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/main/ets/entryability/EntryAbility.ets b/UseSameLayerRender/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/UseSameLayerRender/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets b/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets new file mode 100644 index 0000000000000000000000000000000000000000..89604aae09899f587e68f765b39057adfa62f32e --- /dev/null +++ b/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets @@ -0,0 +1,216 @@ +/* + * 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 draw_x_component_av_player_button] +// 创建NodeController +import { webview } from '@kit.ArkWeb'; +import { UIContext, NodeController, BuilderNode, NodeRenderType, FrameNode } from '@kit.ArkUI'; +import { AVPlayerDemo } from './PlayerDemo'; + +@Observed +declare class Params { + public textOne : string + public textTwo : string + public width : number + public height : number +} + +declare class NodeControllerParams { + public surfaceId : string + public type : string + public renderType : NodeRenderType + public embedId : string + public width : number + public height : number +} + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用。 +class MyNodeController extends NodeController { + private rootNode: BuilderNode<[Params]> | undefined | null; + private embedId_ : string = ''; + private surfaceId_ : string = ''; + private renderType_ :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; + private width_ : number = 0; + private height_ : number = 0; + private type_ : string = ''; + private isDestroy_ : boolean = false; + + setRenderOption(params : NodeControllerParams) { + this.surfaceId_ = params.surfaceId; + this.renderType_ = params.renderType; + this.embedId_ = params.embedId; + this.width_ = params.width; + this.height_ = params.height; + this.type_ = params.type; + } + // 必须要重写的方法,用于构建节点数、返回节点数挂载在对应NodeContainer中。 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新。 + makeNode(uiContext: UIContext): FrameNode | null{ + if (this.isDestroy_) { // rootNode为null + return null; + } + if (!this.rootNode) { // rootNode 为undefined时 + this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_}); + if (this.type_ === 'native/video') { + this.rootNode.build( + wrapBuilder(videoBuilder), {textOne: 'myButton', width : this.width_, height : this.height_}); + } else { + // other + } + } + // 返回FrameNode节点。 + return this.rootNode.getFrameNode(); + } + + setBuilderNode(rootNode: BuilderNode | null): void{ + this.rootNode = rootNode; + } + + getBuilderNode(): BuilderNode<[Params]> | undefined | null{ + return this.rootNode; + } + + updateNode(arg: Object): void { + this.rootNode?.update(arg); + } + getEmbedId() : string { + return this.embedId_; + } + + setDestroy(isDestroy : boolean) : void { + this.isDestroy_ = isDestroy; + if (this.isDestroy_) { + this.rootNode = null; + } + } + + postEvent(event: TouchEvent | undefined) : boolean { + return this.rootNode?.postTouchEvent(event) as boolean; + } +} + +@Component +struct VideoComponent { + @ObjectLink params: Params; + @State bkColor: Color = Color.Red; + mXComponentController: XComponentController = new XComponentController(); + @State playerChanged: boolean = false; + player?: AVPlayerDemo; + + build() { + Column() { + Button(this.params.textOne); + + XComponent({ id: 'video_player_id', type: XComponentType.SURFACE, controller: this.mXComponentController}) + .border({width: 1, color: Color.Red}) + .onLoad(() => { + this.player = new AVPlayerDemo(); + this.player.setSurfaceID(this.mXComponentController.getXComponentSurfaceId()); + this.playerChanged = !this.playerChanged; + this.player.avPlayerLiveDemo(); + }) + .width(300) + .height(200) + } + //自定义组件中的最外层容器组件宽高应该为同层标签的宽高 + .width(this.params.width) + .height(this.params.height) + } +} +// @Builder中为动态组件的具体组件内容。 +@Builder +function videoBuilder(params: Params) { + VideoComponent({ params: params }) + .backgroundColor(Color.Gray) +} + +@Entry +@Component +struct WebIndex { + browserTabController: WebviewController = new webview.WebviewController() + private nodeControllerMap: Map = new Map(); + @State componentIdArr: Array = []; + + aboutToAppear() { + // 配置web开启调试模式。 + webview.WebviewController.setWebDebuggingAccess(true); + } + + build(){ + Row() { + Column() { + Stack() { + ForEach(this.componentIdArr, (componentId: string) => { + NodeContainer(this.nodeControllerMap.get(componentId)); + }, (embedId: string) => embedId) + // Web组件加载本地test.html页面。 + Web({ src: $rawfile('test3.html'), controller: this.browserTabController }) + // 配置同层渲染开关开启。 + .enableNativeEmbedMode(true) + // 获取embed标签的生命周期变化数据。 + .onNativeEmbedLifecycleChange((embed) => { + console.log('NativeEmbed surfaceId' + embed.surfaceId); + // 1. 如果使用embed.info.id作为映射nodeController的key,请在h5页面显式指定id + const componentId = embed.info?.id?.toString() as string + if (embed.status == NativeEmbedStatus.CREATE) { + console.log('NativeEmbed create' + JSON.stringify(embed.info)) + // 创建节点控制器,设置参数并rebuild。 + let nodeController = new MyNodeController() + // 1. embed.info.width和embed.info.height单位是px格式,需要转换成ets侧的默认单位vp + nodeController.setRenderOption({ + surfaceId : embed.surfaceId as string, type : embed.info?.type as string, + renderType : NodeRenderType.RENDER_TYPE_TEXTURE, embedId : embed.embedId as string, + width : px2vp(embed.info?.width), height : px2vp(embed.info?.height)}); + nodeController.setDestroy(false); + // 根据web传入的embed的id属性作为key,将nodeController存入map。 + this.nodeControllerMap.set(componentId, nodeController) + // 将web传入的embed的id属性存入@State状态数组变量中,用于动态创建nodeContainer节点容器,需要将push动作放在set之后。 + this.componentIdArr.push(componentId) + } else if (embed.status == NativeEmbedStatus.UPDATE) { + let nodeController = this.nodeControllerMap.get(componentId); + nodeController?.updateNode({ + textOne: 'update', width: px2vp(embed.info?.width), height: px2vp(embed.info?.height)} as ESObject); + } else { + let nodeController = this.nodeControllerMap.get(componentId); + nodeController?.setDestroy(true); + this.nodeControllerMap.clear(); + this.componentIdArr.length = 0; + } + })// 获取同层渲染组件触摸事件信息。 + .onNativeEmbedGestureEvent((touch) => { + console.log('NativeEmbed onNativeEmbedGestureEvent' + JSON.stringify(touch.touchEvent)); + this.componentIdArr.forEach((componentId: string) => { + let nodeController = this.nodeControllerMap.get(componentId) + // 将获取到的同层区域的事件发送到该区域embedId对应的nodeController上 + if (nodeController?.getEmbedId() === touch.embedId) { + let ret = nodeController?.postEvent(touch.touchEvent) + if (ret) { + console.log('onNativeEmbedGestureEvent success ' + componentId); + } else { + console.log('onNativeEmbedGestureEvent fail ' + componentId); + } + if (touch.result) { + // 通知Web组件手势事件消费结果 + touch.result.setGestureEventResult(ret); + } + } + }) + }) + } + } + } + } +} +// [End draw_x_component_av_player_button] diff --git a/UseSameLayerRender/entry/src/main/ets/pages/Index.ets b/UseSameLayerRender/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..be598b7d155a0ab9f72e9841e8736b663fd3ad67 --- /dev/null +++ b/UseSameLayerRender/entry/src/main/ets/pages/Index.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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('RenderTxtBoxSameLayer_one') + .onClick(() => { + router.pushUrl({ url: 'pages/RenderTxtBoxSameLayer_one' }); + }) + Button('RenderTxtBoxSameLayer_two') + .onClick(() => { + router.pushUrl({ url: 'pages/RenderTxtBoxSameLayer_two' }); + }) + Button('DrawXCompAVPBtn') + .onClick(() => { + router.pushUrl({ url: 'pages/DrawXCompAVPBtn' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets b/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets new file mode 100644 index 0000000000000000000000000000000000000000..4602bf074253a3183617acd4a3858759cda8f4af --- /dev/null +++ b/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets @@ -0,0 +1,103 @@ +/* + * 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 mp4_player_example] +import { media } from '@kit.MediaKit'; +import { BusinessError } from '@ohos.base'; + +export class AVPlayerDemo { + private count: number = 0; + private surfaceId: string = ''; // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接见上面Xcomponent创建方法。 + private isSeek: boolean = true; // 用于区分模式是否支持seek操作。 + + setSurfaceID(id: string){ + console.log('setSurfaceID : ' + id); + this.surfaceId = id; + } + // 注册avplayer回调函数。 + setAVPlayerCallback(avPlayer: media.AVPlayer) { + // seek操作结果回调函数。 + avPlayer.on('seekDone', (seekDoneTime: number) => { + console.info(`AVPlayer seek succeeded, seek time is ${seekDoneTime}`); + }) + // error回调监听函数,当avplayer在操作过程中出现错误时,调用reset接口触发重置流程。 + avPlayer.on('error', (err: BusinessError) => { + console.error(`Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`); + avPlayer.reset(); + }) + // 状态机变化回调函数。 + avPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => { + switch (state) { + case 'idle': // 成功调用reset接口后触发该状态机上报。 + console.info('AVPlayer state idle called.'); + avPlayer.release(); // 调用release接口销毁实例对象。 + break; + case 'initialized': // avplayer 设置播放源后触发该状态上报。 + console.info('AVPlayer state initialized called.'); + avPlayer.surfaceId = this.surfaceId; // 设置显示画面,当播放的资源为纯音频时无需设置。 + avPlayer.prepare(); + break; + case 'prepared': // prepared调用成功后上报该状态机。 + console.info('AVPlayer state prepared called.'); + avPlayer.play(); // 调用播放接口开始播放。 + break; + case 'playing': // play成功调用后触发该状态机上报。 + console.info('AVPlayer state prepared called.'); + if(this.count !== 0) { + if (this.isSeek) { + console.info('AVPlayer start to seek.'); + avPlayer.seek(avPlayer.duration); // seek到视频末尾。 + } else { + // 当播放模式不支持seek操作时继续播放到结尾。 + console.info('AVPlayer wait to play end.'); + } + } else { + avPlayer.pause(); // 调用暂停接口暂停播放。 + } + this.count++; + break; + case 'paused': // pause成功调用后触发该状态机上报。 + console.info('AVPlayer state paused called.'); + avPlayer.play(); // 再次播放接口开始播放。 + break; + case 'completed': //播放接口后触发该状态机上报。 + console.info('AVPlayer state paused called.'); + avPlayer.stop(); // 调用播放接口接口。 + break; + case 'stopped': // stop接口后触发该状态机上报。 + console.info('AVPlayer state stopped called.'); + avPlayer.reset(); // 调用reset接口初始化avplayer状态。 + break; + case 'released': //播放接口后触发该状态机上报。 + console.info('AVPlayer state released called.'); + break; + default: + break; + } + }) + } + + // 通过url设置网络地址来实现播放直播码流。 + async avPlayerLiveDemo(){ + // 创建avPlayer实例对象 + let avPlayer: media.AVPlayer = await media.createAVPlayer(); + // 创建状态机变化回调函数。 + this.setAVPlayerCallback(avPlayer); + this.isSeek = false; // 不支持seek操作。 + // 使用时需要自行替换视频链接 + avPlayer.url = 'xxx/demo.mp4'; + } +} +// [End mp4_player_example] diff --git a/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_one.ets b/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_one.ets new file mode 100644 index 0000000000000000000000000000000000000000..454fd7bc143928a672889793e231749429d8c30a --- /dev/null +++ b/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_one.ets @@ -0,0 +1,238 @@ +/* + * 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 webview from '@ohos.web.webview'; +import { UIContext } from '@ohos.arkui.UIContext'; +import { NodeController, BuilderNode, NodeRenderType, FrameNode } from '@ohos.arkui.node'; + +@Observed +declare class Params{ + public elementId: string + public textOne: string + public textTwo: string + public width: number + public height: number +} + +declare class NodeControllerParams { + public surfaceId: string + public type: string + public renderType: NodeRenderType + public embedId: string + public width: number + public height: number +} + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用。 +class MyNodeController extends NodeController { + private rootNode: BuilderNode<[Params]> | undefined | null; + private embedId_: string = ''; + private surfaceId_: string = ''; + private renderType_: NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; + private width_: number = 0; + private height_: number = 0; + private type_: string = ''; + private isDestroy_: boolean = false; + + setRenderOption(params: NodeControllerParams) { + this.surfaceId_ = params.surfaceId; + this.renderType_ = params.renderType; + this.embedId_ = params.embedId; + this.width_ = params.width; + this.height_ = params.height; + this.type_ = params.type; + } + + // 必须要重写的方法,用于构建节点数、返回节点数挂载在对应NodeContainer中。 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新。 + makeNode(uiContext: UIContext): FrameNode | null { + if (this.isDestroy_) { // rootNode为null + return null; + } + if (!this.rootNode) {// rootNode 为undefined时 + this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_ }); + if(this.rootNode) { + this.rootNode.build( + wrapBuilder(textInputBuilder), { textOne: 'myTextInput', width: this.width_, height: this.height_ }); + return this.rootNode.getFrameNode(); + }else{ + return null; + } + } + // 返回FrameNode节点。 + return this.rootNode.getFrameNode(); + } + + setBuilderNode(rootNode: BuilderNode | null): void { + this.rootNode = rootNode; + } + + getBuilderNode(): BuilderNode<[Params]> | undefined | null { + return this.rootNode; + } + + updateNode(arg: Object): void { + this.rootNode?.update(arg); + } + + getEmbedId(): string { + return this.embedId_; + } + + setDestroy(isDestroy: boolean): void { + this.isDestroy_ = isDestroy; + if (this.isDestroy_) { + this.rootNode = null; + } + } + + postEvent(event: TouchEvent | undefined): boolean { + return this.rootNode?.postTouchEvent(event) as boolean; + } +} + +@Component +struct TextInputComponent { + @Prop params: Params; + @State bkColor: Color = Color.White; + + build() { + Column() { + TextInput({text: '', placeholder: 'please input your word...'}) + .placeholderColor(Color.Gray) + .id(this.params?.elementId) + .placeholderFont({size: 13, weight: 400}) + .caretColor(Color.Gray) + .fontSize(14) + .fontColor(Color.Black) + } + //自定义组件中的最外层容器组件宽高应该为同层标签的宽高 + .width(this.params.width) + .height(this.params.height) + } +} + +// @Builder中为动态组件的具体组件内容。 +@Builder +function textInputBuilder(params:Params) { + TextInputComponent({params: params}) + .width(params.width) + .height(params.height) + .backgroundColor(Color.White) +} + +@Entry +@Component +struct Page{ + browserTabController: WebviewController = new webview.WebviewController(); + private nodeControllerMap: Map = new Map(); + @State componentIdArr: Array = []; + @State posMap: Map = new Map(); + @State widthMap: Map = new Map(); + @State heightMap: Map = new Map(); + @State positionMap: Map = new Map(); + @State edges: Edges = {}; + + build() { + Row() { + Column() { + Stack() { + ForEach(this.componentIdArr, (componentId: string) => { + NodeContainer(this.nodeControllerMap.get(componentId)) + .position(this.positionMap.get(componentId)) + .width(this.widthMap.get(componentId)) + .height(this.heightMap.get(componentId)) + }, (embedId: string) => embedId) + // Web组件加载本地test1.html页面。 + Web({src: $rawfile('test1.html'), controller: this.browserTabController}) + // 配置同层渲染开关开启。 + .enableNativeEmbedMode(true) + // 获取embed标签的生命周期变化数据。 + .onNativeEmbedLifecycleChange((embed) => { + console.log('NativeEmbed surfaceId' + embed.surfaceId); + // 如果使用embed.info.id作为映射nodeController的key,请在h5页面显式指定id + const componentId = embed.info?.id?.toString() as string; + if (embed.status == NativeEmbedStatus.CREATE) { + console.log('NativeEmbed create' + JSON.stringify(embed.info)); + // 创建节点控制器、设置参数并rebuild + let nodeController = new MyNodeController(); + // embed.info.width和embed.info.height单位是px格式,需要转换成ets侧的默认单位vp + nodeController.setRenderOption({surfaceId : embed.surfaceId as string, + type : embed.info?.type as string, + renderType : NodeRenderType.RENDER_TYPE_TEXTURE, + embedId : embed.embedId as string, + width : px2vp(embed.info?.width), + height : px2vp(embed.info?.height)}); + this.edges = { + left: `${embed.info?.position?.x as number}px`, + top: `${embed.info?.position?.y as number}px` + }; + nodeController.setDestroy(false); + //根据web传入的embed的id属性作为key,将nodeController存入Map + this.nodeControllerMap.set(componentId, nodeController); + this.widthMap.set(componentId, px2vp(embed.info?.width)); + this.heightMap.set(componentId, px2vp(embed.info?.height)); + this.positionMap.set(componentId, this.edges); + // 将web传入的embed的id属性存入@State状态数组变量中,用于动态创建nodeContainer节点容器,需要将push动作放在set之后 + this.componentIdArr.push(componentId); + } else if (embed.status == NativeEmbedStatus.UPDATE) { + let nodeController = this.nodeControllerMap.get(componentId); + console.log('NativeEmbed update' + JSON.stringify(embed)); + this.edges = { + left: `${embed.info?.position?.x as number}px`, + top: `${embed.info?.position?.y as number}px` + }; + this.positionMap.set(componentId, this.edges); + this.widthMap.set(componentId, px2vp(embed.info?.width)); + this.heightMap.set(componentId, px2vp(embed.info?.height)); + nodeController?.updateNode( + {textOne: 'update', width: px2vp(embed.info?.width), height: px2vp(embed.info?.height)} as ESObject); + } else if (embed.status == NativeEmbedStatus.DESTROY) { + console.log('NativeEmbed destroy' + JSON.stringify(embed)); + let nodeController = this.nodeControllerMap.get(componentId); + nodeController?.setDestroy(true); + this.nodeControllerMap.clear(); + this.positionMap.delete(componentId); + this.widthMap.delete(componentId); + this.heightMap.delete(componentId); + this.componentIdArr.filter((value: string) => value != componentId); + } else { + console.log('NativeEmbed status' + embed.status); + } + })// 获取同层渲染组件触摸事件信息。 + .onNativeEmbedGestureEvent((touch) => { + console.log('NativeEmbed onNativeEmbedGestureEvent' + JSON.stringify(touch.touchEvent)); + this.componentIdArr.forEach((componentId: string) => { + let nodeController = this.nodeControllerMap.get(componentId); + // 将获取到的同层区域的事件发送到该区域embedId对应的nodeController上 + if(nodeController?.getEmbedId() == touch.embedId) { + let ret = nodeController?.postEvent(touch.touchEvent); + if(ret) { + console.log('onNativeEmbedGestureEvent success ' + componentId); + } else { + console.log('onNativeEmbedGestureEvent fail ' + componentId); + } + if(touch.result) { + // 通知Web组件手势事件消费结果 + touch.result.setGestureEventResult(ret); + } + } + }) + }) + } + } + } + } +} diff --git a/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets b/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets new file mode 100644 index 0000000000000000000000000000000000000000..3423db539ced44ca6fa04f0e1dd5251b7009ce50 --- /dev/null +++ b/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets @@ -0,0 +1,257 @@ +/* + * 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_web_peer_render] +import webview from '@ohos.web.webview'; +import { UIContext } from '@ohos.arkui.UIContext'; +import { NodeController, BuilderNode, NodeRenderType, FrameNode } from '@ohos.arkui.node'; + +@Observed +declare class Params{ + public elementId: string + public textOne: string + public textTwo: string + public width: number + public height: number +} + +declare class NodeControllerParams { + public surfaceId: string + public type: string + public renderType: NodeRenderType + public embedId: string + public width: number + public height: number +} + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用。 +// [Start control_reflect_node_container] +class MyNodeController extends NodeController { + private rootNode: BuilderNode<[Params]> | undefined | null; + private embedId_: string = ''; + private surfaceId_: string = ''; + private renderType_: NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; + private width_: number = 0; + private height_: number = 0; + private type_: string = ''; + private isDestroy_: boolean = false; + + setRenderOption(params: NodeControllerParams) { + this.surfaceId_ = params.surfaceId; + this.renderType_ = params.renderType; + this.embedId_ = params.embedId; + this.width_ = params.width; + this.height_ = params.height; + this.type_ = params.type; + } + + // 必须要重写的方法,用于构建节点数、返回节点数挂载在对应NodeContainer中。 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新。 + makeNode(uiContext: UIContext): FrameNode | null { + if (this.isDestroy_) { // rootNode为null + return null; + } + if (!this.rootNode) {// rootNode 为undefined时 + this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_ }); + if(this.rootNode) { + this.rootNode.build( + wrapBuilder(textInputBuilder), { textOne: 'myTextInput', width: this.width_, height: this.height_ }); + return this.rootNode.getFrameNode(); + }else{ + return null; + } + } + // 返回FrameNode节点。 + return this.rootNode.getFrameNode(); + } + + setBuilderNode(rootNode: BuilderNode | null): void { + this.rootNode = rootNode; + } + + getBuilderNode(): BuilderNode<[Params]> | undefined | null { + return this.rootNode; + } + + updateNode(arg: Object): void { + this.rootNode?.update(arg); + } + + getEmbedId(): string { + return this.embedId_; + } + + setDestroy(isDestroy: boolean): void { + this.isDestroy_ = isDestroy; + if (this.isDestroy_) { + this.rootNode = null; + } + } + + postEvent(event: TouchEvent | undefined): boolean { + return this.rootNode?.postTouchEvent(event) as boolean; + } +} +// [End control_reflect_node_container] + +// [Start create_custom_module] +@Component +struct TextInputComponent { + @Prop params: Params; + @State bkColor: Color = Color.White; + + build() { + Column() { + TextInput({text: '', placeholder: 'please input your word...'}) + .placeholderColor(Color.Gray) + .id(this.params?.elementId) + .placeholderFont({size: 13, weight: 400}) + .caretColor(Color.Gray) + .fontSize(14) + .fontColor(Color.Black) + } + //自定义组件中的最外层容器组件宽高应该为同层标签的宽高 + .width(this.params.width) + .height(this.params.height) + } +} + +// @Builder中为动态组件的具体组件内容。 +@Builder +function textInputBuilder(params:Params) { + TextInputComponent({params: params}) + .width(params.width) + .height(params.height) + .backgroundColor(Color.White) +} +// [End create_custom_module] + +@Entry +@Component +struct Page{ + browserTabController: WebviewController = new webview.WebviewController() + private nodeControllerMap: Map = new Map(); + @State componentIdArr: Array = []; + @State posMap: Map = new Map(); + @State widthMap: Map = new Map(); + @State heightMap: Map = new Map(); + @State positionMap: Map = new Map(); + @State edges: Edges = {}; + + // [Start listen_peer_renders_life_cycle] + // [Start peer_renders_gesture_event] + build() { + Row() { + Column() { + Stack() { + ForEach(this.componentIdArr, (componentId: string) => { + NodeContainer(this.nodeControllerMap.get(componentId)) + .position(this.positionMap.get(componentId)) + .width(this.widthMap.get(componentId)) + .height(this.heightMap.get(componentId)) + }, (embedId: string) => embedId) + // Web组件加载本地test2.html页面。 + // [Start register_object_label] + Web({src: $rawfile('test2.html'), controller: this.browserTabController}) + // 注册同层标签为'object',类型为'test'前缀 + .registerNativeEmbedRule('object', 'test') + // [End register_object_label] + // 配置同层渲染开关开启。 + .enableNativeEmbedMode(true) + // 获取embed标签的生命周期变化数据。 + .onNativeEmbedLifecycleChange((embed) => { + // [StartExclude peer_renders_gesture_event] + console.log('NativeEmbed surfaceId' + embed.surfaceId); + // 如果使用embed.info.id作为映射nodeController的key,请在h5页面显式指定id + const componentId = embed.info?.id?.toString() as string; + if (embed.status == NativeEmbedStatus.CREATE) { + console.log('NativeEmbed create' + JSON.stringify(embed.info)); + // 创建节点控制器、设置参数并rebuild + let nodeController = new MyNodeController(); + // embed.info.width和embed.info.height单位是px格式,需要转换成ets侧的默认单位vp + nodeController.setRenderOption({surfaceId : embed.surfaceId as string, + type : embed.info?.type as string, + renderType : NodeRenderType.RENDER_TYPE_TEXTURE, + embedId : embed.embedId as string, + width : px2vp(embed.info?.width), + height : px2vp(embed.info?.height)}) + this.edges = { + left: `${embed.info?.position?.x as number}px`, + top: `${embed.info?.position?.y as number}px` + }; + nodeController.setDestroy(false); + //根据web传入的embed的id属性作为key,将nodeController存入Map + this.nodeControllerMap.set(componentId, nodeController); + this.widthMap.set(componentId, px2vp(embed.info?.width)); + this.heightMap.set(componentId, px2vp(embed.info?.height)); + this.positionMap.set(componentId, this.edges); + // 将web传入的embed的id属性存入@State状态数组变量中,用于动态创建nodeContainer节点容器,需要将push动作放在set之后 + this.componentIdArr.push(componentId); + } else if (embed.status == NativeEmbedStatus.UPDATE) { + let nodeController = this.nodeControllerMap.get(componentId); + console.log('NativeEmbed update' + JSON.stringify(embed)); + this.edges = { + left: `${embed.info?.position?.x as number}px`, + top: `${embed.info?.position?.y as number}px` + }; + this.positionMap.set(componentId, this.edges); + this.widthMap.set(componentId, px2vp(embed.info?.width)); + this.heightMap.set(componentId, px2vp(embed.info?.height)); + nodeController?.updateNode( + {textOne: 'update', width: px2vp(embed.info?.width), height: px2vp(embed.info?.height)} as ESObject); + } else if (embed.status == NativeEmbedStatus.DESTROY) { + console.log('NativeEmbed destroy' + JSON.stringify(embed)); + let nodeController = this.nodeControllerMap.get(componentId); + nodeController?.setDestroy(true); + this.nodeControllerMap.clear(); + this.positionMap.delete(componentId); + this.widthMap.delete(componentId); + this.heightMap.delete(componentId); + this.componentIdArr.filter((value: string) => value != componentId); + } else { + console.log('NativeEmbed status' + embed.status); + } + // [EndExclude peer_renders_gesture_event] + }) + // [StartExclude listen_peer_renders_life_cycle] + // 获取同层渲染组件触摸事件信息。 + .onNativeEmbedGestureEvent((touch) => { + console.log('NativeEmbed onNativeEmbedGestureEvent' + JSON.stringify(touch.touchEvent)); + this.componentIdArr.forEach((componentId: string) => { + let nodeController = this.nodeControllerMap.get(componentId); + // 将获取到的同层区域的事件发送到该区域embedId对应的nodeController上 + if(nodeController?.getEmbedId() == touch.embedId) { + let ret = nodeController?.postEvent(touch.touchEvent); + if(ret) { + console.log('onNativeEmbedGestureEvent success ' + componentId); + } else { + console.log('onNativeEmbedGestureEvent fail ' + componentId); + } + if(touch.result) { + // 通知Web组件手势事件消费结果 + touch.result.setGestureEventResult(ret); + } + } + }) + }) + // [EndExclude listen_peer_renders_life_cycle] + } + } + } + } + // [End peer_renders_gesture_event] + // [End listen_peer_renders_life_cycle] +} +// [End set_web_peer_render] diff --git a/UseSameLayerRender/entry/src/main/module.json5 b/UseSameLayerRender/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6596c6e68646da9acd1cde9626902cf5abf8f73c --- /dev/null +++ b/UseSameLayerRender/entry/src/main/module.json5 @@ -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. + */ + +{ + "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 request_permissions] + "requestPermissions":[ + { + "name" : "ohos.permission.INTERNET" + } + ], + // [End request_permissions] + + } +} \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/main/resources/base/element/color.json b/UseSameLayerRender/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/main/resources/base/element/string.json b/UseSameLayerRender/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..191baf03d76bbe473fc51c3ab758f67e1128b4a4 --- /dev/null +++ b/UseSameLayerRender/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": "UseSameLayerRender" + } + ] +} \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/main/resources/base/media/background.png b/UseSameLayerRender/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UseSameLayerRender/entry/src/main/resources/base/media/background.png differ diff --git a/UseSameLayerRender/entry/src/main/resources/base/media/foreground.png b/UseSameLayerRender/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UseSameLayerRender/entry/src/main/resources/base/media/foreground.png differ diff --git a/UseSameLayerRender/entry/src/main/resources/base/media/layered_image.json b/UseSameLayerRender/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/main/resources/base/media/startIcon.png b/UseSameLayerRender/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UseSameLayerRender/entry/src/main/resources/base/media/startIcon.png differ diff --git a/UseSameLayerRender/entry/src/main/resources/base/profile/backup_config.json b/UseSameLayerRender/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/UseSameLayerRender/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/main/resources/base/profile/main_pages.json b/UseSameLayerRender/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..e281fa6fca77c81593e512b2b51c38c762562be8 --- /dev/null +++ b/UseSameLayerRender/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/RenderTxtBoxSameLayer_one", + "pages/RenderTxtBoxSameLayer_two", + "pages/DrawXCompAVPBtn" + ] +} diff --git a/UseSameLayerRender/entry/src/main/resources/en_US/element/string.json b/UseSameLayerRender/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..191baf03d76bbe473fc51c3ab758f67e1128b4a4 --- /dev/null +++ b/UseSameLayerRender/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": "UseSameLayerRender" + } + ] +} \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/main/resources/rawfile/test1.html b/UseSameLayerRender/entry/src/main/resources/rawfile/test1.html new file mode 100644 index 0000000000000000000000000000000000000000..0417d261ed1318fd12c337cb4c18868d212c88b0 --- /dev/null +++ b/UseSameLayerRender/entry/src/main/resources/rawfile/test1.html @@ -0,0 +1,33 @@ + + + + + + + 同层渲染测试html + + + + + + + + + + + + + diff --git a/UseSameLayerRender/entry/src/main/resources/rawfile/test2.html b/UseSameLayerRender/entry/src/main/resources/rawfile/test2.html new file mode 100644 index 0000000000000000000000000000000000000000..a87df34562671a9c9c06b0cfe6161df49876b9ba --- /dev/null +++ b/UseSameLayerRender/entry/src/main/resources/rawfile/test2.html @@ -0,0 +1,33 @@ + + + + + + + 同层渲染测试html + + + + + + + + + + + + + diff --git a/UseSameLayerRender/entry/src/main/resources/rawfile/test3.html b/UseSameLayerRender/entry/src/main/resources/rawfile/test3.html new file mode 100644 index 0000000000000000000000000000000000000000..641bb291f12a36c0fbaa7b68519c974494be2082 --- /dev/null +++ b/UseSameLayerRender/entry/src/main/resources/rawfile/test3.html @@ -0,0 +1,29 @@ + + + + + + 同层渲染测试html + + + +
+
+ +
+
+ + \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/main/resources/zh_CN/element/string.json b/UseSameLayerRender/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..901c1ae3eee1b94fd8ea803333bd6b3e1d20ed2e --- /dev/null +++ b/UseSameLayerRender/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": "UseSameLayerRender" + } + ] +} \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/mock/mock-config.json5 b/UseSameLayerRender/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/ohosTest/ets/test/Ability.test.ets b/UseSameLayerRender/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e68c25cab9287b7a786446174025d3ee91471ef --- /dev/null +++ b/UseSameLayerRender/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,122 @@ +/* + * 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. + }) + + /* + * 打开应用,点击 RenderTxtBoxSameLayer_one 按钮 + * 采用标签同层渲染输入框 + */ + it('RenderTxtBoxSameLayer_one',0, async (done: Function) => { + console.info('uitest: RenderTxtBoxSameLayer_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(3000); + + const button1 = await driver.findComponent(ON.text('RenderTxtBoxSameLayer_one')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('test1.html'); + + await driver.pressBack(); + console.info('uitest: RenderTxtBoxSameLayer_one end'); + done(); + }); + + /* + * 点击 RenderTxtBoxSameLayer_two 按钮 + * 采用标签同层渲染输入框 + */ + it('RenderTxtBoxSameLayer_two', 0, async (done: Function) => { + console.info('uitest: RenderTxtBoxSameLayer_two begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('RenderTxtBoxSameLayer_two')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('test2.html'); + + await driver.pressBack(); + console.info('uitest: RenderTxtBoxSameLayer_two end'); + done(); + }); + + /* + * 点击 DrawXCompAVPBtn 按钮 + * 通过 enableNativeEmbedMode 控制同层渲染开关,显式使用embed标签 + */ + it('DrawXCompAVPBtn', 0, async (done: Function) => { + console.info('uitest: DrawXCompAVPBtn begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('DrawXCompAVPBtn')); + 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('test3.html'); + + console.info('uitest: DrawXCompAVPBtn end'); + done(); + }); + }) +} \ No newline at end of file diff --git a/UseSameLayerRender/entry/src/ohosTest/ets/test/List.test.ets b/UseSameLayerRender/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/ohosTest/module.json5 b/UseSameLayerRender/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/test/List.test.ets b/UseSameLayerRender/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/entry/src/test/LocalUnit.test.ets b/UseSameLayerRender/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/hvigor/hvigor-config.json5 b/UseSameLayerRender/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/hvigorfile.ts b/UseSameLayerRender/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/oh-package.json5 b/UseSameLayerRender/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/UseSameLayerRender/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/UseSameLayerRender/ohosTest.md b/UseSameLayerRender/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..31d7c5f6a59c0f772bdf8e3d14f0cd59ce150218 --- /dev/null +++ b/UseSameLayerRender/ohosTest.md @@ -0,0 +1,18 @@ +#### RenderTxtBoxSameLayer_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ------------ | --------------------------------------- | -------- | -------- | +| 同层渲染 | 设备运转正常 | 应用启动成功 | 利用同层渲染展示三个标签的输入框 | Yes | Pass | + +#### RenderTxtBoxSameLayer_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ------------ | ---------------------------------------- | -------- | -------- | +| 同层渲染 | 设备运转正常 | 应用启动成功 | 利用同层渲染展示三个标签的输入框 | Yes | Pass | + +#### DrawXCompAVPBtn + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ------------ | ---------------------------------------- | -------- | -------- | +| 同层渲染 | 设备运转正常 | 应用启动成功 | 绘制 XComponent、AVPlayer 和 Button 组件 | Yes | Pass | + diff --git a/UseSameLayerRender/screenshots/DrawXCompAVPBtn.png b/UseSameLayerRender/screenshots/DrawXCompAVPBtn.png new file mode 100644 index 0000000000000000000000000000000000000000..1f07c365c79f7796ffa17005c987de9bfe2b23e1 Binary files /dev/null and b/UseSameLayerRender/screenshots/DrawXCompAVPBtn.png differ diff --git a/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_one.png b/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_one.png new file mode 100644 index 0000000000000000000000000000000000000000..7a693b9b79b8269a3654f2d175c5f9b9d53c6922 Binary files /dev/null and b/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_one.png differ diff --git a/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_two.png b/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_two.png new file mode 100644 index 0000000000000000000000000000000000000000..986d1c0de0236ef3aa64e54f168dfab147800f2e Binary files /dev/null and b/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_two.png differ diff --git a/UsingWebMultimedia/.gitignore b/UsingWebMultimedia/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/UsingWebMultimedia/.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/UsingWebMultimedia/AppScope/app.json5 b/UsingWebMultimedia/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed067223abed18cf6afb0dc022c9555edc5e3324 --- /dev/null +++ b/UsingWebMultimedia/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.usingwebmultimedia", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/UsingWebMultimedia/AppScope/resources/base/element/string.json b/UsingWebMultimedia/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..201e95512e21670a1e1919950431b844e7376f2d --- /dev/null +++ b/UsingWebMultimedia/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UsingWebMultimedia" + } + ] +} diff --git a/UsingWebMultimedia/AppScope/resources/base/media/app_icon.png b/UsingWebMultimedia/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/UsingWebMultimedia/AppScope/resources/base/media/app_icon.png differ diff --git a/UsingWebMultimedia/README.md b/UsingWebMultimedia/README.md new file mode 100644 index 0000000000000000000000000000000000000000..54ecebee6c337a69c1f193c2245b6a97929332c7 --- /dev/null +++ b/UsingWebMultimedia/README.md @@ -0,0 +1,150 @@ +# entry: + +### 使用WebRTC进行Web视频会议 + +#### 介绍 + +1. 本示例主要介绍使用WebRTC进行Web视频会议,Web组件可以通过W3C标准协议接口拉起摄像头和麦克风,通过onPermissionRequest接口接收权限请求通知,需在配置文件中声明相应的音频权限。 +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-rtc.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### 效果预览 + +| 主页 | 权限请求 | 摄像头 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | | + +使用说明 + +1. 点击前端页面中的开起摄像头按钮再点击onConfirm,打开摄像头和麦克风。 + +#### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + +#### 相关权限 + +[ohos.permission.CAMERA](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioncamera) + +[ohos.permission.MICROPHONE](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmicrophone) + +# entry2: + +### 托管网页中的媒体播放 + +#### 介绍 + +1. 本示例主要介绍托管网页中的媒体播放。通过enableNativeMediaPlayer接口,开启接管网页媒体播放的功能,用来支持应用增强网页的媒体播放,如画质增强等。 +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/app-takeovers-web-media.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 使用时需要自行替换前端页面视频链接。 +1. 点击play播放,点击pause暂停播放。 + +#### 工程目录 + +``` +entry2/src/main/ +|---ets +|---|---entry2ability +|---|---|---Entry2Ability.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---PlayerDemo.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) + +# entry3: + +### Web组件支持画中画 + +#### 介绍 + +1. 本示例主要介绍Web画中画。借助Picture-in-Picture Web API,在网页上拉起一个浮动窗口播放视频,以便用户在浏览器其他网页或者与其他应用交互时通过画中画窗口继续观看视频。 +2. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-picture-in-picture.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### 效果预览 + +| 主页 | +|---------------------------------------------------------------| +| | + +使用说明 + +1. 使用时需要自行替换前端页面视频链接。 +2. 点击开启画中画按钮,进入画中画播放模式,在画中画模式时点击退出画中画,恢复原页面播放。 +3. 点击画中画窗口,可以显示控制层控件,支持播放、暂停、前进、后退;双击画中画窗口支持放大或缩小窗口。 + +#### 工程目录 + +``` +entry3/src/main/ +|---ets +|---|---entry3ability +|---|---|---Entry3Ability.ets +|---|---pages +|---|---|---Index.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 code/DocsSample/ArkWeb/UsingWebMultimedia > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/UsingWebMultimedia/build-profile.json5 b/UsingWebMultimedia/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c5d90d7e6c7621e07d4f59d1051f83f9f478d8aa --- /dev/null +++ b/UsingWebMultimedia/build-profile.json5 @@ -0,0 +1,75 @@ +/* +* 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" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UsingWebMultimedia/code-linter.json5 b/UsingWebMultimedia/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/.gitignore b/UsingWebMultimedia/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UsingWebMultimedia/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UsingWebMultimedia/entry/build-profile.json5 b/UsingWebMultimedia/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/hvigorfile.ts b/UsingWebMultimedia/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/obfuscation-rules.txt b/UsingWebMultimedia/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/oh-package.json5 b/UsingWebMultimedia/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/src/main/ets/entryability/EntryAbility.ets b/UsingWebMultimedia/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..7582e04e8680aeb0224bcd7a2b42ed6932f80f29 --- /dev/null +++ b/UsingWebMultimedia/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,59 @@ +/* + * 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'; + +const ARK_WEB_MEDIA_LOG_INFO = 0x0000; +const ARK_WEB_MEDIA_LOG_ERROR = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(ARK_WEB_MEDIA_LOG_ERROR, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/UsingWebMultimedia/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/UsingWebMultimedia/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..07890bf5a1996166c52502ac9b991ea114aa918d --- /dev/null +++ b/UsingWebMultimedia/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,29 @@ +/* + * 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'; + +const ARK_WEB_MEDIA_LOG_INFO = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/main/ets/pages/Index.ets b/UsingWebMultimedia/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b45e3d66fd7b5dde9c59b5a4ed3d769871ef8aa1 --- /dev/null +++ b/UsingWebMultimedia/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,69 @@ +/* + * 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 click_button_to_turn_on_camera_microphone] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { abilityAccessCtrl } from '@kit.AbilityKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + aboutToAppear() { + // 配置Web开启调试模式 + webview.WebviewController.setWebDebuggingAccess(true); + let atManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(getContext(this), ['ohos.permission.CAMERA', 'ohos.permission.MICROPHONE']) + .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}`); + }) + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + // 获取权限请求通知,点击onConfirm按钮后,拉起摄像头和麦克风。 + .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()); + } + }, + cancel: () => { + event.request.deny(); + } + }) + } + }) + } + } +} +// [End click_button_to_turn_on_camera_microphone] \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/main/module.json5 b/UsingWebMultimedia/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..54af2946ce321bd54d9423e8d3bd4543005f8dcc --- /dev/null +++ b/UsingWebMultimedia/entry/src/main/module.json5 @@ -0,0 +1,110 @@ +/* + * 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.CAMERA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + }, + { + "name" : "ohos.permission.MICROPHONE", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + } + ], + "requestPermissions": [ + { + "name" : "ohos.permission.CAMERA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + }, + { + "name" : "ohos.permission.MICROPHONE", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + }, + { + "name": "ohos.permission.INTERNET" + } + ] + + } +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/main/resources/base/element/color.json b/UsingWebMultimedia/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/src/main/resources/base/element/string.json b/UsingWebMultimedia/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5b2c6b7ddaf83f48cd8bfe687f3c975591593729 --- /dev/null +++ b/UsingWebMultimedia/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": "UsingWebMultimedia" + } + ] +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/main/resources/base/media/background.png b/UsingWebMultimedia/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UsingWebMultimedia/entry/src/main/resources/base/media/background.png differ diff --git a/UsingWebMultimedia/entry/src/main/resources/base/media/foreground.png b/UsingWebMultimedia/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UsingWebMultimedia/entry/src/main/resources/base/media/foreground.png differ diff --git a/UsingWebMultimedia/entry/src/main/resources/base/media/layered_image.json b/UsingWebMultimedia/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/src/main/resources/base/media/startIcon.png b/UsingWebMultimedia/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UsingWebMultimedia/entry/src/main/resources/base/media/startIcon.png differ diff --git a/UsingWebMultimedia/entry/src/main/resources/base/profile/backup_config.json b/UsingWebMultimedia/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/UsingWebMultimedia/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/main/resources/base/profile/main_pages.json b/UsingWebMultimedia/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UsingWebMultimedia/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UsingWebMultimedia/entry/src/main/resources/en_US/element/string.json b/UsingWebMultimedia/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5b2c6b7ddaf83f48cd8bfe687f3c975591593729 --- /dev/null +++ b/UsingWebMultimedia/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": "UsingWebMultimedia" + } + ] +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/main/resources/rawfile/index.html b/UsingWebMultimedia/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..9464d7b99d8a7202b56532f5a6fcd338b67ce151 --- /dev/null +++ b/UsingWebMultimedia/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,45 @@ + + + + + + + + + + +
+ + + + diff --git a/UsingWebMultimedia/entry/src/main/resources/zh_CN/element/string.json b/UsingWebMultimedia/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ba500fcf3b2babf9e8107ce001ae118ef87dc23b --- /dev/null +++ b/UsingWebMultimedia/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": "UsingWebMultimedia" + } + ] +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/mock/mock-config.json5 b/UsingWebMultimedia/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/src/ohosTest/ets/test/Ability.test.ets b/UsingWebMultimedia/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..96081385b8af436ee7672fd419f1d9bc80d5edc8 --- /dev/null +++ b/UsingWebMultimedia/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. + }) + + /* + * 打开应用 + * 通过W3C标准协议接口拉起摄像头和麦克风 + */ + 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(3000); + + const button1 = await driver.findComponent(ON.text('允许')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('允许')); + await button2.click(); + await driver.delayMs(1000); + + const button3 = await driver.findComponent(ON.type('button')); + await button3.click(); + await driver.delayMs(3000); + + const size = await driver.getDisplaySize(); + await driver.click(size.x / 2 + 50, size.y / 2 + 50); + await driver.delayMs(3000); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry/src/ohosTest/ets/test/List.test.ets b/UsingWebMultimedia/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/src/ohosTest/module.json5 b/UsingWebMultimedia/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/src/test/List.test.ets b/UsingWebMultimedia/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry/src/test/LocalUnit.test.ets b/UsingWebMultimedia/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/.gitignore b/UsingWebMultimedia/entry2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UsingWebMultimedia/entry2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UsingWebMultimedia/entry2/build-profile.json5 b/UsingWebMultimedia/entry2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9edfdf8c4a72db3313433e7366df25b6beb1c3a7 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/hvigorfile.ts b/UsingWebMultimedia/entry2/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/obfuscation-rules.txt b/UsingWebMultimedia/entry2/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/oh-package.json5 b/UsingWebMultimedia/entry2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2944307304532e967f4956384cc91447f2c9bf8c --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/UsingWebMultimedia/entry2/src/main/ets/entry2ability/Entry2Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..d1bd537608caacae6ca2c6ce6239b6edc4468462 --- /dev/null +++ b/UsingWebMultimedia/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -0,0 +1,57 @@ +/* + * 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 { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +// [Start allow_subsequent_rendering_to_use_ui] +import { window } from '@kit.ArkUI'; + +export default class Entry2Ability extends UIAbility { + // [StartExclude allow_subsequent_rendering_to_use_ui] + 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'); + } + // [EndExclude allow_subsequent_rendering_to_use_ui] + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + return; + } + // 保存 UIContext, 在后续的同层渲染绘制中会用到。 + AppStorage.setOrCreate('UIContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + // [StartExclude allow_subsequent_rendering_to_use_ui] + 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'); + } + // [EndExclude allow_subsequent_rendering_to_use_ui] +} +// [End allow_subsequent_rendering_to_use_ui] \ No newline at end of file diff --git a/UsingWebMultimedia/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/UsingWebMultimedia/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9a6b459004e1f1d0aefe9350f2c2ee907f66ff3 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/main/ets/pages/Index.ets b/UsingWebMultimedia/entry2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..778738e0706c4c442912054d962bba8ed41935cb --- /dev/null +++ b/UsingWebMultimedia/entry2/src/main/ets/pages/Index.ets @@ -0,0 +1,468 @@ +/* + * 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 video_hosting_usage] +import { webview } from '@kit.ArkWeb'; +import { BuilderNode, FrameNode, NodeController, NodeRenderType, UIContext } from '@kit.ArkUI'; +import { AVPlayerDemo, AVPlayerListener } from './PlayerDemo'; + +// 实现 webview.NativeMediaPlayerBridge 接口。 +// ArkWeb 内核调用该类的方法来对 NativeMediaPlayer 进行播控。 +class NativeMediaPlayerImpl implements webview.NativeMediaPlayerBridge { + private surfaceId: string; + mediaSource: string; + private mediaHandler: webview.NativeMediaPlayerHandler; + nativePlayerInfo: NativePlayerInfo; + nativePlayer: AVPlayerDemo; + httpHeaders: Record; + + constructor( + nativePlayerInfo: NativePlayerInfo, handler: webview.NativeMediaPlayerHandler, mediaInfo: webview.MediaInfo) { + console.log(`NativeMediaPlayerImpl.constructor, surface_id[${mediaInfo.surfaceInfo.id}]`); + this.nativePlayerInfo = nativePlayerInfo; + this.mediaHandler = handler; + this.surfaceId = mediaInfo.surfaceInfo.id; + this.mediaSource = mediaInfo.mediaSrcList.find((item)=>{ + item.source.indexOf('.mp4') > 0 + })?.source || mediaInfo.mediaSrcList[0].source; + this.httpHeaders = mediaInfo.headers; + this.nativePlayer = new AVPlayerDemo(); + + // 使用同层渲染功能,将视频及其播控组件绘制到网页中 + this.nativePlayerInfo.nodeController = new MyNodeController( + this.nativePlayerInfo, this.surfaceId, this.mediaHandler, this, NodeRenderType.RENDER_TYPE_TEXTURE); + this.nativePlayerInfo.nodeController.build(); + this.nativePlayerInfo.showNativeMediaPlayer = true; + + console.log( + `NativeMediaPlayerImpl.mediaSource: ${this.mediaSource}, headers: ${JSON.stringify(this.httpHeaders)}`); + } + + updateRect(x: number, y: number, width: number, height: number): void { + let widthInVp = px2vp(width); + let heightInVp = px2vp(height); + console.log(`updateRect(${x}, ${y}, ${width}, ${height}), vp:{${widthInVp}, ${heightInVp}}`); + this.nativePlayerInfo.updateNativePlayerRect(x, y, width, height); + } + + play() { + console.log('NativeMediaPlayerImpl.play'); + this.nativePlayer.play(); + } + pause() { + console.log('NativeMediaPlayerImpl.pause'); + this.nativePlayer.pause(); + } + seek(targetTime: number) { + console.log(`NativeMediaPlayerImpl.seek(${targetTime})`); + this.nativePlayer.seek(targetTime); + } + setVolume(volume: number) { + console.log(`NativeMediaPlayerImpl.setVolume(${volume})`); + this.nativePlayer.setVolume(volume); + } + setMuted(muted: boolean) { + console.log(`NativeMediaPlayerImpl.setMuted(${muted})`); + } + setPlaybackRate(playbackRate: number) { + console.log(`NativeMediaPlayerImpl.setPlaybackRate(${playbackRate})`); + this.nativePlayer.setPlaybackRate(playbackRate); + } + release() { + console.log('NativeMediaPlayerImpl.release'); + this.nativePlayer?.release(); + this.nativePlayerInfo.showNativeMediaPlayer = false; + this.nativePlayerInfo.nodeWidth = 300; + this.nativePlayerInfo.nodeHeight = 150; + this.nativePlayerInfo.destroyed(); + } + enterFullscreen() { + console.log('NativeMediaPlayerImpl.enterFullscreen'); + } + exitFullscreen() { + console.log('NativeMediaPlayerImpl.exitFullscreen'); + } +} + +// 监听NativeMediaPlayer的状态,然后通过 webview.NativeMediaPlayerHandler 将状态上报给 ArkWeb 内核。 +class AVPlayerListenerImpl implements AVPlayerListener { + handler: webview.NativeMediaPlayerHandler; + component: NativePlayerComponent; + + constructor(handler: webview.NativeMediaPlayerHandler, component: NativePlayerComponent) { + this.handler = handler; + this.component = component; + } + onPlaying() { + console.log('AVPlayerListenerImpl.onPlaying'); + this.handler.handleStatusChanged(webview.PlaybackStatus.PLAYING); + } + onPaused() { + console.log('AVPlayerListenerImpl.onPaused'); + this.handler.handleStatusChanged(webview.PlaybackStatus.PAUSED); + } + onDurationChanged(duration: number) { + console.log(`AVPlayerListenerImpl.onDurationChanged(${duration})`); + this.handler.handleDurationChanged(duration); + } + onBufferedTimeChanged(buffered: number) { + console.log(`AVPlayerListenerImpl.onBufferedTimeChanged(${buffered})`); + this.handler.handleBufferedEndTimeChanged(buffered); + } + onTimeUpdate(time: number) { + this.handler.handleTimeUpdate(time); + } + onEnded() { + console.log('AVPlayerListenerImpl.onEnded'); + this.handler.handleEnded(); + } + onError() { + console.log('AVPlayerListenerImpl.onError'); + this.component.has_error = true; + setTimeout(()=>{ + this.handler.handleError(1, 'Oops!'); + }, 200); + } + onVideoSizeChanged(width: number, height: number) { + console.log(`AVPlayerListenerImpl.onVideoSizeChanged(${width}, ${height})`); + this.handler.handleVideoSizeChanged(width, height); + this.component.onSizeChanged(width, height); + } + onDestroyed(): void { + console.log('AVPlayerListenerImpl.onDestroyed'); + } +} + +interface ComponentParams { + text: string; + text2: string; + playerInfo: NativePlayerInfo; + handler: webview.NativeMediaPlayerHandler; + player: NativeMediaPlayerImpl; +} + +// 自定义的播放器组件 +@Component +struct NativePlayerComponent { + params?: ComponentParams; + @State bgColor: Color = Color.Red; + mXComponentController: XComponentController = new XComponentController(); + + videoController: VideoController = new VideoController(); + offsetX: number = 0; + offsetY: number = 0; + @State videoWidthPercent: number = 100; + @State videoHeightPercent: number = 100; + viewWidth: number = 0; + viewHeight: number = 0; + videoWidth: number = 0; + videoHeight: number = 0; + + fullscreen: boolean = false; + @State has_error: boolean = false; + + onSizeChanged(width: number, height: number) { + this.videoWidth = width; + this.videoHeight = height; + let scale: number = this.viewWidth / width; + let scaledVideoHeight: number = scale * height; + this.videoHeightPercent = scaledVideoHeight / this.viewHeight * 100; + console.log( + `NativePlayerComponent.onSizeChanged(${width},${height}), videoHeightPercent[${this.videoHeightPercent }]`); + } + + build() { + Column() { + Stack() { + XComponent({ id: 'video_player_id', type: XComponentType.SURFACE, controller: this.mXComponentController }) + .width(this.videoWidthPercent + '%') + .height(this.videoHeightPercent + '%') + .onLoad(()=>{ + if (!this.params) { + console.log('this.params is null'); + return; + } + console.log('NativePlayerComponent.onLoad, params[' + this.params + + '], text[' + this.params.text + '], text2[' + this.params.text2 + + '], web_tab[' + this.params.playerInfo + '], handler[' + this.params.handler + ']'); + this.params.player.nativePlayer.setSurfaceID(this.mXComponentController.getXComponentSurfaceId()); + + this.params.player.nativePlayer.avPlayerLiveDemo({ + url: this.params.player.mediaSource, + listener: new AVPlayerListenerImpl(this.params.handler, this), + httpHeaders: this.params.player.httpHeaders, + }); + }) + Column() { + Row() { + Button(this.params?.text) + .height(50) + .border({ width: 2, color: Color.Red }) + .backgroundColor(this.bgColor) + .onClick(()=>{ + console.log(`NativePlayerComponent.Button[${this.params?.text}] is clicked`); + this.params?.player.nativePlayer?.play(); + }) + .onTouch((event: TouchEvent) => { + event.stopPropagation(); + }) + Button(this.params?.text2) + .height(50) + .border({ width: 2, color: Color.Red }) + .onClick(()=>{ + console.log(`NativePlayerComponent.Button[${this.params?.text2}] is clicked`); + this.params?.player.nativePlayer?.pause(); + }) + .onTouch((event: TouchEvent) => { + event.stopPropagation(); + }) + } + .width('100%') + .justifyContent(FlexAlign.SpaceEvenly) + } + if (this.has_error) { + Column() { + Text('Error') + .fontSize(30) + } + .backgroundColor('#eb5555') + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } + } + } + .width('100%') + .height('100%') + .onAreaChange((oldValue: Area, newValue: Area) => { + console.log(`NativePlayerComponent.onAreaChange(${JSON.stringify(oldValue)}, ${JSON.stringify(newValue)})`); + this.viewWidth = parseFloat(newValue.width.toString()); + this.viewHeight = parseFloat(newValue.height.toString()); + this.onSizeChanged(this.videoWidth, this.videoHeight); + }) + } +} + +@Builder +function nativePlayerComponentBuilder(params: ComponentParams) { + NativePlayerComponent({ params: params }) + .backgroundColor(Color.Green) + .border({ width: 1, color: Color.Brown }) + .width('100%') + .height('100%') +} + +// 通过 NodeController 来动态创建自定义的播放器组件, 并将组件内容绘制到 surfaceId 指定的 surface 上。 +class MyNodeController extends NodeController { + private rootNode: BuilderNode<[ComponentParams]> | undefined; + playerInfo: NativePlayerInfo; + listener: webview.NativeMediaPlayerHandler; + player: NativeMediaPlayerImpl; + + constructor(playerInfo: NativePlayerInfo, + surfaceId: string, + listener: webview.NativeMediaPlayerHandler, + player: NativeMediaPlayerImpl, + renderType: NodeRenderType) { + super(); + this.playerInfo = playerInfo; + this.listener = listener; + this.player = player; + let uiContext = AppStorage.get('UIContext'); + this.rootNode = new BuilderNode(uiContext as UIContext, { surfaceId: surfaceId, type: renderType }); + console.log( + `MyNodeController, + rootNode[${this.rootNode}], + playerInfo[${playerInfo}], + listener[${listener}], + surfaceId[${surfaceId}]`); + } + + makeNode(): FrameNode | null { + if (this.rootNode) { + return this.rootNode.getFrameNode() as FrameNode; + } + return null; + } + + build() { + let params: ComponentParams = { + 'text': 'play', + 'text2': 'pause', + playerInfo: this.playerInfo, + handler: this.listener, + player: this.player + }; + if (this.rootNode) { + this.rootNode.build(wrapBuilder(nativePlayerComponentBuilder), params); + } + } + + postTouchEvent(event: TouchEvent) { + return this.rootNode?.postTouchEvent(event); + } +} + +class Rect { + x: number = 0; + y: number = 0; + width: number = 0; + height: number = 0; + + static toNodeRect(rectInPx: webview.RectEvent) : Rect { + let rect = new Rect(); + rect.x = px2vp(rectInPx.x); + rect.y = px2vp(rectInPx.x); + rect.width = px2vp(rectInPx.width); + rect.height = px2vp(rectInPx.height); + return rect; + } +} + +@Observed +class NativePlayerInfo { + public web: WebComponent; + public embedId: string; + public player: webview.NativeMediaPlayerBridge; + public nodeController?: MyNodeController; + public showNativeMediaPlayer: boolean = false; + public nodePosX: number; + public nodePosY: number; + public nodeWidth: number; + public nodeHeight: number; + + playerComponent?: NativeMediaPlayerComponent; + + constructor(web: WebComponent, handler: webview.NativeMediaPlayerHandler, videoInfo: webview.MediaInfo) { + this.web = web; + this.embedId = videoInfo.embedID; + + let nodeRect = Rect.toNodeRect(videoInfo.surfaceInfo.rect); + this.nodePosX = nodeRect.x; + this.nodePosY = nodeRect.y; + this.nodeWidth = nodeRect.width; + this.nodeHeight = nodeRect.height; + + this.player = new NativeMediaPlayerImpl(this, handler, videoInfo); + } + + updateNativePlayerRect(x: number, y: number, width: number, height: number) { + this.playerComponent?.updateNativePlayerRect(x, y, width, height); + } + + destroyed() { + let infoList = this.web.nativePlayerInfoList; + console.log(`NativePlayerInfo[${this.embedId}] destroyed, list.size[${infoList.length}]`); + this.web.nativePlayerInfoList = infoList.filter((item) => item.embedId != this.embedId); + console.log(`NativePlayerInfo after destroyed, new_list.size[${this.web.nativePlayerInfoList.length}]`); + } +} + +@Component +struct NativeMediaPlayerComponent { + @ObjectLink playerInfo: NativePlayerInfo; + + aboutToAppear() { + this.playerInfo.playerComponent = this; + } + + build() { + NodeContainer(this.playerInfo.nodeController) + .width(this.playerInfo.nodeWidth) + .height(this.playerInfo.nodeHeight) + .offset({x: this.playerInfo.nodePosX, y: this.playerInfo.nodePosY}) + .backgroundColor(Color.Transparent) + .border({ width: 2, color: Color.Orange }) + .onAreaChange((oldValue, newValue) => { + console.log(`NodeContainer[${this.playerInfo.embedId}]` + + `.onAreaChange([${oldValue.width} x ${oldValue.height}]->[${newValue.width} x ${newValue.height}])`) + }); + } + + updateNativePlayerRect(x: number, y: number, width: number, height: number) { + let nodeRect = Rect.toNodeRect({x, y, width, height}); + this.playerInfo.nodePosX = nodeRect.x; + this.playerInfo.nodePosY = nodeRect.y; + this.playerInfo.nodeWidth = nodeRect.width; + this.playerInfo.nodeHeight = nodeRect.height; + } +} + +@Entry +@Component +struct WebComponent { + controller: WebviewController = new webview.WebviewController(); + pageUrl: Resource = $rawfile('main.html'); + + @State nativePlayerInfoList: NativePlayerInfo[] = []; + + area?: Area; + + build() { + Column() { + Stack({alignContent: Alignment.TopStart}) { + ForEach(this.nativePlayerInfoList, (item: NativePlayerInfo) => { + if (item.showNativeMediaPlayer) { + NativeMediaPlayerComponent({ playerInfo: item }) + } + }, (item: NativePlayerInfo) => { + return item.embedId; + }) + Web({ src: this.pageUrl, controller: this.controller }) + .enableNativeMediaPlayer({ enable: true, shouldOverlay: true }) + .onPageBegin(() => { + this.controller.onCreateNativeMediaPlayer(( + handler: webview.NativeMediaPlayerHandler, mediaInfo: webview.MediaInfo) => { + console.log('onCreateNativeMediaPlayer(' + JSON.stringify(mediaInfo) + ')'); + let nativePlayerInfo = new NativePlayerInfo(this, handler, mediaInfo); + this.nativePlayerInfoList.push(nativePlayerInfo); + return nativePlayerInfo.player; + }); + }) + .onNativeEmbedGestureEvent((event) => { + if (!event.touchEvent || !event.embedId) { + event.result?.setGestureEventResult(false); + return; + } + console.log(`WebComponent.onNativeEmbedGestureEvent, embedId[${event.embedId}]`); + let nativePlayerInfo = this.getNativePlayerInfoByEmbedId(event.embedId); + if (!nativePlayerInfo) { + console.log(`WebComponent.onNativeEmbedGestureEvent, embedId[${event.embedId}], no nativePlayerInfo`); + event.result?.setGestureEventResult(false); + return; + } + if (!nativePlayerInfo.nodeController) { + console.log(`WebComponent.onNativeEmbedGestureEvent, embedId[${event.embedId}], no nodeController`); + event.result?.setGestureEventResult(false); + return; + } + let ret = nativePlayerInfo.nodeController.postTouchEvent(event.touchEvent); + console.log(`WebComponent.postTouchEvent, ret[${ret}], touchEvent[${JSON.stringify(event.touchEvent)}]`); + event.result?.setGestureEventResult(ret); + }) + .width('100%') + .height('100%') + .onAreaChange((oldValue: Area, newValue: Area) => { + oldValue; + this.area = newValue; + }) + } + } + } + + getNativePlayerInfoByEmbedId(embedId: string) : NativePlayerInfo | undefined { + return this.nativePlayerInfoList.find((item)=> item.embedId == embedId); + } +} +// [End video_hosting_usage] \ No newline at end of file diff --git a/UsingWebMultimedia/entry2/src/main/ets/pages/PlayerDemo.ets b/UsingWebMultimedia/entry2/src/main/ets/pages/PlayerDemo.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ed1e324c889f12bfd47d49dce62d5ac6e15e222 --- /dev/null +++ b/UsingWebMultimedia/entry2/src/main/ets/pages/PlayerDemo.ets @@ -0,0 +1,278 @@ +/* + * 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 video_playing_usage] +import { media } from '@kit.MediaKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +export interface AVPlayerListener { + onPlaying() : void; + onPaused() : void; + onDurationChanged(duration: number) : void; + onBufferedTimeChanged(buffered: number) : void; + onTimeUpdate(time: number) : void; + onEnded() : void; + onError() : void; + onVideoSizeChanged(width: number, height: number): void; + onDestroyed(): void; +} + +interface PlayerParam { + url: string; + listener?: AVPlayerListener; + httpHeaders?: Record; +} + +interface PlayCommand { + func: Function; + name?: string; +} + +interface CheckPlayCommandResult { + ignore: boolean; + indexToRemove: number; +} + +export class AVPlayerDemo { + // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接见上面Xcomponent创建方法 + private surfaceID: string = ''; + + public avPlayer?: media.AVPlayer; + public prepared: boolean = false; + + public commands: PlayCommand[] = []; + + setSurfaceID(id: string) { + console.log(`AVPlayerDemo.setSurfaceID : ${id}`); + this.surfaceID = id; + } + // 注册avplayer回调函数 + setAVPlayerCallback(avPlayer: media.AVPlayer, listener?: AVPlayerListener) { + // seek操作结果回调函数 + avPlayer.on('seekDone', (seekDoneTime: number) => { + console.info(`AVPlayer seek succeeded, seek time is ${seekDoneTime}`); + }); + // error回调监听函数,当avPlayer在操作过程中出现错误时调用reset接口触发重置流程 + avPlayer.on('error', (err: BusinessError) => { + console.error(`Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`); + listener?.onError(); + avPlayer.reset(); // 调用reset重置资源,触发idle状态 + }); + // 状态机变化回调函数 + avPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => { + switch (state) { + case 'idle': // 成功调用reset接口后触发该状态机上报 + console.info('AVPlayer state idle called.'); + avPlayer.release(); // 调用release接口销毁实例对象 + break; + case 'initialized': // avplayer 设置播放源后触发该状态上报 + console.info('AVPlayer state initialized called.'); + avPlayer.surfaceId = this.surfaceID; // 设置显示画面,当播放的资源为纯音频时无需设置 + avPlayer.prepare(); + break; + case 'prepared': // prepare调用成功后上报该状态机 + console.info('AVPlayer state prepared called.'); + this.prepared = true; + this.schedule(); + break; + case 'playing': // play成功调用后触发该状态机上报 + console.info('AVPlayer state playing called.'); + listener?.onPlaying(); + break; + case 'paused': // pause成功调用后触发该状态机上报 + console.info('AVPlayer state paused called.'); + listener?.onPaused(); + break; + case 'completed': // 播放结束后触发该状态机上报 + console.info('AVPlayer state completed called.'); + avPlayer.stop(); //调用播放结束接口 + break; + case 'stopped': // stop接口成功调用后触发该状态机上报 + console.info('AVPlayer state stopped called.'); + listener?.onEnded(); + break; + case 'released': + this.prepared = false; + listener?.onDestroyed(); + console.info('AVPlayer state released called.'); + break; + default: + console.info('AVPlayer state unknown called.'); + break; + } + }); + avPlayer.on('durationUpdate', (duration: number) => { + console.info(`AVPlayer state durationUpdate success,new duration is :${duration}`); + listener?.onDurationChanged(duration/1000); + }); + avPlayer.on('timeUpdate', (time:number) => { + listener?.onTimeUpdate(time/1000); + }); + avPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => { + console.info(`AVPlayer state bufferingUpdate success,and infoType value is:${infoType}, value is : ${value}`); + if (infoType == media.BufferingInfoType.BUFFERING_PERCENT) { + } + listener?.onBufferedTimeChanged(value); + }) + avPlayer.on('videoSizeChange', (width: number, height: number) => { + console.info(`AVPlayer state videoSizeChange success,and width is:${width}, height is : ${height}`); + listener?.onVideoSizeChanged(width, height); + }) + } + + // 以下demo为通过url设置网络地址来实现播放直播码流的demo + async avPlayerLiveDemo(playerParam: PlayerParam) { + // 创建avPlayer实例对象 + this.avPlayer = await media.createAVPlayer(); + // 创建状态机变化回调函数 + this.setAVPlayerCallback(this.avPlayer, playerParam.listener); + + let mediaSource: media.MediaSource = media.createMediaSourceWithUrl(playerParam.url, playerParam.httpHeaders); + let strategy: media.PlaybackStrategy = { + preferredWidth: 100, + preferredHeight: 100, + preferredBufferDuration: 100, + preferredHdr: false + }; + this.avPlayer.setMediaSource(mediaSource, strategy); + console.log(`AVPlayer url:[${playerParam.url}]`); + } + + schedule() { + if (!this.avPlayer) { + return; + } + if (!this.prepared) { + return; + } + if (this.commands.length > 0) { + let command = this.commands.shift(); + if (command) { + command.func(); + } + if (this.commands.length > 0) { + setTimeout(() => { + this.schedule(); + }); + } + } + } + + private checkCommand(selfName: string, oppositeName: string) { + let indexToRemove = -1; + let ignoreThisAction = false; + let index = this.commands.length - 1; + while (index >= 0) { + if (this.commands[index].name == selfName) { + ignoreThisAction = true; + break; + } + if (this.commands[index].name == oppositeName) { + indexToRemove = index; + break; + } + index--; + } + + let result : CheckPlayCommandResult = { + ignore: ignoreThisAction, + indexToRemove: indexToRemove, + }; + return result; + } + + play() { + let commandName = 'play'; + let checkResult = this.checkCommand(commandName, 'pause'); + if (checkResult.ignore) { + console.log(`AVPlayer ${commandName} ignored.`); + this.schedule(); + return; + } + if (checkResult.indexToRemove >= 0) { + let removedCommand = this.commands.splice(checkResult.indexToRemove, 1); + console.log(`AVPlayer ${JSON.stringify(removedCommand)} removed.`); + return; + } + this.commands.push({ func: ()=>{ + console.info('AVPlayer.play()'); + this.avPlayer?.play(); + }, name: commandName}); + this.schedule(); + } + pause() { + let commandName = 'pause'; + let checkResult = this.checkCommand(commandName, 'play'); + console.log(`checkResult:${JSON.stringify(checkResult)}`); + if (checkResult.ignore) { + console.log(`AVPlayer ${commandName} ignored.`); + this.schedule(); + return; + } + if (checkResult.indexToRemove >= 0) { + let removedCommand = this.commands.splice(checkResult.indexToRemove, 1); + console.log(`AVPlayer ${JSON.stringify(removedCommand)} removed.`); + return; + } + this.commands.push({ func: ()=>{ + console.info('AVPlayer.pause()'); + this.avPlayer?.pause(); + }, name: commandName}); + this.schedule(); + } + release() { + this.commands.push({ func: ()=>{ + console.info('AVPlayer.release()'); + this.avPlayer?.release(); + }}); + this.schedule(); + } + seek(time: number) { + this.commands.push({ func: ()=>{ + console.info(`AVPlayer.seek(${time})`); + this.avPlayer?.seek(time * 1000); + }}); + this.schedule(); + } + setVolume(volume: number) { + this.commands.push({ func: ()=>{ + console.info(`AVPlayer.setVolume(${volume})`); + this.avPlayer?.setVolume(volume); + }}); + this.schedule(); + } + setPlaybackRate(playbackRate: number) { + let speed = media.PlaybackSpeed.SPEED_FORWARD_1_00_X; + let delta = 0.05; + playbackRate += delta; + if (playbackRate < 1) { + speed = media.PlaybackSpeed.SPEED_FORWARD_0_75_X; + } else if (playbackRate < 1.25) { + speed = media.PlaybackSpeed.SPEED_FORWARD_1_00_X; + } else if (playbackRate < 1.5) { + speed = media.PlaybackSpeed.SPEED_FORWARD_1_25_X; + } else if (playbackRate < 2) { + speed = media.PlaybackSpeed.SPEED_FORWARD_1_75_X; + } else { + speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; + } + this.commands.push({ func: ()=>{ + console.info(`AVPlayer.setSpeed(${speed})`); + this.avPlayer?.setSpeed(speed); + }}); + this.schedule(); + } +} +//[End video_playing_usage] \ No newline at end of file diff --git a/UsingWebMultimedia/entry2/src/main/module.json5 b/UsingWebMultimedia/entry2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8b99132eae7ead0171b7952619e38a38db15406e --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/main/resources/base/element/color.json b/UsingWebMultimedia/entry2/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/main/resources/base/element/string.json b/UsingWebMultimedia/entry2/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0b6e03b6c50d1e80040acc8fe8759beb373f65bc --- /dev/null +++ b/UsingWebMultimedia/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": "UsingWebMultimedia" + } + ] +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry2/src/main/resources/base/media/background.png b/UsingWebMultimedia/entry2/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/UsingWebMultimedia/entry2/src/main/resources/base/media/background.png differ diff --git a/UsingWebMultimedia/entry2/src/main/resources/base/media/foreground.png b/UsingWebMultimedia/entry2/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/UsingWebMultimedia/entry2/src/main/resources/base/media/foreground.png differ diff --git a/UsingWebMultimedia/entry2/src/main/resources/base/media/layered_image.json b/UsingWebMultimedia/entry2/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/main/resources/base/media/startIcon.png b/UsingWebMultimedia/entry2/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UsingWebMultimedia/entry2/src/main/resources/base/media/startIcon.png differ diff --git a/UsingWebMultimedia/entry2/src/main/resources/base/profile/backup_config.json b/UsingWebMultimedia/entry2/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/UsingWebMultimedia/entry2/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry2/src/main/resources/base/profile/main_pages.json b/UsingWebMultimedia/entry2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UsingWebMultimedia/entry2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UsingWebMultimedia/entry2/src/main/resources/rawfile/main.html b/UsingWebMultimedia/entry2/src/main/resources/rawfile/main.html new file mode 100644 index 0000000000000000000000000000000000000000..f87d2d199170c56b2219813f0ff5788b3a7fe1ab --- /dev/null +++ b/UsingWebMultimedia/entry2/src/main/resources/rawfile/main.html @@ -0,0 +1,27 @@ + + + + + 视频托管测试html + + + +
+ + +
+ + diff --git a/UsingWebMultimedia/entry2/src/mock/mock-config.json5 b/UsingWebMultimedia/entry2/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2417dae33e86618dcf41b9c0c0f2835b30e47b34 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/ohosTest/ets/test/Ability.test.ets b/UsingWebMultimedia/entry2/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..daa7eb0c2e3b58b822206c06e35685653fd9ad10 --- /dev/null +++ b/UsingWebMultimedia/entry2/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. + }) + + /* + * 打开应用 + * 通过 enableNativeMediaPlayer 接口,接管网页中的媒体播放 + */ + it('testUiExample', 0, async (done: Function) => { + console.info('uitest: TestUiExample 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(3000); + + const button1 = await driver.findComponent(ON.text('play')); + const button2 = await driver.findComponent(ON.text('pause')); + + await button1.click(); + await driver.delayMs(3000); + + await button2.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('main.html'); + + console.info('uitest: TestUiExample end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry2/src/ohosTest/ets/test/List.test.ets b/UsingWebMultimedia/entry2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/ohosTest/module.json5 b/UsingWebMultimedia/entry2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..275d4a7e53feffc965753732f517aa2fb1a9ba7e --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/test/List.test.ets b/UsingWebMultimedia/entry2/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry2/src/test/LocalUnit.test.ets b/UsingWebMultimedia/entry2/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/.gitignore b/UsingWebMultimedia/entry3/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/UsingWebMultimedia/entry3/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/UsingWebMultimedia/entry3/build-profile.json5 b/UsingWebMultimedia/entry3/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9edfdf8c4a72db3313433e7366df25b6beb1c3a7 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/hvigorfile.ts b/UsingWebMultimedia/entry3/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/obfuscation-rules.txt b/UsingWebMultimedia/entry3/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/oh-package.json5 b/UsingWebMultimedia/entry3/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fdde2dca53a66167a411ea77e7804f0200b86663 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/UsingWebMultimedia/entry3/src/main/ets/entry3ability/Entry3Ability.ets new file mode 100644 index 0000000000000000000000000000000000000000..94de6f8cdbcc8368475625ab2473f464389fa297 --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/ets/entry3ability/Entry3Ability.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 { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class Entry3Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/UsingWebMultimedia/entry3/src/main/ets/entry3backupability/Entry3BackupAbility.ets b/UsingWebMultimedia/entry3/src/main/ets/entry3backupability/Entry3BackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0370ffb34e8c7f6d75ff139c8bbed7aa57f739e3 --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/ets/entry3backupability/Entry3BackupAbility.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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class Entry3BackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry3/src/main/ets/pages/Index.ets b/UsingWebMultimedia/entry3/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc21b2bffefad7e901ea2d1153d55dda01734c5e --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/ets/pages/Index.ets @@ -0,0 +1,29 @@ +/* + * 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 { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct Index { + @State videoSrc: Resource = $rawfile('PictureInPicture.html') + controller: webview.WebviewController = new webview.WebviewController() + + build() { + Column() { + Web({ src: this.videoSrc, controller: this.controller }) + } + } +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry3/src/main/module.json5 b/UsingWebMultimedia/entry3/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..405a5183ab930aa877b589758a75862a2822a6fe --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/module.json5 @@ -0,0 +1,65 @@ +/* +* 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": "entry", + "description": "$string:module_desc", + "mainElement": "Entry3Ability", + "deviceTypes": [ + "default" + ], + "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, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry3BackupAbility", + "srcEntry": "./ets/entry3backupability/Entry3BackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry3/src/main/resources/base/element/color.json b/UsingWebMultimedia/entry3/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/src/main/resources/base/element/float.json b/UsingWebMultimedia/entry3/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/UsingWebMultimedia/entry3/src/main/resources/base/element/string.json b/UsingWebMultimedia/entry3/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5416aefe3699bc869fd4896df9f691be313b0250 --- /dev/null +++ b/UsingWebMultimedia/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": "label" + } + ] +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry3/src/main/resources/base/media/background.png b/UsingWebMultimedia/entry3/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/UsingWebMultimedia/entry3/src/main/resources/base/media/background.png differ diff --git a/UsingWebMultimedia/entry3/src/main/resources/base/media/foreground.png b/UsingWebMultimedia/entry3/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/UsingWebMultimedia/entry3/src/main/resources/base/media/foreground.png differ diff --git a/UsingWebMultimedia/entry3/src/main/resources/base/media/layered_image.json b/UsingWebMultimedia/entry3/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/src/main/resources/base/media/startIcon.png b/UsingWebMultimedia/entry3/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/UsingWebMultimedia/entry3/src/main/resources/base/media/startIcon.png differ diff --git a/UsingWebMultimedia/entry3/src/main/resources/base/profile/backup_config.json b/UsingWebMultimedia/entry3/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/UsingWebMultimedia/entry3/src/main/resources/base/profile/main_pages.json b/UsingWebMultimedia/entry3/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/UsingWebMultimedia/entry3/src/main/resources/rawfile/PictureInPicture.html b/UsingWebMultimedia/entry3/src/main/resources/rawfile/PictureInPicture.html new file mode 100644 index 0000000000000000000000000000000000000000..bf46d9515a2d629dab31874485d53520bba0c035 --- /dev/null +++ b/UsingWebMultimedia/entry3/src/main/resources/rawfile/PictureInPicture.html @@ -0,0 +1,87 @@ + + + + + + + Picture-in-Picture Demo + + + + + + + + + + + \ No newline at end of file diff --git a/UsingWebMultimedia/entry3/src/mock/mock-config.json5 b/UsingWebMultimedia/entry3/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2417dae33e86618dcf41b9c0c0f2835b30e47b34 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/src/ohosTest/ets/test/Ability.test.ets b/UsingWebMultimedia/entry3/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/UsingWebMultimedia/entry3/src/ohosTest/ets/test/Ability.test.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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + 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/UsingWebMultimedia/entry3/src/ohosTest/ets/test/List.test.ets b/UsingWebMultimedia/entry3/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/src/ohosTest/module.json5 b/UsingWebMultimedia/entry3/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..33e7ebcfda25a462ba4f3739cc88fac6f545c4d5 --- /dev/null +++ b/UsingWebMultimedia/entry3/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": "entry3_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/UsingWebMultimedia/entry3/src/test/List.test.ets b/UsingWebMultimedia/entry3/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/entry3/src/test/LocalUnit.test.ets b/UsingWebMultimedia/entry3/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/hvigor/hvigor-config.json5 b/UsingWebMultimedia/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/hvigorfile.ts b/UsingWebMultimedia/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/oh-package.json5 b/UsingWebMultimedia/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/UsingWebMultimedia/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/UsingWebMultimedia/ohosTest.md b/UsingWebMultimedia/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..d8768213e8a4eef77bf79da742e14e4c3303cd5a --- /dev/null +++ b/UsingWebMultimedia/ohosTest.md @@ -0,0 +1,14 @@ +#### HoldVideoConfWebRTC + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ------------------------------------------ | ------------------ | -------- | -------- | +| 使用WebRTC进行Web视频会议 | 设备运转正常 | 应用启动成功,击前端页面中的开起摄像头按钮 | 弹出提示框 | Yes | Pass | +| 打开摄像头和麦克风 | 弹出提示框 | 点击onConfirm按钮 | 打开摄像头和麦克风 | Yes | Pass | + +#### TakeOverMediaPlay + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | -------------------------- | ------------------ | -------- | -------- | +| 托管网页中的媒体播放 | 设备运转正常 | 应用启动成功,点击play按钮 | 启动本地播放器播放 | Yes | Pass | +| 暂停本地播放器播放 | 设备运转正常 | 点击pause按钮 | 暂停本地播放器播放 | Yes | Pass | + diff --git a/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_1.png b/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_1.png new file mode 100644 index 0000000000000000000000000000000000000000..b3e0c5406d3e864183deedb58f6f8f3227da9156 Binary files /dev/null and b/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_1.png differ diff --git a/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_2.png b/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_2.png new file mode 100644 index 0000000000000000000000000000000000000000..e8c91e89720d1fc364cc0234e9510c4aca58ad1f Binary files /dev/null and b/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_2.png differ diff --git a/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_3.png b/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_3.png new file mode 100644 index 0000000000000000000000000000000000000000..b3019d3610f022c3cc28bae1ce65cefb73c6cffa Binary files /dev/null and b/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_3.png differ diff --git a/UsingWebMultimedia/screenshots/PictureInPicture.png b/UsingWebMultimedia/screenshots/PictureInPicture.png new file mode 100644 index 0000000000000000000000000000000000000000..bc4fdb220b1c7222f7a45548018018aa827e5b75 Binary files /dev/null and b/UsingWebMultimedia/screenshots/PictureInPicture.png differ diff --git a/UsingWebMultimedia/screenshots/TakeOverMediaPlay.png b/UsingWebMultimedia/screenshots/TakeOverMediaPlay.png new file mode 100644 index 0000000000000000000000000000000000000000..88aa91787628e450f0a3802420315613807926bb Binary files /dev/null and b/UsingWebMultimedia/screenshots/TakeOverMediaPlay.png differ diff --git a/WebRenderLayout/.gitignore b/WebRenderLayout/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/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/WebRenderLayout/AppScope/app.json5 b/WebRenderLayout/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..05d4077ce4a7d7033ee498e91542b02a57098a33 --- /dev/null +++ b/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/WebRenderLayout/AppScope/resources/base/element/string.json b/WebRenderLayout/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d141695c97a80ba162c219dfd4c5afa0b1ae7772 --- /dev/null +++ b/WebRenderLayout/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "WebRenderLayout" + } + ] +} diff --git a/WebRenderLayout/AppScope/resources/base/media/app_icon.png b/WebRenderLayout/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/WebRenderLayout/AppScope/resources/base/media/app_icon.png differ diff --git a/WebRenderLayout/README.md b/WebRenderLayout/README.md new file mode 100644 index 0000000000000000000000000000000000000000..30b81346fda26e83638d54597b4e8f6ad5a7053c --- /dev/null +++ b/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 code/DocsSample/ArkWeb/WebRenderLayout > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/WebRenderLayout/build-profile.json5 b/WebRenderLayout/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/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/WebRenderLayout/code-linter.json5 b/WebRenderLayout/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/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/WebRenderLayout/entry/.gitignore b/WebRenderLayout/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/WebRenderLayout/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/WebRenderLayout/entry/build-profile.json5 b/WebRenderLayout/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/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/WebRenderLayout/entry/hvigorfile.ts b/WebRenderLayout/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..98d52319cb1dee60511b5716dba03b76e68a6d8b --- /dev/null +++ b/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/WebRenderLayout/entry/obfuscation-rules.txt b/WebRenderLayout/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/WebRenderLayout/entry/oh-package.json5 b/WebRenderLayout/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets b/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets b/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets new file mode 100644 index 0000000000000000000000000000000000000000..540e3cb7c6c821ee0737b9c7131947102d04689b --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/ets/pages/Index.ets b/WebRenderLayout/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..df919e917f89291db2860580991977a30666f74e --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets b/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets new file mode 100644 index 0000000000000000000000000000000000000000..fa5b59c771ce7e9d4fab94562ec97740f72df354 --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/module.json5 b/WebRenderLayout/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/resources/base/element/color.json b/WebRenderLayout/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/resources/base/element/string.json b/WebRenderLayout/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6e797f7e8ed5cd498631cffb6be41435d3a4c35f --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/resources/base/media/background.png b/WebRenderLayout/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/WebRenderLayout/entry/src/main/resources/base/media/background.png differ diff --git a/WebRenderLayout/entry/src/main/resources/base/media/foreground.png b/WebRenderLayout/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/WebRenderLayout/entry/src/main/resources/base/media/foreground.png differ diff --git a/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json b/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png b/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png differ diff --git a/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json b/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json b/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..a632b71f19e592ae7862ebda48f5b871bd93c7b9 --- /dev/null +++ b/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/FitPageContent", + "pages/RenderMode" + ] +} diff --git a/WebRenderLayout/entry/src/main/resources/en_US/element/string.json b/WebRenderLayout/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f618771a19f0dffbca09170f416db1ff866c5972 --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html b/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html new file mode 100644 index 0000000000000000000000000000000000000000..46c149ed86bd171a04921aed7d9c4dc5b927eccf --- /dev/null +++ b/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/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json b/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8b827c36ef821c56b3e6ef65fd4d64627a4a978b --- /dev/null +++ b/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/WebRenderLayout/entry/src/mock/mock-config.json5 b/WebRenderLayout/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/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/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets b/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1375e7a47ea13527ce438c9327cb82226ebfed3e --- /dev/null +++ b/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/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets b/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/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/WebRenderLayout/entry/src/ohosTest/module.json5 b/WebRenderLayout/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/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/WebRenderLayout/entry/src/test/List.test.ets b/WebRenderLayout/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/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/WebRenderLayout/entry/src/test/LocalUnit.test.ets b/WebRenderLayout/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/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/WebRenderLayout/hvigor/hvigor-config.json5 b/WebRenderLayout/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- /dev/null +++ b/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/WebRenderLayout/hvigorfile.ts b/WebRenderLayout/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..1307c03303328d961439d1f6983b09e728b5e8ce --- /dev/null +++ b/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/WebRenderLayout/oh-package.json5 b/WebRenderLayout/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93f097993a458e967d6d5239ea0580e79b5d6998 --- /dev/null +++ b/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/WebRenderLayout/ohosTest.md b/WebRenderLayout/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..adb0630d5903794a19ddf997a1149a45d5be34f3 --- /dev/null +++ b/WebRenderLayout/ohosTest.md @@ -0,0 +1,12 @@ +#### renderMode + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------- | ------------ | ------------ | -------------------------- | -------- | -------- | +| Web组件渲染模式 | 设备运转正常 | 应用启动成功 | 设置渲染模式为同步渲染模式 | Yes | Pass | + +#### FitPageContent + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------- | ------------ | ------------ | ------------------------------------- | -------- | -------- | +| Web组件大小自适应页面内容布局 | 设备运转正常 | 应用启动成功 | 使Web组件的大小根据页面内容自适应变化 | Yes | Pass | + diff --git a/WebRenderLayout/screenshots/FitPageContent.png b/WebRenderLayout/screenshots/FitPageContent.png new file mode 100644 index 0000000000000000000000000000000000000000..9adcb9f829555ac56fb968df666af85a404fff83 Binary files /dev/null and b/WebRenderLayout/screenshots/FitPageContent.png differ diff --git a/WebRenderLayout/screenshots/RenderModeWebComp.png b/WebRenderLayout/screenshots/RenderModeWebComp.png new file mode 100644 index 0000000000000000000000000000000000000000..aaad114cf5305f8c82ea1b1238330f61a3b7625d Binary files /dev/null and b/WebRenderLayout/screenshots/RenderModeWebComp.png differ