Commit 0f9bdf49 authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Add check for the precision of display zoom value

Display preferences for chrome OS stores the display zoom value only
upto a precision of 2 decimal point.

This patch adds a check of precision to ensure that in the future if
any changes are made to the way display zoom values are generated then
those changes keep in mind this precision that is used by display prefs.

Bug: 823922
Change-Id: I8370415041bcaeac55c4afef9a4e4125979559b4
Component: Display Util Test
Reviewed-on: https://chromium-review.googlesource.com/974264Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544897}
parent b5891adf
...@@ -52,9 +52,18 @@ TEST_F(DisplayUtilTest, DisplayZooms) { ...@@ -52,9 +52,18 @@ TEST_F(DisplayUtilTest, DisplayZooms) {
ManagedDisplayMode mode(gfx::Size(size, size), 60, false, true, 1.f, 1.f); ManagedDisplayMode mode(gfx::Size(size, size), 60, false, true, 1.f, 1.f);
const std::vector<double> zoom_values = GetDisplayZoomFactors(mode); const std::vector<double> zoom_values = GetDisplayZoomFactors(mode);
EXPECT_EQ(zoom_values.size(), kNumOfZoomFactors); EXPECT_EQ(zoom_values.size(), kNumOfZoomFactors);
for (std::size_t j = 0; j < kNumOfZoomFactors; j++) for (std::size_t j = 0; j < kNumOfZoomFactors; j++) {
EXPECT_NEAR(zoom_values[j], pair.second[j], 0.001); EXPECT_NEAR(zoom_values[j], pair.second[j], 0.001);
// Display pref stores the zoom value only upto 2 decimal places. This
// check ensures that the expected precision is only upto 2 decimal
// points. Before changing this line please ensure that you have updated
// chromeos/display/display_prefs.cc
int percentage_value = std::round(zoom_values[j] * 100.f);
float fractional_value = static_cast<float>(percentage_value) / 100.f;
EXPECT_NEAR(zoom_values[j], fractional_value, 0.0001f);
}
const int effective_minimum_width_possible = size / zoom_values.back(); const int effective_minimum_width_possible = size / zoom_values.back();
const int effective_maximum_width_possible = size * zoom_values.front(); const int effective_maximum_width_possible = size * zoom_values.front();
......
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