Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / display / chromeos / apply_content_protection_task_unittest.cc
blobdf279c948d19c6d99b5f25dc6b46d709f8875faa
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.
5 #include "base/bind.h"
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"
14 namespace ui {
15 namespace test {
17 namespace {
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();
28 } // namespace
30 class ApplyContentProtectionTaskTest : public testing::Test {
31 public:
32 enum Response {
33 ERROR,
34 SUCCESS,
35 NOT_CALLED,
38 ApplyContentProtectionTaskTest()
39 : response_(NOT_CALLED), display_delegate_(&log_) {}
40 ~ApplyContentProtectionTaskTest() override {}
42 void ResponseCallback(bool success) { response_ = success ? SUCCESS : ERROR; }
44 protected:
45 Response response_;
46 ActionLogger log_;
47 TestNativeDisplayDelegate display_delegate_;
49 private:
50 DISALLOW_COPY_AND_ASSIGN(ApplyContentProtectionTaskTest);
53 TEST_F(ApplyContentProtectionTaskTest, ApplyWithNoHDCPCapableDisplay) {
54 ScopedVector<DisplaySnapshot> displays;
55 displays.push_back(
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)));
66 task.Run();
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)));
84 task.Run();
86 EXPECT_EQ(SUCCESS, response_);
87 EXPECT_EQ(
88 JoinActions(GetSetHDCPStateAction(*layout_manager.GetDisplayStates()[0],
89 HDCP_STATE_DESIRED).c_str(),
90 NULL),
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)));
106 task.Run();
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)));
125 task.Run();
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)));
144 task.Run();
146 EXPECT_EQ(ERROR, response_);
147 EXPECT_EQ(
148 JoinActions(GetSetHDCPStateAction(*layout_manager.GetDisplayStates()[0],
149 HDCP_STATE_DESIRED).c_str(),
150 NULL),
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)));
167 task.Run();
169 EXPECT_EQ(SUCCESS, response_);
170 EXPECT_EQ(kNoActions, log_.GetActionsAndClear());
173 } // namespace test
174 } // namespace ui