Commit bf8876e1 by Anton Stupak

Merge pull request #4106 from edx/anton/fix-seek-log

Video: fix seek tracking log.
parents 8191d3c7 af67873b
...@@ -356,77 +356,80 @@ function (VideoPlayer) { ...@@ -356,77 +356,80 @@ function (VideoPlayer) {
describe('onSeek', function () { describe('onSeek', function () {
beforeEach(function () { beforeEach(function () {
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
state.videoEl = $('video, iframe'); state.videoEl = $('video, iframe');
});
runs(function () { describe('when the video is playing', function () {
state.videoPlayer.play(); beforeEach(function () {
}); runs(function () {
state.videoPlayer.play();
waitsFor(function () { });
var duration = state.videoPlayer.duration();
return duration > 0 && state.videoPlayer.isPlaying(); waitsFor(function () {
}, 'video begins playing', WAIT_TIMEOUT); var duration = state.videoPlayer.duration();
});
it('Slider event causes log update', function () { return duration > 0 && state.videoPlayer.isPlaying();
runs(function () { }, 'video didn\'t start playing', WAIT_TIMEOUT);
spyOn(state.videoPlayer, 'log');
state.videoProgressSlider.onSlide(
jQuery.Event('slide'), { value: 2 }
);
}); });
waitsFor(function () { it('slider event causes log update', function () {
return state.videoPlayer.currentTime >= 2; runs(function () {
}, 'currentTime is less than 2 seconds', WAIT_TIMEOUT); spyOn(state.videoPlayer, 'log');
state.videoProgressSlider.onSlide(
jQuery.Event('slide'), { value: 2 }
);
});
runs(function () { waitsFor(function () {
expect(state.videoPlayer.log).toHaveBeenCalledWith( return state.videoPlayer.currentTime >= 2;
'seek_video', }, 'currentTime is less than 2 seconds', WAIT_TIMEOUT);
{
old_time: jasmine.any(Number),
new_time: 2,
type: 'onSlideSeek'
}
);
});
});
it('seek the player', function () { runs(function () {
runs(function () { var args = state.videoPlayer.log.calls[0].args;
spyOn(state.videoPlayer.player, 'seekTo').andCallThrough();
state.videoProgressSlider.onSlide( expect(args[0]).toBe('seek_video');
jQuery.Event('slide'), { value: 30 } expect(args[1].old_time).toBeLessThan(2);
); expect(args[1].new_time).toBe(2);
expect(args[1].type).toBe('onSlideSeek');
});
}); });
waitsFor(function () { it('seek the player', function () {
return state.videoPlayer.currentTime >= 30; runs(function () {
}, 'currentTime is less than 30 seconds', WAIT_TIMEOUT); spyOn(state.videoPlayer.player, 'seekTo')
.andCallThrough();
state.videoProgressSlider.onSlide(
jQuery.Event('slide'), { value: 30 }
);
});
runs(function () { waitsFor(function () {
expect(state.videoPlayer.player.seekTo) return state.videoPlayer.currentTime >= 30;
.toHaveBeenCalledWith(30, true); }, 'currentTime is less than 30 seconds', WAIT_TIMEOUT);
});
});
it('call updatePlayTime on player', function () { runs(function () {
runs(function () { expect(state.videoPlayer.player.seekTo)
spyOn(state.videoPlayer, 'updatePlayTime').andCallThrough(); .toHaveBeenCalledWith(30, true);
state.videoProgressSlider.onSlide( });
jQuery.Event('slide'), { value: 30 }
);
}); });
waitsFor(function () { it('call updatePlayTime on player', function () {
return state.videoPlayer.currentTime >= 30; runs(function () {
}, 'currentTime is less than 30 seconds', WAIT_TIMEOUT); spyOn(state.videoPlayer, 'updatePlayTime')
.andCallThrough();
state.videoProgressSlider.onSlide(
jQuery.Event('slide'), { value: 30 }
);
});
runs(function () { waitsFor(function () {
expect(state.videoPlayer.updatePlayTime) return state.videoPlayer.currentTime >= 30;
.toHaveBeenCalledWith(jasmine.any(Number)); }, 'currentTime is less than 30 seconds', WAIT_TIMEOUT);
runs(function () {
expect(state.videoPlayer.updatePlayTime)
.toHaveBeenCalledWith(30, true);
});
}); });
}); });
...@@ -452,13 +455,31 @@ function (VideoPlayer) { ...@@ -452,13 +455,31 @@ function (VideoPlayer) {
describe('when the video is not playing', function () { describe('when the video is not playing', function () {
beforeEach(function () { beforeEach(function () {
state = jasmine.initializePlayer(); spyOn(state.videoPlayer, 'setPlaybackRate')
.andCallThrough();
});
spyOn(state.videoPlayer, 'updatePlayTime').andCallThrough(); it('slider event causes log update', function () {
spyOn(state, 'setSpeed').andCallThrough(); runs(function () {
spyOn(state.videoPlayer, 'log').andCallThrough(); spyOn(state.videoPlayer, 'log');
spyOn(state.videoPlayer.player, 'setPlaybackRate').andCallThrough(); state.videoProgressSlider.onSlide(
spyOn(state.videoPlayer, 'setPlaybackRate').andCallThrough(); jQuery.Event('slide'), { value: 2 }
);
});
waitsFor(function () {
return state.videoPlayer.currentTime >= 2;
}, 'currentTime is less than 2 seconds', WAIT_TIMEOUT);
runs(function () {
expect(state.videoPlayer.log).toHaveBeenCalledWith(
'seek_video', {
old_time: 0,
new_time: 2,
type: 'onSlideSeek'
}
);
});
}); });
it('video has a correct speed', function () { it('video has a correct speed', function () {
...@@ -483,7 +504,8 @@ function (VideoPlayer) { ...@@ -483,7 +504,8 @@ function (VideoPlayer) {
it('set the volume on player', function () { it('set the volume on player', function () {
spyOn(state.videoPlayer.player, 'setVolume'); spyOn(state.videoPlayer.player, 'setVolume');
state.videoPlayer.onVolumeChange(60); state.videoPlayer.onVolumeChange(60);
expect(state.videoPlayer.player.setVolume).toHaveBeenCalledWith(60); expect(state.videoPlayer.player.setVolume)
.toHaveBeenCalledWith(60);
}); });
describe('when the video is not playing', function () { describe('when the video is not playing', function () {
...@@ -522,7 +544,8 @@ function (VideoPlayer) { ...@@ -522,7 +544,8 @@ function (VideoPlayer) {
}); });
it('does not trigger updatePlayTime event', function () { it('does not trigger updatePlayTime event', function () {
expect(state.videoPlayer.updatePlayTime).not.toHaveBeenCalled(); expect(state.videoPlayer.updatePlayTime)
.not.toHaveBeenCalled();
}); });
}); });
......
...@@ -431,7 +431,8 @@ function (HTML5Video, Resizer) { ...@@ -431,7 +431,8 @@ function (HTML5Video, Resizer) {
// Reinitialized on a onSeek event. // Reinitialized on a onSeek event.
function onSeek(params) { function onSeek(params) {
var time = params.time, var time = params.time,
type = params.type; type = params.type,
oldTime = this.videoPlayer.currentTime;
// After the user seeks, the video will start playing from // After the user seeks, the video will start playing from
// the sought point, and stop playing at the end. // the sought point, and stop playing at the end.
...@@ -441,11 +442,10 @@ function (HTML5Video, Resizer) { ...@@ -441,11 +442,10 @@ function (HTML5Video, Resizer) {
} }
this.videoPlayer.seekTo(time); this.videoPlayer.seekTo(time);
this.videoPlayer.log( this.videoPlayer.log(
'seek_video', 'seek_video',
{ {
old_time: this.videoPlayer.currentTime, old_time: oldTime,
new_time: time, new_time: time,
type: type type: type
} }
......
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