Changed TestShellWebMimeRegistryImpl to blacklist rather than whitelist containers and codecs.

New expected results for four tests need to be committed in WebKit.

BUG=119667
TEST=WebM tests in LayoutTests/media/W3C/video/canPlayType/ now say "probably" or "maybe".


Review URL: http://codereview.chromium.org/9969061

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132463 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc
index 85f5d15..ab505b0 100644
--- a/net/base/mime_util.cc
+++ b/net/base/mime_util.cc
@@ -234,7 +234,8 @@
 
 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type
 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php
-static const char* const supported_media_types[] = {
+// This set of codecs is supported by all variations of Chromium.
+static const char* const common_media_types[] = {
   // Ogg.
   "audio/ogg",
   "application/ogg",
@@ -247,8 +248,10 @@
   "audio/webm",
   "audio/wav",
   "audio/x-wav",
+};
 
-#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
+// List of proprietary types only supported by Google Chrome.
+static const char* const proprietary_media_types[] = {
   // MPEG-4.
   "video/mp4",
   "video/x-m4v",
@@ -259,21 +262,17 @@
   "audio/mp3",
   "audio/x-mp3",
   "audio/mpeg",
-#endif
 };
 
 // List of supported codecs when passed in with <source type="...">.
+// This set of codecs is supported by all variations of Chromium.
 //
 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support
 // for more information.
 //
 // The codecs for WAV are integers as defined in Appendix A of RFC2361:
 // http://tools.ietf.org/html/rfc2361
-static const char* const supported_media_codecs[] = {
-#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
-  "avc1",
-  "mp4a",
-#endif
+static const char* const common_media_codecs[] = {
 #if defined(ENABLE_MEDIA_CODEC_THEORA)
   "theora",
 #endif
@@ -282,6 +281,12 @@
   "1"  // WAVE_FORMAT_PCM.
 };
 
+// List of proprietary codecs only supported by Google Chrome.
+static const char* const proprietary_media_codecs[] = {
+  "avc1",
+  "mp4a"
+};
+
 // Note: does not include javascript types list (see supported_javascript_types)
 static const char* const supported_non_image_types[] = {
   "text/cache-manifest",
@@ -376,12 +381,20 @@
     non_image_map_.insert(supported_non_image_types[i]);
   for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
     non_image_map_.insert(supported_javascript_types[i]);
-  for (size_t i = 0; i < arraysize(supported_media_types); ++i)
-    non_image_map_.insert(supported_media_types[i]);
+  for (size_t i = 0; i < arraysize(common_media_types); ++i)
+    non_image_map_.insert(common_media_types[i]);
+#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
+  for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
+    non_image_map_.insert(proprietary_media_types[i]);
+#endif
 
   // Initialize the supported media types.
-  for (size_t i = 0; i < arraysize(supported_media_types); ++i)
-    media_map_.insert(supported_media_types[i]);
+  for (size_t i = 0; i < arraysize(common_media_types); ++i)
+    media_map_.insert(common_media_types[i]);
+#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
+  for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
+    media_map_.insert(proprietary_media_types[i]);
+#endif
 
   for (size_t i = 0; i < arraysize(supported_javascript_types); ++i)
     javascript_map_.insert(supported_javascript_types[i]);
@@ -389,8 +402,12 @@
   for (size_t i = 0; i < arraysize(view_source_types); ++i)
     view_source_map_.insert(view_source_types[i]);
 
-  for (size_t i = 0; i < arraysize(supported_media_codecs); ++i)
-    codecs_map_.insert(supported_media_codecs[i]);
+  for (size_t i = 0; i < arraysize(common_media_codecs); ++i)
+    codecs_map_.insert(common_media_codecs[i]);
+#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
+  for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
+    codecs_map_.insert(proprietary_media_codecs[i]);
+#endif
 
   // Initialize the strict supported media types.
   for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) {
@@ -748,4 +765,28 @@
   HashSetToVector(&unique_extensions, extensions);
 }
 
+void GetMediaTypesBlacklistedForTests(std::vector<std::string>* types) {
+  types->clear();
+
+// Unless/until WebM files are added to the media layout tests, we need to avoid
+// blacklisting mp4 and H.264 when Theora is not supported (and proprietary
+// codecs are) so that the media tests can still run.
+#if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS)
+  for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
+    types->push_back(proprietary_media_types[i]);
+#endif
+}
+
+void GetMediaCodecsBlacklistedForTests(std::vector<std::string>* codecs) {
+  codecs->clear();
+
+// Unless/until WebM files are added to the media layout tests, we need to avoid
+// blacklisting mp4 and H.264 when Theora is not supported (and proprietary
+// codecs are) so that the media tests can still run.
+#if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS)
+  for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
+    codecs->push_back(proprietary_media_codecs[i]);
+#endif
+}
+
 }  // namespace net
diff --git a/net/base/mime_util.h b/net/base/mime_util.h
index adff518..ba3e25d 100644
--- a/net/base/mime_util.h
+++ b/net/base/mime_util.h
@@ -110,6 +110,15 @@
     const std::string& mime_type,
     std::vector<FilePath::StringType>* extensions);
 
+// Test only methods that return lists of proprietary media types and codecs
+// that are not supported by all variations of Chromium.
+// These types and codecs must be blacklisted to ensure consistent layout test
+// results across all Chromium variations.
+NET_EXPORT void GetMediaTypesBlacklistedForTests(
+    std::vector<std::string>* types);
+NET_EXPORT void GetMediaCodecsBlacklistedForTests(
+    std::vector<std::string>* codecs);
+
 }  // namespace net
 
 #endif  // NET_BASE_MIME_UTIL_H__
