From 5123cfc4080fb5d55c94545866c20e61515b3d3c Mon Sep 17 00:00:00 2001 From: vrosenberg Date: Tue, 20 Jul 2021 13:39:04 +0200 Subject: [PATCH] check if stream offers thumbnail --- samples/functional-tests/index.html | 11 ++++++- test/functional/tests/scripts/constants.js | 10 ++++-- test/functional/tests/scripts/player.js | 6 ++-- test/functional/tests/thumbnails.js | 38 ++++++++++++---------- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/samples/functional-tests/index.html b/samples/functional-tests/index.html index e386769205..192defaeaf 100644 --- a/samples/functional-tests/index.html +++ b/samples/functional-tests/index.html @@ -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; + } + diff --git a/test/functional/tests/scripts/constants.js b/test/functional/tests/scripts/constants.js index c6b1c78f7b..53c319fcb9 100644 --- a/test/functional/tests/scripts/constants.js +++ b/test/functional/tests/scripts/constants.js @@ -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, + } +} \ No newline at end of file diff --git a/test/functional/tests/scripts/player.js b/test/functional/tests/scripts/player.js index d4e9c3ab6e..8d9cf44fcd 100644 --- a/test/functional/tests/scripts/player.js +++ b/test/functional/tests/scripts/player.js @@ -156,7 +156,9 @@ module.exports = { attachTTMLRenderingDiv: function(ttmlDiv){ player.attachTTMLRenderingDiv(ttmlDiv); - } - + }, + containsThumbnails: function(){ + return containsThumbnails(); + } }; diff --git a/test/functional/tests/thumbnails.js b/test/functional/tests/thumbnails.js index dc4ba32ee7..b4f071cdc3 100644 --- a/test/functional/tests/thumbnails.js +++ b/test/functional/tests/thumbnails.js @@ -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'); @@ -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(); @@ -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); });