Commit ac4ac23d by Jay Zoldak

Fix intermittently failing video js tests

parent b5f1d998
...@@ -58,7 +58,7 @@ window.jQuery.ajaxWithPrefix = (url, settings) -> ...@@ -58,7 +58,7 @@ window.jQuery.ajaxWithPrefix = (url, settings) ->
oldAjaxWithPrefix.apply @, arguments oldAjaxWithPrefix.apply @, arguments
# Time waitsFor() should wait for before failing a test. # Time waitsFor() should wait for before failing a test.
window.WAIT_TIMEOUT = 1000 window.WAIT_TIMEOUT = 5000
jasmine.getFixtures().fixturesPath += 'fixtures' jasmine.getFixtures().fixturesPath += 'fixtures'
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
}); });
afterEach(function() { afterEach(function() {
YT.Player = void 0; state = undefined;
$.fn.scrollTo.reset(); $.fn.scrollTo.reset();
$('.subtitles').remove(); $('.subtitles').remove();
$('source').remove(); $('source').remove();
...@@ -40,10 +40,7 @@ ...@@ -40,10 +40,7 @@
expect(player.video.play).toHaveBeenCalled(); expect(player.video.play).toHaveBeenCalled();
}); });
// Temporarily disabled due to intermittent failures it('player state was changed', function () {
// Fails with "timeout: timed out after 1000 msec waiting for Player state should be changed"
// on Firefox
xit('player state was changed', function () {
waitsFor(function () { waitsFor(function () {
return player.getPlayerState() !== STATUS.PAUSED; return player.getPlayerState() !== STATUS.PAUSED;
}, 'Player state should be changed', WAIT_TIMEOUT); }, 'Player state should be changed', WAIT_TIMEOUT);
...@@ -63,36 +60,36 @@ ...@@ -63,36 +60,36 @@
}); });
}); });
}); });
});
describe('when player is played', function () { describe('when player is playing', function () {
beforeEach(function () { beforeEach(function () {
spyOn(player.video, 'pause').andCallThrough(); spyOn(player.video, 'pause').andCallThrough();
player.playerState = STATUS.PLAYING; player.playerState = STATUS.PLAYING;
$(player.videoEl).trigger('click'); $(player.videoEl).trigger('click');
}); });
it('native event was called', function () { it('native event was called', function () {
expect(player.video.pause).toHaveBeenCalled(); expect(player.video.pause).toHaveBeenCalled();
}); });
it('player state was changed', function () { it('player state was changed', function () {
waitsFor(function () { waitsFor(function () {
return player.getPlayerState() !== STATUS.PLAYING; return player.getPlayerState() !== STATUS.PLAYING;
}, 'Player state should be changed', WAIT_TIMEOUT); }, 'Player state should be changed', WAIT_TIMEOUT);
runs(function () { runs(function () {
expect(player.getPlayerState()).toBe(STATUS.PAUSED); expect(player.getPlayerState()).toBe(STATUS.PAUSED);
});
}); });
});
it('callback was called', function () { it('callback was called', function () {
waitsFor(function () { waitsFor(function () {
return player.getPlayerState() !== STATUS.PLAYING; return player.getPlayerState() !== STATUS.PLAYING;
}, 'Player state should be changed', WAIT_TIMEOUT); }, 'Player state should be changed', WAIT_TIMEOUT);
runs(function () { runs(function () {
expect(player.callStateChangeCallback).toHaveBeenCalled(); expect(player.callStateChangeCallback).toHaveBeenCalled();
});
}); });
}); });
}); });
...@@ -132,7 +129,11 @@ ...@@ -132,7 +129,11 @@
describe('pause', function () { describe('pause', function () {
beforeEach(function () { beforeEach(function () {
spyOn(player.video, 'pause').andCallThrough(); spyOn(player.video, 'pause').andCallThrough();
player.playerState = STATUS.UNSTARTED;
player.playVideo(); player.playVideo();
waitsFor(function () {
return player.getPlayerState() !== STATUS.UNSTARTED;
}, 'Video never started playing', WAIT_TIMEOUT);
player.pauseVideo(); player.pauseVideo();
}); });
...@@ -142,7 +143,7 @@ ...@@ -142,7 +143,7 @@
it('player state was changed', function () { it('player state was changed', function () {
waitsFor(function () { waitsFor(function () {
return player.getPlayerState() !== STATUS.UNSTARTED; return player.getPlayerState() !== STATUS.PLAYING;
}, 'Player state should be changed', WAIT_TIMEOUT); }, 'Player state should be changed', WAIT_TIMEOUT);
runs(function () { runs(function () {
...@@ -152,7 +153,7 @@ ...@@ -152,7 +153,7 @@
it('callback was called', function () { it('callback was called', function () {
waitsFor(function () { waitsFor(function () {
return player.getPlayerState() !== STATUS.UNSTARTED; return player.getPlayerState() !== STATUS.PLAYING;
}, 'Player state should be changed', WAIT_TIMEOUT); }, 'Player state should be changed', WAIT_TIMEOUT);
runs(function () { runs(function () {
expect(player.callStateChangeCallback).toHaveBeenCalled(); expect(player.callStateChangeCallback).toHaveBeenCalled();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment