2016-08-04 17:49:32 +02:00
/* eslint-env qunit */
2021-11-17 22:59:01 +02:00
import EventTarget from '../../src/js/event-target.js' ;
2015-04-14 22:08:32 +02:00
import VolumeControl from '../../src/js/control-bar/volume-control/volume-control.js' ;
2015-03-26 06:43:41 +02:00
import MuteToggle from '../../src/js/control-bar/mute-toggle.js' ;
2017-02-21 22:53:56 +02:00
import VolumeBar from '../../src/js/control-bar/volume-control/volume-bar.js' ;
2018-11-02 22:47:52 +02:00
import PlayToggle from '../../src/js/control-bar/play-toggle.js' ;
2015-04-14 22:08:32 +02:00
import PlaybackRateMenuButton from '../../src/js/control-bar/playback-rate-menu/playback-rate-menu-button.js' ;
import Slider from '../../src/js/slider/slider.js' ;
2019-06-18 22:42:02 +02:00
import PictureInPictureToggle from '../../src/js/control-bar/picture-in-picture-toggle.js' ;
2016-08-15 23:44:01 +02:00
import FullscreenToggle from '../../src/js/control-bar/fullscreen-toggle.js' ;
2018-12-11 21:23:13 +02:00
import ControlBar from '../../src/js/control-bar/control-bar.js' ;
2021-11-17 22:59:01 +02:00
import SeekBar from '../../src/js/control-bar/progress-control/seek-bar.js' ;
2021-12-20 22:37:33 +02:00
import RemainingTimeDisplay from '../../src/js/control-bar/time-controls/remaining-time-display.js' ;
2015-03-26 06:43:41 +02:00
import TestHelpers from './test-helpers.js' ;
import document from 'global/document' ;
2023-04-04 22:44:16 +02:00
import window from 'global/window' ;
2017-02-21 22:53:56 +02:00
import sinon from 'sinon' ;
QUnit . module ( 'Controls' , {
beforeEach ( assert ) {
this . clock = sinon . useFakeTimers ( ) ;
} ,
afterEach ( assert ) {
this . clock . restore ( ) ;
}
} ) ;
2013-03-02 01:11:20 +03:00
2018-06-21 20:33:09 +02:00
QUnit . test ( 'should hide volume and mute toggle control if it\'s not supported' , function ( assert ) {
2016-08-12 19:51:31 +02:00
assert . expect ( 2 ) ;
2017-01-27 03:53:53 +02:00
const player = TestHelpers . makePlayer ( ) ;
player . tech _ . featuresVolumeControl = false ;
2018-06-21 20:33:09 +02:00
player . tech _ . featuresMuteControl = false ;
2013-04-09 23:18:55 +03:00
2016-08-04 17:49:32 +02:00
const volumeControl = new VolumeControl ( player ) ;
const muteToggle = new MuteToggle ( player ) ;
2013-03-02 01:11:20 +03:00
2017-01-27 03:53:53 +02:00
assert . ok ( volumeControl . hasClass ( 'vjs-hidden' ) , 'volumeControl is not hidden' ) ;
assert . ok ( muteToggle . hasClass ( 'vjs-hidden' ) , 'muteToggle is not hidden' ) ;
2018-01-30 20:26:21 +02:00
2017-01-27 03:53:53 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
volumeControl . dispose ( ) ;
muteToggle . dispose ( ) ;
2013-03-02 01:11:20 +03:00
} ) ;
2018-11-02 22:47:52 +02:00
QUnit . test ( 'should show replay icon when video playback ended' , function ( assert ) {
assert . expect ( 1 ) ;
const player = TestHelpers . makePlayer ( ) ;
const playToggle = new PlayToggle ( player ) ;
player . trigger ( 'ended' ) ;
assert . ok ( playToggle . hasClass ( 'vjs-ended' ) , 'playToogle is in the ended state' ) ;
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
playToggle . dispose ( ) ;
2018-11-02 22:47:52 +02:00
} ) ;
QUnit . test ( 'should show replay icon when video playback ended and replay option is set to true' , function ( assert ) {
assert . expect ( 1 ) ;
const player = TestHelpers . makePlayer ( ) ;
const playToggle = new PlayToggle ( player , { replay : true } ) ;
player . trigger ( 'ended' ) ;
assert . ok ( playToggle . hasClass ( 'vjs-ended' ) , 'playToogle is in the ended state' ) ;
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
playToggle . dispose ( ) ;
2018-11-02 22:47:52 +02:00
} ) ;
QUnit . test ( 'should not show the replay icon when video playback ended' , function ( assert ) {
assert . expect ( 1 ) ;
const player = TestHelpers . makePlayer ( ) ;
const playToggle = new PlayToggle ( player , { replay : false } ) ;
player . trigger ( 'ended' ) ;
assert . equal ( playToggle . hasClass ( 'vjs-ended' ) , false , 'playToogle is not in the ended state' ) ;
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
playToggle . dispose ( ) ;
2018-11-02 22:47:52 +02:00
} ) ;
2016-08-12 19:51:31 +02:00
QUnit . test ( 'should test and toggle volume control on `loadstart`' , function ( assert ) {
2017-01-27 03:53:53 +02:00
const player = TestHelpers . makePlayer ( ) ;
player . tech _ . featuresVolumeControl = true ;
2018-06-21 20:33:09 +02:00
player . tech _ . featuresMuteControl = true ;
2013-04-09 23:18:55 +03:00
2016-08-04 17:49:32 +02:00
const volumeControl = new VolumeControl ( player ) ;
const muteToggle = new MuteToggle ( player ) ;
2013-03-02 01:11:20 +03:00
2016-08-12 19:51:31 +02:00
assert . equal ( volumeControl . hasClass ( 'vjs-hidden' ) , false , 'volumeControl is hidden initially' ) ;
assert . equal ( muteToggle . hasClass ( 'vjs-hidden' ) , false , 'muteToggle is hidden initially' ) ;
2013-03-02 01:11:20 +03:00
2016-08-04 17:49:32 +02:00
player . tech _ . featuresVolumeControl = false ;
2018-06-21 20:33:09 +02:00
player . tech _ . featuresMuteControl = false ;
2017-01-27 03:53:53 +02:00
player . trigger ( 'loadstart' ) ;
2013-03-02 01:11:20 +03:00
2016-08-12 19:51:31 +02:00
assert . equal ( volumeControl . hasClass ( 'vjs-hidden' ) , true , 'volumeControl does not hide itself' ) ;
assert . equal ( muteToggle . hasClass ( 'vjs-hidden' ) , true , 'muteToggle does not hide itself' ) ;
2013-03-02 01:11:20 +03:00
2016-08-04 17:49:32 +02:00
player . tech _ . featuresVolumeControl = true ;
2018-06-21 20:33:09 +02:00
player . tech _ . featuresMuteControl = true ;
2017-01-27 03:53:53 +02:00
player . trigger ( 'loadstart' ) ;
2013-03-02 01:11:20 +03:00
2016-08-12 19:51:31 +02:00
assert . equal ( volumeControl . hasClass ( 'vjs-hidden' ) , false , 'volumeControl does not show itself' ) ;
assert . equal ( muteToggle . hasClass ( 'vjs-hidden' ) , false , 'muteToggle does not show itself' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
volumeControl . dispose ( ) ;
muteToggle . dispose ( ) ;
2013-03-02 01:11:20 +03:00
} ) ;
2013-04-22 20:57:42 +03:00
2016-08-12 19:51:31 +02:00
QUnit . test ( 'calculateDistance should use changedTouches, if available' , function ( assert ) {
2017-01-27 03:53:53 +02:00
const player = TestHelpers . makePlayer ( ) ;
player . tech _ . featuresVolumeControl = true ;
2016-08-04 17:49:32 +02:00
const slider = new Slider ( player ) ;
2013-04-22 20:57:42 +03:00
document . body . appendChild ( slider . el _ ) ;
slider . el _ . style . position = 'absolute' ;
slider . el _ . style . width = '200px' ;
slider . el _ . style . left = '0px' ;
2016-08-04 17:49:32 +02:00
const event = {
2013-04-22 20:57:42 +03:00
pageX : 10 ,
changedTouches : [ {
pageX : 100
} ]
} ;
2016-08-12 19:51:31 +02:00
assert . equal ( slider . calculateDistance ( event ) , 0.5 , 'we should have touched exactly in the center, so, the ratio should be half' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
slider . dispose ( ) ;
2013-04-22 20:57:42 +03:00
} ) ;
2014-05-14 00:02:02 +03:00
2021-11-17 22:59:01 +02:00
QUnit . test ( "SeekBar doesn't set scrubbing on mouse down, only on mouse move" , function ( assert ) {
const player = TestHelpers . makePlayer ( ) ;
const scrubbingSpy = sinon . spy ( player , 'scrubbing' ) ;
const seekBar = new SeekBar ( player ) ;
const doc = new EventTarget ( ) ;
2023-05-31 16:30:13 +02:00
player . duration ( 0 ) ;
2021-11-17 22:59:01 +02:00
// mousemove is listened to on the document.
// Specifically, we check the ownerDocument of the seekBar's bar.
// Therefore, we want to mock it out to be able to trigger mousemove
seekBar . bar . dispose ( ) ;
seekBar . bar . el _ = new EventTarget ( ) ;
seekBar . bar . el _ . ownerDocument = doc ;
seekBar . trigger ( 'mousedown' ) ;
assert . ok ( scrubbingSpy . calledWith ( ) , 'called scrubbing as a getter' ) ;
assert . notOk ( scrubbingSpy . calledWith ( true ) , 'did not set scrubbing true' ) ;
player . scrubbing ( false ) ;
scrubbingSpy . resetHistory ( ) ;
doc . trigger ( 'mousemove' ) ;
assert . ok ( scrubbingSpy . calledWith ( ) , 'called scrubbing as a getter' ) ;
assert . ok ( scrubbingSpy . calledWith ( true ) , 'did set scrubbing true' ) ;
seekBar . dispose ( ) ;
player . dispose ( ) ;
} ) ;
2021-06-08 17:01:56 +02:00
QUnit . test ( 'playback rate button is hidden by default' , function ( assert ) {
2016-08-12 19:51:31 +02:00
assert . expect ( 1 ) ;
2014-05-14 00:02:02 +03:00
2016-08-04 17:49:32 +02:00
const player = TestHelpers . makePlayer ( ) ;
const playbackRate = new PlaybackRateMenuButton ( player ) ;
2014-05-14 00:02:02 +03:00
2021-06-08 17:01:56 +02:00
assert . ok ( playbackRate . el ( ) . className . indexOf ( 'vjs-hidden' ) >= 0 , 'playbackRate is hidden' ) ;
player . dispose ( ) ;
playbackRate . dispose ( ) ;
} ) ;
QUnit . test ( 'playback rate button is not hidden if playback rates are set' , function ( assert ) {
assert . expect ( 1 ) ;
const player = TestHelpers . makePlayer ( {
playbackRates : [ 1 , 2 , 3 ]
} ) ;
const playbackRate = new PlaybackRateMenuButton ( player ) ;
assert . ok ( playbackRate . el ( ) . className . indexOf ( 'vjs-hidden' ) === - 1 , 'playbackRate is not hidden' ) ;
player . dispose ( ) ;
playbackRate . dispose ( ) ;
} ) ;
QUnit . test ( 'should show or hide playback rate menu button on playback rates change' , function ( assert ) {
const rates = [ 1 , 2 , 3 ] ;
const norates = [ ] ;
let playbackRatesReturnValue = rates ;
const player = TestHelpers . makePlayer ( ) ;
player . playbackRates = ( ) => playbackRatesReturnValue ;
const playbackRate = new PlaybackRateMenuButton ( player ) ;
assert . ok ( playbackRate . el ( ) . className . indexOf ( 'vjs-hidden' ) === - 1 , 'playbackRate is not hidden' ) ;
playbackRatesReturnValue = norates ;
player . trigger ( 'playbackrateschange' ) ;
assert . ok ( playbackRate . el ( ) . className . indexOf ( 'vjs-hidden' ) >= 0 , 'playbackRate is hidden' ) ;
2018-01-30 20:26:21 +02:00
2016-08-25 16:58:42 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
playbackRate . dispose ( ) ;
2014-05-14 00:02:02 +03:00
} ) ;
2016-08-15 23:44:01 +02:00
2019-06-20 21:11:21 +02:00
QUnit . test ( 'Picture-in-Picture control text should be correct when enterpictureinpicture and leavepictureinpicture are triggered' , function ( assert ) {
2019-06-18 22:42:02 +02:00
const player = TestHelpers . makePlayer ( ) ;
const pictureInPictureToggle = new PictureInPictureToggle ( player ) ;
player . isInPictureInPicture ( true ) ;
2019-06-20 21:11:21 +02:00
player . trigger ( 'enterpictureinpicture' ) ;
2019-06-18 22:42:02 +02:00
assert . equal ( pictureInPictureToggle . controlText ( ) , 'Exit Picture-in-Picture' , 'Control Text is correct while switching to Picture-in-Picture mode' ) ;
player . isInPictureInPicture ( false ) ;
2019-06-20 21:11:21 +02:00
player . trigger ( 'leavepictureinpicture' ) ;
2019-06-18 22:42:02 +02:00
assert . equal ( pictureInPictureToggle . controlText ( ) , 'Picture-in-Picture' , 'Control Text is correct while switching back to normal mode' ) ;
player . dispose ( ) ;
pictureInPictureToggle . dispose ( ) ;
} ) ;
2020-04-22 18:41:21 +02:00
QUnit . test ( 'Picture-in-Picture control enabled property value should be correct when enterpictureinpicture and leavepictureinpicture are triggered' , function ( assert ) {
const player = TestHelpers . makePlayer ( ) ;
const pictureInPictureToggle = new PictureInPictureToggle ( player ) ;
assert . equal ( pictureInPictureToggle . enabled _ , false , 'pictureInPictureToggle button should be disabled after creation' ) ;
2020-06-19 20:36:43 +02:00
if ( 'pictureInPictureEnabled' in document && player . disablePictureInPicture ( ) === false ) {
2020-04-22 18:41:21 +02:00
player . isInPictureInPicture ( true ) ;
player . trigger ( 'enterpictureinpicture' ) ;
assert . equal ( pictureInPictureToggle . enabled _ , true , 'pictureInPictureToggle button should be enabled after triggering an enterpictureinpicture event' ) ;
player . isInPictureInPicture ( false ) ;
player . trigger ( 'leavepictureinpicture' ) ;
assert . equal ( pictureInPictureToggle . enabled _ , true , 'pictureInPictureToggle button should be enabled after triggering an leavepictureinpicture event' ) ;
} else {
player . isInPictureInPicture ( true ) ;
player . trigger ( 'enterpictureinpicture' ) ;
assert . equal ( pictureInPictureToggle . enabled _ , false , 'pictureInPictureToggle button should be disabled after triggering an enterpictureinpicture event' ) ;
player . isInPictureInPicture ( false ) ;
player . trigger ( 'leavepictureinpicture' ) ;
assert . equal ( pictureInPictureToggle . enabled _ , false , 'pictureInPictureToggle button should be disabled after triggering an leavepictureinpicture event' ) ;
}
player . dispose ( ) ;
pictureInPictureToggle . dispose ( ) ;
} ) ;
QUnit . test ( 'Picture-in-Picture control enabled property value should be correct when loadedmetadata is triggered' , function ( assert ) {
const player = TestHelpers . makePlayer ( ) ;
const pictureInPictureToggle = new PictureInPictureToggle ( player ) ;
assert . equal ( pictureInPictureToggle . enabled _ , false , 'pictureInPictureToggle button should be disabled after creation' ) ;
2020-06-19 20:36:43 +02:00
if ( 'pictureInPictureEnabled' in document && player . disablePictureInPicture ( ) === false ) {
2020-04-22 18:41:21 +02:00
player . trigger ( 'loadedmetadata' ) ;
assert . equal ( pictureInPictureToggle . enabled _ , true , 'pictureInPictureToggle button should be enabled after triggering an loadedmetadata event' ) ;
} else {
player . trigger ( 'loadedmetadata' ) ;
assert . equal ( pictureInPictureToggle . enabled _ , false , 'pictureInPictureToggle button should be disabled after triggering an loadedmetadata event' ) ;
}
player . dispose ( ) ;
pictureInPictureToggle . dispose ( ) ;
} ) ;
2022-03-17 23:10:33 +02:00
QUnit . test ( 'Picture-in-Picture control is hidden when the source is audio' , function ( assert ) {
const player = TestHelpers . makePlayer ( { } ) ;
const pictureInPictureToggle = new PictureInPictureToggle ( player ) ;
player . src ( { src : 'example.mp4' , type : 'video/mp4' } ) ;
player . trigger ( 'loadedmetadata' ) ;
assert . notOk ( pictureInPictureToggle . hasClass ( 'vjs-hidden' ) , 'pictureInPictureToggle button is not hidden initially' ) ;
player . src ( { src : 'example1.mp3' , type : 'audio/mp3' } ) ;
player . trigger ( 'loadedmetadata' ) ;
assert . ok ( pictureInPictureToggle . hasClass ( 'vjs-hidden' ) , 'pictureInPictureToggle button is hidden whenh the source is audio' ) ;
player . dispose ( ) ;
pictureInPictureToggle . dispose ( ) ;
} ) ;
2023-04-04 22:44:16 +02:00
QUnit . test ( 'Picture-in-Picture control is displayed if docPiP is enabled' , function ( assert ) {
const player = TestHelpers . makePlayer ( {
disablePictureInPicture : true ,
enableDocumentPictureInPicture : true
} ) ;
const pictureInPictureToggle = new PictureInPictureToggle ( player ) ;
const testPiPObj = { } ;
if ( ! window . documentPictureInPicture ) {
window . documentPictureInPicture = testPiPObj ;
}
player . src ( { src : 'example.mp4' , type : 'video/mp4' } ) ;
player . trigger ( 'loadedmetadata' ) ;
assert . notOk ( pictureInPictureToggle . hasClass ( 'vjs-hidden' ) , 'pictureInPictureToggle button is not hidden' ) ;
player . dispose ( ) ;
pictureInPictureToggle . dispose ( ) ;
if ( window . documentPictureInPicture === testPiPObj ) {
delete window . documentPictureInPicture ;
}
} ) ;
2017-11-17 01:12:09 +02:00
QUnit . test ( 'Fullscreen control text should be correct when fullscreenchange is triggered' , function ( assert ) {
2020-01-31 22:59:12 +02:00
const player = TestHelpers . makePlayer ( { controlBar : false } ) ;
2016-08-15 23:44:01 +02:00
const fullscreentoggle = new FullscreenToggle ( player ) ;
2016-08-16 00:20:47 +02:00
2020-01-31 22:59:12 +02:00
// make the fullscreenchange handler doesn't trigger
player . off ( player . fsApi _ . fullscreenchange , player . boundDocumentFullscreenChange _ ) ;
2016-08-15 23:44:01 +02:00
player . isFullscreen ( true ) ;
player . trigger ( 'fullscreenchange' ) ;
2022-07-27 19:27:38 +02:00
assert . equal ( fullscreentoggle . controlText ( ) , 'Exit Fullscreen' , 'Control Text is correct while switching to fullscreen mode' ) ;
2018-01-30 20:26:21 +02:00
2016-08-15 23:44:01 +02:00
player . isFullscreen ( false ) ;
player . trigger ( 'fullscreenchange' ) ;
2017-11-17 01:12:09 +02:00
assert . equal ( fullscreentoggle . controlText ( ) , 'Fullscreen' , 'Control Text is correct while switching back to normal mode' ) ;
2018-01-30 20:26:21 +02:00
2016-08-25 16:58:42 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
fullscreentoggle . dispose ( ) ;
2016-08-16 00:20:47 +02:00
} ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
QUnit . test ( 'Clicking MuteToggle when volume is above 0 should toggle muted property and not change volume' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
assert . equal ( player . volume ( ) , 1 , 'volume is above 0' ) ;
assert . equal ( player . muted ( ) , false , 'player is not muted' ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
muteToggle . handleClick ( ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
assert . equal ( player . volume ( ) , 1 , 'volume is same' ) ;
assert . equal ( player . muted ( ) , true , 'player is muted' ) ;
2018-01-30 20:26:21 +02:00
2018-03-23 19:25:12 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
muteToggle . dispose ( ) ;
2018-03-23 19:25:12 +02:00
} ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
QUnit . test ( 'Clicking MuteToggle when volume is 0 and muted is false should set volume to lastVolume and keep muted false' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
player . volume ( 0 ) ;
assert . equal ( player . lastVolume _ ( ) , 1 , 'lastVolume is set' ) ;
assert . equal ( player . muted ( ) , false , 'player is muted' ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
muteToggle . handleClick ( ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
assert . equal ( player . volume ( ) , 1 , 'volume is set to lastVolume' ) ;
assert . equal ( player . muted ( ) , false , 'muted remains false' ) ;
2018-01-30 20:26:21 +02:00
2018-03-23 19:25:12 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
muteToggle . dispose ( ) ;
2018-03-23 19:25:12 +02:00
} ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
QUnit . test ( 'Clicking MuteToggle when volume is 0 and muted is true should set volume to lastVolume and sets muted to false' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
player . volume ( 0 ) ;
player . muted ( true ) ;
player . lastVolume _ ( 0.5 ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
muteToggle . handleClick ( ) ;
2017-01-31 22:29:07 +02:00
2018-03-23 19:25:12 +02:00
assert . equal ( player . volume ( ) , 0.5 , 'volume is set to lastVolume' ) ;
assert . equal ( player . muted ( ) , false , 'muted is set to false' ) ;
2018-01-30 20:26:21 +02:00
2018-03-23 19:25:12 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
muteToggle . dispose ( ) ;
2018-03-23 19:25:12 +02:00
} ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
QUnit . test ( 'Clicking MuteToggle when volume is 0, lastVolume is less than 0.1, and muted is true sets volume to 0.1 and muted to false' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-03-24 21:14:41 +02:00
2018-03-23 19:25:12 +02:00
player . volume ( 0 ) ;
player . muted ( true ) ;
player . lastVolume _ ( 0.05 ) ;
2017-03-24 21:14:41 +02:00
2018-03-23 19:25:12 +02:00
muteToggle . handleClick ( ) ;
2017-03-24 21:14:41 +02:00
2018-03-23 19:25:12 +02:00
// `Number.prototype.toFixed()` is used here to circumvent rounding issues
assert . equal ( player . volume ( ) . toFixed ( 1 ) , ( 0.1 ) . toFixed ( 1 ) , 'since lastVolume is less than 0.1, volume is set to 0.1' ) ;
assert . equal ( player . muted ( ) , false , 'muted is set to false' ) ;
2018-01-30 20:26:21 +02:00
2018-03-23 19:25:12 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
muteToggle . dispose ( ) ;
2018-03-23 19:25:12 +02:00
} ) ;
2017-03-24 21:14:41 +02:00
2018-03-23 19:25:12 +02:00
QUnit . test ( 'ARIA value of VolumeBar should start at 100' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const volumeBar = new VolumeBar ( player ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
this . clock . tick ( 1 ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
assert . equal ( volumeBar . el _ . getAttribute ( 'aria-valuenow' ) , 100 , 'ARIA value of VolumeBar is 100' ) ;
2018-01-30 20:26:21 +02:00
2018-03-23 19:25:12 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
volumeBar . dispose ( ) ;
2018-03-23 19:25:12 +02:00
} ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
QUnit . test ( 'Muting with MuteToggle should set ARIA value of VolumeBar to 0' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const volumeBar = new VolumeBar ( player ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
this . clock . tick ( 1 ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
assert . equal ( player . volume ( ) , 1 , 'Volume is 1' ) ;
assert . equal ( player . muted ( ) , false , 'Muted is false' ) ;
assert . equal ( volumeBar . el _ . getAttribute ( 'aria-valuenow' ) , 100 , 'ARIA value of VolumeBar is 100' ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
muteToggle . handleClick ( ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
// Because `volumechange` is triggered asynchronously, it doesn't end up
// getting fired on `player` in the test environment, so we run it
// manually.
player . trigger ( 'volumechange' ) ;
2017-02-21 22:53:56 +02:00
2018-03-23 19:25:12 +02:00
assert . equal ( player . volume ( ) , 1 , 'Volume remains 1' ) ;
assert . equal ( player . muted ( ) , true , 'Muted is true' ) ;
assert . equal ( volumeBar . el _ . getAttribute ( 'aria-valuenow' ) , 0 , 'ARIA value of VolumeBar is 0' ) ;
2018-01-30 20:26:21 +02:00
2018-03-23 19:25:12 +02:00
player . dispose ( ) ;
2019-03-18 21:49:48 +02:00
muteToggle . dispose ( ) ;
volumeBar . dispose ( ) ;
2018-03-23 19:25:12 +02:00
} ) ;
2018-12-11 21:23:13 +02:00
QUnit . test ( 'controlbar children to false individually, does not cause an assertion' , function ( assert ) {
const defaultChildren = ControlBar . prototype . options _ . children ;
defaultChildren . forEach ( ( childName ) => {
const options = { controlBar : { } } ;
options . controlBar [ childName ] = false ;
const player = TestHelpers . makePlayer ( options ) ;
this . clock . tick ( 1000 ) ;
player . triggerReady ( ) ;
player . dispose ( ) ;
assert . ok ( true , ` ${ childName } : false. did not cause an assertion ` ) ;
} ) ;
} ) ;
QUnit . test ( 'all controlbar children to false, does not cause an assertion' , function ( assert ) {
const defaultChildren = ControlBar . prototype . options _ . children ;
const options = { controlBar : { } } ;
defaultChildren . forEach ( ( childName ) => {
options . controlBar [ childName ] = false ;
} ) ;
const player = TestHelpers . makePlayer ( options ) ;
this . clock . tick ( 1000 ) ;
player . triggerReady ( ) ;
player . dispose ( ) ;
assert . ok ( true , 'did not cause an assertion' ) ;
} ) ;
2021-12-20 22:37:33 +02:00
QUnit . test ( 'Remaing time negative sign can be optional' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const rtd1 = new RemainingTimeDisplay ( player ) ;
const rtd2 = new RemainingTimeDisplay ( player , { displayNegative : false } ) ;
this . clock . tick ( 1 ) ;
assert . ok ( rtd1 . el ( ) . textContent . indexOf ( '-' ) > 0 , 'Value is negative by default' ) ;
assert . equal ( rtd2 . el ( ) . textContent . indexOf ( '-' ) , - 1 , 'Value is positive with option' ) ;
rtd1 . dispose ( ) ;
rtd2 . dispose ( ) ;
player . dispose ( ) ;
} ) ;