1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/string16.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/shell/shell.h"
#include "content/test/content_browser_test.h"
#include "content/test/content_browser_test_utils.h"
#include "googleurl/src/gurl.h"
#include "webkit/media/crypto/key_systems.h"
namespace content {
// Platform-specific filename relative to the chrome executable.
#if defined(OS_WIN)
const wchar_t kLibraryName[] = L"clearkeycdmplugin.dll";
#elif defined(OS_MACOSX)
const char kLibraryName[] = "clearkeycdmplugin.plugin";
#elif defined(OS_POSIX)
const char kLibraryName[] = "libclearkeycdmplugin.so";
#endif
// Available key systems.
const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey";
class EncryptedMediaTest : public testing::WithParamInterface<const char*>,
public ContentBrowserTest {
public:
void TestSimplePlayback(const char* encrypted_video, const char* key_system,
const string16 expectation) {
PlayEncryptedMedia("encrypted_media_player.html", encrypted_video,
key_system, expectation);
}
void TestFrameSizeChange(const char* key_system, const string16 expectation) {
PlayEncryptedMedia("encrypted_frame_size_change.html",
"frame_size_change-av-enc-v.webm", key_system,
expectation);
}
void PlayEncryptedMedia(const char* html_page, const char* media_file,
const char* key_system, const string16 expectation) {
// TODO(shadi): Add non-HTTP tests once src is supported for EME.
ASSERT_TRUE(test_server()->Start());
const string16 kError = ASCIIToUTF16("ERROR");
const string16 kFailed = ASCIIToUTF16("FAILED");
GURL player_gurl = test_server()->GetURL(base::StringPrintf(
"files/media/%s?keysystem=%s&mediafile=%s", html_page, key_system,
media_file));
TitleWatcher title_watcher(shell()->web_contents(), expectation);
title_watcher.AlsoWaitForTitle(kError);
title_watcher.AlsoWaitForTitle(kFailed);
NavigateToURL(shell(), player_gurl);
string16 final_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(expectation, final_title);
if (final_title == kFailed) {
std::string fail_message;
EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
shell()->web_contents()->GetRenderViewHost(), L"",
L"window.domAutomationController.send(failMessage);", &fail_message));
LOG(INFO) << "Test failed: " << fail_message;
}
}
protected:
// Registers any CDM plugins not registered by default.
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kDisableAudio);
command_line->AppendSwitch(switches::kEnableEncryptedMedia);
command_line->AppendSwitch(switches::kPpapiOutOfProcess);
// Append the switch to register the Clear Key CDM plugin.
FilePath plugin_dir;
EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
FilePath plugin_lib = plugin_dir.Append(kLibraryName);
EXPECT_TRUE(file_util::PathExists(plugin_lib));
FilePath::StringType pepper_plugin = plugin_lib.value();
pepper_plugin.append(FILE_PATH_LITERAL(
"#Clear Key CDM#Clear Key CDM 0.1.0.0#0.1.0.0;"));
#if defined(OS_WIN)
pepper_plugin.append(ASCIIToWide(
webkit_media::GetPluginType(kExternalClearKeyKeySystem)));
#else
pepper_plugin.append(
webkit_media::GetPluginType(kExternalClearKeyKeySystem));
#endif
command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
pepper_plugin);
}
};
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback) {
const string16 kExpected = ASCIIToUTF16("ENDED");
ASSERT_NO_FATAL_FAILURE(TestSimplePlayback("bear-320x240-encrypted.webm",
GetParam(), kExpected));
}
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, DISABLED_FrameChangeVideo) {
const string16 kExpected = ASCIIToUTF16("ENDED");
ASSERT_NO_FATAL_FAILURE(TestFrameSizeChange(GetParam(), kExpected));
}
IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, InvalidKeySystem) {
const string16 kExpected = ASCIIToUTF16(
StringToUpperASCII(std::string("GenerateKeyRequestException")));
ASSERT_NO_FATAL_FAILURE(TestSimplePlayback("bear-320x240-encrypted.webm",
"com.example.invalid", kExpected));
}
INSTANTIATE_TEST_CASE_P(ClearKey, EncryptedMediaTest,
::testing::Values(kClearKeyKeySystem));
// http://crbug.com/152864 (Mac) and http://crbug.com/157759 (ASAN on Aura)
#if !defined(OS_MACOSX) && !(defined(ADDRESS_SANITIZER) && defined(USE_AURA))
INSTANTIATE_TEST_CASE_P(ExternalClearKey, EncryptedMediaTest,
::testing::Values(kExternalClearKeyKeySystem));
#endif
} // namespace content
|