Skip to content

Commit

Permalink
Don't use |session.closed| in DrmEngine.destroy.
Browse files Browse the repository at this point in the history
If a session has been created but the license request hasn't been sent,
the session is not "callable".  This will cause the |session.close()|
to be rejected and the |session.closed| Promise to never resolve.  So
in DrmEngine.destroy, we should be using the Promise returned from
|session.close()| instead of |session.closed|.  The |session.close()|
Promise will only resolve once the |session.closed| Promise is resolved
so they are effectively the same.

Closes #664

Change-Id: Ia619740d1eb3fa8ca1bdf121574d1efb1ddbea26
  • Loading branch information
TheModMaker authored and joeyparrish committed Jan 27, 2017
1 parent 3e8847d commit 6a01da0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ shaka.media.DrmEngine.prototype.destroy = function() {
// Ignore any errors when closing the sessions. One such error would be
// an invalid state error triggered by closing a session which has not
// generated any key requests.
activeSession.session.close().catch(Functional.noop);
goog.asserts.assert(activeSession.session.closed, 'Bad EME implementation');
return activeSession.session.closed;
return activeSession.session.close().catch(Functional.noop);
});
this.allSessionsLoaded_.reject();

Expand Down
33 changes: 33 additions & 0 deletions test/media/drm_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,39 @@ describe('DrmEngine', function() {
}).catch(fail).then(done);
// onError is a failure by default.
});

it('still completes if session is not callable', function(done) {
// Before, we would use |session.closed| as part of destroy(). However,
// this doesn't work if the session is not callable (no license request
// sent). So |session.closed| should never resolve and |session.close()|
// should be rejected and destroy() should still succeed.
// https://github.com/google/shaka-player/issues/664
initAndAttach().then(function() {
session1.closed = new shaka.util.PublicPromise();
session2.closed = new shaka.util.PublicPromise();
session1.close.and.returnValue(Promise.reject());
session2.close.and.returnValue(Promise.reject());

var initData1 = new Uint8Array(1);
var initData2 = new Uint8Array(2);
mockVideo.on['encrypted'](
{ initDataType: 'webm', initData: initData1 });
mockVideo.on['encrypted'](
{ initDataType: 'webm', initData: initData2 });

// Still resolve these since we are mocking close and closed. This
// ensures DrmEngine is in the correct state.
var message = new Uint8Array(0);
session1.on['message']({ target: session1, message: message });
session1.update.and.returnValue(Promise.resolve());
session2.on['message']({ target: session2, message: message });
session2.update.and.returnValue(Promise.resolve());

return shaka.test.Util.delay(0.5);
}).then(function() {
return drmEngine.destroy();
}).catch(fail).then(done);
});
}); // describe('destroy')

describe('getDrmInfo', function() {
Expand Down

0 comments on commit 6a01da0

Please sign in to comment.