Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Unified Diff: media/base/key_systems_unittest.cc

Issue 2712983004: Simplify/Cleanup MediaClient (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/key_systems_unittest.cc
diff --git a/media/base/key_systems_unittest.cc b/media/base/key_systems_unittest.cc
index 665e68df4b30d07699ee6c2c25539671d791173a..575258575e47bc06cc61f2e768ad1d8fc94c41a1 100644
--- a/media/base/key_systems_unittest.cc
+++ b/media/base/key_systems_unittest.cc
@@ -19,6 +19,7 @@
#include "media/base/media_client.h"
#include "ppapi/features/features.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/widevine/cdm/widevine_cdm_common.h"
namespace media {
@@ -26,9 +27,7 @@ namespace media {
// kUsesAes uses the AesDecryptor like Clear Key.
// kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
const char kUsesAes[] = "x-org.example.clear";
-const char kUseAesNameForUMA[] = "UseAes";
const char kExternal[] = "x-com.example.test";
-const char kExternalNameForUMA[] = "External";
const char kClearKey[] = "org.w3.clearkey";
const char kExternalClearKey[] = "org.chromium.externalclearkey";
@@ -174,56 +173,21 @@ class TestMediaClient : public MediaClient {
~TestMediaClient() override;
// MediaClient implementation.
- void AddKeySystemsInfoForUMA(
- std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) final;
- bool IsKeySystemsUpdateNeeded() final;
void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>*
key_systems_properties) override;
void RecordRapporURL(const std::string& metric, const GURL& url) final;
bool IsSupportedVideoConfig(const media::VideoConfig& config) final;
-
- // Helper function to test the case where IsKeySystemsUpdateNeeded() is true
- // after AddSupportedKeySystems() is called.
- void SetKeySystemsUpdateNeeded();
-
- // Helper function to disable "kExternal" key system support so that we can
- // test the key system update case.
- void DisableExternalKeySystemSupport();
-
- private:
- bool is_update_needed_;
- bool supports_external_key_system_;
};
-TestMediaClient::TestMediaClient()
- : is_update_needed_(true), supports_external_key_system_(true) {
-}
+TestMediaClient::TestMediaClient() {}
TestMediaClient::~TestMediaClient() {
}
-void TestMediaClient::AddKeySystemsInfoForUMA(
- std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) {
- key_systems_info_for_uma->push_back(
- media::KeySystemInfoForUMA(kUsesAes, kUseAesNameForUMA));
- key_systems_info_for_uma->push_back(
- media::KeySystemInfoForUMA(kExternal, kExternalNameForUMA));
-}
-
-bool TestMediaClient::IsKeySystemsUpdateNeeded() {
- return is_update_needed_;
-}
-
void TestMediaClient::AddSupportedKeySystems(
std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) {
- DCHECK(is_update_needed_);
-
key_systems->emplace_back(new AesKeySystemProperties(kUsesAes));
-
- if (supports_external_key_system_)
- key_systems->emplace_back(new ExternalKeySystemProperties());
-
- is_update_needed_ = false;
+ key_systems->emplace_back(new ExternalKeySystemProperties());
}
void TestMediaClient::RecordRapporURL(const std::string& /* metric */,
@@ -235,47 +199,6 @@ bool TestMediaClient::IsSupportedVideoConfig(const media::VideoConfig& config) {
return true;
}
-void TestMediaClient::SetKeySystemsUpdateNeeded() {
- is_update_needed_ = true;
-}
-
-void TestMediaClient::DisableExternalKeySystemSupport() {
- supports_external_key_system_ = false;
-}
-
-class PotentiallySupportedNamesTestMediaClient : public TestMediaClient {
- void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>*
- key_systems_properties) final;
-};
-
-void PotentiallySupportedNamesTestMediaClient::AddSupportedKeySystems(
- std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) {
- // org.w3.clearkey is automatically registered.
- key_systems->emplace_back(new AesKeySystemProperties("com.widevine.alpha"));
- key_systems->emplace_back(
- new AesKeySystemProperties("org.chromium.externalclearkey"));
- key_systems->emplace_back(
- new AesKeySystemProperties("org.chromium.externalclearkey.something"));
- key_systems->emplace_back(
- new AesKeySystemProperties("com.chromecast.something"));
- key_systems->emplace_back(new AesKeySystemProperties("x-something"));
-}
-
-class KeySystemsPotentiallySupportedNamesTest : public testing::Test {
- protected:
- KeySystemsPotentiallySupportedNamesTest() {
- SetMediaClient(&test_media_client_);
- }
-
- ~KeySystemsPotentiallySupportedNamesTest() override {
- // Clear the use of |test_media_client_|, which was set in SetUp().
- SetMediaClient(nullptr);
- }
-
- private:
- PotentiallySupportedNamesTestMediaClient test_media_client_;
-};
-
class KeySystemsTest : public testing::Test {
protected:
KeySystemsTest() {
@@ -320,14 +243,11 @@ class KeySystemsTest : public testing::Test {
~KeySystemsTest() override {
// Clear the use of |test_media_client_|, which was set in SetUp().
+ // NOTE: This does not clear any cached KeySystemProperties in the global
+ // KeySystems instance.
SetMediaClient(nullptr);
}
- void UpdateClientKeySystems() {
- test_media_client_.SetKeySystemsUpdateNeeded();
- test_media_client_.DisableExternalKeySystemSupport();
- }
-
typedef std::vector<std::string> CodecVector;
const CodecVector& no_codecs() const { return no_codecs_; }
@@ -436,7 +356,7 @@ TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
kVideoWebM, no_codecs(), kUsesAes));
// No UMA value for this test key system.
- EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes));
+ EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAes));
EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
#if BUILDFLAG(ENABLE_PEPPER_CDMS)
@@ -710,69 +630,12 @@ TEST_F(
TEST_F(KeySystemsTest, KeySystemNameForUMA) {
EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
+ EXPECT_EQ("Widevine", GetKeySystemNameForUMA(kWidevineKeySystem));
+ EXPECT_EQ("Unknown", GetKeySystemNameForUMA("Foo"));
// External Clear Key never has a UMA name.
if (CanRunExternalKeySystemTests())
EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey));
}
-TEST_F(KeySystemsTest, KeySystemsUpdate) {
- EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
- EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
- kVideoWebM, no_codecs(), kUsesAes));
-
- if (CanRunExternalKeySystemTests()) {
- EXPECT_TRUE(IsSupportedKeySystem(kExternal));
- EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(),
- kExternal));
- }
-
- UpdateClientKeySystems();
-
- EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
- EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
- kVideoWebM, no_codecs(), kUsesAes));
- if (CanRunExternalKeySystemTests())
- EXPECT_FALSE(IsSupportedKeySystem(kExternal));
-}
-
-TEST_F(KeySystemsPotentiallySupportedNamesTest, PotentiallySupportedNames) {
- EXPECT_FALSE(IsSupportedKeySystem("org.w3"));
- EXPECT_FALSE(IsSupportedKeySystem("org.w3."));
- EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearke"));
- EXPECT_TRUE(IsSupportedKeySystem("org.w3.clearkey"));
- EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkeys"));
-
- EXPECT_FALSE(IsSupportedKeySystem("com.widevine"));
- EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
- EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
- EXPECT_TRUE(IsSupportedKeySystem("com.widevine.alpha"));
- EXPECT_FALSE(IsSupportedKeySystem("com.widevine.beta"));
- EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphabeta"));
- EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.beta"));
-
- EXPECT_FALSE(IsSupportedKeySystem("org.chromium"));
- EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
- EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
- EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey"));
- EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeys"));
- EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey."));
- EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey.something"));
- EXPECT_FALSE(
- IsSupportedKeySystem("org.chromium.externalclearkey.something.else"));
- EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.other"));
- EXPECT_FALSE(IsSupportedKeySystem("org.chromium.other"));
-
- EXPECT_FALSE(IsSupportedKeySystem("com.chromecast"));
- EXPECT_FALSE(IsSupportedKeySystem("com.chromecast."));
- EXPECT_TRUE(IsSupportedKeySystem("com.chromecast.something"));
- EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else"));
- EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other"));
-
- EXPECT_FALSE(IsSupportedKeySystem("x-"));
- EXPECT_TRUE(IsSupportedKeySystem("x-something"));
- EXPECT_FALSE(IsSupportedKeySystem("x-something.else"));
- EXPECT_FALSE(IsSupportedKeySystem("x-other"));
-}
-
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698