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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
17 #include "content/shell/shell.h" | 17 #include "content/shell/shell.h" |
18 #include "content/test/content_browser_test.h" | 18 #include "content/test/content_browser_test.h" |
19 #include "content/test/content_browser_test_utils.h" | 19 #include "content/test/content_browser_test_utils.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
22 #include "webkit/media/crypto/key_systems.h" | 22 #include "webkit/media/crypto/key_systems.h" |
23 | 23 |
24 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 24 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
25 | 25 |
26 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(OS_LINUX) | 26 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(OS_LINUX) |
27 #include <gnu/libc-version.h> | 27 #include <gnu/libc-version.h> |
28 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(OS_LINUX) | 28 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(OS_LINUX) |
29 | 29 |
| 30 #if defined(ENABLE_PEPPER_CDMS) |
30 // Platform-specific filename relative to the chrome executable. | 31 // Platform-specific filename relative to the chrome executable. |
31 #if defined(OS_WIN) | 32 static const char kClearKeyCdmAdapterFileName[] = |
32 static const char kClearKeyLibraryName[] = "clearkeycdmadapter.dll"; | 33 #if defined(OS_MACOSX) |
33 static const char kWidevineLibraryName[] = "widevinecdmadapter.dll"; | 34 "clearkeycdmadapter.plugin"; |
34 #elif defined(OS_MACOSX) | 35 #elif defined(OS_WIN) |
35 static const char kClearKeyLibraryName[] = "clearkeycdmadapter.plugin"; | 36 "clearkeycdmadapter.dll"; |
36 static const char kWidevineLibraryName[] = "widevinecdmadapter.plugin"; | |
37 #elif defined(OS_POSIX) | 37 #elif defined(OS_POSIX) |
38 static const char kClearKeyLibraryName[] = "libclearkeycdmadapter.so"; | 38 "libclearkeycdmadapter.so"; |
39 static const char kWidevineLibraryName[] = "libwidevinecdmadapter.so"; | |
40 #endif | 39 #endif |
| 40 #endif // defined(ENABLE_PEPPER_CDMS) |
41 | 41 |
42 // Available key systems. | 42 // Available key systems. |
43 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 43 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
44 static const char kExternalClearKeyKeySystem[] = | 44 static const char kExternalClearKeyKeySystem[] = |
45 "org.chromium.externalclearkey"; | 45 "org.chromium.externalclearkey"; |
46 | 46 |
47 // Supported media types. | 47 // Supported media types. |
48 static const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; | 48 static const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; |
49 static const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; | 49 static const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; |
50 static const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; | 50 static const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 std::string fail_message; | 97 std::string fail_message; |
98 EXPECT_TRUE(ExecuteScriptAndExtractString( | 98 EXPECT_TRUE(ExecuteScriptAndExtractString( |
99 shell()->web_contents(), | 99 shell()->web_contents(), |
100 "window.domAutomationController.send(failMessage);", | 100 "window.domAutomationController.send(failMessage);", |
101 &fail_message)); | 101 &fail_message)); |
102 LOG(INFO) << "Test failed: " << fail_message; | 102 LOG(INFO) << "Test failed: " << fail_message; |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 protected: | 106 protected: |
107 // Registers any CDM plugins not registered by default. | 107 #if defined(ENABLE_PEPPER_CDMS) |
108 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 108 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
109 RegisterPepperPlugin(command_line, kClearKeyLibraryName, | 109 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, |
110 kExternalClearKeyKeySystem); | 110 kExternalClearKeyKeySystem); |
111 } | 111 } |
112 | 112 |
113 virtual void RegisterPepperPlugin(CommandLine* command_line, | 113 virtual void RegisterPepperCdm(CommandLine* command_line, |
114 const std::string& library_name, | 114 const std::string& adapter_name, |
115 const std::string& key_system) { | 115 const std::string& key_system) { |
116 // Append the switch to register the Clear Key CDM Adapter. | 116 // Append the switch to register the Clear Key CDM Adapter. |
117 base::FilePath plugin_dir; | 117 base::FilePath plugin_dir; |
118 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); | 118 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); |
119 #if defined(OS_WIN) | 119 base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name); |
120 base::FilePath plugin_lib = plugin_dir.Append(ASCIIToWide(library_name)); | |
121 #else | |
122 base::FilePath plugin_lib = plugin_dir.Append(library_name); | |
123 #endif | |
124 EXPECT_TRUE(file_util::PathExists(plugin_lib)); | 120 EXPECT_TRUE(file_util::PathExists(plugin_lib)); |
125 base::FilePath::StringType pepper_plugin = plugin_lib.value(); | 121 base::FilePath::StringType pepper_plugin = plugin_lib.value(); |
126 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;")); | 122 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;")); |
127 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
128 pepper_plugin.append(ASCIIToWide(webkit_media::GetPluginType(key_system))); | 124 pepper_plugin.append(ASCIIToWide(webkit_media::GetPepperType(key_system))); |
129 #else | 125 #else |
130 pepper_plugin.append(webkit_media::GetPluginType(key_system)); | 126 pepper_plugin.append(webkit_media::GetPepperType(key_system)); |
131 #endif | 127 #endif |
132 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, | 128 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, |
133 pepper_plugin); | 129 pepper_plugin); |
134 } | 130 } |
| 131 #endif // defined(ENABLE_PEPPER_CDMS) |
135 }; | 132 }; |
136 | 133 |
137 #if defined(WIDEVINE_CDM_AVAILABLE) | 134 #if defined(WIDEVINE_CDM_AVAILABLE) |
138 class WVEncryptedMediaTest : public EncryptedMediaTest { | 135 class WVEncryptedMediaTest : public EncryptedMediaTest { |
139 public: | 136 public: |
140 // Tests that the following happen after trying to play encrypted media: | 137 // Tests that the following happen after trying to play encrypted media: |
141 // - webkitneedkey event is fired. | 138 // - webkitneedkey event is fired. |
142 // - webkitGenerateKeyRequest() does not fail. | 139 // - webkitGenerateKeyRequest() does not fail. |
143 // - webkitkeymessage is fired | 140 // - webkitkeymessage is fired |
144 // - webkitAddKey() generates a WebKitKeyError since no real WV key is added. | 141 // - webkitAddKey() generates a WebKitKeyError since no real WV key is added. |
(...skipping 12 matching lines...) Expand all Loading... |
157 key_system, kKeyError); | 154 key_system, kKeyError); |
158 bool receivedKeyMessage = false; | 155 bool receivedKeyMessage = false; |
159 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 156 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
160 shell()->web_contents(), | 157 shell()->web_contents(), |
161 "window.domAutomationController.send(video.receivedKeyMessage);", | 158 "window.domAutomationController.send(video.receivedKeyMessage);", |
162 &receivedKeyMessage)); | 159 &receivedKeyMessage)); |
163 ASSERT_TRUE(receivedKeyMessage); | 160 ASSERT_TRUE(receivedKeyMessage); |
164 } | 161 } |
165 | 162 |
166 protected: | 163 protected: |
167 // Registers any CDM plugins not registered by default. | 164 #if defined(ENABLE_PEPPER_CDMS) |
168 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 165 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
169 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); | 166 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, |
170 RegisterPepperPlugin(command_line, kWidevineLibraryName, | 167 kWidevineKeySystem); |
171 kWidevineKeySystem); | |
172 } | 168 } |
| 169 #endif // defined(ENABLE_PEPPER_CDMS) |
173 }; | 170 }; |
174 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 171 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
175 | 172 |
176 INSTANTIATE_TEST_CASE_P(ClearKey, EncryptedMediaTest, | 173 INSTANTIATE_TEST_CASE_P(ClearKey, EncryptedMediaTest, |
177 ::testing::Values(kClearKeyKeySystem)); | 174 ::testing::Values(kClearKeyKeySystem)); |
178 | 175 |
| 176 // External Clear Key is currently only used on platforms that use Pepper CDMs. |
| 177 #if defined(ENABLE_PEPPER_CDMS) |
179 INSTANTIATE_TEST_CASE_P(ExternalClearKey, EncryptedMediaTest, | 178 INSTANTIATE_TEST_CASE_P(ExternalClearKey, EncryptedMediaTest, |
180 ::testing::Values(kExternalClearKeyKeySystem)); | 179 ::testing::Values(kExternalClearKeyKeySystem)); |
| 180 #endif |
181 | 181 |
182 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, InvalidKeySystem) { | 182 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, InvalidKeySystem) { |
183 const string16 kExpected = ASCIIToUTF16( | 183 const string16 kExpected = ASCIIToUTF16( |
184 StringToUpperASCII(std::string("GenerateKeyRequestException"))); | 184 StringToUpperASCII(std::string("GenerateKeyRequestException"))); |
185 TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo, | 185 TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo, |
186 "com.example.invalid", kExpected); | 186 "com.example.invalid", kExpected); |
187 } | 187 } |
188 | 188 |
189 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { | 189 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { |
190 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly, GetParam(), kEnded); | 190 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly, GetParam(), kEnded); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 267 |
268 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, Playback_AudioOnly_MP4) { | 268 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, Playback_AudioOnly_MP4) { |
269 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly, | 269 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly, |
270 kWidevineKeySystem); | 270 kWidevineKeySystem); |
271 } | 271 } |
272 #endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 272 #endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
273 #endif // !defined(DISABLE_WIDEVINE_CDM_BROWSERTESTS) | 273 #endif // !defined(DISABLE_WIDEVINE_CDM_BROWSERTESTS) |
274 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 274 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
275 | 275 |
276 } // namespace content | 276 } // namespace content |
OLD | NEW |