From 51b57d41a387e18d22e09ea502e0de7d5d0b46f2 Mon Sep 17 00:00:00 2001 From: Pat O'Neill Date: Tue, 17 Oct 2017 16:26:47 -0400 Subject: [PATCH] Add test --- test/unit/player.test.js | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/unit/player.test.js b/test/unit/player.test.js index c0b30fb13d..ec8300700f 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1621,6 +1621,64 @@ QUnit.test('src_ does not call loadTech is name is titleCaseEquals', function(as assert.equal(loadTechCalled, 0, 'loadTech was not called'); }); +QUnit.test('subsequent calls to src() will put the player in a non-ready state, so calling ready() immediately after will correctly wait until the new source is set', function(assert) { + const tag = TestHelpers.makeTag(); + const player = videojs(tag); + const onReadySpy = sinon.spy(); + const readySpy = sinon.spy(); + + player.on('ready', onReadySpy); + player.ready(readySpy); + + assert.equal(onReadySpy.callCount, 0, 'no readiness yet...'); + assert.equal(readySpy.callCount, 0, 'no readiness yet...'); + + this.clock.tick(1); + + assert.equal(onReadySpy.callCount, 1, 'saw an initial "ready"'); + assert.equal(readySpy.callCount, 1, 'saw an initial ready() callback'); + + player.src({ + src: 'http://example.com/video.mp4', + type: 'video/mp4' + }); + + player.ready(readySpy); + + assert.equal(onReadySpy.callCount, 1, 'did not see a "ready" because source setting is async'); + assert.equal(readySpy.callCount, 1, 'did not see a ready() callback because source setting is async'); + + this.clock.tick(1); + + assert.equal(onReadySpy.callCount, 1, 'did not see a "ready" because middleware queues up another async operation'); + assert.equal(readySpy.callCount, 1, 'did not see a ready() callback because middleware queues up another async operation'); + + this.clock.tick(1); + + assert.equal(onReadySpy.callCount, 2, 'saw second "ready" because source setting and tech selection are complete'); + assert.equal(readySpy.callCount, 2, 'saw second ready() callback because source setting and tech selection are complete'); + + player.src({ + src: 'http://example.com/video2.mp4', + type: 'video/mp4' + }); + + player.ready(readySpy); + + assert.equal(onReadySpy.callCount, 2, 'did not see a "ready" because source setting is async'); + assert.equal(readySpy.callCount, 2, 'did not see a ready() callback because source setting is async'); + + this.clock.tick(1); + + assert.equal(onReadySpy.callCount, 2, 'did not see a "ready" because middleware queues up another async operation'); + assert.equal(readySpy.callCount, 2, 'did not see a ready() callback because middleware queues up another async operation'); + + this.clock.tick(1); + + assert.equal(onReadySpy.callCount, 3, 'saw third "ready" because source setting and tech selection are complete'); + assert.equal(readySpy.callCount, 3, 'saw third ready() callback because source setting and tech selection are complete'); +}); + QUnit.test('options: plugins', function(assert) { const optionsSpy = sinon.spy();