Skip to content

Commit

Permalink
Move FakeDrmEngine To Its Own File
Browse files Browse the repository at this point in the history
As DrmEngine has changed over time, FakeDrmEngine has grown
less and less simple. So this change moves it from simple_fakes.js
to its own file.

Change-Id: I28c53d82c35b5b26be7d2f3591730dcd5f4e5fec
  • Loading branch information
vaage committed Aug 20, 2018
1 parent 3b25ee8 commit d2b727d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 64 deletions.
106 changes: 106 additions & 0 deletions test/test/util/fake_drm_engine.js
Original file line number Diff line number Diff line change
@@ -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.<number>} */
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.<number>} sessions
*/
setSessionIds(sessions) {
// Copy the values to break the reference to the input value.
this.offlineSessions_ = sessions.map((s) => s);
}
};
64 changes: 0 additions & 64 deletions test/test/util/simple_fakes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.<string>} sessions */
shaka.test.FakeDrmEngine.prototype.setSessionIds;


/**
* A fake StreamingEngine.
*
Expand Down

0 comments on commit d2b727d

Please sign in to comment.