From 555d5e2b0c72cf3e9897465485750d8c86884aee Mon Sep 17 00:00:00 2001 From: stivn Date: Thu, 27 Oct 2022 13:58:10 +0800 Subject: [PATCH] Add acts Signed-off-by: stivn --- multimedia/BUILD.gn | 2 +- .../avsessionManager/BUILD.gn | 33 + .../avsessionManager/Test.json | 20 + .../signature/openharmony_sx.p7b | Bin 0 -> 3472 bytes .../avsessionManager/src/main/config.json | 105 + .../src/main/js/MainAbility/app.js | 23 + .../src/main/js/MainAbility/i18n/en-US.json | 6 + .../src/main/js/MainAbility/i18n/zh-CN.json | 6 + .../main/js/MainAbility/pages/index/index.css | 46 + .../main/js/MainAbility/pages/index/index.hml | 5 + .../main/js/MainAbility/pages/index/index.js | 27 + .../src/main/js/TestAbility/app.js | 31 + .../src/main/js/TestAbility/i18n/en-US.json | 8 + .../src/main/js/TestAbility/i18n/zh-CN.json | 8 + .../main/js/TestAbility/pages/index/index.css | 30 + .../main/js/TestAbility/pages/index/index.hml | 5 + .../main/js/TestAbility/pages/index/index.js | 26 + .../js/TestRunner/OpenHarmonyTestRunner.js | 58 + .../src/main/js/test/AVSession.test.js | 2433 +++++++++++++++++ .../main/js/test/AVSessionCallback.test.js | 1248 +++++++++ .../main/js/test/AVSessionController.test.js | 1684 ++++++++++++ .../test/AVSessionControllerCallback.test.js | 790 ++++++ .../src/main/js/test/AVSessionManager.test.js | 1144 ++++++++ .../js/test/AVSessionManagerCallback.test.js | 863 ++++++ .../src/main/js/test/List.test.js | 29 + .../main/resources/base/element/string.json | 28 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes 27 files changed, 8657 insertions(+), 1 deletion(-) create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/BUILD.gn create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/Test.json create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/signature/openharmony_sx.p7b create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/config.json create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/app.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/i18n/en-US.json create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/i18n/zh-CN.json create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/pages/index/index.css create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/pages/index/index.hml create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/pages/index/index.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/app.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/en-US.json create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/zh-CN.json create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.css create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.hml create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestRunner/OpenHarmonyTestRunner.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionCallback.test.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerCallback.test.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerCallback.test.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/resources/base/element/string.json create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/resources/base/media/icon.png diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index 77617e5fd..4176c36e6 100644 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -25,6 +25,7 @@ group("multimedia") { "audio/audio_js_standard/audioManager:audio_manager_js_hap", "audio/audio_js_standard/audioRenderer:audio_renderer_js_hap", "audio/audio_js_standard/audioVoip:audio_voip_js_hap", + "avsession/avsession_js_standard/avsessionManager:avsession_framework_js_hap", "camera/camera_js_standard:camera_framework_ets_hap", "image/image_js_standard/image:image_js_hap", "image/image_js_standard/imageColorspace:image_colorspace_js_hap", @@ -42,7 +43,6 @@ group("multimedia") { "image/image_js_standard/imageYUV:image_yuv_js_hap", "image/image_js_standard/image_ndk_test:image_pixelmap_ndk_hap", "media/media_cpp_standard:ActsAvcodecNdkTest", - "media/media_cpp_standard:ActsAvcodecNdkTest", "media/media_js_standard/audioPlayer:audio_player_js_hap", "media/media_js_standard/audioRecorder:audio_recorder_js_hap", "media/media_js_standard/recorderFormat:recorder_format_js_hap", diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/BUILD.gn b/multimedia/avsession/avsession_js_standard/avsessionManager/BUILD.gn new file mode 100644 index 000000000..5cc046fdc --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/BUILD.gn @@ -0,0 +1,33 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("avsession_framework_js_hap") { + hap_profile = "./src/main/config.json" + deps = [ + ":avsession_framework_js_assets", + ":avsession_framework_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsAvsessionFrameworkJsTest" +} +ohos_js_assets("avsession_framework_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("avsession_framework_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/Test.json b/multimedia/avsession/avsession_js_standard/avsessionManager/Test.json new file mode 100644 index 000000000..fabbe7fee --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/Test.json @@ -0,0 +1,20 @@ +{ + "description": "Configuration for avsession manager Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "1800000", + "shell-timeout": "900000", + "bundle-name": "com.example.myapplication", + "package-name": "com.example.myapplication", + "testcase-timeout": "20000" + }, + "kits": [ + { + "test-file-name": [ + "ActsAvsessionFrameworkJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/signature/openharmony_sx.p7b b/multimedia/avsession/avsession_js_standard/avsessionManager/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..0c4198a5b85a61aa9ffb713b43383df5b179b5af GIT binary patch literal 3472 zcmcgvYj6|S6}BEW7$Yz-U~mB&L2LrZzAH<%S0T}vb6Hb zq7YX!<_)DxfP_cP%RmDp1%h!qA!(XG2n`H@dNL`766&^45}IHLgn@R~cED!fM<+Ar zhjz~6-u?ER?|gSINJv(uq)u%%G=DD<3=*~^Bnv@8(kK)NAPGoINuA$p5Rf9VPyiCi zvPX%6mPGOdaUwZufwX}PNBlG;bJ1>6S|XqR&_NMF&LNfOgM1*JE{#V0Zq8H!d9hQi zCS^(w_opaQx@Br5P{{~237|rS$3sFYE}Ll#@r%P`fFvR$=O98MncE*>!hUCz;osMn zK}Tx*6hnH$1n=b%8;F44?PnULB@3h!&B&ajhYoXlK}xkkRiuQLG?y+js~^bj5?zRwxK=VY6>$NHCSAuft{omW{n8!HKK$?QxMm}7~=KT`|4^f zr8usISv!pBv6vUC(#aeOw)GNmqkd9+NgYjjqqqofV3 z!Vs4phU};&hT*nCB;c&``CLJ$!AaG5%k|~HYRYLtYcUPllLf~x;_)oJ5@DVCK&_+F z8gj}NUL2sT!RIn#wJ3|#!i^jTn=xjwVX+F%Yu47quv#qk&{vDl7#?9Ycn?NB%9^yc zTGWmq#$H@LY)&=x*gIo-8(i7@oe>*~s@bXvrO{DoVw`fN(x|fr92FooTMGw!b1+*q zWdM(5p*q&3kA)m^9U!<`7o9f^;Or1@RhEndTWg#2y52Bu+8bP zXmC7Kq4c=x90s#O*#IgFVFM9^rm5wUP9Q0yPgl>pBNxUAm(U6g~Yhe$M+)#$0dM#YxMQl!A*yXRLbc}rtZI2cf zmX#MrJ*dt@7#V9Ew)AAgorqb8w)_CnGJau6%HF&Ls=A-SCD~ne*s-h z#o>SssI-*R6t-9x3x(G!S%alCpmiV$3uBL4942lX7tMrG$`muj^$}k|HPtf`s9F1j zG2texZyNh_#6<`5$rup~1<3qhBPRy|e%yLzo(KiFv5PcD7&2Jn;>W#LFgzr|MET*D z`Z%5Fi*rk*+^iF>K!hK1A`qZi(k<(?=SrpXxF9$4L4SnTwVs?X$qSE*;nD^~=JL5* zUX)i7X{gTMqeWqg2uK&UBvQTx3E@j1A$Y$EMr7?P3JPi&yEAd~l|Wu*7>=GaIg2u%VL`H(0htA7Z7RGl0R z3?^hsLJi3ap*|CYej*3}@_Rw#Jq<)@nD+PsWRA60&w&GEqzvjQ zgHX^{50PMy2uTuGoDu%Jz4hQ%aQ(4SCx0{Ljs3df#gdKLf`9Fw`q9dZ7cNi0_7vX| zeg5rnN;u6nGyDBdTJW{0qyMx{aau&JI6mf$9ac~ZvN<^8CyB>^(M==&+T11`{gOIgD;A4{gPOp2-X10%EgpG_xcc7ixcU5<*AD&adh-3- zH4=e!V9!MUB;XN3N&8kGNKH5!4;UtoK(7CqZ1<%cd~QoRt9$wW_3azmzCzZxFL-WU z-raq9RZ7wP2fy9IEoo`4jbC~&v;@9BdET7liOc`k+GGJ2w0~Qk+iA`EK%m)kb@HJd z%JkUY2a!cxe;eF%S#z{lwNy0lB@c%YItxtTfF$Mj}W7srr$q z$9#rJ8bJCZ@+43Dr8r3{awdtfqRz&(b&|!KZ%9nXA55XYalyga3)*FAn;YJ{=5U;y zyJ`EZ#1BW#ImG%En0{kuJ+fvw__cd6R%!2-qq%5BltTcF)Tjwsce;UUML?b;znSLywlUPk6Oysxn@^Yuh;4 z*7G0J;z@o-9meymL{ga@mPRKMNgfXg%_0 zE2ud9<%TImrSG=A{o$sp&AVVMM+pKng+d!p~KUUuSN-^3I(SU(MbVMO&{NOFz+(ab=+=-O^>SUs~2Q z*4JkI?)s&fLx4j{F*X{Xe(>w6Ih@eh>O!p7=E;1|s zweDM=fFTc0a-mocP~pU++aBFE_V9wtmkdXLcY578Tyu2xTK)a*B{ToEy5e(W4` + + {{ $t('strings.hello') }} {{ title }} + + diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/pages/index/index.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 000000000..f3287ba7a --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,27 @@ +/* + * 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. + */ +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + }, +}; \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/app.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/app.js new file mode 100644 index 000000000..c3f64fa8c --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; + +export default { + onCreate() { + console.info('TestApplication onCreate'); + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + console.info('start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/en-US.json b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 000000000..55561b837 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/zh-CN.json b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 000000000..cce1af067 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.css b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 000000000..b21c92c62 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.hml b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 000000000..f64b040a5 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 000000000..d94b75c08 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 000000000..1bba9fed6 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,58 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key]; + } + } + return targetParams.trim(); +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'; + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters); + var debug = abilityDelegatorArguments.parameters["-D"]; + console.info('debug value : '+ debug); + if (debug == 'true') { + cmd += ' -D'; + } + console.info('cmd : '+ cmd); + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }); + } +}; \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js new file mode 100644 index 000000000..4e226d671 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js @@ -0,0 +1,2433 @@ +/* + * 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 avSession from '@ohos.multimedia.avsession'; +import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from '@ohos/hypium'; +import image from '@ohos.multimedia.image'; +import WantAgent from '@ohos.wantAgent'; +import featureAbility from '@ohos.ability.featureAbility'; + +export default function AVSession() { + describe('AVSession', function () { + let tag = 'ApplicationA'; + let type = 'audio'; + let session; + let controller; + let keyItem = {code:0x49, pressedTime:123456789, deviceId:0}; + let event = {action:2, key:keyItem, keys:[keyItem]}; + let context = featureAbility.getContext(); + + function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + async function getPixelMap() { + let color = new ArrayBuffer(96); + let bufferArr = new Uint8Array(color); + bufferArr.fill('3', 0, 95); + let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, AlphaType: 3}; + return image.createPixelMap(color, opts); + } + + beforeAll(function () { + console.info('TestLog: Start Testing avSession Interfaces'); + }) + + beforeEach(async function () { + console.info('TestLog: Init Session And Controller'); + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await avSession.createController(session.sessionId).then((data) => { + controller = data; + }).catch((err) => { + console.info(`TestLog: Controller create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + }) + + afterEach(async function (done) { + console.info('TestLog: Destroy Session And Controller'); + await session.destroy().then(() => { + console.info('TestLog: Session destroy success'); + }).catch((err) => { + console.info(`TestLog: Session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await controller.destroy().then(() => { + console.info('TestLog: Controller destroy success'); + }).catch((err) => { + console.info(`TestLog: Controller destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + afterAll(function () { + console.info('TestLog: End Testing avSession Interfaces'); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_READ_SESSION_ID_0100 + * @tc.name : READ_SESSION_ID_0100 + * @tc.desc : Testing read sessionId + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_READ_SESSION_ID_0100', 0, async function (done) { + if (session.sessionId.length === 64) { + console.info('TestLog: Read sessionId successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Read sessionId failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0100 + * @tc.name : SETMETADATA_0100 + * @tc.desc : Testing set assetId - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0100', 0, async function (done) { + let metadata0 = { + assetId: '121278', + }; + await session.setAVMetadata(metadata0).then(() => { + console.info('TestLog: Set assetId successfully'); + }).catch((err) => { + console.info(`TestLog: Set assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.assetId === '121278') { + console.info('TestLog: Get assetId Successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get assetId failed'); + console.info(`TestLog: assetId is: ${data.assetId}`); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0200 + * @tc.name : SETMETADATA_0200 + * @tc.desc : Testing set artist - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0200', 0, async function (done) { + let metadata1 = { + assetId: '121278', + artist: 'Eminem', + }; + await session.setAVMetadata(metadata1).then(() => { + console.info('TestLog: Set artist successfully'); + }).catch((err) => { + console.info(`TestLog: Set artist error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.artist === metadata1.artist) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get artist failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get artist error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0300 + * @tc.name : SETMETADATA_0300 + * @tc.desc : Testing set author - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0300', 0, async function (done) { + let metadata2 = { + assetId: '121278', + author: 'ST', + }; + await session.setAVMetadata(metadata2).then(() => { + console.info('TestLog: Set author successfully'); + }).catch((err) => { + console.info(`TestLog: Set author error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.author === metadata2.author) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get author failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get author error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0400 + * @tc.name : SETMETADATA_0400 + * @tc.desc : Testing set album - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0400', 0, async function (done) { + let metadata3 = { + assetId: '121278', + album: 'Slim shady', + }; + await session.setAVMetadata(metadata3).then(() => { + console.info('TestLog: Set album successfully'); + }).catch((err) => { + console.info(`TestLog: Set album error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.album === metadata3.album) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get album failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get album error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0500 + * @tc.name : SETMETADATA_0500 + * @tc.desc : Testing set writer - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0500', 0, async function (done) { + let metadata4 = { + assetId: '121278', + writer: 'ST', + }; + await session.setAVMetadata(metadata4).then(() => { + console.info('TestLog: Set writer successfully'); + }).catch((err) => { + console.info(`TestLog: Set writer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.writer === metadata4.writer) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get writer failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get writer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0600 + * @tc.name : SETMETADATA_0600 + * @tc.desc : Testing set composer - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0600', 0, async function (done) { + let metadata5 = { + assetId: '121278', + composer: 'ST', + }; + await session.setAVMetadata(metadata5).then(() => { + console.info('TestLog: Set composer successfully'); + }).catch((err) => { + console.info(`TestLog: Set composer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.composer === metadata5.composer) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get composer failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get composer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0700 + * @tc.name : SETMETADATA_0700 + * @tc.desc : Testing set duration - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0700', 0, async function (done) { + let metadata6 = { + assetId: '121278', + duration: 2222, + }; + await session.setAVMetadata(metadata6).then(() => { + console.info('TestLog: Set duration successfully'); + }).catch((err) => { + console.info(`TestLog: Set duration error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.duration === metadata6.duration) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get duration failed'); + console.info(`TestLog: Get duration is: ${data.duration}`); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get duration error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0800 + * @tc.name : SETMETADATA_0800 + * @tc.desc : Testing set mediaImage - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0800', 0, async function (done) { + let metadata7 = { + assetId: '121278', + mediaImage: 'https://img2.baidu.com/it/u=3583435814,2833583486&fm=253&fmt=auto&app=138&f=JPEG?w=526&h=500', + }; + await session.setAVMetadata(metadata7).then(() => { + console.info('TestLog: Set mediaImage successfully'); + }).catch((err) => { + console.info(`TestLog: Set mediaImage error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.mediaImage === metadata7.mediaImage) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get mediaImage failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get mediaImage error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0900 + * @tc.name : SETMETADATA_0900 + * @tc.desc : Testing set mediaImage - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0900', 0, async function (done) { + console.info('TestLog: Creat pixelmap'); + let pixelMap = await getPixelMap(); + let readBuffer0 = new ArrayBuffer(96); + await pixelMap.readPixelsToBuffer(readBuffer0); + let bufferArr0 = new Uint8Array(readBuffer0); + let metadata8 = { + assetId: '121278', + mediaImage: pixelMap, + }; + await session.setAVMetadata(metadata8).then(() => { + console.info('TestLog: Set pixelMap successfully'); + }).catch((err) => { + console.info(`TestLog: Set pixelMap error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + let pixMap; + await controller.getAVMetadata().then((data) => { + if (data.assetId === '121278') { + pixMap = data.mediaImage; + } else { + console.info('TestLog: Get pixelMap failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get pixelMap error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + let pixelSize = pixMap.getPixelBytesNumber(); + console.info(`TestLog: pixelSize is: ${pixelSize}`); + let readBuffer = new ArrayBuffer(pixelSize); + await pixMap.readPixelsToBuffer(readBuffer); + let bufferArr2 = new Uint8Array(readBuffer); + for (let i = 0; i < bufferArr2.length; i++) { + if (bufferArr0[i] !== bufferArr2[i]) { + expect(false).assertTrue(); + } else { + expect(true).assertTrue(); + } + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1000 + * @tc.name : SETMETADATA_1000 + * @tc.desc : Testing set publishDate - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1000', 0, async function (done) { + let metadata9 = { + assetId: '121278', + publishDate: new Date(1994,1,1,1), + }; + await session.setAVMetadata(metadata9).then(() => { + console.info('TestLog: Set publishDate successfully'); + }).catch((err) => { + console.info(`TestLog: Set publishDate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.publishDate.getTime() === metadata9.publishDate.getTime()) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get publishDate failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get publishDate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1100 + * @tc.name : SETMETADATA_1100 + * @tc.desc : Testing set subtitle - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1100', 0, async function (done) { + let metadata10 = { + assetId: '121278', + subtitle: '8 Mile', + }; + await session.setAVMetadata(metadata10).then(() => { + console.info('TestLog: Set subtitle successfully'); + }).catch((err) => { + console.info(`TestLog: Set subtitle error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVMetadata().then((data) => { + if (data.subtitle === metadata10.subtitle) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get subtitle failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get subtitle error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1200 + * @tc.name : SETMETADATA_1200 + * @tc.desc : Testing set description - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1200', 0, async function (done) { + let metadata11 = { + assetId: '121278', + description: 'Rap', + }; + await session.setAVMetadata(metadata11).then(() => { + console.info('TestLog: Set description successfully'); + }).catch((err) => { + console.info(`TestLog: Set description error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.description === metadata11.description) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get description failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get description error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1300 + * @tc.name : SETMETADATA_1300 + * @tc.desc : Testing set lyric - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1300', 0, async function (done) { + let metadata12 = { + assetId: '121278', + lyric: 'https://lyric.tingmall.com/lyric/58/970/589710004-LRC-LRC.lrc?t=1649918948000', + }; + await session.setAVMetadata(metadata12).then(() => { + console.info('TestLog: Set lyric successfully'); + }).catch((err) => { + console.info(`TestLog: Set lyric error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVMetadata().then((data) => { + if (data.lyric === metadata12.lyric) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get lyric failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get lyric error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1400 + * @tc.name : SETMETADATA_1400 + * @tc.desc : Testing set assetId - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1400', 0, async function (done) { + let metadata13 = { + assetId: '121278', + previousAssetId: '121277', + nextAssetId: '121279', + }; + await session.setAVMetadata(metadata13).then(() => { + console.info('TestLog: Set assetId successfully'); + }).catch((err) => { + console.info(`TestLog: Set assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVMetadata().then((data) => { + if (data.previousAssetId === metadata13.previousAssetId + && data.nextAssetId === metadata13.nextAssetId) { + expect(true).assertTrue(); + } else { + console.info('TestLog: Get assetId failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1500 + * @tc.name : SETMETADATA_1500 + * @tc.desc : Testing set metadata - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1500', 0, async function (done) { + let metadata14 = { + assetId: '121278', + }; + await session.destroy(); + await sleep(500); + await session.setAVMetadata(metadata14).then(() => { + console.info('TestLog: Set metadata successfully'); + expect(false).assertTrue(); + }).catch((err) => { + console.info(`TestLog: Set metadata error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1600 + * @tc.name : SETMETADATA_1600 + * @tc.desc : Testing set error metadata - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1600', 0, async function (done) { + let metadata15 = { + assetId: '121278', + duration: -2, + }; + await session.setAVMetadata(metadata15).then(() => { + console.info('TestLog: Set duration successfully'); + expect(false).assertTrue(); + }).catch((err) => { + console.info(`TestLog: Set duration error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0100 + * @tc.name : SETAVPLAYBACKSTATE_0100 + * @tc.desc : Testing set playbackstate - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0100', 0, async function (done) { + let PlaybackState1 = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + }; + await session.setAVPlaybackState(PlaybackState1).then(() => { + console.info('TestLog: Set State successfully'); + }).catch((err) => { + console.info(`TestLog: Set State error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.state === 2) { + console.info('TestLog: Get State successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get State failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get State error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0200 + * @tc.name : SETAVPLAYBACKSTATE_0200 + * @tc.desc : Testing set speed - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0200', 0, async function (done) { + let PlaybackState2 = { + speed: 2.6, + }; + + await session.setAVPlaybackState(PlaybackState2).then(() => { + console.info('TestLog: Set speed successfully'); + }).catch((err) => { + console.info(`TestLog: Set speed error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.speed === 2.6) { + console.info('TestLog: Get speed successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get speed failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get speed error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0300 + * @tc.name : SETAVPLAYBACKSTATE_0300 + * @tc.desc : Testing set position - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0300', 0, async function (done) { + let PlaybackState3 = { + position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + }; + + await session.setAVPlaybackState(PlaybackState3).then(() => { + console.info('TestLog: Set position successfully'); + }).catch((err) => { + console.info(`TestLog: Set position error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.position.elapsedTime === 10) { + console.info('TestLog: Get position successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get position failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get position error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0400 + * @tc.name : SETAVPLAYBACKSTATE_0400 + * @tc.desc : Testing set bufferedTime - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0400', 0, async function (done) { + let PlaybackState4 = { + bufferedTime: 1000, + }; + + await session.setAVPlaybackState(PlaybackState4).then(() => { + console.info('TestLog: Set bufferedTime successfully'); + }).catch((err) => { + console.info(`TestLog: Set bufferedTime error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.bufferedTime === 1000) { + console.info('TestLog: Get bufferedTime successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get bufferedTime failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get bufferedTime error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0500 + * @tc.name : SETAVPLAYBACKSTATE_0500 + * @tc.desc : Testing set loopMode - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0500', 0, async function (done) { + let PlaybackState5 = { + loopMode:avSession.LoopMode.LOOP_MODE_SEQUENCE, + }; + + await session.setAVPlaybackState(PlaybackState5).then(() => { + console.info('TestLog: Set loopMode successfully'); + }).catch((err) => { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.loopMode === 0) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0600 + * @tc.name : SETAVPLAYBACKSTATE_0600 + * @tc.desc : Testing set loopMode - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0600', 0, async function (done) { + let PlaybackState6 = { + loopMode: avSession.LoopMode.LOOP_MODE_SINGLE, + }; + + await session.setAVPlaybackState(PlaybackState6).then(() => { + console.info('TestLog: Set loopMode successfully'); + }).catch((err) => { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.loopMode === 1) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0700 + * @tc.name : SETAVPLAYBACKSTATE_0700 + * @tc.desc : Testing set loopMode - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0700', 0, async function (done) { + let PlaybackState7 = { + loopMode: avSession.LoopMode.LOOP_MODE_LIST, + }; + + await session.setAVPlaybackState(PlaybackState7).then(() => { + console.info('TestLog: Set loopMode successfully'); + }).catch((err) => { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.loopMode === 2) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0800 + * @tc.name : SETAVPLAYBACKSTATE_0800 + * @tc.desc : Testing set loopMode - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0800', 0, async function (done) { + let PlaybackState8 = { + loopMode: avSession.LoopMode.LOOP_MODE_SHUFFLE, + }; + + await session.setAVPlaybackState(PlaybackState8).then(() => { + console.info('TestLog: Set loopMode successfully'); + }).catch((err) => { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.loopMode === 3) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0900 + * @tc.name : SETAVPLAYBACKSTATE_0900 + * @tc.desc : Testing set isFavorite - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0900', 0, async function (done) { + let PlaybackState9 = { + isFavorite: true, + }; + + await session.setAVPlaybackState(PlaybackState9).then(() => { + console.info('TestLog: Set isFavorite successfully'); + }).catch((err) => { + console.info(`TestLog: Set isFavorite error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + await controller.getAVPlaybackState().then((data) => { + if (data.isFavorite === true) { + console.info('TestLog: Get isFavorite successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get isFavorite failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get isFavorite error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_1000 + * @tc.name : SETAVPLAYBACKSTATE_1000 + * @tc.desc : Testing set playbackstate - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_1000', 0, async function (done) { + let PlaybackState10 = { + state: avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: 1.0, + position: {elapsedTime: 10, updateTime: (new Date()).getTime()}, + bufferedTime: 1000, + loopMode: avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite: true, + }; + await session.destroy(); + await sleep(500); + await session.setAVPlaybackState(PlaybackState10).then(() => { + console.info('TestLog: Set playbackState successfully'); + expect(false).assertTrue(); + }).catch((err) => { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_1100 + * @tc.name : SETAVPLAYBACKSTATE_1100 + * @tc.desc : Testing set playbackstate - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_1100', 0, async function (done) { + let PlaybackState11 = { + state: avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: -2, + position: {elapsedTime: -2, updateTime: (new Date()).getTime()}, + bufferedTime: -4, + loopMode: avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite: true, + }; + await session.setAVPlaybackState(PlaybackState11).then(() => { + console.info('TestLog: Set playbackState successfully'); + expect(false).assertTrue(); + }).catch((err) => { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETLAUNCHABILITY_PROMISE_0100 + * @tc.name : SETLAUNCHABILITY_0100 + * @tc.desc : Testing set LaunchAbility - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETLAUNCHABILITY_PROMISE_0100', 0, async function(done) { + let wantAgentInfo = { + wants : [ + { + bundleName : 'com.example.myapplication', + abilityName: 'com.example.myapplication.MainAbility' + } + ], + operationType: WantAgent.OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags: [WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] + }; + let agent; + await WantAgent.getWantAgent(wantAgentInfo).then((callback) => { + agent = callback; + }); + + await session.setLaunchAbility(agent).then(() => { + console.info('TestLog: AVSessionTest : Set LaunchAbility'); + }).catch((err) => { + console.info(`TestLog: Set LaunchAbility error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + let wantagent; + await controller.getLaunchAbility().then((data) => { + wantagent = data; + console.info('TestLog: Get launchAbility'); + }).catch((err) => { + console.info(`TestLog: Get LaunchAbility error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await WantAgent.equal(agent, wantagent).then((bool) => { + if (bool) { + console.info('TestLog: AVSessionTest : Set LaunchAbility successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: AVSessionTest : Set LaunchAbility failed'); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SESSIONACTIVATE_PROMISE_0100 + * @tc.name : SESSIONACTIVATE_0100 + * @tc.desc : Testing set session active - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_SESSIONACTIVATE_PROMISE_0100', 0, async function (done) { + await session.activate().then(() => { + console.info('TestLog: Set session active successfully'); + }).catch((err) => { + console.info(`TestLog: Set active error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await controller.isActive().then((data) => { + if (data) { + console.info('TestLog: session is active'); + expect(true).assertTrue(); + } else { + console.info('TestLog: session is directive'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: AVSessionTest error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SESSIONDEACTIVATE_PROMISE_0100 + * @tc.name : SESSIONDEACTIVATE_0100 + * @tc.desc : Testing deactivate session- promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_SESSIONDEACTIVATE_PROMISE_0100', 0, async function (done) { + await session.activate().then(() => { + console.info('TestLog: Set session active'); + }).catch((err) => { + console.info(`TestLog: Set active error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + await session.deactivate().then(() => { + console.info('TestLog: Deactivate session'); + }).catch((err) => { + console.info(`TestLog: Deactivate session error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + await controller.isActive().then((data) => { + if (data) { + console.info('TestLog: session deactivate failed'); + expect(false).assertTrue(); + } else { + console.info('TestLog: session deactivate successfully'); + expect(true).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: AVSessionTest error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SESSIONDESTROY_PROMISE_0100 + * @tc.name : SESSIONDESTROY_0100 + * @tc.desc : Testing destroy session - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_SESSIONDESTROY_PROMISE_0100', 0, async function (done) { + let flag = false; + controller.on('sessionDestroy', () => { + console.info('TestLog: Session destroy successfully'); + flag = true; + }); + + await session.destroy().then(() => { + console.info('TestLog: Session destroy'); + }).catch((err) => { + console.info(`TestLog: Session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: Session destroy successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Session destroy failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPLAY_0100 + * @tc.name : ONPLAY_0100 + * @tc.desc : Testing onPlay callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPLAY_0100', 0, async function (done) { + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({command:'play'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPAUSE_0100 + * @tc.name : ONPAUSE_0100 + * @tc.desc : Testing onPause callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPAUSE_0100', 0, async function (done) { + session.on('pause', () => { + console.info('TestLog: Pause command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({command:'pause'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONSTOP_0100 + * @tc.name : ONSTOP_0100 + * @tc.desc : Testing onStop callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONSTOP_0100', 0, async function (done) { + session.on('stop', () => { + console.info('TestLog: Stop command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({command:'stop'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPLAYNEXT_0100 + * @tc.name : ONPLAYNEXT_0100 + * @tc.desc : Testing onPlayNext callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPLAYNEXT_0100', 0, async function (done) { + session.on('playNext', () => { + console.info('TestLog: PlayNext command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({command:'playNext'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPLAYPREVIOUS_0100 + * @tc.name : ONPLAYPREVIOUS_0100 + * @tc.desc : Testing onPlayPrevious callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPLAYPREVIOUS_0100', 0, async function (done) { + session.on('playPrevious', () => { + console.info('TestLog: PlayPrevious command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({command:'playPrevious'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONFASTFORWARD_0100 + * @tc.name : ONFASTFORWARD_0100 + * @tc.desc : Testing onFastForward callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONFASTFORWARD_0100', 0, async function (done) { + session.on('fastForward', () => { + console.info('TestLog: FastForward command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({command:'fastForward'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONREWIND_0100 + * @tc.name : ONREWIND_0100 + * @tc.desc : Testing onRewind callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONREWIND_0100', 0, async function (done) { + session.on('rewind', () => { + console.info('TestLog: Rewind command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({command:'rewind'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONSEEK_0100 + * @tc.name : ONSEEK_0100 + * @tc.desc : Testing onSeek callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONSEEK_0100', 0, async function (done) { + session.on('seek', (callback) => { + if (callback === 10) { + console.info('TestLog: Seek command callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Seek command callback registration failed'); + expect(false).assertTrue(); + } + }); + + await controller.sendControlCommand({command:'seek', parameter:10}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONSETSPEED_0100 + * @tc.name : ONSETSPEED_0100 + * @tc.desc : Testing Set Speed callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONSETSPEED_0100', 0, async function (done) { + session.on('setSpeed', (callback) => { + if (callback === 2.6) { + console.info('TestLog: SetSpeed command callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: SetSpeed command callback registration error'); + expect(false).assertTrue(); + } + }); + + await controller.sendControlCommand({command:'setSpeed', parameter:2.6}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONSETLOOPMODE_0100 + * @tc.name : ONSETLOOPMODE_0100 + * @tc.desc : Testing Set LoopMode callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONSETLOOPMODE_0100', 0, async function (done) { + session.on('setLoopMode', (callback) => { + if (callback === 1) { + console.info('TestLog: Set LoopMode command callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Set LoopMode command callback registration error'); + expect(false).assertTrue(); + } + }); + + await controller.sendControlCommand({command:'setLoopMode', parameter: + avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONTOGGLEFAVORITE_0100 + * @tc.name : ONTOGGLEFAVORITE_0100 + * @tc.desc : Testing Set toggleFavorite callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONTOGGLEFAVORITE_0100', 0, async function (done) { + session.on('toggleFavorite', (callback) => { + if (callback === 'false') { + console.info('TestLog: Set toggleFavorite command callback registration successful'); + expect(true).assertTrue(); + } + else { + console.info('TestLog: Set toggleFavorite command callback registration error'); + expect(false).assertTrue(); + } + }); + + await controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONHANDLEKEYEVENT_0100 + * @tc.name : ONHANDLEKEYEVENT_0100 + * @tc.desc : Testing Handle KeyEvent callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONHANDLEKEYEVENT_0100', 0, async function (done) { + session.on('handleKeyEvent', (callback) => { + if (callback.action === 2) { + console.info('TestLog: Handle keyEvent callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Handle keyEvent callback registration error'); + expect(false).assertTrue(); + } + }); + + await controller.sendAVKeyEvent(event).then(() => { + console.info('TestLog: Controller send AVKeyEvent successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send AVKeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONWRONGCALLBACK_0100 + * @tc.name : ONWRONGCALLBACK_0100 + * @tc.desc : Testing wrong callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONWRONGCALLBACK_0100', 0, function (done) { + try { + session.on('wrongCall', () => { + console.info('TestLog: Wrong callback registration successful'); + }); + } catch (err) { + console.info(`TestLog: Wrong callback registration error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + done(); + } + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0100 + * @tc.name : OFFPLAY_0100 + * @tc.desc : Testing offPlay callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: Play command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Play command registration2 success'); + expect(false).assertTrue(); + } + + session.on('play', callback1); + + session.on('play', callback2); + + session.off('play'); + + await controller.sendControlCommand({command:'play'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0200 + * @tc.name : OFFPLAY_0200 + * @tc.desc : Testing offPlay callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it ('SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: Play command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Play command registration2 success'); + expect(true).assertTrue(); + } + + session.on('play', callback1); + + session.on('play', callback2); + + session.off('play', callback1); + + await controller.sendControlCommand({command:'play'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPAUSE_0100 + * @tc.name : OFFPAUSE_0100 + * @tc.desc : Testing offPause callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPAUSE_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: Pause command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Pause command registration2 success'); + expect(false).assertTrue(); + } + + session.on('pause', callback1); + + session.on('pause', callback2); + + session.off('pause'); + + await controller.sendControlCommand({command:'pause'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPAUSE_0200 + * @tc.name : OFFPAUSE_0200 + * @tc.desc : Testing offPause callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPAUSE_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: Pause command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Pause command registration2 success'); + expect(true).assertTrue(); + } + + session.on('pause', callback1); + + session.on('pause', callback2); + + session.off('pause', callback1); + + await controller.sendControlCommand({command:'pause'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSTOP_0100 + * @tc.name : OFFSTOP_0100 + * @tc.desc : Testing offStop callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSTOP_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: Stop command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Stop command registration2 success'); + expect(false).assertTrue(); + } + + session.on('stop', callback1) + + session.on('stop', callback2) + + session.off('stop'); + + await controller.sendControlCommand({command:'stop'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSTOP_0200 + * @tc.name : OFFSTOP_0200 + * @tc.desc : Testing offStop callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSTOP_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: Stop command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Stop command registration2 success'); + expect(true).assertTrue(); + } + + session.on('stop', callback1) + + session.on('stop', callback2) + + session.off('stop', callback1) + + await controller.sendControlCommand({command:'stop'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAYNEXT_0100 + * @tc.name : OFFPLAYNEXT_0100 + * @tc.desc : Testing offPlayNext callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAYNEXT_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: PlayNext command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: PlayNext command registration2 success'); + expect(false).assertTrue(); + } + + session.on('playNext', callback1); + + session.on('playNext', callback2); + + session.off('playNext'); + + await controller.sendControlCommand({command:'playNext'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAYNEXT_0200 + * @tc.name : OFFPLAYNEXT_0200 + * @tc.desc : Testing offPlayNext callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAYNEXT_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: PlayNext command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: PlayNext command registration2 success'); + expect(true).assertTrue(); + } + + session.on('playNext', callback1); + + session.on('playNext', callback2); + + session.off('playNext', callback1); + + await controller.sendControlCommand({command:'playNext'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAYPREVIOUS_0100 + * @tc.name : OFFPLAYPREVIOUS_0100 + * @tc.desc : Testing offPlayPrevious callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAYPREVIOUS_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: PlayPrevious command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: PlayPrevious command registration2 success'); + expect(false).assertTrue(); + } + + session.on('playPrevious', callback1); + + session.on('playPrevious', callback2); + + session.off('playPrevious'); + + await controller.sendControlCommand({command:'playPrevious'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAYPREVIOUS_0200 + * @tc.name : OFFPLAYPREVIOUS_0200 + * @tc.desc : Testing offPlayPrevious callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAYPREVIOUS_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: PlayPrevious command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: PlayPrevious command registration2 success'); + expect(true).assertTrue(); + } + + session.on('playPrevious', callback1); + + session.on('playPrevious', callback2); + + session.off('playPrevious', callback1); + + await controller.sendControlCommand({command:'playPrevious'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFFASTFORWARD_0100 + * @tc.name : OFFFASTFORWARD_0100 + * @tc.desc : Testing offFastForward callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFFASTFORWARD_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: FastForward command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: FastForward command registration2 success'); + expect(false).assertTrue(); + } + + session.on('fastForward', callback1); + + session.on('fastForward', callback2); + + session.off('fastForward'); + + await controller.sendControlCommand({command:'fastForward'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFFASTFORWARD_0200 + * @tc.name : OFFFASTFORWARD_0200 + * @tc.desc : Testing offFastForward callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFFASTFORWARD_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: FastForward command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: FastForward command registration2 success'); + expect(true).assertTrue(); + } + + session.on('fastForward', callback1); + + session.on('fastForward', callback2); + + session.off('fastForward', callback1); + + await controller.sendControlCommand({command:'fastForward'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFREWIND_0100 + * @tc.name : OFFREWIND_0100 + * @tc.desc : Testing offRewind callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFREWIND_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: Rewind command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Rewind command registration2 success'); + expect(false).assertTrue(); + } + + session.on('rewind', callback1); + + session.on('rewind', callback2); + + session.off('rewind'); + + await controller.sendControlCommand({command:'rewind'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFREWIND_0200 + * @tc.name : OFFREWIND_0200 + * @tc.desc : Testing offRewind callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFREWIND_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: Rewind command registration1 success'); + expect(false).assertTrue(); + } + + function callback2() { + console.info('TestLog: Rewind command registration2 success'); + expect(true).assertTrue(); + } + + session.on('rewind', callback1); + + session.on('rewind', callback2); + + session.off('rewind', callback1); + + await controller.sendControlCommand({command:'rewind'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSEEK_0100 + * @tc.name : OFFSEEK_0100 + * @tc.desc : Testing offSeek callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSEEK_0100', 0, async function (done) { + function callback1(data) { + if (data === 5) { + console.info('TestLog: offSeek callback1 registration'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 10) { + console.info('TestLog: offSeek callback2 registration'); + expect(false).assertTrue; + } + } + + session.on('seek', callback1); + + session.on('seek', callback2); + + session.off('seek'); + + await controller.sendControlCommand({command:'seek', parameter:10}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSEEK_0200 + * @tc.name : OFFSEEK_0200 + * @tc.desc : Testing offSeek callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSEEK_0200', 0, async function (done) { + function callback1(data) { + if (data === 5) { + console.info('TestLog: offSeek callback1 registration'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 10) { + console.info('TestLog: offSeek callback2 registration'); + expect(true).assertTrue; + } + } + + session.on('seek', callback1); + + session.on('seek', callback2); + + session.off('seek', callback1); + + await controller.sendControlCommand({command:'seek', parameter:10}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSETSPEED_0100 + * @tc.name : OFFSETSPEED_0100 + * @tc.desc : Testing offSetSpeed callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSETSPEED_0100', 0, async function (done) { + function callback1(data) { + if (data === 1.0) { + console.info('TestLog: SetSpend command registration1 success'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 2.0) { + console.info('TestLog: SetSpend command registration2 success'); + expect(false).assertTrue; + } + } + + session.on('setSpeed', callback1); + + session.on('setSpeed', callback2); + + session.off('setSpeed'); + + await controller.sendControlCommand({command:'setSpeed', parameter:2.0}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSETSPEED_0200 + * @tc.name : OFFSETSPEED_0200 + * @tc.desc : Testing offSetSpeed callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSETSPEED_0200', 0, async function (done) { + function callback1(data) { + if (data === 1.0) { + console.info('TestLog: SetSpend command registration1 success'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 2.0) { + console.info('TestLog: SetSpend command registration2 success'); + expect(true).assertTrue; + } + } + + session.on('setSpeed', callback1); + + session.on('setSpeed', callback2); + + session.off('setSpeed', callback1); + + await controller.sendControlCommand({command:'setSpeed', parameter:2.0}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSETLOOPMODE_0100 + * @tc.name : OFFSETLOOPMODE_0100 + * @tc.desc : Testing offSetLoopMode callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSETLOOPMODE_0100', 0, async function (done) { + function callback1(data) { + if (data === 1) { + console.info('TestLog: SetLoopMode command registration1 success'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 2) { + console.info('TestLog: SetLoopMode command registration2 success'); + expect(false).assertTrue; + } + } + + session.on('setLoopMode', callback1); + + session.on('setLoopMode', callback2); + + session.off('setLoopMode'); + + await controller.sendControlCommand({command:'setLoopMode', + parameter:avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSETLOOPMODE_0200 + * @tc.name : OFFSETLOOPMODE_0200 + * @tc.desc : Testing offSetLoopMode callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSETLOOPMODE_0200', 0, async function (done) { + function callback1(data) { + if (data === 2) { + console.info('TestLog: SetLoopMode command registration1 success'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 1) { + console.info('TestLog: SetLoopMode command registration2 success'); + expect(true).assertTrue; + } + } + + session.on('setLoopMode', callback1); + + session.on('setLoopMode', callback2); + + session.off('setLoopMode', callback1); + + await controller.sendControlCommand({command:'setLoopMode', + parameter:avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFTOGGLEFAVORITE_0100 + * @tc.name : OFFTOGGLEFAVORITE_0100 + * @tc.desc : Testing offToggleFavorite callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFTOGGLEFAVORITE_0100', 0, async function (done) { + function callback1(data) { + if (data === 'true') { + console.info('TestLog: ToggleFavorite command registration1 success'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 'false') { + console.info('TestLog: ToggleFavorite command registration1 success'); + expect(false).assertTrue; + } + } + + session.on('toggleFavorite', callback1); + + session.on('toggleFavorite', callback2); + + session.off('toggleFavorite'); + + await controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFTOGGLEFAVORITE_0200 + * @tc.name : OFFTOGGLEFAVORITE_0200 + * @tc.desc : Testing offToggleFavorite callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFTOGGLEFAVORITE_0200', 0, async function (done) { + function callback1(data) { + if (data === 'true') { + console.info('TestLog: ToggleFavorite command registration1 success'); + expect(false).assertTrue; + } + } + + function callback2(data) { + if (data === 'false') { + console.info('TestLog: ToggleFavorite command registration2 success'); + expect(true).assertTrue; + } + } + + session.on('toggleFavorite', callback1); + + session.on('toggleFavorite', callback2); + + session.off('toggleFavorite', callback1); + + await controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFHANDLEKEYEVENT_0100 + * @tc.name : OFFHANDLEKEYEVENT_0100 + * @tc.desc : Testing offHandleKeyEvent callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFHANDLEKEYEVENT_0100', 0, async function (done) { + let flag = true; + function callback1(data) { + if (data.action === 1) { + console.info('TestLog: HandleKeyEvent command registration1 success'); + flag = false; + } + } + + function callback2(data) { + if (data.action === 2) { + console.info('TestLog: HandleKeyEvent command registration2 success'); + flag = false; + } + } + + session.on('handleKeyEvent', callback1); + + session.on('handleKeyEvent', callback2); + + session.off('handleKeyEvent'); + + await controller.sendAVKeyEvent(event).then(() => { + console.info('TestLog: Controller send AVKeyEvent successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send AVKeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + if (flag) { + console.info('TestLog: HandleKeyEvent command callback unRegistration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: HandleKeyEvent command callback unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFHANDLEKEYEVENT_0200 + * @tc.name : OFFHANDLEKEYEVENT_0200 + * @tc.desc : Testing offHandleKeyEvent callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFHANDLEKEYEVENT_0200', 0, async function (done) { + function callback1(data) { + if (data.action === 1) { + console.info('TestLog: HandleKeyEvent command registration1 success'); + expect(false).assertTrue(); + } + } + + function callback2(data) { + if (data.action === 2) { + console.info('TestLog: HandleKeyEvent command registration2 success'); + expect(true).assertTrue(); + } + } + + session.on('handleKeyEvent', callback1); + + session.on('handleKeyEvent', callback2); + + session.off('handleKeyEvent', callback1); + + await controller.sendAVKeyEvent(event).then(() => { + console.info('TestLog: Controller send AVKeyEvent successfully'); + }).catch((err) => { + console.info(`TestLog: Controller send AVKeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + }) +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionCallback.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionCallback.test.js new file mode 100644 index 000000000..bb0695ec8 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionCallback.test.js @@ -0,0 +1,1248 @@ +/* + * 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 avSession from '@ohos.multimedia.avsession'; +import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from '@ohos/hypium'; +import image from '@ohos.multimedia.image'; +import WantAgent from '@ohos.wantAgent'; +import featureAbility from '@ohos.ability.featureAbility'; + +export default function AVSessionCallback() { + describe('AVSessionCallback', function () { + let tag = 'ApplicationA'; + let type = 'audio'; + let session; + let controller; + let context = featureAbility.getContext(); + + function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + async function getPixelMap() { + let color = new ArrayBuffer(96); + let bufferArr = new Uint8Array(color); + bufferArr.fill('3', 0, 95); + let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, AlphaType: 3}; + return image.createPixelMap(color, opts); + } + + beforeAll(function () { + console.info('TestLog: Start Testing AVSession Interfaces'); + }) + + beforeEach(async function () { + console.info('TestLog: Init Session And Controller'); + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await avSession.createController(session.sessionId).then((data) => { + controller = data; + }).catch((err) => { + console.info(`TestLog: Controller created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + }) + + afterEach(async function (done) { + console.info('TestLog: Destroy Session And Controller'); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await controller.destroy().then(() => { + console.info('TestLog: Controller Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Controller Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + afterAll(function () { + console.info('TestLog: End Testing AVSession Interfaces'); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0100 + * @tc.name : SETMETADATA_0100 + * @tc.desc : Testing set assetId - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0100', 0, async function (done) { + let metadata0 = { + assetId: '121278', + }; + + session.setAVMetadata(metadata0, (err) => { + if (err) { + console.info(`TestLog: Set assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }); + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.assetId === metadata0.assetId) { + console.info('TestLog: Get assetId Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get assetId failed: ${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0200 + * @tc.name : SETMETADATA_0200 + * @tc.desc : Testing set artist - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0200', 0, async function (done) { + let metadata1 = { + assetId: '121278', + artist: 'Eminem', + }; + session.setAVMetadata(metadata1, (err) => { + if (err) { + console.info(`TestLog: Set artist error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }); + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get artist error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.artist === metadata1.artist) { + console.info('TestLog: Get artist Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get artist failed' ${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0300 + * @tc.name : SETMETADATA_0300 + * @tc.desc : Testing set author - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0300', 0, async function (done) { + let metadata2 = { + assetId: '121278', + author: 'ST', + }; + session.setAVMetadata(metadata2, (err) => { + if (err) { + console.info(`TestLog: Set author error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get author error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.author === metadata2.author) { + console.info('TestLog: Get author Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get author failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0400 + * @tc.name : SETMETADATA_0400 + * @tc.desc : Testing set album - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0400', 0, async function (done) { + let metadata3 = { + assetId: '121278', + album: 'Slim shady', + }; + session.setAVMetadata(metadata3, (err) => { + if (err) { + console.info(`TestLog: Set album error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get album error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.album === metadata3.album) { + console.info('TestLog: Get album Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get album failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0500 + * @tc.name : SETMETADATA_0500 + * @tc.desc : Testing set writer - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0500', 0, async function (done) { + let metadata4 = { + assetId: '121278', + writer: 'ST', + }; + session.setAVMetadata(metadata4, (err) => { + if (err) { + console.info(`TestLog: Set writer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get writer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.writer === metadata4.writer) { + console.info('TestLog: Get writer Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get writer failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0600 + * @tc.name : SETMETADATA_0600 + * @tc.desc : Testing set composer - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0600', 0, async function (done) { + let metadata5 = { + assetId: '121278', + composer: 'ST', + }; + session.setAVMetadata(metadata5, (err) => { + if (err) { + console.info(`TestLog: Set composer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get composer error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.composer === metadata5.composer) { + console.info('TestLog: Get composer Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get composer failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0700 + * @tc.name : SETMETADATA_0700 + * @tc.desc : Testing set duration - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0700', 0, async function (done) { + let metadata6 = { + assetId: '121278', + duration: 2222, + }; + session.setAVMetadata(metadata6, (err) => { + if (err) { + console.info(`TestLog: Set duration error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get duration error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.duration === metadata6.duration) { + console.info('TestLog: Get duration Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get duration failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0800 + * @tc.name : SETMETADATA_0800 + * @tc.desc : Testing set mediaImage - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0800', 0, async function (done) { + let metadata7 = { + assetId: '121278', + mediaImage: 'https://img2.baidu.com/it/u=3583435814,2833583486&fm=253&fmt=auto&app=138&f=JPEG?w=526&h=500', + }; + session.setAVMetadata(metadata7, (err) => { + if (err) { + console.info(`TestLog: Set mediaImage error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get mediaImage error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.mediaImage === metadata7.mediaImage) { + console.info('TestLog: Get mediaImage Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get mediaImage failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0900 + * @tc.name : SETMETADATA_0900 + * @tc.desc : Testing set mediaImage - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_0900', 0, async function (done) { + console.info('TestLog: Create pixelmap'); + let pixelMap = await getPixelMap(); + let readBuffer0 = new ArrayBuffer(96); + await pixelMap.readPixelsToBuffer(readBuffer0); + let bufferArr0 = new Uint8Array(readBuffer0); + let metadata8 = { + assetId: '121278', + mediaImage: pixelMap, + }; + session.setAVMetadata(metadata8, (err) => { + if (err) { + console.info(`TestLog: Set pixelMap error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + let pixMap; + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get pixelMap error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.assetId === metadata8.assetId) { + console.info('TestLog: Get pixelMap Successfully'); + pixMap = value.mediaImage; + } else { + console.info(`TestLog: Get pixelMap failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + let pixelSize = pixMap.getPixelBytesNumber(); + console.info(`TestLog: pixelSize is:${pixelSize}`); + let readBuffer = new ArrayBuffer(pixelSize); + pixMap.readPixelsToBuffer(readBuffer); + await sleep(500); + let bufferArr2 = new Uint8Array(readBuffer); + for (let i = 0; i < bufferArr2.length; i++) { + if (bufferArr0[i] !== bufferArr2[i]) { + expect(false).assertTrue(); + } else { + expect(true).assertTrue(); + } + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1000 + * @tc.name : SETMETADATA_1000 + * @tc.desc : Testing set publishDate - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1000', 0, async function (done) { + let metadata9 = { + assetId: '121278', + publishDate: new Date(1994,1,1,1), + }; + session.setAVMetadata(metadata9, (err) => { + if (err) { + console.info(`TestLog: Set publishDate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set publishDate : successfully'); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get publishDate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.publishDate.getTime() === metadata9.publishDate.getTime()) { + console.info('TestLog: Get publishDate Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get publishDate failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1100 + * @tc.name : SETMETADATA_1100 + * @tc.desc : Testing set subtitle - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1100', 0, async function (done) { + let metadata10 = { + assetId: '121278', + subtitle: '8 Mile', + }; + + session.setAVMetadata(metadata10, (err) => { + if (err) { + console.info(`TestLog: Set subtitle error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set subtitle successfully'); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get subtitle error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.subtitle === metadata10.subtitle) { + console.info('TestLog: Get subtitle Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get subtitle failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1200 + * @tc.name : SETMETADATA_1200 + * @tc.desc : Testing set description - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1200', 0, async function (done) { + let metadata11 = { + assetId: '121278', + description: 'Rap', + }; + session.setAVMetadata(metadata11, (err) => { + if (err) { + console.info(`TestLog: Set description error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get description error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.description === metadata11.description) { + console.info('TestLog: Get description Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get description failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1300 + * @tc.name : SETMETADATA_1300 + * @tc.desc : Testing set lyric - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1300', 0, async function (done) { + let metadata12 = { + assetId: '121278', + lyric: 'https://lyric.tingmall.com/lyric/58/970/58970104-LRC-LRC.lrc?t=1649918948000', + }; + + session.setAVMetadata(metadata12, (err) => { + if (err) { + console.info(`TestLog: Set lyric error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get lyric error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.lyric === metadata12.lyric) { + console.info('TestLog: Get lyric Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get lyric failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1400 + * @tc.name : SETMETADATA_1400 + * @tc.desc : Testing set assetId - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1400', 0, async function (done) { + let metadata13 = { + assetId: '121278', + previousAssetId: '121277', + nextAssetId: '121279', + }; + + session.setAVMetadata(metadata13, (err) => { + if (err) { + console.info(`TestLog: Set assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }) + await sleep(500); + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get assetId error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.previousAssetId === metadata13.previousAssetId + && value.nextAssetId === metadata13.nextAssetId) { + console.info('TestLog: Get assetId Successfully'); + expect(true).assertTrue(); + } else { + console.info(`TestLog: Get assetId failed:${value}`); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1500 + * @tc.name : SETMETADATA_1500 + * @tc.desc : Testing set metadata - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1500', 0, async function (done) { + let metadata14 = { + assetId: '121278', + }; + session.destroy((err) => { + if (err) { + console.info('TestLog: session destroy failed'); + expect(false).assertTrue(); + } else { + console.info('TestLog: session destroy successfully'); + } + }); + await sleep(500); + session.setAVMetadata(metadata14, (err) => { + if (err) { + console.info(`TestLog: Set metadata error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Set metadata : successfully'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1600 + * @tc.name : SETMETADATA_1600 + * @tc.desc : Testing set error metadata - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETMETADATA_CALLBACK_1600', 0, async function (done) { + let metadata15 = { + assetId: '121278', + duration: -2, + }; + + session.setAVMetadata(metadata15, (err) => { + if (err) { + console.info(`TestLog: Set duration error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Set duration : successfully'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0100 + * @tc.name : SETAVPLAYBACKSTATE_0100 + * @tc.desc : Testing set playbackstate - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0100', 0, async function (done) { + let PlaybackState1 = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + }; + session.setAVPlaybackState(PlaybackState1, (err) => { + if (err) { + console.info(`TestLog: Set State error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set State successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get State error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.state === 2) { + console.info('TestLog: Get State successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get State failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0200 + * @tc.name : SETAVPLAYBACKSTATE_0200 + * @tc.desc : Testing set speed - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0200', 0, async function (done) { + let PlaybackState2 = { + speed: 2.6, + }; + + session.setAVPlaybackState(PlaybackState2, (err) => { + if (err) { + console.info(`TestLog: Set speed error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set speed successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get speed error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.speed === 2.6) { + console.info('TestLog: Get speed successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get speed failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0300 + * @tc.name : SETAVPLAYBACKSTATE_0300 + * @tc.desc : Testing set position - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0300', 0, async function (done) { + let PlaybackState3 = { + position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + }; + + session.setAVPlaybackState(PlaybackState3, (err) => { + if (err) { + console.info(`TestLog: Set position error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set position successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get position error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.position.elapsedTime === 10) { + console.info('TestLog: Get position successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get position failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0400 + * @tc.name : SETAVPLAYBACKSTATE_0400 + * @tc.desc : Testing set bufferedTime - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0400', 0, async function (done) { + let PlaybackState4 = { + bufferedTime: 1000, + }; + + session.setAVPlaybackState(PlaybackState4, (err) => { + if (err) { + console.info(`TestLog: Set bufferedTime error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set bufferedTime successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get bufferedTime error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.bufferedTime === 1000) { + console.info('TestLog: Get bufferedTime successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get bufferedTime failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0500 + * @tc.name : SETAVPLAYBACKSTATE_0500 + * @tc.desc : Testing set loopMode - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0500', 0, async function (done) { + let PlaybackState5 = { + loopMode:avSession.LoopMode.LOOP_MODE_SEQUENCE, + }; + + session.setAVPlaybackState(PlaybackState5, (err) => { + if (err) { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set loopMode successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.loopMode === 0) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(1000); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0600 + * @tc.name : SETAVPLAYBACKSTATE_0600 + * @tc.desc : Testing set loopMode - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0600', 0, async function (done) { + let PlaybackState6 = { + loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, + }; + + session.setAVPlaybackState(PlaybackState6, (err) => { + if (err) { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set loopMode successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.loopMode === 1) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(1000); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0700 + * @tc.name : SETAVPLAYBACKSTATE_0700 + * @tc.desc : Testing set loopMode - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0700', 0, async function (done) { + let PlaybackState7 = { + loopMode:avSession.LoopMode.LOOP_MODE_LIST, + }; + + session.setAVPlaybackState(PlaybackState7, (err) => { + if (err) { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set loopMode successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.loopMode === 2) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(1000); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0800 + * @tc.name : SETAVPLAYBACKSTATE_0800 + * @tc.desc : Testing set loopMode - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0800', 0, async function (done) { + let PlaybackState8 = { + loopMode:avSession.LoopMode.LOOP_MODE_SHUFFLE, + }; + + session.setAVPlaybackState(PlaybackState8, (err) => { + if (err) { + console.info(`TestLog: Set loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set loopMode successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get loopMode error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.loopMode === 3) { + console.info('TestLog: Get loopMode successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get loopMode failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(1000); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0900 + * @tc.name : SETAVPLAYBACKSTATE_0900 + * @tc.desc : Testing set isFavorite - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_0900', 0, async function (done) { + let PlaybackState9 = { + isFavorite:true, + }; + + session.setAVPlaybackState(PlaybackState9, (err) => { + if (err) { + console.info(`TestLog: Set isFavorite error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set isFavorite successfully'); + } + }) + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get isFavorite error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }else if (value.isFavorite === true) { + console.info('TestLog: Get isFavorite successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get isFavorite failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(1000); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_1000 + * @tc.name : SETAVPLAYBACKSTATE_1000 + * @tc.desc : Testing set playbackstate - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_1000', 0, async function (done) { + let PlaybackState10 = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: 1.0, + position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + bufferedTime:1000, + loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite:true, + }; + session.destroy((err) => { + if (err) { + console.info(`TestLog: session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } + }); + await sleep(500); + session.setAVPlaybackState(PlaybackState10, (err) => { + if (err) { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Set playbackState successfully'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_1100 + * @tc.name : SETAVPLAYBACKSTATE_1100 + * @tc.desc : Testing set playbackstate - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_CALLBACK_1100', 0, async function (done) { + let PlaybackState11 = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: -2, + position:{elapsedTime:-2, updateTime:(new Date()).getTime()}, + bufferedTime:-4, + loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite:true, + }; + session.setAVPlaybackState(PlaybackState11, (err) => { + if (err) { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Set playbackState successfully'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SETLAUNCHABILITY_CALLBACK_0100 + * @tc.name : SETLAUNCHABILITY_0100 + * @tc.desc : Testing set LaunchAbility - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SETLAUNCHABILITY_CALLBACK_0100', 0, async function(done) { + let wantAgentInfo = { + wants : [ + { + bundleName : 'com.example.myapplication', + abilityName: 'com.example.myapplication.MainAbility' + } + ], + operationType: WantAgent.OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags: [WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] + }; + let agent; + await WantAgent.getWantAgent(wantAgentInfo).then((callback) => { + agent = callback; + }); + + session.setLaunchAbility(agent, (err) => { + if (err) { + console.info(`TestLog: Set launchAbility error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set launchAbility successfully'); + } + }); + + await sleep(500); + let wantagent; + controller.getLaunchAbility((err, value) => { + if (err) { + console.info(`TestLog: error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Get launchAbility'); + wantagent = value; + } + }); + await sleep(500); + await WantAgent.equal(agent, wantagent).then((bool) => { + if (bool) { + console.info('AVSessionTest : Set LaunchAbility successfully'); + expect(true).assertTrue(); + } else { + console.info('AVSessionTest : Set LaunchAbility failed'); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SESSIONACTIVATE_CALLBACK_0100 + * @tc.name : SESSIONACTIVATE_0100 + * @tc.desc : Testing set session active - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SESSIONACTIVATE_CALLBACK_0100', 0, async function (done) { + controller.isActive((err, value) => { + if (err) { + console.info(`TestLog: error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value) { + console.info('TestLog: session is active'); + expect(true).assertTrue(); + } else { + console.info('TestLog: session is directive'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SESSIONDEACTIVATE_CALLBACK_0100 + * @tc.name : SESSIONDEACTIVATE_0100 + * @tc.desc : Testing deactivate session- callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SESSIONDEACTIVATE_CALLBACK_0100', 0, async function (done) { + session.deactivate((err) => { + if (err) { + console.info(`TestLog: Deactivate session error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Deactivate session'); + } + + }); + await sleep(500); + + await controller.isActive((err, value) => { + if (err) { + console.info(`TestLog: error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value === false) { + console.info('TestLog: session deactivate successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: session deactivate failed'); + expect(false).assertTrue(); + } + done(); + }) + await sleep(500); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SESSIONDESTROY_CALLBACK_0100 + * @tc.name : SESSIONDESTROY_0100 + * @tc.desc : Testing destroy session - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SESSIONDESTROY_CALLBACK_0100', 0, async function (done) { + let flag = false; + controller.on('sessionDestroy', () => { + console.info('TestLog: Session destroyed successfully'); + flag = true; + }); + + session.destroy((err) => { + if (err) { + console.info(`TestLog: Session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Session destroy'); + } + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: Session destroyed successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Session destroyed failed'); + expect(false).assertTrue(); + } + done(); + }) + }) +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js new file mode 100644 index 000000000..505963f0e --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js @@ -0,0 +1,1684 @@ +/* + * 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 avSession from '@ohos.multimedia.avsession'; +import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from '@ohos/hypium'; +import WantAgent from '@ohos.wantAgent'; +import featureAbility from '@ohos.ability.featureAbility'; + +export default function Controller() { + describe('Controller', function () { + let tag = 'ApplicationA'; + let type = 'audio'; + let session; + let controller; + let keyItem = {code:10, pressedTime:123456789, deviceId:0}; + let event = {action:2, key:keyItem, keys:[keyItem]}; + let PlaybackState = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: 2.0, + position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + bufferedTime:1000, + loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite:true, + }; + let metadata = { + assetId: '121278', + title: 'lose yourself', + artist: 'Eminem', + author: 'ST', + album: 'Slim shady', + writer: 'ST', + composer: 'ST', + duration: 2222, + mediaImage: 'https://img2.baidu.com/it/u=3583435814,2833583486&fm=253&fmt=auto&app=138&f=JPEG?w=526&h=500', + subtitle: '8 Mile', + description: 'Rap', + lyric: 'https://lyric.tingmall.com/lyric/58/970/58970104-LRC-LRC.lrc?t=1649918948000', + previousAssetId: '121277', + nextAssetId: '121279', + }; + let context = featureAbility.getContext(); + + function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(function () { + console.info('TestLog: Start Testing avSessionController Interfaces'); + }) + + beforeEach(async function () { + console.info('TestLog: Init the avSession And Controller'); + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await avSession.createController(session.sessionId).then((data) => { + controller = data; + }).catch((err) => { + console.info(`TestLog: Controller create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + }) + + afterEach(async function (done) { + console.info('TestLog: Destroy the Session And Controller'); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await controller.destroy().then(() => { + console.info('TestLog: Controller Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Controller Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + afterAll(function () { + console.info('TestLog: End Testing avSessionController Interfaces'); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETSESSIONID_0100 + * @tc.name : GETSESSIONID_0100 + * @tc.desc : Testing get sessionId + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETSESSIONID_0100', 0, async function (done) { + if (controller.sessionId.length === 64) { + console.info('TestLog: Get sessionId successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get sessionId failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETAVPLAYBACKSTATE_PROMISE_0100 + * @tc.name : GETAVPLAYBACKSTATE_0100 + * @tc.desc : Testing get playbackstate - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETAVPLAYBACKSTATE_PROMISE_0100', 0, async function (done) { + await session.setAVPlaybackState(PlaybackState).then(() => { + console.info('TestLog: Set playbackState successfully'); + }).catch((err) => { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVPlaybackState().then((data) => { + if (data.state === 2 && data.speed === 2.0 + && data.isFavorite === true && data.bufferedTime === 1000 + && data.loopMode === 1) { + console.info('TestLog: Get playbackState successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get playbackState failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETAVMETADATA_PROMISE_0100 + * @tc.name : GETAVMETADATA_0100 + * @tc.desc : Testing get metadata -promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETAVMETADATA_PROMISE_0100', 0, async function (done) { + await session.setAVMetadata(metadata).then(() => { + console.info('TestLog: Set metadata successfully'); + }).catch((err) => { + console.info(`TestLog: Set metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await controller.getAVMetadata().then((data) => { + if (data.assetId === '121278' && data.title === 'lose yourself' + && data.artist === 'Eminem' && data.author === 'ST' + && data.album === 'Slim shady' && data.writer === 'ST' + && data.composer === 'ST' && data.duration === 2222 + && data.mediaImage === 'https://img2.baidu.com/it/u=3583435814,2833583486&fm=253&fmt=auto&app=138&f=JPEG?w=526&h=500' + && data.subtitle === '8 Mile' && data.description === 'Rap' + && data.lyric === 'https://lyric.tingmall.com/lyric/58/970/58970104-LRC-LRC.lrc?t=1649918948000' + ) { + console.info('TestLog: Get metadata successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get metadata failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get Metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CONTROLLERSENDEVENT_PROMISE_0100 + * @tc.name : CONTROLLERSENDEVENT_0100 + * @tc.desc : Testing send AVKeyEvent - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_CONTROLLERSENDEVENT_PROMISE_0100', 0, async function (done) { + let flag = false; + session.on('handleKeyEvent', (callback) => { + if (callback.action === 2) { + console.info('TestLog: Get AVKeyEvent successfully'); + flag = true; + } else { + console.info('TestLog: Get AVKeyEvent error'); + } + }); + await controller.sendAVKeyEvent(event).then(() => { + console.info('TestLog: Send AVKeyEvent'); + }).catch((err) => { + console.info(`TestLog: Send AVKeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + if (flag) { + console.info('TestLog: Controller send AVKeyEvent successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Controller send AVKeyEvent failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETLAUNCHABILITY_PROMISE_0100 + * @tc.name : GETLAUNCHABILITY_0100 + * @tc.desc : Testing get LaunchAbility - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETLAUNCHABILITY_PROMISE_0100', 0, async function(done) { + let wantAgentInfo = { + wants : [ + { + bundleName : 'com.example.myapplication', + abilityName: 'com.example.myapplication.MainAbility' + } + ], + operationType: WantAgent.OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags: [WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] + }; + let agent; + await WantAgent.getWantAgent(wantAgentInfo).then((callback) => { + agent = callback; + }); + + await session.setLaunchAbility(agent).then(() => { + console.info('TestLog: Set LaunchAbility'); + }).catch((err) => { + console.info(`TestLog: Set LaunchAbility error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + let wantagent; + await controller.getLaunchAbility().then((data) => { + wantagent = data; + console.info('TestLog: Get launchAbility'); + }).catch((err) => { + console.info(`TestLog: Get LaunchAbility error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await WantAgent.equal(agent, wantagent).then((bool) => { + if (bool) { + console.info('TestLog: Get LaunchAbility successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get LaunchAbility failed'); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETREALPLAYBACKPOSITIONSYNC_0100 + * @tc.name : GETREALPLAYBACKPOSITIONSYNC_0100 + * @tc.desc : Testing get position + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETREALPLAYBACKPOSITIONSYNC_0100', 0, async function (done) { + controller.on('playbackStateChange', 'all', (callback) => { + console.info(`TestLog: Current elapsedTime is :${callback.position.elapsedTime}`); + console.info(`TestLog: Current updateTime is :${callback.position.updateTime}`); + }); + let changeState = { + position:{elapsedTime:20, updateTime:(new Date()).getTime()}, + }; + await session.setAVPlaybackState(changeState).then(() => { + console.info('TestLog: Set playbackState successfully'); + }).catch((err) => { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(1000); + let position = controller.getRealPlaybackPositionSync(); + if (position > 20) { + console.info(`TestLog: Get realPosition successfully and position is:${position}`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get realPosition failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_PROMISE_0100 + * @tc.name : CONTROLLERISACTIVE_0100 + * @tc.desc : Testing session active -promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_PROMISE_0100', 0, async function (done) { + await controller.isActive().then((data) => { + if (data) { + console.info('TestLog: session is active'); + expect(true).assertTrue(); + } else { + console.info('TestLog: session is directive'); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_PROMISE_0200 + * @tc.name : CONTROLLERISACTIVE_0200 + * @tc.desc : Testing session active - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_PROMISE_0200', 0, async function (done) { + await session.deactivate().then(() => { + console.info('TestLog: Set session deactivate successfully'); + }).catch((err) => { + console.info(`TestLog: Set deactivate error: code: ${err.code}, message: ${err.message}`); + }); + + await sleep(500); + + await controller.isActive().then((data) => { + if (data) { + console.info('TestLog: session is active'); + expect(false).assertTrue(); + } else { + console.info('TestLog: session is directive'); + expect(true).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_DESTROYCONTROLLER_PROMISE_0100 + * @tc.name : DESTROYCONTROLLER_0100 + * @tc.desc : Testing destroy the controller - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_DESTROYCONTROLLER_PROMISE_0100', 0, async function (done) { + await controller.destroy().then(() => { + console.info('TestLog: Controller destroy successfully'); + expect(true).assertTrue(); + }).catch((err) => { + console.info(`TestLog: Controller destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETVALIDCOMMAND_PROMISE_0100 + * @tc.name : GETVALIDCOMMAND_0100 + * @tc.desc : Testing get valid command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETVALIDCOMMAND_PROMISE_0100', 0, async function (done) { + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + }); + + session.on('pause', () => { + console.info('TestLog: Pause command callback registration successful'); + }); + + session.on('stop', () => { + console.info('TestLog: Stop command callback registration successful'); + }); + + await controller.getValidCommands().then((data) => { + if (data.length === 3 && data[0] === 'play') { + console.info('TestLog: Get valid command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get valid command failed'); + console.info(`TestLog: Valid command size is:${data.length}`); + for(var i = 0; i < data.length; i++) { + console.info(data[i]); + } + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get valid command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0100 + * @tc.name : SENDCONTROLCOMMAND_0100 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0100', 0, async function (done) { + let flag = false; + session.on('play', () => { + console.info('TestLog: Get play command successfully'); + flag = true; + }); + + await controller.sendControlCommand({command:'play'}).then(() => { + console.info('TestLog: Send play command'); + }).catch((err) => { + console.info(`TestLog: Send play command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send play command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send play command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0200 + * @tc.name : SENDCONTROLCOMMAND_0200 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0200', 0, async function (done) { + let flag = false; + session.on('pause', () => { + console.info('TestLog: Get pause command successfully'); + flag = true; + }); + + await controller.sendControlCommand({command:'pause'}).then(() => { + console.info('TestLog: Send pause command'); + }).catch((err) => { + console.info(`TestLog: Send pause command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send pause command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send pause command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0300 + * @tc.name : SENDCONTROLCOMMAND_0300 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0300', 0, async function (done) { + let flag = false; + session.on('stop', () => { + console.info('TestLog: Get stop command successfully'); + flag = true; + }); + + await controller.sendControlCommand({command:'stop'}).then(() => { + console.info('TestLog: Send stop command'); + }).catch((err) => { + console.info(`TestLog: Send stop command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send stop command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send stop command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0400 + * @tc.name : SENDCONTROLCOMMAND_0400 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0400', 0, async function (done) { + let flag = false; + session.on('playNext', () => { + console.info('TestLog: Get playNext command successfully'); + flag = true; + }); + + await controller.sendControlCommand({command:'playNext'}).then(() => { + console.info('TestLog: Send playNext command'); + }).catch((err) => { + console.info(`TestLog: Send playNext command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send playNext command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send playNext command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0500 + * @tc.name : SENDCONTROLCOMMAND_0500 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0500', 0, async function (done) { + let flag = false; + session.on('playPrevious', () => { + console.info('TestLog: Get playPrevious command successfully'); + flag = true; + }); + + await controller.sendControlCommand({command:'playPrevious'}).then(() => { + console.info('TestLog: Send playPrevious command'); + }).catch((err) => { + console.info(`TestLog: Send playPrevious command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send playPrevious command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send playPrevious command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0600 + * @tc.name : SENDCONTROLCOMMAND_0600 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0600', 0, async function (done) { + let flag = false; + session.on('fastForward', () => { + console.info('TestLog: Get fastForward command successfully'); + flag = true; + }); + + await controller.sendControlCommand({command:'fastForward'}).then(() => { + console.info('TestLog: Send fastForward command'); + }).catch((err) => { + console.info(`TestLog: Send fastForward command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send fastForward command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send fastForward command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0700 + * @tc.name : SENDCONTROLCOMMAND_0700 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0700', 0, async function (done) { + let flag = false; + session.on('rewind', () => { + console.info('TestLog: Get rewind command successfully'); + flag = true; + }); + + await controller.sendControlCommand({command:'rewind'}).then(() => { + console.info('TestLog: Send rewind command'); + }).catch((err) => { + console.info(`TestLog: Send rewind command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send rewind command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send rewind command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0800 + * @tc.name : SENDCONTROLCOMMAND_0800 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0800', 0, async function (done) { + let flag = false; + session.on('seek', (callback) => { + if (callback === 10) { + console.info('TestLog: Get seek command successfully'); + flag = true; + } + }); + await controller.sendControlCommand({command:'seek', parameter:10}).then(() => { + console.info('TestLog: Send seek command'); + }).catch((err) => { + console.info(`TestLog: Send seek command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send seek command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send seek command failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0900 + * @tc.name : SENDCONTROLCOMMAND_0900 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_0900', 0, async function (done) { + let flag = false; + session.on('setSpeed', (callback) => { + if (callback === 2.6) { + console.info('TestLog: Get setSpeed command successfully'); + flag = true; + } + }); + await controller.sendControlCommand({command:'setSpeed', parameter:2.6}).then(() => { + console.info('TestLog: Send setSpeed command'); + }).catch((err) => { + console.info(`TestLog: Send setSpeed command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send setSpeed command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send setSpeed command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_1000 + * @tc.name : SENDCONTROLCOMMAND_1000 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_1000', 0, async function (done) { + let flag = false; + session.on('setLoopMode', (callback) => { + if (callback === 1) { + console.info('TestLog: Get setLoopMode command successfully'); + flag = true; + } + }); + await controller.sendControlCommand({command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + console.info('TestLog: Send setLoopMode command'); + }).catch((err) => { + console.info(`TestLog: Send setLoopMode command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send setLoopMode command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send setLoopMode command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_1100 + * @tc.name : SENDCONTROLCOMMAND_1100 + * @tc.desc : Testing send control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_PROMISE_1100', 0, async function (done) { + let flag = false; + session.on('toggleFavorite', (callback) => { + if (callback === 'false') { + console.info('TestLog: Get toggleFavorite command successfully'); + flag = true; + } + }); + await controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + console.info('TestLog: Send toggleFavorite command'); + }).catch((err) => { + console.info(`TestLog: Send toggleFavorite command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send toggleFavorite command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send toggleFavorite command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONWRONGCALLBACK_0100 + * @tc.name : ONWRONGCALLBACK_0100 + * @tc.desc : Testing wrong callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONWRONGCALLBACK_0100', 0, function (done) { + try { + controller.on('wrongCall', () => { + console.info('TestLog: Wrong callback registration successful'); + }); + } catch (err) { + console.info(`TestLog: Wrong callback registration error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + done(); + } + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONMETADATACHANGE_0100 + * @tc.name : ONMETADATACHANGE_0100 + * @tc.desc : Testing metadata change callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONMETADATACHANGE_0100', 0, async function (done) { + let filter = ['title', 'author', 'artist']; + let flag = false; + controller.on('metadataChange', filter, (callback) => { + if (callback.title === 'love yourself' && callback.artist === 'Justin Biber') { + console.info('TestLog: Metadata filter set successful'); + flag = true; + } + else { + console.info('TestLog: Metadata filter set error'); + } + }); + + let changedata = { + assetId : '9526', + title: 'love yourself', + artist: 'Justin Biber', + author: 'St', + }; + + await session.setAVMetadata(changedata).then(() => { + console.info('TestLog: Change metadata successfully'); + }).catch((err) => { + console.info(`TestLog: Change metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: Metadata change callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Metadata change callback registration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONMETADATACHANGE_0200 + * @tc.name : ONMETADATACHANGE_0200 + * @tc.desc : Testing metadata change callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONMETADATACHANGE_0200', 0, async function (done) { + let filter = ['title', 'author', 'artist']; + let flag = true; + controller.on('metadataChange', filter, (callback) => { + if (callback.album === 'HhHhHHH' && callback.writer === 'ST') { + console.info('TestLog: Metadata filter set failed'); + flag = false; + } + else { + console.info('TestLog: Metadata filter set error'); + flag = false; + } + }); + + let changedata = { + assetId: '9527', + album: 'HhHhHHH', + writer: 'ST', + composer: 'ST', + duration: 2222, + mediaImage: 'aaa', + }; + + await session.setAVMetadata(changedata).then(() => { + console.info('TestLog: Change metadata successfully'); + }).catch((err) => { + console.info(`TestLog: Change metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: Metadata change callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Metadata change callback registration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONMETADATACHANGE_0300 + * @tc.name : ONMETADATACHANGE_0300 + * @tc.desc : Testing metadata change callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONMETADATACHANGE_0300', 0, async function (done) { + let flag = false; + controller.on('metadataChange', 'all', (callback) => { + if (callback.album=== 'HhHhHHH' && callback.writer === 'ST') { + console.info('TestLog: Metadata filter set successful'); + flag = true; + } + else { + console.info('TestLog: Metadata filter set error'); + } + }); + + let changedata = { + assetId: '9527', + title: 'love yourself', + artist: 'Justin Biber', + author: 'St', + album: 'HhHhHHH', + writer: 'ST', + composer: 'ST', + duration: 2222, + mediaImage: 'aaa', + }; + + await session.setAVMetadata(changedata).then(() => { + console.info('TestLog: Change metadata successfully'); + }).catch((err) => { + console.info(`TestLog: Change metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + if (flag) { + console.info('TestLog: Metadata change callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Metadata change callback registration failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPLAYBACKSTATECHANGE_0100 + * @tc.name : ONPLAYBACKSTATECHANGE_0100 + * @tc.desc : Testing playbackState change callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPLAYBACKSTATECHANGE_0100', 0, async function (done) { + let flag = false; + controller.on('playbackStateChange', 'all', (callback) => { + if (callback.isFavorite === false && callback.speed === 3.0) { + console.info('TestLog: PlaybackState filter set successful'); + console.info(`TestLog: Current speed is :${callback.speed}`); + flag = true; + } else { + console.info('TestLog: PlaybackState filter set error'); + } + }); + let changestate = {speed: 3.0, isFavorite:false,}; + + await session.setAVPlaybackState(changestate).then(() => { + console.info('TestLog: Change playbackState successfully'); + }).catch((err) => { + console.info(`TestLog: Change playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: PlaybackState change callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: PlaybackState change callback registration failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPLAYBACKSTATECHANGE_0200 + * @tc.name : ONPLAYBACKSTATECHANGE_0200 + * @tc.desc : Testing playbackState change callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPLAYBACKSTATECHANGE_0200', 0, async function (done) { + let flag = false; + let filter = ['speed', 'isFavorite']; + controller.on('playbackStateChange', filter, (callback) => { + if (callback.isFavorite === false && callback.speed === 3.0) { + console.info('TestLog: PlaybackState filter set successful'); + console.info(`TestLog: Current speed is :${callback.speed}`); + flag = true; + } else { + console.info('TestLog: PlaybackState filter set error'); + } + }); + + let changestate = {speed: 3.0, isFavorite:false,}; + + await session.setAVPlaybackState(changestate).then(() => { + console.info('TestLog: Change playbackState successfully'); + }).catch((err) => { + console.info(`TestLog: Change playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: PlaybackState changed callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: PlaybackState changed callback registration failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPLAYBACKSTATECHANGE_0300 + * @tc.name : ONPLAYBACKSTATECHANGE_0300 + * @tc.desc : Testing playbackState change callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPLAYBACKSTATECHANGE_0300', 0, async function (done) { + let flag = true; + let filter = ['speed', 'isFavorite']; + controller.on('playbackStateChange', filter, (callback) => { + if (callback.bufferedTime === 1000) { + console.info('TestLog: PlaybackState filter set failed'); + flag = false; + } else { + console.info('TestLog: PlaybackState filter set error'); + flag = false; + } + }); + + let changestate = {bufferedTime:1000, loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,}; + + await session.setAVPlaybackState(changestate).then(() => { + console.info('TestLog: Change playbackState successfully'); + }).catch((err) => { + console.info(`TestLog: Change playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: PlaybackState change callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: PlaybackState change callback registration failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONSESSIONDESTROY_0100 + * @tc.name : ONSESSIONDESTROY_0100 + * @tc.desc : Testing session destroy Callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONSESSIONDESTROY_0100', 0, async function (done) { + let flag = false; + controller.on('sessionDestroy', () => { + console.info('TestLog: Session destroy successfully'); + flag = true; + }); + + await session.destroy(); + + await sleep(500); + + if (flag) { + console.info('TestLog: onSessionDestroy callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: onSessionDestroy callback registration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONACTIVESTATECHANGE_0100 + * @tc.name : ONACTIVESTATECHANGE_0100 + * @tc.desc : Testing active State callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONACTIVESTATECHANGE_0100', 0, async function (done) { + let flag = false; + controller.on('activeStateChange', (callback) => { + if (callback) { + console.info('TestLog: Active state change successful'); + flag = true; + } else { + console.info('TestLog: Active state change error'); + } + }); + + await session.activate(); + await sleep(500); + + if (flag) { + console.info('TestLog: ActiveStateChange callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: ActiveStateChange callback registration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONVALIDCOMMANDCHANGE_0100 + * @tc.name : ONVALIDCOMMANDCHANGE_0100 + * @tc.desc : Testing valid command change callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONVALIDCOMMANDCHANGE_0100', 0, async function (done) { + let flag = false; + controller.on('validCommandChange', (callback) => { + if (callback.length > 0 && callback[0] === 'play') { + console.info('TestLog: Valid command change successfully'); + flag = true; + } else { + console.info('TestLog: Get valid command failed'); + console.info(`TestLog: Valid command size is:${callback.length}`); + for(var i = 0; i < callback.length; i++) { + console.info(callback[i]); + } + console.info('TestLog: Valid Command change error'); + } + }); + + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: ValidCommandChange callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: ValidCommandChange callback registration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFMETADATACHANGE_0100 + * @tc.name : OFFMETADATACHANGE_0100 + * @tc.desc : Testing metadata change callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFMETADATACHANGE_0100', 0, async function (done) { + let flag = true; + function callback1(data) { + if (data.title === 'love yourself' && data.artist === 'Justin Biber') { + console.info('TestLog: MetadataChange command registration1 success'); + flag = false; + } + else { + console.info('TestLog: Metadata set error'); + flag = false; + } + } + + function callback2(data) { + if (data.title === 'love yourself' && data.artist === 'Justin Biber') { + console.info('TestLog: MetadataChange command registration2 success'); + flag = false; + } + else { + console.info('TestLog: Metadata set error'); + flag = false; + } + } + + controller.on('metadataChange', 'all', callback1); + + controller.on('metadataChange', 'all', callback2); + + controller.off('metadataChange'); + + let changedata = { + assetId: '9527', + title: 'love yourself', + artist: 'Justin Biber', + author: 'St', + album: 'HhHhHHH', + writer: 'ST', + composer: 'ST', + duration: 2222, + mediaImage: 'aaa', + }; + + await session.setAVMetadata(changedata).then(() => { + console.info('TestLog: Change metadata successfully'); + }).catch((err) => { + console.info(`TestLog: Change metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + if (flag) { + console.info('TestLog: metadataChanged callback unRegistration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: metadataChanged callback unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFMETADATACHANGE_0200 + * @tc.name : OFFMETADATACHANGE_0200 + * @tc.desc : Testing metadata change callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFMETADATACHANGE_0200', 0, async function (done) { + function callback1(data) { + if (data.title === 'love yourself' && data.artist === 'Justin Biber') { + console.info('TestLog: MetadataChange command registration1 success'); + expect(false).assertTrue(); + } + else { + console.info('TestLog: Metadata set error'); + expect(false).assertTrue(); + } + } + + function callback2(data) { + if (data.title === 'love yourself' && data.artist === 'Justin Biber') { + console.info('TestLog: MetadataChange command registration2 success'); + expect(true).assertTrue(); + } + else { + console.info('TestLog: Metadata set error'); + expect(false).assertTrue(); + } + } + + controller.on('metadataChange', 'all', callback1); + + controller.on('metadataChange', 'all', callback2); + + controller.off('metadataChange', callback1); + + let changedata = { + assetId: '9527', + title: 'love yourself', + artist: 'Justin Biber', + author: 'St', + album: 'HhHhHHH', + writer: 'ST', + composer: 'ST', + duration: 2222, + mediaImage: 'aaa', + }; + + await session.setAVMetadata(changedata).then(() => { + console.info('TestLog: Change metadata successfully'); + }).catch((err) => { + console.info(`TestLog: Change metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAYBACKSTATECHANGE_0100 + * @tc.name : OFFPLAYBACKSTATECHANGE_0100 + * @tc.desc : Testing playbackState change callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAYBACKSTATECHANGE_0100', 0, async function (done) { + let flag = true; + function callback1(data) { + if (data.isFavorite === false && data.speed === 3.0) { + console.info('TestLog: PlaybackState set successful'); + console.info(`TestLog: Current speed is :${data.speed}`); + flag = false; + } else { + console.info('TestLog: PlaybackState set error'); + flag = false; + } + } + + function callback2(data) { + if (data.isFavorite === false && data.speed === 3.0) { + console.info('TestLog: PlaybackState set successful'); + console.info(`TestLog: Current speed is :${data.speed}`); + flag = false; + } else { + console.info('TestLog: PlaybackState set error'); + flag = false; + } + } + + controller.on('playbackStateChange', 'all', callback1); + + controller.on('playbackStateChange', 'all', callback2); + + controller.off('playbackStateChange'); + + let changestate = {speed: 3.0, isFavorite:false,}; + + await session.setAVPlaybackState(changestate).then(() => { + console.info('TestLog: Change playbackState successfully'); + }).catch((err) => { + console.info(`TestLog: Change playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: playbackStateChanged callback unRegistration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: playbackStateChanged callback unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAYBACKSTATECHANGE_0200 + * @tc.name : OFFPLAYBACKSTATECHANGE_0200 + * @tc.desc : Testing playbackState change callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAYBACKSTATECHANGE_0200', 0, async function (done) { + function callback1(data) { + if (data.isFavorite === false && data.speed === 3.0) { + console.info('TestLog: PlaybackState set successful'); + expect(false).assertTrue(); + } else { + console.info('TestLog: PlaybackState set error'); + expect(false).assertTrue(); + } + } + + function callback2(data) { + if (data.isFavorite === false && data.speed === 3.0) { + console.info('TestLog: PlaybackState set successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: PlaybackState set error'); + expect(false).assertTrue(); + } + } + + controller.on('playbackStateChange', 'all', callback1); + + controller.on('playbackStateChange', 'all', callback2); + + controller.off('playbackStateChange', callback1); + + let changestate = {speed: 3.0, isFavorite:false,}; + + await session.setAVPlaybackState(changestate).then(() => { + console.info('TestLog: Change playbackState successfully'); + }).catch((err) => { + console.info(`TestLog: Change playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0100 + * @tc.name : OFFSESSIONDESTROY_0100 + * @tc.desc : Testing session destroy Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0100', 0, async function (done) { + let flag = true; + function callback1() { + console.info('TestLog: SessionDestory command registration1 success'); + flag = false; + } + + function callback2() { + console.info('TestLog: SessionDestory command registration2 success'); + flag = false; + } + + controller.on('sessionDestroy', callback1); + + controller.on('sessionDestroy', callback2); + + controller.off('sessionDestroy'); + + await session.destroy().then(() => { + console.info('TestLog: Destory session successfully'); + }).catch((err) => { + console.info(`TestLog: Destory session error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: SessionDestroy callback unRegistration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: SessionDestroy callback unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0200 + * @tc.name : OFFSESSIONDESTROY_0200 + * @tc.desc : Testing session destroy Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0200', 0, async function (done) { + function callback1() { + console.info('TestLog: SessionDestory command registration1 success'); + expect(false).assertTrue; + } + + function callback2() { + console.info('TestLog: SessionDestory command registration2 success'); + expect(true).assertTrue; + } + + controller.on('sessionDestroy', callback1); + + controller.on('sessionDestroy', callback2); + + controller.off('sessionDestroy', callback1); + + await session.destroy().then(() => { + console.info('TestLog: Destory session successfully'); + }).catch((err) => { + console.info(`TestLog: Destory session error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFACTIVESTATECHANGE_0100 + * @tc.name : OFFACTIVESTATECHANGE_0100 + * @tc.desc : Testing active State callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFACTIVESTATECHANGE_0100', 0, async function (done) { + let flag = true; + + function callback1(data) { + if (data) { + console.info('TestLog: ActiveStateChange command registration1 success'); + flag = false; + } + } + + function callback2(data) { + if (data) { + console.info('TestLog: ActiveStateChange command registration2 success'); + flag = false; + } + } + + controller.on('activeStateChange', callback1); + + controller.on('activeStateChange', callback2); + + controller.off('activeStateChange'); + + await session.activate().then(() => { + console.info('TestLog: Session activate successfully'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + if (flag) { + console.info('TestLog: activeStateChange command unRegistration success') + expect(true).assertTrue(); + } else { + console.info('TestLog: activeStateChange command unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFACTIVESTATECHANGE_0200 + * @tc.name : OFFACTIVESTATECHANGE_0200 + * @tc.desc : Testing active State callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFACTIVESTATECHANGE_0200', 0, async function (done) { + function callback1(data) { + if (data) { + console.info('TestLog: ActiveStateChange command registration1 success'); + expect(false).assertTrue(); + } + } + + function callback2(data) { + if (data) { + console.info('TestLog: ActiveStateChange command registration1 success'); + expect(true).assertTrue(); + } + } + + controller.on('activeStateChange', callback1); + + controller.on('activeStateChange', callback2); + + controller.off('activeStateChange', callback1); + + await session.activate().then(() => { + console.info('TestLog: Session activate successfully'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFVALIDCOMMANDCHANGE_0100 + * @tc.name : OFFVALIDCOMMANDCHANGE_0100 + * @tc.desc : Testing valid command change callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFVALIDCOMMANDCHANGE_0100', 0, async function (done) { + let flag = true; + + function callback1(data) { + if (data.length > 0 && data[0] === 'play') { + console.info('TestLog: Valid command change successfully'); + flag = false; + } else { + console.info('TestLog: Get valid command failed'); + flag = false; + } + } + + function callback2(data) { + if (data.length > 0 && data[0] === 'play') { + console.info('TestLog: Valid command change successfully'); + flag = false; + } else { + console.info('TestLog: Get valid command failed'); + flag = false; + } + } + + controller.on('validCommandChange', callback1); + + controller.on('validCommandChange', callback2); + + controller.off('validCommandChange'); + + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: Valid command changed callback unRegistration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Valid command changed callback unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFVALIDCOMMANDCHANGE_0200 + * @tc.name : OFFVALIDCOMMANDCHANGE_0200 + * @tc.desc : Testing valid command change callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFVALIDCOMMANDCHANGE_0200', 0, async function (done) { + function callback1(data) { + if (data.length > 0 && data[0] === 'play') { + console.info('TestLog: Valid command change successfully'); + expect(false).assertTrue(); + } else { + console.info('TestLog: Get valid command failed'); + expect(false).assertTrue(); + } + } + + function callback2(data) { + if (data.length > 0 && data[0] === 'play') { + console.info('TestLog: Valid command change successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get valid command failed'); + expect(false).assertTrue(); + } + } + + controller.on('validCommandChange', callback1); + + controller.on('validCommandChange', callback2); + + controller.off('validCommandChange', callback1); + + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + }); + + await sleep(500); + done(); + }) + }) +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerCallback.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerCallback.test.js new file mode 100644 index 000000000..4bc687104 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerCallback.test.js @@ -0,0 +1,790 @@ +/* + * 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 avSession from '@ohos.multimedia.avsession'; +import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from '@ohos/hypium'; +import WantAgent from '@ohos.wantAgent'; +import featureAbility from '@ohos.ability.featureAbility'; + +export default function ControllerCallback() { + describe('ControllerCallback', function () { + let tag = 'ApplicationA'; + let type = 'audio'; + let session; + let controller; + let keyItem = {code:10, pressedTime:123456789, deviceId:0}; + let event = {action:2, key:keyItem, keys:[keyItem]}; + let PlaybackState = { + state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + speed: 2.0, + position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + bufferedTime:1000, + loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, + isFavorite:true, + }; + let metadata = { + assetId: '121278', + title: 'lose yourself', + artist: 'Eminem', + author: 'ST', + album: 'Slim shady', + writer: 'ST', + composer: 'ST', + duration: 2222, + mediaImage: 'https://img2.baidu.com/it/u=3583435814,2833583486&fm=253&fmt=auto&app=138&f=JPEG?w=526&h=500', + subtitle: '8 Mile', + description: 'Rap', + lyric: 'https://lyric.tingmall.com/lyric/58/970/58970104-LRC-LRC.lrc?t=1649918948000', + previousAssetId: '121277', + nextAssetId: '121279', + }; + let context = featureAbility.getContext(); + + function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(function () { + console.info('TestLog: Start Testing AVSessionController Interfaces'); + }) + + beforeEach(async function () { + console.info('TestLog: Init the AVSession And Controller'); + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activated error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await avSession.createController(session.sessionId).then((data) => { + controller = data; + }).catch((err) => { + console.info(`TestLog: Controller created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + }) + + afterEach(async function (done) { + console.info('TestLog: Destroy the Session And Controller'); + await session.destroy(); + await controller.destroy(); + done(); + }) + + afterAll(function () { + console.info('TestLog: End Testing AVSessionController Interfaces'); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETAVPLAYBACKSTATE_CALLBACK_0100 + * @tc.name : GETAVPLAYBACKSTATE_0100 + * @tc.desc : Testing get playbackstate - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + * + */ + it('SUB_MULTIMEDIA_AVSESSION_GETAVPLAYBACKSTATE_CALLBACK_0100', 0, async function (done) { + session.setAVPlaybackState(PlaybackState, (err) => { + if (err) { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set playbackState successfully'); + } + }); + + await sleep(500); + controller.getAVPlaybackState((err, value) => { + if (err) { + console.info(`TestLog: Get playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.state === 2 && value.speed === 2.0 + && value.isFavorite === true && value.bufferedTime === 1000 + && value.loopMode === 1) { + console.info('TestLog: Get playbackState successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get playbackState failed'); + expect(false).assertTrue(); + } + }) + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETAVMETADATA_CALLBACK_0100 + * @tc.name : GETAVMETADATA_0100 + * @tc.desc : Testing get metadata - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETAVMETADATA_CALLBACK_0100', 0, async function (done) { + session.setAVMetadata(metadata, (err) => { + if (err) { + console.info(`TestLog: Set playbackState error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set playbackState successfully'); + } + }); + await sleep(500); + + controller.getAVMetadata((err, value) => { + if (err) { + console.info(`TestLog: Get Metadata error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.assetId === '121278' && value.title === 'lose yourself' + && value.artist === 'Eminem' && value.author === 'ST' + && value.album === 'Slim shady' && value.writer === 'ST' + && value.composer === 'ST' && value.duration === 2222 + && value.mediaImage === + 'https://img2.baidu.com/it/u=3583435814,2833583486&fm=253&fmt=auto&app=138&f=JPEG?w=526&h=500' + && value.subtitle === '8 Mile' && value.description === 'Rap' + && value.lyric === 'https://lyric.tingmall.com/lyric/58/970/58970104-LRC-LRC.lrc?t=1649918948000') { + console.info('TestLog: Get metadata successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get metadata failed'); + expect(false).assertTrue(); + } + }) + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CONTROLLERSENDEVENT_CALLBACK_0100 + * @tc.name : CONTROLLERSENDEVENT_0100 + * @tc.desc : Testing send AVKeyEvent - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CONTROLLERSENDEVENT_CALLBACK_0100', 0, async function (done) { + let flag = false; + session.on('handleKeyEvent', (callback) => { + if (callback.action === 2) { + console.info('TestLog: Get AVKeyEvent successfully'); + flag = true; + } else { + console.info('TestLog: Get AVKeyEvent error'); + } + }); + controller.sendAVKeyEvent(event, (err) => { + if (err) { + console.info(`TestLog: Send AVKeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send AVKeyEvent'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Controller send AVKeyEvent successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Controller send AVKeyEvent failed'); + expect(false).assertTrue(); + } + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETLAUNCHABILITY_CALLBACK_0100 + * @tc.name : GETLAUNCHABILITY_0100 + * @tc.desc : Testing get LaunchAbility - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETLAUNCHABILITY_CALLBACK_0100', 0, async function(done) { + let wantAgentInfo = { + wants : [ + { + bundleName : 'com.example.myapplication', + abilityName: 'com.example.myapplication.MainAbility' + } + ], + operationType: WantAgent.OperationType.START_ABILITIES, + requestCode: 0, + wantAgentFlags: [WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] + }; + let agent; + await WantAgent.getWantAgent(wantAgentInfo).then((callback) => { + agent = callback; + }); + + session.setLaunchAbility(agent, (err) => { + if (err) { + console.info(`TestLog: Set launchAbility error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Set launchAbility successfully'); + } + }); + + await sleep(500); + let wantagent; + controller.getLaunchAbility((err, value) => { + if (err) { + console.info(`TestLog: error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Get launchAbility'); + wantagent = value; + } + }); + await sleep(500); + await WantAgent.equal(agent, wantagent).then((bool) => { + if (bool) { + console.info('AVSessionTest : Get LaunchAbility successfully'); + expect(true).assertTrue(); + } else { + console.info('AVSessionTest : Get LaunchAbility failed'); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_CALLBACK_0100 + * @tc.name : CONTROLLERISACTIVE_0100 + * @tc.desc : Testing session active - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_CALLBACK_0100', 0, async function (done) { + controller.isActive((err, value) => { + if (err) { + console.info(`TestLog: isActive error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value) { + console.info('TestLog: session is active'); + expect(true).assertTrue(); + } else { + console.info('TestLog: session is directive'); + expect(false).assertTrue(); + } + }) + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_CALLBACK_0200 + * @tc.name : CONTROLLERISACTIVE_0200 + * @tc.desc : Testing session active - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CONTROLLERISACTIVE_CALLBACK_0200', 0, async function (done) { + await session.deactivate().then(() => { + console.info('TestLog: Set session deactivate successfully'); + }).catch((err) => { + console.info(`TestLog: Set deactivate error: code: ${err.code}, message: ${err.message}`); + }); + + controller.isActive((err, value) => { + if (err) { + console.info(`TestLog: isActive error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value) { + console.info('TestLog: session is active'); + expect(false).assertTrue(); + } else { + console.info('TestLog: session is directive'); + expect(true).assertTrue(); + } + }) + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_DESTROYCONTROLLER_CALLBACK_0100 + * @tc.name : DESTROYCONTROLLER_0100 + * @tc.desc : Testing destroy the controller - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_DESTROYCONTROLLER_CALLBACK_0100', 0, async function (done) { + controller.destroy((err) => { + if (err) { + console.info(`TestLog: Controller destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Controller destroy successfully'); + expect(true).assertTrue(); + } + }) + await sleep(500); + avSession.createController(session.sessionId, (err, value) => { + if (err) { + console.info(`TestLog: Controller created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + controller = value; + } + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETVALIDCOMMAND_CALLBACK_0100 + * @tc.name : GETVALIDCOMMAND_0100 + * @tc.desc : Testing get valid command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETVALIDCOMMAND_CALLBACK_0100', 0, async function (done) { + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + }); + + session.on('pause', () => { + console.info('TestLog: Pause command callback registration successful'); + }); + + session.on('stop', () => { + console.info('TestLog: Stop command callback registration successful'); + }); + + controller.getValidCommands((err, value) => { + if (err) { + console.info(`TestLog: Get valid command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.length === 3 && value[0] === 'play') { + console.info('TestLog: Get valid command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get valid command failed'); + expect(false).assertTrue(); + } + }) + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0100 + * @tc.name : SENDCONTROLCOMMAND_0100 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0100', 0, async function (done) { + let flag = false; + + session.on('play', () => { + console.info('TestLog: Get play command successfully'); + flag = true; + }); + + controller.sendControlCommand({command:'play'}, (err) => { + if (err) { + console.info(`TestLog: Send play command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send play command'); + } + done(); + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send play command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send play command failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0200 + * @tc.name : SENDCONTROLCOMMAND_0200 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0200', 0, async function (done) { + let flag = false; + session.on('pause', () => { + console.info('TestLog: Get pause command successfully'); + flag = true; + }); + + controller.sendControlCommand({command:'pause'}, (err) => { + if (err) { + console.info(`TestLog: Send pause command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send pause command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send pause command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send pause command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0300 + * @tc.name : SENDCONTROLCOMMAND_0300 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0300', 0, async function (done) { + let flag = false; + + session.on('stop', () => { + console.info('TestLog: Get stop command successfully'); + flag = true; + }); + + controller.sendControlCommand({command:'stop'}, (err) => { + if (err) { + console.info(`TestLog: Send stop command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send stop command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send stop command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send stop command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0400 + * @tc.name : SENDCONTROLCOMMAND_0400 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0400', 0, async function (done) { + let flag = false; + + session.on('playNext', () => { + console.info('TestLog: Get playNext command successfully'); + flag = true; + }); + + controller.sendControlCommand({command:'playNext'}, (err) => { + if (err) { + console.info(`TestLog: Send playNext command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send playNext command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send playNext command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send playNext command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0500 + * @tc.name : SENDCONTROLCOMMAND_0500 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0500', 0, async function (done) { + let flag = false; + + session.on('playPrevious', () => { + console.info('TestLog: Get playPrevious command successfully'); + flag = true; + }); + + controller.sendControlCommand({command:'playPrevious'}, (err) => { + if (err) { + console.info(`TestLog: Send playPrevious command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send playPrevious command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send playPrevious command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send playPrevious command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0600 + * @tc.name : SENDCONTROLCOMMAND_0600 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0600', 0, async function (done) { + let flag = false; + + session.on('fastForward', () => { + console.info('TestLog: Get fastForward command successfully'); + flag = true; + }); + + controller.sendControlCommand({command:'fastForward'}, (err) => { + if (err) { + console.info(`TestLog: Send fastForward command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send fastForward command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send fastForward command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send fastForward command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0700 + * @tc.name : SENDCONTROLCOMMAND_0700 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0700', 0, async function (done) { + let flag = false; + + session.on('rewind', () => { + console.info('TestLog: Get rewind command successfully'); + flag = true; + }); + + controller.sendControlCommand({command:'rewind'}, (err) => { + if (err) { + console.info(`TestLog: Send rewind command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send rewind command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send rewind command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send rewind command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0800 + * @tc.name : SENDCONTROLCOMMAND_0800 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0800', 0, async function (done) { + let flag = false; + + session.on('seek', (callback) => { + if (callback === 10) { + console.info('TestLog: Get seek command successfully'); + flag = true; + } + }); + controller.sendControlCommand({command:'seek', parameter:10}, (err) => { + if (err) { + console.info(`TestLog: Send seek command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send seek command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send seek command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send seek command failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0900 + * @tc.name : SENDCONTROLCOMMAND_0900 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_0900', 0, async function (done) { + let flag = false; + + session.on('setSpeed', (callback) => { + if (callback === 2.6) { + console.info('TestLog: Get setSpeed command successfully'); + flag = true; + } + }); + controller.sendControlCommand({command:'setSpeed', parameter:2.6}, (err) => { + if (err) { + console.info(`TestLog: Send setSpeed command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send setSpeed command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send setSpeed command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send setSpeed command failed'); + expect(false).assertTrue(); + } + + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_1000 + * @tc.name : SENDCONTROLCOMMAND_1000 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_1000', 0, async function (done) { + let flag = false; + + session.on('setLoopMode', (callback) => { + if (callback === 1) { + console.info('TestLog: Get setLoopMode command successfully'); + flag = true; + } + }); + controller.sendControlCommand({command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}, (err) => { + if (err) { + console.info(`TestLog: Send setLoopMode command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send setLoopMode command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send setLoopMode command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send setLoopMode command failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_1100 + * @tc.name : SENDCONTROLCOMMAND_1100 + * @tc.desc : Testing send control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDCONTROLCOMMAND_CALLBACK_1100', 0, async function (done) { + let flag = false; + + session.on('toggleFavorite', (callback) => { + if (callback === 'false') { + console.info('TestLog: Get toggleFavorite command successfully'); + flag = true; + } + }); + controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}, (err) => { + if (err) { + console.info(`TestLog: Send toggleFavorite command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send toggleFavorite command'); + } + }); + await sleep(500); + if (flag) { + console.info('TestLog: Send toggleFavorite command successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send toggleFavorite command failed'); + expect(false).assertTrue(); + } + done(); + }) + }) +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js new file mode 100644 index 000000000..8b76de186 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js @@ -0,0 +1,1144 @@ +/* + * 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 avSession from '@ohos.multimedia.avsession'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; +import featureAbility from '@ohos.ability.featureAbility'; + +export default function AVSessionManager() { + describe('AVSessionManager', function () { + let tag = 'ApplicationA'; + let type = 'audio'; + let session; + let controller; + let id = '9527'; + let keyItem = {code:10, pressedTime:123456789, deviceId:0}; + let event = {action:2, key:keyItem, keys:[keyItem]}; + let context = featureAbility.getContext(); + + function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(function () { + console.info('TestLog: Start Testing avSessionManager Interfaces'); + }) + + beforeEach(function () { + console.info('TestLog: Start testing testcase'); + }) + + afterEach(function () { + console.info('TestLog: End testing testcase'); + }) + + afterAll(function () { + console.info('TestLog: End Testing avSessionManager Interfaces'); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_PROMISE_0100 + * @tc.name : CREATEAVSESSION_0100 + * @tc.desc : Testing createavSession with right parameter - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_PROMISE_0100', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + if(session.sessionId.length === 64) { + console.info('TestLog: avSession create successfully'); + expect(true).assertTrue(); + } + else { + console.info('TestLog: avSession create failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: avSession create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_PROMISE_0200 + * @tc.name : CREATEAVSESSION_0200 + * @tc.desc : Testing createavSession with wrong type + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_PROMISE_0200', 0, async function (done) { + await avSession.createAVSession(context, tag, 'aaa').then((data) => { + console.info('TestLog: avSession create successfully'); + }).catch((err) => { + console.info(`TestLog: avSession create error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_PROMISE_0300 + * @tc.name : CREATEAVSESSION_0300 + * @tc.desc : Testing createavSession with wrong parameter + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_PROMISE_0300', 0, async function (done) { + await avSession.createAVSession(context, '', type).then((data) => { + console.info('TestLog: avSession create successfully'); + }).catch((err) => { + console.info(`TestLog: avSession create error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETALLSESSIONDESCRIPTORS_PROMISE_0100 + * @tc.name : GETALLSESSIONDESCRIPTORS_0100 + * @tc.desc : Testing get sessionDescriptors - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETALLSESSIONDESCRIPTORS_PROMISE_0100', 0, async function (done) { + await avSession.createAVSession(context, 'ApplicationB', type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session Create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await avSession.getAllSessionDescriptors().then((descriptors) => { + if (descriptors[0].isActive === false && descriptors[0].type === 'audio' + && descriptors[0].sessionTag === 'ApplicationB') { + console.info('TestLog: Get AllSessionDescriptors successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get AllSessionDescriptors failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Get AllSessionDescriptors error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_PROMISE_0100 + * @tc.name : CREATECONTROLLER_0100 + * @tc.desc : Testing creat session controller - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_PROMISE_0100', 0, async function (done) { + await avSession.createController(id).then((controller) => { + if (controller.sessionId.length === 64) { + console.info('TestLog: Controller create successfully'); + expect(false).assertTrue(); + } else { + console.info('TestLog: Controller create failed'); + expect(true).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Controller create error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_PROMISE_0200 + * @tc.name : CREATECONTROLLER_0200 + * @tc.desc : Testing creat session controller - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_PROMISE_0200', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: avSession create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await avSession.createController(session.sessionId).then((data) => { + controller = data; + if (controller.sessionId === session.sessionId) { + console.info('TestLog: Controller create successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Controller create failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`TestLog: Controller create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await controller.destroy().then(() => { + console.info('TestLog: controller Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: controller Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONWRONGCALLBACK_0100 + * @tc.name : ONWRONGCALLBACK_0100 + * @tc.desc : Testing wrong callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONWRONGCALLBACK_0100', 0, function (done) { + try { + avSession.on('wrongCall', () => { + console.info('TestLog: Wrong callback registration successful'); + expect(false).assertTrue(); + }); + } catch (err) { + console.info(`TestLog: Wrong callback registration error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + done(); + } + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONSESSIONCREATE_0100 + * @tc.name : ONSESSIONCREATE_0100 + * @tc.desc : Testing session create Callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONSESSIONCREATE_0100', 0, async function (done) { + let newSessionId; + avSession.on('sessionCreate', (descriptor) => { + console.info(`TestLog: descriptor.sessionId = ${descriptor.sessionId}`); + newSessionId = descriptor.sessionId; + }); + + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + console.info('TestLog: Session create successfully'); + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + if (newSessionId === session.sessionId) { + console.info('TestLog: sessionId equels'); + expect(true).assertTrue(); + } else { + console.info('TestLog: sessionId not equels'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONSESSIONDESTROY_0100 + * @tc.name : ONSESSIONDESTROY_0100 + * @tc.desc : Testing session destroy Callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONSESSIONDESTROY_0100', 0, async function (done) { + avSession.on('sessionDestroy', (callback) => { + if (callback.sessionId === session.sessionId) { + console.info(`TestLog: Session: ${callback.sessionId} destroy callback registration successful`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Session destroy callback registration failed'); + expect(false).assertTrue(); + } + }); + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONTOPSESSIONCHANGE_0100 + * @tc.name : ONTOPSESSIONCHANGE_0100 + * @tc.desc : Testing top session change Callback registration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONTOPSESSIONCHANGE_0100', 0, async function (done) { + avSession.on('topSessionChange', (callback) => { + if (callback.sessionId.length === 64) { + console.info(`TestLog: Session: ${callback.sessionId} is top session now`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Top session change callback registration failed'); + expect(false).assertTrue(); + } + }); + + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + console.info('TestLog: Session create successfully'); + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + avSession.off('topSessionChange'); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSESSIONCREATE_0100 + * @tc.name : OFFSESSIONCREATE_0100 + * @tc.desc : Testing session create Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSESSIONCREATE_0100', 0, async function (done) { + let flag = true; + function callback1(callback) { + console.info(`TestLog: Session: ${callback.sessionId} created`); + flag = false; + } + + function callback2(callback) { + console.info(`TestLog: Session: ${callback.sessionId} created`); + flag = false; + } + + avSession.on('sessionCreate', callback1); + + avSession.on('sessionCreate', callback2); + + avSession.off('sessionCreate'); + + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + console.info('TestLog: Session create successfully'); + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: Session created callback unRegistration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Session created callback unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0100 + * @tc.name : OFFSESSIONDESTROY_0100 + * @tc.desc : Testing session destroy Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0100', 0, async function (done) { + let flag = true; + function callback1(callback) { + console.info(`TestLog: Session: ${callback.sessionId} destroyed`); + flag = false; + } + + function callback2(callback) { + console.info(`TestLog: Session: ${callback.sessionId} destroyed`); + flag = false; + } + + avSession.on('sessionDestroy', callback1); + + avSession.on('sessionDestroy', callback2); + + avSession.off('sessionDestroy'); + + await session.destroy().then(() => { + console.info('TestLog: Session destroy successfully'); + }).catch((err) => { + console.info(`TestLog: Session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + + if (flag) { + console.info('TestLog: Session destroy callback unRegistration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Session destroy callback unRegistration failed'); + expect(false).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSESSIONCREATE_0200 + * @tc.name : OFFSESSIONCREATE_0200 + * @tc.desc : Testing session create Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSESSIONCREATE_0200', 0, async function (done) { + function callback1(callback) { + console.info(`TestLog: Session: ${callback.sessionId} created`); + expect(false).assertTrue(); + } + + function callback2(callback) { + console.info(`TestLog: Session: ${callback.sessionId} created`); + expect(true).assertTrue(); + } + + avSession.on('sessionCreate', callback1); + + avSession.on('sessionCreate', callback2); + + avSession.off('sessionCreate', callback1); + + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + console.info('TestLog: Session create successfully'); + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(100); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0200 + * @tc.name : OFFSESSIONDESTROY_0200 + * @tc.desc : Testing session destroy Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFSESSIONDESTROY_0200', 0, async function (done) { + function callback1(callback) { + console.info(`TestLog: Session: ${callback.sessionId} destroyed`); + expect(false).assertTrue(); + } + + function callback2(callback) { + console.info(`TestLog: Session: ${callback.sessionId} destroyed`); + expect(true).assertTrue(); + } + + avSession.on('sessionDestroy', callback1); + + avSession.on('sessionDestroy', callback2); + + avSession.off('sessionDestroy', callback1); + + await session.destroy().then(() => { + console.info('TestLog: Session destroy successfully'); + }).catch((err) => { + console.info(`TestLog: Session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFTOPSESSIONCHANGE_0100 + * @tc.name : OFFTOPSESSIONCHANGE_0100 + * @tc.desc : Testing top session change Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFTOPSESSIONCHANGE_0100', 0, async function (done) { + let flag = true; + function callback1(callback) { + if (callback.sessionId.length === 64) { + console.info(`TestLog: Session:${callback.sessionId} is top session now`); + flag = false; + } else { + console.info('TestLog: Top session change callback registration failed'); + flag = false; + } + } + + function callback2(callback) { + if (callback.sessionId.length === 64) { + console.info(`TestLog: Session:${callback.sessionId}is top session now`); + flag = false; + } else { + console.info('TestLog: Top session change callback registration failed'); + flag = false; + } + } + avSession.on('topSessionChange', callback1); + + avSession.on('topSessionChange', callback2); + + avSession.off('topSessionChange'); + + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + console.info('TestLog: Session create successfully'); + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + if (flag) { + console.info('TestLog: Top session change callback unRegistration successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Top session change callback unRegistration failed'); + expect(false).assertTrue(); + } + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFTOPSESSIONCHANGE_0200 + * @tc.name : OFFTOPSESSIONCHANGE_0200 + * @tc.desc : Testing top session change Callback unRegistration + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFTOPSESSIONCHANGE_0200', 0, async function (done) { + function callback1(callback) { + if (callback.sessionId.length === 64) { + console.info(`TestLog: Session:${callback.sessionId} is top session now`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Top session change callback registration failed'); + expect(false).assertTrue(); + } + } + + function callback2(callback) { + if (callback.sessionId.length === 64) { + console.info(`TestLog: Session:${callback.sessionId}is top session now`); + expect(true).assertTrue(); + } else { + console.info('TestLog: Top session change callback registration failed'); + expect(false).assertTrue(); + } + } + avSession.on('topSessionChange', callback1); + + avSession.on('topSessionChange', callback2); + + avSession.off('topSessionChange', callback1); + + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + console.info('TestLog: Session create successfully'); + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + + avSession.off('topSessionChange', callback2); + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMAVKEYEVENT_PROMISE_0100 + * @tc.name : SENDSYSTEMAVKEYEVENT_0100 + * @tc.desc : Testing send systemKeyEvent - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMAVKEYEVENT_PROMISE_0100', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('handleKeyEvent', (callback) => { + if (callback.action === 2) { + console.info('TestLog: Send System keyEvent successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send System keyEvent failed'); + expect(false).assertTrue(); + } + }); + + await avSession.sendSystemAVKeyEvent(event).then(() => { + console.info('TestLog: Send System KeyEvent'); + }).catch((err) => { + console.info(`TestLog: Send System KeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0100 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0100 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0100', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + expect(true).assertTrue(); + }); + + await avSession.sendSystemControlCommand({command:'play'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0200 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0200 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0200', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('pause', () => { + console.info('TestLog: Pause command callback registration successful'); + expect(true).assertTrue(); + }); + + await avSession.sendSystemControlCommand({command:'pause'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0300 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0300 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0300', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('stop', () => { + console.info('TestLog: stop command callback registration successful'); + expect(true).assertTrue(); + }); + + await avSession.sendSystemControlCommand({command:'stop'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0400 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0400 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0400', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('playNext', () => { + console.info('TestLog: playNext command callback registration successful'); + expect(true).assertTrue(); + }); + + await avSession.sendSystemControlCommand({command:'playNext'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0500 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0500 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0500', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('playPrevious', () => { + console.info('TestLog: playPrevious command callback registration successful'); + expect(true).assertTrue(); + }); + + await avSession.sendSystemControlCommand({command:'playPrevious'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0600 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0600 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0600', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('fastForward', () => { + console.info('TestLog: fastForward command callback registration successful'); + expect(true).assertTrue(); + }); + + await avSession.sendSystemControlCommand({command:'fastForward'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0700 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0700 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0700', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('rewind', () => { + console.info('TestLog: rewind command callback registration successful'); + expect(true).assertTrue(); + }); + + await avSession.sendSystemControlCommand({command:'rewind'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0800 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0800 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0800', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('seek', (callback) => { + if (callback === 10) { + console.info('TestLog: Get seek command successfully'); + expect(true).assertTrue(); + } + }); + + await avSession.sendSystemControlCommand({command:'seek', parameter:10}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0900 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0900 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_0900', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('setSpeed', (callback) => { + if (callback === 2.6) { + console.info('TestLog: Get setSpeed command successfully'); + expect(true).assertTrue(); + } + }); + + await avSession.sendSystemControlCommand({command:'setSpeed', parameter:2.6}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_1000 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_1000 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_1000', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('setLoopMode', (callback) => { + if (callback === 1) { + console.info('TestLog: Get setLoopMode command successfully'); + expect(true).assertTrue(); + } + }); + + await avSession.sendSystemControlCommand({command:'setLoopMode', parameter: + avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_1100 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_1100 + * @tc.desc : Testing send system control command - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_PROMISE_1100', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + }); + + session.on('toggleFavorite', (callback) => { + if (callback === 'false') { + console.info('TestLog: Get toggleFavorite command successfully'); + expect(true).assertTrue(); + } + }); + + await avSession.sendSystemControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + console.info('TestLog: Send System control command successfully'); + }).catch((err) => { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + }) +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerCallback.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerCallback.test.js new file mode 100644 index 000000000..f1a195f4f --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerCallback.test.js @@ -0,0 +1,863 @@ +/* + * 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 avSession from '@ohos.multimedia.avsession'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; +import featureAbility from '@ohos.ability.featureAbility'; + +export default function AVSessionManagerCallback() { + describe('AVSessionManagerCallback', function () { + let tag = 'ApplicationA'; + let type = 'audio'; + let id = 9527; + let keyItem = {code:10, pressedTime:123456789, deviceId:0}; + let event = {action:2, key:keyItem, keys:[keyItem]}; + let context = featureAbility.getContext(); + + function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(function () { + console.info('TestLog: Start Testing AVSessionManager Interfaces'); + }) + + beforeEach(function () { + console.info('TestLog: Start testing testcase'); + }) + + afterEach(async function (done) { + console.info('TestLog: End testing testcase'); + await sleep(1000); + done(); + }) + + afterAll(function () { + console.info('TestLog: End Testing AVSessionManager Interfaces'); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_CALLBACK_0100 + * @tc.name : CREATEAVSESSION_0100 + * @tc.desc : Testing createAVSession with right parameter - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_CALLBACK_0100', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: AVSession created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue() + } else if (value.sessionId.length === 64){ + session = value; + console.info(`TestLog: AVSession :${session.sessionId}created successfully`); + expect(true).assertTrue() + } else { + console.info('TestLog: AVSession created failed'); + expect(false).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + console.info(`TestLog: AVSession :${session.sessionId}destroyed successfully`); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_CALLBACK_0200 + * @tc.name : CREATEAVSESSION_0200 + * @tc.desc : Testing createAVSession with wrong type - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_CALLBACK_0200', 0, async function (done) { + avSession.createAVSession(context, tag, 'aaa', (err, data) => { + if (err) { + console.info(`TestLog: AVSession created error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info(`TestLog: AVSession ${data.sessionId} created successfully`); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_CALLBACK_0300 + * @tc.name : CREATEAVSESSION_0300 + * @tc.desc : Testing createAVSession with wrong parameter - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATEAVSESSION_CALLBACK_0300', 0, async function (done) { + avSession.createAVSession(context, '', type, (err, data) => { + if (err) { + console.info(`TestLog: AVSession created error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info(`TestLog: AVSession ${data.sessionId} created successfully`); + expect(false).assertTrue(); + } + done(); + }); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETALLSESSIONDESCRIPTORS_CALLBACK_0100 + * @tc.name : GETALLSESSIONDESCRIPTORS_0100 + * @tc.desc : Testing get sessionDescriptors - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETALLSESSIONDESCRIPTORS_CALLBACK_0100', 0, async function (done) { + let session; + avSession.createAVSession(context, 'ApplicationB', type, (err, value) => { + if (err) { + console.info(`TestLog: Session Created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + avSession.getAllSessionDescriptors((err, descriptors) => { + if (err) { + console.info(`TestLog: Get AllSessionDescriptors error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (descriptors[0].isActive === false && descriptors[0].type === 'audio' + && descriptors[0].sessionTag === 'ApplicationB') { + console.info('TestLog: Get AllSessionDescriptors successfully'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Get AllSessionDescriptors failed'); + expect(false).assertTrue(); + } + + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + console.info(`TestLog: AVSession :${session.sessionId}destroyed successfully`); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_CALLBACK_0100 + * @tc.name : CREATECONTROLLER_0100 + * @tc.desc : Testing creat session controller - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_CALLBACK_0100', 0, async function (done) { + avSession.createController(id, (err, controller) => { + if (err) { + console.info(`TestLog: Controller created error: code: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else if (controller.sessionId === id) { + console.info('TestLog: Controller created successfully'); + expect(false).assertTrue(); + } else { + console.info('TestLog: Controller created failed'); + expect(false).assertTrue(); + } + }) + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_CALLBACK_0200 + * @tc.name : CREATECONTROLLER_0200 + * @tc.desc : Testing creat session controller - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CREATECONTROLLER_CALLBACK_0200', 0, async function (done) { + let session; + let controller; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: AVSession created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + done(); + }); + await sleep(500); + avSession.createController(session.sessionId, (err, value) => { + if (err) { + console.info(`TestLog: Controller created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (value.sessionId === session.sessionId) { + console.info('TestLog: Controller created successfully'); + controller = value; + expect(true).assertTrue(); + } else { + console.info('TestLog: Controller created failed'); + expect(false).assertTrue(); + } + }); + await sleep(500); + session.destroy((err) => { + if (err) { + console.info(`TestLog: session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: session destroy successfully'); + console.info(`TestLog: AVSession :${session.sessionId}destroyed successfully`); + } + }); + await sleep(500); + controller.destroy((err) => { + if (err) { + console.info(`TestLog: controller destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: controller destroy successfully'); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMAVKEYEVENT_CALLBACK_0100 + * @tc.name : SENDSYSTEMAVKEYEVENT_0100 + * @tc.desc : Testing send systemKeyEvent - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMAVKEYEVENT_CALLBACK_0100', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: AVSession created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + done(); + }); + + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('handleKeyEvent', (callback) => { + if (callback.action === 2) { + console.info('TestLog: Send System keyEvent successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Send System keyEvent failed'); + expect(false).assertTrue(); + } + }); + + avSession.sendSystemAVKeyEvent(event, (err) => { + if (err) { + console.info(`TestLog: Send System KeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System KeyEvent'); + } + }); + await sleep(500); + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + console.info(`TestLog: AVSession :${session.sessionId}destroyed successfully`); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0100 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0100 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0100', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'play'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + console.info(`TestLog: AVSession :${session.sessionId}destroyed successfully`); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0200 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0200 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0200', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('pause', () => { + console.info('TestLog: Pause command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'pause'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0300 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0300 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0300', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('stop', () => { + console.info('TestLog: stop command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'stop'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0400 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0400 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0400', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('playNext', () => { + console.info('TestLog: playNext command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'playNext'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0500 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0500 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0500', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('playPrevious', () => { + console.info('TestLog: playPrevious command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'playPrevious'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0600 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0600 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0600', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('fastForward', () => { + console.info('TestLog: fastForward command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'fastForward'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0700 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0700 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0700', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('rewind', () => { + console.info('TestLog: rewind command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'rewind'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0800 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0800 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0800', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('seek', (callback) => { + console.info('TestLog: seek command callback registration successful'); + }); + + + avSession.sendSystemControlCommand({command:'seek', parameter:10}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0900 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_0900 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_0900', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('setSpeed', (callback) => { + console.info('TestLog: setSpeed command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'setSpeed', parameter:2.6}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_1000 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_1000 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_1000', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('setLoopMode', (callback) => { + console.info('TestLog: setLoopMode command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'setLoopMode', parameter: + avSession.LoopMode.LOOP_MODE_SINGLE}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_1100 + * @tc.name : SENDSYSTEMCONTROLCOMMAND_1100 + * @tc.desc : Testing send system control command - callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SENDSYSTEMCONTROLCOMMAND_CALLBACK_1100', 0, async function (done) { + let session; + avSession.createAVSession(context, tag, type, (err, value) => { + if (err) { + console.info(`TestLog: Session created error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + session = value; + } + }); + await sleep(500); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + session.on('toggleFavorite', (callback) => { + console.info('TestLog: toggleFavorite command callback registration successful'); + }); + + avSession.sendSystemControlCommand({command:'toggleFavorite', parameter:'false'}, (err) => { + if (err) { + console.info(`TestLog: Send System control command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else { + console.info('TestLog: Send System control command successfully'); + expect(true).assertTrue(); + } + }); + await sleep(500); + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + }) +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js new file mode 100644 index 000000000..25bf126a2 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js @@ -0,0 +1,29 @@ +/* + * 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 AVSession from './AVSession.test.js'; +import AVSessionController from './AVSessionController.test.js'; +import AVSessionManager from './AVSessionManager.test.js'; +import AVSessionCallback from './AVSessionCallback.test.js'; +import AVSessionControllerCallback from './AVSessionControllerCallback.test.js'; +import AVSessionManagerCallback from './AVSessionManagerCallback.test.js'; + +export default function testsuite() { + AVSession() + AVSessionController() + AVSessionManager() + AVSessionCallback() + AVSessionControllerCallback() + AVSessionManagerCallback() +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/resources/base/element/string.json b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/resources/base/element/string.json new file mode 100644 index 000000000..a623995eb --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainAbility_description", + "value": "JS_Empty Ability" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/resources/base/media/icon.png b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(kzvMZ^(@4fD_{QVu$(&K6H|C37TG1Am9Re{<<3gd zh@`>;BqkXMW&p0T6rt|iB$)~CvFe(XC)F9WgAZn*0@t$oZo;!*}r@_`h?KKH&6A@3= zISXoQB+~`op>NP-buiA*^0n{@i{_?MRG)&k)c)k_F+-2Lud!S9pc+i`s74NpBCaGF zXN+pHkubw*msGBTY27BKHv)RRh3;nMg4&$fD_6X9Vt~;_4D+5XPH~#Kn-yjcy!$}1 zigv#FNY>TqMhtIBb@UoF!cE~Q8~;!Pek>SQQwHnHuWKoVBosAiOr}q>!>aE*Krc)V zBUMEcJ5NU0g8}-h6i1zpMY9>m4ne?=U2~`w7K7Q0gB_=p@$5K7p6}thw z-~3dMj?YNX2X$lZ+7ngQ$=s}3mizNN@kE%OtB)?c&i~2L55z8^=yz;xMHLmlY>&Q# zJj?!)M#q_SyfkQh)k?j8IfLtB)ZCp|*vf4_B zos?73yd^h-Ac+;?E4*bpf=o*^3x3-`TVjbY4n6!EN10K6o@fxdyps05Vo3PU)otB} z`3kR+2w7_C#8Z!q`J)p{Vh!+m9-UP!$STp+Hb}}#@#_u^SsUQg<}59< zTvH3%XS4G+6FF^(m6bVF&nSUIXcl;nw{=H$%fgeJ>CgDYiLdpDXr{;-AnG z8dvcrHYVMI&`R6;GWekI@Ir3!uo)oz4^{6q0m^}@f2tM9&=YHNi6-?rh0-{+k@cQm zdp`g#YdQn%MDVg2GR>wZ`n2<0l4)9nx1Wfr&!Dvz=bPwU!h2S?ez6MVc5APE4-xLB zi&W9Q8k2@0w!C53g?iAIQ}~p*3O(@zja6KQ=M3zfW*_6o5SwR-)6VBh~m7{^-=MC-owYH5-u40a}a0liho3QZZ5L{bS_xM1)4}19)zTU$$MY zq3eZML1WC{K%YFd`Be0M-rkO^l?h{kM{$2oK1*A@HVJ57*yhDkUF!2WZ&oA4Y-sK( zCY69%#`mBCi6>6uw(x4gbFaP0+FD*JKJ-q!F1E?vLJ+d35!I5d7@^eU?(CS|C^tmI5?lv@s{{*|1F zFg|OzNpZ0hxljdjaW%45O0MOttRrd(Z?h{HYbB-KFUx&9GfFL3b8NwZ$zNu)WbBD` zYkj$^UB5%3Pj1MDr>S2Ejr9pUcgA!;ZG!@{uAy12)vG=*^9-|dNQBc8&`oxBlU~#y zs!anJX&T?57Jdr^sb>e+V`MVfY>Y0ESg7MG<7W0g&bR-ZYzzZ%2H&Etcp zcd6QeXO1D!5A#zM0lx*GH}`M)2~ZFLE;sP^RSB5wVMNfiZXPd(cmO>j=OSA3`o5r& zna(|^jGXbdN7PK)U8b7^zYtYkkeb%<%F~=OqB~kXMQkq}ii|skh@WSRt>5za;cjP0 zZ~nD%6)wzedqE}BMLt~qKwlvTr33))#uP~xyw#*Eaa|DbMQ_%mG0U8numf8)0DX`r zRoG2bM;#g|p-8gWnwRV5SCW0tLjLO&9Z?K>FImeIxlGUgo0Zk`9Qzhj1eco~7XZy+hXc@YF&ZQ=? zn*^1O56yK^x{y}q`j7}blGCx%dydV!c7)g~tJzmHhV=W~jbWRRR{1<^oDK+1clprm zz$eCy7y9+?{E|YgkW~}}iB#I4XoJ*xr8R?i_Hv$=Cof5bo-Nj~f`-DLebH}&0% zfQj9@WGd4;N~Y?mzQsHJTJq6!Qzl^-vwol(+fMt#Pl=Wh#lI5Vmu@QM0=_r+1wHt` z+8WZ~c2}KQQ+q)~2Ki77QvV&`xb|xVcTms99&cD$Zz4+-^R4kvUBxG8gDk7Y`K*)JZ^2rL(+ZWV~%W(@6 z)0bPArG#BROa_PHs~&WplQ_UIrpd)1N1QGPfv!J(Z9jNT#i%H?CE6|pPZb9hJ1JW4 z^q;ft#!HRNV0YgPojzIYT`8LuET2rUe-J|c!9l4`^*;4WtY@Ew@pL>wkjmMgGfN7 ze}}GtmU0@<_#08~I-Suk=^*9GLW=H4xhsml;vAV{%hy5Eegl@!6qKqbG024%n2HHw zCc@ivW_$@5ZoHP70(7D+(`PvgjW1Pd`wsiuv-aCukMrafwDm)B!xXVy*j2opohhoU zcJz%ADmj>i3`-3-$7nQKBQQuGY;2Qt&+(L~C>vSGFj5{Mlv?T_^dql;{zkpe4R1}R z%XfZyQ}wr*sr>jrKgm*PWLjuVc%6&&`Kbf1SuFpHPN&>W)$GmqC;pIoBC`=4-hPY8 zT*>%I2fP}vGW;R=^!1be?ta2UQd2>alOFFbVl;(SQJ4Jk#)4Z0^wpWEVvY4=vyDk@ zqlModi@iVPMC+{?rm=4(n+<;|lmUO@UKYA>EPTS~AndtK^Wy^%#3<;(dQdk3WaUkRtzSMC9}7x2||CNpF#(3T4C)@ z$~RWs`BNABKX|{cmBt>Q=&gkXl&x!!NK_%5hW0LS)Z4PB>%sV?F-{Wyj#s7W%$F{D zXdK^Fp3wvy+48+GP6F_|^PCRx=ddcTO3sG;B23A49~Qaw31SZ0Rc~`r4qqt%#OGW{ zCA_(LG5^N>yzUn&kAgVmxb=EA8s&tBXC}S1CZ(KoW)(%^JjLTPo^fs`Va;`=YlVPgmB$!yB}<(4ym6OeZ3xAJJ#;)2+B%p3P1Wt+d$eo`vz`T zXfUP2))kBDPoscH;Jc7I3NU<({|@wM$&GaDt`n7WLgIY3IA7A6-_R?z8N3mz|}*i z(zl5ot--Oq@f2-nv{X(ujT2T(k1vY_qh93pK@>H-qc%2Xta)IP0Q%zt%bqYgI`o!wv!0QerB`nCN^1n|@$sVOQ!V0teVG!I z_fD%JvfDeT1cK#-{o6Gv7}& zY0#NWin~kVaf$aufV&;63Hbs|`QVZWpDX6IMk1Hj2G}fiH9e-^6u2zf^FIr^BwD<6zjw63+{yUe8PUFvk8v{sJ=R{d#`O!sz`Q13~< zPT$JS(w=yQfU2`zPCNfSw=&zup@DXc(98afjhv@1w_f!m2Z>rMJ19AB&dB%P#Ls3b z=lK7OILM+SQ&VEd=1GN6o&>YVVtIzoZ%=Z_SdqJN2}E43{bE`>w+A;=y->@^k{oCC z$F*WTY&?34;kfyFV?b*Xb1Pq`Z=%OgwEg)Rz)tx=`f%5#w_INP=x&z5!jI;#;N$ma zhO)+MDm;SxOEVL15; zGq(v2pL3&P1Sl)8P*;G-fd{l1QJsv@e@d8)1PK4w2m*M%V3j-V~L^$i|&C@b?D?9tfwE{B^}Z$k8e5FmQ>v7Xz)sG32g9t}YBt zyR$+*_00RmPx+0mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y