scoped_fake_ash_display_util.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2021 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 REMOTING_HOST_CHROMEOS_SCOPED_FAKE_ASH_DISPLAY_UTIL_H_
  5. #define REMOTING_HOST_CHROMEOS_SCOPED_FAKE_ASH_DISPLAY_UTIL_H_
  6. #include <string>
  7. #include <vector>
  8. #include "remoting/host/chromeos/ash_display_util.h"
  9. #include "base/test/test_future.h"
  10. namespace remoting {
  11. namespace test {
  12. struct ScreenshotRequest {
  13. ScreenshotRequest(DisplayId display,
  14. AshDisplayUtil::ScreenshotCallback callback);
  15. ScreenshotRequest(ScreenshotRequest&&);
  16. ScreenshotRequest& operator=(ScreenshotRequest&&);
  17. ~ScreenshotRequest();
  18. DisplayId display;
  19. AshDisplayUtil::ScreenshotCallback callback;
  20. };
  21. // Simple basic implementation of |AshDisplayUtil|.
  22. // Will automatically register itself as the global version in the constructor,
  23. // and deregister in the destructor.
  24. class ScopedFakeAshDisplayUtil : public AshDisplayUtil {
  25. public:
  26. static constexpr DisplayId kDefaultPrimaryDisplayId = 12345678901;
  27. ScopedFakeAshDisplayUtil();
  28. ScopedFakeAshDisplayUtil(const ScopedFakeAshDisplayUtil&) = delete;
  29. ScopedFakeAshDisplayUtil& operator=(const ScopedFakeAshDisplayUtil&) = delete;
  30. ~ScopedFakeAshDisplayUtil() override;
  31. display::Display& AddPrimaryDisplay(DisplayId id = kDefaultPrimaryDisplayId);
  32. display::Display& AddDisplayWithId(DisplayId id);
  33. // Create a display with the given specifications.
  34. // See display::ManagedDisplayInfo::CreateFromSpec for details of the
  35. // specification string.
  36. display::Display& AddDisplayFromSpecWithId(const std::string& spec,
  37. DisplayId id);
  38. void RemoveDisplay(DisplayId id);
  39. ScreenshotRequest WaitForScreenshotRequest();
  40. void ReplyWithScreenshot(const absl::optional<SkBitmap>& screenshot);
  41. // AshDisplayUtil implementation:
  42. DisplayId GetPrimaryDisplayId() const override;
  43. const std::vector<display::Display>& GetActiveDisplays() const override;
  44. const display::Display* GetDisplayForId(DisplayId display_id) const override;
  45. void TakeScreenshotOfDisplay(DisplayId display_id,
  46. ScreenshotCallback callback) override;
  47. private:
  48. display::Display& AddDisplay(display::Display new_display);
  49. DisplayId primary_display_id_ = -1;
  50. std::vector<display::Display> displays_;
  51. base::test::TestFuture<ScreenshotRequest> screenshot_request_;
  52. };
  53. } // namespace test
  54. } // namespace remoting
  55. #endif // REMOTING_HOST_CHROMEOS_SCOPED_FAKE_ASH_DISPLAY_UTIL_H_