未验证 提交 df284154 编写于 作者: O openharmony_ci 提交者: Gitee

!5291 【杂散】【上传下载】优化request用例执行失败问题,挑单到mothly816分支

Merge pull request !5291 from 张育帅/cherry-pick-1661768094
...@@ -14,5 +14,8 @@ ...@@ -14,5 +14,8 @@
import("//build/ohos_var.gni") import("//build/ohos_var.gni")
group("request") { group("request") {
testonly = true testonly = true
deps = [ "RequestTest_ets:ActsRequestETSApiTest" ] deps = [
"RequestTest_Stage:ActsRequestStageTest",
"RequestTest_ets:ActsRequestETSApiTest",
]
} }
{
"app":{
"bundleName":"com.acts.request.test",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:app_name",
"description":"$string:description_application",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":9,
"targetAPIVersion":9,
"car":{
"apiCompatibleVersion":9,
"singleUser":false
}
}
}
{
"string":[
{
"name":"app_name",
"value":"ohosProject"
}
]
}
\ No newline at end of file
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsRequestStageTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":requestStage_ets_assets",
":requestStage_resources",
]
ets2abc = true
certificate_profile = "signature/actsRequestStageTest.p7b"
hap_name = "ActsRequestStageTest"
subsystem_name = "request"
part_name = "request"
}
ohos_app_scope("requestStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("requestStage_ets_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("requestStage_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":requestStage_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.acts.request.test",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [{
"test-file-name": [
"ActsRequestStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}]
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage onCreate");
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.info("requestStageTestAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.info("requestStageTestAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.info("requestStageTestAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
console.info("requestStageTestAbility onWindowStageCreate finish")
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.info("requestStageTestAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.info("requestStageTestAbility onForeground")
}
onBackground() {
// Ability has back to background
console.info("requestStageTestAbility onBackground")
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a com.acts.request.test.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../test/List.test'
@Entry
@Component
struct Index {
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {})
}
.width('100%')
.height('100%')
}
aboutToAppear(){
let abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import requestUploadJSUnit from './requestUpload.test'
import requestDownloadJSUnit from './requestDownload.test';
export default function testsuite() {
requestUploadJSUnit()
requestDownloadJSUnit()
}
\ No newline at end of file
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index";
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import request from "@ohos.request";
export default function requestDownloadJSUnit() {
describe('requestDownloadTest', function () {
console.info('################################request download Test start');
/**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
*/
beforeAll(function () {
console.info('beforeAll: Prerequisites are executed.');
});
/**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
*/
beforeEach(function () {
console.info('beforeEach: Prerequisites is executed.');
});
/**
* afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
*/
afterEach(function () {
console.info('afterEach: Test case-level clearance conditions is executed.');
});
/**
* afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed.
*/
afterAll(function () {
console.info('afterAll: Test suite-level cleanup condition is executed');
});
let downloadTask;
let downloadConfig = {
url: 'http://download.ci.openharmony.cn/version/Daily_Version/',
header: {
headers: 'http'
},
enableMetered: false,
enableRoaming: false,
description: 'XTS download test!',
networkType: request.NETWORK_WIFI,
filePath: 'internal://cache/test.txt',
title: 'XTS download test!',
background: true
}
/**
* @tc.number SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------");
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
try {
request.download(context, downloadConfig, (data)=>{
downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
});
} catch (err) {
console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
done();
});
/**
* @tc.number SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 is starting-----------------------");
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
request.download(context, downloadConfig).then(data => {
downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask);
expect(true).assertEqual(downloadTask != undefined);
}).catch(err => {
console.error("SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
console.info("-----------------------SUB_REQUEST_DOWNLOAD_STAGE_API_PROMISE_0001 end-----------------------");
done();
});
})
}
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index";
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import request from "@ohos.request";
export default function requestUploadJSUnit() {
describe('requestUploadTest', function () {
console.info('################################request upload Test start');
/**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
*/
beforeAll(function () {
console.info('beforeAll: Prerequisites are executed.');
});
/**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
*/
beforeEach(function () {
console.info('beforeEach: Prerequisites is executed.');
});
/**
* afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
*/
afterEach(function () {
console.info('afterEach: Test case-level clearance conditions is executed.');
});
/**
* afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed.
*/
afterAll(function () {
console.info('afterAll: Test suite-level cleanup condition is executed');
});
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
let uploadTask;
let RequestData = {
name: 'name',
value: '123'
}
let File = {
filename: 'test',
name: 'test',
uri: 'internal://cache/test.txt',
type: 'txt'
}
let uploadConfig = {
url: 'http://127.0.0.1',
header: {
headers: 'http'
},
method: 'POST',
files: [File],
data: [RequestData]
};
/**
* @tc.number SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 context = " + appContext);
request.upload(appContext, uploadConfig, (data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask));
expect(true).assertEqual(uploadTask != undefined);
uploadTask.on('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 on data2 =" + data2);
});
uploadTask.off('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 off data2 =" + data2);
});
uploadTask.remove((err, data) => {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 remove =" + data);
});
});
} catch (err) {
console.error("SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 error: " + err);
expect().assertFail();
}
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_CALLBACK_0001 end-----------------------");
done();
});
/*
* @tc.number : SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 context = " + appContext);
request.upload(appContext, uploadConfig).then((data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 uploadTask = " + uploadTask);
expect(true).assertEqual(uploadTask != undefined);
uploadTask.on('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.off('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.remove().then((result)=>{
console.info("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 remove result = " + result);
expect(result).assertEqual(true);
});
});
} catch (e) {
console.error("SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(e).assertFail();
}
console.info("-----------------------SUB_REQUEST_UPLOAD_STAGE_API_PROMISE_0001 end-----------------------");
done();
});
})
}
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:phone_entry_dsc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"name": "com.acts.request.test.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:phone_entry_main",
"icon": "$media:icon",
"label": "$string:entry_label",
"visible": true,
"orientation": "portrait",
"launchType": "singleton",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name":"ohos.permission.INTERNET",
"reason":"need use ohos.permission.INTERNET."
}
]
}
}
{
"string": [
{
"name": "phone_entry_dsc",
"value": "i am an entry for phone"
},
{
"name": "phone_entry_main",
"value": "the phone entry ability"
},
{
"name": "entry_label",
"value": "ActsImeAbilityTest"
},
{
"name": "ime_description",
"value": "input method extension ability."
},
{
"name": "ime_label",
"value": "inputMethod extension ability services."
},
{
"name": "ime_label_1",
"value": "inputMethod extension ability services_1."
},
{
"name": "description_application",
"value": "demo for test"
},
{
"name": "app_name",
"value": "Demo"
}
]
}
{
"src": [
"pages/index/index",
"pages/second/second"
]
}
\ No newline at end of file
...@@ -23,7 +23,7 @@ ohos_js_hap_suite("ActsRequestETSApiTest") { ...@@ -23,7 +23,7 @@ ohos_js_hap_suite("ActsRequestETSApiTest") {
ets2abc = true ets2abc = true
subsystem_name = "request" subsystem_name = "request"
part_name = "request" part_name = "request"
certificate_profile = "./signature/openharmony_sx.p7b" certificate_profile = "./signature/ActsRequestETSApiTest.p7b"
hap_name = "ActsRequestETSApiTest" hap_name = "ActsRequestETSApiTest"
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"test-timeout": "600000", "test-timeout": "600000",
"bundle-name": "com.acts.requesttest", "bundle-name": "com.acts.requesttest",
"package-name": "com.acts.requesttest", "package-name": "com.acts.requesttest",
"shell-timeout": "60000" "shell-timeout": "600000"
}, },
"kits": [ "kits": [
{ {
......
...@@ -62,6 +62,18 @@ ...@@ -62,6 +62,18 @@
"launchType": "standard" "launchType": "standard"
} }
], ],
"reqPermissions": [
{
"name": "ohos.permission.INTERNET",
"reason": "need use ohos.permission.INTERNET",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when": "inuse"
}
}
],
"js": [ "js": [
{ {
"mode": { "mode": {
......
文件模式从 100755 更改为 100644
...@@ -52,7 +52,7 @@ export default function requestDownloadJSUnit() { ...@@ -52,7 +52,7 @@ export default function requestDownloadJSUnit() {
let downloadTask; let downloadTask;
let downloadConfig = { let downloadConfig = {
url: 'http://download.ci.openharmony.cn/version/Daily_Version/', url: 'http://127.0.0.1',
header: { header: {
headers: 'http' headers: 'http'
}, },
...@@ -60,7 +60,7 @@ export default function requestDownloadJSUnit() { ...@@ -60,7 +60,7 @@ export default function requestDownloadJSUnit() {
enableRoaming: false, enableRoaming: false,
description: 'XTS download test!', description: 'XTS download test!',
networkType: request.NETWORK_WIFI, networkType: request.NETWORK_WIFI,
filePath: 'internal://cache/test.txt', filePath: 'test.txt',
title: 'XTS download test!', title: 'XTS download test!',
background: true background: true
} }
...@@ -88,31 +88,6 @@ export default function requestDownloadJSUnit() { ...@@ -88,31 +88,6 @@ export default function requestDownloadJSUnit() {
done(); done();
}); });
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 is starting-----------------------");
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
try {
request.download(context, downloadConfig, (data)=>{
downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
});
} catch (err) {
console.error("SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 error: " + err);
expect().assertFail();
}
console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 end-----------------------");
done();
});
/** /**
* @tc.number SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 * @tc.number SUB_REQUEST_DOWNLOAD_API_PROMISE_0001
* @tc.desc Starts a download session. * @tc.desc Starts a download session.
...@@ -134,29 +109,6 @@ export default function requestDownloadJSUnit() { ...@@ -134,29 +109,6 @@ export default function requestDownloadJSUnit() {
done(); done();
}); });
/**
* @tc.number SUB_REQUEST_DOWNLOAD_API_PROMISE_0002
* @tc.desc Starts a download session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_DOWNLOAD_API_PROMISE_0002', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 is starting-----------------------");
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let context = abilityDelegator.getAppContext();
request.download(context, downloadConfig).then(data => {
downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true);
}).catch(err => {
console.error("SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 error: " + err);
expect().assertFail();
})
console.info("-----------------------SUB_REQUEST_DOWNLOAD_API_PROMISE_0002 end-----------------------");
done();
});
/** /**
* @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001
* @tc.desc alled when the current download session is in process. * @tc.desc alled when the current download session is in process.
...@@ -169,12 +121,12 @@ export default function requestDownloadJSUnit() { ...@@ -169,12 +121,12 @@ export default function requestDownloadJSUnit() {
request.download( downloadConfig, (data)=>{ request.download( downloadConfig, (data)=>{
downloadTask = data; downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 downloadTask: " + downloadTask); console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true); expect(true).assertEqual(downloadTask != undefined);
downloadTask.on('progress', (data1, data2) => { downloadTask.on('progress', (data1, data2) => {
console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data1 =" + data1); console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data1 =" + data1);
console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data2 =" + data2); console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data2 =" + data2);
expect(data1 != undefined).assertEqual(true); expect(true).assertEqual(data1 != undefined);
expect(data2 != undefined).assertEqual(true); expect(true).assertEqual(data2 != undefined);
}); });
}); });
...@@ -194,7 +146,7 @@ export default function requestDownloadJSUnit() { ...@@ -194,7 +146,7 @@ export default function requestDownloadJSUnit() {
request.download( downloadConfig, (data)=>{ request.download( downloadConfig, (data)=>{
downloadTask = data; downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: " + downloadTask); console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true); expect(true).assertEqual(downloadTask != undefined);
try{ try{
downloadTask.on('complete', () => { downloadTask.on('complete', () => {
console.info('SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 task completed.') console.info('SUB_REQUEST_DOWNLOAD_API_CALLBACK_0002 task completed.')
...@@ -220,7 +172,7 @@ export default function requestDownloadJSUnit() { ...@@ -220,7 +172,7 @@ export default function requestDownloadJSUnit() {
request.download( downloadConfig, (data)=>{ request.download( downloadConfig, (data)=>{
downloadTask = data; downloadTask = data;
console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: " + downloadTask); console.info("SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: " + downloadTask);
expect(downloadTask != undefined).assertEqual(true); expect(true).assertEqual(downloadTask != undefined);
try{ try{
downloadTask.on('pause', () => { downloadTask.on('pause', () => {
console.info('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task pause.') console.info('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task pause.')
......
...@@ -255,49 +255,6 @@ export default function requestUploadJSUnit() { ...@@ -255,49 +255,6 @@ export default function requestUploadJSUnit() {
done(); done();
}); });
/**
* @tc.number SUB_REQUEST_UPLOAD_API_CALLBACK_0002
* @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME
* @tc.desc Test requestUploadTest API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_CALLBACK_0002', 0, async function (done) {
console.info("-----------------------Request_test_0006 is starting-----------------------");
try {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 uploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 context = " + appContext);
request.upload(appContext, uploadConfig, (data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 progress uploadTask =" + JSON.stringify(uploadTask));
expect(uploadTask != undefined).assertEqual(true);
uploadTask.on('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 on data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 on data2 =" + data2);
});
uploadTask.off('progress', function (data1, data2) {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 off data1 =" + data1);
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 off data2 =" + data2);
});
uploadTask.remove((err, data) => {
console.info("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 remove =" + data);
});
});
} catch (err) {
console.error("SUB_REQUEST_UPLOAD_API_CALLBACK_0002 error: " + err);
expect().assertFail();
}
sleep(Date.now(), 20000);
console.info("-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0002 end-----------------------");
done();
});
/* /*
* @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0001 * @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0001
* @tc.name : Use getEntries get the value by mixing the string key * @tc.name : Use getEntries get the value by mixing the string key
...@@ -307,6 +264,7 @@ export default function requestUploadJSUnit() { ...@@ -307,6 +264,7 @@ export default function requestUploadJSUnit() {
* @tc.level : Level 1 * @tc.level : Level 1
*/ */
it('SUB_REQUEST_UPLOAD_API_PROMISE_0001', 0, async function (done) { it('SUB_REQUEST_UPLOAD_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------");
try { try {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig));
request.upload(uploadConfig).then((data) => { request.upload(uploadConfig).then((data) => {
...@@ -331,52 +289,12 @@ export default function requestUploadJSUnit() { ...@@ -331,52 +289,12 @@ export default function requestUploadJSUnit() {
}); });
} catch (e) { } catch (e) {
console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e)); console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e));
expect(e).assertFail(); expect(true).assertFail(true);
} }
sleep(Date.now(), 20000); sleep(Date.now(), 20000);
console.info("-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------");
done(); done();
}); });
/*
* @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0002
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Mixed strings value can be obtained correctly
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_REQUEST_UPLOAD_API_PROMISE_0002', 0, async function (done) {
try {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 UploadConfig = " + JSON.stringify(uploadConfig));
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let appContext = abilityDelegator.getAppContext();
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 context = " + appContext);
request.upload(appContext, uploadConfig).then((data) => {
uploadTask = data;
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 uploadTask = " + uploadTask);
expect(data != undefined).assertEqual(true);
uploadTask.on('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.off('headerReceive', (header) => {
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 header = " + header);
expect(true).assertEqual((header != undefined) || (header != "") || (header != {}));
});
uploadTask.remove().then((result)=>{
console.info("SUB_REQUEST_UPLOAD_API_PROMISE_0002 remove result = " + result);
expect(result).assertEqual(true);
});
});
} catch (e) {
console.error("SUB_REQUEST_UPLOAD_API_PROMISE_0002 error: " + JSON.stringify(e));
expect(e).assertFail();
}
sleep(Date.now(), 20000);
done();
});
}) })
} }
...@@ -70,10 +70,24 @@ ...@@ -70,10 +70,24 @@
], ],
"reqPermissions": [ "reqPermissions": [
{ {
"name": "ohos.permission.SET_WALLPAPER" "name": "ohos.permission.SET_WALLPAPER",
"reason": "need use ohos.permission.SET_WALLPAPER",
"usedScene": {
"ability": [
"com.acts.theme.wallpapertest.MainAbility"
],
"when": "inuse"
}
}, },
{ {
"name": "ohos.permission.GET_WALLPAPER" "name": "ohos.permission.GET_WALLPAPER",
"reason": "need use ohos.permission.GET_WALLPAPER",
"usedScene": {
"ability": [
"com.acts.theme.wallpapertest.MainAbility"
],
"when": "inuse"
}
} }
], ],
"js": [ "js": [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册