cast_screen_unittest.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2019 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.
  4. #include "chromecast/graphics/cast_screen.h"
  5. #include "testing/gmock/include/gmock/gmock.h"
  6. #include "ui/aura/test/aura_test_base.h"
  7. #include "ui/display/display_observer.h"
  8. using testing::_;
  9. using testing::AllOf;
  10. using testing::Property;
  11. namespace chromecast {
  12. namespace test {
  13. namespace {
  14. constexpr int64_t kMockDisplayId = 0xcafebabe;
  15. }
  16. using CastScreenTest = aura::test::AuraTestBase;
  17. class MockDisplayObserver : public display::DisplayObserver {
  18. public:
  19. MOCK_METHOD2(OnDisplayMetricsChanged,
  20. void(const display::Display& display, uint32_t changed_metrics));
  21. };
  22. TEST_F(CastScreenTest, OverrideAndRestore) {
  23. MockDisplayObserver mock_display_observer;
  24. CastScreen screen;
  25. // Set up initial screen.
  26. screen.OnDisplayChanged(kMockDisplayId, 1.0,
  27. display::Display::Rotation::ROTATE_0,
  28. gfx::Rect(0, 0, 1920, 1080));
  29. EXPECT_CALL(mock_display_observer,
  30. OnDisplayMetricsChanged(
  31. AllOf(Property(&display::Display::id, kMockDisplayId),
  32. Property(&display::Display::device_scale_factor, 2.2),
  33. Property(&display::Display::rotation,
  34. display::Display::Rotation::ROTATE_270)),
  35. _));
  36. EXPECT_CALL(mock_display_observer,
  37. OnDisplayMetricsChanged(
  38. AllOf(Property(&display::Display::id, kMockDisplayId),
  39. Property(&display::Display::device_scale_factor, 1.0),
  40. Property(&display::Display::rotation,
  41. display::Display::Rotation::ROTATE_0)),
  42. _));
  43. screen.AddObserver(&mock_display_observer);
  44. screen.OverridePrimaryDisplaySettings(gfx::Rect(0, 0, 1000, 1000), 2.2,
  45. display::Display::Rotation::ROTATE_270);
  46. screen.RestorePrimaryDisplaySettings();
  47. }
  48. } // namespace test
  49. } // namespace chromecast