Commit af67873b by polesye

Fix seek log.

parent 8191d3c7
...@@ -356,9 +356,11 @@ function (VideoPlayer) { ...@@ -356,9 +356,11 @@ 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');
});
describe('when the video is playing', function () {
beforeEach(function () {
runs(function () { runs(function () {
state.videoPlayer.play(); state.videoPlayer.play();
}); });
...@@ -367,10 +369,10 @@ function (VideoPlayer) { ...@@ -367,10 +369,10 @@ function (VideoPlayer) {
var duration = state.videoPlayer.duration(); var duration = state.videoPlayer.duration();
return duration > 0 && state.videoPlayer.isPlaying(); return duration > 0 && state.videoPlayer.isPlaying();
}, 'video begins playing', WAIT_TIMEOUT); }, 'video didn\'t start playing', WAIT_TIMEOUT);
}); });
it('Slider event causes log update', function () { it('slider event causes log update', function () {
runs(function () { runs(function () {
spyOn(state.videoPlayer, 'log'); spyOn(state.videoPlayer, 'log');
state.videoProgressSlider.onSlide( state.videoProgressSlider.onSlide(
...@@ -383,20 +385,19 @@ function (VideoPlayer) { ...@@ -383,20 +385,19 @@ function (VideoPlayer) {
}, 'currentTime is less than 2 seconds', WAIT_TIMEOUT); }, 'currentTime is less than 2 seconds', WAIT_TIMEOUT);
runs(function () { runs(function () {
expect(state.videoPlayer.log).toHaveBeenCalledWith( var args = state.videoPlayer.log.calls[0].args;
'seek_video',
{ expect(args[0]).toBe('seek_video');
old_time: jasmine.any(Number), expect(args[1].old_time).toBeLessThan(2);
new_time: 2, expect(args[1].new_time).toBe(2);
type: 'onSlideSeek' expect(args[1].type).toBe('onSlideSeek');
}
);
}); });
}); });
it('seek the player', function () { it('seek the player', function () {
runs(function () { runs(function () {
spyOn(state.videoPlayer.player, 'seekTo').andCallThrough(); spyOn(state.videoPlayer.player, 'seekTo')
.andCallThrough();
state.videoProgressSlider.onSlide( state.videoProgressSlider.onSlide(
jQuery.Event('slide'), { value: 30 } jQuery.Event('slide'), { value: 30 }
); );
...@@ -414,7 +415,8 @@ function (VideoPlayer) { ...@@ -414,7 +415,8 @@ function (VideoPlayer) {
it('call updatePlayTime on player', function () { it('call updatePlayTime on player', function () {
runs(function () { runs(function () {
spyOn(state.videoPlayer, 'updatePlayTime').andCallThrough(); spyOn(state.videoPlayer, 'updatePlayTime')
.andCallThrough();
state.videoProgressSlider.onSlide( state.videoProgressSlider.onSlide(
jQuery.Event('slide'), { value: 30 } jQuery.Event('slide'), { value: 30 }
); );
...@@ -426,7 +428,8 @@ function (VideoPlayer) { ...@@ -426,7 +428,8 @@ function (VideoPlayer) {
runs(function () { runs(function () {
expect(state.videoPlayer.updatePlayTime) expect(state.videoPlayer.updatePlayTime)
.toHaveBeenCalledWith(jasmine.any(Number)); .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