Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
27d41ad1
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看板
未验证
提交
27d41ad1
编写于
7月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!9293 request子系统跨平台API测试套,覆盖request的下载API以及常量
Merge pull request !9293 from huyanqiang/master
上级
88c5c006
1a161190
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
2935 addition
and
0 deletion
+2935
-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
+50
-0
request/crossplatform/RequestTest_ets/Test.json
request/crossplatform/RequestTest_ets/Test.json
+29
-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
+24
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/RequestUpload.test.ets
.../RequestTest_ets/src/main/ets/test/RequestUpload.test.ets
+541
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets
...equestTest_ets/src/main/ets/test/requestConstant.test.ets
+96
-0
request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets
...equestTest_ets/src/main/ets/test/requestDownload.test.ets
+1919
-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
浏览文件 @
27d41ad1
...
...
@@ -17,6 +17,7 @@ group("request") {
deps = [
"RequestTest_Stage:ActsRequestStageTest",
"RequestTest_ets:ActsRequestETSApiTest",
"crossplatform/RequestTest_ets:ActsRequestETSApiCrossplatformTest",
"newRequestAuthorityTest:ActsRequestAuthorityTest",
"newRequestTest:ActsRequestNewTest",
]
...
...
request/crossplatform/RequestTest_ets/AppScope/app.json
0 → 100644
浏览文件 @
27d41ad1
{
"app"
:
{
"bundleName"
:
"ohos.acts.request.crossplatform.request"
,
"vendor"
:
"example"
,
"versionCode"
:
1000000
,
"versionName"
:
"1.0.0"
,
"icon"
:
"$media:app_icon"
,
"label"
:
"$string:app_name"
,
"minAPIVersion"
:
10
,
"targetAPIVersion"
:
10
,
"car"
:
{
"apiCompatibleVersion"
:
10
,
"singleUser"
:
false
}
}
}
request/crossplatform/RequestTest_ets/AppScope/resources/base/element/string.json
0 → 100644
浏览文件 @
27d41ad1
{
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"ActsRequestETSApiCrossplatformTest"
}
]
}
request/crossplatform/RequestTest_ets/AppScope/resources/base/media/app_icon.png
0 → 100644
浏览文件 @
27d41ad1
6.6 KB
request/crossplatform/RequestTest_ets/BUILD.gn
0 → 100644
浏览文件 @
27d41ad1
# Copyright (C) 2023 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"
}
request/crossplatform/RequestTest_ets/Test.json
0 → 100644
浏览文件 @
27d41ad1
{
"description"
:
"Configuration for hjunit demo Tests"
,
"driver"
:
{
"type"
:
"OHJSUnitTest"
,
"test-timeout"
:
"60000"
,
"shell-timeout"
:
"60000"
,
"testcase-timeout"
:
15000
,
"bundle-name"
:
"ohos.acts.request.crossplatform.request"
,
"module-name"
:
"crossplatform_request_test_ets"
},
"kits"
:
[
{
"test-file-name"
:
[
"ActsRequestETSApiCrossplatformTest.hap"
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"power-shell wakeup"
,
"power-shell setmode 602"
,
"uinput -T -m 300 720 300 360 200"
,
"uinput -T -m 650 2760 650 1380 200"
]
}
]
}
\ No newline at end of file
request/crossplatform/RequestTest_ets/signature/openharmony_sx.p7b
0 → 100644
浏览文件 @
27d41ad1
文件已添加
request/crossplatform/RequestTest_ets/src/main/ets/TestAbility/TestAbility.ets
0 → 100644
浏览文件 @
27d41ad1
/**
* Copyright (c) 2023 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
浏览文件 @
27d41ad1
/**
* 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
浏览文件 @
27d41ad1
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
浏览文件 @
27d41ad1
/*
* Copyright (c) 2023 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 crossplatformRequestDownloadTest from './requestDownload.test';
import crossplatformRequestConstantTest from './requestConstant.test';
import crossplatformRequestUploadTest from './RequestUpload.test';
export default function testsuite() {
crossplatformRequestDownloadTest();
crossplatformRequestConstantTest();
crossplatformRequestUploadTest();
}
\ No newline at end of file
request/crossplatform/RequestTest_ets/src/main/ets/test/RequestUpload.test.ets
0 → 100644
浏览文件 @
27d41ad1
/*
* Copyright (c) 2023 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";
function prepareFile(fpath, content) {
try {
let file = fileIO.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE);
fileIO.truncateSync(file.fd);
fileIO.writeSync(file.fd, content);
fileIO.fsyncSync(file.fd);
fileIO.closeSync(file);
return true;
} catch (e) {
console.log("Failed to prepareFile for " + e);
return false;
}
}
export default function requestUploadCrossplatformJSUnit() {
let testFilePath = '';
describe('requestUploadCrossplatformTest', 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.');
testFilePath = globalThis.abilityContext.cacheDir + '/test.txt';
console.log('testFilePath: ' + testFilePath)
prepareFile(testFilePath, '123');
});
/**
* 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 uploadTask;
let RequestData = {
name: 'name',
value: '123'
}
let File = {
filename: 'test',
name: 'test',
uri: 'internal://cache/test.txt',
type: 'txt'
}
let uploadConfig = {
url: 'http://127.0.0.1',
header: {
headers: 'http'
},
method: 'POST',
files: [File],
data: [RequestData]
};
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.NETWORK_MOBILE:" + request.NETWORK_MOBILE);
expect(request.NETWORK_MOBILE).assertEqual(1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.NETWORK_WIFI:" + request.NETWORK_WIFI);
expect(request.NETWORK_WIFI).assertEqual(65536);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.ERROR_CANNOT_RESUME:" + request.ERROR_CANNOT_RESUME);
expect(request.ERROR_CANNOT_RESUME).assertEqual(0);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 request.ERROR_DEVICE_NOT_FOUND:" + request.ERROR_DEVICE_NOT_FOUND);
expect(request.ERROR_DEVICE_NOT_FOUND).assertEqual(1);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_FILE_ALREADY_EXISTS:" + request.ERROR_FILE_ALREADY_EXISTS);
expect(request.ERROR_FILE_ALREADY_EXISTS).assertEqual(2);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_FILE_ERROR:" + request.ERROR_FILE_ERROR);
expect(request.ERROR_FILE_ERROR).assertEqual(3);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_HTTP_DATA_ERROR:" + request.ERROR_HTTP_DATA_ERROR);
expect(request.ERROR_HTTP_DATA_ERROR).assertEqual(4);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 request.ERROR_INSUFFICIENT_SPACE:" + request.ERROR_INSUFFICIENT_SPACE);
expect(request.ERROR_INSUFFICIENT_SPACE).assertEqual(5);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0002 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.ERROR_TOO_MANY_REDIRECTS:" + request.ERROR_TOO_MANY_REDIRECTS);
expect(request.ERROR_TOO_MANY_REDIRECTS).assertEqual(6);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.ERROR_UNHANDLED_HTTP_CODE:" + request.ERROR_UNHANDLED_HTTP_CODE);
expect(request.ERROR_UNHANDLED_HTTP_CODE).assertEqual(7);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.ERROR_UNKNOWN:" + request.ERROR_UNKNOWN);
expect(request.ERROR_UNKNOWN).assertEqual(8);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 request.PAUSED_QUEUED_FOR_WIFI:" + request.PAUSED_QUEUED_FOR_WIFI);
expect(request.PAUSED_QUEUED_FOR_WIFI).assertEqual(0);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0003 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_UNKNOWN:" + request.PAUSED_UNKNOWN);
expect(request.PAUSED_UNKNOWN).assertEqual(4);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_WAITING_FOR_NETWORK:" + request.PAUSED_WAITING_FOR_NETWORK);
expect(request.PAUSED_WAITING_FOR_NETWORK).assertEqual(1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_WAITING_TO_RETRY:" + request.PAUSED_WAITING_TO_RETRY);
expect(request.PAUSED_WAITING_TO_RETRY).assertEqual(2);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 request.PAUSED_BY_USER:" + request.PAUSED_BY_USER);
expect(request.PAUSED_BY_USER).assertEqual(3);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0004 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_FAILED:" + request.SESSION_FAILED);
expect(request.SESSION_FAILED).assertEqual(4);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_PAUSED:" + request.SESSION_PAUSED);
expect(request.SESSION_PAUSED).assertEqual(3);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_PENDING:" + request.SESSION_PENDING);
expect(request.SESSION_PENDING).assertEqual(2);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_RUNNING:" + request.SESSION_RUNNING);
expect(request.SESSION_RUNNING).assertEqual(1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 request.SESSION_SUCCESSFUL:" + request.SESSION_SUCCESSFUL);
expect(request.SESSION_SUCCESSFUL).assertEqual(0);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0005 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_PERMISSION:" + request.EXCEPTION_PERMISSION);
expect(request.EXCEPTION_PERMISSION).assertEqual(201);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_PARAMCHECK:" + request.EXCEPTION_PARAMCHECK);
expect(request.EXCEPTION_PARAMCHECK).assertEqual(401);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_UNSUPPORTED:" + request.EXCEPTION_UNSUPPORTED);
expect(request.EXCEPTION_UNSUPPORTED).assertEqual(801);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_FILEIO:" + request.EXCEPTION_FILEIO);
expect(request.EXCEPTION_FILEIO).assertEqual(13400001);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_FILEPATH:" + request.EXCEPTION_FILEPATH);
expect(request.EXCEPTION_FILEPATH).assertEqual(13400002);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_SERVICE:" + request.EXCEPTION_SERVICE);
expect(request.EXCEPTION_SERVICE).assertEqual(13400003);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.EXCEPTION_OTHERS:" + request.EXCEPTION_OTHERS);
expect(request.EXCEPTION_OTHERS).assertEqual(13499999);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.ERROR_OFFLINE:" + request.ERROR_OFFLINE);
expect(request.ERROR_OFFLINE).assertEqual(9);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 request.ERROR_UNSUPPORTED_NETWORK_TYPE:" + request.ERROR_UNSUPPORTED_NETWORK_TYPE);
expect(request.ERROR_UNSUPPORTED_NETWORK_TYPE).assertEqual(10);
} catch (err) {
expect().assertFail();
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 error: " + err);
}
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0006 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig, async (err, uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on('progress', (data1, data2) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 on data1 =" + data1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 on data2 =" + data2);
});
uploadTask.off('progress', (data1, data2) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 off data1 =" + data1);
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 off data2 =" + data2);
});
uploadTask.delete((err, data) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 remove =" + data);
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 end-----------------------");
done();
});
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
});
/**
* @tc.number : SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('headerReceive', (header) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != {} || header != undefined));
});
uploadTask.off('headerReceive', (header) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != {} || header != undefined));
});
uploadTask.delete().then((result)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 remove result = " + result);
expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 end-----------------------");
done();
});
});
} catch (e) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(true).assertFail();
}
});
/**
* @tc.number : SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 UploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('complete', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 on_complete" );
});
uploadTask.off('complete', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 off_complete");
});
uploadTask.delete().then((result)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 remove result = " + result);
expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 end-----------------------");
done();
});
});
} catch (e) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0007 error: " + JSON.stringify(e));
expect().assertFail();
}
});
/**
* @tc.number : SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 is starting-----------------------");
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 UploadConfig = " + JSON.stringify(uploadConfig));
request.uploadFile(globalThis.abilityContext, uploadConfig).then((uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 uploadTask = " + uploadTask);
expect(true).assertEqual((uploadTask != undefined));
uploadTask.on('fail', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 on_fail");
});
uploadTask.off('fail', (taskStates) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 off_fail");
});
uploadTask.delete().then((result)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 remove result = " + result);
expect(result).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 end-----------------------");
done();
});
});
} catch (e) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_0008 error: " + JSON.stringify(e));
expect().assertFail();
}
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask)=>{
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
};
let t = setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------");
clearTimeout(t);
done();
}, 10000);
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
try{
request.uploadFile(globalThis.abilityContext, uploadConfig).then(uploadTask => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 except error: " + e);
}
}).catch(err => {
console.error("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
}catch(err){
console.error("====>SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err);
}
let t = setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_uploadFile_STAGE_API_PROMISE_0001 end-----------------------");
clearTimeout(t);
done();
}, 10000);
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
try{
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task.');
expect().assertFail();
done();
}
console.info('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 uploadTask task delete success.');
expect(typeof data == "boolean").assertTrue();
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 end-----------------------");
done();
}catch(err){
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 delete error' + err);
done();
}
});
} catch (error) {
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0001 delete catch error' + error);
done();
}
})
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, uploadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
try{
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete().then(data => {
console.info('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 delete data:' + JSON.stringify(data));
expect(data).assertEqual(true);
done();
}).catch((err) => {
console.info('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task.');
expect().assertFail();
done();
})
}catch(err){
console.error('====>SUB_REQUEST_CROSSPLATFORM_UPLOAD_API_DELETE_0002 delete catch err');
done();
}
})
});
})
}
request/crossplatform/RequestTest_ets/src/main/ets/test/requestConstant.test.ets
0 → 100644
浏览文件 @
27d41ad1
/*
* Copyright (c) 2023 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 requestConstantCrossplatformJSUnit() {
describe('requestConstantCrossplatformTest', 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_CROSSPLATFORM_CONSTANT_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_CONSTANT_0001
* @tc.desc Test constants of the request module.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_CROSSPLATFORM_CONSTANT_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CONSTANT_0001 is starting-----------------------");
expect(request.EXCEPTION_PERMISSION === 201).assertTrue();
expect(request.EXCEPTION_PARAMCHECK === 401).assertTrue();
expect(request.EXCEPTION_UNSUPPORTED === 801).assertTrue();
expect(request.EXCEPTION_FILEIO === 13400001).assertTrue();
expect(request.EXCEPTION_FILEPATH === 13400002).assertTrue();
expect(request.EXCEPTION_SERVICE === 13400003).assertTrue();
expect(request.EXCEPTION_OTHERS === 13499999).assertTrue();
expect(request.NETWORK_MOBILE === 1).assertTrue();
expect(request.NETWORK_WIFI === 65536).assertTrue();
expect(request.ERROR_CANNOT_RESUME === 0).assertTrue();
expect(request.ERROR_DEVICE_NOT_FOUND === 1).assertTrue();
expect(request.ERROR_FILE_ALREADY_EXISTS === 2).assertTrue();
expect(request.ERROR_FILE_ERROR === 3).assertTrue();
expect(request.ERROR_HTTP_DATA_ERROR === 4).assertTrue();
expect(request.ERROR_INSUFFICIENT_SPACE === 5).assertTrue();
expect(request.ERROR_TOO_MANY_REDIRECTS === 6).assertTrue();
expect(request.ERROR_UNHANDLED_HTTP_CODE === 7).assertTrue();
expect(request.ERROR_UNKNOWN === 8).assertTrue();
expect(request.ERROR_OFFLINE === 9).assertTrue();
expect(request.ERROR_UNSUPPORTED_NETWORK_TYPE === 10).assertTrue();
expect(request.PAUSED_QUEUED_FOR_WIFI === 0).assertTrue();
expect(request.PAUSED_WAITING_FOR_NETWORK === 1).assertTrue();
expect(request.PAUSED_WAITING_TO_RETRY === 2).assertTrue();
expect(request.PAUSED_BY_USER === 3).assertTrue();
expect(request.PAUSED_UNKNOWN === 4).assertTrue();
expect(request.SESSION_SUCCESSFUL === 0).assertTrue();
expect(request.SESSION_RUNNING === 1).assertTrue();
expect(request.SESSION_PENDING === 2).assertTrue();
expect(request.SESSION_PAUSED === 3).assertTrue();
expect(request.SESSION_FAILED === 4).assertTrue();
done();
});
})
}
request/crossplatform/RequestTest_ets/src/main/ets/test/requestDownload.test.ets
0 → 100644
浏览文件 @
27d41ad1
/*
* Copyright (C) 2023 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 requestCrossplatformDownloadJSUnit() {
describe("requestCrossplatformDownloadTest", 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_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_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_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
} catch (e) {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 except error: " + e);
}
await downloadTask.delete();
removeFile(downloadFilePath);
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0001 end-----------------------");
done();
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk",
header: {
headers: "http",
},
enableMetered: true,
enableRoaming: true,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: true,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
} catch (e) {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 except error: " + e);
}
await downloadTask.delete();
removeFile(downloadFilePath);
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_CALLBACK_0002 end-----------------------");
done();
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001
* @tc.desc Starts a download session.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001", 0, async function (done) {
console.info("-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_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_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
await downloadTask.delete();
})
.catch((err) => {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 error: " + err);
})
.finally(() => {
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_FILE_STAGE_API_PROMISE_0001 catch error: " + err);
done();
}
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001
* @tc.desc Delete the download task.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.delete(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001 Failed to delete the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001 Download task delete success.");
expect(typeof data == "boolean").assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001 delete throw error" + err);
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (error) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0001 delete catch error" + error);
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0002
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0002
* @tc.desc Delete the download task.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.delete()
.then(async (data) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0002 Download task delete success.");
expect(data).assertEqual(true);
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_DELETE_0002 end-----------------------");
})
.catch(async (err) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001
* @tc.desc Suspend the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.suspend(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001 Failed to suspend the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001 Download task suspend success.");
expect(data == true).assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0001 suspend catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0002
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0002
* @tc.desc Suspend the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0002 throw_err:" + JSON.stringify(err));
}
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_SUSPEND_0002 suspend catch error" + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001
* @tc.desc Restore the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.restore(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001 Failed to restore the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001 Download restore success.");
expect(data == true).assertTrue();
} catch (err) {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001 throw_err:" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0001 restore catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0002
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0002
* @tc.desc Restore the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0002", 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0002 is starting-----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.restore()
.then(async (data) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_RESTORE_0002 Download task restore.");
expect(data == true).assertTrue();
})
.catch(async (err) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001
* @tc.desc Get the download task info
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_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("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_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_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask
.getTaskInfo()
.then(async (data) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.");
expect(typeof data == "object").assertTrue();
})
.catch(async (err) => {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.");
})
.finally(async () => {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001
* @tc.desc Get mimetype of the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_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_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.getTaskMimeType(async (err, data) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType enter");
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001 getTaskMimeType err: " + err);
expect(data != null).assertEqual(true);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001 callback error: " + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_GETTASKMINETYPE_0001 error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_0002
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_0002
* @tc.desc Get mimetype of the download task
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_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_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_0002 downloadTask: " + downloadTask);
try {
let data = await downloadTask.getTaskMimeType();
expect(data != undefined).assertEqual(true);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNLOAD_API_GETTASKMINETYPE_0002 throw_error: " + JSON.stringify(err));
} finally {
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_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("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_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_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", async () => {
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
console.info('SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001 data:' + JSON.stringify(data));
expect(data.description).assertEqual('XTS download test!');
expect(data.downloadedBytes).assertEqual(1042003);
expect(typeof data.downloadId == "number").assertTrue();
expect(data.failedReason).assertEqual(0);
expect(data.fileName).assertEqual('SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001.txt');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001.txt`);
expect(data.pausedReason).assertEqual(0);
expect(data.status).assertEqual(0);
expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk');
expect(data.downloadTitle).assertEqual('XTS download test!');
expect(data.downloadTotalBytes).assertEqual(1042003);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0001 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002
* @tc.desc Get the error download task info, and test the field of TaskInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test_not_exists.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_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on('fail', err => {
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
console.info('SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002 data:' + JSON.stringify(data));
expect(data.description).assertEqual('XTS download test!');
expect(data.downloadedBytes).assertEqual(0);
expect(data.failedReason).assertEqual(8);
expect(typeof data.downloadId == "number").assertTrue();
expect(data.fileName).assertEqual('SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002.txt');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002.txt`);
expect(data.pausedReason).assertEqual(0);
expect(data.status).assertEqual(4);
expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test_not_exists.apk');
expect(data.downloadTitle).assertEqual('XTS download test!');
expect(data.downloadTotalBytes).assertEqual(-1);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
})
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0002 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003
* @tc.desc Get the download task info, and test the field of TaskInfo
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003", 0, async function (done) {
console.info("====>---------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 is starting---------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003.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,
background: true,
};
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 downloadTask: " + downloadTask);
try {
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", async () => {
downloadTask.getTaskInfo(async (err, data) => {
try {
if (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 Failed to getTaskInfo the download task.");
expect().assertFail();
done();
}
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 Download getTaskInfo success.");
expect(typeof data == "object").assertTrue();
console.info('SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 data:' + JSON.stringify(data));
expect(data.description).assertEqual('XTS download test!');
expect(data.downloadedBytes).assertEqual(1042003);
expect(typeof data.downloadId == "number").assertTrue();
expect(data.failedReason).assertEqual(0);
expect(data.fileName).assertEqual('test.apk');
expect(data.filePath).assertEqual(`${globalThis.abilityContext.cacheDir}/test.apk`);
expect(data.pausedReason).assertEqual(0);
expect(data.status).assertEqual(0);
expect(data.targetURI).assertEqual('https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk');
expect(data.downloadTitle).assertEqual('download');
expect(data.downloadTotalBytes).assertEqual(1042003);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 throw_error" + JSON.stringify(err));
}
await downloadTask.delete();
removeFile(downloadFilePath);
done();
});
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_TASKINFO_0003 getTaskInfo catch error" + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001_bk.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001_bk.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_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("progress", async (receivedSize: number, totalSize: number) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001 downloadTask in progress");
expect(receivedSize != null).assertTrue();
expect(totalSize != null).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001 on api throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0001 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002_bk.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002_bk.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) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002 complete in callback");
expect(true).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002 complete api throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0002 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.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) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", async () => {
try {
expect(true).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0003 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004
* @tc.desc Start download task, and test the event 'off progress' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004.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,
};
let count = 0;
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("progress", () => {
downloadTask.off("progress");
count++;
});
downloadTask.on("complete", async () => {
try {
console.log("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004 count: " + count);
expect(count).assertEqual(1);
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004 throw_error in complete: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0004 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005
* @tc.desc Start download task, and test the event 'off complete' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005.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,
};
let result = true;
let onFailedCallback = function() {
result = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", onFailedCallback);
downloadTask.off("complete", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005 in setTimeout");
clearTimeout(t);
expect(result).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0005 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006
* @tc.desc Start download task, and test the event 'off error' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
let result = true;
let onFailedCallback = function() {
result = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", onFailedCallback);
downloadTask.off("fail", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006 in setTimeout");
clearTimeout(t);
expect(result).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0006 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007
* @tc.desc Start download task, and test the event 'off complete' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007.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,
};
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", onFailedCallback)
downloadTask.on("complete", onFailedCallback2)
downloadTask.off("complete", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertFalse();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0007 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008
* @tc.desc Start download task, and test the event 'off error' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", onFailedCallback);
downloadTask.on("fail", onFailedCallback2);
downloadTask.off("fail", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertFalse();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0008 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009.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_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("pause", async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009 downloadTask in pause");
expect(true).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009 on api throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
await downloadTask.suspend();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0009 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010.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_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
downloadTask.on("remove", async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010 downloadTask in remove");
expect(true).assertTrue();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010 on api throw_error: " + JSON.stringify(err));
removeFile(downloadFilePath);
done();
}
});
await downloadTask.delete();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0010 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011
* @tc.desc Start download task, and test the event 'off complete' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011.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,
};
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("complete", onFailedCallback)
downloadTask.on("complete", onFailedCallback2)
downloadTask.off("complete");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0011 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012
* @tc.desc Start download task, and test the event 'off error' of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012.txt`);
let downloadFileConfig = {
url: "https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/not-exist.apk",
header: {
headers: "http",
},
enableMetered: false,
enableRoaming: false,
description: "XTS download test!",
networkType: request.NETWORK_WIFI,
filePath: downloadFilePath,
title: "XTS download test!",
background: false,
};
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 onFailedCallback");
}
request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, downloadTask) => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
downloadTask.on("fail", onFailedCallback);
downloadTask.on("fail", onFailedCallback2);
downloadTask.off("fail");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0012 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013.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_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 onFailedCallback");
}
downloadTask.on("pause", onFailedCallback);
downloadTask.on("pause", onFailedCallback2);
downloadTask.off("pause", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2 == false).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.suspend();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0013 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014.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_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 onFailedCallback");
}
downloadTask.on("pause", onFailedCallback);
downloadTask.on("pause", onFailedCallback2);
downloadTask.off("pause");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
await downloadTask.delete();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 throw_error in setTimeout: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.suspend();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0014 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015.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_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 onFailedCallback");
}
downloadTask.on("remove", onFailedCallback);
downloadTask.on("remove", onFailedCallback2);
downloadTask.off("remove", onFailedCallback);
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2 == false).assertTrue();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 throw_error in setTimeout: " + JSON.stringify(err));
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.delete();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0015 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
/**
* @tc.number SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016
* *@tc.name SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016
* @tc.desc Start download task, and test the event of it.
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016", 0, async function (done) {
console.info("====>-------------------SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 is starting----------------------");
let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016.txt`;
console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016.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_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
try {
let result1 = true;
let result2 = true;
let onFailedCallback = function() {
result1 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 onFailedCallback");
}
let onFailedCallback2 = function() {
result2 = false;
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 onFailedCallback");
}
downloadTask.on("remove", onFailedCallback);
downloadTask.on("remove", onFailedCallback2);
downloadTask.off("remove");
const t = setTimeout(async () => {
try {
console.info("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 in setTimeout");
clearTimeout(t);
expect(result1).assertTrue();
expect(result2).assertTrue();
removeFile(downloadFilePath);
done();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 throw_error in setTimeout: " + JSON.stringify(err));
removeFile(downloadFilePath);
done();
}
}, 5000);
await downloadTask.delete();
} catch (err) {
console.error("====>SUB_REQUEST_CROSSPLATFORM_DOWNDLOAD_API_EVENT_0016 throw_error: " + JSON.stringify(err));
await downloadTask.delete();
removeFile(downloadFilePath);
done();
}
});
});
});
}
request/crossplatform/RequestTest_ets/src/main/module.json
0 → 100644
浏览文件 @
27d41ad1
{
"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
浏览文件 @
27d41ad1
{
"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
浏览文件 @
27d41ad1
{
"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
浏览文件 @
27d41ad1
6.6 KB
request/crossplatform/RequestTest_ets/src/main/resources/base/profile/test_pages.json
0 → 100644
浏览文件 @
27d41ad1
{
"src"
:
[
"TestAbility/pages/Index"
]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录