diff --git a/webkit/tools/layout_tests/test_expectations.txt b/webkit/tools/layout_tests/test_expectations.txt
index 510f0cf..deafa05 100644
--- a/webkit/tools/layout_tests/test_expectations.txt
+++ b/webkit/tools/layout_tests/test_expectations.txt
@@ -28,3 +28,8 @@
 // Right?)
 //
 // EVERYTHING BELOW THIS LINE WILL BE DELETED AT EVERY WEBKIT DEPS ROLL
+BUGCR119667 : media/W3C/video/canPlayType/canPlayType_codecs_order_1.html = PASS
+BUGCR119667 : media/W3C/video/canPlayType/canPlayType_supported_but_no_codecs_parameter_1.html = PASS
+BUGCR119667 : media/W3C/video/canPlayType/canPlayType_two_implies_one_1.html = PASS
+BUGCR119667 : media/W3C/video/canPlayType/canPlayType_two_implies_one_2.html = PASS
+
diff --git a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc
index d0989dd..ebc19e25 100644
--- a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc
+++ b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc
@@ -4,6 +4,7 @@
 
 #include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h"
 
+#include "base/basictypes.h"
 #include "base/string_util.h"
 #include "net/base/mime_util.h"
 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
@@ -22,49 +23,46 @@
 }  // namespace
 
 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() {
-  // Claim we support Ogg+Theora/Vorbis.
-  media_map_.insert("video/ogg");
-  media_map_.insert("audio/ogg");
-  media_map_.insert("application/ogg");
-  codecs_map_.insert("theora");
-  codecs_map_.insert("vorbis");
+  net::GetMediaTypesBlacklistedForTests(&blacklisted_media_types_);
 
-  // Claim we support WAV.
-  media_map_.insert("audio/wav");
-  media_map_.insert("audio/x-wav");
-  codecs_map_.insert("1");  // PCM for WAV.
+  net::GetMediaCodecsBlacklistedForTests(&blacklisted_media_codecs_);
 }
 
 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {}
 
+// Returns IsNotSupported if mime_type or any of the codecs are not supported.
+// Otherwse, defers to the real registry.
 WebMimeRegistry::SupportsType
-    TestShellWebMimeRegistryImpl::supportsMediaMIMEType(
+TestShellWebMimeRegistryImpl::supportsMediaMIMEType(
     const WebString& mime_type,
     const WebString& codecs) {
-  // Not supporting the container is a flat-out no.
-  if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type)))
+  if (IsBlacklistedMediaMimeType(ToASCIIOrEmpty(mime_type)))
     return IsNotSupported;
 
-  // If we don't recognize the codec, it's possible we support it.
   std::vector<std::string> parsed_codecs;
   net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
-  if (!AreSupportedMediaCodecs(parsed_codecs))
-    return MayBeSupported;
+  if (HasBlacklistedMediaCodecs(parsed_codecs))
+    return IsNotSupported;
 
-  // Otherwise we have a perfect match.
-  return IsSupported;
+  return SimpleWebMimeRegistryImpl::supportsMediaMIMEType(mime_type, codecs);
 }
 
-bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType(
+bool TestShellWebMimeRegistryImpl::IsBlacklistedMediaMimeType(
     const std::string& mime_type) {
-  return media_map_.find(mime_type) != media_map_.end();
+  for (size_t i = 0; i < blacklisted_media_types_.size(); ++i) {
+    if (blacklisted_media_types_[i] == mime_type)
+      return true;
+  }
+  return false;
 }
 
-bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs(
+bool TestShellWebMimeRegistryImpl::HasBlacklistedMediaCodecs(
     const std::vector<std::string>& codecs) {
   for (size_t i = 0; i < codecs.size(); ++i) {
-    if (codecs_map_.find(codecs[i]) == codecs_map_.end())
-      return false;
+    for (size_t j = 0; j < blacklisted_media_codecs_.size(); ++j) {
+      if (blacklisted_media_codecs_[j] == codecs[i])
+        return true;
+    }
   }
-  return !codecs.empty();
+  return false;
 }
diff --git a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h
index ecf7d4d..40ac863 100644
--- a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h
+++ b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h
@@ -18,24 +18,25 @@
   TestShellWebMimeRegistryImpl();
   virtual ~TestShellWebMimeRegistryImpl();
 
-  // Override to force that we only support ogg, vorbis and theora.
+  // Override to force that we only support types and codecs that are supported
+  // by all variations of Chromium.
   //
   // Media layout tests use canPlayType() to determine the test input files.
   // Different flavours of Chromium support different codecs, which has an
-  // impact on how canPlayType() behaves.  Since Chromium's baselines are
-  // generated against ogg/vorbis/theora content we need to lock down how
-  // canPlayType() behaves when running layout tests.
+  // impact on how canPlayType() behaves.  Since Chromium's baselines and
+  // expectations are generated against the common set of types, we need to
+  // prevent canPlayType() from indicating it supports other types when running
+  // layout tests.
   virtual WebKit::WebMimeRegistry::SupportsType supportsMediaMIMEType(
       const WebKit::WebString&,
       const WebKit::WebString&) OVERRIDE;
 
  private:
-  bool IsSupportedMediaMimeType(const std::string& mime_type);
-  bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs);
+  bool IsBlacklistedMediaMimeType(const std::string& mime_type);
+  bool HasBlacklistedMediaCodecs(const std::vector<std::string>& codecs);
 
-  typedef base::hash_set<std::string> MimeMappings;
-  MimeMappings media_map_;
-  MimeMappings codecs_map_;
+  std::vector<std::string> blacklisted_media_types_;
+  std::vector<std::string> blacklisted_media_codecs_;
 
   DISALLOW_COPY_AND_ASSIGN(TestShellWebMimeRegistryImpl);
 };