blob: 8f30094a88aaec7da5a463ed7b358d24a2a7d55e [file] [log] [blame]
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +01001// Copyright (c) 2013 The Chromium Authors. All rights reserved.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00005#include "base/command_line.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00006#include "base/path_service.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01007#include "base/strings/utf_string_conversions.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00008#include "base/win/windows_version.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01009#include "content/browser/media/media_browsertest.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000010#include "content/public/common/content_switches.h"
11#include "content/public/test/browser_test_utils.h"
Torne (Richard Coles)3551c9c2013-08-23 16:39:15 +010012#include "content/shell/browser/shell.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000013
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014// Available key systems.
15static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000016
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010017// Supported media types.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000018static const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
19static const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
20static const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000021
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +010022// EME-specific test results and errors.
23static const char kEmeGkrException[] = "GENERATE_KEY_REQUEST_EXCEPTION";
24static const char kEmeKeyError[] = "KEYERROR";
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010025
Ben Murdocheb525c52013-07-10 11:40:50 +010026// The type of video src used to load media.
27enum SrcType {
28 SRC,
29 MSE
30};
31
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000032namespace content {
33
Ben Murdocheb525c52013-07-10 11:40:50 +010034// Tests encrypted media playback with a combination of parameters:
35// - char*: Key system name.
36// - bool: True to load media using MSE, otherwise use src.
37class EncryptedMediaTest : public content::MediaBrowserTest,
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010038 public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000039 public:
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010040 // Can only be used in parameterized (*_P) tests.
41 const char* CurrentKeySystem() {
42 return std::tr1::get<0>(GetParam());
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000043 }
44
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010045 // Can only be used in parameterized (*_P) tests.
46 SrcType CurrentSourceType() {
47 return std::tr1::get<1>(GetParam());
Ben Murdocheb525c52013-07-10 11:40:50 +010048 }
49
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010050 void TestSimplePlayback(const char* encrypted_media, const char* media_type) {
51 RunSimpleEncryptedMediaTest(
52 encrypted_media, media_type, CurrentKeySystem(), CurrentSourceType());
53 }
54
55 void TestFrameSizeChange() {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010056 RunEncryptedMediaTest("encrypted_frame_size_change.html",
57 "frame_size_change-av-enc-v.webm", kWebMAudioVideo,
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010058 CurrentKeySystem(), CurrentSourceType(), kEnded);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000059 }
60
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010061 void TestConfigChange() {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010062 std::vector<StringPair> query_params;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010063 query_params.push_back(std::make_pair("keysystem", CurrentKeySystem()));
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010064 query_params.push_back(std::make_pair("runencrypted", "1"));
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010065 RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010066 }
67
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010068 void RunEncryptedMediaTest(const char* html_page,
69 const char* media_file,
70 const char* media_type,
71 const char* key_system,
72 SrcType src_type,
73 const char* expectation) {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010074 std::vector<StringPair> query_params;
75 query_params.push_back(std::make_pair("mediafile", media_file));
76 query_params.push_back(std::make_pair("mediatype", media_type));
77 query_params.push_back(std::make_pair("keysystem", key_system));
Ben Murdocheb525c52013-07-10 11:40:50 +010078 if (src_type == MSE)
79 query_params.push_back(std::make_pair("usemse", "1"));
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010080 RunMediaTestPage(html_page, &query_params, expectation, true);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000081 }
82
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010083 void RunSimpleEncryptedMediaTest(const char* media_file,
84 const char* media_type,
85 const char* key_system,
86 SrcType src_type) {
87 RunEncryptedMediaTest("encrypted_media_player.html", media_file,
88 media_type, key_system, src_type, kEnded);
89 }
90
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000091 protected:
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +010092 // We want to fail quickly when a test fails because an error is encountered.
93 virtual void AddWaitForTitles(content::TitleWatcher* title_watcher) OVERRIDE {
94 MediaBrowserTest::AddWaitForTitles(title_watcher);
95 title_watcher->AlsoWaitForTitle(ASCIIToUTF16(kEmeGkrException));
96 title_watcher->AlsoWaitForTitle(ASCIIToUTF16(kEmeKeyError));
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010097 }
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010098
99#if defined(OS_ANDROID)
100 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
101 command_line->AppendSwitch(
102 switches::kDisableGestureRequirementForMediaPlayback);
103 }
104#endif
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000105};
106
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100107using ::testing::Combine;
108using ::testing::Values;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000109
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100110#if !defined(OS_ANDROID)
111// Encrypted media playback with SRC is not supported on Android.
112INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest,
113 Combine(Values(kClearKeyKeySystem), Values(SRC)));
114#endif // defined(OS_ANDROID)
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000115
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100116INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest,
117 Combine(Values(kClearKeyKeySystem), Values(MSE)));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000118
119IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) {
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100120 TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000121}
122
123IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) {
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100124 TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000125}
126
127IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) {
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100128 TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000129}
130
131IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) {
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100132 TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000133}
134
135IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) {
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100136 TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000137}
138
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100139IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) {
140 TestConfigChange();
141}
142
143IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000144 // Times out on Windows XP. http://crbug.com/171937
145#if defined(OS_WIN)
146 if (base::win::GetVersion() < base::win::VERSION_VISTA)
147 return;
148#endif
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100149 TestFrameSizeChange();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000150}
151
Torne (Richard Coles)424c4d72013-08-30 15:14:49 +0100152IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) {
153 RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm",
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100154 kWebMAudioOnly, "com.example.foo", MSE,
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +0100155 kEmeGkrException);
Torne (Richard Coles)424c4d72013-08-30 15:14:49 +0100156}
157
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000158} // namespace content