OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/android/build_info.h" | 5 #include "base/android/build_info.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "media/base/android/media_drm_bridge.h" | 9 #include "media/base/android/media_drm_bridge.h" |
| 10 #include "media/base/android/provision_fetcher.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 13 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
13 | 14 |
14 namespace media { | 15 namespace media { |
15 | 16 |
16 #define EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(a) \ | 17 #define EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(a) \ |
17 do { \ | 18 do { \ |
18 if (!MediaDrmBridge::IsKeySystemSupported(kWidevineKeySystem)) { \ | 19 if (!MediaDrmBridge::IsKeySystemSupported(kWidevineKeySystem)) { \ |
19 VLOG(0) << "Widevine not supported on device."; \ | 20 VLOG(0) << "Widevine not supported on device."; \ |
(...skipping 15 matching lines...) Expand all Loading... |
35 | 36 |
36 // Helper functions to avoid typing "MediaDrmBridge::" in tests. | 37 // Helper functions to avoid typing "MediaDrmBridge::" in tests. |
37 | 38 |
38 static bool IsKeySystemSupportedWithType( | 39 static bool IsKeySystemSupportedWithType( |
39 const std::string& key_system, | 40 const std::string& key_system, |
40 const std::string& container_mime_type) { | 41 const std::string& container_mime_type) { |
41 return MediaDrmBridge::IsKeySystemSupportedWithType(key_system, | 42 return MediaDrmBridge::IsKeySystemSupportedWithType(key_system, |
42 container_mime_type); | 43 container_mime_type); |
43 } | 44 } |
44 | 45 |
| 46 namespace { |
| 47 // Mock ProvisionFetcher. |
| 48 class MockProvisionFetcher : public ProvisionFetcher { |
| 49 public: |
| 50 void Retrieve(const std::string& default_url, |
| 51 const std::string& request_data, |
| 52 const ResponseCB& response_cb) override {} |
| 53 |
| 54 static scoped_ptr<ProvisionFetcher> Create() { |
| 55 return scoped_ptr<ProvisionFetcher>(new MockProvisionFetcher); |
| 56 } |
| 57 }; |
| 58 |
| 59 } // namespace (anonymous) |
| 60 |
45 TEST(MediaDrmBridgeTest, IsKeySystemSupported_Widevine) { | 61 TEST(MediaDrmBridgeTest, IsKeySystemSupported_Widevine) { |
46 // TODO(xhwang): Enable when b/13564917 is fixed. | 62 // TODO(xhwang): Enable when b/13564917 is fixed. |
47 // EXPECT_TRUE_IF_AVAILABLE( | 63 // EXPECT_TRUE_IF_AVAILABLE( |
48 // IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4)); | 64 // IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioMp4)); |
49 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( | 65 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( |
50 IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoMp4)); | 66 IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoMp4)); |
51 | 67 |
52 if (base::android::BuildInfo::GetInstance()->sdk_int() <= 19) { | 68 if (base::android::BuildInfo::GetInstance()->sdk_int() <= 19) { |
53 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM)); | 69 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM)); |
54 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM)); | 70 EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM)); |
(...skipping 16 matching lines...) Expand all Loading... |
71 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoMp4)); | 87 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoMp4)); |
72 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioWebM)); | 88 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kAudioWebM)); |
73 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoWebM)); | 89 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, kVideoWebM)); |
74 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "unknown")); | 90 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "unknown")); |
75 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "video/avi")); | 91 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "video/avi")); |
76 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "audio/mp3")); | 92 EXPECT_FALSE(IsKeySystemSupportedWithType(kInvalidKeySystem, "audio/mp3")); |
77 } | 93 } |
78 | 94 |
79 TEST(MediaDrmBridgeTest, CreateWithoutSessionSupport_Widevine) { | 95 TEST(MediaDrmBridgeTest, CreateWithoutSessionSupport_Widevine) { |
80 base::MessageLoop message_loop_; | 96 base::MessageLoop message_loop_; |
81 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( | 97 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(MediaDrmBridge::CreateWithoutSessionSupport( |
82 MediaDrmBridge::CreateWithoutSessionSupport(kWidevineKeySystem)); | 98 kWidevineKeySystem, MockProvisionFetcher::Create().Pass())); |
83 } | 99 } |
84 | 100 |
85 // Invalid key system is NOT supported regardless whether MediaDrm is available. | 101 // Invalid key system is NOT supported regardless whether MediaDrm is available. |
86 TEST(MediaDrmBridgeTest, CreateWithoutSessionSupport_InvalidKeySystem) { | 102 TEST(MediaDrmBridgeTest, CreateWithoutSessionSupport_InvalidKeySystem) { |
87 base::MessageLoop message_loop_; | 103 base::MessageLoop message_loop_; |
88 EXPECT_FALSE(MediaDrmBridge::CreateWithoutSessionSupport(kInvalidKeySystem)); | 104 EXPECT_FALSE(MediaDrmBridge::CreateWithoutSessionSupport( |
| 105 kInvalidKeySystem, MockProvisionFetcher::Create().Pass())); |
89 } | 106 } |
90 | 107 |
91 TEST(MediaDrmBridgeTest, SetSecurityLevel_Widevine) { | 108 TEST(MediaDrmBridgeTest, SetSecurityLevel_Widevine) { |
92 base::MessageLoop message_loop_; | 109 base::MessageLoop message_loop_; |
93 scoped_refptr<MediaDrmBridge> media_drm_bridge = | 110 scoped_refptr<MediaDrmBridge> media_drm_bridge = |
94 MediaDrmBridge::CreateWithoutSessionSupport(kWidevineKeySystem); | 111 MediaDrmBridge::CreateWithoutSessionSupport( |
| 112 kWidevineKeySystem, MockProvisionFetcher::Create().Pass()); |
95 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(media_drm_bridge); | 113 EXPECT_TRUE_IF_WIDEVINE_AVAILABLE(media_drm_bridge); |
96 if (!media_drm_bridge) | 114 if (!media_drm_bridge) |
97 return; | 115 return; |
98 | 116 |
99 EXPECT_FALSE(media_drm_bridge->SetSecurityLevel(kLNone)); | 117 EXPECT_FALSE(media_drm_bridge->SetSecurityLevel(kLNone)); |
100 // We test "L3" fully. But for "L1" we don't check the result as it depends on | 118 // We test "L3" fully. But for "L1" we don't check the result as it depends on |
101 // whether the test device supports "L1". | 119 // whether the test device supports "L1". |
102 EXPECT_TRUE(media_drm_bridge->SetSecurityLevel(kL3)); | 120 EXPECT_TRUE(media_drm_bridge->SetSecurityLevel(kL3)); |
103 media_drm_bridge->SetSecurityLevel(kL1); | 121 media_drm_bridge->SetSecurityLevel(kL1); |
104 } | 122 } |
105 | 123 |
106 } // namespace media | 124 } // namespace media |
OLD | NEW |