Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / content / renderer / media / render_media_client_unittest.cc
blob2366156bd39643c9fcaa96dbd8d233bb822d0faf
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
6 #include <vector>
8 #include "base/test/simple_test_tick_clock.h"
9 #include "content/public/renderer/content_renderer_client.h"
10 #include "content/renderer/media/render_media_client.h"
11 #include "content/test/test_content_client.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
16 namespace content {
18 namespace {
20 class TestContentRendererClient : public ContentRendererClient {
21 public:
22 TestContentRendererClient() : is_extra_key_system_enabled_(false) {}
24 // ContentRendererClient implementation.
25 void AddKeySystems(
26 std::vector<media::KeySystemInfo>* key_systems_info) override {
27 // TODO(sandersd): Was this supposed to be added to the list?
28 media::KeySystemInfo key_system_info;
29 key_system_info.key_system = "test.keysystem";
30 key_system_info.persistent_license_support =
31 media::EME_SESSION_TYPE_NOT_SUPPORTED;
32 key_system_info.persistent_release_message_support =
33 media::EME_SESSION_TYPE_NOT_SUPPORTED;
34 key_system_info.persistent_state_support =
35 media::EME_FEATURE_NOT_SUPPORTED;
36 key_system_info.distinctive_identifier_support =
37 media::EME_FEATURE_NOT_SUPPORTED;
38 key_systems_info->push_back(key_system_info);
39 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
40 if (is_extra_key_system_enabled_) {
41 media::KeySystemInfo wv_key_system_info;
42 wv_key_system_info.key_system = kWidevineKeySystem;
43 wv_key_system_info.persistent_license_support =
44 media::EME_SESSION_TYPE_NOT_SUPPORTED;
45 wv_key_system_info.persistent_release_message_support =
46 media::EME_SESSION_TYPE_NOT_SUPPORTED;
47 wv_key_system_info.persistent_state_support =
48 media::EME_FEATURE_NOT_SUPPORTED;
49 wv_key_system_info.distinctive_identifier_support =
50 media::EME_FEATURE_NOT_SUPPORTED;
51 key_systems_info->push_back(wv_key_system_info);
53 #endif
56 void EnableExtraKeySystem() { is_extra_key_system_enabled_ = true; }
58 private:
59 // Whether a platform-specific extra key system is "supported" by |this|.
60 bool is_extra_key_system_enabled_;
63 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
64 bool ContainsWidevine(
65 const std::vector<media::KeySystemInfo>& key_systems_info) {
66 for (const auto& key_system_info: key_systems_info) {
67 if (key_system_info.key_system == kWidevineKeySystem)
68 return true;
70 return false;
72 #endif
74 } // namespace
76 class RenderMediaClientTest : public testing::Test {
77 protected:
78 RenderMediaClientTest()
79 : render_media_client_(GetRenderMediaClientInstanceForTesting()) {
80 SetContentClient(&test_content_client_);
81 SetRendererClientForTesting(&test_content_renderer_client_);
84 void EnableExtraKeySystem() {
85 test_content_renderer_client_.EnableExtraKeySystem();
88 RenderMediaClient* render_media_client_;
90 private:
91 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap;
93 TestContentClient test_content_client_;
94 TestContentRendererClient test_content_renderer_client_;
95 KeySystemNameForUMAMap key_system_name_for_uma_map_;
98 TEST_F(RenderMediaClientTest, KeySystemNameForUMA) {
99 std::vector<media::KeySystemInfoForUMA> key_systems_info_for_uma;
100 render_media_client_->AddKeySystemsInfoForUMA(&key_systems_info_for_uma);
102 std::string widevine_uma_name;
103 std::string clearkey_uma_name;
104 for (const media::KeySystemInfoForUMA& info : key_systems_info_for_uma) {
105 if (info.key_system == "com.widevine.alpha")
106 widevine_uma_name = info.key_system_name_for_uma;
107 if (info.key_system == "org.w3.clearkey")
108 clearkey_uma_name = info.key_system_name_for_uma;
111 #if defined(WIDEVINE_CDM_AVAILABLE)
112 EXPECT_EQ("Widevine", widevine_uma_name);
113 #else
114 EXPECT_TRUE(widevine_uma_name.empty());
115 #endif
117 EXPECT_TRUE(clearkey_uma_name.empty()) << "Clear Key is added by media/ and "
118 "should not be added by the "
119 "MediaClient.";
123 TEST_F(RenderMediaClientTest, IsKeySystemsUpdateNeeded) {
124 base::SimpleTestTickClock* tick_clock = new base::SimpleTestTickClock();
125 render_media_client_->SetTickClockForTesting(
126 scoped_ptr<base::TickClock>(tick_clock));
128 // IsKeySystemsUpdateNeeded() always returns true after construction.
129 EXPECT_TRUE(render_media_client_->IsKeySystemsUpdateNeeded());
131 std::vector<media::KeySystemInfo> key_systems_info;
132 render_media_client_->AddSupportedKeySystems(&key_systems_info);
134 // No update needed immediately after AddSupportedKeySystems() call.
135 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded());
137 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
138 // Widevine not supported because extra key system isn't enabled.
139 EXPECT_FALSE(ContainsWidevine(key_systems_info));
141 // This is timing related. The update interval for Widevine is 1000 ms.
142 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded());
143 tick_clock->Advance(base::TimeDelta::FromMilliseconds(990));
144 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded());
145 tick_clock->Advance(base::TimeDelta::FromMilliseconds(10));
146 EXPECT_TRUE(render_media_client_->IsKeySystemsUpdateNeeded());
148 EnableExtraKeySystem();
150 key_systems_info.clear();
151 render_media_client_->AddSupportedKeySystems(&key_systems_info);
152 EXPECT_TRUE(ContainsWidevine(key_systems_info));
154 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded());
155 tick_clock->Advance(base::TimeDelta::FromMilliseconds(1000));
156 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded());
157 tick_clock->Advance(base::TimeDelta::FromMilliseconds(1000));
158 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded());
159 #endif
162 } // namespace content