mirror of
https://gitee.com/openharmony/request_request
synced 2024-11-23 15:00:48 +00:00
commit
208aea3393
29
test/unittest/js_test/requestPermissonTest/BUILD.gn
Executable file
29
test/unittest/js_test/requestPermissonTest/BUILD.gn
Executable file
@ -0,0 +1,29 @@
|
||||
# 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("//build/test.gni")
|
||||
|
||||
module_output_path = "request/request"
|
||||
|
||||
ohos_js_unittest("RequestPermissionTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
hap_profile = "./config.json"
|
||||
|
||||
certificate_profile = "./signature/openharmony_sx.p7b"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":RequestPermissionTest" ]
|
||||
}
|
196
test/unittest/js_test/requestPermissonTest/Permission.test.js
Normal file
196
test/unittest/js_test/requestPermissonTest/Permission.test.js
Normal file
@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index';
|
||||
import { agent } from '@ohos.request';
|
||||
import featureAbility from '@ohos.ability.featureAbility'
|
||||
import fs from '@ohos.file.fs';
|
||||
|
||||
describe('PermissionTest', function () {
|
||||
beforeAll(function () {
|
||||
console.info('beforeAll called')
|
||||
let file = fs.openSync(cacheDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
||||
fs.closeSync(file)
|
||||
})
|
||||
|
||||
afterAll(function () {
|
||||
console.info('afterAll called')
|
||||
if (fs.accessSync(cacheDir + '/test.txt')) {
|
||||
fs.unlinkSync(cacheDir + '/test.txt')
|
||||
}
|
||||
})
|
||||
|
||||
beforeEach(function () {
|
||||
console.info('beforeEach called')
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
console.info('afterEach called')
|
||||
if (task !== undefined) {
|
||||
await agent.remove(context, task.tid)
|
||||
task = undefined
|
||||
}
|
||||
})
|
||||
|
||||
let context = featureAbility.getContext()
|
||||
let cacheDir = '/data/storage/el2/base/haps/entry/files/';
|
||||
let task = undefined
|
||||
|
||||
/**
|
||||
* @tc.name: testCreateTask001
|
||||
* @tc.desc: Test start task for callback no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testCreateTask001', async function (done) {
|
||||
let conf = {
|
||||
action: agent.Action.UPLOAD,
|
||||
url: 'http://127.0.0.1',
|
||||
}
|
||||
task.create(conf, (err) => {
|
||||
if (err) {
|
||||
expect(err.code).assertEqual(201)
|
||||
} else {
|
||||
expect(false).assertTrue()
|
||||
}
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: testCreateTask002
|
||||
* @tc.desc: Test create task for promise no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testCreateTask002', async function (done) {
|
||||
let conf = {
|
||||
action: agent.Action.UPLOAD,
|
||||
url: 'http://127.0.0.1',
|
||||
}
|
||||
task.create().then((task) => {
|
||||
expect(false).assertTrue()
|
||||
done()
|
||||
}).catch((err) => {
|
||||
expect(err.code).assertEqual(201)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: testSearchTask001
|
||||
* @tc.desc: Test search task for callback no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testSearchTask001', async function (done) {
|
||||
let filter = {
|
||||
bundle: 'com.acts.request'
|
||||
}
|
||||
agent.search(context, filter, (err) => {
|
||||
if (err) {
|
||||
expect(err.code).assertEqual(202)
|
||||
} else {
|
||||
expect(false).assertTrue()
|
||||
}
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: testSearchTask002
|
||||
* @tc.desc: Test search task for promise no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testSearchTask002', async function (done) {
|
||||
let filter = {
|
||||
bundle: 'com.acts.request'
|
||||
}
|
||||
agent.search(context, filter).then((err) => {
|
||||
expect(false).assertTrue()
|
||||
done()
|
||||
}).catch((err) => {
|
||||
expect(err.code).assertEqual(202)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: testQueryTask001
|
||||
* @tc.desc: Test query task for callback no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testQueryTask001', function (done) {
|
||||
agent.query(context, '123', (err) => {
|
||||
if (err) {
|
||||
expect(err.code).assertEqual(202)
|
||||
} else {
|
||||
expect(false).assertTrue()
|
||||
}
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: testQueryTask002
|
||||
* @tc.desc: Test query task for promise no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testQueryTask002', async function (done) {
|
||||
agent.query(context, '123').then((err) => {
|
||||
expect(false).assertTrue()
|
||||
done()
|
||||
}).catch((err) => {
|
||||
expect(err.code).assertEqual(202)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: testClearTask001
|
||||
* @tc.desc: Test clear task for callback no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testClearTask001', function (done) {
|
||||
agent.query(context, ['123'], (err) => {
|
||||
if (err) {
|
||||
expect(err.code).assertEqual(202)
|
||||
} else {
|
||||
expect(false).assertTrue()
|
||||
}
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: testClearTask002
|
||||
* @tc.desc: Test clear task for promise no permission
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
it('testClearTask002', async function (done) {
|
||||
agent.clear(context, ['123']).then((err) => {
|
||||
expect(false).assertTrue()
|
||||
done()
|
||||
}).catch((err) => {
|
||||
expect(err.code).assertEqual(202)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
61
test/unittest/js_test/requestPermissonTest/config.json
Executable file
61
test/unittest/js_test/requestPermissonTest/config.json
Executable file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.acts.request",
|
||||
"vendor": "acts",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 8,
|
||||
"target": 9
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.acts.request",
|
||||
"name": ".MainAbility",
|
||||
"deviceType": [
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"visible": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "com.acts.request.MainAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"label": "$string:app_name",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index"
|
||||
],
|
||||
"name": "default",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
BIN
test/unittest/js_test/requestPermissonTest/signature/openharmony_sx.p7b
Executable file
BIN
test/unittest/js_test/requestPermissonTest/signature/openharmony_sx.p7b
Executable file
Binary file not shown.
29
test/unittest/js_test/requestTest/BUILD.gn
Executable file
29
test/unittest/js_test/requestTest/BUILD.gn
Executable file
@ -0,0 +1,29 @@
|
||||
# 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("//build/test.gni")
|
||||
|
||||
module_output_path = "request/request"
|
||||
|
||||
ohos_js_unittest("RequestTaskTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
hap_profile = "./config.json"
|
||||
|
||||
certificate_profile = "./signature/openharmony_sx.p7b"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":RequestTaskTest" ]
|
||||
}
|
1503
test/unittest/js_test/requestTest/RequestTask.test.js
Normal file
1503
test/unittest/js_test/requestTest/RequestTask.test.js
Normal file
File diff suppressed because it is too large
Load Diff
61
test/unittest/js_test/requestTest/config.json
Executable file
61
test/unittest/js_test/requestTest/config.json
Executable file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.acts.request",
|
||||
"vendor": "acts",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 8,
|
||||
"target": 9
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.acts.request",
|
||||
"name": ".MainAbility",
|
||||
"deviceType": [
|
||||
"default",
|
||||
"tablet"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"visible": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "com.acts.request.MainAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"label": "$string:app_name",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index"
|
||||
],
|
||||
"name": "default",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
BIN
test/unittest/js_test/requestTest/signature/openharmony_sx.p7b
Executable file
BIN
test/unittest/js_test/requestTest/signature/openharmony_sx.p7b
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user