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/display_layout_manager.h"
8 #include "ui/display/chromeos/query_content_protection_task.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 QueryContentProtectionTaskTest
: public testing::Test
{
32 QueryContentProtectionTaskTest()
33 : display_delegate_(&log_
), has_response_(false) {}
34 ~QueryContentProtectionTaskTest() override
{}
36 void ResponseCallback(QueryContentProtectionTask::Response response
) {
43 TestNativeDisplayDelegate display_delegate_
;
46 QueryContentProtectionTask::Response response_
;
49 DISALLOW_COPY_AND_ASSIGN(QueryContentProtectionTaskTest
);
52 TEST_F(QueryContentProtectionTaskTest
, QueryWithNoHDCPCapableDisplay
) {
53 ScopedVector
<DisplaySnapshot
> displays
;
55 CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_INTERNAL
));
56 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
57 MULTIPLE_DISPLAY_STATE_SINGLE
);
59 QueryContentProtectionTask
task(
60 &layout_manager
, &display_delegate_
, 1,
61 base::Bind(&QueryContentProtectionTaskTest::ResponseCallback
,
62 base::Unretained(this)));
65 EXPECT_TRUE(has_response_
);
66 EXPECT_TRUE(response_
.success
);
67 EXPECT_EQ(DISPLAY_CONNECTION_TYPE_INTERNAL
, response_
.link_mask
);
68 EXPECT_EQ(0u, response_
.enabled
);
69 EXPECT_EQ(0u, response_
.unfulfilled
);
72 TEST_F(QueryContentProtectionTaskTest
, QueryWithUnknownDisplay
) {
73 ScopedVector
<DisplaySnapshot
> displays
;
74 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_UNKNOWN
));
75 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
76 MULTIPLE_DISPLAY_STATE_SINGLE
);
78 QueryContentProtectionTask
task(
79 &layout_manager
, &display_delegate_
, 1,
80 base::Bind(&QueryContentProtectionTaskTest::ResponseCallback
,
81 base::Unretained(this)));
84 EXPECT_TRUE(has_response_
);
85 EXPECT_FALSE(response_
.success
);
86 EXPECT_EQ(DISPLAY_CONNECTION_TYPE_UNKNOWN
, response_
.link_mask
);
87 EXPECT_EQ(0u, response_
.enabled
);
88 EXPECT_EQ(0u, response_
.unfulfilled
);
91 TEST_F(QueryContentProtectionTaskTest
, FailQueryWithHDMIDisplay
) {
92 ScopedVector
<DisplaySnapshot
> displays
;
93 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
94 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
95 MULTIPLE_DISPLAY_STATE_SINGLE
);
96 display_delegate_
.set_get_hdcp_state_expectation(false);
98 QueryContentProtectionTask
task(
99 &layout_manager
, &display_delegate_
, 1,
100 base::Bind(&QueryContentProtectionTaskTest::ResponseCallback
,
101 base::Unretained(this)));
104 EXPECT_TRUE(has_response_
);
105 EXPECT_FALSE(response_
.success
);
106 EXPECT_EQ(DISPLAY_CONNECTION_TYPE_HDMI
, response_
.link_mask
);
109 TEST_F(QueryContentProtectionTaskTest
, QueryWithHDMIDisplayAndUnfulfilled
) {
110 ScopedVector
<DisplaySnapshot
> displays
;
111 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
112 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
113 MULTIPLE_DISPLAY_STATE_SINGLE
);
115 QueryContentProtectionTask
task(
116 &layout_manager
, &display_delegate_
, 1,
117 base::Bind(&QueryContentProtectionTaskTest::ResponseCallback
,
118 base::Unretained(this)));
121 EXPECT_TRUE(has_response_
);
122 EXPECT_TRUE(response_
.success
);
123 EXPECT_EQ(DISPLAY_CONNECTION_TYPE_HDMI
, response_
.link_mask
);
124 EXPECT_EQ(0u, response_
.enabled
);
125 EXPECT_EQ(CONTENT_PROTECTION_METHOD_HDCP
, response_
.unfulfilled
);
128 TEST_F(QueryContentProtectionTaskTest
, QueryWithHDMIDisplayAndFulfilled
) {
129 ScopedVector
<DisplaySnapshot
> displays
;
130 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
131 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
132 MULTIPLE_DISPLAY_STATE_SINGLE
);
133 display_delegate_
.set_hdcp_state(HDCP_STATE_ENABLED
);
135 QueryContentProtectionTask
task(
136 &layout_manager
, &display_delegate_
, 1,
137 base::Bind(&QueryContentProtectionTaskTest::ResponseCallback
,
138 base::Unretained(this)));
141 EXPECT_TRUE(has_response_
);
142 EXPECT_TRUE(response_
.success
);
143 EXPECT_EQ(DISPLAY_CONNECTION_TYPE_HDMI
, response_
.link_mask
);
144 EXPECT_EQ(CONTENT_PROTECTION_METHOD_HDCP
, response_
.enabled
);
145 EXPECT_EQ(0u, response_
.unfulfilled
);
148 TEST_F(QueryContentProtectionTaskTest
, QueryWith2HDCPDisplays
) {
149 ScopedVector
<DisplaySnapshot
> displays
;
150 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
151 displays
.push_back(CreateDisplaySnapshot(2, DISPLAY_CONNECTION_TYPE_DVI
));
152 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
153 MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED
);
155 QueryContentProtectionTask
task(
156 &layout_manager
, &display_delegate_
, 1,
157 base::Bind(&QueryContentProtectionTaskTest::ResponseCallback
,
158 base::Unretained(this)));
161 EXPECT_TRUE(has_response_
);
162 EXPECT_TRUE(response_
.success
);
163 EXPECT_EQ(DISPLAY_CONNECTION_TYPE_HDMI
, response_
.link_mask
);
164 EXPECT_EQ(0u, response_
.enabled
);
165 EXPECT_EQ(CONTENT_PROTECTION_METHOD_HDCP
, response_
.unfulfilled
);
168 TEST_F(QueryContentProtectionTaskTest
, QueryWithMirrorHDCPDisplays
) {
169 ScopedVector
<DisplaySnapshot
> displays
;
170 displays
.push_back(CreateDisplaySnapshot(1, DISPLAY_CONNECTION_TYPE_HDMI
));
171 displays
.push_back(CreateDisplaySnapshot(2, DISPLAY_CONNECTION_TYPE_DVI
));
172 TestDisplayLayoutManager
layout_manager(displays
.Pass(),
173 MULTIPLE_DISPLAY_STATE_DUAL_MIRROR
);
175 QueryContentProtectionTask
task(
176 &layout_manager
, &display_delegate_
, 1,
177 base::Bind(&QueryContentProtectionTaskTest::ResponseCallback
,
178 base::Unretained(this)));
181 EXPECT_TRUE(has_response_
);
182 EXPECT_TRUE(response_
.success
);
183 EXPECT_EQ(static_cast<uint32_t>(DISPLAY_CONNECTION_TYPE_HDMI
|
184 DISPLAY_CONNECTION_TYPE_DVI
),
185 response_
.link_mask
);
186 EXPECT_EQ(0u, response_
.enabled
);
187 EXPECT_EQ(CONTENT_PROTECTION_METHOD_HDCP
, response_
.unfulfilled
);