2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2015-04-14 22:08:32 +02:00
|
|
|
import PosterImage from '../../src/js/poster-image.js';
|
2015-05-04 01:12:38 +02:00
|
|
|
import * as browser from '../../src/js/utils/browser.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import TestHelpers from './test-helpers.js';
|
|
|
|
import document from 'global/document';
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.module('PosterImage', {
|
2016-08-12 19:51:31 +02:00
|
|
|
beforeEach() {
|
2014-10-16 22:59:41 +03:00
|
|
|
// Store the original background support so we can test different vals
|
2015-05-04 01:12:38 +02:00
|
|
|
this.origVal = browser.BACKGROUND_SIZE_SUPPORTED;
|
2015-08-25 02:46:54 +02:00
|
|
|
this.poster1 = '#poster1';
|
|
|
|
this.poster2 = '#poster2';
|
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,
|
2016-08-03 21:27:03 +02:00
|
|
|
poster() {
|
2014-10-16 22:59:41 +03:00
|
|
|
return this.poster_;
|
|
|
|
},
|
|
|
|
handler_: null,
|
2018-01-30 20:26:21 +02:00
|
|
|
off() {},
|
2016-08-03 21:27:03 +02:00
|
|
|
on(type, handler) {
|
2014-10-16 22:59:41 +03:00
|
|
|
this.handler_ = handler;
|
|
|
|
},
|
2016-08-03 21:27:03 +02:00
|
|
|
trigger(type) {
|
2014-10-16 22:59:41 +03:00
|
|
|
this.handler_.call();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
2016-08-12 19:51:31 +02:00
|
|
|
afterEach() {
|
2015-05-04 01:12:38 +02:00
|
|
|
browser.BACKGROUND_SIZE_SUPPORTED = this.origVal;
|
2014-10-16 22:59:41 +03:00
|
|
|
}
|
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should create and update a poster image', function(assert) {
|
2015-05-04 01:12:38 +02:00
|
|
|
browser.BACKGROUND_SIZE_SUPPORTED = true;
|
2015-08-25 02:46:54 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
2015-08-25 02:46:54 +02:00
|
|
|
let backgroundImage = posterImage.el().style.backgroundImage;
|
2016-08-03 21:27:03 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(backgroundImage.indexOf(this.poster1), -1, '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-08-25 02:46:54 +02:00
|
|
|
backgroundImage = posterImage.el().style.backgroundImage;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(backgroundImage.indexOf(this.poster2), -1, 'Background image updated');
|
2018-01-30 20:26:21 +02:00
|
|
|
|
|
|
|
posterImage.dispose();
|
2014-10-16 22:59:41 +03:00
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should create and update a fallback image in older browsers', function(assert) {
|
2015-05-04 01:12:38 +02:00
|
|
|
browser.BACKGROUND_SIZE_SUPPORTED = false;
|
2015-08-25 02:46:54 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(posterImage.fallbackImg_.src.indexOf(this.poster1),
|
2016-08-03 21:27:03 +02:00
|
|
|
-1,
|
|
|
|
'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');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.notEqual(posterImage.fallbackImg_.src.indexOf(this.poster2),
|
2016-08-03 21:27:03 +02:00
|
|
|
-1,
|
|
|
|
'Fallback image updated');
|
2018-01-30 20:26:21 +02:00
|
|
|
|
|
|
|
posterImage.dispose();
|
2014-10-16 22:59:41 +03:00
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should remove itself from the document flow when there is no poster', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.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');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(posterImage.hasClass('vjs-hidden'),
|
2016-08-03 21:27:03 +02:00
|
|
|
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');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(posterImage.hasClass('vjs-hidden'),
|
2016-08-03 21:27:03 +02:00
|
|
|
false,
|
|
|
|
'Poster image shows again when there is a source');
|
2018-01-30 20:26:21 +02:00
|
|
|
|
|
|
|
posterImage.dispose();
|
2013-11-27 03:53:23 +03:00
|
|
|
});
|
2014-10-01 04:34:51 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should hide the poster in the appropriate player states', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
|
|
|
const playerDiv = document.createElement('div');
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
const 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';
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(TestHelpers.getComputedStyle(el, 'display'),
|
2016-08-03 21:27:03 +02:00
|
|
|
'none',
|
|
|
|
'The poster hides when the video has started (CSS may not be loaded)');
|
2014-10-16 22:59:41 +03:00
|
|
|
|
|
|
|
playerDiv.className = 'video-js vjs-has-started vjs-audio';
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(TestHelpers.getComputedStyle(el, 'display'),
|
2016-08-03 21:27:03 +02:00
|
|
|
'block',
|
|
|
|
'The poster continues to show when playing audio');
|
2018-01-30 20:26:21 +02:00
|
|
|
|
|
|
|
posterImage.dispose();
|
2014-10-01 04:34:51 +03:00
|
|
|
});
|