Files
shaka-player/test/offline/offline_scheme_unit.js
T
Aaron Vaage 33547d071c Stubbing-in Mechanism & Cell Fields in Offline Uri
Adding "mechanism" and "cell" fields to offline uri. But since
they are not used anywhere, this change sets them to dummy values
so that all the constructors could be updated.

Moved the manifest reconstruction code into a instance class as
the mechanism and cell for the asset is needed in order to create
all the segment uris.

Change-Id: I2b5738805b17c4aa33d39b3166fddf1528aed489
2018-03-27 21:19:47 +00:00

144 lines
4.6 KiB
JavaScript

/**
* @license
* Copyright 2016 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.
*/
describe('OfflineScheme', function() {
const OfflineScheme = shaka.offline.OfflineScheme;
describe('Get data from storage', function() {
let mockSEFactory = new shaka.test.MockStorageEngineFactory();
/** @type {!shaka.offline.IStorageEngine} */
let fakeStorageEngine;
/** @type {shakaExtern.Request} */
let request;
beforeEach(function() {
fakeStorageEngine = new shaka.test.MemoryStorageEngine();
mockSEFactory.overrideIsSupported(true);
mockSEFactory.overrideCreate(function() {
return Promise.resolve(fakeStorageEngine);
});
// The whole request is ignored by the OfflineScheme.
let retry = shaka.net.NetworkingEngine.defaultRetryParameters();
request = shaka.net.NetworkingEngine.makeRequest([], retry);
});
afterEach(function() {
mockSEFactory.resetAll();
});
it('will return special content-type header for manifests', function(done) {
/** @type {!shaka.offline.OfflineUri} */
let uri;
Promise.resolve()
.then(function() {
return fakeStorageEngine.addManifest({
originalManifestUri: '',
duration: 0,
size: 0,
expiration: 0,
periods: [],
sessionIds: [],
drmInfo: null,
appMetadata: {}
});
})
.then(function(id) {
uri = shaka.offline.OfflineUri.manifest(
'mechanism', 'cell', id);
return OfflineScheme(uri.toString(), request).promise;
})
.then(function(response) {
expect(response).toBeTruthy();
expect(response.uri).toBe(uri.toString());
expect(response.headers['content-type'])
.toBe('application/x-offline-manifest');
})
.catch(fail)
.then(done);
});
it('will get segment data from storage engine', function(done) {
const originalData = new Uint8Array([0, 1, 2, 3]);
/** @type {!shaka.offline.OfflineUri} */
let uri;
Promise.resolve()
.then(function() {
return fakeStorageEngine.addSegment({
data: originalData.buffer
});
})
.then(function(id) {
uri = shaka.offline.OfflineUri.segment('mechanism', 'cell', id);
return OfflineScheme(uri.toString(), request).promise;
})
.then(function(response) {
expect(response).toBeTruthy();
expect(response.uri).toBe(uri.toString());
expect(response.data).toBeTruthy();
const responseData = new Uint8Array(response.data);
expect(responseData).toEqual(originalData);
})
.catch(fail)
.then(done);
});
it('will fail if segment not found', function(done) {
const id = 789;
const uri = shaka.offline.OfflineUri.segment('mechanism', 'cell', id);
OfflineScheme(uri.toString(), request).promise
.then(fail)
.catch(function(err) {
shaka.test.Util.expectToEqualError(
err,
new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.STORAGE,
shaka.util.Error.Code.REQUESTED_ITEM_NOT_FOUND,
id));
})
.catch(fail)
.then(done);
});
it('will fail for invalid URI', function(done) {
/** @type {string} */
let uri = 'offline:this-is-invalid';
OfflineScheme(uri, request).promise
.then(fail)
.catch(function(err) {
shaka.test.Util.expectToEqualError(
err,
new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.MALFORMED_OFFLINE_URI,
uri));
})
.then(done);
});
});
});