• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import rpc from "@ohos.rpc";
17import avSession from "@ohos.multimedia.avsession";
18import featureAbility from '@ohos.ability.featureAbility';
19import deviceManager from '@ohos.distributedDeviceManager';
20import process from "@ohos.process";
21import audio from "@ohos.multimedia.audio";
22import TestService from "./testService";
23import "./testService";
24import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Size, Level } from '@ohos/hypium';
25import { UiDriver, BY } from '@ohos.UiTest'
26
27export default function AVSessionManagerJsUnit() {
28    describe('AVSessionManagerJsUnit', function () {
29        console.info("----------AVSession_Manager_Distributed JS Test is starting----------");
30        const CODE_CAST_AUDIO = 1;
31        let tag = "Application";
32        let type = 'audio';
33        let context = featureAbility.getContext();
34        let session = null;
35        let controller = null;
36        let sessionId = "";
37        let pid = process.pid;
38        let uid = process.uid;
39        let sessionToken = null;
40        let audioDevices = [];
41        let remoteDeviceId = 0;
42        let metadata1 = {
43            assetId: "121278",
44            artist: "Eminem",
45        };
46        let gIRemoteObject = null;
47        let audioManager = null;
48        let localAudioDevice;
49        let testservice = null;
50        let localDeviceId = undefined;
51        let dvList = [];
52        let dvId = null;
53        let dmInstance;
54        let logTag = "DctsAvsession"
55
56
57        function sleep(time) {
58            return new Promise(resolve => setTimeout(resolve, time));
59        }
60
61        async function checkAvailableDevice() {
62            console.info(logTag + "checkAvailableDevice in ");
63            let dmInstance = deviceManager.createDeviceManager("com.acts.avsessionserver");
64            let deviceInfoList = dmInstance.getAvailableDeviceListSync();
65            console.info(logTag + "checkAvailableDevice get deviceInfoList " + JSON.stringify(deviceInfoList));
66            if (deviceInfoList.length != 0) {
67                return false;
68            } else{
69                return true;
70  }
71}
72
73        async function getPermission() {
74            console.info(`getPermission is start`);
75            let permissions = ['ohos.permission.DISTRIBUTED_DATASYNC'];
76            let context = featureAbility.getContext()
77            context.requestPermissionsFromUser(permissions, 666, (data) => {
78                console.info("request success" + JSON.stringify(data));
79            })
80        }
81
82        async function driveFn() {
83            try {
84                let driver = await UiDriver.create()
85                console.info(`come in driveFn`)
86                console.info(`driver is ${JSON.stringify(driver)}`)
87                await sleep(2000);
88                let button = await driver.findComponent(BY.text('允许'));
89                console.info(`button is ${JSON.stringify(button)}`);
90                await sleep(5000);
91                await button.click();
92            } catch (err) {
93                console.info('err is ' + err);
94                return;
95            }
96        }
97
98        beforeAll(async function (done) {
99            console.info('beforeAll called avsession server');
100            testservice = new TestService
101            await getPermission();
102            sleep(5000);
103            await driveFn();
104            await sleep(500);
105
106            //环境初始化
107            let checkResult = await checkAvailableDevice();
108            if (!checkResult) {
109                testservice.unbindStub();
110            }
111            await sleep(500);
112            let checkResult1 = await checkAvailableDevice();
113            //如果有可信的设备 就不需要再通过PIN码bind
114            if (checkResult1) {
115                testservice.startDiscovering();
116                await sleep(3000);
117                testservice.bindStub();
118                await sleep(20000);
119                testservice.stopDiscovering();
120                await sleep(3000);
121            }
122
123            try {
124                dmInstance = deviceManager.createDeviceManager("com.acts.avsessionserver");
125                if (dmInstance) {
126                    console.info("Client ceate device manager success");
127                    localDeviceId = dmInstance.getLocalDeviceId();
128                    console.info("local device id is: " + localDeviceId);
129                    let deviceList = dmInstance.getAvailableDeviceListSync();
130                    dvList = deviceList;
131                    let deviceId = deviceList[0].deviceId;
132                    dvId = deviceId;
133                    console.info("deviceid is: " + deviceId)
134                    console.info("deviceList is: " + JSON.stringify(deviceList))
135                }
136            } catch(err) {
137                console.info('err is ' + err);
138                return;
139            }
140
141            audioManager = audio.getAudioManager().getRoutingManager();
142
143            await audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
144                console.info('get localDevice successfully');
145                localAudioDevice = data;
146                localAudioDevice[0].name = 'name';
147                localAudioDevice[0].address = 'address';
148            }).catch((err) => {
149                console.info(`Get device BusinessError: ${err.code}, message: ${err.message}`);
150                expect(false).assertTrue();
151            });
152
153            sleep(1500);
154
155            await testservice.toConnectAbility().then(data => {
156                gIRemoteObject = data;
157                console.info("toConnectAbility data is:" + data);
158            })
159            done();
160            console.info('beforeAll done');
161        })
162
163        beforeEach(async function () {
164            await sleep(500);
165            await avSession.createAVSession(context, tag, type).then((data) => {
166                session = data;
167                sessionId = session.sessionId;
168                sessionToken = { sessionId, pid, uid };
169                console.info(sessionToken.pid);
170                console.info(sessionToken.uid);
171            }).catch((err) => {
172                console.info(`Session create BusinessError: ${err.code}, message: ${err.message}`);
173                expect(false).assertTrue();
174            });
175            await session.activate().then(() => {
176                console.info('Session activate');
177            }).catch((err) => {
178                console.info(`Session activate BusinessError: ${err.code}, message: ${err.message}`);
179                expect(false).assertTrue();
180            })
181            await session.setAVMetadata(metadata1).then(() => {
182                console.info('Set artist successfully');
183            }).catch((err) => {
184                console.info(`Set AVMetadata error, error code: ${err.code}, error message: ${err.message}`);
185                expect(false).assertTrue();
186            })
187            await sleep(500);
188            console.info('beforeEach called');
189        })
190
191        afterEach(async function () {
192            await sleep(500);
193            await session.destroy().catch((err) => {
194                console.info(`Destroy session error, error code:: ${err.code}, error message: ${err.message}`);
195                expect(false).assertTrue();
196            });
197            await sleep(500);
198            console.info('afterEach called');
199        })
200
201        afterAll(async function (done) {
202            console.info('afterAll called');
203            testservice = new TestService;
204            await sleep(1000);
205            // 删除当前应用的可信设备
206            let checkResult = await checkAvailableDevice();
207            if (!checkResult) {
208                testservice.unbindStub();
209            }
210            await sleep(1000);
211            done();
212            console.info("afterAll done");
213        })
214
215        /**
216         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0100
217         * @tc.name      : CAST_AUDIO_0100
218         * @tc.desc      : Testing cast audio with all session
219         * @tc.size      : MediumTest
220         * @tc.type      : Function
221         * @tc.level     : Level2
222         */
223        it("SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
224            if (Object.keys(audioDevices).length === 0) {
225                expect(true).assertTrue();
226                done();
227            } else {
228                avSession.castAudio('all', audioDevices, (err) => {
229                    if (err) {
230                        console.info(`Cast audio to remote device BusinessError: ${err.code}, message: ${err.message}`);
231                        expect(false).assertTrue();
232                    } else {
233                        console.info('Cast audio to remote device');
234                    }
235                });
236                await sleep(1500);
237                try {
238                    let data = rpc.MessageParcel.create();
239                    let reply = rpc.MessageParcel.create();
240                    let option = new rpc.MessageOption();
241
242                    if (gIRemoteObject === undefined) {
243                        console.info('gIRemoteObject undefined');
244                    }
245
246                    await gIRemoteObject.sendRequest(CODE_CAST_AUDIO, data, reply, option).then((result) => {
247                        console.info(`sendRequest success, result is ${result.errCode}`);
248                        let remoteResult = result.reply.readString();
249                        console.info(`Run readString success, remoteResult is ${remoteResult}`);
250                        expect(remoteResult === 'case 1 get successfully').assertTrue();
251                    }).catch((err) => {
252                        console.info(`sendRequest has failed BusinessError: ${err.code}, message: ${err.message}`);
253                        expect(false).assertTrue();
254                    }).finally(() => {
255                        data.reclaim();
256                        reply.reclaim();
257                    });
258                } catch (err) {
259                    console.info(`Testing has failed BusinessError: ${err.code}, message: ${err.message}`);
260                    expect(false).assertTrue();
261                }
262                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
263                    console.info('Cast audio to local device');
264                }).catch((err) => {
265                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
266                    expect(false).assertTrue();
267                })
268                await sleep(1000);
269                done();
270            }
271        })
272
273        /**
274         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0100
275         * @tc.name      : CAST_AUDIO_0100
276         * @tc.desc      : Testing cast audio
277         * @tc.size      : MediumTest
278         * @tc.type      : Function
279         * @tc.level     : Level2
280         */
281        it("SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
282            if (Object.keys(audioDevices).length === 0) {
283                expect(true).assertTrue();
284                done();
285            } else {
286                await avSession.castAudio('all', audioDevices).then(() => {
287                    console.info('Cast audio to remote');
288                }).catch((err) => {
289                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
290                    expect(false).assertTrue();
291                })
292
293                await sleep(1500);
294
295                try {
296                    let data = rpc.MessageParcel.create();
297                    let reply = rpc.MessageParcel.create();
298                    let option = new rpc.MessageOption();
299
300                    if (gIRemoteObject === undefined) {
301                        console.info('gIRemoteObject undefined');
302                    }
303
304                    await gIRemoteObject.sendRequest(CODE_CAST_AUDIO, data, reply, option).then((result) => {
305                        console.info(`sendRequest success, result is ${result.errCode}`);
306                        let remoteResult = result.reply.readString();
307                        console.info(`Run readString success, remoteResult is ${remoteResult}`);
308                        expect(remoteResult === 'case 1 get successfully').assertTrue();
309                    }).catch((err) => {
310                        console.info(`sendRequest has failed BusinessError: ${err.code}, message: ${err.message}`);
311                        expect(false).assertTrue();
312                    }).finally(() => {
313                        data.reclaim();
314                        reply.reclaim();
315                    });
316                } catch (err) {
317                    console.info(`Testing has failed BusinessError: ${err.code}, message: ${err.message}`);
318                    expect(false).assertTrue();
319                }
320
321                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
322                    console.info('Cast audio to local device');
323                }).catch((err) => {
324                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
325                    expect(false).assertTrue();
326                })
327                await sleep(1000);
328                done();
329            }
330        })
331
332        /**
333         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0200
334         * @tc.name      : CAST_AUDIO_0200
335         * @tc.desc      : Testing cast audio
336         * @tc.size      : MediumTest
337         * @tc.type      : Function
338         * @tc.level     : Level2
339         */
340        it("SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0200", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
341            if (Object.keys(audioDevices).length === 0) {
342                expect(true).assertTrue();
343                done();
344            } else {
345                avSession.castAudio(sessionToken, audioDevices, (err) => {
346                    if (err) {
347                        console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
348                        expect(false).assertTrue();
349                    } else {
350                        console.info('Cast audio to remote device');
351                    }
352                });
353                await sleep(1500);
354                try {
355                    let data = rpc.MessageParcel.create();
356                    let reply = rpc.MessageParcel.create();
357                    let option = new rpc.MessageOption();
358
359                    if (gIRemoteObject === undefined) {
360                        console.info('gIRemoteObject undefined');
361                    }
362
363                    await gIRemoteObject.sendRequest(CODE_CAST_AUDIO, data, reply, option).then((result) => {
364                        console.info(`sendRequest success, result is ${result.errCode}`);
365                        let remoteResult = result.reply.readString();
366                        console.info(`Run readString success, remoteResult is ${remoteResult}`);
367                        expect(remoteResult === 'case 1 get successfully').assertTrue();
368                    }).catch((err) => {
369                        console.info(`sendRequest has failed BusinessError: ${err.code}, message: ${err.message}`);
370                        expect(false).assertTrue();
371                    }).finally(() => {
372                        data.reclaim();
373                        reply.reclaim();
374                    });
375                } catch (err) {
376                    console.info(`Testing has failed BusinessError: ${err.code}, message: ${err.message}`);
377                    expect(false).assertTrue();
378                }
379                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
380                    console.info('Cast audio to local device');
381                }).catch((err) => {
382                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
383                    expect(false).assertTrue();
384                })
385                await sleep(1000);
386                done();
387            }
388        })
389
390        /**
391         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0200
392         * @tc.name      : CAST_AUDIO_0200
393         * @tc.desc      : Testing cast audio with all session
394         * @tc.size      : MediumTest
395         * @tc.type      : Function
396         * @tc.level     : Level2
397         */
398        it("SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0200", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
399            if (Object.keys(audioDevices).length === 0) {
400                expect(true).assertTrue();
401                done();
402            } else {
403                await avSession.castAudio(sessionToken, audioDevices).then(() => {
404                    console.info('Cast audio to remote');
405                }).catch((err) => {
406                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
407                    expect(false).assertTrue();
408                })
409
410                await sleep(1500);
411
412                try {
413                    let data = rpc.MessageParcel.create();
414                    let reply = rpc.MessageParcel.create();
415                    let option = new rpc.MessageOption();
416
417                    if (gIRemoteObject === undefined) {
418                        console.info('gIRemoteObject undefined');
419                    }
420
421                    await gIRemoteObject.sendRequest(CODE_CAST_AUDIO, data, reply, option).then((result) => {
422                        console.info(`sendRequest success, result is ${result.errCode}`);
423                        let remoteResult = result.reply.readString();
424                        console.info(`Run readString success, remoteResult is ${remoteResult}`);
425                        expect(remoteResult === 'case 1 get successfully').assertTrue();
426                    }).catch((err) => {
427                        console.info(`sendRequest has failed BusinessError: ${err.code}, message: ${err.message}`);
428                        expect(false).assertTrue();
429                    }).finally(() => {
430                        data.reclaim();
431                        reply.reclaim();
432                    });
433                } catch (err) {
434                    console.info(`Testing has failed BusinessError: ${err.code}, message: ${err.message}`);
435                    expect(false).assertTrue();
436                }
437
438                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
439                    console.info('Cast audio to local device');
440                }).catch((err) => {
441                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
442                    expect(false).assertTrue();
443                })
444                await sleep(1000);
445                done();
446            }
447        })
448
449        /**
450         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0300
451         * @tc.name      : CAST_AUDIO_0300
452         * @tc.desc      : Testing cast audio to local
453         * @tc.size      : MediumTest
454         * @tc.type      : Function
455         * @tc.level     : Level2
456         */
457        it("SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0300", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
458            if (Object.keys(audioDevices).length === 0) {
459                expect(true).assertTrue();
460                done();
461            } else {
462                await avSession.castAudio(sessionToken, audioDevices).then(() => {
463                    console.info('Cast audio to remote device');
464                }).catch((err) => {
465                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
466                    expect(false).assertTrue();
467                })
468
469                await sleep(1500);
470
471                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
472                    console.info('Cast audio to local device');
473                }).catch((err) => {
474                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
475                    expect(false).assertTrue();
476                });
477                await sleep(1500);
478                await session.getOutputDevice().then((data) => {
479                    if (!data.isRemote) {
480                        console.info('Get device information successfully');
481                        expect(true).assertTrue();
482                    } else {
483                        console.info('Get device information failed');
484                        expect(false).assertTrue();
485                    }
486                }).catch((err) => {
487                    console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`);
488                    expect(false).assertTrue();
489                });
490                done();
491            }
492        })
493
494        /**
495         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0300
496         * @tc.name      : CAST_AUDIO_0300
497         * @tc.desc      : Testing cast audio to local
498         * @tc.size      : MediumTest
499         * @tc.type      : Function
500         * @tc.level     : Level2
501         */
502        it("SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0300", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
503            if (Object.keys(audioDevices).length === 0) {
504                expect(true).assertTrue();
505                done();
506            } else {
507                avSession.castAudio(sessionToken, audioDevices, (err) => {
508                    if (err) {
509                        console.info(`Cast audio BusinessError: ${err.code}, message: ${err.message}`);
510                        expect(false).assertTrue();
511                    } else {
512                        console.info('Cast audio to remote device');
513                    }
514                });
515
516                await sleep(1500);
517
518                avSession.castAudio(sessionToken, localAudioDevice, (err) => {
519                    if (err) {
520                        console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
521                        expect(false).assertTrue();
522                    } else {
523                        console.info('Cast audio to local device');
524                    }
525                });
526
527                await sleep(1500);
528                await session.getOutputDevice().then((data) => {
529                    if (!data.isRemote) {
530                        console.info('Get device information successfully');
531                        expect(true).assertTrue();
532                    } else {
533                        console.info('Get device information failed');
534                        expect(false).assertTrue();
535                    }
536                }).catch((err) => {
537                    console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`);
538                    expect(false).assertTrue();
539                })
540                done();
541            }
542        })
543
544        /**
545         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_ONOUTPUTDEVICE_CHANGE_0100
546         * @tc.name      : ONOUTPUTDEVICE_CHANGE_0100
547         * @tc.desc      : Testing output device change callback
548         * @tc.size      : MediumTest
549         * @tc.type      : Function
550         * @tc.level     : Level2
551         */
552        it("SUB_MULTIMEDIA_AVSESSION_ONOUTPUTDEVICE_CHANGE_0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
553            if (Object.keys(audioDevices).length === 0) {
554                expect(true).assertTrue();
555                done();
556            } else {
557                session.on('outputDeviceChange', (callback) => {
558                    if (callback.isRemote) {
559                        console.info(callback.deviceId.size);
560                        console.info(callback.deviceName.size);
561                        console.info('outputDeviceChange callback registration successful');
562                        expect(true).assertTrue();
563                    } else {
564                        console.info('outputDeviceChange callback registration fail');
565                        expect(false).assertTrue();
566                    }
567                });
568
569                await sleep(1500);
570
571                await avSession.castAudio(sessionToken, audioDevices).then(() => {
572                    console.info('Cast audio to remote');
573                }).catch((err) => {
574                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
575                    expect(false).assertTrue();
576                })
577
578                await sleep(1500);
579                session.off('outputDeviceChange');
580
581                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
582                    console.info('Cast audio to local');
583                }).catch((err) => {
584                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
585                    expect(false).assertTrue();
586                })
587                done();
588            }
589        })
590
591        /**
592         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0100
593         * @tc.name      : OFFOUTPUTDEVICE_CHANGE_0100
594         * @tc.desc      : Testing output device change callback
595         * @tc.size      : MediumTest
596         * @tc.type      : Function
597         * @tc.level     : Level2
598         */
599        it("SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
600            if (Object.keys(audioDevices).length === 0) {
601                expect(true).assertTrue();
602                done();
603            } else {
604                let flag = true;
605                function callback1(callback) {
606                    if (callback.isRemote) {
607                        console.info('Outputdevicechanged callback registration successful');
608                        flag = false;
609                    }
610                }
611
612                function callback2(callback) {
613                    if (callback.isRemote) {
614                        console.info('Outputdevicechanged callback registration successful');
615                        flag = false;
616                    }
617                }
618
619                session.on('outputDeviceChange', callback1);
620
621                session.on('outputDeviceChange', callback2);
622
623                session.off('outputDeviceChange');
624
625                await avSession.castAudio(sessionToken, audioDevices).then(() => {
626                    console.info('Cast audio to remote');
627                }).catch((err) => {
628                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
629                    expect(false).assertTrue();
630                })
631
632                await sleep(1000);
633                if (flag) {
634                    console.info('Outputdevicechanged callback unRegistration successful');
635                    expect(true).assertTrue();
636                } else {
637                    console.info('Outputdevicechanged callback unRegistration failed');
638                    expect(false).assertTrue();
639                }
640                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
641                    console.info('Cast audio to local');
642                }).catch((err) => {
643                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
644                    expect(false).assertTrue();
645                })
646                done();
647            }
648        })
649
650        /**
651         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0200
652         * @tc.name      : OFFOUTPUTDEVICE_CHANGE_0200
653         * @tc.desc      : Testing output device change callback
654         * @tc.size      : MediumTest
655         * @tc.type      : Function
656         * @tc.level     : Level2
657         */
658        it("SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0200", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
659            if (Object.keys(audioDevices).length === 0) {
660                expect(true).assertTrue();
661                done();
662            } else {
663                let flag = false;
664                function callback1(callback) {
665                    if (callback.isRemote) {
666                        console.info('Outputdevicechanged callback registration successful');
667                        flag = true;
668                    }
669                }
670
671                function callback2(callback) {
672                    if (callback.isRemote) {
673                        console.info('Outputdevicechanged callback registration successful');
674                        flag = false;
675                    }
676                }
677
678                session.on('outputDeviceChange', callback1);
679
680                session.on('outputDeviceChange', callback2);
681
682                session.off('outputDeviceChange', callback2);
683
684                await avSession.castAudio(sessionToken, audioDevices).then(() => {
685                    console.info('Cast audio to remote');
686                }).catch((err) => {
687                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
688                    expect(false).assertTrue();
689                })
690
691                await sleep(1500);
692                if (flag) {
693                    console.info('Outputdevicechanged callback unRegistration successful');
694                    expect(true).assertTrue();
695                } else {
696                    console.info('Outputdevicechanged callback unRegistration failed');
697                    expect(false).assertTrue();
698                }
699                session.off('outputDeviceChange', callback1);
700                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
701                    console.info('Cast audio to local');
702                }).catch((err) => {
703                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
704                    expect(false).assertTrue();
705                })
706                done();
707            }
708        })
709
710        /**
711         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_ONOUTPUTDEVICE_CHANGE_0200
712         * @tc.name      : ONOUTPUTDEVICE_CHANGE_0200
713         * @tc.desc      : Testing output device change callback
714         * @tc.size      : MediumTest
715         * @tc.type      : Function
716         * @tc.level     : Level2
717         */
718        it("SUB_MULTIMEDIA_AVSESSION_ONOUTPUTDEVICE_CHANGE_0200", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
719            if (Object.keys(audioDevices).length === 0) {
720                expect(true).assertTrue();
721                done();
722            } else {
723                await avSession.createController(session.sessionId).then((data) => {
724                    console.info('Controller create successful');
725                    controller = data;
726                }).catch((err) => {
727                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
728                    expect(false).assertTrue();
729                })
730
731                controller.on('outputDeviceChange', (callback) => {
732                    if (callback.isRemote) {
733                        console.info('outputDeviceChange callback registration successful');
734                        expect(true).assertTrue();
735                    } else {
736                        console.info('outputDeviceChange callback registration fail');
737                        expect(false).assertTrue();
738                    }
739                });
740
741                await avSession.castAudio(sessionToken, audioDevices).then(() => {
742                    console.info('Cast audio to remote device');
743                }).catch((err) => {
744                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
745                    expect(false).assertTrue();
746                })
747
748                await sleep(1500);
749                controller.off('outputDeviceChange');
750
751                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
752                    console.info('Cast audio to local');
753                }).catch((err) => {
754                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
755                    expect(false).assertTrue();
756                })
757                await controller.destroy();
758                done();
759            }
760        })
761
762        /**
763         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0300
764         * @tc.name      : OFFOUTPUTDEVICE_CHANGE_0300
765         * @tc.desc      : Testing output device change callback
766         * @tc.size      : MediumTest
767         * @tc.type      : Function
768         * @tc.level     : Level2
769         */
770        it("SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0300", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
771            if (Object.keys(audioDevices).length === 0) {
772                expect(true).assertTrue();
773                done();
774            } else {
775                await avSession.createController(session.sessionId).then((data) => {
776                    console.info('Controller create successful');
777                    controller = data;
778                }).catch((err) => {
779                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
780                    expect(false).assertTrue();
781                });
782                let flag = true;
783                function callback1(callback) {
784                    if (callback.isRemote) {
785                        console.info('Outputdevicechanged callback registration successful');
786                        flag = false;
787                    }
788                }
789
790                function callback2(callback) {
791                    if (callback.isRemote) {
792                        console.info('Outputdevicechanged callback registration successful');
793                        flag = false;
794                    }
795                }
796
797                controller.on('outputDeviceChange', callback1);
798
799                controller.on('outputDeviceChange', callback2);
800
801                controller.off('outputDeviceChange');
802
803                await avSession.castAudio(sessionToken, audioDevices).then(() => {
804                    console.info('Cast audio to remote');
805                }).catch((err) => {
806                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
807                    expect(false).assertTrue();
808                })
809
810                await sleep(1000);
811                if (flag) {
812                    console.info('Outputdevicechanged callback unRegistration successful');
813                    expect(true).assertTrue();
814                } else {
815                    console.info('Outputdevicechanged callback unRegistration failed');
816                    expect(false).assertTrue();
817                }
818                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
819                    console.info('Cast audio to local');
820                }).catch((err) => {
821                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
822                    expect(false).assertTrue();
823                })
824                await controller.destroy();
825                done();
826            }
827        })
828
829        /**
830         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0400
831         * @tc.name      : OFFOUTPUTDEVICE_CHANGE_0400
832         * @tc.desc      : Testing output device change callback
833         * @tc.size      : MediumTest
834         * @tc.type      : Function
835         * @tc.level     : Level2
836         */
837        it("SUB_MULTIMEDIA_AVSESSION_OFFOUTPUTDEVICE_CHANGE_0400", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
838            if (Object.keys(audioDevices).length === 0) {
839                expect(true).assertTrue();
840                done();
841            } else {
842                await avSession.createController(session.sessionId).then((data) => {
843                    console.info('Controller create successful');
844                    controller = data;
845                }).catch((err) => {
846                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
847                    expect(false).assertTrue();
848                });
849                let flag = false;
850                function callback1(callback) {
851                    if (callback.isRemote) {
852                        console.info('Outputdevicechanged callback registration successful');
853                        flag = true;
854                    }
855                }
856
857                function callback2(callback) {
858                    if (callback.isRemote) {
859                        console.info('Outputdevicechanged callback registration successful');
860                        flag = false;
861                    }
862                }
863
864                controller.on('outputDeviceChange', callback1);
865
866                controller.on('outputDeviceChange', callback2);
867
868                controller.off('outputDeviceChange', callback2);
869
870                await avSession.castAudio(sessionToken, audioDevices).then(() => {
871                    console.info('Cast audio to remote');
872                }).catch((err) => {
873                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
874                    expect(false).assertTrue();
875                })
876
877                await sleep(1500);
878                if (flag) {
879                    console.info('Outputdevicechanged callback unRegistration successful');
880                    expect(true).assertTrue();
881                } else {
882                    console.info('Outputdevicechanged callback unRegistration failed');
883                    expect(false).assertTrue();
884                }
885                controller.off('outputDeviceChange', callback1);
886                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
887                    console.info('Cast audio to local');
888                }).catch((err) => {
889                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
890                    expect(false).assertTrue();
891                })
892                await controller.destroy();
893                done();
894            }
895        })
896
897        /**
898         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETCONTROLLER_PROMISE_0100
899         * @tc.name      : GETCONTROLLER_PROMISE_0100
900         * @tc.desc      : Testing get controller
901         * @tc.size      : MediumTest
902         * @tc.type      : Function
903         * @tc.level     : Level2
904         */
905        it("SUB_MULTIMEDIA_AVSESSION_GETCONTROLLER_PROMISE_0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
906            if (Object.keys(audioDevices).length === 0) {
907                expect(true).assertTrue();
908                done();
909            } else {
910                await avSession.createController(session.sessionId).then((data) => {
911                    console.info('Controller create successful');
912                    controller = data;
913                }).catch((err) => {
914                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
915                    expect(false).assertTrue();
916                });
917
918                await session.getController().then((data) => {
919                    if (controller.sessionId === data.sessionId) {
920                        console.info('Get controller successfully');
921                        expect(true).assertTrue();
922                    } else {
923                        console.info('Get controller failed');
924                        expect(false).assertTrue();
925                    }
926                }).catch((err) => {
927                    console.info(`Get controller BusinessError: ${err.code}, message: ${err.message}`);
928                    expect(false).assertTrue();
929                });
930                await controller.destroy();
931                done();
932            }
933        })
934
935        /**
936         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0100
937         * @tc.name      : GETOUTPUTDEVICE_PROMISE_0100
938         * @tc.desc      : Testing get output device
939         * @tc.size      : MediumTest
940         * @tc.type      : Function
941         * @tc.level     : Level2
942         */
943        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
944            if (Object.keys(audioDevices).length === 0) {
945                expect(true).assertTrue();
946                done();
947            } else {
948                await avSession.castAudio(sessionToken, audioDevices).then(() => {
949                    console.info('Cast audio to remote');
950                }).catch((err) => {
951                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
952                    expect(false).assertTrue();
953                })
954                await sleep(1500);
955                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
956                    console.info('Cast audio to local');
957                }).catch((err) => {
958                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
959                    expect(false).assertTrue();
960                })
961                await sleep(1500);
962                await session.getOutputDevice().then((data) => {
963                    if (!data.isRemote) {
964                        console.info('Get device information successfully');
965                        expect(true).assertTrue();
966                    } else {
967                        console.info('Get device information failed');
968                        expect(false).assertTrue();
969                    }
970                }).catch((err) => {
971                    console.info(`Get device BusinessError: ${err.code}, message: ${err.message}`);
972                    expect(false).assertTrue();
973                })
974                done();
975            }
976        })
977
978        /**
979         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0200
980         * @tc.name      : GETOUTPUTDEVICE_PROMISE_0200
981         * @tc.desc      : Testing get output device
982         * @tc.size      : MediumTest
983         * @tc.type      : Function
984         * @tc.level     : Level2
985         */
986        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0200", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
987            if (Object.keys(audioDevices).length === 0) {
988                expect(true).assertTrue();
989                done();
990            } else {
991                await avSession.castAudio(sessionToken, audioDevices).then(() => {
992                    console.info('Cast audio to remote');
993                }).catch((err) => {
994                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
995                    expect(false).assertTrue();
996                })
997                await sleep(1500);
998                await session.getOutputDevice().then((data) => {
999                    if (data.isRemote) {
1000                        console.info('Get device information successfully');
1001                        expect(true).assertTrue();
1002                    } else {
1003                        console.info('Get device information failed');
1004                        expect(false).assertTrue();
1005                    }
1006                }).catch((err) => {
1007                    console.info(`Get device BusinessError: ${err.code}, message: ${err.message}`);
1008                    expect(false).assertTrue();
1009                });
1010                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
1011                    console.info('Cast audio to local');
1012                }).catch((err) => {
1013                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
1014                    expect(false).assertTrue();
1015                })
1016                done();
1017            }
1018        })
1019
1020        /**
1021         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0300
1022         * @tc.name      : GETOUTPUTDEVICE_PROMISE_0300
1023         * @tc.desc      : Testing get output device
1024         * @tc.size      : MediumTest
1025         * @tc.type      : Function
1026         * @tc.level     : Level2
1027         */
1028        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0300", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
1029            if (Object.keys(audioDevices).length === 0) {
1030                expect(true).assertTrue();
1031                done();
1032            } else {
1033                await avSession.createController(session.sessionId).then((data) => {
1034                    console.info('Controller create successful');
1035                    controller = data;
1036                }).catch((err) => {
1037                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
1038                    expect(false).assertTrue();
1039                });
1040                await avSession.castAudio(sessionToken, audioDevices).then(() => {
1041                    console.info('Cast audio to remote');
1042                }).catch((err) => {
1043                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
1044                    expect(false).assertTrue();
1045                })
1046                await sleep(1500);
1047                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
1048                    console.info('Cast audio to local');
1049                }).catch((err) => {
1050                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
1051                    expect(false).assertTrue();
1052                });
1053                await sleep(1500);
1054                await session.getOutputDevice().then((data) => {
1055                    if (!data.isRemote) {
1056                        console.info('Get device information successfully');
1057                        expect(true).assertTrue();
1058                    } else {
1059                        console.info('Get device information failed');
1060                        expect(false).assertTrue();
1061                    }
1062                }).catch((err) => {
1063                    console.info(`Get device BusinessError: ${err.code}, message: ${err.message}`);
1064                    expect(false).assertTrue();
1065                });
1066                await controller.destroy();
1067                done();
1068            }
1069        })
1070
1071        /**
1072         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0400
1073         * @tc.name      : GETOUTPUTDEVICE_PROMISE_0400
1074         * @tc.desc      : Testing get output device
1075         * @tc.size      : MediumTest
1076         * @tc.type      : Function
1077         * @tc.level     : Level2
1078         */
1079        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0400", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
1080            if (Object.keys(audioDevices).length === 0) {
1081                expect(true).assertTrue();
1082                done();
1083            } else {
1084                await avSession.createController(session.sessionId).then((data) => {
1085                    console.info('Controller create successful');
1086                    controller = data;
1087                }).catch((err) => {
1088                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
1089                    expect(false).assertTrue();
1090                });
1091
1092                await avSession.castAudio(sessionToken, audioDevices).then(() => {
1093                    console.info('Cast audio to remote');
1094                }).catch((err) => {
1095                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
1096                    expect(false).assertTrue();
1097                });
1098
1099                await sleep(1500);
1100
1101                await session.getOutputDevice().then((data) => {
1102                    if (data.isRemote) {
1103                        console.info('Get device information successfully');
1104                        expect(true).assertTrue();
1105                    } else {
1106                        console.info('Get device information failed');
1107                        expect(false).assertTrue();
1108                    }
1109                }).catch((err) => {
1110                    console.info(`Get device BusinessError: ${err.code}, message: ${err.message}`);
1111                    expect(false).assertTrue();
1112                });
1113                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
1114                    console.info('Cast audio to local');
1115                }).catch((err) => {
1116                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
1117                    expect(false).assertTrue();
1118                });
1119                await controller.destroy();
1120                done();
1121            }
1122        })
1123
1124        /**
1125         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0100
1126         * @tc.name      : GETOUTPUTDEVICE_CALLBACK_0100
1127         * @tc.desc      : Testing get output device
1128         * @tc.size      : MediumTest
1129         * @tc.type      : Function
1130         * @tc.level     : Level2
1131         */
1132        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0100", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
1133            if (Object.keys(audioDevices).length === 0) {
1134                expect(true).assertTrue();
1135                done();
1136            } else {
1137                session.getOutputDevice((err, value) => {
1138                    if (err) {
1139                        console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`);
1140                        expect(false).assertTrue();
1141                    } else if (!value.isRemote) {
1142                        console.info('Get device information successfully');
1143                        expect(true).assertTrue();
1144                    } else {
1145                        console.info('Get device information failed');
1146                        expect(false).assertTrue();
1147                    }
1148                });
1149                await sleep(2000);
1150                done();
1151            }
1152        })
1153
1154        /**
1155         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0200
1156         * @tc.name      : GETOUTPUTDEVICE_CALLBACK_0200
1157         * @tc.desc      : Testing get output device
1158         * @tc.size      : MediumTest
1159         * @tc.type      : Function
1160         * @tc.level     : Level2
1161         */
1162        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0200", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
1163            if (Object.keys(audioDevices).length === 0) {
1164                expect(true).assertTrue();
1165                done();
1166            } else {
1167                await avSession.castAudio(sessionToken, audioDevices).then(() => {
1168                    console.info('Cast audio to remote');
1169                }).catch((err) => {
1170                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
1171                    expect(false).assertTrue();
1172                });
1173                await sleep(1500);
1174                session.getOutputDevice((err, value) => {
1175                    if (err) {
1176                        console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`);
1177                        expect(false).assertTrue();
1178                    } else if (value.isRemote) {
1179                        console.info('Get device information successfully');
1180                        expect(true).assertTrue();
1181                    } else {
1182                        console.info('Get device information failed');
1183                        expect(false).assertTrue();
1184                    }
1185                });
1186                await sleep(1500);
1187                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
1188                    console.info('Cast audio to local');
1189                }).catch((err) => {
1190                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
1191                    expect(false).assertTrue();
1192                });
1193                done();
1194            }
1195        })
1196
1197        /**
1198         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0300
1199         * @tc.name      : GETOUTPUTDEVICE_CALLBACK_0300
1200         * @tc.desc      : Testing get output device
1201         * @tc.size      : MediumTest
1202         * @tc.type      : Function
1203         * @tc.level     : Level2
1204         */
1205        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0300", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
1206            if (Object.keys(audioDevices).length === 0) {
1207                expect(true).assertTrue();
1208                done();
1209            } else {
1210                await avSession.createController(session.sessionId).then((data) => {
1211                    console.info('Controller create successful');
1212                    controller = data;
1213                }).catch((err) => {
1214                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
1215                    expect(false).assertTrue();
1216                });
1217                await avSession.castAudio(sessionToken, audioDevices).then(() => {
1218                    console.info('Cast audio to remote');
1219                }).catch((err) => {
1220                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
1221                    expect(false).assertTrue();
1222                });
1223                await sleep(500);
1224                await avSession.castAudio(sessionToken, localAudioDevice).then(() => {
1225                    console.info('Cast audio to local');
1226                }).catch((err) => {
1227                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
1228                    expect(false).assertTrue();
1229                });
1230                await sleep(500);
1231                controller.getOutputDevice((err, value) => {
1232                    if (err) {
1233                        console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`);
1234                        expect(false).assertTrue();
1235                    } else if (!value.isRemote) {
1236                        console.info('Get device information successfully');
1237                        expect(true).assertTrue();
1238                    } else {
1239                        console.info('Get device information failed');
1240                        expect(false).assertTrue();
1241                    }
1242                });
1243                await sleep(1500);
1244                controller.destroy();
1245                done();
1246            }
1247        })
1248
1249        /**
1250         * @tc.number    : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0400
1251         * @tc.name      : GETOUTPUTDEVICE_CALLBACK_0400
1252         * @tc.desc      : Testing get output device
1253         * @tc.size      : MediumTest
1254         * @tc.type      : Function
1255         * @tc.level     : Level2
1256         */
1257        it("SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0400", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
1258            if (Object.keys(audioDevices).length === 0) {
1259                expect(true).assertTrue();
1260                done();
1261            } else {
1262                await avSession.createController(session.sessionId).then((data) => {
1263                    console.info('Controller create success');
1264                    controller = data;
1265                }).catch((err) => {
1266                    console.info(`Controller create BusinessError: ${err.code}, message: ${err.message}`);
1267                    expect(false).assertTrue();
1268                });
1269                await avSession.castAudio(sessionToken, audioDevices).then(() => {
1270                    console.info('Cast audio to remote');
1271                }).catch((err) => {
1272                    console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`);
1273                    expect(false).assertTrue();
1274                });
1275                await sleep(500);
1276                controller.getOutputDevice((err, value) => {
1277                    if (err) {
1278                        console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`);
1279                        expect(false).assertTrue();
1280                    } else if (value.isRemote) {
1281                        console.info('Get device information successfully');
1282                        expect(true).assertTrue();
1283                    } else {
1284                        console.info('Get device information failed');
1285                        expect(false).assertTrue();
1286                    }
1287                });
1288                await sleep(1500);
1289                await avSession.castAudio(sessionToken, audioDevices).then(() => {
1290                    console.info('Cast audio to local');
1291                }).catch((err) => {
1292                    console.info(`Cast audio to local BusinessError: ${err.code}, message: ${err.message}`);
1293                    expect(false).assertTrue();
1294                });
1295                controller.destroy();
1296                done();
1297            }
1298        })
1299
1300        console.info("----------SUB_Multimedia_AV_Session_Distributed JS Test is end----------");
1301    });
1302}