1 // Copyright 2015 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.
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/display/chromeos/apply_content_protection_task.h"
8 #include "ui/display/chromeos/display_layout_manager.h"
9 #include "ui/display/chromeos/test/action_logger_util.h"
10 #include "ui/display/chromeos/test/test_display_layout_manager.h"
11 #include "ui/display/chromeos/test/test_display_snapshot.h"
12 #include "ui/display/chromeos/test/test_native_display_delegate.h"
19 scoped_ptr
<DisplaySnapshot
> CreateDisplaySnapshot(int64_t id
,
20 DisplayConnectionType type
) {
21 scoped_ptr
<TestDisplaySnapshot
> display(new TestDisplaySnapshot());
22 display
->set_display_id(id
);
23 display
->set_type(type
);
25 return display
.Pass();
30 class ApplyContentProtectionTaskTest
: public testing::Test
{
38 ApplyContentProtectionTaskTest()
39 : response_(NOT_CALLED
), display_delegate_(&log_
) {}
40 ~ApplyContentProtectionTaskTest() override
{}
42 void ResponseCallback(bool success
) { response_
= success
? SUCCESS
: ERROR
; }
47 TestNativeDisplayDelegate display_delegate_
;
50 DISALLOW_COPY_AND_ASSIGN(ApplyContentProtectionTaskTest
);
53 TEST_F(ApplyContentProtectionTaskTest
, ApplyWithNoHDCPCapableDisplay
) {
54 ScopedVector
<DisplaySnapshot
> displays
;
56 CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_INTERNAL
));
57 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
58 MULTIPLE_DISPLAY_STATE_SINGLE
);
60 DisplayConfigurator::ContentProtections request
;
61 request
[1] = CONTENT_PROTECTION_METHOD_HDCP
;
62 ApplyContentProtectionTask
task(
63 &layout_manager
, &display_delegate_
, request
,
64 base::Bind(&ApplyContentProtectionTaskTest::ResponseCallback
,
65 base::Unretained(this)));
68 EXPECT_EQ(SUCCESS
, response_
);
69 EXPECT_EQ(kNoActions
, log_
.GetActionsAndClear());
72 TEST_F(ApplyContentProtectionTaskTest
, ApplyWithHDMIDisplay
) {
73 ScopedVector
<DisplaySnapshot
> displays
;
74 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
75 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
76 MULTIPLE_DISPLAY_STATE_SINGLE
);
78 DisplayConfigurator::ContentProtections request
;
79 request
[1] = CONTENT_PROTECTION_METHOD_HDCP
;
80 ApplyContentProtectionTask
task(
81 &layout_manager
, &display_delegate_
, request
,
82 base::Bind(&ApplyContentProtectionTaskTest::ResponseCallback
,
83 base::Unretained(this)));
86 EXPECT_EQ(SUCCESS
, response_
);
88 JoinActions(GetSetHDCPStateAction(*layout_manager
.GetDisplayStates()[0],
89 HDCP_STATE_DESIRED
).c_str(),
91 log_
.GetActionsAndClear());
94 TEST_F(ApplyContentProtectionTaskTest
, ApplyWithUnknownDisplay
) {
95 ScopedVector
<DisplaySnapshot
> displays
;
96 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_UNKNOWN
));
97 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
98 MULTIPLE_DISPLAY_STATE_SINGLE
);
100 DisplayConfigurator::ContentProtections request
;
101 request
[1] = CONTENT_PROTECTION_METHOD_HDCP
;
102 ApplyContentProtectionTask
task(
103 &layout_manager
, &display_delegate_
, request
,
104 base::Bind(&ApplyContentProtectionTaskTest::ResponseCallback
,
105 base::Unretained(this)));
108 EXPECT_EQ(ERROR
, response_
);
109 EXPECT_EQ(kNoActions
, log_
.GetActionsAndClear());
112 TEST_F(ApplyContentProtectionTaskTest
, FailGettingHDCPState
) {
113 ScopedVector
<DisplaySnapshot
> displays
;
114 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
115 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
116 MULTIPLE_DISPLAY_STATE_SINGLE
);
117 display_delegate_
.set_get_hdcp_state_expectation(false);
119 DisplayConfigurator::ContentProtections request
;
120 request
[1] = CONTENT_PROTECTION_METHOD_HDCP
;
121 ApplyContentProtectionTask
task(
122 &layout_manager
, &display_delegate_
, request
,
123 base::Bind(&ApplyContentProtectionTaskTest::ResponseCallback
,
124 base::Unretained(this)));
127 EXPECT_EQ(ERROR
, response_
);
128 EXPECT_EQ(kNoActions
, log_
.GetActionsAndClear());
131 TEST_F(ApplyContentProtectionTaskTest
, FailSettingHDCPState
) {
132 ScopedVector
<DisplaySnapshot
> displays
;
133 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
134 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
135 MULTIPLE_DISPLAY_STATE_SINGLE
);
136 display_delegate_
.set_set_hdcp_state_expectation(false);
138 DisplayConfigurator::ContentProtections request
;
139 request
[1] = CONTENT_PROTECTION_METHOD_HDCP
;
140 ApplyContentProtectionTask
task(
141 &layout_manager
, &display_delegate_
, request
,
142 base::Bind(&ApplyContentProtectionTaskTest::ResponseCallback
,
143 base::Unretained(this)));
146 EXPECT_EQ(ERROR
, response_
);
148 JoinActions(GetSetHDCPStateAction(*layout_manager
.GetDisplayStates()[0],
149 HDCP_STATE_DESIRED
).c_str(),
151 log_
.GetActionsAndClear());
154 TEST_F(ApplyContentProtectionTaskTest
, ApplyNoopProtection
) {
155 ScopedVector
<DisplaySnapshot
> displays
;
156 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
157 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
158 MULTIPLE_DISPLAY_STATE_SINGLE
);
159 display_delegate_
.set_hdcp_state(HDCP_STATE_UNDESIRED
);
161 DisplayConfigurator::ContentProtections request
;
162 request
[1] = CONTENT_PROTECTION_METHOD_NONE
;
163 ApplyContentProtectionTask
task(
164 &layout_manager
, &display_delegate_
, request
,
165 base::Bind(&ApplyContentProtectionTaskTest::ResponseCallback
,
166 base::Unretained(this)));
169 EXPECT_EQ(SUCCESS
, response_
);
170 EXPECT_EQ(kNoActions
, log_
.GetActionsAndClear());