Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / media / encrypted_media_browsertest.cc
blobc049d307cad0ed660ae081b4a75ee91734582dfc
1 // Copyright (c) 2013 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.
5 #include "base/command_line.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "base/win/windows_version.h"
8 #include "content/browser/media/media_browsertest.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/browser_test_utils.h"
11 #include "content/shell/browser/shell.h"
12 #if defined(OS_ANDROID)
13 #include "base/android/build_info.h"
14 #endif
16 // Available key systems.
17 const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
19 // Supported media types.
20 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
21 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
22 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
24 // EME-specific test results and errors.
25 const char kEmeKeyError[] = "KEYERROR";
26 const char kEmeNotSupportedError[] = "NOTSUPPORTEDERROR";
28 const char kDefaultEmePlayer[] = "eme_player.html";
30 // The type of video src used to load media.
31 enum SrcType {
32 SRC,
33 MSE
36 namespace content {
38 // MSE is available on all desktop platforms and on Android 4.1 and later.
39 static bool IsMSESupported() {
40 #if defined(OS_ANDROID)
41 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
42 VLOG(0) << "MSE is only supported in Android 4.1 and later.";
43 return false;
45 #endif // defined(OS_ANDROID)
46 return true;
49 // Tests encrypted media playback with a combination of parameters:
50 // - char*: Key system name.
51 // - bool: True to load media using MSE, otherwise use src.
52 class EncryptedMediaTest : public content::MediaBrowserTest,
53 public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > {
54 public:
55 // Can only be used in parameterized (*_P) tests.
56 const std::string CurrentKeySystem() {
57 return std::tr1::get<0>(GetParam());
60 // Can only be used in parameterized (*_P) tests.
61 SrcType CurrentSourceType() {
62 return std::tr1::get<1>(GetParam());
65 void TestSimplePlayback(const std::string& encrypted_media,
66 const std::string& media_type) {
67 RunSimpleEncryptedMediaTest(
68 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType());
71 void TestFrameSizeChange() {
72 RunEncryptedMediaTest("encrypted_frame_size_change.html",
73 "frame_size_change-av_enc-v.webm", kWebMAudioVideo,
74 CurrentKeySystem(), CurrentSourceType(), kEnded);
77 void TestConfigChange() {
78 if (CurrentSourceType() != MSE || !IsMSESupported()) {
79 VLOG(0) << "Skipping test - config change test requires MSE.";
80 return;
83 media::QueryParams query_params;
84 query_params.push_back(std::make_pair("keySystem", CurrentKeySystem()));
85 query_params.push_back(std::make_pair("runEncrypted", "1"));
86 RunMediaTestPage("mse_config_change.html", query_params, kEnded, true);
89 void RunEncryptedMediaTest(const std::string& html_page,
90 const std::string& media_file,
91 const std::string& media_type,
92 const std::string& key_system,
93 SrcType src_type,
94 const std::string& expectation) {
95 if (src_type == MSE && !IsMSESupported()) {
96 VLOG(0) << "Skipping test - MSE not supported.";
97 return;
100 media::QueryParams query_params;
101 query_params.push_back(std::make_pair("mediaFile", media_file));
102 query_params.push_back(std::make_pair("mediaType", media_type));
103 query_params.push_back(std::make_pair("keySystem", key_system));
104 if (src_type == MSE)
105 query_params.push_back(std::make_pair("useMSE", "1"));
106 RunMediaTestPage(html_page, query_params, expectation, true);
109 void RunSimpleEncryptedMediaTest(const std::string& media_file,
110 const std::string& media_type,
111 const std::string& key_system,
112 SrcType src_type) {
113 RunEncryptedMediaTest(kDefaultEmePlayer,
114 media_file,
115 media_type,
116 key_system,
117 src_type,
118 kEnded);
121 protected:
122 // We want to fail quickly when a test fails because an error is encountered.
123 virtual void AddWaitForTitles(content::TitleWatcher* title_watcher) OVERRIDE {
124 MediaBrowserTest::AddWaitForTitles(title_watcher);
125 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeNotSupportedError));
126 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEmeKeyError));
129 #if defined(OS_ANDROID)
130 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
131 command_line->AppendSwitch(
132 switches::kDisableGestureRequirementForMediaPlayback);
134 #endif
137 using ::testing::Combine;
138 using ::testing::Values;
140 #if !defined(OS_ANDROID)
141 // Encrypted media playback with SRC is not supported on Android.
142 INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest,
143 Combine(Values(kClearKeyKeySystem), Values(SRC)));
144 #endif // !defined(OS_ANDROID)
146 INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest,
147 Combine(Values(kClearKeyKeySystem), Values(MSE)));
149 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
150 TestSimplePlayback("bear-a_enc-a.webm", kWebMAudioOnly);
153 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
154 TestSimplePlayback("bear-320x240-av_enc-a.webm", kWebMAudioVideo);
157 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
158 TestSimplePlayback("bear-320x240-av_enc-av.webm", kWebMAudioVideo);
161 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
162 TestSimplePlayback("bear-320x240-v_enc-v.webm", kWebMVideoOnly);
165 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
166 TestSimplePlayback("bear-320x240-av_enc-v.webm", kWebMAudioVideo);
169 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
170 TestConfigChange();
173 IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
174 // Times out on Windows XP. http://crbug.com/171937
175 #if defined(OS_WIN)
176 if (base::win::GetVersion() < base::win::VERSION_VISTA)
177 return;
178 #elif defined(__aarch64__)
179 // Times out on arm64 currently due to http://crbug.com/403308
180 return;
181 #endif
182 TestFrameSizeChange();
185 IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
186 RunEncryptedMediaTest(kDefaultEmePlayer,
187 "bear-a_enc-a.webm",
188 kWebMAudioOnly,
189 "com.example.foo",
190 MSE,
191 kEmeNotSupportedError);
194 } // namespace content