OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 |
| 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/test/browser_test.h" |
| 15 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/content_browser_test.h" |
| 17 #include "content/public/test/content_browser_test_utils.h" |
| 18 #include "content/shell/browser/shell.h" |
| 19 #include "media/base/media_switches.h" |
| 20 #include "media/base/test_data_util.h" |
| 21 |
| 22 const char kDecodeTestFile[] = "decode_capabilities_test.html"; |
| 23 const char kSupported[] = "SUPPORTED"; |
| 24 const char kUnsupported[] = "UNSUPPORTED"; |
| 25 const char kError[] = "ERROR"; |
| 26 |
| 27 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 28 const char* kPropSupported = kSupported; |
| 29 #else |
| 30 const char* kPropSupported = kUnsupported; |
| 31 #endif // USE_PROPRIETARY_CODECS |
| 32 |
| 33 enum ConfigType { AUDIO, VIDEO }; |
| 34 |
| 35 namespace content { |
| 36 |
| 37 class MediaCapabilitiesTest : public ContentBrowserTest { |
| 38 public: |
| 39 MediaCapabilitiesTest() = default; |
| 40 |
| 41 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 42 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 43 "MediaCapabilities"); |
| 44 command_line->AppendSwitch(switches::kEnableNewVp9CodecString); |
| 45 command_line->AppendSwitch(switches::kEnableVp9InMp4); |
| 46 } |
| 47 |
| 48 std::string CanDecodeAudio(const std::string& content_type) { |
| 49 return CanDecode(content_type, ConfigType::AUDIO); |
| 50 } |
| 51 |
| 52 std::string CanDecodeVideo(const std::string& content_type) { |
| 53 return CanDecode(content_type, ConfigType::VIDEO); |
| 54 } |
| 55 |
| 56 std::string CanDecode(const std::string& content_type, |
| 57 ConfigType configType) { |
| 58 std::string command; |
| 59 if (configType == ConfigType::AUDIO) { |
| 60 command.append("testAudioDecodeContentType("); |
| 61 } else { |
| 62 command.append("testVideoDecodeContentType("); |
| 63 } |
| 64 |
| 65 command.append(content_type); |
| 66 command.append(");"); |
| 67 |
| 68 EXPECT_TRUE(ExecuteScript(shell(), command)); |
| 69 |
| 70 TitleWatcher title_watcher(shell()->web_contents(), |
| 71 base::ASCIIToUTF16(kSupported)); |
| 72 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kUnsupported)); |
| 73 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16(kError)); |
| 74 return base::UTF16ToASCII(title_watcher.WaitAndGetTitle()); |
| 75 } |
| 76 |
| 77 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(MediaCapabilitiesTest); |
| 79 }; |
| 80 |
| 81 // Cover basic codec support. See media_canplaytype_browsertest.cc for more |
| 82 // exhaustive codec string testing. |
| 83 IN_PROC_BROWSER_TEST_F(MediaCapabilitiesTest, VideoDecodeTypes) { |
| 84 base::FilePath file_path = media::GetTestDataFilePath(kDecodeTestFile); |
| 85 |
| 86 EXPECT_TRUE( |
| 87 NavigateToURL(shell(), content::GetFileUrlWithQuery(file_path, ""))); |
| 88 |
| 89 EXPECT_EQ(kSupported, CanDecodeVideo("'video/webm; codecs=\"vp8\"'")); |
| 90 |
| 91 // TODO(chcunningham): Drop support for the old VP9 string. Only support |
| 92 // the new vp09 format which provides critical profile information. |
| 93 EXPECT_EQ(kSupported, CanDecodeVideo("'video/webm; codecs=\"vp9\"'")); |
| 94 // Requires command line flag switches::kEnableNewVp9CodecString |
| 95 EXPECT_EQ(kSupported, |
| 96 CanDecodeVideo("'video/webm; codecs=\"vp09.00.10.08\"'")); |
| 97 |
| 98 // Supported when built with USE_PROPRIETARY_CODECS |
| 99 EXPECT_EQ(kPropSupported, |
| 100 CanDecodeVideo("'video/mp4; codecs=\"avc1.42E01E\"'")); |
| 101 EXPECT_EQ(kPropSupported, |
| 102 CanDecodeVideo("'video/mp4; codecs=\"avc1.42101E\"'")); |
| 103 EXPECT_EQ(kPropSupported, |
| 104 CanDecodeVideo("'video/mp4; codecs=\"avc1.42701E\"'")); |
| 105 EXPECT_EQ(kPropSupported, |
| 106 CanDecodeVideo("'video/mp4; codecs=\"avc1.42F01E\"'")); |
| 107 // Requires command line flag switches::kEnableVp9InMp4 |
| 108 EXPECT_EQ(kPropSupported, |
| 109 CanDecodeVideo("'video/mp4; codecs=\"vp09.00.10.08\"'")); |
| 110 |
| 111 // Test a handful of invalid strings. |
| 112 EXPECT_EQ(kUnsupported, CanDecodeVideo("'video/webm; codecs=\"theora\"'")); |
| 113 EXPECT_EQ(kUnsupported, |
| 114 CanDecodeVideo("'video/webm; codecs=\"avc1.42E01E\"'")); |
| 115 // Only new vp09 format is supported with MP4. |
| 116 EXPECT_EQ(kUnsupported, CanDecodeVideo("'video/mp4; codecs=\"vp9\"'")); |
| 117 } |
| 118 |
| 119 // Cover basic codec support. See media_canplaytype_browsertest.cc for more |
| 120 // exhaustive codec string testing. |
| 121 IN_PROC_BROWSER_TEST_F(MediaCapabilitiesTest, AudioDecodeTypes) { |
| 122 base::FilePath file_path = media::GetTestDataFilePath(kDecodeTestFile); |
| 123 |
| 124 EXPECT_TRUE( |
| 125 NavigateToURL(shell(), content::GetFileUrlWithQuery(file_path, ""))); |
| 126 |
| 127 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/ogg; codecs=\"flac\"'")); |
| 128 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/ogg; codecs=\"vorbis\"'")); |
| 129 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/ogg; codecs=\"opus\"'")); |
| 130 |
| 131 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/webm; codecs=\"opus\"'")); |
| 132 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/webm; codecs=\"vorbis\"'")); |
| 133 |
| 134 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/flac'")); |
| 135 |
| 136 // Supported when built with USE_PROPRIETARY_CODECS |
| 137 EXPECT_EQ(kPropSupported, CanDecodeAudio("'audio/mpeg; codecs=\"mp4a.69\"'")); |
| 138 EXPECT_EQ(kPropSupported, |
| 139 CanDecodeAudio("'audio/mp4; codecs=\"mp4a.40.02\"'")); |
| 140 EXPECT_EQ(kPropSupported, CanDecodeAudio("'audio/aac'")); |
| 141 |
| 142 // Test a handful of invalid strings. |
| 143 EXPECT_EQ(kUnsupported, CanDecodeAudio("'audio/wav; codecs=\"mp3\"'")); |
| 144 EXPECT_EQ(kUnsupported, CanDecodeAudio("'audio/webm; codecs=\"vp8\"'")); |
| 145 } |
| 146 |
| 147 } // namespace content |
OLD | NEW |