Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 2 | // 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 5 | #include "base/command_line.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 6 | #include "base/path_service.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 7 | #include "base/strings/utf_string_conversions.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 8 | #include "base/win/windows_version.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 9 | #include "content/browser/media/media_browsertest.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 10 | #include "content/public/common/content_switches.h" |
| 11 | #include "content/public/test/browser_test_utils.h" |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 12 | #include "content/shell/browser/shell.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 14 | // Available key systems. |
| 15 | static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 16 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 17 | // Supported media types. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 18 | static const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\""; |
| 19 | static const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\""; |
| 20 | static const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\""; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 21 | |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 22 | // EME-specific test results and errors. |
| 23 | static const char kEmeGkrException[] = "GENERATE_KEY_REQUEST_EXCEPTION"; |
| 24 | static const char kEmeKeyError[] = "KEYERROR"; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 25 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 26 | // The type of video src used to load media. |
| 27 | enum SrcType { |
| 28 | SRC, |
| 29 | MSE |
| 30 | }; |
| 31 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 32 | namespace content { |
| 33 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 34 | // 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. |
| 37 | class EncryptedMediaTest : public content::MediaBrowserTest, |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 38 | public testing::WithParamInterface<std::tr1::tuple<const char*, SrcType> > { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 39 | public: |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 40 | // Can only be used in parameterized (*_P) tests. |
| 41 | const char* CurrentKeySystem() { |
| 42 | return std::tr1::get<0>(GetParam()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 45 | // Can only be used in parameterized (*_P) tests. |
| 46 | SrcType CurrentSourceType() { |
| 47 | return std::tr1::get<1>(GetParam()); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 50 | 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 56 | RunEncryptedMediaTest("encrypted_frame_size_change.html", |
| 57 | "frame_size_change-av-enc-v.webm", kWebMAudioVideo, |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 58 | CurrentKeySystem(), CurrentSourceType(), kEnded); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 61 | void TestConfigChange() { |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 62 | std::vector<StringPair> query_params; |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 63 | query_params.push_back(std::make_pair("keysystem", CurrentKeySystem())); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 64 | query_params.push_back(std::make_pair("runencrypted", "1")); |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 65 | RunMediaTestPage("mse_config_change.html", &query_params, kEnded, true); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 68 | 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 74 | 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 Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 78 | if (src_type == MSE) |
| 79 | query_params.push_back(std::make_pair("usemse", "1")); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 80 | RunMediaTestPage(html_page, &query_params, expectation, true); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 83 | 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 91 | protected: |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 92 | // 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) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 97 | } |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 98 | |
| 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 107 | using ::testing::Combine; |
| 108 | using ::testing::Values; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 109 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 110 | #if !defined(OS_ANDROID) |
| 111 | // Encrypted media playback with SRC is not supported on Android. |
| 112 | INSTANTIATE_TEST_CASE_P(SRC_ClearKey, EncryptedMediaTest, |
| 113 | Combine(Values(kClearKeyKeySystem), Values(SRC))); |
| 114 | #endif // defined(OS_ANDROID) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 115 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 116 | INSTANTIATE_TEST_CASE_P(MSE_ClearKey, EncryptedMediaTest, |
| 117 | Combine(Values(kClearKeyKeySystem), Values(MSE))); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 118 | |
| 119 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioOnly_WebM) { |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 120 | TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_AudioClearVideo_WebM) { |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 124 | TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoAudio_WebM) { |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 128 | TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoOnly_WebM) { |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 132 | TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, Playback_VideoClearAudio_WebM) { |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 136 | TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 139 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, ConfigChangeVideo) { |
| 140 | TestConfigChange(); |
| 141 | } |
| 142 | |
| 143 | IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, FrameSizeChangeVideo) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 144 | // 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) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 149 | TestFrameSizeChange(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Torne (Richard Coles) | 424c4d7 | 2013-08-30 15:14:49 +0100 | [diff] [blame] | 152 | IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, UnknownKeySystemThrowsException) { |
| 153 | RunEncryptedMediaTest("encrypted_media_player.html", "bear-a-enc_a.webm", |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 154 | kWebMAudioOnly, "com.example.foo", MSE, |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 155 | kEmeGkrException); |
Torne (Richard Coles) | 424c4d7 | 2013-08-30 15:14:49 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 158 | } // namespace content |