Home | History | Annotate | Download | only in media
      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 <string>
      6 #include <vector>
      7 
      8 #include "base/base_switches.h"
      9 #include "base/command_line.h"
     10 #include "base/files/file_path.h"
     11 #include "base/path_service.h"
     12 #include "base/strings/utf_string_conversions.h"
     13 #include "chrome/browser/ui/browser.h"
     14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
     15 #include "chrome/common/chrome_paths.h"
     16 #include "chrome/test/base/in_process_browser_test.h"
     17 #include "chrome/test/base/ui_test_utils.h"
     18 #include "content/public/common/content_switches.h"
     19 #include "content/public/test/browser_test_utils.h"
     20 #include "media/base/test_data_util.h"
     21 #include "net/test/spawned_test_server/spawned_test_server.h"
     22 #include "url/gurl.h"
     23 
     24 #include "widevine_cdm_version.h"  // In SHARED_INTERMEDIATE_DIR.
     25 
     26 #if defined(OS_ANDROID)
     27 #error This file needs to be updated to run on Android.
     28 #endif
     29 
     30 #if defined(USE_PROPRIETARY_CODECS)
     31 #define EXPECT_PROPRIETARY EXPECT_TRUE
     32 #else
     33 #define EXPECT_PROPRIETARY EXPECT_FALSE
     34 #endif
     35 
     36 // Expectations for External Clear Key.
     37 #if defined(ENABLE_PEPPER_CDMS)
     38 #define EXPECT_ECK EXPECT_TRUE
     39 #define EXPECT_ECKPROPRIETARY EXPECT_PROPRIETARY
     40 #else
     41 #define EXPECT_ECK EXPECT_FALSE
     42 #define EXPECT_ECKPROPRIETARY EXPECT_FALSE
     43 #endif  // defined(ENABLE_PEPPER_CDMS)
     44 
     45 // Expectations for Widevine.
     46 // Note: Widevine is not available on platforms using components because
     47 // RegisterPepperCdm() cannot set the codecs.
     48 // TODO(ddorwin): Enable these tests after we have the ability to use the CUS
     49 // in these tests. See http://crbug.com/311724.
     50 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(WIDEVINE_CDM_IS_COMPONENT)
     51 #define EXPECT_WV EXPECT_TRUE
     52 
     53 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
     54 #define EXPECT_WVMP4 EXPECT_TRUE
     55 #define EXPECT_WVAVC1 EXPECT_TRUE
     56 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
     57 #define EXPECT_WVAVC1AAC EXPECT_TRUE
     58 #else
     59 #define EXPECT_WVAVC1AAC EXPECT_FALSE
     60 #endif  // defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
     61 #else  // !defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
     62 #define EXPECT_WVMP4 EXPECT_FALSE
     63 #define EXPECT_WVAVC1 EXPECT_FALSE
     64 #define EXPECT_WVAVC1AAC EXPECT_FALSE
     65 #endif  // defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
     66 
     67 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
     68 #define EXPECT_WVAAC EXPECT_TRUE
     69 #else
     70 #define EXPECT_WVAAC EXPECT_FALSE
     71 #endif
     72 
     73 #else  // defined(WIDEVINE_CDM_AVAILABLE) && !defined(WIDEVINE_CDM_IS_COMPONENT)
     74 #define EXPECT_WV EXPECT_FALSE
     75 #define EXPECT_WVMP4 EXPECT_FALSE
     76 #define EXPECT_WVAVC1 EXPECT_FALSE
     77 #define EXPECT_WVAVC1AAC EXPECT_FALSE
     78 #define EXPECT_WVAAC EXPECT_FALSE
     79 #endif  // defined(WIDEVINE_CDM_AVAILABLE) &&
     80         // !defined(WIDEVINE_CDM_IS_COMPONENT)
     81 
     82 namespace chrome {
     83 
     84 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
     85 const char kPrefixedClearKeyParent[] = "webkit-org.w3";
     86 // TODO(ddorwin): Duplicate prefixed tests for unprefixed.
     87 const char kUnprefixedClearKey[] = "org.w3.clearkey";
     88 const char kExternalClearKey[] = "org.chromium.externalclearkey";
     89 const char kWidevineAlpha[] = "com.widevine.alpha";
     90 const char kWidevine[] = "com.widevine";
     91 const char kWidevineAlphaHr[] = "com.widevine.alpha.hr";
     92 const char kWidevineAlphaHrNonCompositing[] =
     93     "com.widevine.alpha.hrnoncompositing";
     94 
     95 // TODO(xhwang): Simplify this test! See http://crbug.com/367158
     96 
     97 class EncryptedMediaIsTypeSupportedTest : public InProcessBrowserTest {
     98  protected:
     99   EncryptedMediaIsTypeSupportedTest()
    100       : is_test_page_loaded_(false), is_pepper_cdm_registered_(false) {
    101     vp8_codec_.push_back("vp8");
    102 
    103     vp80_codec_.push_back("vp8.0");
    104 
    105     vp9_codec_.push_back("vp9");
    106 
    107     vp90_codec_.push_back("vp9.0");
    108 
    109     vorbis_codec_.push_back("vorbis");
    110 
    111     vp8_and_vorbis_codecs_.push_back("vp8");
    112     vp8_and_vorbis_codecs_.push_back("vorbis");
    113 
    114     vp9_and_vorbis_codecs_.push_back("vp9");
    115     vp9_and_vorbis_codecs_.push_back("vorbis");
    116 
    117     avc1_codec_.push_back("avc1");
    118 
    119     avc1_extended_codec_.push_back("avc1.4D400C");
    120 
    121     avc1_dot_codec_.push_back("avc1.");
    122 
    123     avc2_codec_.push_back("avc2");
    124 
    125     avc3_codec_.push_back("avc3");
    126 
    127     avc3_extended_codec_.push_back("avc3.64001F");
    128 
    129     aac_codec_.push_back("mp4a.40.2");
    130 
    131     mp4a_invalid_no_extension_.push_back("mp4a");
    132 
    133     avc1_and_aac_codecs_.push_back("avc1");
    134     avc1_and_aac_codecs_.push_back("mp4a.40.2");
    135 
    136     avc3_and_aac_codecs_.push_back("avc3");
    137     avc3_and_aac_codecs_.push_back("mp4a.40.2");
    138 
    139     avc1_extended_and_aac_codecs_.push_back("avc1.4D400C");
    140     avc1_extended_and_aac_codecs_.push_back("mp4a.40.2");
    141 
    142     avc3_extended_and_aac_codecs_.push_back("avc3.64001F");
    143     avc3_extended_and_aac_codecs_.push_back("mp4a.40.2");
    144 
    145     unknown_codec_.push_back("foo");
    146 
    147     mixed_codecs_.push_back("vorbis");
    148     mixed_codecs_.push_back("avc1");
    149 
    150     vp8_invalid_extension_codec_.push_back("vp8.1");
    151   }
    152 
    153   typedef std::vector<std::string> CodecVector;
    154 
    155   const CodecVector& no_codecs() const { return no_codecs_; }
    156   const CodecVector& vp8_codec() const { return vp8_codec_; }
    157   const CodecVector& vp80_codec() const { return vp80_codec_; }
    158   const CodecVector& vp9_codec() const { return vp9_codec_; }
    159   const CodecVector& vp90_codec() const { return vp90_codec_; }
    160   const CodecVector& vorbis_codec() const { return vorbis_codec_; }
    161   const CodecVector& vp8_and_vorbis_codecs() const {
    162     return vp8_and_vorbis_codecs_;
    163   }
    164   const CodecVector& vp9_and_vorbis_codecs() const {
    165     return vp9_and_vorbis_codecs_;
    166   }
    167   const CodecVector& avc1_codec() const { return avc1_codec_; }
    168   const CodecVector& avc1_extended_codec() const {
    169     return avc1_extended_codec_;
    170   }
    171   const CodecVector& avc1_dot_codec() const { return avc1_dot_codec_; }
    172   const CodecVector& avc2_codec() const { return avc2_codec_; }
    173   const CodecVector& avc3_codec() const { return avc3_codec_; }
    174   const CodecVector& avc3_extended_codec() const {
    175     return avc3_extended_codec_;
    176   }
    177   const CodecVector& aac_codec() const { return aac_codec_; }
    178   const CodecVector& mp4a_invalid_no_extension() const {
    179     return mp4a_invalid_no_extension_;
    180   }
    181   const CodecVector& avc1_and_aac_codecs() const {
    182     return avc1_and_aac_codecs_;
    183   }
    184   const CodecVector& avc3_and_aac_codecs() const {
    185     return avc3_and_aac_codecs_;
    186   }
    187   const CodecVector& avc1_extended_and_aac_codecs() const {
    188     return avc1_extended_and_aac_codecs_;
    189   }
    190   const CodecVector& avc3_extended_and_aac_codecs() const {
    191     return avc3_extended_and_aac_codecs_;
    192   }
    193   const CodecVector& unknown_codec() const { return unknown_codec_; }
    194   const CodecVector& mixed_codecs() const { return mixed_codecs_; }
    195   const CodecVector& vp8_invalid_extension_codec() const {
    196     return vp8_invalid_extension_codec_;
    197   }
    198 
    199   // Update the command line to load |adapter_name| for
    200   // |pepper_type_for_key_system|.
    201   void RegisterPepperCdm(CommandLine* command_line,
    202                          const std::string& adapter_name,
    203                          const std::string& pepper_type_for_key_system,
    204                          bool expect_adapter_exists = true) {
    205     DCHECK(!is_pepper_cdm_registered_)
    206         << "RegisterPepperCdm() can only be called once.";
    207     is_pepper_cdm_registered_ = true;
    208 
    209     // Append the switch to register the appropriate adapter.
    210     base::FilePath plugin_dir;
    211     EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
    212     base::FilePath plugin_lib = plugin_dir.AppendASCII(adapter_name);
    213     EXPECT_EQ(expect_adapter_exists, base::PathExists(plugin_lib));
    214     base::FilePath::StringType pepper_plugin = plugin_lib.value();
    215     pepper_plugin.append(FILE_PATH_LITERAL("#CDM#0.1.0.0;"));
    216 #if defined(OS_WIN)
    217     pepper_plugin.append(base::ASCIIToWide(pepper_type_for_key_system));
    218 #else
    219     pepper_plugin.append(pepper_type_for_key_system);
    220 #endif
    221     command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
    222                                      pepper_plugin);
    223   }
    224 
    225   void LoadTestPage() {
    226     // Load the test page needed. IsConcreteSupportedKeySystem() needs some
    227     // JavaScript and a video loaded in order to work.
    228     if (!is_test_page_loaded_) {
    229       scoped_ptr<net::SpawnedTestServer> http_test_server(
    230           new net::SpawnedTestServer(net::SpawnedTestServer::TYPE_HTTP,
    231                                      net::SpawnedTestServer::kLocalhost,
    232                                      media::GetTestDataPath()));
    233       CHECK(http_test_server->Start());
    234       GURL gurl = http_test_server->GetURL(
    235           "files/test_key_system_instantiation.html");
    236       ui_test_utils::NavigateToURL(browser(), gurl);
    237       is_test_page_loaded_ = true;
    238     }
    239   }
    240 
    241   bool IsConcreteSupportedKeySystem(const std::string& key) {
    242     std::string command(
    243         "window.domAutomationController.send(testKeySystemInstantiation('");
    244     command.append(key);
    245     command.append("'));");
    246 
    247     // testKeySystemInstantiation() is a JavaScript function which needs to
    248     // be loaded.
    249     LoadTestPage();
    250 
    251     std::string result;
    252     EXPECT_TRUE(content::ExecuteScriptAndExtractString(
    253         browser()->tab_strip_model()->GetActiveWebContents(),
    254         command,
    255         &result));
    256     CHECK(result == "success" || result == "NotSupportedError") << result;
    257     return (result == "success");
    258   }
    259 
    260   bool IsSupportedKeySystemWithMediaMimeType(const std::string& type,
    261                                              const CodecVector& codecs,
    262                                              const std::string& keySystem) {
    263     std::string command("document.createElement('video').canPlayType(");
    264     if (type.empty()) {
    265       // Simple case, pass "null" as first argument.
    266       command.append("null");
    267       DCHECK(codecs.empty());
    268     } else {
    269       command.append("'");
    270       command.append(type);
    271       if (!codecs.empty()) {
    272         command.append("; codecs=\"");
    273         for (CodecVector::const_iterator it = codecs.begin();
    274              it != codecs.end();
    275              ++it) {
    276           command.append(*it);
    277           command.append(",");
    278         }
    279         command.replace(command.length() - 1, 1, "\"");
    280       }
    281       command.append("'");
    282     }
    283     command.append(",'");
    284     command.append(keySystem);
    285     command.append("')");
    286 
    287     std::string result;
    288     EXPECT_TRUE(content::ExecuteScriptAndExtractString(
    289         browser()->tab_strip_model()->GetActiveWebContents(),
    290         "window.domAutomationController.send(" + command + ");",
    291         &result));
    292     return (result == "maybe" || result == "probably");
    293   }
    294 
    295  private:
    296   const CodecVector no_codecs_;
    297   CodecVector vp8_codec_;
    298   CodecVector vp80_codec_;
    299   CodecVector vp9_codec_;
    300   CodecVector vp90_codec_;
    301   CodecVector vorbis_codec_;
    302   CodecVector vp8_and_vorbis_codecs_;
    303   CodecVector vp9_and_vorbis_codecs_;
    304   CodecVector avc1_codec_;
    305   CodecVector avc1_extended_codec_;
    306   CodecVector avc1_dot_codec_;
    307   CodecVector avc2_codec_;
    308   CodecVector avc3_codec_;
    309   CodecVector avc3_extended_codec_;
    310   CodecVector aac_codec_;
    311   CodecVector mp4a_invalid_no_extension_;
    312   CodecVector avc1_and_aac_codecs_;
    313   CodecVector avc3_and_aac_codecs_;
    314   CodecVector avc1_extended_and_aac_codecs_;
    315   CodecVector avc3_extended_and_aac_codecs_;
    316   CodecVector unknown_codec_;
    317   CodecVector mixed_codecs_;
    318   CodecVector vp8_invalid_extension_codec_;
    319   bool is_test_page_loaded_;
    320   bool is_pepper_cdm_registered_;
    321 };
    322 
    323 // For ExternalClearKey tests, ensure that the ClearKey adapter is loaded.
    324 class EncryptedMediaIsTypeSupportedExternalClearKeyTest
    325     : public EncryptedMediaIsTypeSupportedTest {
    326 #if defined(ENABLE_PEPPER_CDMS)
    327  protected:
    328   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    329     // Platform-specific filename relative to the chrome executable.
    330     const char adapter_file_name[] =
    331 #if defined(OS_MACOSX)
    332         "clearkeycdmadapter.plugin";
    333 #elif defined(OS_WIN)
    334         "clearkeycdmadapter.dll";
    335 #elif defined(OS_POSIX)
    336         "libclearkeycdmadapter.so";
    337 #endif
    338 
    339     const std::string pepper_name("application/x-ppapi-clearkey-cdm");
    340     RegisterPepperCdm(command_line, adapter_file_name, pepper_name);
    341   }
    342 #endif  // defined(ENABLE_PEPPER_CDMS)
    343 };
    344 
    345 // For Widevine tests, ensure that the Widevine adapter is loaded.
    346 class EncryptedMediaIsTypeSupportedWidevineTest
    347     : public EncryptedMediaIsTypeSupportedTest {
    348 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) && \
    349     defined(WIDEVINE_CDM_IS_COMPONENT)
    350  protected:
    351   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    352     // File name of the adapter on different platforms.
    353     const char adapter_file_name[] =
    354 #if defined(OS_MACOSX)
    355         "widevinecdmadapter.plugin";
    356 #elif defined(OS_WIN)
    357         "widevinecdmadapter.dll";
    358 #else  // OS_LINUX, etc.
    359         "libwidevinecdmadapter.so";
    360 #endif
    361 
    362     const std::string pepper_name("application/x-ppapi-widevine-cdm");
    363     RegisterPepperCdm(command_line, adapter_file_name, pepper_name);
    364   }
    365 #endif  // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) &&
    366         // defined(WIDEVINE_CDM_IS_COMPONENT)
    367 };
    368 
    369 #if defined(ENABLE_PEPPER_CDMS)
    370 // Registers ClearKey CDM with the wrong path (filename).
    371 class EncryptedMediaIsTypeSupportedClearKeyCDMRegisteredWithWrongPathTest
    372     : public EncryptedMediaIsTypeSupportedTest {
    373  protected:
    374   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    375    RegisterPepperCdm(command_line,
    376                      "clearkeycdmadapterwrongname.dll",
    377                      "application/x-ppapi-clearkey-cdm",
    378                      false);
    379   }
    380 };
    381 
    382 // Registers Widevine CDM with the wrong path (filename).
    383 class EncryptedMediaIsTypeSupportedWidevineCDMRegisteredWithWrongPathTest
    384     : public EncryptedMediaIsTypeSupportedTest {
    385  protected:
    386   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    387    RegisterPepperCdm(command_line,
    388                      "widevinecdmadapterwrongname.dll",
    389                      "application/x-ppapi-widevine-cdm",
    390                      false);
    391   }
    392 };
    393 #endif  // defined(ENABLE_PEPPER_CDMS)
    394 
    395 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, ClearKey_Basic) {
    396   EXPECT_TRUE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
    397   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    398       "video/webm", no_codecs(), kPrefixedClearKey));
    399 
    400   // Not yet out from behind the vendor prefix.
    401   EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey));
    402   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    403       "video/webm", no_codecs(), kUnprefixedClearKey));
    404 }
    405 
    406 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest, ClearKey_Parent) {
    407   // The parent should be supported but is not. See http://crbug.com/164303.
    408   EXPECT_FALSE(IsConcreteSupportedKeySystem(kPrefixedClearKeyParent));
    409   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    410       "video/webm", no_codecs(), kPrefixedClearKeyParent));
    411 }
    412 
    413 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest,
    414                        ClearKey_IsSupportedKeySystem_InvalidVariants) {
    415   // Case sensitive.
    416   EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.ClEaRkEy"));
    417   // This should fail, but currently canPlayType() converts it to lowercase.
    418   // See http://crbug.com/286036.
    419   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    420       "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy"));
    421 
    422   // TLDs are not allowed.
    423   EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org."));
    424   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    425       "video/webm", no_codecs(), "webkit-org."));
    426   EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org"));
    427   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    428       "video/webm", no_codecs(), "webkit-org"));
    429   EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
    430   EXPECT_FALSE(
    431       IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org."));
    432   EXPECT_FALSE(IsConcreteSupportedKeySystem("org"));
    433   EXPECT_FALSE(
    434       IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org"));
    435 
    436   // Extra period.
    437   EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3."));
    438   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    439       "video/webm", no_codecs(), "webkit-org.w3."));
    440 
    441   // Incomplete.
    442   EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearke"));
    443   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    444       "video/webm", no_codecs(), "webkit-org.w3.clearke"));
    445 
    446   // Extra character.
    447   EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkeyz"));
    448   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    449       "video/webm", no_codecs(), "webkit-org.w3.clearkeyz"));
    450 
    451   // There are no child key systems for Clear Key.
    452   EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.clearkey.foo"));
    453   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    454       "video/webm", no_codecs(), "webkit-org.w3.clearkey.foo"));
    455 }
    456 
    457 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest,
    458                        IsSupportedKeySystemWithMediaMimeType_ClearKey_NoType) {
    459   // These two should be true. See http://crbug.com/164303.
    460   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    461       std::string(), no_codecs(), kPrefixedClearKey));
    462   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    463       std::string(), no_codecs(), kPrefixedClearKeyParent));
    464 
    465   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    466       std::string(), no_codecs(), "webkit-org.w3.foo"));
    467   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    468       std::string(), no_codecs(), "webkit-org.w3.clearkey.foo"));
    469 }
    470 
    471 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest,
    472                        IsSupportedKeySystemWithMediaMimeType_ClearKey_WebM) {
    473   // Valid video types.
    474   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    475       "video/webm", no_codecs(), kPrefixedClearKey));
    476   // The parent should be supported but is not. See http://crbug.com/164303.
    477   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    478       "video/webm", no_codecs(), kPrefixedClearKeyParent));
    479   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    480       "video/webm", vp8_codec(), kPrefixedClearKey));
    481   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    482       "video/webm", vp80_codec(), kPrefixedClearKey));
    483   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    484       "video/webm", vp8_and_vorbis_codecs(), kPrefixedClearKey));
    485   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    486       "video/webm", vp9_codec(), kPrefixedClearKey));
    487   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    488       "video/webm", vp90_codec(), kPrefixedClearKey));
    489   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    490       "video/webm", vp9_and_vorbis_codecs(), kPrefixedClearKey));
    491   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    492       "video/webm", vorbis_codec(), kPrefixedClearKey));
    493 
    494   // Non-Webm codecs.
    495   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    496       "video/webm", avc1_codec(), kPrefixedClearKey));
    497   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    498       "video/webm", avc3_codec(), kPrefixedClearKey));
    499   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    500       "video/webm", unknown_codec(), kPrefixedClearKey));
    501   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    502       "video/webm", mixed_codecs(), kPrefixedClearKey));
    503   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    504       "video/webm", vp8_invalid_extension_codec(), kPrefixedClearKey));
    505 
    506   // Valid audio types.
    507   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    508       "audio/webm", no_codecs(), kPrefixedClearKey));
    509   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    510       "audio/webm", vorbis_codec(), kPrefixedClearKey));
    511 
    512   // Non-audio codecs.
    513   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    514       "audio/webm", vp8_codec(), kPrefixedClearKey));
    515   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    516       "audio/webm", vp8_and_vorbis_codecs(), kPrefixedClearKey));
    517   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    518       "audio/webm", vp9_codec(), kPrefixedClearKey));
    519   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    520       "audio/webm", vp9_and_vorbis_codecs(), kPrefixedClearKey));
    521 
    522   // Non-Webm codec.
    523   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    524       "audio/webm", aac_codec(), kPrefixedClearKey));
    525 }
    526 
    527 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest,
    528                        IsSupportedKeySystemWithMediaMimeType_ClearKey_MP4) {
    529   // Valid video types.
    530   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    531       "video/mp4", no_codecs(), kPrefixedClearKey));
    532   // The parent should be supported but is not. See http://crbug.com/164303.
    533   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    534       "video/mp4", no_codecs(), kPrefixedClearKeyParent));
    535   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    536       "video/mp4", avc1_codec(), kPrefixedClearKey));
    537   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    538       "video/mp4", avc3_codec(), kPrefixedClearKey));
    539   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    540       "video/mp4", avc1_and_aac_codecs(), kPrefixedClearKey));
    541   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    542       "video/mp4", avc3_and_aac_codecs(), kPrefixedClearKey));
    543   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    544       "video/mp4", aac_codec(), kPrefixedClearKey));
    545 
    546   // Extended codecs.
    547   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    548       "video/mp4", avc1_extended_codec(), kPrefixedClearKey));
    549   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    550       "video/mp4", avc3_extended_codec(), kPrefixedClearKey));
    551   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    552       "video/mp4", avc1_extended_and_aac_codecs(), kPrefixedClearKey));
    553   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    554       "video/mp4", avc3_extended_and_aac_codecs(), kPrefixedClearKey));
    555 
    556   // Invalid codec format: profile parameter must be present after the period.
    557   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    558       "video/mp4", avc1_dot_codec(), kPrefixedClearKey));
    559 
    560   // Invalid or Non-MP4 codecs.
    561   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    562       "video/mp4", avc2_codec(), kPrefixedClearKey));
    563   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    564       "video/mp4", mp4a_invalid_no_extension(), kPrefixedClearKey));
    565   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    566       "video/mp4", vp8_codec(), kPrefixedClearKey));
    567   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    568       "video/mp4", unknown_codec(), kPrefixedClearKey));
    569   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    570       "video/mp4", mixed_codecs(), kPrefixedClearKey));
    571   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    572       "video/mp4", vp8_invalid_extension_codec(), kPrefixedClearKey));
    573 
    574   // Valid audio types.
    575   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    576       "audio/mp4", no_codecs(), kPrefixedClearKey));
    577   EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    578       "audio/mp4", aac_codec(), kPrefixedClearKey));
    579 
    580   // Non-audio codecs.
    581   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    582       "audio/mp4", avc1_codec(), kPrefixedClearKey));
    583   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    584       "audio/mp4", avc3_codec(), kPrefixedClearKey));
    585   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    586       "audio/mp4", avc1_extended_codec(), kPrefixedClearKey));
    587   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    588       "audio/mp4", avc3_extended_codec(), kPrefixedClearKey));
    589   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    590       "audio/mp4", avc1_and_aac_codecs(), kPrefixedClearKey));
    591   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    592       "audio/mp4", avc3_and_aac_codecs(), kPrefixedClearKey));
    593   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    594       "audio/mp4", avc1_extended_and_aac_codecs(), kPrefixedClearKey));
    595   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    596       "audio/mp4", avc3_extended_and_aac_codecs(), kPrefixedClearKey));
    597 
    598   // Invalid or Non-MP4 codec.
    599   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    600       "audio/mp4", vorbis_codec(), kPrefixedClearKey));
    601   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    602       "audio/mp4", mp4a_invalid_no_extension(), kPrefixedClearKey));
    603 }
    604 
    605 //
    606 // External Clear Key
    607 //
    608 
    609 // When defined(ENABLE_PEPPER_CDMS), this also tests the Pepper CDM check.
    610 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest,
    611                        ExternalClearKey_Basic) {
    612   EXPECT_ECK(IsConcreteSupportedKeySystem(kExternalClearKey));
    613   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    614       "video/webm", no_codecs(), kExternalClearKey));
    615 }
    616 
    617 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest,
    618                        ExternalClearKey_Parent) {
    619   const char* const kExternalClearKeyParent = "org.chromium";
    620 
    621   // The parent should be supported but is not. See http://crbug.com/164303.
    622   EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalClearKeyParent));
    623   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    624       "video/webm", no_codecs(), kExternalClearKeyParent));
    625 }
    626 
    627 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedExternalClearKeyTest,
    628                        ExternalClearKey_IsSupportedKeySystem_InvalidVariants) {
    629   // Case sensitive.
    630   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy"));
    631   // This should fail, but currently canPlayType() converts it to lowercase.
    632   // See http://crbug.com/286036.
    633   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
    634       "video/webm", no_codecs(), "org.chromium.ExTeRnAlClEaRkEy"));
    635 
    636   // TLDs are not allowed.
    637   EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
    638   EXPECT_FALSE(
    639       IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org."));
    640   EXPECT_FALSE(IsConcreteSupportedKeySystem("org"));
    641   EXPECT_FALSE(
    642       IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "org"));
    643 
    644   // Extra period.
    645   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium."));
    646   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    647       "video/webm", no_codecs(), "org.chromium."));
    648 
    649   // Incomplete.
    650   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearke"));
    651   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    652       "video/webm", no_codecs(), "org.chromium.externalclearke"));
    653 
    654   // Extra character.
    655   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.externalclearkeyz"));
    656   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    657       "video/webm", no_codecs(), "org.chromium.externalclearkeyz"));
    658 
    659   // There are no child key systems for Clear Key.
    660   EXPECT_FALSE(
    661       IsConcreteSupportedKeySystem("org.chromium.externalclearkey.foo"));
    662   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    663       "video/webm", no_codecs(), "org.chromium.externalclearkey.foo"));
    664 }
    665 
    666 IN_PROC_BROWSER_TEST_F(
    667     EncryptedMediaIsTypeSupportedExternalClearKeyTest,
    668     IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_NoType) {
    669   // These two should be true. See http://crbug.com/164303.
    670   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    671       std::string(), no_codecs(), kExternalClearKey));
    672   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    673       std::string(), no_codecs(), "org.chromium"));
    674 
    675   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    676       std::string(), no_codecs(), "org.chromium.foo"));
    677   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    678       std::string(), no_codecs(), "org.chromium.externalclearkey.foo"));
    679 }
    680 
    681 IN_PROC_BROWSER_TEST_F(
    682     EncryptedMediaIsTypeSupportedExternalClearKeyTest,
    683     IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_WebM) {
    684   // Valid video types.
    685   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    686       "video/webm", no_codecs(), kExternalClearKey));
    687   // The parent should be supported but is not. See http://crbug.com/164303.
    688   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    689       "video/webm", no_codecs(), "org.chromium"));
    690   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    691       "video/webm", vp8_codec(), kExternalClearKey));
    692   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    693       "video/webm", vp80_codec(), kExternalClearKey));
    694   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    695       "video/webm", vp8_and_vorbis_codecs(), kExternalClearKey));
    696   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    697       "video/webm", vp9_codec(), kExternalClearKey));
    698   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    699       "video/webm", vp90_codec(), kExternalClearKey));
    700   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    701       "video/webm", vp9_and_vorbis_codecs(), kExternalClearKey));
    702   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    703       "video/webm", vorbis_codec(), kExternalClearKey));
    704 
    705   // Non-Webm codecs.
    706   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    707       "video/webm", avc1_codec(), kExternalClearKey));
    708   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    709       "video/webm", avc3_codec(), kExternalClearKey));
    710   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    711       "video/webm", unknown_codec(), kExternalClearKey));
    712   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    713       "video/webm", mixed_codecs(), kExternalClearKey));
    714   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    715       "video/webm", vp8_invalid_extension_codec(), kExternalClearKey));
    716 
    717   // Valid audio types.
    718   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    719       "audio/webm", no_codecs(), kExternalClearKey));
    720   EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType(
    721       "audio/webm", vorbis_codec(), kExternalClearKey));
    722 
    723   // Non-audio codecs.
    724   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    725       "audio/webm", vp8_codec(), kExternalClearKey));
    726   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    727       "audio/webm", vp8_and_vorbis_codecs(), kExternalClearKey));
    728   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    729       "audio/webm", vp9_codec(), kExternalClearKey));
    730   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    731       "audio/webm", vp9_and_vorbis_codecs(), kExternalClearKey));
    732 
    733   // Non-Webm codec.
    734   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    735       "audio/webm", aac_codec(), kExternalClearKey));
    736 }
    737 
    738 IN_PROC_BROWSER_TEST_F(
    739     EncryptedMediaIsTypeSupportedExternalClearKeyTest,
    740     IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_MP4) {
    741   // Valid video types.
    742   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    743       "video/mp4", no_codecs(), kExternalClearKey));
    744   // The parent should be supported but is not. See http://crbug.com/164303.
    745   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    746       "video/mp4", no_codecs(), "org.chromium"));
    747   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    748       "video/mp4", avc1_codec(), kExternalClearKey));
    749   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    750       "video/mp4", avc3_codec(), kExternalClearKey));
    751   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    752       "video/mp4", avc1_and_aac_codecs(), kExternalClearKey));
    753   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    754       "video/mp4", avc3_and_aac_codecs(), kExternalClearKey));
    755   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    756       "video/mp4", aac_codec(), kExternalClearKey));
    757 
    758   // Extended codecs.
    759   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    760       "video/mp4", avc1_extended_codec(), kExternalClearKey));
    761   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    762       "video/mp4", avc3_extended_codec(), kExternalClearKey));
    763   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    764       "video/mp4", avc1_extended_and_aac_codecs(), kExternalClearKey));
    765   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    766       "video/mp4", avc3_extended_and_aac_codecs(), kExternalClearKey));
    767 
    768   // Invalid codec format: profile parameter must be present after the period.
    769   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    770       "video/mp4", avc1_dot_codec(), kExternalClearKey));
    771 
    772   // Invalid or Non-MP4 codecs.
    773   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    774       "video/mp4", avc2_codec(), kExternalClearKey));
    775   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    776       "video/mp4", mp4a_invalid_no_extension(), kExternalClearKey));
    777   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    778       "video/mp4", vp8_codec(), kExternalClearKey));
    779   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    780       "video/mp4", unknown_codec(), kExternalClearKey));
    781   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    782       "video/mp4", mixed_codecs(), kExternalClearKey));
    783   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    784       "video/mp4", vp8_invalid_extension_codec(), kExternalClearKey));
    785 
    786   // Valid audio types.
    787   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    788       "audio/mp4", no_codecs(), kExternalClearKey));
    789   EXPECT_ECKPROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
    790       "audio/mp4", aac_codec(), kExternalClearKey));
    791 
    792   // Non-audio codecs.
    793   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    794       "audio/mp4", avc1_codec(), kExternalClearKey));
    795   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    796       "audio/mp4", avc3_codec(), kExternalClearKey));
    797   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    798       "audio/mp4", avc1_extended_codec(), kExternalClearKey));
    799   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    800       "audio/mp4", avc3_extended_codec(), kExternalClearKey));
    801   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    802       "audio/mp4", avc1_and_aac_codecs(), kExternalClearKey));
    803   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    804       "audio/mp4", avc3_and_aac_codecs(), kExternalClearKey));
    805   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    806       "audio/mp4", avc1_extended_and_aac_codecs(), kExternalClearKey));
    807   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    808       "audio/mp4", avc3_extended_and_aac_codecs(), kExternalClearKey));
    809 
    810   // Invalid or Non-MP4 codec.
    811   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    812       "audio/mp4", vorbis_codec(), kExternalClearKey));
    813   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    814       "audio/mp4", mp4a_invalid_no_extension(), kExternalClearKey));
    815 }
    816 
    817 //
    818 // Widevine
    819 //
    820 
    821 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
    822                        Widevine_Basic) {
    823 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
    824   EXPECT_TRUE(IsConcreteSupportedKeySystem(kWidevineAlpha));
    825 #else
    826   EXPECT_WV(IsConcreteSupportedKeySystem(kWidevineAlpha));
    827 #endif
    828   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    829       "video/webm", no_codecs(), kWidevineAlpha));
    830 }
    831 
    832 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
    833                        Widevine_Parent) {
    834   // The parent system is not a concrete system but is supported.
    835   EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevine));
    836   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    837       "video/webm", no_codecs(), kWidevine));
    838 }
    839 
    840 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
    841                        Widevine_IsSupportedKeySystem_InvalidVariants) {
    842   // Case sensitive.
    843   EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.AlPhA"));
    844   // This should fail, but currently canPlayType() converts it to lowercase.
    845   // See http://crbug.com/286036.
    846   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    847       "video/webm", no_codecs(), "com.widevine.AlPhA"));
    848 
    849   // TLDs are not allowed.
    850   EXPECT_FALSE(IsConcreteSupportedKeySystem("com."));
    851   EXPECT_FALSE(
    852       IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "com."));
    853   EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
    854   EXPECT_FALSE(
    855       IsSupportedKeySystemWithMediaMimeType("video/webm", no_codecs(), "com"));
    856 
    857   // Extra period.
    858   EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine."));
    859   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    860       "video/webm", no_codecs(), "com.widevine."));
    861 
    862   // Incomplete.
    863   EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alph"));
    864   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    865       "video/webm", no_codecs(), "com.widevine.alph"));
    866 
    867   // Extra character.
    868   EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alphab"));
    869   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    870       "video/webm", no_codecs(), "com.widevine.alphab"));
    871 
    872   // There are no child key systems for Widevine Alpha.
    873   EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.alpha.foo"));
    874   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    875       "video/webm", no_codecs(), "com.widevine.alpha.foo"));
    876 }
    877 
    878 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
    879                        IsSupportedKeySystemWithMediaMimeType_Widevine_NoType) {
    880   // These two should be true. See http://crbug.com/164303.
    881   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    882       std::string(), no_codecs(), kWidevineAlpha));
    883   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    884       std::string(), no_codecs(), kWidevine));
    885 
    886   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    887       std::string(), no_codecs(), "com.widevine.foo"));
    888   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    889       std::string(), no_codecs(), "com.widevine.alpha.foo"));
    890 }
    891 
    892 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
    893                        IsSupportedKeySystemWithMediaMimeType_Widevine_WebM) {
    894   // Valid video types.
    895   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    896       "video/webm", no_codecs(), kWidevineAlpha));
    897   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    898       "video/webm", vp8_codec(), kWidevineAlpha));
    899   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    900       "video/webm", vp80_codec(), kWidevineAlpha));
    901   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    902       "video/webm", vp8_and_vorbis_codecs(), kWidevineAlpha));
    903   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    904       "video/webm", vp9_codec(), kWidevineAlpha));
    905   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    906       "video/webm", vp90_codec(), kWidevineAlpha));
    907   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    908       "video/webm", vp9_and_vorbis_codecs(), kWidevineAlpha));
    909   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    910       "video/webm", vorbis_codec(), kWidevineAlpha));
    911 
    912   // Valid video types - parent key system.
    913   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    914       "video/webm", no_codecs(), kWidevine));
    915   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    916       "video/webm", vp8_codec(), kWidevine));
    917   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    918       "video/webm", vp80_codec(), kWidevine));
    919   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    920       "video/webm", vp8_and_vorbis_codecs(), kWidevine));
    921   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    922       "video/webm", vp9_codec(), kWidevine));
    923   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    924       "video/webm", vp90_codec(), kWidevine));
    925   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    926       "video/webm", vp9_and_vorbis_codecs(), kWidevine));
    927   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    928       "video/webm", vorbis_codec(), kWidevine));
    929 
    930   // Non-Webm codecs.
    931   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    932       "video/webm", avc1_codec(), kWidevineAlpha));
    933   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    934       "video/webm", avc3_codec(), kWidevineAlpha));
    935   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    936       "video/webm", unknown_codec(), kWidevineAlpha));
    937   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    938       "video/webm", mixed_codecs(), kWidevineAlpha));
    939   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    940       "video/webm", vp8_invalid_extension_codec(), kWidevineAlpha));
    941 
    942   // Valid audio types.
    943   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    944       "audio/webm", no_codecs(), kWidevineAlpha));
    945   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    946       "audio/webm", vorbis_codec(), kWidevineAlpha));
    947 
    948   // Valid audio types - parent key system.
    949   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    950       "audio/webm", no_codecs(), kWidevine));
    951   EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
    952       "audio/webm", vorbis_codec(), kWidevine));
    953 
    954   // Non-audio codecs.
    955   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    956       "audio/webm", vp8_codec(), kWidevineAlpha));
    957   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    958       "audio/webm", vp8_and_vorbis_codecs(), kWidevineAlpha));
    959   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    960       "audio/webm", vp9_codec(), kWidevineAlpha));
    961   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    962       "audio/webm", vp9_and_vorbis_codecs(), kWidevineAlpha));
    963 
    964   // Non-Webm codec.
    965   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
    966       "audio/webm", aac_codec(), kWidevineAlpha));
    967 }
    968 
    969 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
    970                        IsSupportedKeySystemWithMediaMimeType_Widevine_MP4) {
    971   // Valid video types.
    972   EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType(
    973       "video/mp4", no_codecs(), kWidevineAlpha));
    974   EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
    975       "video/mp4", avc1_codec(), kWidevineAlpha));
    976   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
    977       "video/mp4", avc1_and_aac_codecs(), kWidevineAlpha));
    978   EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
    979       "video/mp4", avc3_codec(), kWidevineAlpha));
    980   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
    981       "video/mp4", avc3_and_aac_codecs(), kWidevineAlpha));
    982   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
    983       "video/mp4", aac_codec(), kWidevineAlpha));
    984 
    985   // Valid video types - parent key system.
    986   EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType(
    987       "video/mp4", no_codecs(), kWidevine));
    988   EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
    989       "video/mp4", avc1_codec(), kWidevine));
    990   EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
    991       "video/mp4", avc3_codec(), kWidevine));
    992   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
    993       "video/mp4", avc1_and_aac_codecs(), kWidevine));
    994   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
    995       "video/mp4", avc3_and_aac_codecs(), kWidevine));
    996   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
    997       "video/mp4", aac_codec(), kWidevine));
    998 
    999   // Extended codecs.
   1000   EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
   1001       "video/mp4", avc1_extended_codec(), kWidevineAlpha));
   1002   EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
   1003       "video/mp4", avc3_extended_codec(), kWidevineAlpha));
   1004   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
   1005       "video/mp4", avc1_extended_and_aac_codecs(), kWidevineAlpha));
   1006   EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
   1007       "video/mp4", avc3_extended_and_aac_codecs(), kWidevineAlpha));
   1008 
   1009   // Invalid codec format: profile paramter must be present after the period.
   1010   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1011       "video/mp4", avc1_dot_codec(), kWidevineAlpha));
   1012 
   1013   // Invalid or Non-MP4 codecs.
   1014   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1015       "video/mp4", avc2_codec(), kWidevineAlpha));
   1016   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1017       "video/mp4", mp4a_invalid_no_extension(), kWidevineAlpha));
   1018   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1019       "video/mp4", vp8_codec(), kWidevineAlpha));
   1020   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1021       "video/mp4", unknown_codec(), kWidevineAlpha));
   1022   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1023       "video/mp4", mixed_codecs(), kWidevineAlpha));
   1024   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1025       "video/mp4", vp8_invalid_extension_codec(), kWidevineAlpha));
   1026 
   1027   // Valid audio types.
   1028   EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType(
   1029       "audio/mp4", no_codecs(), kWidevineAlpha));
   1030   EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
   1031       "audio/mp4", aac_codec(), kWidevineAlpha));
   1032 
   1033   // Valid audio types - parent key system.
   1034   EXPECT_WVMP4(IsSupportedKeySystemWithMediaMimeType(
   1035       "audio/mp4", no_codecs(), kWidevine));
   1036   EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
   1037       "audio/mp4", aac_codec(), kWidevine));
   1038 
   1039   // Non-audio codecs.
   1040   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1041       "audio/mp4", avc1_codec(), kWidevineAlpha));
   1042   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1043       "audio/mp4", avc3_codec(), kWidevineAlpha));
   1044   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1045       "audio/mp4", avc1_extended_codec(), kWidevineAlpha));
   1046   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1047       "audio/mp4", avc3_extended_codec(), kWidevineAlpha));
   1048   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1049       "audio/mp4", avc1_and_aac_codecs(), kWidevineAlpha));
   1050   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1051       "audio/mp4", avc3_and_aac_codecs(), kWidevineAlpha));
   1052   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1053       "audio/mp4", avc1_extended_and_aac_codecs(), kWidevineAlpha));
   1054   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1055       "audio/mp4", avc3_extended_and_aac_codecs(), kWidevineAlpha));
   1056 
   1057   // Invalid or Non-MP4 codec.
   1058   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1059       "audio/mp4", vorbis_codec(), kWidevineAlpha));
   1060   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1061       "audio/mp4", mp4a_invalid_no_extension(), kWidevineAlpha));
   1062 }
   1063 
   1064 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
   1065                        Widevine_HR_Basic) {
   1066   // HR support cannot be detected in tests, so this is expected to fail
   1067   // everywhere.
   1068   EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlphaHr));
   1069   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1070       "video/webm", no_codecs(), kWidevineAlphaHr));
   1071 }
   1072 
   1073 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedWidevineTest,
   1074                        Widevine_HR_NonCompositing_Basic) {
   1075   // HR non-compositing support cannot be detected in tests, so this is expected
   1076   // to fail everywhere.
   1077   EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlphaHrNonCompositing));
   1078   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1079       "video/webm", no_codecs(), kWidevineAlphaHrNonCompositing));
   1080 }
   1081 
   1082 #if defined(ENABLE_PEPPER_CDMS)
   1083 // Since this test fixture does not register the CDMs on the command line, the
   1084 // check for the CDMs in chrome_key_systems.cc should fail, and they should not
   1085 // be registered with KeySystems.
   1086 IN_PROC_BROWSER_TEST_F(EncryptedMediaIsTypeSupportedTest,
   1087                        PepperCDMsNotRegistered) {
   1088   EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalClearKey));
   1089   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1090       "video/webm", no_codecs(), kExternalClearKey));
   1091 
   1092   // This will fail in all builds unless widevine is available but not a
   1093   // component, in which case it is registered internally
   1094 #if !defined(WIDEVINE_CDM_AVAILABLE) || defined(WIDEVINE_CDM_IS_COMPONENT)
   1095   EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlpha));
   1096   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1097       "video/webm", no_codecs(), kWidevineAlpha));
   1098 #endif
   1099 
   1100   // Clear Key should still be registered.
   1101   EXPECT_TRUE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
   1102   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
   1103       "video/webm", no_codecs(), kPrefixedClearKey));
   1104 
   1105   // Not yet out from behind the vendor prefix.
   1106   EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey));
   1107   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1108       "video/webm", no_codecs(), kUnprefixedClearKey));
   1109 }
   1110 
   1111 // Since this test fixture does not register the CDMs on the command line, the
   1112 // check for the CDMs in chrome_key_systems.cc should fail, and they should not
   1113 // be registered with KeySystems.
   1114 IN_PROC_BROWSER_TEST_F(
   1115     EncryptedMediaIsTypeSupportedClearKeyCDMRegisteredWithWrongPathTest,
   1116     PepperCDMsRegisteredButAdapterNotPresent) {
   1117   EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalClearKey));
   1118   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1119       "video/webm", no_codecs(), kExternalClearKey));
   1120 
   1121   // Clear Key should still be registered.
   1122   EXPECT_TRUE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
   1123   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
   1124       "video/webm", no_codecs(), kPrefixedClearKey));
   1125 
   1126   // Not yet out from behind the vendor prefix.
   1127   EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey));
   1128   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1129       "video/webm", no_codecs(), kUnprefixedClearKey));
   1130 }
   1131 
   1132 // This will fail in all builds unless Widevine is available but not a
   1133 // component, in which case it is registered internally.
   1134 // TODO(xhwang): Define EXPECT_WV and run this test in all cases.
   1135 #if !defined(WIDEVINE_CDM_AVAILABLE) || defined(WIDEVINE_CDM_IS_COMPONENT)
   1136 IN_PROC_BROWSER_TEST_F(
   1137     EncryptedMediaIsTypeSupportedWidevineCDMRegisteredWithWrongPathTest,
   1138     PepperCDMsRegisteredButAdapterNotPresent) {
   1139   EXPECT_FALSE(IsConcreteSupportedKeySystem(kWidevineAlpha));
   1140   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
   1141       "video/webm", no_codecs(), kWidevineAlpha));
   1142 }
   1143 #endif  // !defined(WIDEVINE_CDM_AVAILABLE) || defined(WIDEVINE_CDM_IS_COMPONENT)
   1144 #endif  // defined(ENABLE_PEPPER_CDMS)
   1145 
   1146 }  // namespace chrome
   1147