diff --git a/OAT.xml b/OAT.xml index a859db12f89c5a9c27affe4176ee471b5ac41b19..b7266b506238613c5c6fc40df93ee2fa8845320e 100644 --- a/OAT.xml +++ b/OAT.xml @@ -1246,6 +1246,10 @@ Note:If the text contains special characters, please escape them according to th + + + + diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/.gitignore b/code/DocsSample/ArkWeb/LifecycleWebComp/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/app.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..eb9fbe57f49f96a77bcb145b91a6263644b2b049 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..c5e75bb9ea567447aa93d5e5ee84a4021dc7158a --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "LifecycleWebComp" + } + ] +} diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/README.md b/code/DocsSample/ArkWeb/LifecycleWebComp/README.md new file mode 100755 index 0000000000000000000000000000000000000000..f53c81fb0cf109b75f31c20742964503385f1b4e --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/README.md @@ -0,0 +1,58 @@ +# 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. 本示例仅支持标准系统上运行,支持设备:RK3568。 +2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 +3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +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/code/DocsSample/ArkWeb/LifecycleWebComp/build-profile.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..20e9fa86a96ec102bf5a1b534dc8f6e8551c07df --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/build-profile.json5 @@ -0,0 +1,52 @@ +/* + * 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", + "compileSdkVersion": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/code-linter.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..eff2dbc9b8a447e5a99b0aab08ca2b766d786bf6 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/.gitignore b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/build-profile.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..90b14923bfc8eb7450488a9312783c21aa1966db --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/oh-package.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..41a4755f666bbe0bb1a9ebbedd6fb045727e62fb --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..d91a720cecfabf830b9e63a5949b2a24bebe0ccf --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..1755a4686cf9f79996fdcd75b26f06b555c3ad3f --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..170cc62808fe146f1a0b47b2a6f851c78d1ee6d6 --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,130 @@ +/* + * 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 { 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 + }); + }) + } + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b541792385cb5a1a925f93ae8c9242b9596ec27e --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..38f261172dc69d5f1652c4a07e5197966e5d449f --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..38f261172dc69d5f1652c4a07e5197966e5d449f --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html new file mode 100755 index 0000000000000000000000000000000000000000..f7fceda00c2bd2ff398912e9a5fe07a1c18dafa4 --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,9 @@ + + + + + + +

Hello, ArkWeb

+ + diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..00df20570eb1892ed5e7d19b125c9f65988634c4 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..26ed9f53bc46192a07ad5ab16ea24e7ce9a79328 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..72a538fe044d7e7dbbac4010a47249c3eeabeeb7 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..e909c66ab67746c53f694cc12a0a604748a8b661 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..1f646ea03f584d15f4a5406ea548af0214a093d4 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..ab6445db05608a5b7f851a85add24f32b890b0f8 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..4b7b4eb2ff9627c7184e386fe88c2ba1b507f905 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..5f9d8a57584fa98d3e8f6c63a304213b801d0dff --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/hvigorfile.ts b/code/DocsSample/ArkWeb/LifecycleWebComp/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/oh-package.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..fb70d168e165b1212a708f14edd3945c775d6543 --- /dev/null +++ b/code/DocsSample/ArkWeb/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/code/DocsSample/ArkWeb/LifecycleWebComp/ohosTest.md b/code/DocsSample/ArkWeb/LifecycleWebComp/ohosTest.md new file mode 100755 index 0000000000000000000000000000000000000000..cbf90fb29998b1baec6a0ea45fdd2c6ff8633012 --- /dev/null +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/ohosTest.md @@ -0,0 +1,4 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ------------ | ---------------- | -------- | -------- | +| Web组件的生命周期 | 设备运转正常 | 应用启动成功 | 日志输出相关信息 | Yes | Pass | + diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png b/code/DocsSample/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png new file mode 100755 index 0000000000000000000000000000000000000000..879273b457515acee4cc9752e74440204b7ac63c Binary files /dev/null and b/code/DocsSample/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png differ diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/.gitignore b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/.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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/app.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..59517a1ddc276596c103dfd1d17937e524431f59 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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.defuseragent", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..6e44efba73908c91c80b23cd3b93926c3153cabf --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DefUserAgent" + } + ] +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/README.md b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/README.md new file mode 100755 index 0000000000000000000000000000000000000000..c8b825c3bef3dc57e480e6353be48fcc26e25f55 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/README.md @@ -0,0 +1,100 @@ +# UserAgent开发指导 + +### 介绍 + +1. UserAgent(简称UA)是一个特殊的字符串,它包含了设备类型、操作系统及版本等关键信息。如果页面无法正确识别UA,可能会导致一系列异常情况,例如页面布局错误、渲染问题以及逻辑错误等。 +2. 实现对以下指南文档中 https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/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()接口获取自定义用户代理。 + +### 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---UserAgent_one.ets +|---|---|---UserAgent_three.ets +|---|---|---UserAgent_two.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + +### 相关权限 + +[ohos.permission.INTERNET](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 +2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 +3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent > .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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/build-profile.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..87d40a385e30dc461bee671328ee541abfafd5de --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/build-profile.json5 @@ -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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/code-linter.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/.gitignore b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/build-profile.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/oh-package.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..b23d2fe946b5f93ddc577864f9da7c6516f59209 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..1504a74f09dfdcfae408be979f99369a2c5affab --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..e90ffd1b88b4dde2272c053ab747a9e3f09968aa --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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('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' }); + }) + }.height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_one.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_one.ets new file mode 100755 index 0000000000000000000000000000000000000000..079e103a1f2af2a31b64ae6fb501b857ec4ab165 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_one.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 { 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 }) + } + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_three.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_three.ets new file mode 100755 index 0000000000000000000000000000000000000000..9a1b8c38603f1e0b00ae9c1214920635466930f6 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_three.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES 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 { 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 }) + } + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_two.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_two.ets new file mode 100755 index 0000000000000000000000000000000000000000..5c5a97eebcb47d1bc9afcb8e1a590abe28c55922 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/ets/pages/UserAgent_two.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. + */ + +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}`); + } + }) + } + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..646e723f6045c7a73ae504a77097d58c8808e51d --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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": "DefUserAgent" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..3892aaadf5161c35a88963555d435a64e06f12ff --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/UserAgent_one", + "pages/UserAgent_two", + "pages/UserAgent_three" + ] +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/en_US/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..646e723f6045c7a73ae504a77097d58c8808e51d --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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": "DefUserAgent" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/main/resources/zh_CN/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..eafe7fffdbbcd49eaa51c7328e3477b2393da34b --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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": "DefUserAgent" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..367288df40e2d5f9586c23740dd82d9410abd473 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES 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('UserAgent_one', 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'); + console.info("uitest: UserAgent_one begin"); + + 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(); + }); + + 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(); + }); + + 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'); + + console.info("uitest: UserAgent_three end"); + done(); + }); + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9983b2ba4e55e31a172f0328c82c9a75bfa00ded --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c61d3eed60978a00d9a67b754ec36c0c9dcde929 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/hvigorfile.ts b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/oh-package.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..4c8bad9bdbdd8da17793a0e43f29d9e7232dce00 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/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/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/ohosTest.md b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/ohosTest.md new file mode 100755 index 0000000000000000000000000000000000000000..25e3f510fceb95be9bc4ef965ffe6a424fe43408 --- /dev/null +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/ohosTest.md @@ -0,0 +1,17 @@ +### UserAgent_one + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------- | ------------ | ---------------------------------- | -------------------- | -------- | -------- | +| 设置UserAgent | 设备运转正常 | 应用启动成功,点击getUserAgent按钮 | 获取当前默认用户代理 | Yes | Pass | + +### UserAgent_two + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------- | ------------ | ------------ | ------------------------------- | -------- | -------- | +| 设置UserAgent | 设备运转正常 | 应用启动成功 | 加载网页时使用定制后的UserAgent | Yes | Pass | + +### UserAgent_three + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------- | ------------ | ---------------------------------------- | ---------------------- | -------- | -------- | +| 设置UserAgent | 设备运转正常 | 应用启动成功,点击getCustomUserAgent按钮 | 获取当前自定义用户代理 | Yes | Pass | diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_one.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_one.png new file mode 100755 index 0000000000000000000000000000000000000000..ee8c9c998321599f0d0381deac96e827fceac5ac Binary files /dev/null and b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_one.png differ diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_three.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_three.png new file mode 100755 index 0000000000000000000000000000000000000000..4f00b024de82f2bb88b33471bd1440b798d56859 Binary files /dev/null and b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_three.png differ diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_two.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_two.png new file mode 100755 index 0000000000000000000000000000000000000000..5249dc4104448d82890889afdc1c61092980bac8 Binary files /dev/null and b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/DefUserAgent/screenshots/UserAgent_two.png differ