Skip to content

Commit

Permalink
(test) WIP Create test for audio live stream
Browse files Browse the repository at this point in the history
[Issue #11]
[PR #12]
  • Loading branch information
Lindsay-Needs-Sleep committed Nov 2, 2020
1 parent 508ce1a commit 07e9c89
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
24 changes: 24 additions & 0 deletions tests/www/js/tests_auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,30 @@
assert.fail('Unexpected Error: ' + err.code + ': ' + err.description);
});
});
it('session.loadMedia should be able to load live stream audio media', function (done) {
this.timeout(90000);
var mediaInfo = mediaUtils.getMediaInfoItem('LIVE_AUDIO');
session.loadMedia(new chrome.cast.media.LoadRequest(mediaInfo), function (m) {
media = m;
utils.testMediaProperties(media, true);
mediaUtils.assertMediaInfoItemEquals(media.media, mediaInfo);
media.addUpdateListener(function listener (isAlive) {
assert.isTrue(isAlive);
utils.testMediaProperties(media, true);
mediaUtils.assertMediaInfoItemEquals(media.media, mediaInfo);
assert.oneOf(media.playerState, [
chrome.cast.media.PlayerState.PLAYING,
chrome.cast.media.PlayerState.BUFFERING]);
if (media.playerState === chrome.cast.media.PlayerState.PLAYING) {
console.log(media);
media.removeUpdateListener(listener);
done();
}
});
}, function (err) {
assert.fail('Unexpected Error: ' + err.code + ': ' + err.description);
});
});
it('session.loadMedia should be able to load remote image and return the PhotoMediaMetadata', function (done) {
var mediaInfo = mediaUtils.getMediaInfoItem('IMAGE', chrome.cast.media.MetadataType.PHOTO);
session.loadMedia(new chrome.cast.media.LoadRequest(mediaInfo), function (m) {
Expand Down
4 changes: 4 additions & 0 deletions tests/www/lib/mediaGenerateAndAssert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

var audioUrl = 'https://ia800306.us.archive.org/26/items/1939RadioNews/1939-10-24-CBS-Elmer-Davis-Reports-City-Of-Flint-Still-Missing.mp3';
var imageUrl = 'https://ia800705.us.archive.org/1/items/GoodHousekeeping193810/Good%20Housekeeping%201938-10.jpg';
var liveAudioUrl = 'http://relay.publicdomainproject.org/classical.mp3';
var videoUrl = 'https://ia801302.us.archive.org/1/items/TheWater_201510/TheWater.mp4';

var mediaUtils = {
Expand All @@ -23,6 +24,9 @@
},
'IMAGE': function () {
return new chrome.cast.media.MediaInfo(imageUrl, 'image/jpeg');
},
'LIVE_AUDIO': function () {
return new chrome.cast.media.MediaInfo(liveAudioUrl, 'audio/mpeg');
}
}
};
Expand Down
19 changes: 12 additions & 7 deletions tests/www/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@
assert.isFunction(session.loadMedia);
};

utils.testMediaProperties = function (media) {
utils.testMediaProperties = function (media, isLiveStream) {
assert.instanceOf(media, chrome.cast.media.Media);
assert.isNumber(media.currentItemId);
assert.isNumber(media.currentTime);
if (media.idleReason) {
assert.oneOf(media.idleReason, utils.getObjectValues(chrome.cast.media.IdleReason));
}
utils.testMediaInfoProperties(media.media);
utils.testMediaInfoProperties(media.media, isLiveStream);
assert.isNumber(media.mediaSessionId);
assert.isNumber(media.playbackRate);
assert.oneOf(media.playerState, utils.getObjectValues(chrome.cast.media.PlayerState));
Expand All @@ -298,14 +298,19 @@
assert.isFunction(media.removeUpdateListener);
};

utils.testMediaInfoProperties = function (mediaInfo) {
utils.testMediaInfoProperties = function (mediaInfo, isLiveStream) {
// queue items contain a subset of identical properties
utils.testQueueItemMediaInfoProperties(mediaInfo);
// properties that are exclusive (or mandatory) to media.media
assert.isNumber(mediaInfo.duration);
if (mediaInfo.contentType.toLowerCase().indexOf('video') > -1
|| mediaInfo.contentType.toLowerCase().indexOf('audio') > -1) {
assert.isAbove(mediaInfo.duration, 0);
if (isLiveStream) {
// Live stream has null duration
assert.isNull(mediaInfo.duration);
} else {
assert.isNumber(mediaInfo.duration);
if (mediaInfo.contentType.toLowerCase().indexOf('video') > -1
|| mediaInfo.contentType.toLowerCase().indexOf('audio') > -1) {
assert.isAbove(mediaInfo.duration, 0);
}
}
assert.isArray(mediaInfo.tracks);
};
Expand Down

0 comments on commit 07e9c89

Please sign in to comment.