Skip to content

Commit

Permalink
Merge pull request #283 from fmtvp/restart_successful_event
Browse files Browse the repository at this point in the history
IPLAYERTVV1-3166 Restart successful event
  • Loading branch information
sdclibbery committed Aug 21, 2015
2 parents 723ad2a + 04fd6d1 commit a47baa0
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 33 deletions.
20 changes: 20 additions & 0 deletions static/script-tests/tests/devices/mediaplayer/cehtmlcommontests.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ window.commonTests.mediaPlayer.cehtml.mixinTests = function (testCase, mediaPlay
fakeCEHTMLObject.PLAY_STATE_ERROR = 6;

this.runMediaPlayerTest = runMediaPlayerTest;
this.runMediaPlayerTestWithSpecificConfig = runMediaPlayerTestWithSpecificConfig;
this.fakeCEHTMLObject = fakeCEHTMLObject;
this.deviceMockingHooks = deviceMockingHooks;
};
Expand All @@ -174,6 +175,7 @@ window.commonTests.mediaPlayer.cehtml.mixinTests = function (testCase, mediaPlay
deviceMockingHooks.mockTime();
self._device = application.getDevice();
self._mediaPlayer = self._device.getMediaPlayer();
self._clock = clock;
try {
action.call(self, MediaPlayer);
}
Expand All @@ -184,6 +186,24 @@ window.commonTests.mediaPlayer.cehtml.mixinTests = function (testCase, mediaPlay
}, config);
};

var runMediaPlayerTestWithSpecificConfig = function (self, queue, action, newConfig) {
queuedApplicationInit(queue, 'lib/mockapplication', ["antie/devices/mediaplayer/mediaplayer"],
function(application, MediaPlayer) {
deviceMockingHooks.setup.call(self, self.sandbox, application);
deviceMockingHooks.mockTime();
self._device = application.getDevice();
self._mediaPlayer = self._device.getMediaPlayer();
self._clock = clock;
try {
action.call(self, MediaPlayer);
}
finally {
deviceMockingHooks.unmockTime();
}

}, newConfig);
};

