Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Unified Diff: chromeos/display/output_configurator_unittest.cc

Issue 25058009: Unit tests for output protection in output configurator (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: revise according to review comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/display/output_configurator_unittest.cc
diff --git a/chromeos/display/output_configurator_unittest.cc b/chromeos/display/output_configurator_unittest.cc
index 18b2bdc290ff02a305969ec800baf1256d4b9f0c..4e2334573a0eb71cc152270c68da8355ef5f8fe2 100644
--- a/chromeos/display/output_configurator_unittest.cc
+++ b/chromeos/display/output_configurator_unittest.cc
@@ -72,6 +72,11 @@ std::string GetCTMAction(
ctm.x_scale, ctm.x_offset, ctm.y_scale, ctm.y_offset);
}
+// Returns a string describing a TestDelegate::SetHDCPState() call.
+std::string GetSetHDCPStateAction(RROutput id, HDCPState state) {
+ return base::StringPrintf("set_hdcp(id=%lu,state=%d)", id, state);
+}
+
// Joins a sequence of strings describing actions (e.g. kScreenDim) such
// that they can be compared against a string returned by
// TestDelegate::GetActionsAndClear(). The list of actions must be
@@ -95,7 +100,9 @@ class TestDelegate : public OutputConfigurator::Delegate {
public:
static const int kXRandREventBase = 10;
- TestDelegate() : configure_crtc_result_(true) {}
+ TestDelegate()
+ : configure_crtc_result_(true),
+ hdcp_state_(HDCP_STATE_UNDESIRED) {}
virtual ~TestDelegate() {}
const std::vector<OutputConfigurator::OutputSnapshot>& outputs() const {
@@ -110,6 +117,8 @@ class TestDelegate : public OutputConfigurator::Delegate {
configure_crtc_result_ = result;
}
+ void set_hdcp_state(HDCPState state) { hdcp_state_ = state; }
+
// Returns a comma-separated string describing the actions that were
// requested since the previous call to GetActionsAndClear() (i.e.
// results are non-repeatable).
@@ -168,10 +177,12 @@ class TestDelegate : public OutputConfigurator::Delegate {
}
virtual bool GetHDCPState(RROutput id, HDCPState* state) OVERRIDE {
+ *state = hdcp_state_;
return true;
}
virtual bool SetHDCPState(RROutput id, HDCPState state) OVERRIDE {
+ AppendAction(GetSetHDCPStateAction(id, state));
return true;
}
@@ -204,6 +215,9 @@ class TestDelegate : public OutputConfigurator::Delegate {
// Return value returned by ConfigureCrtc().
bool configure_crtc_result_;
+ // Result value of GetHDCPState().
+ HDCPState hdcp_state_;
+
DISALLOW_COPY_AND_ASSIGN(TestDelegate);
};
@@ -340,6 +354,7 @@ class OutputConfiguratorTest : public testing::Test {
o->current_mode = kSmallModeId;
o->native_mode = kSmallModeId;
o->is_internal = true;
+ o->type = OUTPUT_TYPE_INTERNAL;
o->is_aspect_preserving_scaling = true;
o->mode_infos[kSmallModeId] = small_mode_info;
o->has_display_id = true;
@@ -351,6 +366,7 @@ class OutputConfiguratorTest : public testing::Test {
o->current_mode = kBigModeId;
o->native_mode = kBigModeId;
o->is_internal = false;
+ o->type = OUTPUT_TYPE_HDMI;
o->is_aspect_preserving_scaling = true;
o->mode_infos[kSmallModeId] = small_mode_info;
o->mode_infos[kBigModeId] = big_mode_info;
@@ -1090,4 +1106,102 @@ TEST_F(OutputConfiguratorTest, PanelFitting) {
EXPECT_EQ(kSmallModeHeight, info->height);
}
+TEST_F(OutputConfiguratorTest, OutputProtection) {
+ configurator_.Init(false);
+ configurator_.Start(0);
+ EXPECT_NE(kNoActions, delegate_->GetActionsAndClear());
+
+ OutputConfigurator::OutputProtectionClientId id =
+ configurator_.RegisterOutputProtectionClient();
+ EXPECT_NE(0u, id);
+
+ // One output.
+ UpdateOutputs(1, true);
+ EXPECT_NE(kNoActions, delegate_->GetActionsAndClear());
+ uint32_t link_mask = 0;
+ uint32_t protection_mask = 0;
+ EXPECT_TRUE(configurator_.QueryOutputProtectionStatus(id, &link_mask,
+ &protection_mask));
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_TYPE_INTERNAL), link_mask);
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_PROTECTION_METHOD_NONE),
+ protection_mask);
+ EXPECT_EQ(kNoActions, delegate_->GetActionsAndClear());
+
+ // Two outputs.
+ UpdateOutputs(2, true);
+ EXPECT_NE(kNoActions, delegate_->GetActionsAndClear());
+ EXPECT_TRUE(configurator_.QueryOutputProtectionStatus(id, &link_mask,
+ &protection_mask));
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_TYPE_INTERNAL | OUTPUT_TYPE_HDMI),
+ link_mask);
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_PROTECTION_METHOD_NONE),
+ protection_mask);
+ EXPECT_EQ(kNoActions, delegate_->GetActionsAndClear());
+
+ EXPECT_TRUE(
+ configurator_.EnableOutputProtection(id, OUTPUT_PROTECTION_METHOD_HDCP));
+ EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output, HDCP_STATE_DESIRED),
+ delegate_->GetActionsAndClear());
+
+ // Enable protection.
+ delegate_->set_hdcp_state(HDCP_STATE_ENABLED);
+ EXPECT_TRUE(configurator_.QueryOutputProtectionStatus(id, &link_mask,
+ &protection_mask));
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_TYPE_INTERNAL | OUTPUT_TYPE_HDMI),
+ link_mask);
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_PROTECTION_METHOD_HDCP),
+ protection_mask);
+ EXPECT_EQ(kNoActions, delegate_->GetActionsAndClear());
+}
+
+TEST_F(OutputConfiguratorTest, OutputProtectionTwoClients) {
+ OutputConfigurator::OutputProtectionClientId client1 =
+ configurator_.RegisterOutputProtectionClient();
+ OutputConfigurator::OutputProtectionClientId client2 =
+ configurator_.RegisterOutputProtectionClient();
+ EXPECT_NE(client1, client2);
+
+ configurator_.Init(false);
+ configurator_.Start(0);
+ UpdateOutputs(2, true);
+ EXPECT_NE(kNoActions, delegate_->GetActionsAndClear());
+
+ // Clients never know state enableness for methods that they didn't request.
+ EXPECT_TRUE(
+ configurator_.EnableOutputProtection(client1,
+ OUTPUT_PROTECTION_METHOD_HDCP));
+ EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output,
+ HDCP_STATE_DESIRED).c_str(),
+ delegate_->GetActionsAndClear());
+ delegate_->set_hdcp_state(HDCP_STATE_ENABLED);
+
+ uint32_t link_mask = 0;
+ uint32_t protection_mask = 0;
+ EXPECT_TRUE(configurator_.QueryOutputProtectionStatus(client1, &link_mask,
+ &protection_mask));
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_TYPE_INTERNAL | OUTPUT_TYPE_HDMI),
+ link_mask);
+ EXPECT_EQ(OUTPUT_PROTECTION_METHOD_HDCP, protection_mask);
+
+ EXPECT_TRUE(configurator_.QueryOutputProtectionStatus(client2, &link_mask,
+ &protection_mask));
+ EXPECT_EQ(static_cast<uint32_t>(OUTPUT_TYPE_INTERNAL | OUTPUT_TYPE_HDMI),
+ link_mask);
+ EXPECT_EQ(OUTPUT_PROTECTION_METHOD_NONE, protection_mask);
+
+ // Protections will be disabled only if no more clients request them.
+ EXPECT_TRUE(
+ configurator_.EnableOutputProtection(client2,
+ OUTPUT_PROTECTION_METHOD_NONE));
+ EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output,
+ HDCP_STATE_DESIRED).c_str(),
+ delegate_->GetActionsAndClear());
+ EXPECT_TRUE(
+ configurator_.EnableOutputProtection(client1,
+ OUTPUT_PROTECTION_METHOD_NONE));
+ EXPECT_EQ(GetSetHDCPStateAction(outputs_[1].output,
+ HDCP_STATE_UNDESIRED).c_str(),
+ delegate_->GetActionsAndClear());
+}
+
} // namespace chromeos
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698