diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 22:08:03 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 22:08:03 +0000 |
commit | d56a89cca85b9607ca2e4e37efc8b2eb71ab8dd2 (patch) | |
tree | 6b76df353af8fffb7c52acfddb93960d33a748b0 /webkit | |
parent | 10baea924c51ef80c02d95009cab728b38feb03c (diff) | |
download | chromium_src-d56a89cca85b9607ca2e4e37efc8b2eb71ab8dd2.zip chromium_src-d56a89cca85b9607ca2e4e37efc8b2eb71ab8dd2.tar.gz chromium_src-d56a89cca85b9607ca2e4e37efc8b2eb71ab8dd2.tar.bz2 |
Override SimpleWebMimeRegistryImpl::supportsMediaMIMEType() for test_shell.
Different versions of Chromium support different codecs, which results in all media layout tests failing since they are generated against ogg/vorbis/theora content. By overriding supportsMediaMIMEType() all media layout tests will use ogg/vorbis/theora test input.
BUG=25886
TEST=test_shell on offical builder should start passing media layout tests
Review URL: http://codereview.chromium.org/1356003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42837 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/simple_webmimeregistry_impl.cc | 16 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc | 65 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webmimeregistry_impl.h | 40 |
5 files changed, 118 insertions, 11 deletions
diff --git a/webkit/glue/simple_webmimeregistry_impl.cc b/webkit/glue/simple_webmimeregistry_impl.cc index ce5c94e..f12f48b 100644 --- a/webkit/glue/simple_webmimeregistry_impl.cc +++ b/webkit/glue/simple_webmimeregistry_impl.cc @@ -17,7 +17,7 @@ namespace { // Convert a WebString to ASCII, falling back on an empty string in the case // of a non-ASCII string. -std::string AsASCII(const WebString& string) { +std::string ToASCIIOrEmpty(const WebString& string) { if (!IsStringASCII(string)) return std::string(); return UTF16ToASCII(string); @@ -29,21 +29,21 @@ namespace webkit_glue { WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( const WebString& mime_type) { - if (!net::IsSupportedMimeType(AsASCII(mime_type).c_str())) + if (!net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type).c_str())) return WebMimeRegistry::IsNotSupported; return WebMimeRegistry::IsSupported; } WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( const WebString& mime_type) { - if (!net::IsSupportedImageMimeType(AsASCII(mime_type).c_str())) + if (!net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type).c_str())) return WebMimeRegistry::IsNotSupported; return WebMimeRegistry::IsSupported; } WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( const WebString& mime_type) { - if (!net::IsSupportedJavascriptMimeType(AsASCII(mime_type).c_str())) + if (!net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type).c_str())) return WebMimeRegistry::IsNotSupported; return WebMimeRegistry::IsSupported; } @@ -51,12 +51,12 @@ WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsJavaScriptMIMET WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( const WebString& mime_type, const WebString& codecs) { // Not supporting the container is a flat-out no. - if (!net::IsSupportedMediaMimeType(AsASCII(mime_type).c_str())) + if (!net::IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type).c_str())) return IsNotSupported; // If we don't recognize the codec, it's possible we support it. std::vector<std::string> parsed_codecs; - net::ParseCodecString(AsASCII(codecs).c_str(), &parsed_codecs); + net::ParseCodecString(ToASCIIOrEmpty(codecs).c_str(), &parsed_codecs); if (!net::AreSupportedMediaCodecs(parsed_codecs)) return MayBeSupported; @@ -66,7 +66,7 @@ WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( const WebString& mime_type) { - if (!net::IsSupportedNonImageMimeType(AsASCII(mime_type).c_str())) + if (!net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type).c_str())) return WebMimeRegistry::IsNotSupported; return WebMimeRegistry::IsSupported; } @@ -90,7 +90,7 @@ WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile( WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( const WebString& mime_type) { FilePath::StringType file_extension; - net::GetPreferredExtensionForMimeType(AsASCII(mime_type), + net::GetPreferredExtensionForMimeType(ToASCIIOrEmpty(mime_type), &file_extension); return FilePathStringToWebString(file_extension); } diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index c82bd79..a414092 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2010 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -95,6 +95,8 @@ 'test_shell_switches.h', 'test_shell_win.cc', 'test_shell_webkit_init.h', + 'test_shell_webmimeregistry_impl.cc', + 'test_shell_webmimeregistry_impl.h', 'test_shell_webthemecontrol.h', 'test_shell_webthemecontrol.cc', 'test_shell_webthemeengine.h', diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index f2f314e..65ada15 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -26,7 +26,6 @@ #include "webkit/database/vfs_backend.h" #include "webkit/extensions/v8/gears_extension.h" #include "webkit/extensions/v8/interval_extension.h" -#include "webkit/glue/simple_webmimeregistry_impl.h" #include "webkit/glue/webclipboard_impl.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webkitclient_impl.h" @@ -35,6 +34,7 @@ #include "webkit/tools/test_shell/simple_database_system.h" #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/simple_webcookiejar_impl.h" +#include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h" #include "v8/include/v8.h" #if defined(OS_WIN) @@ -234,7 +234,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { } private: - webkit_glue::SimpleWebMimeRegistryImpl mime_registry_; + TestShellWebMimeRegistryImpl mime_registry_; MockWebClipboardImpl mock_clipboard_; webkit_glue::WebClipboardImpl real_clipboard_; ScopedTempDir appcache_dir_; diff --git a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc new file mode 100644 index 0000000..0a53345 --- /dev/null +++ b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h" + +#include "base/string_util.h" +#include "net/base/mime_util.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" + +using WebKit::WebString; +using WebKit::WebMimeRegistry; + +namespace { + +// Convert a WebString to ASCII, falling back on an empty string in the case +// of a non-ASCII string. +std::string ToASCIIOrEmpty(const WebString& string) { + if (!IsStringASCII(string)) + return std::string(); + return UTF16ToASCII(string); +} + +} // namespace + +TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { + media_map_.insert("video/ogg"); + media_map_.insert("audio/ogg"); + media_map_.insert("application/ogg"); + + codecs_map_.insert("theora"); + codecs_map_.insert("vorbis"); +} + +WebMimeRegistry::SupportsType +TestShellWebMimeRegistryImpl::supportsMediaMIMEType( + const WebString& mime_type, const WebString& codecs) { + // Not supporting the container is a flat-out no. + if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type).c_str())) + 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).c_str(), &parsed_codecs); + if (!AreSupportedMediaCodecs(parsed_codecs)) + return MayBeSupported; + + // Otherwise we have a perfect match. + return IsSupported; +} + +bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType( + const std::string& mime_type) { + return media_map_.find(mime_type) != media_map_.end(); +} + +bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs( + 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; + } + } + return true; +} diff --git a/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h new file mode 100644 index 0000000..f20b52a --- /dev/null +++ b/webkit/tools/test_shell/test_shell_webmimeregistry_impl.h @@ -0,0 +1,40 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBMIMEREGISTRY_IMPL_H_ +#define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBMIMEREGISTRY_IMPL_H_ + +#include <string> +#include <vector> + +#include "base/hash_tables.h" +#include "webkit/glue/simple_webmimeregistry_impl.h" + +class TestShellWebMimeRegistryImpl + : public webkit_glue::SimpleWebMimeRegistryImpl { + public: + TestShellWebMimeRegistryImpl(); + + // Override to force that we only support ogg, vorbis and theora. + // + // 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. + virtual WebKit::WebMimeRegistry::SupportsType supportsMediaMIMEType( + const WebKit::WebString&, const WebKit::WebString&); + + private: + bool IsSupportedMediaMimeType(const std::string& mime_type); + bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs); + + typedef base::hash_set<std::string> MimeMappings; + MimeMappings media_map_; + MimeMappings codecs_map_; + + DISALLOW_COPY_AND_ASSIGN(TestShellWebMimeRegistryImpl); +}; + +#endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBMIMEREGISTRY_IMPL_H_ |