/**
* @license
* Copyright 2015 Google Inc.
*
* 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.
*/
goog.require('shaka.dash.mpd');
describe('mpd.BaseUrl', function() {
it('resolves relative and absolute URLs at every level', function() {
var source = [
'',
' http://example.com/',
' ',
' Period1/',
' ',
' AdaptationSet1/',
' ',
' Representation1',
' ',
' ',
' ',
' ',
' Period2',
' ',
' AdaptationSet2',
' ',
' Representation2',
' ',
' ',
' ',
' ',
' /Period3/',
' ',
' /AdaptationSet3',
' ',
' ?Representation3',
' ',
' ',
' #Representation4',
' ',
' ',
' http://foo.bar/',
' ',
' ',
' ',
' http://foo.bar/multi/level',
' ',
' ?Representation5',
' ',
' ',
' ',
''].join('\n');
var mpd = shaka.dash.mpd.parseMpd(source, createFailover('').urls);
expect(mpd).toBeTruthy();
expect(mpd.baseUrl.toString()).toBe('http://example.com/');
expect(mpd.periods.length).toBe(3);
var p = mpd.periods;
expect(p[0].baseUrl.toString()).
toBe('http://example.com/Period1/');
expect(p[0].adaptationSets[0].baseUrl.toString()).
toBe('http://example.com/Period1/AdaptationSet1/');
expect(p[0].adaptationSets[0].representations[0].baseUrl.toString()).
toBe('http://example.com/Period1/AdaptationSet1/Representation1');
expect(p[1].baseUrl.toString()).
toBe('http://example.com/Period2');
expect(p[1].adaptationSets[0].baseUrl.toString()).
toBe('http://example.com/AdaptationSet2');
expect(p[1].adaptationSets[0].representations[0].baseUrl.toString()).
toBe('http://example.com/Representation2');
expect(p[2].baseUrl.toString()).
toBe('http://example.com/Period3/');
expect(p[2].adaptationSets[0].baseUrl.toString()).
toBe('http://example.com/AdaptationSet3');
expect(p[2].adaptationSets[0].representations[0].baseUrl.toString()).
toBe('http://example.com/AdaptationSet3?Representation3');
expect(p[2].adaptationSets[0].representations[1].baseUrl.toString()).
toBe('http://example.com/AdaptationSet3#Representation4');
expect(p[2].adaptationSets[0].representations[2].baseUrl.toString()).
toBe('http://foo.bar/');
expect(p[2].adaptationSets[1].baseUrl.toString()).
toBe('http://foo.bar/multi/level');
expect(p[2].adaptationSets[1].representations[0].baseUrl.toString()).
toBe('http://foo.bar/multi/level?Representation5');
});
it('resolves relative URLs across levels', function() {
var source = [
'',
' sub/',
' ',
' ',
' ',
' 1.webm',
' ',
' ',
' 2.webm',
' ',
' ',
' ',
''].join('\n');
var mpd = shaka.dash.mpd.parseMpd(source, createFailover('').urls);
expect(mpd).toBeTruthy();
expect(mpd.baseUrl.toString()).toBe('sub/');
expect(mpd.periods.length).toBe(1);
var p = mpd.periods[0];
expect(p.baseUrl.toString()).toBe('sub/');
expect(p.adaptationSets.length).toBe(1);
var as = p.adaptationSets[0];
expect(as.baseUrl.toString()).toBe('sub/');
expect(as.representations.length).toBe(2);
var r = as.representations;
expect(r[0].baseUrl.toString()).toBe('sub/1.webm');
expect(r[1].baseUrl.toString()).toBe('sub/2.webm');
});
it('resolves relative URLs with respect to the MPD URL', function() {
var source = [
'',
' ',
' ',
' ',
' 1.webm',
' ',
' ',
' ',
''].join('\n');
var mpdUrl = 'http://example.com/dash/test.mpd';
var mpd = shaka.dash.mpd.parseMpd(source, createFailover(mpdUrl).urls);
expect(mpd).toBeTruthy();
expect(mpd.baseUrl.toString()).toBe(mpdUrl);
expect(mpd.periods.length).toBe(1);
var p = mpd.periods[0];
expect(p.baseUrl.toString()).toBe(mpdUrl);
expect(p.adaptationSets.length).toBe(1);
var as = p.adaptationSets[0];
expect(as.baseUrl.toString()).toBe(mpdUrl);
expect(as.representations.length).toBe(1);
var r = as.representations[0];
expect(r.baseUrl.toString()).toBe('http://example.com/dash/1.webm');
});
it('supports multiple Base URLs', function() {
var source = [
'',
' http://www.example.com/',
' ',
' ',
' ',
' 1.webm',
' 2.webm',
' ',
' ',
' ',
''].join('\n');
var mpdUrl = createFailover('').urls;
var mpd = shaka.dash.mpd.parseMpd(source, mpdUrl);
expect(mpd).toBeTruthy();
expect(mpd.periods.length).toBe(1);
var p = mpd.periods[0];
expect(p.adaptationSets.length).toBe(1);
var as = p.adaptationSets[0];
expect(as.representations.length).toBe(1);
var r = as.representations[0];
expect(r.baseUrl).toBeTruthy();
expect(r.baseUrl.length).toBe(2);
expect(r.baseUrl[0].toString()).toBe('http://www.example.com/1.webm');
expect(r.baseUrl[1].toString()).toBe('http://www.example.com/2.webm');
});
it('overrides multiple Base URLs', function() {
var source = [
'',
' http://www.example.com/',
' http://www.google.com/',
' ',
' ',
' ',
' 1.webm',
' 2.webm',
' ',
' ',
' ',
''].join('\n');
var mpdUrl = createFailover('').urls;
var mpd = shaka.dash.mpd.parseMpd(source, mpdUrl);
expect(mpd).toBeTruthy();
expect(mpd.periods.length).toBe(1);
var p = mpd.periods[0];
expect(p.adaptationSets.length).toBe(1);
var as = p.adaptationSets[0];
expect(as.representations.length).toBe(1);
var r = as.representations[0];
expect(r.baseUrl).toBeTruthy();
expect(r.baseUrl.length).toBe(2);
expect(r.baseUrl[0].toString()).toBe('http://www.example.com/1.webm');
expect(r.baseUrl[1].toString()).toBe('http://www.example.com/2.webm');
});
it('handles multiple Base URLs in media urls', function() {
var source = [
'',
' http://www.example.com/',
' ',
' ',
' ',
' cat/',
' dog/',
' ',
' ',
' ',
' ',
' ',
' ',
''].join('\n');
var mpdUrl = createFailover('').urls;
var mpd = shaka.dash.mpd.parseMpd(source, mpdUrl);
expect(mpd).toBeTruthy();
expect(mpd.periods.length).toBe(1);
var p = mpd.periods[0];
expect(p.adaptationSets.length).toBe(1);
var as = p.adaptationSets[0];
expect(as.representations.length).toBe(1);
var r = as.representations[0];
expect(r.baseUrl).toBeTruthy();
expect(r.baseUrl.length).toBe(2);
expect(r.baseUrl[0].toString()).toBe('http://www.example.com/cat/');
expect(r.baseUrl[1].toString()).toBe('http://www.example.com/dog/');
var sl = r.segmentList;
expect(sl).toBeTruthy();
expect(sl.segmentUrls.length).toBe(2);
var url1 = sl.segmentUrls[0];
expect(url1.mediaUrl.length).toBe(2);
expect(url1.mediaUrl[0].toString()).toBe(
'http://www.example.com/cat/a/1.webm');
expect(url1.mediaUrl[1].toString()).toBe(
'http://www.example.com/dog/a/1.webm');
var url2 = sl.segmentUrls[1];
expect(url2.mediaUrl.length).toBe(2);
expect(url2.mediaUrl[0].toString()).toBe(
'http://www.example.com/cat/a/2.webm');
expect(url2.mediaUrl[1].toString()).toBe(
'http://www.example.com/dog/a/2.webm');
});
});