From e850894b42be7e4fb5df75392ccb79e18ccffe01 Mon Sep 17 00:00:00 2001 From: jrummell Date: Thu, 16 Oct 2014 12:45:07 -0700 Subject: [PATCH] Add unprefixed EME tests for LoadSession() BUG=338830 TEST=new EME tests pass Review URL: https://codereview.chromium.org/641443002 Cr-Commit-Position: refs/heads/master@{#299960} --- .../browser/media/encrypted_media_browsertest.cc | 38 ++++++++++++++++++++++ .../cdm/ppapi/external_clear_key/clear_key_cdm.cc | 7 ++++ media/test/data/eme_player_js/player_utils.js | 23 ++++++------- media/test/data/eme_player_js/test_config.js | 9 +++++ 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/chrome/browser/media/encrypted_media_browsertest.cc b/chrome/browser/media/encrypted_media_browsertest.cc index bd6cd7d09f25..da9f0c0cc2c5 100644 --- a/chrome/browser/media/encrypted_media_browsertest.cc +++ b/chrome/browser/media/encrypted_media_browsertest.cc @@ -332,6 +332,19 @@ class ECKEncryptedMediaTest : public EncryptedMediaTestBase { } }; +// Tests encrypted media playback using ExternalClearKey key system in +// decrypt-and-decode mode for unprefixed EME. +// TODO(jrummell): Merge with ECKEncryptedMediaTest once unprefixed is +// enabled by default. +class ECKUnprefixedEncryptedMediaTest : public EncryptedMediaTestBase { + protected: + virtual void SetUpCommandLine(CommandLine* command_line) override { + EncryptedMediaTestBase::SetUpCommandLine(command_line); + command_line->AppendSwitch(switches::kEnableEncryptedMedia); + SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line); + } +}; + #if defined(WIDEVINE_CDM_AVAILABLE) // Tests encrypted media playback using Widevine key system. class WVEncryptedMediaTest : public EncryptedMediaTestBase { @@ -666,4 +679,29 @@ IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) { false, kEmeKeyError); } + +IN_PROC_BROWSER_TEST_F(ECKUnprefixedEncryptedMediaTest, LoadLoadableSession) { + RunEncryptedMediaTest(kDefaultEmePlayer, + "bear-320x240-v_enc-v.webm", + kWebMVideoOnly, + kExternalClearKeyKeySystem, + SRC, + UNPREFIXED, + kLoadableSession, + false, + kEnded); +} + +IN_PROC_BROWSER_TEST_F(ECKUnprefixedEncryptedMediaTest, LoadUnknownSession) { + // TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound. + RunEncryptedMediaTest(kDefaultEmePlayer, + "bear-320x240-v_enc-v.webm", + kWebMVideoOnly, + kExternalClearKeyKeySystem, + SRC, + UNPREFIXED, + kUnknownSession, + false, + kEmeKeyError); +} #endif // defined(ENABLE_PEPPER_CDMS) diff --git a/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc b/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc index 84a6a3142659..7b6db1b87bd4 100644 --- a/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc +++ b/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc @@ -700,6 +700,10 @@ void ClearKeyCdm::OnSessionMessage(const std::string& web_session_id, void ClearKeyCdm::OnSessionKeysChange(const std::string& web_session_id, bool has_additional_usable_key) { + // Ignore the message when we are waiting to update the loadable session. + if (web_session_id == session_id_for_emulated_loadsession_) + return; + host_->OnSessionUsableKeysChange(web_session_id.data(), web_session_id.length(), has_additional_usable_key); @@ -749,6 +753,9 @@ void ClearKeyCdm::OnSessionUpdated(uint32 promise_id, // |promise_id| is the LoadSession() promise, so resolve appropriately. host_->OnResolveNewSessionPromise( promise_id, kLoadableWebSessionId, strlen(kLoadableWebSessionId)); + // Generate the UsableKeys event now that the session is "loaded". + host_->OnSessionUsableKeysChange( + kLoadableWebSessionId, strlen(kLoadableWebSessionId), true); return; } diff --git a/media/test/data/eme_player_js/player_utils.js b/media/test/data/eme_player_js/player_utils.js index 16f3de6c5d86..4594c8e2e08f 100644 --- a/media/test/data/eme_player_js/player_utils.js +++ b/media/test/data/eme_player_js/player_utils.js @@ -57,26 +57,23 @@ PlayerUtils.registerEMEEventListeners = function(player) { // TODO(sandersd): Stop checking contentType once we complete the switch to // using the 'encrypted' event. var init_data_type = message.initDataType || message.contentType; - Utils.timeLog('Creating new media key session for initDataType: ' + - init_data_type + ', initData: ' + - Utils.getHexString(new Uint8Array(message.initData))); try { - if (message.target.mediaKeys.createSession.length == 0) { - // FIXME(jrummell): Remove this test (and else branch) once blink - // uses the new API. + if (player.testConfig.sessionToLoad) { + Utils.timeLog('Loading session: ' + player.testConfig.sessionToLoad); + var session = message.target.mediaKeys.createSession('persistent'); + addMediaKeySessionListeners(session); + session.load(player.testConfig.sessionToLoad) + .catch(function(error) { Utils.failTest(error, KEY_ERROR); }); + } else { + Utils.timeLog('Creating new media key session for initDataType: ' + + init_data_type + ', initData: ' + + Utils.getHexString(new Uint8Array(message.initData))); var session = message.target.mediaKeys.createSession(); addMediaKeySessionListeners(session); session.generateRequest(init_data_type, message.initData) .catch(function(error) { Utils.failTest(error, KEY_ERROR); }); - } else { - var session = message.target.mediaKeys.createSession( - init_data_type, message.initData); - session.then(addMediaKeySessionListeners) - .catch(function(error) { - Utils.failTest(error, KEY_ERROR); - }); } } catch (e) { Utils.failTest(e); diff --git a/media/test/data/eme_player_js/test_config.js b/media/test/data/eme_player_js/test_config.js index 8be8a9adb5a7..6484eb54d97e 100644 --- a/media/test/data/eme_player_js/test_config.js +++ b/media/test/data/eme_player_js/test_config.js @@ -28,6 +28,15 @@ TestConfig.prototype.loadQueryParams = function() { this.useMSE = this.useMSE == '1' || this.useMSE == 'true'; this.usePrefixedEME = this.usePrefixedEME == '1' || this.usePrefixedEME == 'true'; + + // Validate that the prefixed/unprefixed EME is available. + if (this.usePrefixedEME) { + if (EME_DISABLED_OPTIONS.indexOf(EME_PREFIXED_VERSION) >= 0) + Utils.failTest('Prefixed EME not available.') + } else { + if (EME_DISABLED_OPTIONS.indexOf(EME_UNPREFIXED_VERSION) >= 0) + Utils.failTest('Unprefixed EME not available.') + } }; TestConfig.updateDocument = function() { -- 2.11.4.GIT