提交 b4ee85cf 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 15d905f0
...@@ -16,52 +16,60 @@ import geolocation from '@ohos.geolocation'; ...@@ -16,52 +16,60 @@ 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: ' + JSON.stringify(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: ' + JSON.stringify(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." + JSON.stringify(error));
expect().assertFail(); expect().assertFail();
}); });
} }
}) });
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(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.debug("=== getAccountManager finish");
if (atManager != null) { let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
let tokenID = appInfo.accessTokenId; console.info("LocalId is :" + 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 :' + JSON.stringify(result));
console.info('[permission] case grantUserGrantedPermission success :' + result); }).catch((err) => {
}).catch((err) => { console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
console.info('[permission] case grantUserGrantedPermission failed :' + err); });
}); await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
} else { console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
console.info('[permission] case apply permission failed, createAtManager failed'); }).catch((err) => {
} console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
} }
describe('geolocationTest', function () { describe('geolocationTest_geo2', function () {
beforeAll(async function (done) { beforeAll(async function (done) {
console.info('beforeAll case'); console.info('beforeAll case');
await applyPermission(); await applyPermission();
...@@ -192,17 +200,12 @@ describe('geolocationTest', function () { ...@@ -192,17 +200,12 @@ describe('geolocationTest', function () {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_HSS_LocationSystem_0005', 0, async function (done) { it('SUB_HSS_LocationSystem_0005', 0, async function (done) {
geolocation.unsubscribe( geolocation.unsubscribe();
(result) => { console.info("[lbs_js] unsubscribe called")
if(err){
return console.info("unsubscribe err: " + err);
}
console.info("unsubscribe result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
done(); done();
}) })
}) })
...@@ -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,22 +35,29 @@ function sleep(ms) { ...@@ -34,22 +35,29 @@ 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: ' + JSON.stringify(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: ' + JSON.stringify(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." + JSON.stringify(error));
expect().assertFail(); expect().assertFail();
}); });
} }
}) });
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
});
} }
async function applyPermission() { async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100); let osAccountManager = osaccount.getAccountManager();
console.debug("=== getAccountManager finish");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("LocalId is :" + 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;
...@@ -57,21 +65,21 @@ async function applyPermission() { ...@@ -57,21 +65,21 @@ async function applyPermission() {
let permissionName1 = 'ohos.permission.LOCATION'; let permissionName1 = 'ohos.permission.LOCATION';
let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result); console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => { }).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err); console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
}); });
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result); console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => { }).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err); console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
}); });
} else { } else {
console.info('[permission] case apply permission failed, createAtManager failed'); console.info('[permission] case apply permission failed, createAtManager failed');
} }
} }
describe('geolocationTest', function () { describe('geolocationTest_geo3', function () {
let data = { let data = {
title: "", title: "",
locationChange: null, locationChange: null,
...@@ -1037,6 +1045,8 @@ describe('geolocationTest', function () { ...@@ -1037,6 +1045,8 @@ describe('geolocationTest', function () {
geolocation.getCachedGnssLocationsSize((err, data) => { geolocation.getCachedGnssLocationsSize((err, data) => {
if (err) { if (err) {
console.info('[lbs_js] getCachedGnssLocationsSize callback err is : ' + err); console.info('[lbs_js] getCachedGnssLocationsSize callback err is : ' + err);
expect(true).assertTrue(err != null);
done();
}else { }else {
console.info("[lbs_js] getCachedGnssLocationsSize callback data is: " + JSON.stringify(data)); console.info("[lbs_js] getCachedGnssLocationsSize callback data is: " + JSON.stringify(data));
expect(true).assertTrue(data != null); expect(true).assertTrue(data != null);
...@@ -1086,7 +1096,8 @@ describe('geolocationTest', function () { ...@@ -1086,7 +1096,8 @@ describe('geolocationTest', function () {
done(); done();
}).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(true).assertTrue(error != null);
done();
done(); done();
}); });
}) })
...@@ -1106,6 +1117,8 @@ describe('geolocationTest', function () { ...@@ -1106,6 +1117,8 @@ describe('geolocationTest', function () {
(result) => { (result) => {
if(err){ if(err){
return console.info("oncachedGnssLocationsReporting callback err: " + err); return console.info("oncachedGnssLocationsReporting callback err: " + err);
expect(true).assertTrue(err != null);
done();
} }
console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result)); console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null); expect(true).assertEqual(result !=null);
...@@ -1128,6 +1141,8 @@ describe('geolocationTest', function () { ...@@ -1128,6 +1141,8 @@ describe('geolocationTest', function () {
geolocation.flushCachedGnssLocations((err, data) => { geolocation.flushCachedGnssLocations((err, data) => {
if (err) { if (err) {
console.info('[lbs_js] flushCachedGnssLocations callback err is : ' + err); console.info('[lbs_js] flushCachedGnssLocations callback err is : ' + err);
expect(true).assertTrue(err != null);
done();
}else { }else {
console.info("[lbs_js] flushCachedGnssLocations callback data is: " + JSON.stringify(data)); console.info("[lbs_js] flushCachedGnssLocations callback data is: " + JSON.stringify(data));
expect(true).assertTrue(data); expect(true).assertTrue(data);
...@@ -1177,7 +1192,7 @@ describe('geolocationTest', function () { ...@@ -1177,7 +1192,7 @@ describe('geolocationTest', function () {
done(); done();
}).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(true).assertTrue(error != null);
done(); done();
}); });
}) })
...@@ -1185,3 +1200,4 @@ describe('geolocationTest', function () { ...@@ -1185,3 +1200,4 @@ describe('geolocationTest', function () {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册