diff --git a/test/test/util/fake_drm_engine.js b/test/test/util/fake_drm_engine.js new file mode 100644 index 0000000000..84373fc4f1 --- /dev/null +++ b/test/test/util/fake_drm_engine.js @@ -0,0 +1,106 @@ +/** + * @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. + */ + +goog.provide('shaka.test.FakeDrmEngine'); + + +/** + * A fake DrmEngine. + * + * @extends {shaka.media.DrmEngine} + */ +shaka.test.FakeDrmEngine = class { + constructor() { + /** @private {!Array.} */ + this.offlineSessions_ = []; + /** @private {?shaka.extern.DrmInfo} */ + this.drmInfo_ = null; + + const resolved = Promise.resolve(); + + /** @type {!jasmine.Spy} */ + this.attach = jasmine.createSpy('attach'); + this.attach.and.returnValue(resolved); + + /** @type {!jasmine.Spy} */ + this.configure = jasmine.createSpy('configure'); + + // Because of the |IDestroyable| interface, we need to cast destroy to be + // a function so that closure will understand that FakeDrmEngine still meets + // the interface requirements. + /** @type {!jasmine.Spy} */ + const destroySpy = jasmine.createSpy('destroy'); + destroySpy.and.returnValue(resolved); + this.destroy = shaka.test.Util.spyFunc(destroySpy); + + /** @type {!jasmine.Spy} */ + this.getDrmInfo = jasmine.createSpy('getDrmInfo'); + // We use |callFake| to ensure that updated values of |this.drmInfo_| will + // be returned. + this.getDrmInfo.and.callFake(() => this.drmInfo_); + + /** @type {!jasmine.Spy} */ + this.getExpiration = jasmine.createSpy('getExpiration'); + this.getExpiration.and.returnValue(Infinity); + + /** @type {!jasmine.Spy} */ + this.getKeyStatuses = jasmine.createSpy('getKeyStatuses'); + this.getKeyStatuses.and.returnValue({}); + + /** @type {!jasmine.Spy} */ + this.getSessionIds = jasmine.createSpy('getSessionIds'); + this.getSessionIds.and.callFake(() => this.offlineSessions_); + + /** + * See |shaka.test.ManifestGenerator.protototype.createStream|. + * @type {!jasmine.Spy} + */ + this.getSupportedTypes = jasmine.createSpy('getSupportedTypes'); + this.getSupportedTypes.and.returnValue(['video/mp4; codecs="avc1.4d401f"']); + + /** @type {!jasmine.Spy} */ + this.init = jasmine.createSpy('init'); + this.init.and.returnValue(resolved); + + /** @type {!jasmine.Spy} */ + this.initialized = jasmine.createSpy('initialized'); + this.initialized.and.returnValue(true); + + /** @type {!jasmine.Spy} */ + this.isSupportedByKeySystem = jasmine.createSpy('isSupportedByKeySystem'); + this.isSupportedByKeySystem.and.returnValue(true); + + /** @type {!jasmine.Spy} */ + this.keySystem = jasmine.createSpy('keySystem'); + this.keySystem.and.returnValue('com.example.fake'); + } + + /** + * @param {shaka.extern.DrmInfo} info + */ + setDrmInfo(info) { + this.drmInfo_ = info; + } + + /** + * @param {!Array.} sessions + */ + setSessionIds(sessions) { + // Copy the values to break the reference to the input value. + this.offlineSessions_ = sessions.map((s) => s); + } +}; diff --git a/test/test/util/simple_fakes.js b/test/test/util/simple_fakes.js index 8448477237..c7e09cbfdd 100644 --- a/test/test/util/simple_fakes.js +++ b/test/test/util/simple_fakes.js @@ -16,7 +16,6 @@ */ goog.provide('shaka.test.FakeAbrManager'); -goog.provide('shaka.test.FakeDrmEngine'); goog.provide('shaka.test.FakeManifestParser'); goog.provide('shaka.test.FakePlayhead'); goog.provide('shaka.test.FakePlayheadObserver'); @@ -113,69 +112,6 @@ shaka.test.FakeAbrManager.prototype.setVariants; shaka.test.FakeAbrManager.prototype.configure; -/** - * A fake DrmEngine. - * - * @constructor - * @struct - * @extends {shaka.media.DrmEngine} - * @return {!Object} - */ -shaka.test.FakeDrmEngine = function() { - let resolve = Promise.resolve.bind(Promise); - let offlineSessionIds = []; - let drmInfo = null; - - let ret = jasmine.createSpyObj('FakeDrmEngine', [ - 'attach', 'configure', 'destroy', 'getDrmInfo', 'getExpiration', - 'getKeyStatuses', 'getSessionIds', 'getSupportedTypes', 'init', - 'initialized', 'isSupportedByKeySystem', 'keySystem', - ]); - ret.attach.and.callFake(resolve); - ret.destroy.and.callFake(resolve); - ret.init.and.callFake(resolve); - ret.initialized.and.returnValue(true); - ret.keySystem.and.returnValue('com.example.fake'); - ret.getExpiration.and.returnValue(Infinity); - ret.getKeyStatuses.and.returnValue({}); - // See shaka.test.ManifestGenerator.protototype.createStream. - ret.getSupportedTypes.and.returnValue( - ['video/mp4; codecs="avc1.4d401f"']); - - ret.setSessionIds = function(sessions) { - offlineSessionIds = sessions; - }; - ret.setDrmInfo = function(info) { drmInfo = info; }; - ret.getDrmInfo.and.callFake(function() { return drmInfo; }); - ret.getSessionIds.and.callFake(function() { - return offlineSessionIds; - }); - ret.isSupportedByKeySystem.and.returnValue(true); - - return ret; -}; - - -/** @type {jasmine.Spy} */ -shaka.test.FakeDrmEngine.prototype.init; - - -/** @type {jasmine.Spy} */ -shaka.test.FakeDrmEngine.prototype.attach; - - -/** @type {jasmine.Spy} */ -shaka.test.FakeDrmEngine.prototype.getExpiration; - - -/** @param {?shaka.extern.DrmInfo} info */ -shaka.test.FakeDrmEngine.prototype.setDrmInfo; - - -/** @param {!Array.} sessions */ -shaka.test.FakeDrmEngine.prototype.setSessionIds; - - /** * A fake StreamingEngine. *