OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/win/windows_version.h" | 8 #include "base/win/windows_version.h" |
9 #include "content/browser/media/media_browsertest.h" | 9 #include "content/browser/media/media_browsertest.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
12 #include "content/shell/browser/shell.h" | 12 #include "content/shell/browser/shell.h" |
| 13 #if defined(OS_ANDROID) |
| 14 #include "base/android/build_info.h" |
| 15 #endif |
13 | 16 |
14 // Available key systems. | 17 // Available key systems. |
15 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 18 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
16 | 19 |
17 // Supported media types. | 20 // Supported media types. |
18 static const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; | 21 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; |
19 static const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; | 22 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; |
20 static const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; | 23 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; |
21 | 24 |
22 // EME-specific test results and errors. | 25 // EME-specific test results and errors. |
23 static const char kEmeKeyError[] = "KEYERROR"; | 26 const char kEmeKeyError[] = "KEYERROR"; |
24 static const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; | 27 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR"; |
25 | 28 |
26 // The type of video src used to load media. | 29 // The type of video src used to load media. |
27 enum SrcType { | 30 enum SrcType { |
28 SRC, | 31 SRC, |
29 MSE | 32 MSE |
30 }; | 33 }; |
31 | 34 |
32 namespace content { | 35 namespace content { |
33 | 36 |
| 37 // MSE is available on all desktop platforms and on Android 4.1 and later. |
| 38 static bool IsMSESupported() { |
| 39 #if defined(OS_ANDROID) |
| 40 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) { |
| 41 LOG(INFO) << "MSE is only supported in Android 4.1 and later."; |
| 42 return false; |
| 43 } |
| 44 #endif // defined(OS_ANDROID) |
| 45 return true; |
| 46 } |
| 47 |
34 // Tests encrypted media playback with a combination of parameters: | 48 // Tests encrypted media playback with a combination of parameters: |
35 // - char*: Key system name. | 49 // - char*: Key system name. |
36 // - bool: True to load media using MSE, otherwise use src. | 50 // - bool: True to load media using MSE, otherwise use src. |
37 class EncryptedMediaTest : public content::MediaBrowserTest, | 51 class EncryptedMediaTest : public content::MediaBrowserTest, |
38 public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > { | 52 public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > { |
39 public: | 53 public: |
40 // Can only be used in parameterized (*_P) tests. | 54 // Can only be used in parameterized (*_P) tests. |
41 const char* CurrentKeySystem() { | 55 const char* CurrentKeySystem() { |
42 return std::tr1::get<0>(GetParam()); | 56 return std::tr1::get<0>(GetParam()); |
43 } | 57 } |
44 | 58 |
45 // Can only be used in parameterized (*_P) tests. | 59 // Can only be used in parameterized (*_P) tests. |
46 SrcType CurrentSourceType() { | 60 SrcType CurrentSourceType() { |
47 return std::tr1::get<1>(GetParam()); | 61 return std::tr1::get<1>(GetParam()); |
48 } | 62 } |
49 | 63 |
50 void TestSimplePlayback(const char* encrypted_media, const char* media_type) { | 64 void TestSimplePlayback(const char* encrypted_media, const char* media_type) { |
51 RunSimpleEncryptedMediaTest( | 65 RunSimpleEncryptedMediaTest( |
52 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType()); | 66 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType()); |
53 } | 67 } |
54 | 68 |
55 void TestFrameSizeChange() { | 69 void TestFrameSizeChange() { |
56 RunEncryptedMediaTest("encrypted_frame_size_change.html", | 70 RunEncryptedMediaTest("encrypted_frame_size_change.html", |
57 "frame_size_change-av-enc-v.webm", kWebMAudioVideo, | 71 "frame_size_change-av-enc-v.webm", kWebMAudioVideo, |
58 CurrentKeySystem(), CurrentSourceType(), kEnded); | 72 CurrentKeySystem(), CurrentSourceType(), kEnded); |
59 } | 73 } |
60 | 74 |
61 void TestConfigChange() { | 75 void TestConfigChange() { |
| 76 if (CurrentSourceType() != MSE || !IsMSESupported()) { |
| 77 LOG(INFO) << "Skipping test - config change test requires MSE."; |
| 78 return; |
| 79 } |
| 80 |
62 std::vector<StringPair> query_params; | 81 std::vector<StringPair> query_params; |
63 query_params.push_back(std::make_pair("keysystem", CurrentKeySystem())); | 82 query_params.push_back(std::make_pair("keysystem", CurrentKeySystem())); |
64 query_params.push_back(std::make_pair("runencrypted", "1")); | 83 query_params.push_back(std::make_pair("runencrypted", "1")); |
65 RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true); | 84 RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true); |
66 } | 85 } |
67 | 86 |
68 void RunEncryptedMediaTest(const char* html_page, | 87 void RunEncryptedMediaTest(const char* html_page, |
69 const char* media_file, | 88 const char* media_file, |
70 const char* media_type, | 89 const char* media_type, |
71 const char* key_system, | 90 const char* key_system, |
72 SrcType src_type, | 91 SrcType src_type, |
73 const char* expectation) { | 92 const char* expectation) { |
| 93 if (src_type == MSE && !IsMSESupported()) { |
| 94 LOG(INFO) << "Skipping test - MSE not supported."; |
| 95 return; |
| 96 } |
| 97 |
74 std::vector<StringPair> query_params; | 98 std::vector<StringPair> query_params; |
75 query_params.push_back(std::make_pair("mediafile", media_file)); | 99 query_params.push_back(std::make_pair("mediafile", media_file)); |
76 query_params.push_back(std::make_pair("mediatype", media_type)); | 100 query_params.push_back(std::make_pair("mediatype", media_type)); |
77 query_params.push_back(std::make_pair("keysystem", key_system)); | 101 query_params.push_back(std::make_pair("keysystem", key_system)); |
78 if (src_type == MSE) | 102 if (src_type == MSE) |
79 query_params.push_back(std::make_pair("usemse", "1")); | 103 query_params.push_back(std::make_pair("usemse", "1")); |
80 RunMediaTestPage(html_page, &query_params, expectation, true); | 104 RunMediaTestPage(html_page, &query_params, expectation, true); |
81 } | 105 } |
82 | 106 |
83 void RunSimpleEncryptedMediaTest(const char* media_file, | 107 void RunSimpleEncryptedMediaTest(const char* media_file, |
(...skipping 20 matching lines...) Expand all Loading... |
104 #endif | 128 #endif |
105 }; | 129 }; |
106 | 130 |
107 using ::testing::Combine; | 131 using ::testing::Combine; |
108 using ::testing::Values; | 132 using ::testing::Values; |
109 | 133 |
110 #if !defined(OS_ANDROID) | 134 #if !defined(OS_ANDROID) |
111 // Encrypted media playback with SRC is not supported on Android. | 135 // Encrypted media playback with SRC is not supported on Android. |
112 INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest, | 136 INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest, |
113 Combine(Values(kClearKeyKeySystem), Values(SRC))); | 137 Combine(Values(kClearKeyKeySystem), Values(SRC))); |
114 #endif // defined(OS_ANDROID) | 138 #endif // !defined(OS_ANDROID) |
115 | 139 |
116 INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest, | 140 INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest, |
117 Combine(Values(kClearKeyKeySystem), Values(MSE))); | 141 Combine(Values(kClearKeyKeySystem), Values(MSE))); |
118 | 142 |
119 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { | 143 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { |
120 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly); | 144 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly); |
121 } | 145 } |
122 | 146 |
123 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { | 147 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { |
124 TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo); | 148 TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo); |
(...skipping 24 matching lines...) Expand all Loading... |
149 TestFrameSizeChange(); | 173 TestFrameSizeChange(); |
150 } | 174 } |
151 | 175 |
152 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) { | 176 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) { |
153 RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm", | 177 RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm", |
154 kWebMAudioOnly, "com.example.foo", MSE, | 178 kWebMAudioOnly, "com.example.foo", MSE, |
155 kEmeNotSupportedError); | 179 kEmeNotSupportedError); |
156 } | 180 } |
157 | 181 |
158 } // namespace content | 182 } // namespace content |
OLD | NEW |