提交 39705b4e 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 f6f68614
......@@ -69,6 +69,16 @@
"when": "inuse"
}
},
{
"name":"ohos.permission.APPROXIMATELY_LOCATION",
"reason":"need use ohos.permission.APPROXIMATELY_LOCATION",
"usedScene": {
"ability": [
"ohos.acts.location.geolocation.function.MainAbility"
],
"when": "inuse"
}
},
{
"name":"ohos.permission.LOCATION_IN_BACKGROUND",
"reason":"need use ohos.permission.LOCATION_IN_BACKGROUND",
......@@ -118,3 +128,4 @@
]
}
}
......@@ -119,7 +119,7 @@ describe('geolocationTest_geo1', function () {
expect(true).assertEqual(JSON.stringify(data) != null);
done();
}
done()
done();
})
});
......@@ -132,14 +132,18 @@ describe('geolocationTest_geo1', function () {
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_Geo_0200', 0, async function (done) {
try {
await geolocation.isGeoServiceAvailable().then((result) => {
console.info('[lbs_js] isGeoServiceAvailable1 promise result: ' + JSON.stringify(result));
console.info('[lbs_js] isGeoServiceAvailable promise result: ' + JSON.stringify(result));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(result) != null);
}).catch((error) => {
console.info("[lbs_js] promise then error." + JSON.stringify(error));
expect().assertFail();
});
} catch (error) {
console.info("[lbs_js] isGeoServiceAvailable error." + JSON.stringify(error));
}
done();
})
......@@ -161,7 +165,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) != null);
}
resolve()
resolve();
});
})
await promise.then(done)
......@@ -231,15 +235,22 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_Geo_0600', 0, async function (done) {
let reverseGeocodeRequest1 = { "latitude": 90, "longitude": 121.62771, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) != null);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null);
console.info('[lbs_js] not support now');
});
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
let reverseGeocodeRequest2 = { "latitude": 90.1, "longitude": 121.62771, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => {
console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
......@@ -247,7 +258,13 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation0602 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) != null);
});
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
let reverseGeocodeRequest3 = { "latitude": -90, "longitude": 121.62771, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) != null);
......@@ -256,7 +273,13 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null);
});
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
let reverseGeocodeRequest4 = { "latitude": -90.1, "longitude": 121.62771, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
......@@ -264,7 +287,11 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation0604 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) != null);
});
done()
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
done();
})
/**
......@@ -277,6 +304,7 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_Geo_0700', 0, async function (done) {
let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) != null);
......@@ -285,7 +313,12 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null);
});
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
let reverseGeocodeRequest1 = { "latitude": 31.265496, "longitude": -180.1, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
......@@ -293,7 +326,12 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation0702 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) != null);
});
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
let reverseGeocodeRequest2 = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) != null);
......@@ -302,7 +340,12 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null);
});
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
let reverseGeocodeRequest3 = { "latitude": 31.265496, "longitude": 180.1, "maxItems": 1 };
try {
await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
......@@ -310,7 +353,11 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation0704 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) != null);
});
done()
} catch (error) {
console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
done();
})
/**
......@@ -429,7 +476,6 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_Geo_1100', 0, async function (done) {
try {
let geocodeRequest = { "description": "", "maxItems": 1 };
await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result));
......@@ -566,7 +612,7 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null);
});
done()
done();
})
/**
......@@ -595,7 +641,7 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null);
});
done()
done();
})
/**
......@@ -772,7 +818,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocationName message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null);
}
done()
done();
})
/**
......@@ -949,3 +995,5 @@ describe('geolocationTest_geo1', function () {
})
})
......@@ -14,7 +14,6 @@
*/
import geolocation from '@ohos.geolocation';
import geolocationm from '@ohos.geoLocationManager';
import geolocations from '@system.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import osaccount from '@ohos.account.osAccount'
......@@ -146,7 +145,7 @@ describe('geolocationTest_4', function () {
* @tc.level since 9
*/
it('SUB_HSS_LocationSystem_CountryCode_0300', 0, async function (done) {
console.info("[lbs_js]countryCodeChange");
console.info("[lbs_js] countryCodeChange");
geolocationm.on('countryCodeChange', function (data) {
console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) );
});
......@@ -165,6 +164,3 @@ describe('geolocationTest_4', function () {
})
})
/*
* Copyright (C) 2022 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 geolocationm from '@ohos.geoLocationManager';
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));
console.info('[lbs_js]sleep function');
}
async function changedLocationMode(){
let result1 = geolocationm.isLocationEnabled();
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result1));
if(!result1){
await geolocationm.requestEnableLocation().then(async(result) => {
await sleep(3000);
console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
}).catch((error) => {
console.info("[lbs_js] promise then error." + JSON.stringify(error));
expect().assertFail();
});
}
let result2 = geolocationm.isLocationEnabled();
console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result2));
}
async function applyPermission() {
let osAccountManager = osaccount.getAccountManager();
console.info("====>testgetuserid get AccountManager finish====");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("====>testgetuserid localId obtained by process:" + 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');
}
}
let CountryCodeType = {
COUNTRY_CODE_FROM_LOCALE : 1,
COUNTRY_CODE_FROM_SIM:2,
COUNTRY_CODE_FROM_LOCATION:3,
COUNTRY_CODE_FROM_NETWORK:4,
}
describe('geolocationTest_6', function () {
beforeAll(async function (done) {
console.info('beforeAll case');
await applyPermission();
done();
})
beforeEach(async function (done) {
console.info('beforeEach case');
await changedLocationMode();
done();
})
/**
* @tc.number SUB_HSS_LocationSystem_CountryCode_0400
* @tc.name Test getCountryCode
* @tc.desc Obtaining Country Code Information
* @tc.type Function
* @tc.level since 9
*/
it('SUB_HSS_LocationSystem_CountryCode_0400', 0, async function (done) {
await geolocationm.getCountryCode().then((result) => {
console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result));
console.info("[lbs_js] country :" + result.country);
console.info("[lbs_js] type: " + result.type);
expect(true).assertTrue(JSON.stringify(result)==CountryCodeType.COUNTRY_CODE_FROM_LOCALE);
expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_SIM);
expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_LOCATION);
expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_NETWORK);
}).catch((error) => {
console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error));
expect().assertFail();
});
done();
})
/**
* @tc.number SUB_HSS_LocationSystem_CountryCode_0500
* @tc.name Test getCountryCode
* @tc.desc Obtaining Country Code Information
* @tc.type Function
* @tc.level since 9
*/
it('SUB_HSS_LocationSystem_CountryCode_0500', 0, async function (done) {
function getCountryCodeCallback() {
return new Promise((resolve, reject) => {
geolocationm.getCountryCode((err,data) => {
if (err) {
return console.info("[lbs_js] getCountryCode callback err: " + JSON.stringify(err));
} else {
console.info("[lbs_js] getCountryCode callback success"+ JSON.stringify(data));
expect(true).assertEqual(data != null);
}
resolve();
})
})
}
await getCountryCodeCallback();
done();
})
/**
* @tc.number SUB_HSS_LocationSystem_CountryCode_0600
* @tc.name getCountryCode_on_off
* @tc.desc The interception country code is changed.
* @tc.type Function
* @tc.level since 9
*/
it('SUB_HSS_LocationSystem_CountryCode_0600', 0, async function (done) {
console.info("[lbs_js] countryCodeChange");
geolocationm.on('countryCodeChange', function (data) {
console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) );
});
await geolocationm.getCountryCode().then((result) => {
console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result));
expect(true).assertTrue(JSON.stringify(result)!=null);
}).catch((error) => {
console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error));
expect().assertFail();
});
geolocationm.off('countryCodeChange', function (data) {
console.info('[lbs_js] countryCodeChange' + JSON.stringify(data));
done();
})
done();
})
})
......@@ -14,6 +14,9 @@
*/
require('./GeocoderTest.test.js')
require('./GeocoderMTest.test.js')
require('./GetCountryCode.test.js')
require('./SystemLocation.test.js')
require('./GetCountryCodeM.test.js')
require('./LocationTest.test.js')
require('./LocationMTest.test.js')
require('./SystemLocation.test.js')
......@@ -127,12 +127,12 @@ describe('geolocationTest_geo3', function () {
console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data));
expect(data).assertTrue();
}
done()
})
done();
});
/**
* @tc.number LocSwitch_0400
* @tc.number SUB_HSS_LocationSystem_LocSwitch_0400
* @tc.name Test requestrequestEnableLocation api.
* @tc.desc Enabling the Location Service Function for a Third-Party Application -Promise Mode
* @tc.size MEDIUM
......@@ -493,11 +493,9 @@ describe('geolocationTest_geo3', function () {
expect(true).assertEqual(JSON.stringify(error) != null);
done();
})
done()
done();
})
/**
* @tc.number SUB_HSS_SendCommand_0100
* @tc.name Test sendCommand
......@@ -508,6 +506,7 @@ describe('geolocationTest_geo3', function () {
*/
it('SUB_HSS_SendCommand_0100', 0, async function (done) {
let requestInfo = { 'scenairo': 0x301, 'command': "command_1" };
try {
await geolocation.sendCommand(requestInfo, (err, result) => {
if (err) {
console.info('sendcommand callback err:' + JSON.stringify(err));
......@@ -516,6 +515,11 @@ describe('geolocationTest_geo3', function () {
}
console.info('sendcommand callback result:' + JSON.stringify(result));
});
} catch (error) {
console.info('sendcommand callback err:' + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null);
}
done();
})
/**
......@@ -528,6 +532,7 @@ describe('geolocationTest_geo3', function () {
*/
it('SUB_HSS_SendCommand_0200', 0, async function (done) {
let requestInfo = { 'scenairo': 0x301, 'command': "command_1" };
try {
geolocation.sendCommand(requestInfo).then((result) => {
console.info('sendCommand promise result:' + result);
done();
......@@ -536,6 +541,12 @@ describe('geolocationTest_geo3', function () {
expect(true).assertEqual(JSON.stringify(error) != null);
done();
})
} catch (error) {
console.info('sendcommand promise err:' + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null);
}
done();
})
/**
......@@ -1249,3 +1260,5 @@ describe('geolocationTest_geo3', function () {
})
})
......@@ -146,7 +146,7 @@ describe('geolocationTest_geo2', function () {
expect().assertFail();
},
});
geolocation.unsubscribe();
geolocations.unsubscribe();
console.info("[lbs_js] unsubscribe called")
done();
})
......@@ -196,3 +196,4 @@ describe('geolocationTest_geo2', function () {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册