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

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 f6f68614
{ {
"app": { "app": {
"bundleName": "ohos.acts.location.geolocation.function", "bundleName": "ohos.acts.location.geolocation.function",
"vendor": "acts", "vendor": "acts",
"version": { "version": {
"code": 1000000, "code": 1000000,
"name": "1.0" "name": "1.0"
}, },
"apiVersion": { "apiVersion": {
"compatible": 4, "compatible": 4,
"target": 5, "target": 5,
"releaseType": "Beta1" "releaseType": "Beta1"
} }
}, },
"deviceConfig": {}, "deviceConfig": {},
"module": { "module": {
"package": "ohos.acts.location.geolocation.function", "package": "ohos.acts.location.geolocation.function",
"name": ".MyApplication", "name": ".MyApplication",
"mainAbility": "ohos.acts.location.geolocation.function.MainAbility", "mainAbility": "ohos.acts.location.geolocation.function.MainAbility",
"deviceType": [ "deviceType": [
"tablet", "tablet",
"default", "default",
"phone" "phone"
], ],
"distro": { "distro": {
"deliveryWithInstall": true, "deliveryWithInstall": true,
"moduleName": "entry", "moduleName": "entry",
"moduleType": "entry" "moduleType": "entry"
}, },
"abilities": [ "abilities": [
{ {
"skills": [ "skills": [
{ {
"entities": [ "entities": [
"entity.system.home" "entity.system.home"
], ],
"actions": [ "actions": [
"action.system.home" "action.system.home"
] ]
} }
], ],
"visible": true, "visible": true,
"name": "ohos.acts.location.geolocation.function.MainAbility", "name": "ohos.acts.location.geolocation.function.MainAbility",
"icon": "$media:icon", "icon": "$media:icon",
"description": "$string:mainability_description", "description": "$string:mainability_description",
"label": "$string:app_name", "label": "$string:app_name",
"type": "page", "type": "page",
"launchType": "standard" "launchType": "standard"
} }
], ],
"reqPermissions": [ "reqPermissions": [
{ {
"name": "ohos.permission.LOCATION", "name": "ohos.permission.LOCATION",
"reason": "need use ohos.permission.LOCATION", "reason": "need use ohos.permission.LOCATION",
"usedScene": { "usedScene": {
"ability": [ "ability": [
"ohos.acts.location.geolocation.function.MainAbility" "ohos.acts.location.geolocation.function.MainAbility"
], ],
"when": "inuse" "when": "inuse"
} }
}, },
{ {
"name":"ohos.permission.ACCESS_LOCATION", "name":"ohos.permission.ACCESS_LOCATION",
"reason":"need use ohos.permission.ACCESS_LOCATION", "reason":"need use ohos.permission.ACCESS_LOCATION",
"usedScene": { "usedScene": {
"ability": [ "ability": [
"ohos.acts.location.geolocation.function.MainAbility" "ohos.acts.location.geolocation.function.MainAbility"
], ],
"when": "inuse" "when": "inuse"
} }
}, },
{ {
"name":"ohos.permission.LOCATION_IN_BACKGROUND", "name":"ohos.permission.APPROXIMATELY_LOCATION",
"reason":"need use ohos.permission.LOCATION_IN_BACKGROUND", "reason":"need use ohos.permission.APPROXIMATELY_LOCATION",
"usedScene": { "usedScene": {
"ability": [ "ability": [
"ohos.acts.location.geolocation.function.MainAbility" "ohos.acts.location.geolocation.function.MainAbility"
], ],
"when": "inuse" "when": "inuse"
} }
}, },
{ {
"name":"ohos.permission.MANAGE_SECURE_SETTINGS", "name":"ohos.permission.LOCATION_IN_BACKGROUND",
"reason":"need use ohos.permission.MANAGE_SECURE_SETTINGS", "reason":"need use ohos.permission.LOCATION_IN_BACKGROUND",
"usedScene": { "usedScene": {
"ability": [ "ability": [
"ohos.acts.location.geolocation.function.MainAbility" "ohos.acts.location.geolocation.function.MainAbility"
], ],
"when": "inuse" "when": "inuse"
} }
}, },
{ {
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", "name":"ohos.permission.MANAGE_SECURE_SETTINGS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" "reason":"need use ohos.permission.MANAGE_SECURE_SETTINGS",
}, "usedScene": {
{ "ability": [
"name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", "ohos.acts.location.geolocation.function.MainAbility"
"reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" ],
}, "when": "inuse"
{ }
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" },
}, {
{ "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"name": "ohos.permission.GET_BUNDLE_INFO" "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
} },
], {
"js": [ "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
{ "reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
"pages": [ },
"pages/index/index" {
], "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
"name": "default", },
"window": { {
"designWidth": 720, "name": "ohos.permission.GET_BUNDLE_INFO"
"autoDesignWidth": false }
} ],
} "js": [
] {
} "pages": [
} "pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
...@@ -119,7 +119,7 @@ describe('geolocationTest_geo1', function () { ...@@ -119,7 +119,7 @@ describe('geolocationTest_geo1', function () {
expect(true).assertEqual(JSON.stringify(data) != null); expect(true).assertEqual(JSON.stringify(data) != null);
done(); done();
} }
done() done();
}) })
}); });
...@@ -132,14 +132,18 @@ describe('geolocationTest_geo1', function () { ...@@ -132,14 +132,18 @@ describe('geolocationTest_geo1', function () {
* @tc.level Level 2 * @tc.level Level 2
*/ */
it('SUB_HSS_LocationSystem_Geo_0200', 0, async function (done) { it('SUB_HSS_LocationSystem_Geo_0200', 0, async function (done) {
await geolocation.isGeoServiceAvailable().then((result) => { try {
console.info('[lbs_js] isGeoServiceAvailable1 promise result: ' + JSON.stringify(result)); await geolocation.isGeoServiceAvailable().then((result) => {
console.info('[lbs_js] not support now'); console.info('[lbs_js] isGeoServiceAvailable promise result: ' + JSON.stringify(result));
expect(true).assertEqual(JSON.stringify(result) != null); console.info('[lbs_js] not support now');
}).catch((error) => { expect(true).assertEqual(JSON.stringify(result) != null);
console.info("[lbs_js] promise then error." + JSON.stringify(error)); }).catch((error) => {
expect().assertFail(); console.info("[lbs_js] promise then error." + JSON.stringify(error));
}); expect().assertFail();
});
} catch (error) {
console.info("[lbs_js] isGeoServiceAvailable error." + JSON.stringify(error));
}
done(); done();
}) })
...@@ -161,7 +165,7 @@ describe('geolocationTest_geo1', function () { ...@@ -161,7 +165,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(data)); console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) != null); expect(true).assertEqual((JSON.stringify(data)) != null);
} }
resolve() resolve();
}); });
}) })
await promise.then(done) await promise.then(done)
...@@ -231,40 +235,63 @@ describe('geolocationTest_geo1', function () { ...@@ -231,40 +235,63 @@ describe('geolocationTest_geo1', function () {
*/ */
it('SUB_HSS_LocationSystem_Geo_0600', 0, async function (done) { it('SUB_HSS_LocationSystem_Geo_0600', 0, async function (done) {
let reverseGeocodeRequest1 = { "latitude": 90, "longitude": 121.62771, "maxItems": 1 }; let reverseGeocodeRequest1 = { "latitude": 90, "longitude": 121.62771, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => {
expect(true).assertEqual((JSON.stringify(data)) != null); console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data));
}).catch(error => { expect(true).assertEqual((JSON.stringify(data)) != null);
console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + JSON.stringify(error)); }).catch(error => {
console.info('[lbs_js] not support now'); console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null); 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 }; let reverseGeocodeRequest2 = { "latitude": 90.1, "longitude": 121.62771, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => {
expect(data.length).assertEqual(0); console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data));
}).catch(error => { expect(data.length).assertEqual(0);
console.info("[lbs_js] getAddressesFromLocation0602 promise then error." + JSON.stringify(error)); }).catch(error => {
expect(true).assertEqual((JSON.stringify(error)) != null); 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 }; let reverseGeocodeRequest3 = { "latitude": -90, "longitude": 121.62771, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => {
expect(true).assertEqual((JSON.stringify(data)) != null); console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data));
}).catch(error => { expect(true).assertEqual((JSON.stringify(data)) != null);
console.info("[lbs_js] getAddressesFromLocation0603 promise then error." + JSON.stringify(error)); }).catch(error => {
console.info('[lbs_js] not support now'); console.info("[lbs_js] getAddressesFromLocation0603 promise then error." + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null); 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 }; let reverseGeocodeRequest4 = { "latitude": -90.1, "longitude": 121.62771, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => {
expect(data.length).assertEqual(0); console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data));
}).catch(error => { expect(data.length).assertEqual(0);
console.info("[lbs_js] getAddressesFromLocation0604 promise then error." + JSON.stringify(error)); }).catch(error => {
expect(true).assertEqual((JSON.stringify(error)) != null); 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,40 +304,60 @@ describe('geolocationTest_geo1', function () { ...@@ -277,40 +304,60 @@ describe('geolocationTest_geo1', function () {
*/ */
it('SUB_HSS_LocationSystem_Geo_0700', 0, async function (done) { it('SUB_HSS_LocationSystem_Geo_0700', 0, async function (done) {
let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
expect(true).assertEqual((JSON.stringify(data)) != null); console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data));
}).catch(error => { expect(true).assertEqual((JSON.stringify(data)) != null);
console.info("[lbs_js] getAddressesFromLocation0701 promise then error." + JSON.stringify(error)); }).catch(error => {
console.info('[lbs_js] not support now'); console.info("[lbs_js] getAddressesFromLocation0701 promise then error." + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null); 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 }; let reverseGeocodeRequest1 = { "latitude": 31.265496, "longitude": -180.1, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => {
expect(data.length).assertEqual(0); console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data));
}).catch(error => { expect(data.length).assertEqual(0);
console.info("[lbs_js] getAddressesFromLocation0702 promise then error." + JSON.stringify(error)); }).catch(error => {
expect(true).assertEqual((JSON.stringify(error)) != null); 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 }; let reverseGeocodeRequest2 = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => {
expect(true).assertEqual((JSON.stringify(data)) != null); console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data));
}).catch(error => { expect(true).assertEqual((JSON.stringify(data)) != null);
console.info("[lbs_js] getAddressesFromLocation0703 promise then error." + JSON.stringify(error)); }).catch(error => {
console.info('[lbs_js] not support now'); console.info("[lbs_js] getAddressesFromLocation0703 promise then error." + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null); 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 }; let reverseGeocodeRequest3 = { "latitude": 31.265496, "longitude": 180.1, "maxItems": 1 };
await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { try {
console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data)); await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => {
expect(data.length).assertEqual(0); console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data));
}).catch(error => { expect(data.length).assertEqual(0);
console.info("[lbs_js] getAddressesFromLocation0704 promise then error." + JSON.stringify(error)); }).catch(error => {
expect(true).assertEqual((JSON.stringify(error)) != null); 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 () { ...@@ -429,7 +476,6 @@ describe('geolocationTest_geo1', function () {
*/ */
it('SUB_HSS_LocationSystem_Geo_1100', 0, async function (done) { it('SUB_HSS_LocationSystem_Geo_1100', 0, async function (done) {
try { try {
let geocodeRequest = { "description": "", "maxItems": 1 }; let geocodeRequest = { "description": "", "maxItems": 1 };
await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result)); console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result));
...@@ -566,7 +612,7 @@ describe('geolocationTest_geo1', function () { ...@@ -566,7 +612,7 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null); expect(true).assertEqual(JSON.stringify(error) != null);
}); });
done() done();
}) })
/** /**
...@@ -595,7 +641,7 @@ describe('geolocationTest_geo1', function () { ...@@ -595,7 +641,7 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] not support now'); console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error) != null); expect(true).assertEqual(JSON.stringify(error) != null);
}); });
done() done();
}) })
/** /**
...@@ -772,7 +818,7 @@ describe('geolocationTest_geo1', function () { ...@@ -772,7 +818,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocationName message." + JSON.stringify(error.message)); console.info("[lbs_js] getAddressesFromLocationName message." + JSON.stringify(error.message));
expect(true).assertEqual((JSON.stringify(error.message)) != null); expect(true).assertEqual((JSON.stringify(error.message)) != null);
} }
done() done();
}) })
/** /**
...@@ -949,3 +995,5 @@ describe('geolocationTest_geo1', function () { ...@@ -949,3 +995,5 @@ describe('geolocationTest_geo1', function () {
}) })
}) })
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
import geolocationm from '@ohos.geoLocationManager'; import geolocationm from '@ohos.geoLocationManager';
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 osaccount from '@ohos.account.osAccount'
...@@ -120,7 +119,7 @@ describe('geolocationTest_4', function () { ...@@ -120,7 +119,7 @@ describe('geolocationTest_4', function () {
* @tc.type Function * @tc.type Function
* @tc.level since 9 * @tc.level since 9
*/ */
it('SUB_HSS_LocationSystem_CountryCode_0200', 0, async function (done) { it('SUB_HSS_LocationSystem_CountryCode_0200', 0, async function (done) {
function getCountryCodeCallback() { function getCountryCodeCallback() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
geolocationm.getCountryCode((err,data) => { geolocationm.getCountryCode((err,data) => {
...@@ -128,7 +127,7 @@ describe('geolocationTest_4', function () { ...@@ -128,7 +127,7 @@ describe('geolocationTest_4', function () {
return console.info("getCountryCode callback err: " + JSON.stringify(err)); return console.info("getCountryCode callback err: " + JSON.stringify(err));
} else { } else {
console.info("getCountryCode callback success"+ JSON.stringify(data)); console.info("getCountryCode callback success"+ JSON.stringify(data));
expect(true).assertEqual(data != null); expect(true).assertEqual(data != null);
} }
resolve(); resolve();
}) })
...@@ -146,7 +145,7 @@ describe('geolocationTest_4', function () { ...@@ -146,7 +145,7 @@ describe('geolocationTest_4', function () {
* @tc.level since 9 * @tc.level since 9
*/ */
it('SUB_HSS_LocationSystem_CountryCode_0300', 0, async function (done) { 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) { geolocationm.on('countryCodeChange', function (data) {
console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) ); console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) );
}); });
...@@ -165,6 +164,3 @@ describe('geolocationTest_4', function () { ...@@ -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 @@ ...@@ -14,6 +14,9 @@
*/ */
require('./GeocoderTest.test.js') require('./GeocoderTest.test.js')
require('./GeocoderMTest.test.js')
require('./GetCountryCode.test.js') require('./GetCountryCode.test.js')
require('./SystemLocation.test.js') require('./GetCountryCodeM.test.js')
require('./LocationTest.test.js') require('./LocationTest.test.js')
require('./LocationMTest.test.js')
require('./SystemLocation.test.js')
...@@ -127,12 +127,12 @@ describe('geolocationTest_geo3', function () { ...@@ -127,12 +127,12 @@ describe('geolocationTest_geo3', function () {
console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data)); console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data));
expect(data).assertTrue(); expect(data).assertTrue();
} }
done()
}) })
done();
}); });
/** /**
* @tc.number LocSwitch_0400 * @tc.number SUB_HSS_LocationSystem_LocSwitch_0400
* @tc.name Test requestrequestEnableLocation api. * @tc.name Test requestrequestEnableLocation api.
* @tc.desc Enabling the Location Service Function for a Third-Party Application -Promise Mode * @tc.desc Enabling the Location Service Function for a Third-Party Application -Promise Mode
* @tc.size MEDIUM * @tc.size MEDIUM
...@@ -164,7 +164,7 @@ describe('geolocationTest_geo3', function () { ...@@ -164,7 +164,7 @@ describe('geolocationTest_geo3', function () {
} }
geolocation.on('locationServiceState', locationServiceState); geolocation.on('locationServiceState', locationServiceState);
geolocation.off('locationServiceState', locationServiceState); geolocation.off('locationServiceState', locationServiceState);
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
}) })
...@@ -193,7 +193,7 @@ describe('geolocationTest_geo3', function () { ...@@ -193,7 +193,7 @@ describe('geolocationTest_geo3', function () {
}); });
}) })
} }
console.info('getCurrentLocationCallback start'); console.info('getCurrentLocationCallback start');
await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
console.info("getCurrentLocation callback_0003, result: " + JSON.stringify(result)); console.info("getCurrentLocation callback_0003, result: " + JSON.stringify(result));
expect(true).assertEqual(result != null); expect(true).assertEqual(result != null);
...@@ -493,11 +493,9 @@ describe('geolocationTest_geo3', function () { ...@@ -493,11 +493,9 @@ describe('geolocationTest_geo3', function () {
expect(true).assertEqual(JSON.stringify(error) != null); expect(true).assertEqual(JSON.stringify(error) != null);
done(); done();
}) })
done() done();
}) })
/** /**
* @tc.number SUB_HSS_SendCommand_0100 * @tc.number SUB_HSS_SendCommand_0100
* @tc.name Test sendCommand * @tc.name Test sendCommand
...@@ -508,14 +506,20 @@ describe('geolocationTest_geo3', function () { ...@@ -508,14 +506,20 @@ describe('geolocationTest_geo3', function () {
*/ */
it('SUB_HSS_SendCommand_0100', 0, async function (done) { it('SUB_HSS_SendCommand_0100', 0, async function (done) {
let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; let requestInfo = { 'scenairo': 0x301, 'command': "command_1" };
await geolocation.sendCommand(requestInfo, (err, result) => { try {
if (err) { await geolocation.sendCommand(requestInfo, (err, result) => {
console.info('sendcommand callback err:' + JSON.stringify(err)); if (err) {
expect(true).assertEqual(JSON.stringify(err) != null); console.info('sendcommand callback err:' + JSON.stringify(err));
done(); expect(true).assertEqual(JSON.stringify(err) != null);
} done();
console.info('sendcommand callback result:' + JSON.stringify(result)); }
}); 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,14 +532,21 @@ describe('geolocationTest_geo3', function () { ...@@ -528,14 +532,21 @@ describe('geolocationTest_geo3', function () {
*/ */
it('SUB_HSS_SendCommand_0200', 0, async function (done) { it('SUB_HSS_SendCommand_0200', 0, async function (done) {
let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; let requestInfo = { 'scenairo': 0x301, 'command': "command_1" };
geolocation.sendCommand(requestInfo).then((result) => { try {
console.info('sendCommand promise result:' + result); geolocation.sendCommand(requestInfo).then((result) => {
done(); console.info('sendCommand promise result:' + result);
}).catch(error => { done();
}).catch(error => {
console.info('sendcommand promise err:' + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null);
done();
})
} catch (error) {
console.info('sendcommand promise err:' + JSON.stringify(error)); console.info('sendcommand promise err:' + JSON.stringify(error));
expect(true).assertEqual(JSON.stringify(error) != null); expect(true).assertEqual(JSON.stringify(error) != null);
done(); }
}) done();
}) })
/** /**
...@@ -1249,3 +1260,5 @@ describe('geolocationTest_geo3', function () { ...@@ -1249,3 +1260,5 @@ describe('geolocationTest_geo3', function () {
}) })
}) })
...@@ -146,7 +146,7 @@ describe('geolocationTest_geo2', function () { ...@@ -146,7 +146,7 @@ describe('geolocationTest_geo2', function () {
expect().assertFail(); expect().assertFail();
}, },
}); });
geolocation.unsubscribe(); geolocations.unsubscribe();
console.info("[lbs_js] unsubscribe called") console.info("[lbs_js] unsubscribe called")
done(); done();
}) })
...@@ -196,3 +196,4 @@ describe('geolocationTest_geo2', function () { ...@@ -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.
先完成此消息的编辑!
想要评论请 注册