display_test_util.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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
  3. // found in the LICENSE file.
  4. #ifndef UI_DISPLAY_TEST_DISPLAY_TEST_UTIL_H_
  5. #define UI_DISPLAY_TEST_DISPLAY_TEST_UTIL_H_
  6. #include "ui/display/display.h"
  7. #include "ui/display/util/display_util.h"
  8. namespace display {
  9. // Use this class instead of calling `SetInternalDisplayIds()` in unit tests to
  10. // avoid leaking the state to other tests.
  11. class ScopedSetInternalDisplayIds {
  12. public:
  13. explicit ScopedSetInternalDisplayIds(const base::flat_set<int64_t> ids) {
  14. SetInternalDisplayIds(ids);
  15. }
  16. explicit ScopedSetInternalDisplayIds(int64_t id) {
  17. SetInternalDisplayIds({id});
  18. }
  19. ScopedSetInternalDisplayIds(const ScopedSetInternalDisplayIds&) = delete;
  20. ScopedSetInternalDisplayIds operator=(const ScopedSetInternalDisplayIds&) =
  21. delete;
  22. ~ScopedSetInternalDisplayIds() { SetInternalDisplayIds({}); }
  23. };
  24. inline void PrintTo(const Display& display, ::std::ostream* os) {
  25. *os << display.ToString();
  26. }
  27. } // namespace display
  28. #endif // UI_DISPLAY_TEST_DISPLAY_TEST_UTIL_H_