| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/display/test/display_matchers.h" | 5 #include "ui/display/test/display_matchers.h" |
| 6 | 6 |
| 7 namespace display { | 7 namespace display { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 const float kEpsilon = 0.0001f; | 11 const float kEpsilon = 0.0001f; |
| 12 | 12 |
| 13 // Matcher to check DisplayMode size and refresh rate. | 13 // Matcher to check DisplayMode size and refresh rate. |
| 14 class DisplayModeMatcher | 14 class DisplayModeMatcher |
| 15 : public testing::MatcherInterface<const ui::DisplayMode&> { | 15 : public testing::MatcherInterface<const DisplayMode&> { |
| 16 public: | 16 public: |
| 17 DisplayModeMatcher(int width, int height, float refresh_rate) | 17 DisplayModeMatcher(int width, int height, float refresh_rate) |
| 18 : size_(width, height), refresh_rate_(refresh_rate) {} | 18 : size_(width, height), refresh_rate_(refresh_rate) {} |
| 19 | 19 |
| 20 bool MatchAndExplain(const ui::DisplayMode& mode, | 20 bool MatchAndExplain(const DisplayMode& mode, |
| 21 testing::MatchResultListener* listener) const override { | 21 testing::MatchResultListener* listener) const override { |
| 22 return mode.size() == size_ && | 22 return mode.size() == size_ && |
| 23 std::fabs(mode.refresh_rate() - refresh_rate_) < kEpsilon; | 23 std::fabs(mode.refresh_rate() - refresh_rate_) < kEpsilon; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void DescribeTo(std::ostream* os) const override { | 26 void DescribeTo(std::ostream* os) const override { |
| 27 *os << "[" << size_.ToString() << " rate=" << refresh_rate_ << "]"; | 27 *os << "[" << size_.ToString() << " rate=" << refresh_rate_ << "]"; |
| 28 } | 28 } |
| 29 | 29 |
| 30 void DescribeNegationTo(std::ostream* os) const override { | 30 void DescribeNegationTo(std::ostream* os) const override { |
| 31 *os << "not [" << size_.ToString() << " rate=" << refresh_rate_ << "]"; | 31 *os << "not [" << size_.ToString() << " rate=" << refresh_rate_ << "]"; |
| 32 } | 32 } |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 gfx::Size size_; | 35 gfx::Size size_; |
| 36 float refresh_rate_; | 36 float refresh_rate_; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 testing::Matcher<const ui::DisplayMode&> IsDisplayMode(int width, | 41 testing::Matcher<const DisplayMode&> IsDisplayMode(int width, |
| 42 int height, | 42 int height, |
| 43 float refresh_rate) { | 43 float refresh_rate) { |
| 44 return testing::MakeMatcher( | 44 return testing::MakeMatcher( |
| 45 new DisplayModeMatcher(width, height, refresh_rate)); | 45 new DisplayModeMatcher(width, height, refresh_rate)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace display | 48 } // namespace display |
| OLD | NEW |