Commit a9318847 authored by kcwu@chromium.org's avatar kcwu@chromium.org

Unit tests for output protection in output configurator

R=derat@chromium.org

Review URL: https://codereview.chromium.org/25058009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226414 0039d316-1c4b-4281-b951-d872f2087c98
parent 6dc9f719
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment