2014-10-16 22:59:41 +03:00
|
|
|
module('PosterImage', {
|
|
|
|
'setup': function(){
|
|
|
|
// Store the original background support so we can test different vals
|
2015-03-11 03:01:11 +02:00
|
|
|
this.origVal = Lib.BACKGROUND_SIZE_SUPPORTED;
|
2014-10-16 22:59:41 +03:00
|
|
|
this.poster1 = 'http://example.com/poster.jpg';
|
|
|
|
this.poster2 = 'http://example.com/UPDATED.jpg';
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Create a mock player object that responds as a player would
|
|
|
|
this.mockPlayer = {
|
|
|
|
poster_: this.poster1,
|
|
|
|
poster: function(){
|
|
|
|
return this.poster_;
|
|
|
|
},
|
|
|
|
handler_: null,
|
|
|
|
on: function(type, handler){
|
|
|
|
this.handler_ = handler;
|
|
|
|
},
|
|
|
|
trigger: function(type){
|
|
|
|
this.handler_.call();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
'teardown': function(){
|
2015-03-11 03:01:11 +02:00
|
|
|
Lib.BACKGROUND_SIZE_SUPPORTED = this.origVal;
|
2014-10-16 22:59:41 +03:00
|
|
|
}
|
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
var PosterImage = vjs.PosterImage;
|
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
test('should create and update a poster image', function(){
|
|
|
|
var posterImage;
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2015-02-17 23:09:19 +02:00
|
|
|
// IE11 adds quotes in the returned background url so need to normalize the result
|
|
|
|
function normalizeUrl(url){
|
|
|
|
return url.replace(new RegExp('\\"', 'g'),'');
|
|
|
|
}
|
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
vjs.BACKGROUND_SIZE_SUPPORTED = true;
|
2015-03-11 03:01:11 +02:00
|
|
|
posterImage = new PosterImage(this.mockPlayer);
|
2015-02-17 23:09:19 +02:00
|
|
|
equal(normalizeUrl(posterImage.el().style.backgroundImage), 'url('+this.poster1+')', 'Background image used');
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Update with a new poster source and check the new value
|
|
|
|
this.mockPlayer.poster_ = this.poster2;
|
|
|
|
this.mockPlayer.trigger('posterchange');
|
2015-02-17 23:09:19 +02:00
|
|
|
equal(normalizeUrl(posterImage.el().style.backgroundImage), 'url('+this.poster2+')', 'Background image updated');
|
2014-10-16 22:59:41 +03:00
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
test('should create and update a fallback image in older browsers', function(){
|
|
|
|
var posterImage;
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
vjs.BACKGROUND_SIZE_SUPPORTED = false;
|
2015-03-11 03:01:11 +02:00
|
|
|
posterImage = new PosterImage(this.mockPlayer);
|
2014-10-16 22:59:41 +03:00
|
|
|
equal(posterImage.fallbackImg_.src, this.poster1, 'Fallback image created');
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Update with a new poster source and check the new value
|
|
|
|
this.mockPlayer.poster_ = this.poster2;
|
|
|
|
this.mockPlayer.trigger('posterchange');
|
|
|
|
equal(posterImage.fallbackImg_.src, this.poster2, 'Fallback image updated');
|
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
test('should remove itself from the document flow when there is no poster', function(){
|
|
|
|
var posterImage;
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
posterImage = new PosterImage(this.mockPlayer);
|
2014-10-16 22:59:41 +03:00
|
|
|
equal(posterImage.el().style.display, '', 'Poster image shows by default');
|
2013-12-02 19:11:22 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Update with an empty string
|
|
|
|
this.mockPlayer.poster_ = '';
|
|
|
|
this.mockPlayer.trigger('posterchange');
|
2014-12-22 19:38:54 +02:00
|
|
|
equal(posterImage.hasClass('vjs-hidden'), true, 'Poster image hides with an empty source');
|
2013-12-02 19:11:22 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Updated with a valid source
|
|
|
|
this.mockPlayer.poster_ = this.poster2;
|
|
|
|
this.mockPlayer.trigger('posterchange');
|
2014-12-22 19:38:54 +02:00
|
|
|
equal(posterImage.hasClass('vjs-hidden'), false, 'Poster image shows again when there is a source');
|
2013-11-27 03:53:23 +03:00
|
|
|
});
|
2014-10-01 04:34:51 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
test('should hide the poster in the appropriate player states', function(){
|
2015-03-11 03:01:11 +02:00
|
|
|
var posterImage = new PosterImage(this.mockPlayer);
|
2014-10-16 22:59:41 +03:00
|
|
|
var playerDiv = document.createElement('div');
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
var el = posterImage.el();
|
2014-10-01 04:34:51 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Remove the source so when we add to the DOM it doesn't throw an error
|
|
|
|
// We want to poster to still think it has a real source so it doesn't hide itself
|
|
|
|
posterImage.setSrc('');
|
|
|
|
|
|
|
|
// Add the elements to the DOM so styles are computed
|
|
|
|
playerDiv.appendChild(el);
|
|
|
|
fixture.appendChild(playerDiv);
|
|
|
|
|
|
|
|
playerDiv.className = 'video-js vjs-has-started';
|
|
|
|
equal(TestHelpers.getComputedStyle(el, 'display'), 'none', 'The poster hides when the video has started');
|
|
|
|
|
|
|
|
playerDiv.className = 'video-js vjs-has-started vjs-audio';
|
|
|
|
equal(TestHelpers.getComputedStyle(el, 'display'), 'block', 'The poster continues to show when playing audio');
|
2014-10-01 04:34:51 +03:00
|
|
|
});
|