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

Side by Side Diff: webkit/tools/test_shell/test_shell_webmimeregistry_impl.cc

Issue 9969061: Changed TestShellWebMimeRegistryImpl to blacklist rather than whitelist containers and codecs. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: s/conditional/blacklisted/ and header comment update. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/tools/test_shell/test_shell_webmimeregistry_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h" 5 #include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h"
6 6
7 #include "base/basictypes.h"
7 #include "base/string_util.h" 8 #include "base/string_util.h"
8 #include "net/base/mime_util.h" 9 #include "net/base/mime_util.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
10 11
11 using WebKit::WebString; 12 using WebKit::WebString;
12 using WebKit::WebMimeRegistry; 13 using WebKit::WebMimeRegistry;
13 14
14 namespace { 15 namespace {
15 16
16 // Convert a WebString to ASCII, falling back on an empty string in the case 17 // Convert a WebString to ASCII, falling back on an empty string in the case
17 // of a non-ASCII string. 18 // of a non-ASCII string.
18 std::string ToASCIIOrEmpty(const WebString& string) { 19 std::string ToASCIIOrEmpty(const WebString& string) {
19 if (!IsStringASCII(string)) 20 if (!IsStringASCII(string))
20 return std::string(); 21 return std::string();
21 return UTF16ToASCII(string); 22 return UTF16ToASCII(string);
22 } 23 }
23 24
25 // Contains the types in mime_util.cc:supported_media_types that are
26 // conditionally compiled based on defined(GOOGLE_CHROME_BUILD) or
27 // defined(USE_PROPRIETARY_CODECS). These must be blacklisted to ensure
28 // consistent layout test results across all Chromium variations.
29 static const char* const blacklisted_media_types[] = {
30 // MPEG-4.
31 "video/mp4",
32 "video/x-m4v",
33 "audio/mp4",
34 "audio/x-m4a",
35
36 // MP3.
37 "audio/mp3",
38 "audio/x-mp3",
39 "audio/mpeg",
40 };
41
42 // Contains the types in mime_util.cc:supported_media_codecs that are
43 // conditionally compiled based on defined(GOOGLE_CHROME_BUILD) or
44 // defined(USE_PROPRIETARY_CODECS). These must be blacklisted to ensure
45 // consistent layout test results across all Chromium variations.
46 static const char* const blacklisted_media_codecs[] = {
47 "avc1",
scherkus (not reviewing) 2012/04/02 19:54:30 should be 2 space indent
48 "mp4a",
49 };
50
24 } // namespace 51 } // namespace
25 52
26 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { 53 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() {
27 // Claim we support Ogg+Theora/Vorbis. 54 for (size_t i = 0; i < arraysize(blacklisted_media_types); ++i)
28 media_map_.insert("video/ogg"); 55 blacklisted_media_map_.insert(blacklisted_media_types[i]);
29 media_map_.insert("audio/ogg");
30 media_map_.insert("application/ogg");
31 codecs_map_.insert("theora");
32 codecs_map_.insert("vorbis");
33 56
34 // Claim we support WAV. 57 for (size_t i = 0; i < arraysize(blacklisted_media_codecs); ++i)
35 media_map_.insert("audio/wav"); 58 blacklisted_codecs_map_.insert(blacklisted_media_codecs[i]);
36 media_map_.insert("audio/x-wav");
37 codecs_map_.insert("1"); // PCM for WAV.
38 } 59 }
39 60
40 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} 61 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {}
41 62
63 // Returns IsNotSupported if mime_type or any of the codecs are not supported.
64 // Otherwse, defers to the real registry.
42 WebMimeRegistry::SupportsType 65 WebMimeRegistry::SupportsType
43 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( 66 TestShellWebMimeRegistryImpl::supportsMediaMIMEType(
44 const WebString& mime_type, const WebString& codecs) { 67 const WebString& mime_type, const WebString& codecs) {
45 // Not supporting the container is a flat-out no. 68 if (IsBlacklistedMediaMimeType(ToASCIIOrEmpty(mime_type).c_str()))
46 if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type).c_str()))
47 return IsNotSupported; 69 return IsNotSupported;
48 70
49 // If we don't recognize the codec, it's possible we support it.
50 std::vector<std::string> parsed_codecs; 71 std::vector<std::string> parsed_codecs;
51 net::ParseCodecString(ToASCIIOrEmpty(codecs).c_str(), &parsed_codecs, true); 72 net::ParseCodecString(ToASCIIOrEmpty(codecs).c_str(), &parsed_codecs, true);
52 if (!AreSupportedMediaCodecs(parsed_codecs)) 73 if (HasBlacklistedMediaCodecs(parsed_codecs))
53 return MayBeSupported; 74 return IsNotSupported;
54 75
55 // Otherwise we have a perfect match. 76 return SimpleWebMimeRegistryImpl::supportsMediaMIMEType(mime_type, codecs);
56 return IsSupported;
57 } 77 }
58 78
59 bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType( 79 bool TestShellWebMimeRegistryImpl::IsBlacklistedMediaMimeType(
60 const std::string& mime_type) { 80 const std::string& mime_type) {
61 return media_map_.find(mime_type) != media_map_.end(); 81 return blacklisted_media_map_.find(mime_type) != blacklisted_media_map_.end();
62 } 82 }
63 83
64 bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs( 84 bool TestShellWebMimeRegistryImpl::HasBlacklistedMediaCodecs(
65 const std::vector<std::string>& codecs) { 85 const std::vector<std::string>& codecs) {
66 for (size_t i = 0; i < codecs.size(); ++i) { 86 for (size_t i = 0; i < codecs.size(); ++i) {
67 if (codecs_map_.find(codecs[i]) == codecs_map_.end()) { 87 if (blacklisted_codecs_map_.find(codecs[i]) !=
68 return false; 88 blacklisted_codecs_map_.end()) {
89 return true;
69 } 90 }
70 } 91 }
71 return true; 92 return false;
72 } 93 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_shell_webmimeregistry_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698