Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
eacb04ab
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看板
未验证
提交
eacb04ab
编写于
6月 01, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8867 avsession新增接口用例合入
Merge pull request !8867 from 张乐杰/OpenHarmony-4.0-Beta1
上级
256ffe87
b0012e3c
变更
4
展开全部
显示空白变更内容
内联
并排
Showing
4 changed file
with
2259 addition
and
0 deletion
+2259
-0
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerJSTest.js
...sionManager/src/main/js/test/AVSessionControllerJSTest.js
+1484
-0
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionJSTest.js
...dard/avsessionManager/src/main/js/test/AVSessionJSTest.js
+472
-0
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerJSTest.js
...sessionManager/src/main/js/test/AVSessionManagerJSTest.js
+297
-0
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js
...s_standard/avsessionManager/src/main/js/test/List.test.js
+6
-0
未找到文件。
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerJSTest.js
0 → 100644
浏览文件 @
eacb04ab
此差异已折叠。
点击以展开。
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionJSTest.js
0 → 100644
浏览文件 @
eacb04ab
/*
* Copyright (c) 2023 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
avSession
from
'
@ohos.multimedia.avsession
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
import
{
afterAll
,
afterEach
,
beforeAll
,
beforeEach
,
describe
,
expect
,
it
}
from
'
@ohos/hypium
'
;
const
TAG
=
"
[AVSessionJSTest]
"
;
export
default
function
AVSessionJsTest
()
{
describe
(
"
AVSessionJsTest
"
,
function
()
{
let
session
=
null
;
let
controller
=
null
;
let
receivedCallback
=
false
;
let
receivedCallback2
=
false
;
let
receivedString
=
null
;
let
receivedString2
=
null
;
let
receivedParam
=
null
;
let
receivedParam2
=
null
;
const
INVALID_STRING
=
"
invalid string
"
;
const
UPDATE_LYRICS_EVENT
=
"
dynamic_lyrics
"
;
const
UPDATE_LYRICS_WANT_PARAMS
=
{
lyric
:
"
This is my lyrics
"
};
const
COMMON_COMMAND_STRING
=
"
common_command
"
;
const
COMMON_COMMAND_PARAMS
=
{
command
:
"
This is my command
"
};
const
CUSTOM_EXTRAS
=
{
extras
:
"
This is custom media packet
"
};
beforeAll
(
async
function
()
{
session
=
await
avSession
.
createAVSession
(
featureAbility
.
getContext
(),
"
AVSessionDemo
"
,
'
audio
'
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
Create AVSession error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
});
session
.
activate
();
controller
=
await
avSession
.
createController
(
session
.
sessionId
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
Create controller error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
})
console
.
info
(
TAG
+
"
Create session finished, beforeAll called
"
);
})
afterAll
(
function
()
{
session
.
destroy
();
console
.
info
(
TAG
+
'
afterAll called
'
)
})
beforeEach
(
function
()
{
console
.
info
(
TAG
+
'
beforeEach called
'
)
})
afterEach
(
function
()
{
console
.
info
(
TAG
+
'
afterEach called
'
)
})
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
));
}
function
commonCommandCallback1
(
command
,
args
)
{
console
.
log
(
TAG
+
"
Callback1 received event:
"
+
JSON
.
stringify
(
command
));
console
.
log
(
TAG
+
"
Callback1 received args:
"
+
JSON
.
stringify
(
args
));
if
(
command
!=
COMMON_COMMAND_STRING
)
{
console
.
error
(
TAG
+
"
Callback1 common command unmatch
"
);
expect
().
assertFail
();
}
receivedCallback
=
true
;
receivedString
=
command
;
receivedParam
=
args
;
}
function
commonCommandCallback2
(
command
,
args
)
{
console
.
log
(
TAG
+
"
Callback2 received event:
"
+
JSON
.
stringify
(
command
));
console
.
log
(
TAG
+
"
Callback2 received args:
"
+
JSON
.
stringify
(
args
));
if
(
command
!=
COMMON_COMMAND_STRING
)
{
console
.
error
(
TAG
+
"
Callback2 common command unmatch
"
);
expect
().
assertFail
();
}
receivedCallback2
=
true
;
receivedString2
=
command
;
receivedParam2
=
args
;
}
/*
* @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100
* @tc.desc:Set session event - callback
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100
"
,
0
,
async
function
(
done
)
{
session
.
dispatchSessionEvent
(
UPDATE_LYRICS_EVENT
,
UPDATE_LYRICS_WANT_PARAMS
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
}
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100 finished
"
);
expect
(
true
).
assertTrue
();
done
();
});
})
/*
* @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200
* @tc.desc:Set session event - promise
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200
"
,
0
,
async
function
(
done
)
{
await
session
.
dispatchSessionEvent
(
UPDATE_LYRICS_EVENT
,
UPDATE_LYRICS_WANT_PARAMS
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200 finished
"
);
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0300
* @tc.desc:Set session event - one param
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0300
"
,
0
,
async
function
(
done
)
{
let
errCode
=
0
;
await
session
.
dispatchSessionEvent
(
UPDATE_LYRICS_EVENT
).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0300 caught error
"
+
err
.
code
);
errCode
=
err
.
code
;
});
sleep
(
200
).
then
(()
=>
{
expect
(
errCode
==
401
).
assertTrue
();
done
();
})
})
/*
* @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0400
* @tc.desc:Set session event - invalid params
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0400
"
,
0
,
async
function
(
done
)
{
let
errCode
=
0
;
await
session
.
dispatchSessionEvent
(
UPDATE_LYRICS_WANT_PARAMS
,
UPDATE_LYRICS_WANT_PARAMS
).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0400 caught error
"
+
err
.
code
);
errCode
=
err
.
code
;
});
sleep
(
200
).
then
(()
=>
{
expect
(
errCode
==
401
).
assertTrue
();
done
();
})
})
/*
* @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0100
* @tc.desc:Set extras - callback
* @tc.type: FUNC
* @tc.require: I6TD43
*/
it
(
"
SUB_MULTIMEDIA_SETEXTRAS_0100
"
,
0
,
async
function
(
done
)
{
session
.
setExtras
(
CUSTOM_EXTRAS
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0100 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
}
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0100 finished
"
);
expect
(
true
).
assertTrue
();
done
();
});
})
/*
* @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0200
* @tc.desc:Set extras - promise
* @tc.type: FUNC
* @tc.require: I6TD43
*/
it
(
"
SUB_MULTIMEDIA_SETEXTRAS_0200
"
,
0
,
async
function
(
done
)
{
await
session
.
setExtras
(
CUSTOM_EXTRAS
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0200 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0200 finished
"
);
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0300
* @tc.desc:Set extras - zero param
* @tc.type: FUNC
* @tc.require: I6TD43
*/
it
(
"
SUB_MULTIMEDIA_SETEXTRAS_0300
"
,
0
,
async
function
(
done
)
{
let
errCode
=
0
;
await
session
.
setExtras
().
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0300 caught error
"
+
err
.
code
);
errCode
=
err
.
code
;
});
sleep
(
200
).
then
(()
=>
{
expect
(
errCode
==
401
).
assertTrue
();
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0300 finished
"
);
done
();
})
})
/*
* @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0400
* @tc.desc:Set extras - invalid params
* @tc.type: FUNC
* @tc.require: I6TD43
*/
it
(
"
SUB_MULTIMEDIA_SETEXTRAS_0400
"
,
0
,
async
function
(
done
)
{
let
errCode
=
0
;
await
session
.
setExtras
(
INVALID_STRING
).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0400 caught error
"
+
err
.
code
);
errCode
=
err
.
code
;
});
sleep
(
200
).
then
(()
=>
{
expect
(
errCode
==
401
).
assertTrue
();
console
.
info
(
TAG
+
"
SUB_MULTIMEDIA_SETEXTRAS_0400 finished
"
);
done
();
})
})
/*
* @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100
* @tc.desc:One on function - common command
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100
"
,
0
,
async
function
(
done
)
{
session
.
on
(
'
commonCommand
'
,
commonCommandCallback1
);
await
controller
.
sendCommonCommand
(
COMMON_COMMAND_STRING
,
COMMON_COMMAND_PARAMS
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
sleep
(
200
).
then
(()
=>
{
if
(
receivedCallback
)
{
console
.
log
(
TAG
+
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100 Received common command
"
);
expect
(
receivedString
==
COMMON_COMMAND_STRING
).
assertTrue
();
expect
(
receivedParam
.
command
==
COMMON_COMMAND_PARAMS
.
command
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100 Common command not received
"
);
expect
().
assertFail
();
}
receivedCallback
=
false
;
receivedString
=
null
;
receivedParam
=
null
;
done
();
})
})
/*
* @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200
* @tc.desc:Two on functions - common command
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200
"
,
0
,
async
function
(
done
)
{
session
.
on
(
'
commonCommand
'
,
commonCommandCallback1
);
session
.
on
(
'
commonCommand
'
,
commonCommandCallback2
);
await
controller
.
sendCommonCommand
(
COMMON_COMMAND_STRING
,
COMMON_COMMAND_PARAMS
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200 Send common command error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
await
sleep
(
200
);
if
(
receivedCallback
&&
receivedCallback2
)
{
console
.
log
(
TAG
+
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200 Received common command
"
);
expect
(
receivedString
==
COMMON_COMMAND_STRING
).
assertTrue
();
expect
(
receivedParam
.
command
==
COMMON_COMMAND_PARAMS
.
command
).
assertTrue
();
expect
(
receivedString2
==
COMMON_COMMAND_STRING
).
assertTrue
();
expect
(
receivedParam2
.
command
==
COMMON_COMMAND_PARAMS
.
command
).
assertTrue
();
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200 Common command not received
"
);
expect
().
assertFail
();
}
receivedCallback
=
false
;
receivedString
=
null
;
receivedParam
=
null
;
receivedCallback2
=
false
;
receivedString2
=
null
;
receivedParam2
=
null
;
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0300
* @tc.desc:One on functions - one param
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0300
"
,
0
,
async
function
(
done
)
{
try
{
session
.
on
(
'
commonCommand
'
);
}
catch
(
err
)
{
expect
(
err
.
code
==
401
).
assertTrue
();
}
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0400
* @tc.desc:One on functions - three params
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0400
"
,
0
,
async
function
(
done
)
{
try
{
session
.
on
(
'
sessionEventChange
'
,
commonCommandCallback1
,
commonCommandCallback2
);
}
catch
(
err
)
{
expect
(
err
.
code
==
401
).
assertTrue
();
}
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0500
* @tc.desc:One on functions - invalid type
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_ONCOMMONCOMMAND_0500
"
,
0
,
async
function
(
done
)
{
try
{
session
.
on
(
'
commonCommand
'
,
INVALID_STRING
);
}
catch
(
err
)
{
expect
(
err
.
code
==
401
).
assertTrue
();
}
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100
* @tc.desc:Two on functions and one off function
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100
"
,
0
,
async
function
(
done
)
{
session
.
on
(
'
commonCommand
'
,
commonCommandCallback1
);
session
.
on
(
'
commonCommand
'
,
commonCommandCallback2
);
session
.
off
(
'
commonCommand
'
,
commonCommandCallback2
);
await
controller
.
sendCommonCommand
(
COMMON_COMMAND_STRING
,
COMMON_COMMAND_PARAMS
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100 Send common command error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
await
sleep
(
200
);
if
(
receivedCallback
&&
!
receivedCallback2
)
{
console
.
log
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100 finished
"
);
expect
(
receivedString
==
COMMON_COMMAND_STRING
).
assertTrue
();
expect
(
receivedParam
.
command
==
COMMON_COMMAND_PARAMS
.
command
).
assertTrue
();
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100 failed
"
);
expect
().
assertFail
();
}
receivedCallback
=
false
;
receivedString
=
null
;
receivedParam
=
null
;
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200
* @tc.desc:Two on functions and two off function
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200
"
,
0
,
async
function
(
done
)
{
session
.
on
(
'
commonCommand
'
,
commonCommandCallback1
);
session
.
on
(
'
commonCommand
'
,
commonCommandCallback2
);
session
.
off
(
'
commonCommand
'
,
commonCommandCallback1
);
session
.
off
(
'
commonCommand
'
,
commonCommandCallback2
);
await
controller
.
sendCommonCommand
(
COMMON_COMMAND_STRING
,
COMMON_COMMAND_PARAMS
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200 Send common command error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
await
sleep
(
200
);
if
(
!
receivedCallback
&&
!
receivedCallback2
)
{
console
.
log
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200 finished
"
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200 failed
"
);
expect
().
assertFail
();
}
receivedCallback
=
false
;
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300
* @tc.desc:Two on functions and off all function
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300
"
,
0
,
async
function
(
done
)
{
session
.
on
(
'
commonCommand
'
,
commonCommandCallback1
);
session
.
on
(
'
commonCommand
'
,
commonCommandCallback2
);
session
.
off
(
'
commonCommand
'
);
await
controller
.
sendCommonCommand
(
COMMON_COMMAND_STRING
,
COMMON_COMMAND_PARAMS
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300 Send common command error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
await
sleep
(
200
);
if
(
!
receivedCallback
&&
!
receivedCallback2
)
{
console
.
log
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300 finished
"
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300 failed
"
);
expect
().
assertFail
();
}
receivedCallback
=
false
;
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0400
* @tc.desc:Two on functions and off function - three params
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0400
"
,
0
,
async
function
(
done
)
{
try
{
session
.
on
(
'
commonCommand
'
,
commonCommandCallback1
);
session
.
on
(
'
commonCommand
'
,
commonCommandCallback2
);
session
.
off
(
'
commonCommand
'
,
commonCommandCallback1
,
commonCommandCallback2
);
}
catch
(
err
)
{
expect
(
err
.
code
==
401
).
assertTrue
();
}
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0500
* @tc.desc:One on functions and off all function - invalid type
* @tc.type: FUNC
* @tc.require: I6ETY6
*/
it
(
"
SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0500
"
,
0
,
async
function
(
done
)
{
try
{
session
.
on
(
'
commonCommand
'
,
commonCommandCallback1
);
session
.
off
(
'
commonCommand
'
,
INVALID_STRING
);
}
catch
(
err
)
{
expect
(
err
.
code
==
401
).
assertTrue
();
}
done
();
})
})
}
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerJSTest.js
0 → 100644
浏览文件 @
eacb04ab
/*
* Copyright (c) 2023 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
AVSessionManager
from
'
@ohos.multimedia.avsession
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
import
{
afterAll
,
afterEach
,
beforeAll
,
beforeEach
,
describe
,
expect
,
it
}
from
'
@ohos/hypium
'
;
const
TAG
=
"
[AVSessionManagerJSTest]
"
;
export
default
function
AVSessionManagerJSTest
()
{
describe
(
"
AVSessionManagerJSTest
"
,
function
()
{
let
session
=
null
;
let
controller
=
null
;
let
receivedCallback
=
false
;
let
receivedCallback2
=
false
;
let
context
=
featureAbility
.
getContext
();
const
INVALID_STRING
=
"
invalid string
"
;
const
UPDATE_LYRICS_EVENT
=
"
dynamic_lyrics
"
;
const
UPDATE_LYRICS_WANT_PARAMS
=
{
lyrics
:
"
This is my lyrics
"
}
beforeAll
(
async
function
()
{
console
.
info
(
TAG
+
"
beforeAll called
"
);
})
afterAll
(
function
()
{
console
.
info
(
TAG
+
'
afterAll called
'
);
})
beforeEach
(
function
()
{
console
.
info
(
TAG
+
'
beforeEach called
'
);
})
afterEach
(
function
()
{
console
.
info
(
TAG
+
'
afterEach called
'
);
})
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
));
}
async
function
createSessionTask
()
{
session
=
await
AVSessionManager
.
createAVSession
(
context
,
"
AVSessionDemo
"
,
'
audio
'
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
Create AVSession error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
});
console
.
info
(
TAG
+
"
Create session finished
"
);
}
function
destroySessionTask
()
{
session
.
destroy
();
console
.
info
(
TAG
+
'
Destroy session finished
'
);
}
async
function
createControllerTask
()
{
controller
=
await
AVSessionManager
.
createController
(
session
.
sessionId
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
Create controller error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
});
console
.
info
(
TAG
+
"
Create controller finished
"
);
}
function
destroyControllerTask
()
{
controller
.
destroy
();
console
.
info
(
TAG
+
'
Destroy session finished
'
);
}
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100
"
,
0
,
async
function
(
done
)
{
await
createSessionTask
();
let
descriptors
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
().
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
destroySessionTask
();
done
();
});
if
(
descriptors
.
length
>=
1
)
{
console
.
info
(
`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive :
${
descriptors
[
0
].
isActive
}
`
);
console
.
info
(
`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type :
${
descriptors
[
0
].
type
}
`
);
console
.
info
(
`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag :
${
descriptors
[
0
].
sessionTag
}
`
);
console
.
info
(
`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId :
${
descriptors
[
0
].
sessionId
}
`
);
console
.
info
(
`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName :
${
descriptors
[
0
].
elementName
.
bundleName
}
`
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100 get history session number :
"
+
descriptors
.
length
+
"
, error
"
);
expect
().
assertFail
();
}
destroySessionTask
();
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200
"
,
0
,
async
function
(
done
)
{
await
createSessionTask
();
let
descriptors
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
(
10
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
destroySessionTask
();
done
();
});
if
(
descriptors
.
length
>=
1
)
{
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200 get history session number :
"
+
descriptors
.
length
+
"
, error
"
);
expect
().
assertFail
();
}
destroySessionTask
();
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300
"
,
0
,
async
function
(
done
)
{
await
createSessionTask
();
let
descriptors
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
(
0
).
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
destroySessionTask
();
done
();
});
if
(
descriptors
.
length
==
0
)
{
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300 get history session number :
"
+
descriptors
.
length
+
"
, error
"
);
expect
().
assertFail
();
}
destroySessionTask
();
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400
"
,
0
,
async
function
(
done
)
{
let
flag
=
false
;
await
createSessionTask
();
let
descriptors
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
(
"
0
"
).
catch
((
err
)
=>
{
flag
=
true
;
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400 param error
"
+
JSON
.
stringify
(
err
));
expect
(
true
).
assertTrue
();
destroySessionTask
();
done
();
});
if
(
flag
||
(
!
descriptors
))
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400 error input param has callback , pass
"
);
expect
(
true
).
assertTrue
();
destroySessionTask
();
done
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400 error input param should not return , error
"
);
expect
().
assertFail
();
destroySessionTask
();
done
();
}
})
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500
"
,
0
,
async
function
(
done
)
{
await
createSessionTask
();
await
AVSessionManager
.
getHistoricalSessionDescriptors
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
destroySessionTask
();
done
();
}
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500 return :
"
+
data
);
if
(
data
.
length
>=
1
)
{
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500 get history session number :
"
+
data
.
length
+
"
, error
"
);
expect
().
assertFail
();
}
destroySessionTask
();
done
();
});
})
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600
"
,
0
,
async
function
(
done
)
{
await
createSessionTask
();
destroySessionTask
();
let
descriptors
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
().
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
destroySessionTask
();
done
();
});
if
(
descriptors
.
length
>=
1
)
{
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600 get history session number :
"
+
descriptors
.
length
+
"
, error
"
);
expect
().
assertFail
();
}
destroySessionTask
();
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700
"
,
0
,
async
function
(
done
)
{
let
descriptors
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
().
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
let
size
=
descriptors
.
length
;
await
createSessionTask
();
destroySessionTask
();
let
descriptorsRetry
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
().
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700 retry error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
done
();
});
if
(
descriptorsRetry
.
length
>=
size
)
{
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700 get history session number :
"
+
descriptors
.
length
+
"
, error
"
);
expect
().
assertFail
();
}
done
();
})
/*
* @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800
* @tc.desc:One on function - lyrics session event
* @tc.type: FUNC
* @tc.require: I6C6IN
*/
it
(
"
SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800
"
,
0
,
async
function
(
done
)
{
await
createSessionTask
();
for
(
let
i
=
0
;
i
<
100
;
i
++
)
{
let
descriptors
=
await
AVSessionManager
.
getHistoricalSessionDescriptors
().
catch
((
err
)
=>
{
console
.
error
(
TAG
+
"
loop :
"
+
i
+
"
, SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800 error
"
+
JSON
.
stringify
(
err
));
expect
().
assertFail
();
destroySessionTask
();
done
();
});
if
(
descriptors
.
length
>=
1
)
{
expect
(
true
).
assertTrue
();
}
else
{
console
.
error
(
TAG
+
"
loop :
"
+
i
+
"
, SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800 get history session number :
"
+
descriptors
.
length
+
"
, error
"
);
expect
().
assertFail
();
destroySessionTask
();
done
();
}
}
destroySessionTask
();
done
();
})
})
}
\ No newline at end of file
multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js
浏览文件 @
eacb04ab
...
@@ -17,6 +17,9 @@ import AVSessionManager from './AVSessionManager.test.js';
...
@@ -17,6 +17,9 @@ import AVSessionManager from './AVSessionManager.test.js';
import
AVSessionCallback
from
'
./AVSessionCallback.test.js
'
;
import
AVSessionCallback
from
'
./AVSessionCallback.test.js
'
;
import
AVSessionManagerCallback
from
'
./AVSessionManagerCallback.test.js
'
;
import
AVSessionManagerCallback
from
'
./AVSessionManagerCallback.test.js
'
;
import
AVSessionErrorCode
from
'
./AVSessionErrorCode.test
'
;
import
AVSessionErrorCode
from
'
./AVSessionErrorCode.test
'
;
import
AVSessionControllerJSTest
from
'
./AVSessionControllerJSTest.js
'
;
import
AVSessionManagerJSTest
from
'
./AVSessionManagerJSTest.js
'
;
import
AVSessionJSTest
from
'
./AVSessionJSTest.js
'
;
export
default
function
testsuite
()
{
export
default
function
testsuite
()
{
AVSession
()
AVSession
()
...
@@ -24,4 +27,7 @@ export default function testsuite() {
...
@@ -24,4 +27,7 @@ export default function testsuite() {
AVSessionCallback
()
AVSessionCallback
()
AVSessionManagerCallback
()
AVSessionManagerCallback
()
AVSessionErrorCode
()
AVSessionErrorCode
()
AVSessionJSTest
()
AVSessionManagerJSTest
()
AVSessionControllerJSTest
()
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录