Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
67251fa2
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
67251fa2
编写于
7月 11, 2023
作者:
H
hu0475
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
'request子系统跨平台API测试套,覆盖request的下载API以及常量'
Signed-off-by:
N
hu0475
<
huyanqiang5@huawei.com
>
上级
19172b16
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
1741 addition
and
0 deletion
+1741
-0
request/BUILD.gn
request/BUILD.gn
+1
-0
request/crossplatform/RequestTest_ets/AppScope/app.json
request/crossplatform/RequestTest_ets/AppScope/app.json
+16
-0
request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json
...questTest_ets/AppScope/resources/base/element/string.json
+8
-0
request/crossplatform/RequestTest_ets/AppScope/resources/base/media/app_icon.png
...equestTest_ets/AppScope/resources/base/media/app_icon.png
+0
-0
request/crossplatform/RequestTest_ets/BUILD.gn
request/crossplatform/RequestTest_ets/BUILD.gn
+46
-0
request/crossplatform/RequestTest_ets/Test.json
request/crossplatform/RequestTest_ets/Test.json
+19
-0
request/crossplatform/RequestTest_ets/signature/openharmony_sx.p7b
...rossplatform/RequestTest_ets/signature/openharmony_sx.p7b
+0
-0
request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/TestAbility.ets
.../RequestTest_ets/src/main/ets/TestAbility/TestAbility.ets
+64
-0
request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/pages/Index.ets
.../RequestTest_ets/src/main/ets/TestAbility/pages/Index.ets
+49
-0
request/crossplatform/RequestTest_ets/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
...Test_ets/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
+49
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets
...splatform/RequestTest_ets/src/main/ets/test/List.test.ets
+22
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets
...equestTest_ets/src/main/ets/test/requestConstant.test.ets
+472
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets
...equestTest_ets/src/main/ets/test/requestDownload.test.ets
+667
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/requestUpload.test.ets
.../RequestTest_ets/src/main/ets/test/requestUpload.test.ets
+239
-0
request/crossplatform/RequestTest_ets/src/main/module.json
request/crossplatform/RequestTest_ets/src/main/module.json
+60
-0
request/crossplatform/RequestTest_ets/src/main/resources/base/element/color.json
...equestTest_ets/src/main/resources/base/element/color.json
+8
-0
request/crossplatform/RequestTest_ets/src/main/resources/base/element/string.json
...questTest_ets/src/main/resources/base/element/string.json
+16
-0
request/crossplatform/RequestTest_ets/src/main/resources/base/media/icon.png
...rm/RequestTest_ets/src/main/resources/base/media/icon.png
+0
-0
request/crossplatform/RequestTest_ets/src/main/resources/base/profile/test_pages.json
...tTest_ets/src/main/resources/base/profile/test_pages.json
+5
-0
未找到文件。
request/BUILD.gn
浏览文件 @
67251fa2
...
...
@@ -19,5 +19,6 @@ group("request") {
"RequestTest_ets:ActsRequestETSApiTest",
"newRequestAuthorityTest:ActsRequestAuthorityTest",
"newRequestTest:ActsRequestNewTest",
"crossplatform/RequestTest_ets:ActsRequestETSApiCrossplatformTest"
]
}
request/crossplatform/RequestTest_ets/AppScope/app.json
0 → 100644
浏览文件 @
67251fa2
{
"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
}
}
}
request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json
0 → 100644
浏览文件 @
67251fa2
{
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"xtsDemo1"
}
]
}
request/crossplatform/RequestTest_ets/AppScope/resources/base/media/app_icon.png
0 → 100644
浏览文件 @
67251fa2
6.6 KB
request/crossplatform/RequestTest_ets/BUILD.gn
0 → 100644
浏览文件 @
67251fa2
# 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
request/crossplatform/RequestTest_ets/Test.json
0 → 100644
浏览文件 @
67251fa2
{
"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
request/crossplatform/RequestTest_ets/signature/openharmony_sx.p7b
0 → 100644
浏览文件 @
67251fa2
文件已添加
request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/TestAbility.ets
0 → 100644
浏览文件 @
67251fa2
/**
* 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
request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/pages/Index.ets
0 → 100644
浏览文件 @
67251fa2
/**
* 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
request/crossplatform/RequestTest_ets/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts
0 → 100644
浏览文件 @
67251fa2
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
request/crossplatform/RequestTest_ets/src/main/ets/test/List.test.ets
0 → 100644
浏览文件 @
67251fa2
/*
* 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
request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets
0 → 100644
浏览文件 @
67251fa2
/*
* 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();
});
})
}
request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets
0 → 100644
浏览文件 @
67251fa2
/*
* 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 fileIo from "@ohos.file.fs";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium";
const removeFile = (filePath: string): void => {
if (fileIo.accessSync(filePath)) fileIo.unlinkSync(filePath);
};
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");
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001
* *@tc.name subRequestDownloadFileStageApiCallback0001
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadFileStageApiCallback0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
} catch (e) {
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
await downloadTask.delete();
removeFile(downloadFilePath);
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------");
done();
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001
* *@tc.name subRequestDownloadFileStageApiPromise0001
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadFileStageApiPromise0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
try {
request
.downloadFile(globalThis.abilityContext, downloadFileConfig)
.then(async (downloadTask) => {
console.info("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
await downloadTask.delete();
})
.catch((err) => {
console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err);
})
.finally(() => {
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err);
done();
}
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_DELETE_0001
* *@tc.name subRequestDownloadApiDelete0001
* @tc.desc Delete the download task.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiDelete0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success.");
expect(typeof data == "boolean").assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete throw error" + err);
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (error) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error" + error);
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_DELETE_0002
* *@tc.name subRequestDownloadApiDelete0002
* @tc.desc Delete the download task.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiDelete0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.delete()
.then(async (data) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Download task delete success.");
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 end-----------------------");
})
.catch(async (err) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task.");
expect().assertFail();
})
.finally(async () => {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (error) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 delete catch error");
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0001
* *@tc.name subRequestDownloadApiSuspend0001
* @tc.desc Suspend the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiSuspend0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Download task suspend success.");
expect(data == true).assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_SUSPEND_0002
* *@tc.name subRequestDownloadApiSuspend0002
* @tc.desc Suspend the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiSuspend0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
try {
let data = await downloadTask.suspend();
expect(data == true).assertTrue();
} catch (err) {
console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 throw_err:" + JSON.stringify(err));
}
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 suspend catch error" + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_RESTORE_0001
* *@tc.name subRequestDownloadApiRestore0001
* @tc.desc Restore the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiRestore0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Download restore success.");
expect(data == true).assertTrue();
} catch (err) {
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 throw_err:" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_RESTORE_0002
* *@tc.name subRequestDownloadApiRestore0002
* @tc.desc Restore the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiRestore0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.restore()
.then(async (data) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore.");
expect(data == true).assertTrue();
await downloadTask.delete();
})
.catch(async (err) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task.");
})
.finally(async () => {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 restore catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0001
* *@tc.name subRequestDownloadApiGetTaskInfo0001
* @tc.desc Get the download task info
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiGetTaskInfo0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_GETTASKINFO_0002
* *@tc.name subRequestDownloadApiGetTaskInfo0002
* @tc.desc Get the download task info
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiGetTaskInfo0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.getTaskInfo()
.then(async (data) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.");
expect(typeof data == "object").assertTrue();
})
.catch(async (err) => {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.");
})
.finally(async () => {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002
* *@tc.name subRequestDownloadApigetTaskMimeType0002
* @tc.desc Get mimetype of the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApigetTaskMimeType0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 downloadTask: " + downloadTask);
try {
let data = await downloadTask.getTaskMimeType();
expect(data != undefined).assertEqual(true);
} catch (err) {
console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMINETYPE_0002 throw_error: " + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001
* *@tc.name subRequestDownloadApiTaskInfo0001
* @tc.desc Get the download task info, and test the field of TaskInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("subRequestDownloadApiTaskInfo0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
expect(typeof data.description == "string").assertTrue();
expect(typeof data.downloadedBytes == "number").assertTrue();
expect(typeof data.downloadId == "number").assertTrue();
expect(typeof data.failedReason == "number").assertTrue();
expect(typeof data.fileName == "string").assertTrue();
expect(typeof data.filePath == "string").assertTrue();
expect(typeof data.pausedReason == "number").assertTrue();
expect(typeof data.status == "number").assertTrue();
expect(typeof data.targetURI == "string").assertTrue();
expect(typeof data.downloadTitle == "string").assertTrue();
expect(typeof data.downloadTotalBytes == "number").assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_DOWNDLOAD_API_TASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
});
}
request/crossplatform/RequestTest_ets/src/main/ets/test/requestUpload.test.ets
0 → 100644
浏览文件 @
67251fa2
/*
* 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();
}
});
});
});
}
request/crossplatform/RequestTest_ets/src/main/module.json
0 → 100644
浏览文件 @
67251fa2
{
"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"
}
}
]
}
}
request/crossplatform/RequestTest_ets/src/main/resources/base/element/color.json
0 → 100644
浏览文件 @
67251fa2
{
"color"
:
[
{
"name"
:
"start_window_background"
,
"value"
:
"#FFFFFF"
}
]
}
\ No newline at end of file
request/crossplatform/RequestTest_ets/src/main/resources/base/element/string.json
0 → 100644
浏览文件 @
67251fa2
{
"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
request/crossplatform/RequestTest_ets/src/main/resources/base/media/icon.png
0 → 100644
浏览文件 @
67251fa2
6.6 KB
request/crossplatform/RequestTest_ets/src/main/resources/base/profile/test_pages.json
0 → 100644
浏览文件 @
67251fa2
{
"src"
:
[
"TestAbility/pages/Index"
]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录