diff --git a/request/BUILD.gn b/request/BUILD.gn old mode 100755 new mode 100644 index d366567d078a8fbb2357d1faff7ae84f46bf7964..444566b1ddcba85d77f107cb8f6686ee35e845bd --- a/request/BUILD.gn +++ b/request/BUILD.gn @@ -14,5 +14,8 @@ import("//build/ohos_var.gni") group("request") { testonly = true - deps = [ "RequestTest_ets:ActsRequestETSApiTest" ] + deps = [ + "RequestTest_Stage:ActsRequestStageTest", + "RequestTest_ets:ActsRequestETSApiTest", + ] } diff --git a/request/RequestTest_Stage/AppScope/app.json b/request/RequestTest_Stage/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..4817f2f10f8ad7d1ae42d6feaea6a262340dfb62 --- /dev/null +++ b/request/RequestTest_Stage/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "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 + } + } +} diff --git a/request/RequestTest_Stage/AppScope/resources/base/element/string.json b/request/RequestTest_Stage/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/request/RequestTest_Stage/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"ohosProject" + } + ] +} \ No newline at end of file diff --git a/request/RequestTest_Stage/AppScope/resources/base/media/app_icon.png b/request/RequestTest_Stage/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/request/RequestTest_Stage/AppScope/resources/base/media/app_icon.png differ diff --git a/request/RequestTest_Stage/BUILD.gn b/request/RequestTest_Stage/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bc2405f195f82135677cf7fe5b557b460e88b101 --- /dev/null +++ b/request/RequestTest_Stage/BUILD.gn @@ -0,0 +1,43 @@ +# 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("//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" + part_name = "request" +} + +ohos_app_scope("requestStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("requestStage_ets_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("requestStage_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":requestStage_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/request/RequestTest_Stage/Test.json b/request/RequestTest_Stage/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..a1fc50004439982c33e2b2454e4f48ae0c8bdc63 --- /dev/null +++ b/request/RequestTest_Stage/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.acts.request.test", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [{ + "test-file-name": [ + "ActsRequestStageTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} diff --git a/request/RequestTest_Stage/entry/src/main/ets/Application/AbilityStage.ts b/request/RequestTest_Stage/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..36a8a495dd6e3323415a2787786eb52eb840a229 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * 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/MainAbility/MainAbility.ts b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..abed5a69dffbe089d8937cf5a9517296d6a8ad7a --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,51 @@ +/* + * 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 diff --git a/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..4d75a00938c8ab6cdeb29bff574dbc371e438966 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a com.acts.request.test.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+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); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..e1942ec72fc60a6c599964b5145e31b564bac3a7 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,51 @@ +/* + * 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/pages/second/second.ets b/request/RequestTest_Stage/entry/src/main/ets/pages/second/second.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9009a3e8567d1f4557ebc11dded54c7e27c0b0d --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * 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%') + } +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..9dafbd92a863cbb8ed96db842ca2cb81f5814084 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * 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 requestUploadJSUnit from './requestUpload.test' +import requestDownloadJSUnit from './requestDownload.test'; + +export default function testsuite() { + requestUploadJSUnit() + requestDownloadJSUnit() +} \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..efe308363f72e1a603485da97dfb9248fbf39f15 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets @@ -0,0 +1,117 @@ +// @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(); + }); + + }) +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..0ace537e403ec461e18373c1fa7bb4caf293d5e7 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets @@ -0,0 +1,168 @@ +// @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 requestUploadJSUnit() { + describe('requestUploadTest', function () { + console.info('################################request upload 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'); + }); + + /** + * sleep function. + */ + function sleep(date, time){ + while(Date.now() - date <= time); + } + + let uploadTask; + let RequestData = { + name: 'name', + value: '123' + } + + let File = { + filename: 'test', + name: 'test', + uri: 'internal://cache/test.txt', + type: 'txt' + } + + let uploadConfig = { + url: 'http://127.0.0.1', + header: { + headers: 'http' + }, + method: 'POST', + files: [File], + data: [RequestData] + }; + + /** + * @tc.number SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------"); + try { + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig)); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let appContext = abilityDelegator.getAppContext(); + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 context = " + appContext); + request.upload(appContext, uploadConfig, (data) => { + uploadTask = data; + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask)); + expect(true).assertEqual(uploadTask != undefined); + + uploadTask.on('progress', function (data1, data2) { + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data1 =" + data1); + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data2 =" + data2); + }); + + uploadTask.off('progress', function (data1, data2) { + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data1 =" + data1); + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data2 =" + data2); + }); + + uploadTask.remove((err, data) => { + console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 remove =" + data); + }); + }); + } catch (err) { + console.error("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 error: " + err); + expect().assertFail(); + } + console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 end-----------------------"); + done(); + }); + + /* + * @tc.number : SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Mixed strings value can be obtained correctly + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 is starting-----------------------"); + try { + console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let appContext = abilityDelegator.getAppContext(); + console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 context = " + appContext); + request.upload(appContext, uploadConfig).then((data) => { + uploadTask = data; + console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 uploadTask = " + uploadTask); + expect(true).assertEqual(uploadTask != undefined); + + uploadTask.on('headerReceive', (header) => { + console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header); + expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); + }); + + uploadTask.off('headerReceive', (header) => { + console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header); + expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); + }); + + uploadTask.remove().then((result)=>{ + console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 remove result = " + result); + expect(result).assertEqual(true); + }); + }); + } catch (e) { + console.error("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 error: " + JSON.stringify(e)); + expect(e).assertFail(); + } + console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 end-----------------------"); + done(); + }); + }) +} diff --git a/request/RequestTest_Stage/entry/src/main/module.json b/request/RequestTest_Stage/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..c86569a6784c96838c4327cf3ec58f04952f6e1c --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/module.json @@ -0,0 +1,44 @@ +{ + "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." + } + ] + } +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..ea8ffb9ce5faaafb968771c65a5ac50db871e1ff --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "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" + } + ] +} diff --git a/request/RequestTest_Stage/entry/src/main/resources/base/media/icon.png b/request/RequestTest_Stage/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/request/RequestTest_Stage/entry/src/main/resources/base/media/icon.png differ 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 new file mode 100644 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/request/RequestTest_ets/signature/openharmony_sx.p7b b/request/RequestTest_Stage/signature/actsRequestStageTest.p7b old mode 100755 new mode 100644 similarity index 51% rename from request/RequestTest_ets/signature/openharmony_sx.p7b rename to request/RequestTest_Stage/signature/actsRequestStageTest.p7b index 66b4457a8a81fb8d3356cf46d67226c850944858..ace47eb1405f4a1f3c7c2622371a48c345568f9b Binary files a/request/RequestTest_ets/signature/openharmony_sx.p7b and b/request/RequestTest_Stage/signature/actsRequestStageTest.p7b differ diff --git a/request/RequestTest_ets/BUILD.gn b/request/RequestTest_ets/BUILD.gn old mode 100755 new mode 100644 index ef14e8bc878e0c669cf2b4371c5bda37307a259f..fe28b739c45939b9b6a65555b26ed5e7548e4a24 --- a/request/RequestTest_ets/BUILD.gn +++ b/request/RequestTest_ets/BUILD.gn @@ -23,7 +23,7 @@ ohos_js_hap_suite("ActsRequestETSApiTest") { ets2abc = true subsystem_name = "request" part_name = "request" - certificate_profile = "./signature/openharmony_sx.p7b" + certificate_profile = "./signature/ActsRequestETSApiTest.p7b" hap_name = "ActsRequestETSApiTest" } diff --git a/request/RequestTest_ets/Test.json b/request/RequestTest_ets/Test.json old mode 100755 new mode 100644 index 2ea5f5cbe3c5470a9a53b66cf223298d3641667e..d987eb48cad9d4281dea0ced1d8a7387d19f5b06 --- a/request/RequestTest_ets/Test.json +++ b/request/RequestTest_ets/Test.json @@ -5,7 +5,7 @@ "test-timeout": "600000", "bundle-name": "com.acts.requesttest", "package-name": "com.acts.requesttest", - "shell-timeout": "60000" + "shell-timeout": "600000" }, "kits": [ { diff --git a/request/RequestTest_ets/entry/src/main/config.json b/request/RequestTest_ets/entry/src/main/config.json old mode 100755 new mode 100644 index c69658fa4ef8c91fd18ca06c46831abd310010c1..33d2f04509db6efe431bc32bbfaa56437424312a --- a/request/RequestTest_ets/entry/src/main/config.json +++ b/request/RequestTest_ets/entry/src/main/config.json @@ -62,6 +62,18 @@ "launchType": "standard" } ], + "reqPermissions": [ + { + "name": "ohos.permission.INTERNET", + "reason": "need use ohos.permission.INTERNET", + "usedScene": { + "ability": [ + "com.acts.request.test.MainAbility" + ], + "when": "inuse" + } + } + ], "js": [ { "mode": { diff --git a/request/RequestTest_ets/entry/src/main/ets/MainAbility/app.ets b/request/RequestTest_ets/entry/src/main/ets/MainAbility/app.ets old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 diff --git a/request/RequestTest_ets/entry/src/main/ets/TestAbility/app.ets b/request/RequestTest_ets/entry/src/main/ets/TestAbility/app.ets old mode 100755 new mode 100644 diff --git a/request/RequestTest_ets/entry/src/main/ets/TestAbility/pages/index.ets b/request/RequestTest_ets/entry/src/main/ets/TestAbility/pages/index.ets old mode 100755 new mode 100644 diff --git a/request/RequestTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/request/RequestTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts old mode 100755 new mode 100644 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 old mode 100755 new mode 100644 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 83da052b3417301e19e5d1117f19444c19fc0c08..ef2bc0b7e4c64a9d06c82136ddcaa694a6a05d28 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 @@ -52,7 +52,7 @@ export default function requestDownloadJSUnit() { let downloadTask; let downloadConfig = { - url: 'http://download.ci.openharmony.cn/version/Daily_Version/', + url: 'http://127.0.0.1', header: { headers: 'http' }, @@ -60,7 +60,7 @@ export default function requestDownloadJSUnit() { enableRoaming: false, description: 'XTS download test!', networkType: request.NETWORK_WIFI, - filePath: 'internal://cache/test.txt', + filePath: 'test.txt', title: 'XTS download test!', background: true } @@ -88,31 +88,6 @@ export default function requestDownloadJSUnit() { done(); }); - /** - * @tc.number SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 - * @tc.desc Starts a download session. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 2 - */ - it('SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 is starting-----------------------"); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let context = abilityDelegator.getAppContext(); - try { - request.download(context, downloadConfig, (data)=>{ - downloadTask = data; - console.info("SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 downloadTask: " + downloadTask); - expect(downloadTask != undefined).assertEqual(true); - }); - } catch (err) { - console.error("SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 error: " + err); - expect().assertFail(); - } - console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 end-----------------------"); - done(); - }); - /** * @tc.number SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 * @tc.desc Starts a download session. @@ -134,29 +109,6 @@ export default function requestDownloadJSUnit() { done(); }); - /** - * @tc.number SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 - * @tc.desc Starts a download session. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 2 - */ - it('SUB_REQUEST_DOWNLOAD_API_PROMISE_0002', 0, async function (done) { - console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 is starting-----------------------"); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let context = abilityDelegator.getAppContext(); - request.download(context, downloadConfig).then(data => { - downloadTask = data; - console.info("SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 downloadTask: " + downloadTask); - expect(downloadTask != undefined).assertEqual(true); - }).catch(err => { - console.error("SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 error: " + err); - expect().assertFail(); - }) - console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 end-----------------------"); - done(); - }); - /** * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 * @tc.desc alled when the current download session is in process. @@ -169,12 +121,12 @@ export default function requestDownloadJSUnit() { request.download( downloadConfig, (data)=>{ downloadTask = data; console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 downloadTask: " + downloadTask); - expect(downloadTask != undefined).assertEqual(true); + expect(true).assertEqual(downloadTask != undefined); downloadTask.on('progress', (data1, data2) => { console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data1 =" + data1); console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data2 =" + data2); - expect(data1 != undefined).assertEqual(true); - expect(data2 != undefined).assertEqual(true); + expect(true).assertEqual(data1 != undefined); + expect(true).assertEqual(data2 != undefined); }); }); @@ -194,7 +146,7 @@ export default function requestDownloadJSUnit() { request.download( downloadConfig, (data)=>{ downloadTask = data; console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: " + downloadTask); - expect(downloadTask != undefined).assertEqual(true); + expect(true).assertEqual(downloadTask != undefined); try{ downloadTask.on('complete', () => { console.info('SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 task completed.') @@ -220,7 +172,7 @@ export default function requestDownloadJSUnit() { request.download( downloadConfig, (data)=>{ downloadTask = data; console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: " + downloadTask); - expect(downloadTask != undefined).assertEqual(true); + expect(true).assertEqual(downloadTask != undefined); try{ downloadTask.on('pause', () => { console.info('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task pause.') 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 0db63d0627463433e76d1a67bef99078b3bf5c39..30d02c27dd8094fa1cae9f782654a1788008c272 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 @@ -255,49 +255,6 @@ export default function requestUploadJSUnit() { done(); }); - /** - * @tc.number SUB_REQUEST_UPLOAD_API_CALLBACK_0002 - * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME - * @tc.desc Test requestUploadTest API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 1 - */ - it('SUB_REQUEST_UPLOAD_API_CALLBACK_0002', 0, async function (done) { - console.info("-----------------------Request_test_0006 is starting-----------------------"); - try { - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 uploadConfig = " + JSON.stringify(uploadConfig)); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let appContext = abilityDelegator.getAppContext(); - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 context = " + appContext); - request.upload(appContext, uploadConfig, (data) => { - uploadTask = data; - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 progress uploadTask =" + JSON.stringify(uploadTask)); - expect(uploadTask != undefined).assertEqual(true); - - uploadTask.on('progress', function (data1, data2) { - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 on data1 =" + data1); - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 on data2 =" + data2); - }); - - uploadTask.off('progress', function (data1, data2) { - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 off data1 =" + data1); - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 off data2 =" + data2); - }); - - uploadTask.remove((err, data) => { - console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 remove =" + data); - }); - }); - } catch (err) { - console.error("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 error: " + err); - expect().assertFail(); - } - sleep(Date.now(), 20000); - console.info("-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0002 end-----------------------"); - done(); - }); - /* * @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0001 * @tc.name : Use getEntries get the value by mixing the string key @@ -307,6 +264,7 @@ export default function requestUploadJSUnit() { * @tc.level : Level 1 */ it('SUB_REQUEST_UPLOAD_API_PROMISE_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------"); try { console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); request.upload(uploadConfig).then((data) => { @@ -331,52 +289,12 @@ export default function requestUploadJSUnit() { }); } catch (e) { console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e)); - expect(e).assertFail(); + expect(true).assertFail(true); } sleep(Date.now(), 20000); + console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------"); done(); }); - /* - * @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0002 - * @tc.name : Use getEntries get the value by mixing the string key - * @tc.desc : Mixed strings value can be obtained correctly - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 1 - */ - it('SUB_REQUEST_UPLOAD_API_PROMISE_0002', 0, async function (done) { - try { - console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 UploadConfig = " + JSON.stringify(uploadConfig)); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let appContext = abilityDelegator.getAppContext(); - console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 context = " + appContext); - request.upload(appContext, uploadConfig).then((data) => { - uploadTask = data; - console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 uploadTask = " + uploadTask); - expect(data != undefined).assertEqual(true); - - uploadTask.on('headerReceive', (header) => { - console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 header = " + header); - expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); - }); - - uploadTask.off('headerReceive', (header) => { - console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 header = " + header); - expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); - }); - - uploadTask.remove().then((result)=>{ - console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 remove result = " + result); - expect(result).assertEqual(true); - }); - }); - } catch (e) { - console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(e)); - expect(e).assertFail(); - } - sleep(Date.now(), 20000); - done(); - }); }) } diff --git a/request/RequestTest_ets/entry/src/main/resources/base/element/string.json b/request/RequestTest_ets/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/request/RequestTest_ets/entry/src/main/resources/base/media/icon.png b/request/RequestTest_ets/entry/src/main/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b b/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..57f4a2edec6549dfa915e017b9a994b1d9b39c0a Binary files /dev/null and b/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b differ diff --git a/theme/wallpaper_ets/entry/src/main/config.json b/theme/wallpaper_ets/entry/src/main/config.json index b4f940dc87485ac1f2ef66b37eb08eca5bb883e7..1d46f06db6513a8dc849635922878d6195bfdafe 100755 --- a/theme/wallpaper_ets/entry/src/main/config.json +++ b/theme/wallpaper_ets/entry/src/main/config.json @@ -70,10 +70,24 @@ ], "reqPermissions": [ { - "name": "ohos.permission.SET_WALLPAPER" + "name": "ohos.permission.SET_WALLPAPER", + "reason": "need use ohos.permission.SET_WALLPAPER", + "usedScene": { + "ability": [ + "com.acts.theme.wallpapertest.MainAbility" + ], + "when": "inuse" + } }, { - "name": "ohos.permission.GET_WALLPAPER" + "name": "ohos.permission.GET_WALLPAPER", + "reason": "need use ohos.permission.GET_WALLPAPER", + "usedScene": { + "ability": [ + "com.acts.theme.wallpapertest.MainAbility" + ], + "when": "inuse" + } } ], "js": [