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

!3441 【location】Location脚本优化。

Merge pull request !3441 from 权力/myfeature
...@@ -17,6 +17,8 @@ import geolocation from '@ohos.geolocation'; ...@@ -17,6 +17,8 @@ import geolocation from '@ohos.geolocation';
import { LocationEventListener } from '@ohos.geolocation'; import { LocationEventListener } from '@ohos.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
import osaccount from '@ohos.account.osAccount'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 , let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 ,
TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303, TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303,
...@@ -44,11 +46,18 @@ async function changedLocationMode(){ ...@@ -44,11 +46,18 @@ async function changedLocationMode(){
expect().assertFail(); expect().assertFail();
}); });
} }
}) });
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] check LocationSwitchState result: ' + result);
});
} }
async function applyPermission() { async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100); let osAccountManager = osaccount.getAccountManager();
console.info('[permission] getAccountManager call end');
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info('[permission] getOsAccountLocalIdFromProcess localId' + localId);
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) { if (atManager != null) {
let tokenID = appInfo.accessTokenId; let tokenID = appInfo.accessTokenId;
...@@ -1009,3 +1018,4 @@ describe('geolocationTest', function () { ...@@ -1009,3 +1018,4 @@ describe('geolocationTest', function () {
...@@ -16,13 +16,15 @@ import geolocation from '@ohos.geolocation'; ...@@ -16,13 +16,15 @@ import geolocation from '@ohos.geolocation';
import geolocations from '@system.geolocation'; import geolocations from '@system.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
import osaccount from '@ohos.account.osAccount'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
function sleep(ms) { function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
async function changedLocationMode(){ async function changedLocationMode(){
await geolocation.isLocationEnabled().then(async(result) => { await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + result); console.info('[lbs_js] getLocationSwitchState result: ' + result);
if(!result){ if(!result){
...@@ -35,11 +37,18 @@ function sleep(ms) { ...@@ -35,11 +37,18 @@ function sleep(ms) {
expect().assertFail(); expect().assertFail();
}); });
} }
}) });
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] check LocationSwitchState result: ' + result);
});
} }
async function applyPermission() { async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100); let osAccountManager = osaccount.getAccountManager();
console.info('[permission] getAccountManager call end');
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info('[permission] getOsAccountLocalIdFromProcess localId' + localId);
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) { if (atManager != null) {
let tokenID = appInfo.accessTokenId; let tokenID = appInfo.accessTokenId;
...@@ -206,3 +215,4 @@ describe('geolocationTest', function () { ...@@ -206,3 +215,4 @@ describe('geolocationTest', function () {
}) })
...@@ -17,6 +17,7 @@ import geolocation from '@ohos.geolocation'; ...@@ -17,6 +17,7 @@ import geolocation from '@ohos.geolocation';
import { LocationEventListener } from '@ohos.geolocation'; import { LocationEventListener } from '@ohos.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
import osaccount from '@ohos.account.osAccount'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 , let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 ,
TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303, TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303,
...@@ -34,41 +35,48 @@ function sleep(ms) { ...@@ -34,41 +35,48 @@ function sleep(ms) {
async function changedLocationMode(){ async function changedLocationMode(){
await geolocation.isLocationEnabled().then(async(result) => { await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + result); console.info('[lbs_js] getLocationSwitchState result: ' + result);
if(!result){ if(!result){
await geolocation.requestEnableLocation().then(async(result) => { await geolocation.requestEnableLocation().then(async(result) => {
await sleep(3000); await sleep(3000);
console.info('[lbs_js] test requestEnableLocation promise result:' + result); console.info('[lbs_js] test requestEnableLocation promise result: ' + result);
expect(result).assertTrue(); expect(result).assertTrue();
}).catch((error) => { }).catch((error) => {
console.info("[lbs_js] promise then error." + error.message); console.info("[lbs_js] promise then error." + error.message);
expect().assertFail(); expect().assertFail();
}); });
} }
}) });
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] check LocationSwitchState result: ' + result);
});
} }
async function applyPermission() { async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100); let osAccountManager = osaccount.getAccountManager();
let atManager = abilityAccessCtrl.createAtManager(); console.info('[permission] getAccountManager call end');
if (atManager != null) { let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
let tokenID = appInfo.accessTokenId; console.info('[permission] getOsAccountLocalIdFromProcess localId' + localId);
console.info('[permission] case accessTokenID is ' + tokenID); let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
let permissionName1 = 'ohos.permission.LOCATION'; let atManager = abilityAccessCtrl.createAtManager();
let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; if (atManager != null) {
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { let tokenID = appInfo.accessTokenId;
console.info('[permission] case grantUserGrantedPermission success :' + result); console.info('[permission] case accessTokenID is ' + tokenID);
}).catch((err) => { let permissionName1 = 'ohos.permission.LOCATION';
console.info('[permission] case grantUserGrantedPermission failed :' + err); let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
}); await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case grantUserGrantedPermission success :' + result); }).catch((err) => {
}).catch((err) => { console.info('[permission] case grantUserGrantedPermission failed :' + err);
console.info('[permission] case grantUserGrantedPermission failed :' + err); });
}); await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
} else { console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case apply permission failed, createAtManager failed'); }).catch((err) => {
} console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
} }
describe('geolocationTest', function () { describe('geolocationTest', function () {
...@@ -1185,3 +1193,4 @@ describe('geolocationTest', function () { ...@@ -1185,3 +1193,4 @@ describe('geolocationTest', function () {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册