Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
0e174642
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0e174642
编写于
7月 08, 2022
作者:
O
openharmony_ci
提交者:
Gitee
7月 08, 2022
浏览文件
操作
浏览文件
下载
差异文件
!4213 【location】脚本优化
Merge pull request !4213 from 权力/myfeature
上级
94e6374f
b4ee85cf
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
318 addition
and
245 deletion
+318
-245
location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js
...on_standard/src/main/js/default/test/GeocoderTest.test.js
+245
-191
location/geolocation_standard/src/main/js/default/test/Geolocation.test.js
...ion_standard/src/main/js/default/test/Geolocation.test.js
+45
-42
location/geolocation_standard/src/main/js/default/test/LocationTest.test.js
...on_standard/src/main/js/default/test/LocationTest.test.js
+28
-12
未找到文件。
location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js
浏览文件 @
0e174642
此差异已折叠。
点击以展开。
location/geolocation_standard/src/main/js/default/test/Geolocation.test.js
浏览文件 @
0e174642
...
...
@@ -16,52 +16,60 @@ 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
){
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:
'
+
JSON
.
stringify
(
result
));
if
(
!
result
){
await
geolocation
.
requestEnableLocation
().
then
(
async
(
result
)
=>
{
await
sleep
(
3000
);
console
.
info
(
'
[lbs_js] test requestEnableLocation promise result:
'
+
JSON
.
stringify
(
result
));
expect
(
result
).
assertTrue
();
}).
catch
((
error
)
=>
{
console
.
info
(
"
[lbs_js] promise then error.
"
+
JSON
.
stringify
(
error
));
expect
().
assertFail
();
});
}
});
await
geolocation
.
isLocationEnabled
().
then
(
async
(
result
)
=>
{
console
.
info
(
'
[lbs_js] getLocationSwitchState result:
'
+
JSON
.
stringify
(
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
.
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
();
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 :
'
+
JSON
.
stringify
(
result
));
}).
catch
((
err
)
=>
{
console
.
info
(
'
[permission] case grantUserGrantedPermission failed :
'
+
JSON
.
stringify
(
err
));
});
await
atManager
.
grantUserGrantedPermission
(
tokenID
,
permissionName2
,
1
).
then
((
result
)
=>
{
console
.
info
(
'
[permission] case grantUserGrantedPermission success :
'
+
JSON
.
stringify
(
result
));
}).
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
)
{
console
.
info
(
'
beforeAll case
'
);
await
applyPermission
();
...
...
@@ -192,17 +200,12 @@ describe('geolocationTest', function () {
* @tc.level Level 2
*/
it
(
'
SUB_HSS_LocationSystem_0005
'
,
0
,
async
function
(
done
)
{
geolocation
.
unsubscribe
(
(
result
)
=>
{
if
(
err
){
return
console
.
info
(
"
unsubscribe err:
"
+
err
);
}
console
.
info
(
"
unsubscribe result:
"
+
JSON
.
stringify
(
result
));
expect
(
true
).
assertEqual
(
result
!=
null
);
});
geolocation
.
unsubscribe
();
console
.
info
(
"
[lbs_js] unsubscribe called
"
)
done
();
})
})
location/geolocation_standard/src/main/js/default/test/LocationTest.test.js
浏览文件 @
0e174642
...
...
@@ -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,22 +35,29 @@ function sleep(ms) {
async
function
changedLocationMode
(){
await
geolocation
.
isLocationEnabled
().
then
(
async
(
result
)
=>
{
console
.
info
(
'
[lbs_js] getLocationSwitchState result:
'
+
result
);
console
.
info
(
'
[lbs_js] getLocationSwitchState result:
'
+
JSON
.
stringify
(
result
)
);
if
(
!
result
){
await
geolocation
.
requestEnableLocation
().
then
(
async
(
result
)
=>
{
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
();
}).
catch
((
error
)
=>
{
console
.
info
(
"
[lbs_js] promise then error.
"
+
error
.
message
);
console
.
info
(
"
[lbs_js] promise then error.
"
+
JSON
.
stringify
(
error
)
);
expect
().
assertFail
();
});
}
})
});
await
geolocation
.
isLocationEnabled
().
then
(
async
(
result
)
=>
{
console
.
info
(
'
[lbs_js] getLocationSwitchState result:
'
+
JSON
.
stringify
(
result
));
});
}
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
();
if
(
atManager
!=
null
)
{
let
tokenID
=
appInfo
.
accessTokenId
;
...
...
@@ -57,21 +65,21 @@ async function applyPermission() {
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
);
console
.
info
(
'
[permission] case grantUserGrantedPermission success :
'
+
JSON
.
stringify
(
result
)
);
}).
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
)
=>
{
console
.
info
(
'
[permission] case grantUserGrantedPermission success :
'
+
result
);
console
.
info
(
'
[permission] case grantUserGrantedPermission success :
'
+
JSON
.
stringify
(
result
)
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[permission] case grantUserGrantedPermission failed :
'
+
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
_geo3
'
,
function
()
{
let
data
=
{
title
:
""
,
locationChange
:
null
,
...
...
@@ -1037,6 +1045,8 @@ describe('geolocationTest', function () {
geolocation
.
getCachedGnssLocationsSize
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
'
[lbs_js] getCachedGnssLocationsSize callback err is :
'
+
err
);
expect
(
true
).
assertTrue
(
err
!=
null
);
done
();
}
else
{
console
.
info
(
"
[lbs_js] getCachedGnssLocationsSize callback data is:
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertTrue
(
data
!=
null
);
...
...
@@ -1086,7 +1096,8 @@ describe('geolocationTest', function () {
done
();
}).
catch
((
error
)
=>
{
console
.
info
(
"
[lbs_js] promise then error.
"
+
error
.
message
);
expect
().
assertFail
();
expect
(
true
).
assertTrue
(
error
!=
null
);
done
();
done
();
});
})
...
...
@@ -1106,6 +1117,8 @@ describe('geolocationTest', function () {
(
result
)
=>
{
if
(
err
){
return
console
.
info
(
"
oncachedGnssLocationsReporting callback err:
"
+
err
);
expect
(
true
).
assertTrue
(
err
!=
null
);
done
();
}
console
.
info
(
"
cachedGnssLocationsReporting result:
"
+
JSON
.
stringify
(
result
));
expect
(
true
).
assertEqual
(
result
!=
null
);
...
...
@@ -1128,6 +1141,8 @@ describe('geolocationTest', function () {
geolocation
.
flushCachedGnssLocations
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
'
[lbs_js] flushCachedGnssLocations callback err is :
'
+
err
);
expect
(
true
).
assertTrue
(
err
!=
null
);
done
();
}
else
{
console
.
info
(
"
[lbs_js] flushCachedGnssLocations callback data is:
"
+
JSON
.
stringify
(
data
));
expect
(
true
).
assertTrue
(
data
);
...
...
@@ -1177,7 +1192,7 @@ describe('geolocationTest', function () {
done
();
}).
catch
((
error
)
=>
{
console
.
info
(
"
[lbs_js] promise then error.
"
+
error
.
message
);
expect
(
).
assertFail
(
);
expect
(
true
).
assertTrue
(
error
!=
null
);
done
();
});
})
...
...
@@ -1185,3 +1200,4 @@ describe('geolocationTest', function () {
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录