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

!4217 【location】脚本优化

Merge pull request !4217 from 权力/cherry-pick-1657244471
...@@ -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;
......
...@@ -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_geo2', function () { ...@@ -206,3 +215,4 @@ describe('geolocationTest_geo2', 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,
...@@ -38,18 +39,25 @@ async function changedLocationMode(){ ...@@ -38,18 +39,25 @@ async function changedLocationMode(){
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();
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;
...@@ -1185,3 +1193,4 @@ describe('geolocationTest_geo3', function () { ...@@ -1185,3 +1193,4 @@ describe('geolocationTest_geo3', function () {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册