提交 67251fa2 编写于 作者: H hu0475

'request子系统跨平台API测试套,覆盖request的下载API以及常量'

Signed-off-by: Nhu0475 <huyanqiang5@huawei.com>
上级 19172b16
......@@ -19,5 +19,6 @@ group("request") {
"RequestTest_ets:ActsRequestETSApiTest",
"newRequestAuthorityTest:ActsRequestAuthorityTest",
"newRequestTest:ActsRequestNewTest",
"crossplatform/RequestTest_ets:ActsRequestETSApiCrossplatformTest"
]
}
{
"app": {
"bundleName": "ohos.acts.request.crossplatform.request",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
{
"string": [
{
"name": "app_name",
"value": "xtsDemo1"
}
]
}
# 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("ActsRequestETSApiCrossplatformTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
# hap_name: HAP的名字,可选,默认为目标名
hap_name = "ActsRequestETSApiCrossplatformTest"
subsystem_name = "request"
part_name = "request"
}
ohos_app_scope("windowStage_app_profile") {
# app_profile: HAP的AppScope中的app.json,只在Stage模型下使用
app_profile = "AppScope/app.json"
# sources: 资源文件路径
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
# source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
# sources: 资源文件路径
sources = [ "src/main/resources" ]
# deps: 当前目标的依赖
deps = [ ":windowStage_app_profile" ]
# hap_profile: HAP的config.json,Stage模型对应module.json
hap_profile = "src/main/module.json"
}
\ No newline at end of file
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.request.crossplatform.request",
"module-name": "crossplatform_request_test_ets"
},
"kits": [
{
"test-file-name": [
"ActsRequestETSApiCrossplatformTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/**
* 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 UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility 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.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
globalThis.abilityContext = this.context;
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
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. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/**
* 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.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page 123')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
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 ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* 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 requestDownloadJSUnit from './requestDownload.test';
import requestConstantJSUnit from './requestConstant.test';
export default function testsuite() {
requestDownloadJSUnit()
requestConstantJSUnit()
}
\ No newline at end of file
/*
* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function requestUploadJSUnit() {
describe('requestConstantJSUnit', 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');
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0001
* *@tc.name subRequestConstant0001
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0001 is starting-----------------------");
expect(typeof request.EXCEPTION_PERMISSION == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0002
* *@tc.name subRequestConstant0002
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0002 is starting-----------------------");
expect(typeof request.EXCEPTION_PARAMCHECK == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0003
* *@tc.name subRequestConstant0003
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0003', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0003 is starting-----------------------");
expect(typeof request.EXCEPTION_UNSUPPORTED == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0004
* *@tc.name subRequestConstant0004
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0004', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0004 is starting-----------------------");
expect(typeof request.EXCEPTION_FILEIO == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0005
* *@tc.name subRequestConstant0005
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0005', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0005 is starting-----------------------");
expect(typeof request.EXCEPTION_FILEPATH == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0006
* *@tc.name subRequestConstant0006
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0006', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0006 is starting-----------------------");
expect(typeof request.EXCEPTION_SERVICE == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0007
* *@tc.name subRequestConstant0007
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0007', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0007 is starting-----------------------");
expect(typeof request.EXCEPTION_OTHERS == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0008
* *@tc.name subRequestConstant0008
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0008', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0008 is starting-----------------------");
expect(typeof request.NETWORK_MOBILE == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0009
* *@tc.name subRequestConstant0009
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0009', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0009 is starting-----------------------");
expect(typeof request.NETWORK_WIFI == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0010
* *@tc.name subRequestConstant0010
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0010', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0010 is starting-----------------------");
expect(typeof request.ERROR_CANNOT_RESUME == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0011
* *@tc.name subRequestConstant0011
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0011', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0011 is starting-----------------------");
expect(typeof request.ERROR_DEVICE_NOT_FOUND == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0012
* *@tc.name subRequestConstant0012
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0012', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0012 is starting-----------------------");
expect(typeof request.ERROR_FILE_ALREADY_EXISTS == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0013
* *@tc.name subRequestConstant0013
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0013', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0013 is starting-----------------------");
expect(typeof request.ERROR_FILE_ERROR == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0014
* *@tc.name subRequestConstant0014
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0014', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0014 is starting-----------------------");
expect(typeof request.ERROR_HTTP_DATA_ERROR == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0015
* *@tc.name subRequestConstant0015
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0015', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0015 is starting-----------------------");
expect(typeof request.ERROR_INSUFFICIENT_SPACE == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0016
* *@tc.name subRequestConstant0016
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0016', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0016 is starting-----------------------");
expect(typeof request.ERROR_TOO_MANY_REDIRECTS == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0017
* *@tc.name subRequestConstant0017
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0017', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0017 is starting-----------------------");
expect(typeof request.ERROR_UNHANDLED_HTTP_CODE == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0018
* *@tc.name subRequestConstant0018
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0018', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0018 is starting-----------------------");
expect(typeof request.ERROR_UNKNOWN == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0019
* *@tc.name subRequestConstant0019
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0019', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0019 is starting-----------------------");
expect(typeof request.ERROR_OFFLINE == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0020
* *@tc.name subRequestConstant0020
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0020', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0020 is starting-----------------------");
expect(typeof request.ERROR_UNSUPPORTED_NETWORK_TYPE == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0021
* *@tc.name subRequestConstant0021
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0021', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0021 is starting-----------------------");
expect(typeof request.PAUSED_QUEUED_FOR_WIFI == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0022
* *@tc.name subRequestConstant0022
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0022', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0022 is starting-----------------------");
expect(typeof request.PAUSED_WAITING_FOR_NETWORK == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0023
* *@tc.name subRequestConstant0023
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0023', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0023 is starting-----------------------");
expect(typeof request.PAUSED_WAITING_TO_RETRY == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0024
* *@tc.name subRequestConstant0024
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0024', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0024 is starting-----------------------");
expect(typeof request.PAUSED_BY_USER == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0025
* *@tc.name subRequestConstant0025
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0025', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0025 is starting-----------------------");
expect(typeof request.PAUSED_UNKNOWN == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0026
* *@tc.name subRequestConstant0026
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0026', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0026 is starting-----------------------");
expect(typeof request.SESSION_SUCCESSFUL == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0027
* *@tc.name subRequestConstant0027
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0027', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0027 is starting-----------------------");
expect(typeof request.SESSION_RUNNING == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0028
* *@tc.name subRequestConstant0028
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0028', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0028 is starting-----------------------");
expect(typeof request.SESSION_PENDING == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0029
* *@tc.name subRequestConstant0029
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0029', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0029 is starting-----------------------");
expect(typeof request.SESSION_PAUSED == 'number').assertTrue();
done();
});
/**
* @tc.number SUB_REQUEST_CONSTANT_0030
* *@tc.name subRequestConstant0030
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('subRequestConstant0030', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0030 is starting-----------------------");
expect(typeof request.SESSION_FAILED == 'number').assertTrue();
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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium";
export default function requestUploadJSUnit() {
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(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 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_API_DELETE_0001
* *@tc.name subRequestUploadApiDelete0001
* @tc.desc upload file and delete the upload task.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestUploadApiDelete0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
try {
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask task delete success.");
expect(typeof data == "boolean").assertTrue();
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 end-----------------------");
done();
} catch (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete error" + err);
done();
}
});
} catch (error) {
console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete catch error" + error);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0002
* *@tc.name subRequestUploadApiDelete0002
* @tc.desc upload file and delete the upload task (Promise).
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestUploadApiDelete0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
try {
expect(uploadTask != undefined).assertEqual(true);
uploadTask
.delete()
.then((data) => {
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete data:" + JSON.stringify(data));
expect(data).assertEqual(true);
done();
})
.catch((err) => {
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task.");
expect().assertFail();
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete catch err");
done();
}
});
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_EVENT_0001
* *@tc.name subRequestUploadApiEvent0001
* @tc.desc upload file and test event.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestUploadApiEvent0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_EVENT_0001 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_UPLOAD_API_EVENT_0001 uploadTask: " + uploadTask);
try {
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on("progress", (uploadedSize, totalSize) => {
expect(uploadedSize != undefined).assertEqual(true);
expect(totalSize != undefined).assertEqual(true);
uploadTask.off("progress", (uploadedSize, totalSize) => {
expect(uploadedSize != undefined).assertEqual(true);
expect(totalSize != undefined).assertEqual(true);
});
});
done();
} catch (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_EVENT_0001 delete catch err");
done();
}
});
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_EVENT_0002
* *@tc.name subRequestUploadApiEvent0002
* @tc.desc upload file and test event.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestUploadApiEvent0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_EVENT_0002 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_UPLOAD_API_EVENT_0002 uploadTask: " + uploadTask);
try {
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on("headerReceive", (header) => {
expect(header != undefined).assertEqual(true);
uploadTask.off("headerReceive", (header) => {
expect(header != undefined).assertEqual(true);
});
});
done();
} catch (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_EVENT_0002 delete catch err");
done();
}
});
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_EVENT_0003
* *@tc.name subRequestUploadApiEvent0003
* @tc.desc upload file and test event.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestUploadApiEvent0003", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_EVENT_0003 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_UPLOAD_API_EVENT_0003 uploadTask: " + uploadTask);
try {
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on("complete", (taskStates) => {
const task = taskStates.length != 0 ? taskStates[0] : null;
if (task) {
expect(task.path != null).assertEqual(true);
expect(task.responseCode != null).assertEqual(true);
expect(task.message != null).assertEqual(true);
} else {
console.info("SUB_REQUEST_UPLOAD_API_EVENT_0003: task is null");
expect().assertFail();
done();
}
uploadTask.off("complete", (taskStates) => {
expect(taskStates != undefined).assertEqual(true);
});
});
done();
} catch (err) {
console.error("====>SUB_REQUEST_UPLOAD_API_EVENT_0003 delete catch err");
done();
}
});
});
});
}
{
"module": {
"name": "crossplatform_request_test_ets",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name":"ohos.permission.INTERNET",
"reason":"need use ohos.permission.INTERNET."
},
{"name": "ohos.permission.WRITE_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
},
{"name": "ohos.permission.READ_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册