875a00389b7fd9a5057816d0db8226856453f2a6
[platform/framework/web/crosswalk.git] / src / chrome / browser / media / encrypted_media_browsertest.cc
1 // Copyright 2013 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.
4
5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/win/windows_version.h"
10 #include "chrome/browser/media/media_browsertest.h"
11 #include "chrome/browser/media/test_license_server.h"
12 #include "chrome/browser/media/wv_test_license_server_config.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest-spi.h"
18 #if defined(OS_ANDROID)
19 #include "base/android/build_info.h"
20 #endif
21
22 #include "widevine_cdm_version.h"  //  In SHARED_INTERMEDIATE_DIR.
23
24 #if defined(ENABLE_PEPPER_CDMS)
25 // Platform-specific filename relative to the chrome executable.
26 const char kClearKeyCdmAdapterFileName[] =
27 #if defined(OS_MACOSX)
28     "clearkeycdmadapter.plugin";
29 #elif defined(OS_WIN)
30     "clearkeycdmadapter.dll";
31 #elif defined(OS_POSIX)
32     "libclearkeycdmadapter.so";
33 #endif
34
35 const char kClearKeyCdmPluginMimeType[] = "application/x-ppapi-clearkey-cdm";
36 #endif  // defined(ENABLE_PEPPER_CDMS)
37
38 // Available key systems.
39 const char kClearKeyKeySystem[] = "org.w3.clearkey";
40 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey";
41 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
42 const char kExternalClearKeyDecryptOnlyKeySystem[] =
43     "org.chromium.externalclearkey.decryptonly";
44 const char kExternalClearKeyFileIOTestKeySystem[] =
45     "org.chromium.externalclearkey.fileiotest";
46 const char kExternalClearKeyInitializeFailKeySystem[] =
47     "org.chromium.externalclearkey.initializefail";
48 const char kExternalClearKeyCrashKeySystem[] =
49     "org.chromium.externalclearkey.crash";
50
51 // Supported media types.
52 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
53 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
54 const char kWebMVP9VideoOnly[] = "video/webm; codecs=\"vp9\"";
55 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
56 #if defined(USE_PROPRIETARY_CODECS)
57 const char kMP4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"";
58 const char kMP4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\"";
59 #endif  // defined(USE_PROPRIETARY_CODECS)
60
61 // Sessions to load.
62 const char kNoSessionToLoad[] = "";
63 const char kLoadableSession[] = "LoadableSession";
64 const char kUnknownSession[] = "UnknownSession";
65
66 // EME-specific test results and errors.
67 const char kEmeKeyError[] = "KEYERROR";
68 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
69 const char kFileIOTestSuccess[] = "FILEIOTESTSUCCESS";
70
71 // The type of video src used to load media.
72 enum SrcType {
73   SRC,
74   MSE
75 };
76
77 // Whether to use prefixed or unprefixed EME.
78 enum EmeVersion {
79   PREFIXED,
80   UNPREFIXED
81 };
82
83 // MSE is available on all desktop platforms and on Android 4.1 and later.
84 static bool IsMSESupported() {
85 #if defined(OS_ANDROID)
86   if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
87     VLOG(0) << "MSE is only supported in Android 4.1 and later.";
88     return false;
89   }
90 #endif  // defined(OS_ANDROID)
91   return true;
92 }
93
94 static bool IsParentKeySystemOf(const std::string& parent_key_system,
95                                 const std::string& key_system) {
96   std::string prefix = parent_key_system + '.';
97   return key_system.substr(0, prefix.size()) == prefix;
98 }
99
100 // Base class for encrypted media tests.
101 class EncryptedMediaTestBase : public MediaBrowserTest {
102  public:
103   EncryptedMediaTestBase() : is_pepper_cdm_registered_(false) {}
104
105   bool IsExternalClearKey(const std::string& key_system) {
106     return key_system == kExternalClearKeyKeySystem ||
107            IsParentKeySystemOf(kExternalClearKeyKeySystem, key_system);
108   }
109
110 #if defined(WIDEVINE_CDM_AVAILABLE)
111   bool IsWidevine(const std::string& key_system) {
112     return key_system == kWidevineKeySystem;
113   }
114 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
115
116   void RunEncryptedMediaTestPage(const std::string& html_page,
117                                  const std::string& key_system,
118                                  std::vector<StringPair>* query_params,
119                                  const std::string& expected_title) {
120     StartLicenseServerIfNeeded(key_system, query_params);
121     RunMediaTestPage(html_page, query_params, expected_title, true);
122   }
123
124   // Tests |html_page| using |media_file| (with |media_type|) and |key_system|.
125   // When |session_to_load| is not empty, the test will try to load
126   // |session_to_load| with stored keys, instead of creating a new session
127   // and trying to update it with licenses.
128   // When |force_invalid_response| is true, the test will provide invalid
129   // responses, which should trigger errors.
130   // TODO(xhwang): Find an easier way to pass multiple configuration test
131   // options.
132   void RunEncryptedMediaTest(const std::string& html_page,
133                              const std::string& media_file,
134                              const std::string& media_type,
135                              const std::string& key_system,
136                              SrcType src_type,
137                              EmeVersion eme_version,
138                              const std::string& session_to_load,
139                              bool force_invalid_response,
140                              const std::string& expected_title) {
141     if (src_type == MSE && !IsMSESupported()) {
142       VLOG(0) << "Skipping test - MSE not supported.";
143       return;
144     }
145     std::vector<StringPair> query_params;
146     query_params.push_back(std::make_pair("mediaFile", media_file));
147     query_params.push_back(std::make_pair("mediaType", media_type));
148     query_params.push_back(std::make_pair("keySystem", key_system));
149     if (src_type == MSE)
150       query_params.push_back(std::make_pair("useMSE", "1"));
151     if (eme_version == PREFIXED)
152       query_params.push_back(std::make_pair("usePrefixedEME", "1"));
153     if (force_invalid_response)
154       query_params.push_back(std::make_pair("forceInvalidResponse", "1"));
155     if (!session_to_load.empty())
156       query_params.push_back(std::make_pair("sessionToLoad", session_to_load));
157     RunEncryptedMediaTestPage(html_page, key_system, &query_params,
158                               expected_title);
159   }
160
161   void RunSimpleEncryptedMediaTest(const std::string& media_file,
162                                    const std::string& media_type,
163                                    const std::string& key_system,
164                                    SrcType src_type,
165                                    EmeVersion eme_version) {
166     std::string expected_title = kEnded;
167     if (!IsPlayBackPossible(key_system))
168       expected_title = kEmeKeyError;
169
170     RunEncryptedMediaTest("encrypted_media_player.html",
171                           media_file,
172                           media_type,
173                           key_system,
174                           src_type,
175                           eme_version,
176                           kNoSessionToLoad,
177                           false,
178                           expected_title);
179     // Check KeyMessage received for all key systems.
180     bool receivedKeyMessage = false;
181     EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
182         browser()->tab_strip_model()->GetActiveWebContents(),
183         "window.domAutomationController.send(video.receivedKeyMessage);",
184         &receivedKeyMessage));
185     EXPECT_TRUE(receivedKeyMessage);
186   }
187
188
189   void StartLicenseServerIfNeeded(const std::string& key_system,
190                                   std::vector<StringPair>* query_params) {
191     scoped_ptr<TestLicenseServerConfig> config = GetServerConfig(key_system);
192     if (!config)
193       return;
194     license_server_.reset(new TestLicenseServer(config.Pass()));
195     EXPECT_TRUE(license_server_->Start());
196     query_params->push_back(std::make_pair("licenseServerURL",
197         license_server_->GetServerURL()));
198   }
199
200   bool IsPlayBackPossible(const std::string& key_system) {
201 #if defined(WIDEVINE_CDM_AVAILABLE)
202     if (IsWidevine(key_system) && !GetServerConfig(key_system))
203       return false;
204 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
205     return true;
206   }
207
208   scoped_ptr<TestLicenseServerConfig> GetServerConfig(
209       const std::string& key_system) {
210 #if defined(WIDEVINE_CDM_AVAILABLE)
211     if (IsWidevine(key_system)) {
212       scoped_ptr<TestLicenseServerConfig> config =
213          scoped_ptr<TestLicenseServerConfig>(new WVTestLicenseServerConfig());
214       if (config->IsPlatformSupported())
215         return config.Pass();
216     }
217 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
218     return scoped_ptr<TestLicenseServerConfig>();
219   }
220
221  protected:
222   scoped_ptr<TestLicenseServer> license_server_;
223
224   // We want to fail quickly when a test fails because an error is encountered.
225   virtual void AddWaitForTitles(content::TitleWatcher* title_watcher) OVERRIDE {
226     MediaBrowserTest::AddWaitForTitles(title_watcher);
227     title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
228     title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeKeyError));
229   }
230
231   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
232 #if defined(OS_ANDROID)
233     command_line->AppendSwitch(
234         switches::kDisableGestureRequirementForMediaPlayback);
235 #endif  // defined(OS_ANDROID)
236   }
237
238   void SetUpCommandLineForKeySystem(const std::string& key_system,
239                                     CommandLine* command_line) {
240     if (GetServerConfig(key_system))
241       // Since the web and license servers listen on different ports, we need to
242       // disable web-security to send license requests to the license server.
243       // TODO(shadi): Add port forwarding to the test web server configuration.
244       command_line->AppendSwitch(switches::kDisableWebSecurity);
245
246 #if defined(ENABLE_PEPPER_CDMS)
247     if (IsExternalClearKey(key_system)) {
248       RegisterPepperCdm(command_line, kClearKeyCdmAdapterFileName, key_system);
249     }
250 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
251     else if (IsWidevine(key_system)) {
252       RegisterPepperCdm(command_line, kWidevineCdmAdapterFileName, key_system);
253     }
254 #endif  // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
255 #endif  // defined(ENABLE_PEPPER_CDMS)
256   }
257
258  private:
259 #if defined(ENABLE_PEPPER_CDMS)
260   void RegisterPepperCdm(CommandLine* command_line,
261                          const std::string& adapter_name,
262                          const std::string& key_system) {
263     DCHECK(!is_pepper_cdm_registered_)
264         << "RegisterPepperCdm() can only be called once.";
265     is_pepper_cdm_registered_ = true;
266
267     // Append the switch to register the Clear Key CDM Adapter.
268     base::FilePath plugin_dir;
269     EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
270     base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name);
271     EXPECT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value();
272     base::FilePath::StringType pepper_plugin = plugin_lib.value();
273     pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;"));
274 #if defined(OS_WIN)
275     pepper_plugin.append(base::ASCIIToWide(GetPepperType(key_system)));
276 #else
277     pepper_plugin.append(GetPepperType(key_system));
278 #endif
279     command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
280                                      pepper_plugin);
281   }
282
283   // Adapted from key_systems.cc.
284   std::string GetPepperType(const std::string& key_system) {
285     if (IsExternalClearKey(key_system))
286       return kClearKeyCdmPluginMimeType;
287 #if defined(WIDEVINE_CDM_AVAILABLE)
288     if (IsWidevine(key_system))
289       return kWidevineCdmPluginMimeType;
290 #endif  // WIDEVINE_CDM_AVAILABLE
291
292     NOTREACHED();
293     return "";
294   }
295 #endif  // defined(ENABLE_PEPPER_CDMS)
296
297   bool is_pepper_cdm_registered_;
298 };
299
300 #if defined(ENABLE_PEPPER_CDMS)
301 // Tests encrypted media playback using ExternalClearKey key system in
302 // decrypt-and-decode mode.
303 class ECKEncryptedMediaTest : public EncryptedMediaTestBase {
304  public:
305   // We use special |key_system| names to do non-playback related tests, e.g.
306   // kExternalClearKeyFileIOTestKeySystem is used to test file IO.
307   void TestNonPlaybackCases(const std::string& key_system,
308                             const std::string& expected_title) {
309     // Since we do not test playback, arbitrarily choose a test file and source
310     // type.
311     RunEncryptedMediaTest("encrypted_media_player.html",
312                           "bear-a-enc_a.webm",
313                           kWebMAudioOnly,
314                           key_system,
315                           SRC,
316                           PREFIXED,
317                           kNoSessionToLoad,
318                           false,
319                           expected_title);
320   }
321
322  protected:
323   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
324     EncryptedMediaTestBase::SetUpCommandLine(command_line);
325     SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
326   }
327 };
328
329 #if defined(WIDEVINE_CDM_AVAILABLE)
330 // Tests encrypted media playback using Widevine key system.
331 class WVEncryptedMediaTest : public EncryptedMediaTestBase {
332  protected:
333   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
334     EncryptedMediaTestBase::SetUpCommandLine(command_line);
335     command_line->AppendSwitch(switches::kEnableEncryptedMedia);
336     SetUpCommandLineForKeySystem(kWidevineKeySystem, command_line);
337   }
338 };
339
340 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
341 #endif  // defined(ENABLE_PEPPER_CDMS)
342
343 // Tests encrypted media playback with a combination of parameters:
344 // - char*: Key system name.
345 // - bool: True to load media using MSE, otherwise use src.
346 // - bool: True to use unprefixed EME, otherwise use prefixed EME.
347 //
348 // Note: Only parameterized (*_P) tests can be used. Non-parameterized (*_F)
349 // tests will crash at GetParam(). To add non-parameterized tests, use
350 // EncryptedMediaTestBase or one of its subclasses (e.g. WVEncryptedMediaTest).
351 class EncryptedMediaTest
352     : public EncryptedMediaTestBase,
353       public testing::WithParamInterface<
354           std::tr1::tuple<const char*, SrcType, EmeVersion> > {
355  public:
356   std::string CurrentKeySystem() {
357     return std::tr1::get<0>(GetParam());
358   }
359
360   SrcType CurrentSourceType() {
361     return std::tr1::get<1>(GetParam());
362   }
363
364   EmeVersion CurrentEmeVersion() {
365     return std::tr1::get<2>(GetParam());
366   }
367
368   void TestSimplePlayback(const std::string& encrypted_media,
369                           const std::string& media_type) {
370     RunSimpleEncryptedMediaTest(encrypted_media,
371                                 media_type,
372                                 CurrentKeySystem(),
373                                 CurrentSourceType(),
374                                 CurrentEmeVersion());
375   }
376
377   void RunInvalidResponseTest() {
378     RunEncryptedMediaTest("encrypted_media_player.html",
379                           "bear-320x240-av-enc_av.webm",
380                           kWebMAudioVideo,
381                           CurrentKeySystem(),
382                           CurrentSourceType(),
383                           CurrentEmeVersion(),
384                           kNoSessionToLoad,
385                           true,
386                           kEmeKeyError);
387   }
388
389   void TestFrameSizeChange() {
390     RunEncryptedMediaTest("encrypted_frame_size_change.html",
391                           "frame_size_change-av-enc-v.webm",
392                           kWebMAudioVideo,
393                           CurrentKeySystem(),
394                           CurrentSourceType(),
395                           CurrentEmeVersion(),
396                           kNoSessionToLoad,
397                           false,
398                           kEnded);
399   }
400
401   void TestConfigChange() {
402     DCHECK(IsMSESupported());
403     std::vector<StringPair> query_params;
404     query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
405     query_params.push_back(std::make_pair("runEncrypted", "1"));
406     if (CurrentEmeVersion() == PREFIXED)
407       query_params.push_back(std::make_pair("usePrefixedEME", "1"));
408     RunEncryptedMediaTestPage("mse_config_change.html",
409                               CurrentKeySystem(),
410                               &query_params,
411                               kEnded);
412   }
413
414  protected:
415   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
416     EncryptedMediaTestBase::SetUpCommandLine(command_line);
417     SetUpCommandLineForKeySystem(CurrentKeySystem(), command_line);
418
419     if (CurrentEmeVersion() == UNPREFIXED)
420       command_line->AppendSwitch(switches::kEnableEncryptedMedia);
421   }
422 };
423
424 using ::testing::Combine;
425 using ::testing::Values;
426
427 #if !defined(OS_ANDROID)
428 INSTANTIATE_TEST_CASE_P(SRC_ClearKey_Prefixed,
429                         EncryptedMediaTest,
430                         Combine(Values(kPrefixedClearKeyKeySystem),
431                                 Values(SRC),
432                                 Values(PREFIXED)));
433
434 // TODO(jrummell): Enable unprefixed tests before shipping unprefixed EME.
435 // Disabled now as they don't provide much additional coverage, but do take a
436 // bit of time to execute.
437 INSTANTIATE_TEST_CASE_P(DISABLED_SRC_ClearKey,
438                         EncryptedMediaTest,
439                         Combine(Values(kClearKeyKeySystem),
440                                 Values(SRC),
441                                 Values(UNPREFIXED)));
442 #endif  // !defined(OS_ANDROID)
443
444 INSTANTIATE_TEST_CASE_P(MSE_ClearKey_Prefixed,
445                         EncryptedMediaTest,
446                         Combine(Values(kPrefixedClearKeyKeySystem),
447                                 Values(MSE),
448                                 Values(PREFIXED)));
449 INSTANTIATE_TEST_CASE_P(MSE_ClearKey,
450                         EncryptedMediaTest,
451                         Combine(Values(kClearKeyKeySystem),
452                                 Values(MSE),
453                                 Values(UNPREFIXED)));
454
455 // External Clear Key is currently only used on platforms that use Pepper CDMs.
456 #if defined(ENABLE_PEPPER_CDMS)
457 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey_Prefixed,
458                         EncryptedMediaTest,
459                         Combine(Values(kExternalClearKeyKeySystem),
460                                 Values(SRC),
461                                 Values(PREFIXED)));
462 INSTANTIATE_TEST_CASE_P(SRC_ExternalClearKey,
463                         EncryptedMediaTest,
464                         Combine(Values(kExternalClearKeyKeySystem),
465                                 Values(SRC),
466                                 Values(UNPREFIXED)));
467 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey_Prefixed,
468                         EncryptedMediaTest,
469                         Combine(Values(kExternalClearKeyKeySystem),
470                                 Values(MSE),
471                                 Values(PREFIXED)));
472 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKey,
473                         EncryptedMediaTest,
474                         Combine(Values(kExternalClearKeyKeySystem),
475                                 Values(MSE),
476                                 Values(UNPREFIXED)));
477 // To reduce test time, only run ExternalClearKeyDecryptOnly with MSE.
478 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly_Prefixed,
479                         EncryptedMediaTest,
480                         Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
481                                 Values(MSE),
482                                 Values(PREFIXED)));
483 INSTANTIATE_TEST_CASE_P(MSE_ExternalClearKeyDecryptOnly,
484                         EncryptedMediaTest,
485                         Combine(Values(kExternalClearKeyDecryptOnlyKeySystem),
486                                 Values(MSE),
487                                 Values(UNPREFIXED)));
488 #endif // defined(ENABLE_PEPPER_CDMS)
489
490 #if defined(WIDEVINE_CDM_AVAILABLE)
491 // This test doesn't fully test playback with Widevine. So we only run Widevine
492 // test with MSE (no SRC) to reduce test time. Also, on Android EME only works
493 // with MSE and we cannot run this test with SRC.
494 INSTANTIATE_TEST_CASE_P(MSE_Widevine_Prefixed,
495                         EncryptedMediaTest,
496                         Combine(Values(kWidevineKeySystem),
497                                 Values(MSE),
498                                 Values(PREFIXED)));
499
500 // Following tests fail if Widevine is loaded as a component, crbug.com/356833.
501 #if !defined(WIDEVINE_CDM_IS_COMPONENT)
502 INSTANTIATE_TEST_CASE_P(MSE_Widevine,
503                         EncryptedMediaTest,
504                         Combine(Values(kWidevineKeySystem),
505                                 Values(MSE),
506                                 Values(UNPREFIXED)));
507 #endif  // !defined(WIDEVINE_CDM_IS_COMPONENT)
508 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
509
510 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
511   TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly);
512 }
513
514 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
515   TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo);
516 }
517
518 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
519   TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo);
520 }
521
522 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
523   TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly);
524 }
525
526 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
527   TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo);
528 }
529
530 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VP9Video_WebM) {
531 #if defined(WIDEVINE_CDM_AVAILABLE)
532   // TODO(xhwang): Remove this once VP9 is supported by Widevine CDM.
533   // See http://crbug.com/361318.
534   if (IsWidevine(CurrentKeySystem())) {
535     VLOG(0) << "VP9 not supported in Widevine CDM.";
536     return;
537   }
538 #endif
539   TestSimplePlayback("bear-320x240-v-vp9-enc_v.webm", kWebMVP9VideoOnly);
540 }
541
542 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, InvalidResponseKeyError) {
543   RunInvalidResponseTest();
544 }
545
546 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
547   if (CurrentSourceType() != MSE || !IsMSESupported()) {
548     VLOG(0) << "Skipping test - ConfigChange test requires MSE.";
549     return;
550   }
551   if (!IsPlayBackPossible(CurrentKeySystem())) {
552     VLOG(0) << "Skipping test - ConfigChange test requires video playback.";
553     return;
554   }
555   TestConfigChange();
556 }
557
558 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
559   // Times out on Windows XP. http://crbug.com/171937
560 #if defined(OS_WIN)
561   if (base::win::GetVersion() < base::win::VERSION_VISTA)
562     return;
563 #endif
564   if (!IsPlayBackPossible(CurrentKeySystem())) {
565     VLOG(0) << "Skipping test - FrameSizeChange test requires video playback.";
566     return;
567   }
568   TestFrameSizeChange();
569 }
570
571 #if defined(USE_PROPRIETARY_CODECS)
572 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_MP4) {
573   // MP4 without MSE is not support yet, http://crbug.com/170793.
574   if (CurrentSourceType() != MSE) {
575     VLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
576     return;
577   }
578   TestSimplePlayback("bear-640x360-v_frag-cenc.mp4", kMP4VideoOnly);
579 }
580
581 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_MP4) {
582   // MP4 without MSE is not support yet, http://crbug.com/170793.
583   if (CurrentSourceType() != MSE) {
584     VLOG(0) << "Skipping test; Can only play MP4 encrypted streams by MSE.";
585     return;
586   }
587   TestSimplePlayback("bear-640x360-a_frag-cenc.mp4", kMP4AudioOnly);
588 }
589 #endif  // defined(USE_PROPRIETARY_CODECS)
590
591 #if defined(WIDEVINE_CDM_AVAILABLE)
592 // The parent key system cannot be used in generateKeyRequest.
593 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException_Prefixed) {
594   RunEncryptedMediaTest("encrypted_media_player.html",
595                         "bear-a-enc_a.webm",
596                         kWebMAudioOnly,
597                         "com.widevine",
598                         MSE,
599                         PREFIXED,
600                         kNoSessionToLoad,
601                         false,
602                         kEmeNotSupportedError);
603 }
604
605 // TODO(jrummell): http://crbug.com/349181
606 // The parent key system cannot be used when creating MediaKeys.
607 IN_PROC_BROWSER_TEST_F(WVEncryptedMediaTest, ParentThrowsException) {
608   RunEncryptedMediaTest("encrypted_media_player.html",
609                         "bear-a-enc_a.webm",
610                         kWebMAudioOnly,
611                         "com.widevine",
612                         MSE,
613                         UNPREFIXED,
614                         kNoSessionToLoad,
615                         false,
616                         kEmeNotSupportedError);
617 }
618 #endif  // defined(WIDEVINE_CDM_AVAILABLE)
619
620 #if defined(ENABLE_PEPPER_CDMS)
621 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, InitializeCDMFail) {
622   TestNonPlaybackCases(kExternalClearKeyInitializeFailKeySystem, kEmeKeyError);
623 }
624
625 // When CDM crashes, we should still get a decode error.
626 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMCrashDuringDecode) {
627   IgnorePluginCrash();
628   TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError);
629 }
630
631 // Testing that the media browser test does fail on plugin crash.
632 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, CDMExpectedCrash) {
633   // Plugin crash is not ignored by default, the test is expected to fail.
634   EXPECT_NONFATAL_FAILURE(
635       TestNonPlaybackCases(kExternalClearKeyCrashKeySystem, kError),
636       "plugin crash");
637 }
638
639 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, FileIOTest) {
640   TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem,
641                        kFileIOTestSuccess);
642 }
643
644 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadLoadableSession) {
645   RunEncryptedMediaTest("encrypted_media_player.html",
646                         "bear-320x240-v-enc_v.webm",
647                         kWebMVideoOnly,
648                         kExternalClearKeyKeySystem,
649                         SRC,
650                         PREFIXED,
651                         kLoadableSession,
652                         false,
653                         kEnded);
654 }
655
656 IN_PROC_BROWSER_TEST_F(ECKEncryptedMediaTest, LoadUnknownSession) {
657   // TODO(xhwang): Add a specific error for this failure, e.g. kSessionNotFound.
658   RunEncryptedMediaTest("encrypted_media_player.html",
659                         "bear-320x240-v-enc_v.webm",
660                         kWebMVideoOnly,
661                         kExternalClearKeyKeySystem,
662                         SRC,
663                         PREFIXED,
664                         kUnknownSession,
665                         false,
666                         kEmeKeyError);
667 }
668 #endif  // defined(ENABLE_PEPPER_CDMS)