提交 7ef3a1ea 编写于 作者: H huyanqiang5@huawei.com 提交者: hu0475

完成security子系统ohos.abilityAccessCtrl模块的跨平台测试套

Signed-off-by: Nhuyanqiang5@huawei.com <huyanqiang5@huawei.com>
上级 19172b16
# Copyright (C) 2021 Huawei Device Co., Ltd.
# 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
......@@ -23,6 +23,7 @@ group("security") {
"certificate_framework/js_api_test_oh40:ActsCertFrameworkTwoJSNormalTest",
"certificate_framework/js_api_test_one:ActsCertificateFrameworkJSNormalTest",
"cipher/datacipher:datacipher",
"crossplatform:crossplatform",
"cryptoFramework/js_api_test_oh40:ActsCryptoFrameworkTwoJSNormalTest",
"cryptoFramework/js_api_test_one:ActsCryptoFrameworkJSNormalTest",
"huks_napi_BasicTest:ActsHuksNAPITest",
......
# 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")
group("crossplatform") {
testonly = true
if (is_standard_system) {
deps = [ "securityacessAblityCtrletstest:ActsSecurityAccessAblityCtrlTest" ]
}
}
{
"app": {
"bundleName": "ohos.acts.security.crossplatform.accessAblityCtrl.normal",
"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
}
}
}
# 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("ActsSecurityAccessAblityCtrlTest") {
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 = "ActsSecurityAccessAblityCtrlTest"
subsystem_name = "security"
part_name = "access_token"
}
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"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.security.crossplatform.accessAblityCtrl.normal",
"module-name": "entry_test"
},
"kits": [
{
"test-file-name": [
"ActsSecurityAccessAblityCtrlTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/*
* 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) {
globalThis.abilityContext = this.context;
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/*
* Copyright (c) 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 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')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (c) 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 '@ohos/hypium'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import bundleManager from '@ohos.bundle.bundleManager';
import osAccount from '@ohos.account.osAccount'
const GrantStatus = abilityAccessCtrl.GrantStatus;
const TIMEOUT = 5000;
const ERR_PARAM_INVALID = 12100001;
var permissionNameUser = "ohos.permission.DISTRIBUTED_DATASYNC";
var permissionNameSystem = "ohos.permission.GET_BUNDLE_INFO";
var tokenID = undefined;
export default function AccessTokenTest() {
describe('AccessTokenTest', function () {
beforeAll(async function (done) {
var accountManager = osAccount.getAccountManager();
var userId = await accountManager.getOsAccountLocalIdFromProcess();
try {
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION;
var buddleInfo = await bundleManager.getBundleInfoForSelf(bundleFlags);
console.log('getBundleInfoForSelf ok')
var appInfo = buddleInfo.appInfo;
console.log('getBundleInfoForSelf ok2')
tokenID = appInfo.accessTokenId;
console.log('getBundleInfoForSelf ok3'+tokenID)
console.info("AccessTokenTest accessTokenId:" + appInfo.accessTokenId + ", name:" + appInfo.name
+ ", bundleName:" + 'com.example.myapplication')
console.info("sleep begin");
sleep(TIMEOUT);
console.info("sleep end");
done();
} catch (err) {
console.log('beforeAll error' + JSON.stringify(err));
done();
}
})
beforeEach(function () {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach(function () {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(function () {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
function sleep(delay) {
var start = (new Date()).getTime();
var next = (new Date()).getTime();
while (next - start < delay) {
next = (new Date()).getTime();
}
}
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_001
*@tc.name : testCheckAccessToken001
*@tc.desc : After the installation, user_grant permission is not granted by default(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessToken001', 0, async function(done){
console.info("Test_checkAccessToken_001 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
var result = await atManager.checkAccessToken(tokenID,permissionNameUser);
console.info("Test_checkAccessToken_001 tokenID" + tokenID + "-" + result)
expect(result).assertEqual(GrantStatus.PERMISSION_DENIED);
done();
} catch(error) {
console.info("Test_checkAccessToken_001 tokenID" + JSON.stringify(error))
}
done();
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_002
*@tc.name : testCheckAccessToken002
*@tc.desc : After the installation, system_grant permission is granted by default(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessToken002', 0, async function(done){
console.info("Test_checkAccessToken_002 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
var result = await atManager.checkAccessToken(tokenID,permissionNameSystem);
console.info("Test_checkAccessToken_002 tokenID" + tokenID + "-" + result)
expect(result).assertEqual(GrantStatus.PERMISSION_DENIED);
done();
} catch(error) {
console.info("Test_checkAccessToken_002 error code" + error.code + "error message" + error.message);
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_003
*@tc.name : testCheckAccessToken003
*@tc.desc : Test invalid permission(empty)(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessToken003', 0, async function(done){
console.info("Test_checkAccessToken_003 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
atManager.checkAccessToken(tokenID, "").then((data) => {
console.log(`Test_checkAccessToken_003 , data->${JSON.stringify(data)}`);
}).catch((err) => {
console.log(`Test_checkAccessToken_003 err->${JSON.stringify(err)}`);
expect(err.code).assertEqual(ERR_PARAM_INVALID)
done();
});
}catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_004
*@tc.name : testCheckAccessToken004
*@tc.desc : Test invalid tokenId(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessToken004', 0, async function(done){
console.info("Test_checkAccessToken_004 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
atManager.checkAccessToken(11, permissionNameUser).then((data) => {
console.log(`Test_checkAccessToken_004 data->${JSON.stringify(data)}`);
expect(data).assertEqual(GrantStatus.PERMISSION_DENIED);
done();
}).catch((err) => {
console.log(`Test_checkAccessToken_004 err->${JSON.stringify(err)}`);
});
}catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_005
*@tc.name : testCheckAccessToken005
*@tc.desc : Test invalid permission(length exceeds 256)(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessToken005', 0, async function(done){
console.info("Test_checkAccessToken_005 start");
var atManager = abilityAccessCtrl.createAtManager();
var permissionName = "ohos.permission.testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"
+ "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"
+ "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest";
try {
atManager.checkAccessToken(tokenID, permissionName).then((data) => {
console.log(`Test_checkAccessToken_005 success, data->${JSON.stringify(data)}`);
}).catch((err) => {
console.log(`Test_checkAccessToken_005 err->${JSON.stringify(err)}`);
expect(err.code).assertEqual(ERR_PARAM_INVALID)
done();
});
}catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_SYNC_001
*@tc.name : testCheckAccessTokenSync001
*@tc.desc : After the installation, user_grant permission is not granted by default(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessTokenSync001', 0, async function(done){
console.info("Test_checkAccessTokenSync_001 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
var result = await atManager.checkAccessTokenSync(tokenID,permissionNameUser);
console.info("Test_checkAccessTokenSync_001 tokenID" + tokenID + "-" + result)
expect(result).assertEqual(GrantStatus.PERMISSION_DENIED);
done();
} catch(error) {
console.info("Test_checkAccessTokenSync_001 tokenID" + JSON.stringify(error))
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_SYNC_002
*@tc.name : testCheckAccessTokenSync002
*@tc.desc : After the installation, system_grant permission is granted by default(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessTokenSync002', 0, async function(done){
console.info("Test_checkAccessTokenSync_002 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
var result = await atManager.checkAccessTokenSync(tokenID,permissionNameSystem);
console.info("Test_checkAccessTokenSync_002 tokenID" + tokenID + "-" + result)
expect(result).assertEqual(GrantStatus.PERMISSION_DENIED);
done();
} catch(error) {
console.info("Test_checkAccessTokenSync_002 error code" + error.code + "error message" + error.message);
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_SYNC_003
*@tc.name : testCheckAccessTokenSync003
*@tc.desc : Test invalid permission(empty)(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessTokenSync003', 0, async function(done){
console.info("Test_checkAccessTokenSync_003 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
var result = await atManager.checkAccessTokenSync(tokenID,"");
} catch(error) {
console.info("Test_checkAccessTokenSync_003 error code" + error.code + "error message" + error.message);
expect(error.code).assertEqual(ERR_PARAM_INVALID);
done();
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_SYNC_004
*@tc.name : testCheckAccessTokenSync004
*@tc.desc : Test invalid tokenId(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessTokenSync004', 0, async function(done){
console.info("Test_checkAccessTokenSync_004 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
var result = await atManager.checkAccessTokenSync(11,permissionNameSystem);
console.info("Test_checkAccessTokenSync_004 tokenID" + tokenID + "-" + result)
expect(result).assertEqual(GrantStatus.PERMISSION_DENIED);
done();
} catch(error) {
console.info("Test_checkAccessTokenSync_004 error code" + error.code + "error message" + error.message);
}
})
/**
*@tc.number : TEST_CHECK_ACCESS_TOKEN_SYNC_005
*@tc.name : testCheckAccessTokenSync005
*@tc.desc : Test invalid permission(length exceeds 256)(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it('testCheckAccessTokenSync005', 0, async function(done){
console.info("Test_checkAccessTokenSync_005 start");
var atManager = abilityAccessCtrl.createAtManager();
var permissionName = "ohos.permission.testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"
+ "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"
+ "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest";
try {
var result = await atManager.checkAccessTokenSync(tokenID,permissionName);
} catch(error) {
console.info("Test_checkAccessTokenSync_005 error code" + error.code + "error message" + error.message);
expect(error.code).assertEqual(ERR_PARAM_INVALID);
done();
}
})
/**
*@tc.number : TEST_REQUEST_PERMISSION_FROM_USER_001
*@tc.name : testRequestPermissionFromUser001
*@tc.desc : Exception scenario use case(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it("testRequestPermissionFromUser001", 0, async function (done) {
console.info("Test_requestPermissionsFromUser_001 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
atManager
.requestPermissionsFromUser(globalThis.abilityContext, ["ohos.permission.CAMERA"])
.then((data) => {
try {
console.info("Test_requestPermissionsFromUser_001 data:" + JSON.stringify(data));
console.info("Test_requestPermissionsFromUser_001 data permissions:" + data.permissions);
console.info("Test_requestPermissionsFromUser_001 data authResults:" + data.authResults);
expect(data.permissions[0] == "ohos.permission.CAMERA").assertTrue();
expect(data.authResults[0] == 2).assertTrue();
done();
} catch (err) {
console.info("testRequestPermissionFromUser001 meet error:" + JSON.stringify(err));
done();
}
})
.catch((err) => {
console.info("data:" + JSON.stringify(err));
done();
});
} catch (err) {
console.log(`Test_requestPermissionsFromUser_001 catch err->${JSON.stringify(err)}`);
done();
}
});
/**
*@tc.number : TEST_REQUEST_PERMISSION_FROM_USER_002
*@tc.name : testRequestPermissionFromUser002
*@tc.desc : Exception scenario use case(Promise).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it("testRequestPermissionFromUser002", 0, async function (done) {
console.info("Test_requestPermissionsFromUser_002 start");
var atManager = abilityAccessCtrl.createAtManager();
console.info("Test_requestPermissionsFromUser_002 start");
try {
var result = atManager
.requestPermissionsFromUser(globalThis.abilityContext, ["abc"])
.then((data) => {
console.info("Test_requestPermissionsFromUser_002 data:" + JSON.stringify(data));
console.info("Test_requestPermissionsFromUser_002 data permissions:" + data.permissions);
console.info("Test_requestPermissionsFromUser_002 data authResults:" + data.authResults);
done();
})
.catch((err) => {
console.info("Test_requestPermissionsFromUser_002 data:" + JSON.stringify(err));
done();
});
} catch (err) {
console.log("Test_requestPermissionsFromUser_002 catch err" + err.code + "message" + err.message);
expect(result).assertEqual(undefined);
done();
}
});
/**
*@tc.number : TEST_REQUEST_PERMISSION_FROM_USER_003
*@tc.name : testRequestPermissionFromUser003
*@tc.desc : RequestPermissionsFromUser normal scenario(callback).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it("testRequestPermissionFromUser003", 0, async function (done) {
console.info("Test_requestPermissionsFromUser_003 start");
var atManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(globalThis.abilityContext, ["ohos.permission.CAMERA"], (err, data) => {
console.info("Test_requestPermissionsFromUser_003 data:" + JSON.stringify(data));
console.info("Test_requestPermissionsFromUser_003 data permissions:" + data.permissions);
console.info("Test_requestPermissionsFromUser_003 data authResults:" + data.authResults);
expect(data.permissions[0] == "ohos.permission.CAMERA").assertTrue();
expect(data.authResults[0] == 2).assertTrue();
done();
});
} catch (err) {
console.log(`Test_requestPermissionsFromUser_003 catch err->${JSON.stringify(err)}`);
done();
}
});
/**
*@tc.number : TEST_REQUEST_PERMISSION_FROM_USER_004
*@tc.name : testRequestPermissionFromUser004
*@tc.desc : Exception scenario use case(callback).
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it("testRequestPermissionFromUser004", 0, async function (done) {
console.info("Test_requestPermissionsFromUser_004 start ");
var atManager = abilityAccessCtrl.createAtManager();
try {
var result = atManager.requestPermissionsFromUser(globalThis.abilityContext, ["a"], (err, data) => {
console.info("Test_requestPermissionsFromUser_004 data:" + JSON.stringify(data));
console.info("Test_requestPermissionsFromUser_004 data permissions:" + data.permissions);
console.info("Test_requestPermissionsFromUser_004 data authResults:" + data.authResults);
done();
});
} catch (err) {
console.log(`Test_requestPermissionsFromUser_004 catch err->${JSON.stringify(err)}`);
expect(result).assertEqual(undefined);
done();
}
});
/**
*@tc.number : TEST_GRANT_STATUS_001
*@tc.name : testGrantStatus001
*@tc.desc : Test enum.
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it("testGrantStatus001", 0, function () {
try {
expect(abilityAccessCtrl.GrantStatus.PERMISSION_DENIED).assertEqual(-1);
} catch (err) {
console.info("testGrantStatus001 meet an error: " + err);
}
});
/**
*@tc.number : TEST_GRANT_STATUS_002
*@tc.name : testGrantStatus002
*@tc.desc : Test enum.
*@tc.size : MediumTest
*@tc.type : Function
*@tc.level : Level 2
*/
it("testGrantStatus002", 0, function () {
try {
expect(abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED).assertEqual(0);
} catch (err) {
console.info("testGrantStatus002 meet an error: " + err);
}
});
})
}
/*
* 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 AccessTokenTest from './AccessToken.test'
export default function testsuite() {
AccessTokenTest()
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"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"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册