diff --git a/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js b/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js index 5ef1a4d0ce570e953db9eeeaccddab3644f820cb..dbf6dc864820d0cedce78020532c4f1196327a76 100644 --- a/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js +++ b/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js @@ -17,6 +17,8 @@ import geolocation from '@ohos.geolocation'; import { LocationEventListener } from '@ohos.geolocation'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' +import osaccount from '@ohos.account.osAccount' + import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 , TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303, @@ -44,11 +46,18 @@ async function changedLocationMode(){ expect().assertFail(); }); } - }) + }); + await geolocation.isLocationEnabled().then(async(result) => { + console.info('[lbs_js] check LocationSwitchState result: ' + result); + }); } 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(); if (atManager != null) { let tokenID = appInfo.accessTokenId; @@ -1009,3 +1018,4 @@ describe('geolocationTest', function () { + diff --git a/location/geolocation_standard/src/main/js/default/test/Geolocation.test.js b/location/geolocation_standard/src/main/js/default/test/Geolocation.test.js index 328ee5dcf1c6573faa0b15468d001b2bd318a098..f282121b7703115f42a4a8408cef8d48b01ec240 100644 --- a/location/geolocation_standard/src/main/js/default/test/Geolocation.test.js +++ b/location/geolocation_standard/src/main/js/default/test/Geolocation.test.js @@ -16,13 +16,15 @@ import geolocation from '@ohos.geolocation'; import geolocations from '@system.geolocation'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' +import osaccount from '@ohos.account.osAccount' + import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } - async function changedLocationMode(){ +async function changedLocationMode(){ await geolocation.isLocationEnabled().then(async(result) => { console.info('[lbs_js] getLocationSwitchState result: ' + result); if(!result){ @@ -35,11 +37,18 @@ function sleep(ms) { expect().assertFail(); }); } - }) + }); + await geolocation.isLocationEnabled().then(async(result) => { + console.info('[lbs_js] check LocationSwitchState result: ' + result); + }); } 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(); if (atManager != null) { let tokenID = appInfo.accessTokenId; @@ -206,3 +215,4 @@ describe('geolocationTest', function () { }) + diff --git a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js index cd1b6bc5ebad72b82a0c55d6c64fb79f78f512d8..5bcd134051ef5156b11176e6b8b405bc541f4f0c 100644 --- a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js +++ b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js @@ -17,6 +17,7 @@ import geolocation from '@ohos.geolocation'; import { LocationEventListener } from '@ohos.geolocation'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' +import osaccount from '@ohos.account.osAccount' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 , TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303, @@ -34,41 +35,48 @@ function sleep(ms) { async function changedLocationMode(){ await geolocation.isLocationEnabled().then(async(result) => { - console.info('[lbs_js] getLocationSwitchState result: ' + result); - if(!result){ - await geolocation.requestEnableLocation().then(async(result) => { - await sleep(3000); - console.info('[lbs_js] test requestEnableLocation promise result:' + result); - expect(result).assertTrue(); - }).catch((error) => { - console.info("[lbs_js] promise then error." + error.message); - expect().assertFail(); - }); - } - }) + console.info('[lbs_js] getLocationSwitchState result: ' + result); + if(!result){ + await geolocation.requestEnableLocation().then(async(result) => { + await sleep(3000); + console.info('[lbs_js] test requestEnableLocation promise result: ' + result); + expect(result).assertTrue(); + }).catch((error) => { + console.info("[lbs_js] promise then error." + error.message); + expect().assertFail(); + }); + } + }); + await geolocation.isLocationEnabled().then(async(result) => { + console.info('[lbs_js] check LocationSwitchState result: ' + result); + }); } async function applyPermission() { - let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100); - let atManager = abilityAccessCtrl.createAtManager(); - if (atManager != null) { - let tokenID = appInfo.accessTokenId; - console.info('[permission] case accessTokenID is ' + tokenID); - let permissionName1 = 'ohos.permission.LOCATION'; - let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; - await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { - console.info('[permission] case grantUserGrantedPermission success :' + result); - }).catch((err) => { - console.info('[permission] case grantUserGrantedPermission failed :' + err); - }); - await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { - console.info('[permission] case grantUserGrantedPermission success :' + result); - }).catch((err) => { - console.info('[permission] case grantUserGrantedPermission failed :' + err); - }); - } else { - console.info('[permission] case apply permission failed, createAtManager failed'); - } + 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(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.LOCATION'; + let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; + await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + err); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.info('[permission] case grantUserGrantedPermission failed :' + err); + }); + } else { + console.info('[permission] case apply permission failed, createAtManager failed'); + } } describe('geolocationTest', function () { @@ -1185,3 +1193,4 @@ describe('geolocationTest', function () { +