var getToBuffering = function(self, MediaPlayer, startTime) {
self._mediaPlayer.setSource(MediaPlayer.TYPE.VIDEO, 'http://testurl/', 'video/mp4');
self._mediaPlayer.beginPlaybackFrom(startTime || 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* @preserve Copyright (c) 2014 British Broadcasting Corporation
* (http://www.bbc.co.uk) and TAL Contributors (1)
*
* (1) TAL Contributors are listed in the AUTHORS file and at
* https://github.com/fmtvp/TAL/AUTHORS - please extend this file,
* not this notice.
*
* @license Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* All rights reserved
* Please contact us for an alternative licence
*/

(function() {
// jshint newcap: false
this.CEHTMLSeekFinishedEmitEventTests = AsyncTestCase("CEHTMLSeekFinishedEmitEvent");

var config = {"modules":{"base":"antie/devices/browserdevice","modifiers":["antie/devices/mediaplayer/cehtmlseekfinishedemitevent"]}, "input":{"map":{}},"layouts":[{"width":960,"height":540,"module":"fixtures/layouts/default","classes":["browserdevice540p"]}],"deviceConfigurationKey":"devices-html5-1"};
var configWithRestartTimeout = {"restartTimeout":10000, "modules":{"base":"antie/devices/browserdevice","modifiers":["antie/devices/mediaplayer/cehtmlseekfinishedemitevent"]}, "input":{"map":{}},"layouts":[{"width":960,"height":540,"module":"fixtures/layouts/default","classes":["browserdevice540p"]}],"deviceConfigurationKey":"devices-html5-1"};

var eventWasFired = function(eventHandler, eventType) {
for(var i = 0; i < eventHandler.callCount; i++) {
if(eventHandler.getCall(i).args[0].type === eventType) {
return true;
}
}
return false;
};

var eventNotFired = function(eventHandler, eventType) {
return !eventWasFired(eventHandler, eventType);
};

// ---------------
// Mix in the base HTML5 tests to make sure the sub-modifier doesn't break basic functionality
// ---------------
window.commonTests.mediaPlayer.cehtml.mixinTests(this.CEHTMLSeekFinishedEmitEventTests, "antie/devices/mediaplayer/cehtmlseekfinishedemitevent", config);

// ---------------
// Remove tests that are irrelevant for this sub-modifier.
// ---------------

// ---------------
// Additional tests for this sub-modifier.
// ---------------
this.CEHTMLSeekFinishedEmitEventTests.prototype.testIfTimeIsInRangeAndHasBeenPlaying5TimesWithNoTimeoutWeFireSeekFinishedEvent = function(queue) {
expectAsserts(7);
var self = this;
this.runMediaPlayerTest(this, queue, function (MediaPlayer) {
var eventHandler = self.sandbox.stub();
self._mediaPlayer.addEventCallback(null, eventHandler);

self._mediaPlayer.setSource(MediaPlayer.TYPE.VIDEO, 'http://testurl/', 'video/mp4');
self._mediaPlayer.beginPlaybackFrom(1000);
self.deviceMockingHooks.sendMetadata(self._mediaPlayer, 0, { start: 0, end: 100 });
self.deviceMockingHooks.finishBuffering(self._mediaPlayer);

assert(eventWasFired(eventHandler, MediaPlayer.EVENT.SEEK_ATTEMPTED));
for(var i = 0; i < 5; i++) {
assert(eventNotFired(eventHandler, MediaPlayer.EVENT.SEEK_FINISHED));
self._clock.tick(500);
self.fakeCEHTMLObject.playPosition += 500;
eventHandler.reset();
}

self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventWasFired(eventHandler, MediaPlayer.EVENT.SEEK_FINISHED));
});
};

this.CEHTMLSeekFinishedEmitEventTests.prototype.testIfWeFiredSeekFinishedEventDoNotFireAnother = function(queue) {
expectAsserts(8);
var self = this;
this.runMediaPlayerTest(this, queue, function (MediaPlayer) {
var eventHandler = self.sandbox.stub();
self._mediaPlayer.addEventCallback(null, eventHandler);

self._mediaPlayer.setSource(MediaPlayer.TYPE.VIDEO, 'http://testurl/', 'video/mp4');
self._mediaPlayer.beginPlaybackFrom(1000);
self.deviceMockingHooks.sendMetadata(self._mediaPlayer, 0, { start: 0, end: 100 });
self.deviceMockingHooks.finishBuffering(self._mediaPlayer);

assert(eventWasFired(eventHandler, MediaPlayer.EVENT.SEEK_ATTEMPTED));
for(var i = 0; i < 5; i++) {
assert(eventNotFired(eventHandler, MediaPlayer.EVENT.SEEK_FINISHED));
self._clock.tick(500);
self.fakeCEHTMLObject.playPosition += 500;
eventHandler.reset();
}

self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventWasFired(eventHandler, MediaPlayer.EVENT.SEEK_FINISHED));
eventHandler.reset();

self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventNotFired(eventHandler, MediaPlayer.EVENT.SEEK_FINISHED));
});
};

this.CEHTMLSeekFinishedEmitEventTests.prototype.testIfTimeIsInRangeAndHasBeenPlaying5TimesWith10SecondTimeoutWeFireSeekFinishedEvent = function(queue) {
var self = this;
expectAsserts(21);
this.runMediaPlayerTestWithSpecificConfig(this, queue, function (MediaPlayer) {
var eventHandler = self.sandbox.stub();
self._mediaPlayer.addEventCallback(null, eventHandler);

self._mediaPlayer.setSource(MediaPlayer.TYPE.VIDEO, 'http://testurl/', 'video/mp4');
self._mediaPlayer.beginPlaybackFrom(1000);
self.deviceMockingHooks.sendMetadata(self._mediaPlayer, 0, { start: 0, end: 100 });
self.deviceMockingHooks.finishBuffering(self._mediaPlayer);

assert(eventWasFired(eventHandler, MediaPlayer.EVENT.SEEK_ATTEMPTED));

var numberOfLoops = configWithRestartTimeout.restartTimeout/500;
for(var i = 0; i < numberOfLoops - 1; i++) {
self._clock.tick(500);
self.fakeCEHTMLObject.playPosition += 500;
assert(eventNotFired(eventHandler, MediaPlayer.EVENT.SEEK_FINISHED));
}

self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventWasFired(eventHandler, MediaPlayer.EVENT.SEEK_FINISHED));
}, configWithRestartTimeout);
};
})();
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ window.commonTests.mediaPlayer.html5.mixinTests = function (testCase, mediaPlaye
this.stubCreateElementResults = stubCreateElementResults;
this.deviceMockingHooks = deviceMockingHooks;
this.runMediaPlayerTest = runMediaPlayerTest;
this.runMediaPlayerTestWithSpecificConfig = runMediaPlayerTestWithSpecificConfig;
};

