Correct type info in tests

In many places in the tests, we used "Object" or "*" or just no type
at all for various fakes.  These were all flagged by the new Closure
Compiler version we are adopting.

In some other places, we mixed up similar types or had the wrong
nullability on a type.

In still others, types were missing fields.

These issues were caught by a compiler upgrade.

Issue #2528

Change-Id: I324e0b28f7e30a4102aa26ec2c9901fa9732211b
This commit is contained in:
Joey Parrish
2020-04-28 20:50:34 -07:00
parent 7ee124c2c1
commit 4eefaa44cb
20 changed files with 83 additions and 64 deletions
+2 -2
View File
@@ -329,8 +329,8 @@ filterDescribe('CastReceiver', castReceiverIntegrationSupport, () => {
}
/**
* @param {?} message
* @param {!Object} bus
* @param {*} message
* @param {!cast.receiver.CastMessageBus} bus
* @param {string=} senderId
*/
function fakeIncomingMessage(message, bus, senderId) {
+6 -4
View File
@@ -271,6 +271,8 @@ filterDescribe('CastReceiver', castReceiverSupport, () => {
mockVideo, mockPlayer, Util.spyFunc(mockAppDataCallback));
fakeInitState = {
manifest: null,
startTime: null,
player: {
configure: fakeConfig,
},
@@ -307,7 +309,7 @@ filterDescribe('CastReceiver', castReceiverSupport, () => {
// The rest is done async:
await shaka.test.Util.shortDelay();
expect(mockPlayer.setTextTrackVisibility).toHaveBeenCalledWith(
fakeInitState['playerAfterLoad'].setTextTrackVisibility);
fakeInitState.playerAfterLoad.setTextTrackVisibility);
expect(mockVideo.loop).toBe(fakeInitState.video.loop);
expect(mockVideo.playbackRate).toBe(fakeInitState.video.playbackRate);
});
@@ -418,7 +420,7 @@ filterDescribe('CastReceiver', castReceiverSupport, () => {
// State was still transferred, though:
expect(mockPlayer.setTextTrackVisibility).toHaveBeenCalledWith(
fakeInitState['playerAfterLoad'].setTextTrackVisibility);
fakeInitState.playerAfterLoad.setTextTrackVisibility);
expect(mockVideo.loop).toBe(fakeInitState.video.loop);
expect(mockVideo.playbackRate).toBe(fakeInitState.video.playbackRate);
});
@@ -988,8 +990,8 @@ filterDescribe('CastReceiver', castReceiverSupport, () => {
}
/**
* @param {?} message
* @param {!Object} bus
* @param {*} message
* @param {!cast.receiver.CastMessageBus} bus
* @param {string=} senderId
*/
function fakeIncomingMessage(message, bus, senderId) {
+1 -1
View File
@@ -2061,7 +2061,7 @@ describe('HlsParser', () => {
// We are assuming that the time will be pulled out of the main mp4
// segment, so if we see a request that has a range header, we will stop
// the parser.
/** @type {!Map.<string, !ArrayBuffer>} */
/** @type {!Map.<string, !BufferSource>} */
const responses = new Map();
responses.set('test:/main.mp4', segmentData);
responses.set('test:/init.mp4', initSegmentData);
+3 -2
View File
@@ -758,8 +758,9 @@ describe('DrmEngine', () => {
expect(session.generateRequest)
.toHaveBeenCalledWith('keyids', jasmine.any(Uint8Array));
const initData = JSON.parse(shaka.util.StringUtils.fromUTF8(
session.generateRequest.calls.argsFor(0)[1]));
const initData = /** @type {{kids: !Array.<string>}} */(JSON.parse(
shaka.util.StringUtils.fromUTF8(
session.generateRequest.calls.argsFor(0)[1])));
const keyId1 = Uint8ArrayUtils.toHex(
Uint8ArrayUtils.fromBase64(initData.kids[0]));
const keyId2 = Uint8ArrayUtils.toHex(
+1 -1
View File
@@ -1183,7 +1183,7 @@ describe('MediaSourceEngine', () => {
function createMockTextEngineCtor() {
const ctor = jasmine.createSpy('TextEngine');
ctor.isTypeSupported = () => true;
ctor['isTypeSupported'] = () => true;
ctor.and.callFake(() => {
expect(mockTextEngine).toBeFalsy();
mockTextEngine = jasmine.createSpyObj('TextEngine', [
+4 -1
View File
@@ -58,7 +58,8 @@ let PlayingTestInfo;
* seekTo: number,
* expectedEndTime: number,
* expectEvent: boolean,
* jumpLargeGaps: (boolean|undefined)
* jumpLargeGaps: (boolean|undefined),
* preventDefault: (boolean|undefined)
* }}
*
* @description
@@ -83,6 +84,8 @@ let PlayingTestInfo;
* If true, expect the 'largegap' event to be fired.
* @property {(boolean|undefined)} jumpLargeGaps
* If given, set this field of the Playhead configuration.
* @property {(boolean|undefined)} preventDefault
* If true, call preventDefault() on the 'largegap' event.
*/
let SeekTestInfo;
+2 -2
View File
@@ -58,9 +58,9 @@ filterDescribe('Offline', supportsStorage, () => {
const contentUri = content.offlineUri;
goog.asserts.assert(
contentUri, 'Stored content should have an offline uri.');
contentUri != null, 'Stored content should have an offline uri.');
await player.load(content.offlineUri);
await player.load(contentUri);
video.play();
await playTo(/* end= */ 3, /* timeout= */ 10);
+1 -1
View File
@@ -16,7 +16,7 @@ async function drmStorageSupport() {
const support = await shaka.Player.probeSupport();
const widevineSupport = support.drm['com.widevine.alpha'];
return widevineSupport && widevineSupport.persistentState;
return !!(widevineSupport && widevineSupport.persistentState);
}
filterDescribe('Storage', storageSupport, () => {
+5 -5
View File
@@ -734,14 +734,14 @@ describe('Player', () => {
it('does not pollute other advanced DRM configs', () => {
player.configure('drm.advanced.foo', {});
player.configure('drm.advanced.bar', {});
const fooConfig1 = player.getConfiguration().drm.advanced.foo;
const barConfig1 = player.getConfiguration().drm.advanced.bar;
const fooConfig1 = player.getConfiguration().drm.advanced['foo'];
const barConfig1 = player.getConfiguration().drm.advanced['bar'];
expect(fooConfig1.distinctiveIdentifierRequired).toBe(false);
expect(barConfig1.distinctiveIdentifierRequired).toBe(false);
player.configure('drm.advanced.foo.distinctiveIdentifierRequired', true);
const fooConfig2 = player.getConfiguration().drm.advanced.foo;
const barConfig2 = player.getConfiguration().drm.advanced.bar;
const fooConfig2 = player.getConfiguration().drm.advanced['foo'];
const barConfig2 = player.getConfiguration().drm.advanced['bar'];
expect(fooConfig2.distinctiveIdentifierRequired).toBe(true);
expect(barConfig2.distinctiveIdentifierRequired).toBe(false);
});
@@ -1585,7 +1585,7 @@ describe('Player', () => {
// choices are limited only by channel count and key status.
for (const variant of manifest.variants) {
const keyId = (variant.audio.id % 2) ? 'aaa' : 'bbb';
variant.audio.keyId = keyId;
variant.audio.keyIds = new Set([keyId]);
variant.video.roles = [];
variant.audio.roles = [];
}
+2 -2
View File
@@ -289,11 +289,11 @@ describe('Walker', () => {
const goToC = startNewRoute(nodeC, /* interruptible= */ false);
const goToB = startNewRoute(nodeB, /* interruptible= */ true);
/** @type {jasmine.Spy} */
/** @type {!jasmine.Spy} */
const canceledCSpy = jasmine.createSpy('cancel c');
goToC.onCancel = shaka.test.Util.spyFunc(canceledCSpy);
/** @type {jasmine.Spy} */
/** @type {!jasmine.Spy} */
const canceledBSpy = jasmine.createSpy('cancel b');
goToB.onCancel = shaka.test.Util.spyFunc(canceledBSpy);
+11 -7
View File
@@ -223,7 +223,7 @@ jasmine.SpyStrategy = function() {};
/**
* @param {...*} varArgs
* @return {*}
* @return {?}
*/
jasmine.SpyStrategy.prototype.exec = function(varArgs) {};
@@ -271,15 +271,15 @@ jasmine.SpyStrategy.prototype.stub = function() {};
jasmine.CallContext = function() {};
/** @const {*} */
/** @const {?} */
jasmine.CallContext.prototype.object;
/** @const {!Array.<*>} */
/** @const {!Array.<?>} */
jasmine.CallContext.prototype.args;
/** @const {*} */
/** @const {?} */
jasmine.CallContext.prototype.returnValue;
@@ -300,12 +300,12 @@ jasmine.CallTracker.prototype.count = function() {};
/**
* @param {number} i
* @return {!Array.<*>}
* @return {!Array.<?>}
*/
jasmine.CallTracker.prototype.argsFor = function(i) {};
/** @return {!Array.<!Array.<*>>} */
/** @return {!Array.<!Array.<?>>} */
jasmine.CallTracker.prototype.allArgs = function() {};
@@ -375,9 +375,13 @@ jasmine.any = function(factory) {};
jasmine.anything = function() {};
/** @typedef {{ sample: ? }} */
jasmine.ObjectContainingType;
/**
* @param {!Object} value
* @return {!Object}
* @return {jasmine.ObjectContainingType}
*/
jasmine.objectContaining = function(value) {};
+5 -3
View File
@@ -29,7 +29,7 @@ shaka.test.CannedIDB = class {
static async dumpJSON(name, dummyArrayBuffers) {
const savedDatabase = await this.dump(name);
const replacer =
(key, value) => this.replacer_(dummyArrayBuffers, key, value);
(key, value) => this.replacer_(dummyArrayBuffers || false, key, value);
return JSON.stringify(savedDatabase, replacer);
}
@@ -72,7 +72,9 @@ shaka.test.CannedIDB = class {
* @return {!Promise} Resolved when the operation is complete.
*/
static async restoreJSON(name, savedDatabaseJson, wipeDatabase) {
const savedDatabase = JSON.parse(savedDatabaseJson, this.reviver_);
const savedDatabase =
/** @type {shaka.test.CannedIDB.SavedDatabase} */(JSON.parse(
savedDatabaseJson, this.reviver_));
await this.restore(name, savedDatabase, wipeDatabase);
}
@@ -153,7 +155,7 @@ shaka.test.CannedIDB = class {
/**
* @param {string} name The name of the database to open.
* @return {!Promise.<IDBDatabase>} Resolved when the named DB has been
* @return {!Promise.<!IDBDatabase>} Resolved when the named DB has been
* opened.
* @private
*/
+9 -9
View File
@@ -57,11 +57,11 @@ jasmine.Fetch = class {
* @private
*/
static makeAbortError_() {
// As per the spec, this should be a DOMException, but
// there is not a public constructor for this
// According to the spec, this should be a DOMException, but there is not a
// public constructor for that. So we make this look-alike instead.
const exception = new Error('The operation was aborted. ');
exception.name = 'AbortError';
exception.code = 20;
exception['code'] = DOMException['ABORT_ERR'];
return exception;
}
@@ -211,13 +211,13 @@ jasmine.Fetch.requests = class {
};
jasmine.Fetch.ReadableStream = class {
/** @param {!Object} underlyingSource */
/** @param {!ReadableStreamSource} underlyingSource */
constructor(underlyingSource) {
const noop = () => {};
const controller = {
close: noop,
enqueue: noop,
};
const controller = /** @type {!ReadableByteStreamController} */({
close: () => {},
enqueue: (chunk) => {},
error: (err) => {},
});
underlyingSource.start(controller);
}
};
+4 -2
View File
@@ -19,7 +19,9 @@ shaka.test.UiUtils = class {
// Create UI
config = config || {};
const ui = new shaka.ui.Overlay(player, videoContainer, video);
ui.getControls().addEventListener('error', (/** * */ e) => fail(e.detail));
// TODO: generate externs automatically from @event types
// This event should be a shaka.Player.ErrorEvent
ui.getControls().addEventListener('error', (e) => fail(e['detail']));
ui.configure(config);
return ui;
}
@@ -126,7 +128,7 @@ shaka.test.UiUtils = class {
/**
* @param {!Element} cssLink
* @param {!HTMLLinkElement} cssLink
*/
static async setupCSS(cssLink) {
const head = document.head;
+15 -12
View File
@@ -20,13 +20,14 @@ shaka.test.StatusPromise = class {
this.status;
// TODO: investigate using expectAsync() for this when possible.
p.status = 'pending';
p.then(() => {
p.status = 'resolved';
const p2 = /** @type {!shaka.test.StatusPromise} */(p);
p2.status = 'pending';
p2.then(() => {
p2.status = 'resolved';
}, () => {
p.status = 'rejected';
p2.status = 'rejected';
});
return /** @type {!shaka.test.StatusPromise} */(p);
return p2;
}
};
@@ -104,7 +105,7 @@ shaka.test.Util = class {
/**
* @param {!shaka.util.Error} error
* @return {!Object}
* @return {jasmine.ObjectContainingType}
*/
static jasmineError(error) {
// NOTE: Safari will add extra properties to any thrown object, and some of
@@ -213,8 +214,10 @@ shaka.test.Util = class {
const isInit = first instanceof shaka.media.InitSegmentReference &&
second instanceof shaka.media.InitSegmentReference;
if (isSegment || isInit) {
const a = first.getUris();
const b = second.getUris();
const firstRef = /** @type {shaka.media.AnySegmentReference} */(first);
const secondRef = /** @type {shaka.media.AnySegmentReference} */(second);
const a = firstRef.getUris();
const b = secondRef.getUris();
if (typeof a !== 'object' || typeof b !== 'object' ||
typeof a.length != 'number' || typeof b.length !== 'number') {
return false;
@@ -225,10 +228,10 @@ shaka.test.Util = class {
}
// Make shallow copies of each, without their getUris fields.
const trimmedFirst = Object.assign({}, /** @type {Object} */(first));
delete trimmedFirst.getUris;
const trimmedSecond = Object.assign({}, /** @type {Object} */(second));
delete trimmedSecond.getUris;
const trimmedFirst = Object.assign({}, /** @type {Object} */(firstRef));
delete trimmedFirst['getUris'];
const trimmedSecond = Object.assign({}, /** @type {Object} */(secondRef));
delete trimmedSecond['getUris'];
// Compare those using Jasmine's utility, which will compare the fields of
// an object and the items of an array.
+2 -2
View File
@@ -5,7 +5,7 @@
describe('Ad UI', () => {
const UiUtils = shaka.test.UiUtils;
/** @type {!Element} */
/** @type {!HTMLLinkElement} */
let cssLink;
/** @type {!HTMLElement} */
let container;
@@ -19,7 +19,7 @@ describe('Ad UI', () => {
beforeAll(async () => {
// Add css file
cssLink = document.createElement('link');
cssLink = /** @type {!HTMLLinkElement} */(document.createElement('link'));
await UiUtils.setupCSS(cssLink);
shaka.Player.setAdManagerFactory(() => new shaka.test.FakeAdManager());
});
+1 -1
View File
@@ -23,7 +23,7 @@ describe('UITextDisplayer', () => {
* font-size: '10px',
* }
* @param {string} cssStr
* @return {Object.<string, string|number>}
* @return {!Object.<string, string|number>}
*/
function parseCssText(cssStr) {
// Remove the white spaces in the string.
+2 -2
View File
@@ -5,7 +5,7 @@
describe('UI Customization', () => {
const UiUtils = shaka.test.UiUtils;
/** @type {!Element} */
/** @type {!HTMLLinkElement} */
let cssLink;
/** @type {!HTMLElement} */
let container;
@@ -14,7 +14,7 @@ describe('UI Customization', () => {
beforeAll(async () => {
// Add css file
cssLink = document.createElement('link');
cssLink = /** @type {!HTMLLinkElement} */(document.createElement('link'));
await UiUtils.setupCSS(cssLink);
});
+5 -3
View File
@@ -20,7 +20,7 @@ describe('UI', () => {
let eventManager;
/** @type {shaka.test.Waiter} */
let waiter;
/** @type {!Element} */
/** @type {!HTMLLinkElement} */
let cssLink;
/** @type {!shaka.ui.Controls} */
let controls;
@@ -28,7 +28,7 @@ describe('UI', () => {
let compiledShaka;
beforeAll(async () => {
cssLink = document.createElement('link');
cssLink = /** @type {!HTMLLinkElement} */(document.createElement('link'));
await UiUtils.setupCSS(cssLink);
compiledShaka = await Util.loadShaka(getClientArg('uncompiled'));
@@ -72,7 +72,9 @@ describe('UI', () => {
eventManager = new shaka.util.EventManager();
waiter = new shaka.test.Waiter(eventManager);
controls = ui.getControls();
const tempControls = ui.getControls();
goog.asserts.assert(tempControls != null, 'Controls are null!');
controls = tempControls;
onErrorSpy = jasmine.createSpy('onError');
onErrorSpy.and.callFake((event) => {
+2 -2
View File
@@ -11,12 +11,12 @@ describe('UI', () => {
/** @type {shaka.Player} */
let player;
/** @type {!Element} */
/** @type {!HTMLLinkElement} */
let cssLink;
beforeAll(async () => {
// Add css file
cssLink = document.createElement('link');
cssLink = /** @type {!HTMLLinkElement} */(document.createElement('link'));
await UiUtils.setupCSS(cssLink);
});