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

Side by Side Diff: content/browser/media/encrypted_media_browsertest.cc

Issue 15028015: Conditionally build support for Pepper-based CDMs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback and cleaned up a few more things. Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 base::FilePath::CharType kClearKeyCdmAdapterFileName[] =
32 static const char kClearKeyLibraryName[] = "clearkeycdmadapter.dll"; 33 #if defined(OS_MACOSX)
33 static const char kWidevineLibraryName[] = "widevinecdmadapter.dll"; 34 FILE_PATH_LITERAL("clearkeycdmadapter.plugin");
34 #elif defined(OS_MACOSX) 35 #elif defined(OS_WIN)
35 static const char kClearKeyLibraryName[] = "clearkeycdmadapter.plugin"; 36 FILE_PATH_LITERAL("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 FILE_PATH_LITERAL("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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 std::string fail_message; 98 std::string fail_message;
99 EXPECT_TRUE(ExecuteScriptAndExtractString( 99 EXPECT_TRUE(ExecuteScriptAndExtractString(
100 shell()->web_contents(), 100 shell()->web_contents(),
101 "window.domAutomationController.send(failMessage);", 101 "window.domAutomationController.send(failMessage);",
102 &fail_message)); 102 &fail_message));
103 LOG(INFO) << "Test failed: " << fail_message; 103 LOG(INFO) << "Test failed: " << fail_message;
104 } 104 }
105 } 105 }
106 106
107 protected: 107 protected:
108 // Registers any CDM plugins not registered by default. 108 #if defined(ENABLE_PEPPER_CDMS)
109 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 109 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
110 RegisterPepperPlugin(command_line, kClearKeyLibraryName, 110 RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName,
111 kExternalClearKeyKeySystem); 111 kExternalClearKeyKeySystem);
112 } 112 }
113 113
114 virtual void RegisterPepperPlugin(CommandLine* command_line, 114 virtual void RegisterPepperCdm(CommandLine* command_line,
115 const std::string& library_name, 115 const base::FilePath::StringType& adapter_name,
116 const std::string& key_system) { 116 const std::string& key_system) {
117 // Append the switch to register the Clear Key CDM Adapter. 117 // Append the switch to register the Clear Key CDM Adapter.
118 base::FilePath plugin_dir; 118 base::FilePath plugin_dir;
119 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 119 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
120 #if defined(OS_WIN) 120 base::FilePath plugin_lib = plugin_dir.Append(adapter_name);
121 base::FilePath plugin_lib = plugin_dir.Append(ASCIIToWide(library_name));
122 #else
123 base::FilePath plugin_lib = plugin_dir.Append(library_name);
124 #endif
125 EXPECT_TRUE(file_util::PathExists(plugin_lib)); 121 EXPECT_TRUE(file_util::PathExists(plugin_lib));
126 base::FilePath::StringType pepper_plugin = plugin_lib.value(); 122 base::FilePath::StringType pepper_plugin = plugin_lib.value();
127 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;")); 123 pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;"));
128 #if defined(OS_WIN) 124 #if defined(OS_WIN)
129 pepper_plugin.append(ASCIIToWide(webkit_media::GetPluginType(key_system))); 125 pepper_plugin.append(ASCIIToWide(webkit_media::GetPepperType(key_system)));
130 #else 126 #else
131 pepper_plugin.append(webkit_media::GetPluginType(key_system)); 127 pepper_plugin.append(webkit_media::GetPepperType(key_system));
132 #endif 128 #endif
133 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 129 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
134 pepper_plugin); 130 pepper_plugin);
131 #endif // defined(ENABLE_PEPPER_CDMS)
xhwang 2013/05/14 16:35:44 shouldn't this be after line 132?
ddorwin 2013/05/14 20:14:28 Done. Fixed in Patch 5.
135 } 132 }
136 }; 133 };
137 134
138 #if defined(WIDEVINE_CDM_AVAILABLE) 135 #if defined(WIDEVINE_CDM_AVAILABLE)
139 class WVEncryptedMediaTest : public EncryptedMediaTest { 136 class WVEncryptedMediaTest : public EncryptedMediaTest {
140 public: 137 public:
141 // Tests that the following happen after trying to play encrypted media: 138 // Tests that the following happen after trying to play encrypted media:
142 // - webkitneedkey event is fired. 139 // - webkitneedkey event is fired.
143 // - webkitGenerateKeyRequest() does not fail. 140 // - webkitGenerateKeyRequest() does not fail.
144 // - webkitkeymessage is fired 141 // - webkitkeymessage is fired
(...skipping 13 matching lines...) Expand all
158 key_system, kExpectedWebKitError); 155 key_system, kExpectedWebKitError);
159 bool receivedKeyMessage = false; 156 bool receivedKeyMessage = false;
160 EXPECT_TRUE(ExecuteScriptAndExtractBool( 157 EXPECT_TRUE(ExecuteScriptAndExtractBool(
161 shell()->web_contents(), 158 shell()->web_contents(),
162 "window.domAutomationController.send(video.receivedKeyMessage);", 159 "window.domAutomationController.send(video.receivedKeyMessage);",
163 &receivedKeyMessage)); 160 &receivedKeyMessage));
164 ASSERT_TRUE(receivedKeyMessage); 161 ASSERT_TRUE(receivedKeyMessage);
165 } 162 }
166 163
167 protected: 164 protected:
168 // Registers any CDM plugins not registered by default. 165 #if defined(ENABLE_PEPPER_CDMS)
169 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 166 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
170 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); 167 RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName,
171 RegisterPepperPlugin(command_line, kWidevineLibraryName, 168 kWidevineKeySystem);
172 kWidevineKeySystem);
173 } 169 }
170 #endif // defined(ENABLE_PEPPER_CDMS)
174 }; 171 };
175 #endif // defined(WIDEVINE_CDM_AVAILABLE) 172 #endif // defined(WIDEVINE_CDM_AVAILABLE)
176 173
177 INSTANTIATE_TEST_CASE_P(ClearKey, EncryptedMediaTest, 174 INSTANTIATE_TEST_CASE_P(ClearKey, EncryptedMediaTest,
178 ::testing::Values(kClearKeyKeySystem)); 175 ::testing::Values(kClearKeyKeySystem));
179 176
177 // External Clear Key is currently only used on platforms that use Pepper CDMs.
178 #if defined(ENABLE_PEPPER_CDMS)
180 INSTANTIATE_TEST_CASE_P(ExternalClearKey, EncryptedMediaTest, 179 INSTANTIATE_TEST_CASE_P(ExternalClearKey, EncryptedMediaTest,
181 ::testing::Values(kExternalClearKeyKeySystem)); 180 ::testing::Values(kExternalClearKeyKeySystem));
181 #endif
xhwang 2013/05/14 16:35:44 nit: #endif // defined(ENABLE_PEPPER_CDMS)
ddorwin 2013/05/14 20:14:28 I believe the general pattern is to add a comment
182 182
183 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, InvalidKeySystem) { 183 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, InvalidKeySystem) {
184 const string16 kExpected = ASCIIToUTF16( 184 const string16 kExpected = ASCIIToUTF16(
185 StringToUpperASCII(std::string("GenerateKeyRequestException"))); 185 StringToUpperASCII(std::string("GenerateKeyRequestException")));
186 TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo, 186 TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo,
187 "com.example.invalid", kExpected); 187 "com.example.invalid", kExpected);
188 } 188 }
189 189
190 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { 190 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
191 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly, GetParam(), 191 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly, GetParam(),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, Playback_AudioOnly_MP4) { 270 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, Playback_AudioOnly_MP4) {
271 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly, 271 TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly,
272 kWidevineKeySystem); 272 kWidevineKeySystem);
273 } 273 }
274 #endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) 274 #endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
275 #endif // !defined(DISABLE_WIDEVINE_CDM_BROWSERTESTS) 275 #endif // !defined(DISABLE_WIDEVINE_CDM_BROWSERTESTS)
276 #endif // defined(WIDEVINE_CDM_AVAILABLE) 276 #endif // defined(WIDEVINE_CDM_AVAILABLE)
277 277
278 } // namespace content 278 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698