mixins.tearDown = function() {
Expand All @@ -183,7 +184,7 @@ window.commonTests.mediaPlayer.html5.mixinTests = function (testCase, mediaPlaye
queuedApplicationInit(queue, 'lib/mockapplication', ["antie/devices/mediaplayer/mediaplayer"],
function(application, MediaPlayer) {
deviceMockingHooks.mockTime(self._mediaPlayer);

self._clock = clock;
self._createElementStub = stubCreateElement(self.sandbox, application);
self._device = application.getDevice();
self._mediaPlayer = self._device.getMediaPlayer();
Expand All @@ -201,6 +202,28 @@ window.commonTests.mediaPlayer.html5.mixinTests = function (testCase, mediaPlaye
}, config);
};

var runMediaPlayerTestWithSpecificConfig = function (self, queue, action, newConfig) {
queuedApplicationInit(queue, 'lib/mockapplication', ["antie/devices/mediaplayer/mediaplayer"],
function(application, MediaPlayer) {
deviceMockingHooks.mockTime(self._mediaPlayer);
self._clock = clock;
self._createElementStub = stubCreateElement(self.sandbox, application);
self._device = application.getDevice();
self._mediaPlayer = self._device.getMediaPlayer();
self._application = application;

self._eventCallback = self.sandbox.stub();
self._mediaPlayer.addEventCallback(null, self._eventCallback);

try {
action.call(self, MediaPlayer);
}
finally {
deviceMockingHooks.unmockTime(self._mediaPlayer);
}
}, newConfig);
};

var fireSentinels = function (self) {
clock.tick(1100);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* @preserve Copyright (c) 2014 British Broadcasting Corporation
* (http://www.bbc.co.uk) and TAL Contributors (1)
*
* (1) TAL Contributors are listed in the AUTHORS file and at
* https://github.com/fmtvp/TAL/AUTHORS - please extend this file,
* not this notice.
*
* @license Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* All rights reserved
* Please contact us for an alternative licence
*/

(function() {
// jshint newcap: false
this.HTML5SeekFinishedEmitEventTests = AsyncTestCase("HTML5SeekFinishedEmitEvent");

var config = {"modules":{"base":"antie/devices/browserdevice","modifiers":["antie/devices/mediaplayer/html5seekfinishedemitevent"]}, "input":{"map":{}},"layouts":[{"width":960,"height":540,"module":"fixtures/layouts/default","classes":["browserdevice540p"]}],"deviceConfigurationKey":"devices-html5-1"};
var configWithRestartTimeout = {"restartTimeout":10000, "modules":{"base":"antie/devices/browserdevice","modifiers":["antie/devices/mediaplayer/html5seekfinishedemitevent"]}, "input":{"map":{}},"layouts":[{"width":960,"height":540,"module":"fixtures/layouts/default","classes":["browserdevice540p"]}],"deviceConfigurationKey":"devices-html5-1"};

var eventWasFired = function(self, eventType) {
for(var i = 0; i < self._eventCallback.args.length; i++) {
if(eventType === self._eventCallback.args[i][0].type) {
return true;
}
}
return false;
};

var eventNotFired = function(self, eventType) {
return !eventWasFired(self, eventType);
};

// ---------------
// Mix in the base HTML5 tests to make sure the sub-modifier doesn't break basic functionality
// ---------------
window.commonTests.mediaPlayer.html5.mixinTests(this.HTML5SeekFinishedEmitEventTests, "antie/devices/mediaplayer/html5seekfinishedemitevent", config);

// ---------------
// Remove tests that are irrelevant for this sub-modifier.
// ---------------

// ---------------
// Additional tests for this sub-modifier.
// ---------------

var getToPlaying = function(self, MediaPlayer) {
self._mediaPlayer.setSource(MediaPlayer.TYPE.VIDEO, 'http://testurl/', 'video/mp4');
self._mediaPlayer.beginPlaybackFrom(0);
self.deviceMockingHooks.sendMetadata(self._mediaPlayer, 0, { start: 0, end: 100 });
self.deviceMockingHooks.finishBuffering(self._mediaPlayer);
};

this.HTML5SeekFinishedEmitEventTests.prototype.testIfTimeIsInRangeAndHasBeenPlaying5TimesWithNoTimeoutWeFireSeekFinishedEvent = function(queue) {
var self = this;
expectAsserts(7);
this.runMediaPlayerTest(this, queue, function (MediaPlayer) {
getToPlaying(this, MediaPlayer);

assert(eventWasFired(self, MediaPlayer.EVENT.SEEK_ATTEMPTED));
for(var i = 0; i < 5; i++) {
self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventNotFired(self, MediaPlayer.EVENT.SEEK_FINISHED));
self._clock.tick(1000);
self.stubCreateElementResults.video.currentTime += 1;
self._eventCallback.reset();
}

self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventWasFired(self, MediaPlayer.EVENT.SEEK_FINISHED));
});
};

this.HTML5SeekFinishedEmitEventTests.prototype.testWeAlreadyFiredSeekFinishedEventDoNotFireAnother = function(queue) {
var self = this;
expectAsserts(8);
this.runMediaPlayerTest(this, queue, function (MediaPlayer) {
getToPlaying(this, MediaPlayer);

assert(eventWasFired(self, MediaPlayer.EVENT.SEEK_ATTEMPTED));
for(var i = 0; i < 5; i++) {
self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventNotFired(self, MediaPlayer.EVENT.SEEK_FINISHED));
self._clock.tick(1000);
self.stubCreateElementResults.video.currentTime += 1;
self._eventCallback.reset();
}

self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventWasFired(self, MediaPlayer.EVENT.SEEK_FINISHED));

self._eventCallback.reset();
self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
assert(eventNotFired(self, MediaPlayer.EVENT.SEEK_FINISHED));
});
};

this.HTML5SeekFinishedEmitEventTests.prototype.testIfTimeIsInRangeAndHasBeenPlaying5TimesWith10SecondTimeoutWeFireSeekFinishedEvent = function(queue) {
var self = this;
expectAsserts(12);
this.runMediaPlayerTestWithSpecificConfig(this, queue, function (MediaPlayer) {
getToPlaying(this, MediaPlayer);

assert(eventWasFired(self, MediaPlayer.EVENT.SEEK_ATTEMPTED));
for(var i = 0; i < 10; i++) {
self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
self._clock.tick(1000);
self.stubCreateElementResults.video.currentTime += 1;
assert(eventNotFired(self, MediaPlayer.EVENT.SEEK_FINISHED));
self._eventCallback.reset();
}

self.deviceMockingHooks.makeOneSecondPass(self._mediaPlayer);
self._clock.tick(1000);
assert(eventWasFired(self, MediaPlayer.EVENT.SEEK_FINISHED));
}, configWithRestartTimeout);
};
})();
14 changes: 14 additions & 0 deletions static/script/devices/mediaplayer/cehtmlseekfinishedemitevent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require.def(
"antie/devices/mediaplayer/cehtmlseekfinishedemitevent",
[
"antie/devices/mediaplayer/seekfinishedemitevent",
"antie/devices/mediaplayer/cehtml"
],
function (SeekFinishedEmitEvent, CEHTML) {
"use strict";

SeekFinishedEmitEvent(CEHTML);

return CEHTML;
}
);
Loading

0 comments on commit a47baa0

Please sign in to comment.