From b8fc09633d85e57d6134cdbc8f40019707f315ef Mon Sep 17 00:00:00 2001 From: zwx1016320 Date: Thu, 29 Sep 2022 01:54:05 +0000 Subject: [PATCH] fixed 46f8b75 from https://gitee.com/yu-shuai-zhang/xts_acts/pulls/5770 modified request Signed-off-by: zwx1016320 --- request/BUILD.gn | 2 +- request/RequestTest_Stage/AppScope/app.json | 36 ++- .../resources/base/element/string.json | 16 +- request/RequestTest_Stage/BUILD.gn | 10 +- request/RequestTest_Stage/Test.json | 6 +- .../src/main/ets/Application/AbilityStage.ts | 23 -- .../main/ets/Application/MyAbilityStage.ts | 9 + .../src/main/ets/MainAbility/MainAbility.ts | 117 +++++---- .../ets/TestRunner/OpenHarmonyTestRunner.ts | 45 ++-- .../pages/{second/second.ets => index.ets} | 79 +++--- .../entry/src/main/ets/pages/index/index.ets | 51 ---- .../entry/src/main/ets/test/List.test.ets | 3 +- .../main/ets/test/requestDownload.test.ets | 232 +++++++++--------- .../src/main/ets/test/requestUpload.test.ets | 27 +- .../entry/src/main/module.json | 87 ++++--- .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/string.json | 52 ++-- .../resources/base/profile/main_pages.json | 9 +- .../src/main/ets/MainAbility/pages/index.ets | 2 +- .../entry/src/main/ets/test/List.test.ets | 2 +- .../main/ets/test/requestDownload.test.ets | 5 +- ...ystemJSUnit.ets => requestSystem.test.ets} | 30 +-- .../src/main/ets/test/requestUpload.test.ets | 5 +- 23 files changed, 380 insertions(+), 476 deletions(-) delete mode 100644 request/RequestTest_Stage/entry/src/main/ets/Application/AbilityStage.ts create mode 100644 request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts rename request/RequestTest_Stage/entry/src/main/ets/pages/{second/second.ets => index.ets} (56%) delete mode 100644 request/RequestTest_Stage/entry/src/main/ets/pages/index/index.ets create mode 100644 request/RequestTest_Stage/entry/src/main/resources/base/element/color.json rename request/RequestTest_ets/entry/src/main/ets/test/{requestSystemJSUnit.ets => requestSystem.test.ets} (91%) diff --git a/request/BUILD.gn b/request/BUILD.gn index 444566b1d..49c17cc8d 100644 --- a/request/BUILD.gn +++ b/request/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (C) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/request/RequestTest_Stage/AppScope/app.json b/request/RequestTest_Stage/AppScope/app.json index 4817f2f10..403c65552 100644 --- a/request/RequestTest_Stage/AppScope/app.json +++ b/request/RequestTest_Stage/AppScope/app.json @@ -1,21 +1,15 @@ -{ - "app":{ - "bundleName":"com.acts.request.test", - "vendor":"huawei", - "versionCode":1000000, - "versionName":"1.0.0", - "debug":false, - "icon":"$media:icon", - "label":"$string:app_name", - "description":"$string:description_application", - "distributedNotificationEnabled":true, - "keepAlive":true, - "singleUser":true, - "minAPIVersion":9, - "targetAPIVersion":9, - "car":{ - "apiCompatibleVersion":9, - "singleUser":false - } - } -} +{ + "app": { + "bundleName": "com.acts.request.test", + "vendor": "huawei", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":9, + "targetAPIVersion":9 + } +} diff --git a/request/RequestTest_Stage/AppScope/resources/base/element/string.json b/request/RequestTest_Stage/AppScope/resources/base/element/string.json index ee69f9a86..066e1ff18 100644 --- a/request/RequestTest_Stage/AppScope/resources/base/element/string.json +++ b/request/RequestTest_Stage/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string":[ - { - "name":"app_name", - "value":"ohosProject" - } - ] -} \ No newline at end of file +{ + "string": [ + { + "name": "app_name", + "value": "ActsTimeAPITest" + } + ] +} diff --git a/request/RequestTest_Stage/BUILD.gn b/request/RequestTest_Stage/BUILD.gn index bc2405f19..2f161101b 100644 --- a/request/RequestTest_Stage/BUILD.gn +++ b/request/RequestTest_Stage/BUILD.gn @@ -14,17 +14,17 @@ import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("ActsRequestStageTest") { - hap_profile = "entry/src/main/module.json" - js_build_mode = "debug" deps = [ ":requestStage_ets_assets", ":requestStage_resources", ] ets2abc = true - certificate_profile = "signature/actsRequestStageTest.p7b" - hap_name = "ActsRequestStageTest" - subsystem_name = "request" + js_build_mode = "debug" part_name = "request" + subsystem_name = "request" + hap_name = "ActsRequestStageTest" + hap_profile = "entry/src/main/module.json" + certificate_profile = "signature/actsRequestStageTest.p7b" } ohos_app_scope("requestStage_app_profile") { diff --git a/request/RequestTest_Stage/Test.json b/request/RequestTest_Stage/Test.json index a1fc50004..0f199b048 100644 --- a/request/RequestTest_Stage/Test.json +++ b/request/RequestTest_Stage/Test.json @@ -4,9 +4,9 @@ "type": "OHJSUnitTest", "test-timeout": "180000", "bundle-name": "com.acts.request.test", - "module-name": "phone", - "shell-timeout": "600000", - "testcase-timeout": 70000 + "module-name": "entry_test", + "shell-timeout": "180000", + "testcase-timeout": 600000 }, "kits": [{ "test-file-name": [ diff --git a/request/RequestTest_Stage/entry/src/main/ets/Application/AbilityStage.ts b/request/RequestTest_Stage/entry/src/main/ets/Application/AbilityStage.ts deleted file mode 100644 index 36a8a495d..000000000 --- a/request/RequestTest_Stage/entry/src/main/ets/Application/AbilityStage.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import AbilityStage from "@ohos.application.AbilityStage" - -export default class MyAbilityStage extends AbilityStage { - onCreate() { - console.log("MyAbilityStage onCreate"); - globalThis.stageOnCreateRun = 1; - globalThis.stageContext = this.context; - } -} diff --git a/request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts b/request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 000000000..4bea34b35 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,9 @@ +import hilog from '@ohos.hilog'; +import AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'AbilityStage onCreate'); + } +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts index abed5a69d..9dc331bc8 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,51 +1,66 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import Ability from '@ohos.application.Ability' - -export default class MainAbility extends Ability { - onCreate(want,launchParam){ - // Ability is creating, initialize resources for this ability - console.info("requestStageTestAbility onCreate") - globalThis.abilityWant = want; - } - - onDestroy() { - // Ability is destroying, release resources for this ability - console.info("requestStageTestAbility onDestroy") - } - - onWindowStageCreate(windowStage) { - // Main window is created, set main page for this ability - console.info("requestStageTestAbility onWindowStageCreate") - globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/index/index", null) - console.info("requestStageTestAbility onWindowStageCreate finish") - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - console.info("requestStageTestAbility onWindowStageDestroy") - } - - onForeground() { - // Ability has brought to foreground - console.info("requestStageTestAbility onForeground") - } - - onBackground() { - // Ability has back to background - console.info("requestStageTestAbility onBackground") - } -}; \ No newline at end of file +import hilog from '@ohos.hilog'; +import Window from '@ohos.window'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import Ability from '@ohos.application.Ability'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + + var abilityDelegator: any; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var abilityDelegatorArguments: any; + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + if (abilityDelegator != undefined && abilityDelegatorArguments != undefined) { + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } else { + hilog.info(0x0000, 'testTag', '%{public}s', 'abilityDelegator or abilityDelegatorArguments is undefined!!!'); + } + } + + onDestroy() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created, set main page for this ability + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/index', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts index 4d75a0093..1b7461ea5 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts +++ b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -1,17 +1,4 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES 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 '@ohos.hilog'; import TestRunner from '@ohos.application.testRunner' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' @@ -34,11 +21,13 @@ function translateParamsToString(parameters) { } async function onAbilityCreateCallback() { - console.log("onAbilityCreateCallback"); + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); } async function addAbilityMonitorCallback(err: any) { - console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); } export default class OpenHarmonyTestRunner implements TestRunner { @@ -46,11 +35,13 @@ export default class OpenHarmonyTestRunner implements TestRunner { } onPrepare() { - console.info("OpenHarmonyTestRunner OnPrepare ") + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); } async onRun() { - console.log('OpenHarmonyTestRunner onRun run') + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' @@ -59,20 +50,22 @@ export default class OpenHarmonyTestRunner implements TestRunner { onAbilityCreate: onAbilityCreateCallback, }; abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - var cmd = 'aa start -d 0 -a com.acts.request.test.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var cmd = 'aa start -d 0 -a MainAbility ' + ' -b ' + abilityDelegatorArguments.bundleName cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) - var debug = abilityDelegatorArguments.parameters["-D"] + var debug = abilityDelegatorArguments.parameters['-D'] if (debug == 'true') { cmd += ' -D' } - console.info('cmd : '+cmd) + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); abilityDelegator.executeShellCommand(cmd, (err: any, d: any) => { - console.info('executeShellCommand : err : ' + JSON.stringify(err)); - console.info('executeShellCommand : data : ' + d.stdResult); - console.info('executeShellCommand : data : ' + d.exitCode); + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); }) - console.info('OpenHarmonyTestRunner onRun end') + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/pages/second/second.ets b/request/RequestTest_Stage/entry/src/main/ets/pages/index.ets similarity index 56% rename from request/RequestTest_Stage/entry/src/main/ets/pages/second/second.ets rename to request/RequestTest_Stage/entry/src/main/ets/pages/index.ets index f9009a3e8..e79e73a09 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/pages/second/second.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/pages/index.ets @@ -1,43 +1,38 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES 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 '@system.router'; - -@Entry -@Component -struct Second { - private content: string = "Second Page" - - build() { - Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text(`${this.content}`) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('back to index') - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => { - router.back() - }) - } - .width('100%') - .height('100%') - } +/** + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES 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 '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + + @State message: string = 'REQUEST TEST' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/pages/index/index.ets b/request/RequestTest_Stage/entry/src/main/ets/pages/index/index.ets deleted file mode 100644 index e1942ec72..000000000 --- a/request/RequestTest_Stage/entry/src/main/ets/pages/index/index.ets +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from '@ohos/hypium' -import testsuite from '../../test/List.test' - -@Entry -@Component -struct Index { - build() { - Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(25) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .onClick(() => {}) - } - .width('100%') - .height('100%') - } - - aboutToAppear(){ - let abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - let abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - console.info('start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } -} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets index 9dafbd92a..7011a1bda 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import requestUploadJSUnit from './requestUpload.test' + +import requestUploadJSUnit from './requestUpload.test'; import requestDownloadJSUnit from './requestDownload.test'; export default function testsuite() { diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets index efe308363..66b23f0d8 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets @@ -1,117 +1,115 @@ -// @ts-nocheck -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES 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 "hypium/index"; -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; -import request from "@ohos.request"; - -export default function requestDownloadJSUnit() { - describe('requestDownloadTest', function () { - console.info('################################request download Test start'); - - /** - * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. - */ - beforeAll(function () { - console.info('beforeAll: Prerequisites are executed.'); - }); - - /** - * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. - */ - beforeEach(function () { - console.info('beforeEach: Prerequisites is executed.'); - }); - - /** - * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. - */ - afterEach(function () { - console.info('afterEach: Test case-level clearance conditions is executed.'); - }); - - /** - * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. - */ - afterAll(function () { - console.info('afterAll: Test suite-level cleanup condition is executed'); - }); - - let downloadTask; - let downloadConfig = { - url: 'http://download.ci.openharmony.cn/version/Daily_Version/', - header: { - headers: 'http' - }, - enableMetered: false, - enableRoaming: false, - description: 'XTS download test!', - networkType: request.NETWORK_WIFI, - filePath: 'internal://cache/test.txt', - title: 'XTS download test!', - background: true - } - - /** - * @tc.number SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 - * @tc.desc Starts a download session. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 2 - */ - it('SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------"); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let context = abilityDelegator.getAppContext(); - try { - request.download(context, downloadConfig, (data)=>{ - downloadTask = data; - console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); - expect(true).assertEqual(downloadTask != undefined); - }); - } catch (err) { - console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err); - expect().assertFail(); - } - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------"); - done(); - }); - - /** - * @tc.number SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 - * @tc.desc Starts a download session. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 2 - */ - it('SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 is starting-----------------------"); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let context = abilityDelegator.getAppContext(); - request.download(context, downloadConfig).then(data => { - downloadTask = data; - console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); - expect(true).assertEqual(downloadTask != undefined); - }).catch(err => { - console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err); - expect().assertFail(); - }) - console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------"); - done(); - }); - - }) -} +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import request from "@ohos.request"; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function requestDownloadJSUnit() { + describe('requestDownloadJSUnit', function () { + console.info('################################request download Test start'); + + /** + * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. + */ + beforeAll(function () { + console.info('beforeAll: Prerequisites are executed.'); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(function () { + console.info('beforeEach: Prerequisites is executed.'); + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterEach(function () { + console.info('afterEach: Test case-level clearance conditions is executed.'); + }); + + /** + * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. + */ + afterAll(function () { + console.info('afterAll: Test suite-level cleanup condition is executed'); + }); + + let downloadTask; + let downloadConfig = { + url: 'http://download.ci.openharmony.cn/version/Daily_Version/', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: 'internal://cache/test.txt', + title: 'XTS download test!', + background: true + } + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 + * @tc.desc Starts a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------"); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let context = abilityDelegator.getAppContext(); + try { + request.download(context, downloadConfig, (data)=>{ + downloadTask = data; + console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); + expect(true).assertEqual(downloadTask != undefined); + }); + } catch (err) { + console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err); + expect().assertFail(); + } + console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 + * @tc.desc Starts a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 is starting-----------------------"); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let context = abilityDelegator.getAppContext(); + request.download(context, downloadConfig).then(data => { + downloadTask = data; + console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); + expect(true).assertEqual(downloadTask != undefined); + }).catch(err => { + console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err); + expect().assertFail(); + }) + console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------"); + done(); + }); + }); +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets index 0ace537e4..f131dec47 100644 --- a/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,45 +13,45 @@ * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; import request from "@ohos.request"; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; export default function requestUploadJSUnit() { - describe('requestUploadTest', function () { + describe('requestUploadJSUnit', function () { console.info('################################request upload Test start'); /** - * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. - */ + * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. + */ beforeAll(function () { console.info('beforeAll: Prerequisites are executed.'); }); /** - * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. - */ + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ beforeEach(function () { console.info('beforeEach: Prerequisites is executed.'); }); /** - * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. - */ + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ afterEach(function () { console.info('afterEach: Test case-level clearance conditions is executed.'); }); /** - * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. - */ + * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. + */ afterAll(function () { console.info('afterAll: Test suite-level cleanup condition is executed'); }); /** - * sleep function. - */ + * sleep function. + */ function sleep(date, time){ while(Date.now() - date <= time); } diff --git a/request/RequestTest_Stage/entry/src/main/module.json b/request/RequestTest_Stage/entry/src/main/module.json index c86569a67..6b6ae4c9e 100644 --- a/request/RequestTest_Stage/entry/src/main/module.json +++ b/request/RequestTest_Stage/entry/src/main/module.json @@ -1,44 +1,43 @@ -{ - "module": { - "name": "phone", - "type": "entry", - "srcEntrance": "./ets/Application/AbilityStage.ts", - "description": "$string:phone_entry_dsc", - "mainElement": "MainAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "uiSyntax": "ets", - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "com.acts.request.test.MainAbility", - "srcEntrance": "./ets/MainAbility/MainAbility.ts", - "description": "$string:phone_entry_main", - "icon": "$media:icon", - "label": "$string:entry_label", - "visible": true, - "orientation": "portrait", - "launchType": "singleton", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities":[ - "entity.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name":"ohos.permission.INTERNET", - "reason":"need use ohos.permission.INTERNET." - } - ] - } -} +{ + "module": { + "name": "entry_test", + "type": "entry", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name":"ohos.permission.INTERNET", + "reason":"need use ohos.permission.INTERNET." + } + ] + } +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/resources/base/element/color.json b/request/RequestTest_Stage/entry/src/main/resources/base/element/color.json new file mode 100644 index 000000000..62a137a61 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/resources/base/element/string.json b/request/RequestTest_Stage/entry/src/main/resources/base/element/string.json index ea8ffb9ce..03bb7d00f 100644 --- a/request/RequestTest_Stage/entry/src/main/resources/base/element/string.json +++ b/request/RequestTest_Stage/entry/src/main/resources/base/element/string.json @@ -1,36 +1,16 @@ -{ - "string": [ - { - "name": "phone_entry_dsc", - "value": "i am an entry for phone" - }, - { - "name": "phone_entry_main", - "value": "the phone entry ability" - }, - { - "name": "entry_label", - "value": "ActsImeAbilityTest" - }, - { - "name": "ime_description", - "value": "input method extension ability." - }, - { - "name": "ime_label", - "value": "inputMethod extension ability services." - }, - { - "name": "ime_label_1", - "value": "inputMethod extension ability services_1." - }, - { - "name": "description_application", - "value": "demo for test" - }, - { - "name": "app_name", - "value": "Demo" - } - ] -} +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "ActsTimeAPITest" + } + ] +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json b/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json index 6898b31d2..feec276e1 100644 --- a/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json +++ b/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,5 @@ { - "src": [ - "pages/index/index", - "pages/second/second" - ] -} \ No newline at end of file + "src": [ + "pages/index" + ] +} diff --git a/request/RequestTest_ets/entry/src/main/ets/MainAbility/pages/index.ets b/request/RequestTest_ets/entry/src/main/ets/MainAbility/pages/index.ets index 464d327c2..bb88bb327 100644 --- a/request/RequestTest_ets/entry/src/main/ets/MainAbility/pages/index.ets +++ b/request/RequestTest_ets/entry/src/main/ets/MainAbility/pages/index.ets @@ -26,7 +26,7 @@ struct MyComponent { alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Text('REQUEST ETS TEST') + Text('REQUEST TEST') .fontSize(50) .fontWeight(FontWeight.Bold) } diff --git a/request/RequestTest_ets/entry/src/main/ets/test/List.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/List.test.ets index 265cf31db..de2cdf52c 100644 --- a/request/RequestTest_ets/entry/src/main/ets/test/List.test.ets +++ b/request/RequestTest_ets/entry/src/main/ets/test/List.test.ets @@ -15,7 +15,7 @@ import requestUploadJSUnit from './requestUpload.test'; import requestDownloadJSUnit from './requestDownload.test'; -import requestSystemJSUnit from './requestSystemJSUnit'; +import requestSystemJSUnit from './requestSystem.test'; export default function testsuite() { requestUploadJSUnit() diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets index ef2bc0b7e..7ac28e4a1 100644 --- a/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; import request from "@ohos.request"; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; export default function requestDownloadJSUnit() { describe('requestDownloadTest', function () { diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestSystemJSUnit.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestSystem.test.ets similarity index 91% rename from request/RequestTest_ets/entry/src/main/ets/test/requestSystemJSUnit.ets rename to request/RequestTest_ets/entry/src/main/ets/test/requestSystem.test.ets index d5cfa3a9e..c1810e3bd 100644 --- a/request/RequestTest_ets/entry/src/main/ets/test/requestSystemJSUnit.ets +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestSystem.test.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /** * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,20 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {describe, it, expect} from 'hypium/index'; + import request from '@system.request'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; export default function requestSystemJSUnit() { describe('requestSystemJSUnit', function () { console.info('****************start requestSystemTest*****************') - /** - * sleep function. - */ - function sleep(date, time){ - while(Date.now() - date <= time); - } - /** * @tc.name: ohos.SUB_REQUESTSYSTEM_UPLOAD_API_0001 * @tc.desc: Upload files. @@ -70,14 +63,13 @@ export default function requestSystemJSUnit() { } try{ let result = request.upload(UploadRequestOptions); - sleep(500) console.info('SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload err:' + result); - expect(true).assertEqual(true) + expect(true).assertEqual(true); }catch(err){ console.info('SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload err:' + err); } console.info("-----------------------SUB_REQUESTSYSTEM_UPLOAD_API_0001 end-----------------------"); - done() + done(); }); /** @@ -109,15 +101,14 @@ export default function requestSystemJSUnit() { } } try{ - let result = request.download(DownloadRequestOptions) - sleep(500) + let result = request.download(DownloadRequestOptions); console.info('SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 upload err:' + result); - expect(result == null).assertEqual(true) + expect(result == null).assertEqual(true); }catch(err){ console.info('SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 download complete' + err); } - done() console.info("-----------------------SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 end-----------------------"); + done(); }); /** @@ -145,12 +136,11 @@ export default function requestSystemJSUnit() { console.info('SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 download complete'); } } - let result = request.onDownloadComplete(OnDownloadCompleteOptions) - sleep(500) + let result = request.onDownloadComplete(OnDownloadCompleteOptions); console.info('SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 upload err:' + result); - expect(result == null).assertEqual(true) - done() + expect(result == null).assertEqual(true); console.info("-----------------------SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 end-----------------------"); + done(); }); }) } diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets index 3d34a3779..0371cc1af 100644 --- a/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; import request from "@ohos.request"; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; export default function requestUploadJSUnit() { describe('requestUploadTest', function () { -- GitLab