Skip to content

Commit

Permalink
check if stream offers thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
vrosenberg committed Jul 20, 2021
1 parent f9eb07f commit 5123cfc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
11 changes: 10 additions & 1 deletion samples/functional-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
return playing;
}

async function containsThumbnails(){
var promise = new Promise(function(resolve,reject){
player.provideThumbnail(0, resolve)
})
if(await promise) return true;
return false;
}

</script>

<style>
Expand All @@ -58,7 +66,8 @@
height: 100%;
}
.seekbar{
width: 201px;
width: 220px;
height: 7px;
}
</style>

Expand Down
10 changes: 8 additions & 2 deletions test/functional/tests/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ module.exports = {
EVENT_TIMEOUT: 10, // Timeout (in sec.) for receiving player or video element events
PROGRESS_DELAY: 3, // Playback progress delay (in sec.) to be checked
SEEK_END_SHIFT: 10, // Shift (in sec.) when seeking to end
DURATION_TOLERANCE: 3 // Tolerance for duration (for seeking)
}
DURATION_TOLERANCE: 3, // Tolerance for duration (for seeking)

SEEKBAR: { // seekbar see \samples\functional-tests\index.html
width: 220,
height: 7,
thumbnailPaddingLeftRight: 5,
}
}
6 changes: 4 additions & 2 deletions test/functional/tests/scripts/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ module.exports = {

attachTTMLRenderingDiv: function(ttmlDiv){
player.attachTTMLRenderingDiv(ttmlDiv);
}

},

containsThumbnails: function(){
return containsThumbnails();
}
};
38 changes: 21 additions & 17 deletions test/functional/tests/thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ PLAY:
- load test page
- load stream
- check playing state
- check if playback progressing
- skip if no thumbnail stream
- check position of thumbnail
**/
const intern = require('intern').default;
const { suite, before, test, after } = intern.getPlugin('interface.tdd');
const { suite, before, test } = intern.getPlugin('interface.tdd');
const { assert } = intern.getPlugin('chai');

const constants = require('./scripts/constants.js');
Expand All @@ -16,6 +17,9 @@ const player = require('./scripts/player.js');
// Suite name
const NAME = 'THUMBNAIL';

// Test constants
const SLEEP = 3; // sleep duration in sec

/** return the current timestamp of the thumbnail in sec */
async function currTimeStamp(thumbnail_time_label){
var timestamp = await thumbnail_time_label.getVisibleText();
Expand All @@ -32,37 +36,37 @@ exports.register = function (stream) {
utils.log(NAME, 'Load stream');
command = remote.get(intern.config.testPage);
await command.execute(player.loadStream, [stream]);
});

test('play', async () => {
utils.log(NAME, 'Play');

// check thumbnail at seekbar pos (in px)
var currPixel = 7;

// check if playing
const playing = await command.executeAsync(player.isPlaying, [constants.EVENT_TIMEOUT]);
stream.available = playing;
assert.isTrue(playing);

var hasThumbnail = await command.execute(player.containsThumbnails, []);
if(!hasThumbnail) suite.skip();
});

test('check position', async () => {
utils.log(NAME, 'Check Position');

// check thumbnail at seekbar rand pos not too close to the left and right end (in px)
var currPixel = Math.floor(Math.random() * (constants.SEEKBAR.width - constants.SEEKBAR.thumbnailPaddingLeftRight * 2)) + constants.SEEKBAR.thumbnailPaddingLeftRight;

// setup values
await command.sleep(SLEEP * 1000);
var element = await command.findById('seekbar');
await command.moveMouseTo(element,currPixel,4);
await command.sleep(5000);
var size = await command.findById('seekbar').getSize();
await command.moveMouseTo(element,currPixel,Math.floor(constants.SEEKBAR.height/2));
await command.sleep(SLEEP * 1000);

// get curr timestamp
var timeLabelElement = await command.findById('thumbnail-time-label');
actualTimeStamp = await currTimeStamp(timeLabelElement);
console.log(actualTimeStamp);

// expected timestamp
const duration = await command.execute(player.getDuration);
var expectedTimeStamp = currPixel/size.width * duration;
console.log(expectedTimeStamp);
var expectedTimeStamp = currPixel/constants.SEEKBAR.width * duration;

// delta, if actual thumbnail is within a pixel range
var delta = Math.abs(expectedTimeStamp - (currPixel+1)/size.width * duration);
var delta = Math.abs(expectedTimeStamp - (currPixel+1)/constants.SEEKBAR.width * duration);

assert.approximately(actualTimeStamp,expectedTimeStamp,delta);
});
Expand Down

0 comments on commit 5123cfc

Please sign in to comment.