From b0012e3c712d5989a460b2caa8edc85753ec8474 Mon Sep 17 00:00:00 2001 From: zljzero Date: Thu, 1 Jun 2023 16:05:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=90=88=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zljzero --- .../main/js/test/AVSessionControllerJSTest.js | 1484 +++++++++++++++++ .../src/main/js/test/AVSessionJSTest.js | 472 ++++++ .../main/js/test/AVSessionManagerJSTest.js | 297 ++++ .../src/main/js/test/List.test.js | 6 + 4 files changed, 2259 insertions(+) create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerJSTest.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionJSTest.js create mode 100644 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerJSTest.js diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerJSTest.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerJSTest.js new file mode 100644 index 000000000..bf52c1e71 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionControllerJSTest.js @@ -0,0 +1,1484 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import avSession from '@ohos.multimedia.avsession'; +import featureAbility from '@ohos.ability.featureAbility'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; + + +const TAG = "[AVSessionControllerJSTest]"; +export default function AVSessionControllerJsTest() { + describe("AVSessionControllerJsTest", function () { + let session = null; + let controller = null; + let receivedCallback = false; + let receivedCallback2 = false; + let receivedString = null; + let receivedString2 = null; + let receivedParam = null; + let receivedParam2 = null; + let receivedExtras = null; + let receivedExtras2 = null; + const INVALID_STRING = "invalid string"; + const UPDATE_LYRICS_EVENT = "dynamic_lyrics"; + const UPDATE_LYRICS_WANT_PARAMS = { + lyrics: "This is my lyrics" + }; + const COMMON_COMMAND_STRING = "common_command"; + const COMMON_COMMAND_PARAMS = { + command: "This is my command" + }; + const CUSTOM_EXTRAS = { + extrasKey: "This is custom media packet" + }; + const QUEUE_ITEM_ID = 666; + const QUEUE_ITEM_LENGTH = 1; + const QUEUE_ITEM_KEY_WORD = "QUEUE_ITEM_RELATE"; + const EXTRAS = { + "items_author": "name" + }; + const QUEUE_ITEM_DESCRIPTION = { + mediaId: QUEUE_ITEM_KEY_WORD, + title: QUEUE_ITEM_KEY_WORD, + extras: EXTRAS + }; + const QUEUE_ITEM = { + itemId: QUEUE_ITEM_ID, + description: QUEUE_ITEM_DESCRIPTION + } + const ITEMS_ARRAY = [QUEUE_ITEM]; + const QUEUE_TITLE = "title"; + const SKIP_ITEM_ID = 200; + + beforeAll(async function () { + session = await avSession.createAVSession(featureAbility.getContext(), "AVSessionDemo", 'audio').catch((err) => { + console.error(TAG + "Create AVSession error " + JSON.stringify(err)); + expect().assertFail(); + }); + session.activate(); + controller = await avSession.createController(session.sessionId).catch((err) => { + console.error(TAG + "Create controller error " + JSON.stringify(err)); + expect().assertFail(); + }) + console.info(TAG + "Create session and controller finished, beforeAll called"); + }) + + afterAll(function () { + controller.destroy(); + session.destroy(); + console.info(TAG + 'afterAll called'); + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach called'); + }) + + afterEach(function () { + console.info(TAG + 'afterEach called'); + }) + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function dynamicLyricsCallback1(sessionEvent, args) { + console.log(TAG + "Callback1 received event: " + JSON.stringify(sessionEvent)); + console.log(TAG + "Callback1 received args: " + JSON.stringify(args)); + if (sessionEvent != UPDATE_LYRICS_EVENT) { + console.error(TAG + "Callback1 lyrics event unmatch"); + expect().assertFail(); + } + receivedCallback = true; + receivedString = sessionEvent; + receivedParam = args; + } + + function dynamicLyricsCallback2(sessionEvent, args) { + console.log(TAG + "Callback2 received event: " + JSON.stringify(sessionEvent)); + console.log(TAG + "Callback2 received args: " + JSON.stringify(args)); + if (sessionEvent != UPDATE_LYRICS_EVENT) { + console.error(TAG + "Callback2 lyrics event unmatch"); + expect().assertFail(); + } + receivedCallback2 = true; + receivedString2 = sessionEvent; + receivedParam2 = args; + } + + function extrasChangeCallback1(extras) { + console.log(TAG + "Callback1 received args: " + JSON.stringify(extras)); + if (extras.extrasKey != CUSTOM_EXTRAS.extrasKey) { + console.error(TAG + "Callback1 extras unmatch"); + expect().assertFail(); + } + receivedCallback = true; + receivedExtras = extras; + } + + function extrasChangeCallback2(extras) { + console.log(TAG + "Callback2 received args: " + JSON.stringify(extras)); + if (extras.extrasKey != CUSTOM_EXTRAS.extrasKey) { + console.error(TAG + "Callback2 extras unmatch"); + expect().assertFail(); + } + receivedCallback2 = true; + receivedExtras2 = extras; + } + + function queueTitleCallback1(title) { + console.log(TAG + "queueTitleCallback1 received Title " + JSON.stringify(title)); + if (title != QUEUE_TITLE) { + console.error(TAG + "queueTitleCallback1 received Title unmatch"); + expect().assertFail(); + } + receivedCallback = true; + } + + function queueTitleCallback2(title) { + console.log(TAG + "queueTitleCallback2 received Title " + JSON.stringify(title)); + if (title != QUEUE_TITLE) { + console.error(TAG + "queueTitleCallback2 received Title unmatch"); + expect().assertFail(); + } + receivedCallback2 = true; + } + + function queueItemsCallback1(items) { + console.log(TAG + "queueItemsCallback1 received items length: " + items.length); + console.log(TAG + "queueItemsCallback1 received items id: " + items[0].itemId); + console.log(TAG + "queueItemsCallback1 received items title: " + items[0].description.title); + if (items.length != QUEUE_ITEM_LENGTH) { + console.error(TAG + "queueItemsCallback1 received items length unmatch"); + expect().assertFail(); + return; + } + if (items[0].itemId != QUEUE_ITEM_ID) { + console.error(TAG + "queueItemsCallback1 received items id unmatch"); + expect().assertFail(); + return; + } + if (items[0].description.title != QUEUE_ITEM_KEY_WORD) { + console.error(TAG + "queueItemsCallback1 received items key word unmatch"); + expect().assertFail(); + return; + } + receivedCallback = true; + } + + function queueItemsCallback2(items) { + console.log(TAG + "queueItemsCallback2 received items length: " + items.length); + console.log(TAG + "queueItemsCallback2 received items id: " + items[0].itemId); + console.log(TAG + "queueItemsCallback2 received items title: " + items[0].description.title); + if (items.length != QUEUE_ITEM_LENGTH) { + console.error(TAG + "queueItemsCallback2 received items length unmatch"); + expect().assertFail(); + return; + } + if (items[0].itemId != QUEUE_ITEM_ID) { + console.error(TAG + "queueItemsCallback2 received items id unmatch"); + expect().assertFail(); + return; + } + if (items[0].description.title != QUEUE_ITEM_KEY_WORD) { + console.error(TAG + "queueItemsCallback2 received items key word unmatch"); + expect().assertFail(); + return; + } + receivedCallback2 = true; + } + + function skipToQueueItemCallback1(itemId) { + console.log(TAG + "skipToQueueItemCallback1 received itemid " + itemId); + if (itemId != SKIP_ITEM_ID) { + console.error(TAG + "skipToQueueItemCallback1 received uid unmatch"); + expect().assertFail(); + } + receivedCallback = true; + } + + function skipToQueueItemCallback2(itemId) { + console.log(TAG + "skipToQueueItemCallback2 received itemid " + itemId); + if (itemId != SKIP_ITEM_ID) { + console.error(TAG + "skipToQueueItemCallback2 received uid unmatch"); + expect().assertFail(); + } + receivedCallback2 = true; + } + + /* + * @tc.name:onSessionEventTest001 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("onSessionEventTest001", 0, async function (done) { + controller.on('sessionEvent', dynamicLyricsCallback1); + await session.dispatchSessionEvent(UPDATE_LYRICS_EVENT, UPDATE_LYRICS_WANT_PARAMS).catch((err) => { + console.error(TAG + "dispatchSessionEventTest002 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + sleep(200).then(() => { + if (receivedCallback) { + console.log(TAG + "Received session event change event"); + expect(receivedString == UPDATE_LYRICS_EVENT).assertTrue(); + expect(receivedParam.lyrics == UPDATE_LYRICS_WANT_PARAMS.lyrics).assertTrue(); + } else { + console.error(TAG + "Session event change event not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedString = null; + receivedParam = null; + done(); + }) + }) + + /* + * @tc.name:onSessionEventTest002 + * @tc.desc:Two on functions - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("onSessionEventTest002", 0, async function (done) { + controller.on('sessionEvent', dynamicLyricsCallback1); + controller.on('sessionEvent', dynamicLyricsCallback2); + await session.dispatchSessionEvent(UPDATE_LYRICS_EVENT, UPDATE_LYRICS_WANT_PARAMS).catch((err) => { + console.error(TAG + "Set session event error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && receivedCallback2) { + console.log(TAG + "Received session event change event"); + expect(receivedString == UPDATE_LYRICS_EVENT).assertTrue(); + expect(receivedParam.lyrics == UPDATE_LYRICS_WANT_PARAMS.lyrics).assertTrue(); + expect(receivedString2 == UPDATE_LYRICS_EVENT).assertTrue(); + expect(receivedParam2.lyrics == UPDATE_LYRICS_WANT_PARAMS.lyrics).assertTrue(); + expect(true).assertTrue(); + } else { + console.error(TAG + "Session event change event not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedCallback2 = false; + receivedString2 = null; + receivedParam2 = null; + receivedString2 = null; + receivedParam2 = null; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONSESSIONEVENT_0300 + * @tc.desc:One on functions - one param + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_ONSESSIONEVENT_0300", 0, async function (done) { + try { + controller.on('sessionEvent'); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONSESSIONEVENT_0400 + * @tc.desc:One on functions - three params + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_ONSESSIONEVENT_0400", 0, async function (done) { + try { + controller.on('sessionEvent', dynamicLyricsCallback1, dynamicLyricsCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONSESSIONEVENT_0500 + * @tc.desc:One on functions - invalid type + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_ONSESSIONEVENT_0500", 0, async function (done) { + try { + controller.on('sessionEvent', INVALID_STRING); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFSESSIONEVENT_0100 + * @tc.desc:Two on functions and one off function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_OFFSESSIONEVENT_0100", 0, async function (done) { + controller.on('sessionEvent', dynamicLyricsCallback1); + controller.on('sessionEvent', dynamicLyricsCallback2); + controller.off('sessionEvent', dynamicLyricsCallback2); + await session.dispatchSessionEvent(UPDATE_LYRICS_EVENT, UPDATE_LYRICS_WANT_PARAMS).catch((err) => { + console.error(TAG + "Set session event error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && !receivedCallback2) { + console.log(TAG + "Received session event change event"); + expect(receivedString == UPDATE_LYRICS_EVENT).assertTrue(); + expect(receivedParam.lyrics == UPDATE_LYRICS_WANT_PARAMS.lyrics).assertTrue(); + expect(true).assertTrue(); + } else { + console.error(TAG + "Session event change event not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedString = null; + receivedParam = null; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFSESSIONEVENT_0200 + * @tc.desc:Two on functions and two off function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_OFFSESSIONEVENT_0200", 0, async function (done) { + controller.on('sessionEvent', dynamicLyricsCallback1); + controller.on('sessionEvent', dynamicLyricsCallback2); + controller.off('sessionEvent', dynamicLyricsCallback1); + controller.off('sessionEvent', dynamicLyricsCallback2); + + await session.dispatchSessionEvent(UPDATE_LYRICS_EVENT, UPDATE_LYRICS_WANT_PARAMS).catch((err) => { + console.error(TAG + "Set session event error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "Received session event change event"); + expect(true).assertTrue(); + } else { + console.error(TAG + "Session event change event not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFSESSIONEVENT_0300 + * @tc.desc:Two on functions and off all function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_OFFSESSIONEVENT_0300", 0, async function (done) { + controller.on('sessionEvent', dynamicLyricsCallback1); + controller.on('sessionEvent', dynamicLyricsCallback2); + controller.off('sessionEvent'); + + await session.dispatchSessionEvent(UPDATE_LYRICS_EVENT, UPDATE_LYRICS_WANT_PARAMS).catch((err) => { + console.error(TAG + "Set session event error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "Received session event change event"); + expect(true).assertTrue(); + } else { + console.error(TAG + "Session event change event not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFSESSIONEVENT_0400 + * @tc.desc:Two on functions and off function - three params + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_OFFSESSIONEVENT_0400", 0, async function (done) { + try { + controller.on('sessionEvent', dynamicLyricsCallback1); + controller.on('sessionEvent', dynamicLyricsCallback2); + controller.off('sessionEvent', dynamicLyricsCallback1, dynamicLyricsCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFSESSIONEVENT_0500 + * @tc.desc:One on functions and off all function - invalid type + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_OFFSESSIONEVENT_0500", 0, async function (done) { + try { + controller.on('sessionEvent', dynamicLyricsCallback1); + controller.off('sessionEvent', INVALID_STRING); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0100 + * @tc.desc:Send common command - callback + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0100", 0, async function (done) { + controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0100 finished"); + expect(true).assertTrue(); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0200 + * @tc.desc:Send common command - promise + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0200", 0, async function (done) { + await controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0300 + * @tc.desc:Set common command - one param + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0300", 0, async function (done) { + let errCode = 0; + await controller.sendCommonCommand(COMMON_COMMAND_STRING).catch((err) => { + console.info(TAG + "SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0300 caught error" + err.code); + errCode = err.code; + }); + sleep(200).then(() => { + expect(errCode == 401).assertTrue(); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0400 + * @tc.desc:Send common command - invalid params + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0400", 0, async function (done) { + let errCode = 0; + await controller.sendCommonCommand(COMMON_COMMAND_PARAMS, COMMON_COMMAND_PARAMS).catch((err) => { + console.info(TAG + "SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0400 caught error" + err.code); + errCode = err.code; + }); + sleep(200).then(() => { + expect(errCode == 401).assertTrue(); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0500 + * @tc.desc:Send common command - deactive + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_SENDCOMMONCOMMAND_0500", 0, async function (done) { + try { + session.deactivate(async () => { + await controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS); + }); + } catch (err) { + expect(err.code == 6600106).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETEXTRAS_0100 + * @tc.desc:Get extras - callback + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_GETEXTRAS_0100", 0, async function (done) { + console.info(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0100 start"); + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0100 error " + JSON.stringify(err)); + expect().assertFail(); + }); + + controller.getExtras((err, extras) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + expect(extras.extrasKey == CUSTOM_EXTRAS.extrasKey).assertTrue(); + console.info(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0100 finished"); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETEXTRAS_0200 + * @tc.desc:Get extras - promise + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_GETEXTRAS_0200", 0, async function (done) { + console.info(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0200 start"); + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0200 error " + JSON.stringify(err)); + expect().assertFail(); + }); + + let extras = await controller.getExtras().catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }) + expect(extras.extrasKey == CUSTOM_EXTRAS.extrasKey).assertTrue(); + console.info(TAG + "SUB_MULTIMEDIA_GETEXTRAS_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONEXTRASCHANGE_0100 + * @tc.desc:One on function - extras change + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_ONEXTRASCHANGE_0100", 0, async function (done) { + console.info(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0100 start"); + controller.on('extrasChange', extrasChangeCallback1); + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + sleep(200).then(() => { + if (receivedCallback) { + console.log(TAG + "Received extras change event"); + expect(receivedExtras.extrasKey == CUSTOM_EXTRAS.extrasKey).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0100 extras change event not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedExtras = null; + console.info(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0100 finished"); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONEXTRASCHANGE_0200 + * @tc.desc:Two on function - extras change + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_ONEXTRASCHANGE_0200", 0, async function (done) { + console.info(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0200 start"); + controller.on('extrasChange', extrasChangeCallback1); + controller.on('extrasChange', extrasChangeCallback2); + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + sleep(200).then(() => { + if (receivedCallback && receivedCallback2) { + console.log(TAG + "Received extras change event"); + expect(receivedExtras.extrasKey == CUSTOM_EXTRAS.extrasKey).assertTrue(); + expect(receivedExtras2.extrasKey == CUSTOM_EXTRAS.extrasKey).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0200 extras change event not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedCallback2 = false; + receivedExtras = null; + receivedExtras2 = null; + console.info(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0200 finished"); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONEXTRASCHANGE_0300 + * @tc.desc:One on functions - one param + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_ONEXTRASCHANGE_0300", 0, async function (done) { + try { + controller.on('extrasChange'); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + console.info(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0300 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONEXTRASCHANGE_0400 + * @tc.desc:One on functions - three params + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_ONEXTRASCHANGE_0400", 0, async function (done) { + try { + controller.on('extrasChange', extrasChangeCallback1, extrasChangeCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + console.info(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0400 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONEXTRASCHANGE_0500 + * @tc.desc:One on functions - invalid type + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_ONEXTRASCHANGE_0500", 0, async function (done) { + try { + controller.on('extrasChange', INVALID_STRING); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + console.info(TAG + "SUB_MULTIMEDIA_ONEXTRASCHANGE_0500 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFEXTRASCHANGE_0100 + * @tc.desc:Two on functions and one off function - extras change + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_OFFEXTRASCHANGE_0100", 0, async function (done) { + controller.on('extrasChange', extrasChangeCallback1); + controller.on('extrasChange', extrasChangeCallback2); + controller.off('extrasChange', extrasChangeCallback2); + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && !receivedCallback2) { + console.log(TAG + "Received extras change event"); + expect(receivedExtras.extrasKey == CUSTOM_EXTRAS.extrasKey).assertTrue(); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0100 Extras change event not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedExtras = null; + console.info(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0100 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFEXTRASCHANGE_0200 + * @tc.desc:Two on functions and two off function - extras change + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_OFFEXTRASCHANGE_0200", 0, async function (done) { + controller.on('extrasChange', extrasChangeCallback1); + controller.on('extrasChange', extrasChangeCallback2); + controller.off('extrasChange', extrasChangeCallback1); + controller.off('extrasChange', extrasChangeCallback2); + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0200 Success, not received extras change event"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0200 failed, extras change event received"); + expect().assertFail(); + } + console.info(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFEXTRASCHANGE_0300 + * @tc.desc:Two on functions and off all function - extras change + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_OFFEXTRASCHANGE_0300", 0, async function (done) { + controller.on('extrasChange', extrasChangeCallback1); + controller.on('extrasChange', extrasChangeCallback2); + controller.off('extrasChange'); + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0300 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0300Success, not received extras change event"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0300 failed, extras change event received"); + expect().assertFail(); + } + console.info(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0300 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFEXTRASCHANGE_0400 + * @tc.desc:Two on functions and off function - three params + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_OFFEXTRASCHANGE_0400", 0, async function (done) { + try { + controller.on('extrasChange', extrasChangeCallback1); + controller.on('extrasChange', extrasChangeCallback2); + controller.off('extrasChange', extrasChangeCallback1, extrasChangeCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + console.info(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0400 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFEXTRASCHANGE_0500 + * @tc.desc:One on functions and off all function - invalid type + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_OFFEXTRASCHANGE_0500", 0, async function (done) { + try { + controller.on('extrasChange', extrasChangeCallback1); + controller.off('extrasChange', INVALID_STRING); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + console.info(TAG + "SUB_MULTIMEDIA_OFFEXTRASCHANGE_0500 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0100 + * @tc.desc:One on function - queue items change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0100", 0, async function (done) { + controller.on('queueItemsChange', queueItemsCallback1); + await session.setAVQueueItems(ITEMS_ARRAY).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0100 setAVQueueItems error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + sleep(200).then(() => { + if (receivedCallback) { + console.log(TAG + "SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0100 Received queue items change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0100 Session queue items change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0200 + * @tc.desc:One on function - queue items change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0200", 0, async function (done) { + controller.on('queueItemsChange', queueItemsCallback1); + controller.on('queueItemsChange', queueItemsCallback2); + await session.setAVQueueItems(ITEMS_ARRAY).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0200 Received queue items change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0200 Session queue items change not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedCallback2 = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0300 + * @tc.desc:One on functions - one param + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0300", 0, async function (done) { + try { + controller.on('queueItemsChange'); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0300 + * @tc.desc:One on functions - three params + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUEITEMSCHANGE_0300", 0, async function (done) { + try { + controller.on('queueItemsChange', queueItemsCallback1, queueItemsCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0100 + * @tc.desc:One on function - queue title change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0100", 0, async function (done) { + controller.on('queueTitleChange', queueTitleCallback1); + await session.setAVQueueTitle(QUEUE_TITLE).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0100 setAVQueueTitle error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + sleep(200).then(() => { + if (receivedCallback) { + console.log(TAG + "SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0100 Received queue Title change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0100 Session queue Title change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0200 + * @tc.desc:One on function - queue title change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0200", 0, async function (done) { + controller.on('queueTitleChange', queueTitleCallback1); + controller.on('queueTitleChange', queueTitleCallback2); + await session.setAVQueueTitle(QUEUE_TITLE).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0200 Received queue Title change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0200 Session queue Title change not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedCallback2 = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0300 + * @tc.desc:One on functions - one param + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0300", 0, async function (done) { + try { + controller.on('queueTitleChange'); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0400 + * @tc.desc:One on functions - three params + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONQUEUETITLECHANGE_0400", 0, async function (done) { + try { + controller.on('queueTitleChange', queueTitleCallback1, queueTitleCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0100 + * @tc.desc:Two on functions and one off function - queue items change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0100", 0, async function (done) { + controller.on('queueItemsChange', queueItemsCallback1); + controller.on('queueItemsChange', queueItemsCallback2); + controller.off('queueItemsChange', queueItemsCallback2); + await session.setAVQueueItems(ITEMS_ARRAY).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0100 setAVQueueItems error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0100 Received queue items change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0100 Session queue items change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0200 + * @tc.desc:Two on functions and two off function - queue items change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0200", 0, async function (done) { + controller.on('queueItemsChange', queueItemsCallback1); + controller.on('queueItemsChange', queueItemsCallback2); + controller.off('queueItemsChange', queueItemsCallback1); + controller.off('queueItemsChange', queueItemsCallback2); + await session.setAVQueueItems(ITEMS_ARRAY).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0200 setAVQueueItems error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0200 Received queue items change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0200 Session queue items change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0300 + * @tc.desc:Two on functions and off all function - queue items change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0300", 0, async function (done) { + controller.on('queueItemsChange', queueItemsCallback1); + controller.on('queueItemsChange', queueItemsCallback2); + controller.off('queueItemsChange'); + await session.setAVQueueItems(ITEMS_ARRAY).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0300 setAVQueueItems error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0300 Received queue items change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0300 Session queue items change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0400 + * @tc.desc:Two on functions and off function - three params + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUEITEMSCHANGE_0400", 0, async function (done) { + try { + controller.on('queueItemsChange', queueItemsCallback1); + controller.on('queueItemsChange', queueItemsCallback2); + controller.off('queueItemsChange', queueItemsCallback1, queueItemsCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0100 + * @tc.desc:Two on functions and one off function - queue title change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0100", 0, async function (done) { + controller.on('queueTitleChange', queueTitleCallback1); + controller.on('queueTitleChange', queueTitleCallback2); + controller.off('queueTitleChange', queueTitleCallback2); + await session.setAVQueueTitle(QUEUE_TITLE).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0100 setAVQueueTitle error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0100 Received queue Title change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0100 Session queue Title change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0200 + * @tc.desc:Two on functions and two off function - queue title change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0200", 0, async function (done) { + controller.on('queueTitleChange', queueTitleCallback1); + controller.on('queueTitleChange', queueTitleCallback2); + controller.off('queueTitleChange', queueTitleCallback1); + controller.off('queueTitleChange', queueTitleCallback2); + + await session.setAVQueueTitle(QUEUE_TITLE).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0200 setAVQueueTitle error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0200 Received queue Title change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0200 Session queue Title change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0300 + * @tc.desc:Two on functions and off all function - queue title change + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0300", 0, async function (done) { + controller.on('queueTitleChange', queueTitleCallback1); + controller.on('queueTitleChange', queueTitleCallback2); + controller.off('queueTitleChange'); + + await session.setAVQueueTitle(QUEUE_TITLE).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0300 setAVQueueTitle error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0300 Received queue Title change"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0300 Session queue Title change not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0400 + * @tc.desc:Two on functions and off function - three params + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_OFFQUEUETITLECHANGE_0400", 0, async function (done) { + try { + controller.on('queueTitleChange', queueTitleCallback1); + controller.on('queueTitleChange', queueTitleCallback2); + controller.off('queueTitleChange', queueTitleCallback1, queueTitleCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETAVQUEUEITEMS_0100 + * @tc.desc:setAVQueueItems - callback + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + + it("SUB_MULTIMEDIA_SETAVQUEUEITEMS_0100", 0, async function (done) { + session.setAVQueueItems(ITEMS_ARRAY, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_SETAVQUEUEITEMS_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_SETAVQUEUEITEMS_0100 finished"); + expect(true).assertTrue(); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETAVQUEUEITEMS_0200 + * @tc.desc:setAVQueueItems - promise + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_SETAVQUEUEITEMS_0200", 0, async function (done) { + await session.setAVQueueItems(ITEMS_ARRAY).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_SETAVQUEUEITEMS_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_SETAVQUEUEITEMS_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETAVQUEUETITLE_0100 + * @tc.desc:setAVQueueTitle - callback + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_SETAVQUEUETITLE_0100", 0, async function (done) { + session.setAVQueueTitle(QUEUE_TITLE, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_SETAVQUEUETITLE_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_SETAVQUEUETITLE_0100 finished"); + expect(true).assertTrue(); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETAVQUEUETITLE_0200 + * @tc.desc:setAVQueueTitle - promise + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_SETAVQUEUETITLE_0200", 0, async function (done) { + await session.setAVQueueTitle(QUEUE_TITLE).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_SETAVQUEUETITLE_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_SETAVQUEUETITLE_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0100 + * @tc.desc:SkipToQueueItem - callback + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0100", 0, async function (done) { + controller.skipToQueueItem(QUEUE_ITEM_ID, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0100 finished"); + expect(true).assertTrue(); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0200 + * @tc.desc:SkipToQueueItem - promise + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0200", 0, async function (done) { + await controller.skipToQueueItem(QUEUE_ITEM_ID).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_SKIPTOQUEUEITEM_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0100 + * @tc.desc:One on function - skip to queue items + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0100", 0, async function (done) { + session.on('skipToQueueItem', skipToQueueItemCallback1); + await controller.skipToQueueItem(SKIP_ITEM_ID).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + sleep(200).then(() => { + if (receivedCallback) { + console.log(TAG + "SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0100 Received skipToQueueItem "); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0100 skipToQueueItem not received"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0200 + * @tc.desc:One on function - skip to queue items + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0200", 0, async function (done) { + session.on('skipToQueueItem', skipToQueueItemCallback1); + session.on('skipToQueueItem', skipToQueueItemCallback2); + await controller.skipToQueueItem(SKIP_ITEM_ID).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0200 Received skipToQueueItem "); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0200skipToQueueItem not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedCallback2 = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0300 + * @tc.desc:One on functions - one param + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0300", 0, async function (done) { + try { + session.on('skipToQueueItem'); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0400 + * @tc.desc:One on functions - three params + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_ONSKIPTOQUEUEITEM_0400", 0, async function (done) { + try { + session.on('skipToQueueItem', skipToQueueItemCallback1, skipToQueueItemCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETAVQUEUEITEMS_0100 + * @tc.desc:GetAVQueueItems - callback + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_GETAVQUEUEITEMS_0100", 0, async function (done) { + session.setAVQueueItems(ITEMS_ARRAY, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0100 finished"); + expect(true).assertTrue(); + done(); + }); + await sleep(200); + controller.getAVQueueItems((err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0100 finished"); + expect(true).assertTrue(); + done(); + }); + await sleep(200); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETAVQUEUEITEMS_0200 + * @tc.desc:GetAVQueueItems - promise + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_GETAVQUEUEITEMS_0200", 0, async function (done) { + await session.setAVQueueItems(ITEMS_ARRAY).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0200 finished"); + done(); + await sleep(200); + await controller.getAVQueueItems().catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUEITEMS_0200 finished"); + done(); + await sleep(200); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETAVQUEUETITLE_0100 + * @tc.desc:GetAVQueueTitle - callback + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_GETAVQUEUETITLE_0100", 0, async function (done) { + session.setAVQueueTitle(QUEUE_TITLE, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0100 finished"); + expect(true).assertTrue(); + done(); + }); + await sleep(200); + controller.getAVQueueTitle((err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0100 finished"); + expect(true).assertTrue(); + done(); + }); + await sleep(200); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETAVQUEUETITLE_0200 + * @tc.desc:GetAVQueueTitle - promise + * @tc.type: FUNC + * @tc.require: I6KTU4 + */ + it("SUB_MULTIMEDIA_GETAVQUEUETITLE_0200", 0, async function (done) { + await session.setAVQueueTitle(QUEUE_TITLE).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0200 finished"); + done(); + await sleep(200); + await controller.getAVQueueTitle().catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_GETAVQUEUETITLE_0200 finished"); + done(); + await sleep(200); + }) + + }) +} diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionJSTest.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionJSTest.js new file mode 100644 index 000000000..6940e47b9 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionJSTest.js @@ -0,0 +1,472 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import avSession from '@ohos.multimedia.avsession'; +import featureAbility from '@ohos.ability.featureAbility'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; + + +const TAG = "[AVSessionJSTest]"; +export default function AVSessionJsTest() { + describe("AVSessionJsTest", function () { + let session = null; + let controller = null; + let receivedCallback = false; + let receivedCallback2 = false; + let receivedString = null; + let receivedString2 = null; + let receivedParam = null; + let receivedParam2 = null; + const INVALID_STRING = "invalid string"; + const UPDATE_LYRICS_EVENT = "dynamic_lyrics"; + const UPDATE_LYRICS_WANT_PARAMS = { + lyric: "This is my lyrics" + }; + const COMMON_COMMAND_STRING = "common_command"; + const COMMON_COMMAND_PARAMS = { + command: "This is my command" + }; + const CUSTOM_EXTRAS = { + extras: "This is custom media packet" + }; + + beforeAll(async function () { + session = await avSession.createAVSession(featureAbility.getContext(), "AVSessionDemo", 'audio').catch((err) => { + console.error(TAG + "Create AVSession error " + JSON.stringify(err)); + expect().assertFail(); + }); + session.activate(); + controller = await avSession.createController(session.sessionId).catch((err) => { + console.error(TAG + "Create controller error " + JSON.stringify(err)); + expect().assertFail(); + }) + console.info(TAG + "Create session finished, beforeAll called"); + }) + + afterAll(function () { + session.destroy(); + console.info(TAG + 'afterAll called') + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach called') + }) + + afterEach(function () { + console.info(TAG + 'afterEach called') + }) + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function commonCommandCallback1(command, args) { + console.log(TAG + "Callback1 received event: " + JSON.stringify(command)); + console.log(TAG + "Callback1 received args: " + JSON.stringify(args)); + if (command != COMMON_COMMAND_STRING) { + console.error(TAG + "Callback1 common command unmatch"); + expect().assertFail(); + } + receivedCallback = true; + receivedString = command; + receivedParam = args; + } + + function commonCommandCallback2(command, args) { + console.log(TAG + "Callback2 received event: " + JSON.stringify(command)); + console.log(TAG + "Callback2 received args: " + JSON.stringify(args)); + if (command != COMMON_COMMAND_STRING) { + console.error(TAG + "Callback2 common command unmatch"); + expect().assertFail(); + } + receivedCallback2 = true; + receivedString2 = command; + receivedParam2 = args; + } + + /* + * @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100 + * @tc.desc:Set session event - callback + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100", 0, async function (done) { + session.dispatchSessionEvent(UPDATE_LYRICS_EVENT, UPDATE_LYRICS_WANT_PARAMS, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0100 finished"); + expect(true).assertTrue(); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200 + * @tc.desc:Set session event - promise + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200", 0, async function (done) { + await session.dispatchSessionEvent(UPDATE_LYRICS_EVENT, UPDATE_LYRICS_WANT_PARAMS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0300 + * @tc.desc:Set session event - one param + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0300", 0, async function (done) { + let errCode = 0; + await session.dispatchSessionEvent(UPDATE_LYRICS_EVENT).catch((err) => { + console.info(TAG + "SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0300 caught error" + err.code); + errCode = err.code; + }); + sleep(200).then(() => { + expect(errCode == 401).assertTrue(); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0400 + * @tc.desc:Set session event - invalid params + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0400", 0, async function (done) { + let errCode = 0; + await session.dispatchSessionEvent(UPDATE_LYRICS_WANT_PARAMS, UPDATE_LYRICS_WANT_PARAMS).catch((err) => { + console.info(TAG + "SUB_MULTIMEDIA_DISPATCHSESSIONEVENT_0400 caught error" + err.code); + errCode = err.code; + }); + sleep(200).then(() => { + expect(errCode == 401).assertTrue(); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0100 + * @tc.desc:Set extras - callback + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_SETEXTRAS_0100", 0, async function (done) { + session.setExtras(CUSTOM_EXTRAS, (err) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0100 finished"); + expect(true).assertTrue(); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0200 + * @tc.desc:Set extras - promise + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_SETEXTRAS_0200", 0, async function (done) { + await session.setExtras(CUSTOM_EXTRAS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0200 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0200 finished"); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0300 + * @tc.desc:Set extras - zero param + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_SETEXTRAS_0300", 0, async function (done) { + let errCode = 0; + await session.setExtras().catch((err) => { + console.info(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0300 caught error" + err.code); + errCode = err.code; + }); + sleep(200).then(() => { + expect(errCode == 401).assertTrue(); + console.info(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0300 finished"); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_SETEXTRAS_0400 + * @tc.desc:Set extras - invalid params + * @tc.type: FUNC + * @tc.require: I6TD43 + */ + it("SUB_MULTIMEDIA_SETEXTRAS_0400", 0, async function (done) { + let errCode = 0; + await session.setExtras(INVALID_STRING).catch((err) => { + console.info(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0400 caught error" + err.code); + errCode = err.code; + }); + sleep(200).then(() => { + expect(errCode == 401).assertTrue(); + console.info(TAG + "SUB_MULTIMEDIA_SETEXTRAS_0400 finished"); + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100 + * @tc.desc:One on function - common command + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100", 0, async function (done) { + session.on('commonCommand', commonCommandCallback1); + await controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + sleep(200).then(() => { + if (receivedCallback) { + console.log(TAG + "SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100 Received common command"); + expect(receivedString == COMMON_COMMAND_STRING).assertTrue(); + expect(receivedParam.command == COMMON_COMMAND_PARAMS.command).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONCOMMONCOMMAND_0100 Common command not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedString = null; + receivedParam = null; + done(); + }) + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200 + * @tc.desc:Two on functions - common command + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200", 0, async function (done) { + session.on('commonCommand', commonCommandCallback1); + session.on('commonCommand', commonCommandCallback2); + await controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200 Send common command error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200 Received common command"); + expect(receivedString == COMMON_COMMAND_STRING).assertTrue(); + expect(receivedParam.command == COMMON_COMMAND_PARAMS.command).assertTrue(); + expect(receivedString2 == COMMON_COMMAND_STRING).assertTrue(); + expect(receivedParam2.command == COMMON_COMMAND_PARAMS.command).assertTrue(); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_ONCOMMONCOMMAND_0200 Common command not received"); + expect().assertFail(); + } + receivedCallback = false; + receivedString = null; + receivedParam = null; + receivedCallback2 = false; + receivedString2 = null; + receivedParam2 = null; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0300 + * @tc.desc:One on functions - one param + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_ONCOMMONCOMMAND_0300", 0, async function (done) { + try { + session.on('commonCommand'); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0400 + * @tc.desc:One on functions - three params + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_ONCOMMONCOMMAND_0400", 0, async function (done) { + try { + session.on('sessionEventChange', commonCommandCallback1, commonCommandCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_ONCOMMONCOMMAND_0500 + * @tc.desc:One on functions - invalid type + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_ONCOMMONCOMMAND_0500", 0, async function (done) { + try { + session.on('commonCommand', INVALID_STRING); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100 + * @tc.desc:Two on functions and one off function + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100", 0, async function (done) { + session.on('commonCommand', commonCommandCallback1); + session.on('commonCommand', commonCommandCallback2); + session.off('commonCommand', commonCommandCallback2); + await controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100 Send common command error" + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100 finished"); + expect(receivedString == COMMON_COMMAND_STRING).assertTrue(); + expect(receivedParam.command == COMMON_COMMAND_PARAMS.command).assertTrue(); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0100 failed"); + expect().assertFail(); + } + receivedCallback = false; + receivedString = null; + receivedParam = null; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200 + * @tc.desc:Two on functions and two off function + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200", 0, async function (done) { + session.on('commonCommand', commonCommandCallback1); + session.on('commonCommand', commonCommandCallback2); + session.off('commonCommand', commonCommandCallback1); + session.off('commonCommand', commonCommandCallback2); + await controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200 Send common command error" + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200 finished"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0200 failed"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300 + * @tc.desc:Two on functions and off all function + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300", 0, async function (done) { + session.on('commonCommand', commonCommandCallback1); + session.on('commonCommand', commonCommandCallback2); + session.off('commonCommand'); + + await controller.sendCommonCommand(COMMON_COMMAND_STRING, COMMON_COMMAND_PARAMS).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300 Send common command error" + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + await sleep(200); + if (!receivedCallback && !receivedCallback2) { + console.log(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300 finished"); + expect(true).assertTrue(); + } else { + console.error(TAG + "SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0300 failed"); + expect().assertFail(); + } + receivedCallback = false; + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0400 + * @tc.desc:Two on functions and off function - three params + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0400", 0, async function (done) { + try { + session.on('commonCommand', commonCommandCallback1); + session.on('commonCommand', commonCommandCallback2); + session.off('commonCommand', commonCommandCallback1, commonCommandCallback2); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0500 + * @tc.desc:One on functions and off all function - invalid type + * @tc.type: FUNC + * @tc.require: I6ETY6 + */ + it("SUB_MULTIMEDIA_OFFCOMMONCOMMAND_0500", 0, async function (done) { + try { + session.on('commonCommand', commonCommandCallback1); + session.off('commonCommand', INVALID_STRING); + } catch (err) { + expect(err.code == 401).assertTrue(); + } + done(); + }) + }) +} diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerJSTest.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerJSTest.js new file mode 100644 index 000000000..0dbbfcbe9 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManagerJSTest.js @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AVSessionManager from '@ohos.multimedia.avsession'; +import featureAbility from '@ohos.ability.featureAbility'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; + + +const TAG = "[AVSessionManagerJSTest]"; +export default function AVSessionManagerJSTest() { + describe("AVSessionManagerJSTest", function () { + let session = null; + let controller = null; + let receivedCallback = false; + let receivedCallback2 = false; + let context = featureAbility.getContext(); + + const INVALID_STRING = "invalid string"; + const UPDATE_LYRICS_EVENT = "dynamic_lyrics"; + const UPDATE_LYRICS_WANT_PARAMS = { + lyrics: "This is my lyrics" + } + + beforeAll(async function () { + console.info(TAG + "beforeAll called"); + }) + + afterAll(function () { + console.info(TAG + 'afterAll called'); + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach called'); + }) + + afterEach(function () { + console.info(TAG + 'afterEach called'); + }) + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + async function createSessionTask() { + session = await AVSessionManager.createAVSession(context, "AVSessionDemo", 'audio').catch((err) => { + console.error(TAG + "Create AVSession error " + JSON.stringify(err)); + expect().assertFail(); + }); + console.info(TAG + "Create session finished"); + } + + function destroySessionTask() { + session.destroy(); + console.info(TAG + 'Destroy session finished'); + } + + async function createControllerTask() { + controller = await AVSessionManager.createController(session.sessionId).catch((err) => { + console.error(TAG + "Create controller error " + JSON.stringify(err)); + expect().assertFail(); + }); + console.info(TAG + "Create controller finished"); + } + + function destroyControllerTask() { + controller.destroy(); + console.info(TAG + 'Destroy session finished'); + } + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100", 0, async function (done) { + await createSessionTask(); + let descriptors = await AVSessionManager.getHistoricalSessionDescriptors().catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100 error " + JSON.stringify(err)); + expect().assertFail(); + destroySessionTask(); + done(); + }); + if (descriptors.length >= 1) { + console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); + console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); + console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); + console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`); + console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); + expect(true).assertTrue(); + } else { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0100 get history session number : " + descriptors.length + ", error "); + expect().assertFail(); + } + destroySessionTask(); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200", 0, async function (done) { + await createSessionTask(); + let descriptors = await AVSessionManager.getHistoricalSessionDescriptors(10).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200 error " + JSON.stringify(err)); + expect().assertFail(); + destroySessionTask(); + done(); + }); + if (descriptors.length >= 1) { + expect(true).assertTrue(); + } else { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0200 get history session number : " + descriptors.length + ", error "); + expect().assertFail(); + } + destroySessionTask(); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300", 0, async function (done) { + await createSessionTask(); + let descriptors = await AVSessionManager.getHistoricalSessionDescriptors(0).catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300 error " + JSON.stringify(err)); + expect().assertFail(); + destroySessionTask(); + done(); + }); + if (descriptors.length == 0) { + expect(true).assertTrue(); + } else { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0300 get history session number : " + descriptors.length + ", error "); + expect().assertFail(); + } + destroySessionTask(); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400", 0, async function (done) { + let flag = false; + await createSessionTask(); + let descriptors = await AVSessionManager.getHistoricalSessionDescriptors("0").catch((err) => { + flag = true; + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400 param error " + JSON.stringify(err)); + expect(true).assertTrue(); + destroySessionTask(); + done(); + }); + if (flag || (!descriptors)) { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400 error input param has callback , pass"); + expect(true).assertTrue(); + destroySessionTask(); + done(); + } else { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0400 error input param should not return , error"); + expect().assertFail(); + destroySessionTask(); + done(); + } + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500", 0, async function (done) { + await createSessionTask(); + await AVSessionManager.getHistoricalSessionDescriptors((err, data) => { + if (err) { + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500 error " + JSON.stringify(err)); + expect().assertFail(); + destroySessionTask(); + done(); + } + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500 return :" + data); + if (data.length >= 1) { + expect(true).assertTrue(); + } else { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0500 get history session number : " + data.length + ", error "); + expect().assertFail(); + } + destroySessionTask(); + done(); + }); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600", 0, async function (done) { + await createSessionTask(); + destroySessionTask(); + let descriptors = await AVSessionManager.getHistoricalSessionDescriptors().catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600 error " + JSON.stringify(err)); + expect().assertFail(); + destroySessionTask(); + done(); + }); + if (descriptors.length >= 1) { + expect(true).assertTrue(); + } else { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0600 get history session number : " + descriptors.length + ", error "); + expect().assertFail(); + } + destroySessionTask(); + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700", 0, async function (done) { + let descriptors = await AVSessionManager.getHistoricalSessionDescriptors().catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700 error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + let size = descriptors.length; + await createSessionTask(); + destroySessionTask(); + let descriptorsRetry = await AVSessionManager.getHistoricalSessionDescriptors().catch((err) => { + console.error(TAG + "SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700 retry error " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + if (descriptorsRetry.length >= size) { + expect(true).assertTrue(); + } else { + console.error(TAG + " SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0700 get history session number : " + descriptors.length + ", error "); + expect().assertFail(); + } + done(); + }) + + /* + * @tc.name:SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800 + * @tc.desc:One on function - lyrics session event + * @tc.type: FUNC + * @tc.require: I6C6IN + */ + it("SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800", 0, async function (done) { + await createSessionTask(); + for (let i = 0; i < 100; i++) { + let descriptors = await AVSessionManager.getHistoricalSessionDescriptors().catch((err) => { + console.error(TAG + " loop : " + i + ", SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800 error " + JSON.stringify(err)); + expect().assertFail(); + destroySessionTask(); + done(); + }); + if (descriptors.length >= 1) { + expect(true).assertTrue(); + } else { + console.error(TAG + " loop : " + i + ", SUB_MULTIMEDIA_GETHISTORICAL_SESSIONDESCRIPTORS_0800 get history session number : " + descriptors.length + ", error "); + expect().assertFail(); + destroySessionTask(); + done(); + } + } + destroySessionTask(); + done(); + }) + }) +} \ No newline at end of file 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 index 835029238..b8fa2b583 100644 --- 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 @@ -17,6 +17,9 @@ import AVSessionManager from './AVSessionManager.test.js'; import AVSessionCallback from './AVSessionCallback.test.js'; import AVSessionManagerCallback from './AVSessionManagerCallback.test.js'; import AVSessionErrorCode from './AVSessionErrorCode.test'; +import AVSessionControllerJSTest from './AVSessionControllerJSTest.js'; +import AVSessionManagerJSTest from './AVSessionManagerJSTest.js'; +import AVSessionJSTest from './AVSessionJSTest.js'; export default function testsuite() { AVSession() @@ -24,4 +27,7 @@ export default function testsuite() { AVSessionCallback() AVSessionManagerCallback() AVSessionErrorCode() + AVSessionJSTest () + AVSessionManagerJSTest () + AVSessionControllerJSTest () } \ No newline at end of file -- GitLab