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() {} | |
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/ogg; codecs=\"theora\"'")); | |
90 EXPECT_EQ(kSupported, CanDecodeVideo("'video/webm; codecs=\"vp8\"'")); | |
91 | |
92 // TODO(chcunningham): Drop support for the old VP9 string. Only support | |
93 // the new vp09 format which provides critical profile information. | |
94 EXPECT_EQ(kSupported, CanDecodeVideo("'video/webm; codecs=\"vp9\"'")); | |
95 // Requires command line flag switches::kEnableNewVp9CodecString | |
96 EXPECT_EQ(kSupported, | |
97 CanDecodeVideo("'video/webm; codecs=\"vp09.00.10.08\"'")); | |
98 // Requires command line flag switches::kEnableVp9InMp4 | |
99 EXPECT_EQ(kSupported, | |
100 CanDecodeVideo("'video/mp4; codecs=\"vp09.00.10.08\"'")); | |
101 | |
102 // Supported when built with USE_PROPRIETARY_CODECS | |
103 EXPECT_EQ(kPropSupported, | |
104 CanDecodeVideo("'video/mp4; codecs=\"avc1.42E01E\"'")); | |
105 EXPECT_EQ(kPropSupported, | |
106 CanDecodeVideo("'video/mp4; codecs=\"avc1.42101E\"'")); | |
107 EXPECT_EQ(kPropSupported, | |
108 CanDecodeVideo("'video/mp4; codecs=\"avc1.42701E\"'")); | |
109 EXPECT_EQ(kPropSupported, | |
110 CanDecodeVideo("'video/mp4; codecs=\"avc1.42F01E\"'")); | |
111 | |
112 // Test a handful of invalid strings. | |
113 EXPECT_EQ(kUnsupported, CanDecodeVideo("'video/webm; codecs=\"theora\"'")); | |
114 EXPECT_EQ(kUnsupported, | |
115 CanDecodeVideo("'video/webm; codecs=\"avc1.42E01E\"'")); | |
116 // Only new vp09 format is supported with MP4. | |
117 EXPECT_EQ(kUnsupported, CanDecodeVideo("'video/mp4; codecs=\"vp9\"'")); | |
jrummell
2017/04/21 21:14:36
How about testing audio codecs in the video field
chcunningham
2017/04/24 22:47:52
In the AudioDecodeTypes I do try 'audio/webm; code
| |
118 } | |
119 | |
120 // Cover basic codec support. See media_canplaytype_browsertest.cc for more | |
121 // exhaustive codec string testing. | |
122 IN_PROC_BROWSER_TEST_F(MediaCapabilitiesTest, AudioDecodeTypes) { | |
123 base::FilePath file_path = media::GetTestDataFilePath(kDecodeTestFile); | |
124 | |
125 EXPECT_TRUE( | |
126 NavigateToURL(shell(), content::GetFileUrlWithQuery(file_path, ""))); | |
127 | |
128 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/ogg; codecs=\"flac\"'")); | |
129 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/ogg; codecs=\"vorbis\"'")); | |
130 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/ogg; codecs=\"opus\"'")); | |
131 | |
132 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/webm; codecs=\"opus\"'")); | |
133 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/webm; codecs=\"vorbis\"'")); | |
134 | |
135 EXPECT_EQ(kSupported, CanDecodeAudio("'audio/flac'")); | |
136 | |
137 // Supported when built with USE_PROPRIETARY_CODECS | |
138 EXPECT_EQ(kPropSupported, CanDecodeAudio("'audio/mpeg; codecs=\"mp4a.69\"'")); | |
139 EXPECT_EQ(kPropSupported, | |
140 CanDecodeAudio("'audio/mp4; codecs=\"mp4a.40.02\"'")); | |
141 EXPECT_EQ(kPropSupported, CanDecodeAudio("'audio/aac'")); | |
142 | |
143 // Test a handful of invalid strings. | |
144 EXPECT_EQ(kUnsupported, CanDecodeAudio("'audio/wav; codecs=\"mp3\"'")); | |
145 EXPECT_EQ(kUnsupported, CanDecodeAudio("'audio/webm; codecs=\"vp8\"'")); | |
146 } | |
147 | |
148 } // namespace content | |
OLD | NEW |